xref: /OK3568_Linux_fs/kernel/Documentation/filesystems/quota.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun===============
4*4882a593SmuzhiyunQuota subsystem
5*4882a593Smuzhiyun===============
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunQuota subsystem allows system administrator to set limits on used space and
8*4882a593Smuzhiyunnumber of used inodes (inode is a filesystem structure which is associated with
9*4882a593Smuzhiyuneach file or directory) for users and/or groups. For both used space and number
10*4882a593Smuzhiyunof used inodes there are actually two limits. The first one is called softlimit
11*4882a593Smuzhiyunand the second one hardlimit.  A user can never exceed a hardlimit for any
12*4882a593Smuzhiyunresource (unless he has CAP_SYS_RESOURCE capability). User is allowed to exceed
13*4882a593Smuzhiyunsoftlimit but only for limited period of time. This period is called "grace
14*4882a593Smuzhiyunperiod" or "grace time". When grace time is over, user is not able to allocate
15*4882a593Smuzhiyunmore space/inodes until he frees enough of them to get below softlimit.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunQuota limits (and amount of grace time) are set independently for each
18*4882a593Smuzhiyunfilesystem.
19*4882a593Smuzhiyun
20*4882a593SmuzhiyunFor more details about quota design, see the documentation in quota-tools package
21*4882a593Smuzhiyun(https://sourceforge.net/projects/linuxquota).
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunQuota netlink interface
24*4882a593Smuzhiyun=======================
25*4882a593SmuzhiyunWhen user exceeds a softlimit, runs out of grace time or reaches hardlimit,
26*4882a593Smuzhiyunquota subsystem traditionally printed a message to the controlling terminal of
27*4882a593Smuzhiyunthe process which caused the excess. This method has the disadvantage that
28*4882a593Smuzhiyunwhen user is using a graphical desktop he usually cannot see the message.
29*4882a593SmuzhiyunThus quota netlink interface has been designed to pass information about
30*4882a593Smuzhiyunthe above events to userspace. There they can be captured by an application
31*4882a593Smuzhiyunand processed accordingly.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThe interface uses generic netlink framework (see
34*4882a593Smuzhiyunhttps://lwn.net/Articles/208755/ and http://www.infradead.org/~tgr/libnl/ for
35*4882a593Smuzhiyunmore details about this layer). The name of the quota generic netlink interface
36*4882a593Smuzhiyunis "VFS_DQUOT". Definitions of constants below are in <linux/quota.h>.  Since
37*4882a593Smuzhiyunthe quota netlink protocol is not namespace aware, quota netlink messages are
38*4882a593Smuzhiyunsent only in initial network namespace.
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunCurrently, the interface supports only one message type QUOTA_NL_C_WARNING.
41*4882a593SmuzhiyunThis command is used to send a notification about any of the above mentioned
42*4882a593Smuzhiyunevents. Each message has six attributes. These are (type of the argument is
43*4882a593Smuzhiyunin parentheses):
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun        QUOTA_NL_A_QTYPE (u32)
46*4882a593Smuzhiyun	  - type of quota being exceeded (one of USRQUOTA, GRPQUOTA)
47*4882a593Smuzhiyun        QUOTA_NL_A_EXCESS_ID (u64)
48*4882a593Smuzhiyun	  - UID/GID (depends on quota type) of user / group whose limit
49*4882a593Smuzhiyun	    is being exceeded.
50*4882a593Smuzhiyun        QUOTA_NL_A_CAUSED_ID (u64)
51*4882a593Smuzhiyun	  - UID of a user who caused the event
52*4882a593Smuzhiyun        QUOTA_NL_A_WARNING (u32)
53*4882a593Smuzhiyun	  - what kind of limit is exceeded:
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun		QUOTA_NL_IHARDWARN
56*4882a593Smuzhiyun		    inode hardlimit
57*4882a593Smuzhiyun		QUOTA_NL_ISOFTLONGWARN
58*4882a593Smuzhiyun		    inode softlimit is exceeded longer
59*4882a593Smuzhiyun		    than given grace period
60*4882a593Smuzhiyun		QUOTA_NL_ISOFTWARN
61*4882a593Smuzhiyun		    inode softlimit
62*4882a593Smuzhiyun		QUOTA_NL_BHARDWARN
63*4882a593Smuzhiyun		    space (block) hardlimit
64*4882a593Smuzhiyun		QUOTA_NL_BSOFTLONGWARN
65*4882a593Smuzhiyun		    space (block) softlimit is exceeded
66*4882a593Smuzhiyun		    longer than given grace period.
67*4882a593Smuzhiyun		QUOTA_NL_BSOFTWARN
68*4882a593Smuzhiyun		    space (block) softlimit
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun	  - four warnings are also defined for the event when user stops
71*4882a593Smuzhiyun	    exceeding some limit:
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun		QUOTA_NL_IHARDBELOW
74*4882a593Smuzhiyun		    inode hardlimit
75*4882a593Smuzhiyun		QUOTA_NL_ISOFTBELOW
76*4882a593Smuzhiyun		    inode softlimit
77*4882a593Smuzhiyun		QUOTA_NL_BHARDBELOW
78*4882a593Smuzhiyun		    space (block) hardlimit
79*4882a593Smuzhiyun		QUOTA_NL_BSOFTBELOW
80*4882a593Smuzhiyun		    space (block) softlimit
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun        QUOTA_NL_A_DEV_MAJOR (u32)
83*4882a593Smuzhiyun	  - major number of a device with the affected filesystem
84*4882a593Smuzhiyun        QUOTA_NL_A_DEV_MINOR (u32)
85*4882a593Smuzhiyun	  - minor number of a device with the affected filesystem
86