129759Swollman.. SPDX-License-Identifier: GPL-2.0
229759Swollman
329759Swollman===============
429759SwollmanQuota subsystem
529759Swollman===============
629759Swollman
729759SwollmanQuota subsystem allows system administrator to set limits on used space and
829759Swollmannumber of used inodes (inode is a filesystem structure which is associated with
929759Swollmaneach file or directory) for users and/or groups. For both used space and number
1029759Swollmanof used inodes there are actually two limits. The first one is called softlimit
1129759Swollmanand the second one hardlimit.  A user can never exceed a hardlimit for any
1229759Swollmanresource (unless he has CAP_SYS_RESOURCE capability). User is allowed to exceed
1329759Swollmansoftlimit but only for limited period of time. This period is called "grace
1429759Swollmanperiod" or "grace time". When grace time is over, user is not able to allocate
1529759Swollmanmore space/inodes until he frees enough of them to get below softlimit.
1629759Swollman
1729759SwollmanQuota limits (and amount of grace time) are set independently for each
1829759Swollmanfilesystem.
1929759Swollman
2029759SwollmanFor more details about quota design, see the documentation in quota-tools package
2129759Swollman(https://sourceforge.net/projects/linuxquota).
2229759Swollman
2329759SwollmanQuota netlink interface
2429759Swollman=======================
2529759SwollmanWhen user exceeds a softlimit, runs out of grace time or reaches hardlimit,
2629759Swollmanquota subsystem traditionally printed a message to the controlling terminal of
2729759Swollmanthe process which caused the excess. This method has the disadvantage that
2829759Swollmanwhen user is using a graphical desktop he usually cannot see the message.
2929759SwollmanThus quota netlink interface has been designed to pass information about
3087715Smarkmthe above events to userspace. There they can be captured by an application
3187715Smarkmand processed accordingly.
3287715Smarkm
3387715SmarkmThe interface uses generic netlink framework (see
3487715Smarkmhttps://lwn.net/Articles/208755/ and http://www.infradead.org/~tgr/libnl/ for
3587715Smarkmmore details about this layer). The name of the quota generic netlink interface
3687715Smarkmis "VFS_DQUOT". Definitions of constants below are in <linux/quota.h>.  Since
3787715Smarkmthe quota netlink protocol is not namespace aware, quota netlink messages are
3829759Swollmansent only in initial network namespace.
3987715Smarkm
4029759SwollmanCurrently, the interface supports only one message type QUOTA_NL_C_WARNING.
4129759SwollmanThis command is used to send a notification about any of the above mentioned
4229759Swollmanevents. Each message has six attributes. These are (type of the argument is
4329759Swollmanin parentheses):
4429759Swollman
4529759Swollman        QUOTA_NL_A_QTYPE (u32)
4629759Swollman	  - type of quota being exceeded (one of USRQUOTA, GRPQUOTA)
4729759Swollman        QUOTA_NL_A_EXCESS_ID (u64)
4829759Swollman	  - UID/GID (depends on quota type) of user / group whose limit
4929759Swollman	    is being exceeded.
5029759Swollman        QUOTA_NL_A_CAUSED_ID (u64)
5129759Swollman	  - UID of a user who caused the event
5229759Swollman        QUOTA_NL_A_WARNING (u32)
53200462Sdelphij	  - what kind of limit is exceeded:
5429759Swollman
55200462Sdelphij		QUOTA_NL_IHARDWARN
5629759Swollman		    inode hardlimit
5729759Swollman		QUOTA_NL_ISOFTLONGWARN
5829759Swollman		    inode softlimit is exceeded longer
5929759Swollman		    than given grace period
6029759Swollman		QUOTA_NL_ISOFTWARN
6129759Swollman		    inode softlimit
6229759Swollman		QUOTA_NL_BHARDWARN
6329759Swollman		    space (block) hardlimit
6429759Swollman		QUOTA_NL_BSOFTLONGWARN
65158160Sbde		    space (block) softlimit is exceeded
66158160Sbde		    longer than given grace period.
67158160Sbde		QUOTA_NL_BSOFTWARN
68158160Sbde		    space (block) softlimit
69158160Sbde
70158160Sbde	  - four warnings are also defined for the event when user stops
71158160Sbde	    exceeding some limit:
72158160Sbde
73158160Sbde		QUOTA_NL_IHARDBELOW
74158160Sbde		    inode hardlimit
75158160Sbde		QUOTA_NL_ISOFTBELOW
76158160Sbde		    inode softlimit
77158160Sbde		QUOTA_NL_BHARDBELOW
78158160Sbde		    space (block) hardlimit
79158160Sbde		QUOTA_NL_BSOFTBELOW
80158160Sbde		    space (block) softlimit
81158160Sbde
82158160Sbde        QUOTA_NL_A_DEV_MAJOR (u32)
8329759Swollman	  - major number of a device with the affected filesystem
8429759Swollman        QUOTA_NL_A_DEV_MINOR (u32)
8529759Swollman	  - minor number of a device with the affected filesystem
8629759Swollman