xref: /linux/fs/xfs/xfs_quota.h (revision 83e782e1a1cc0159888e58e14dfc8f3289663338)
11da177e4SLinus Torvalds /*
27b718769SNathan Scott  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
37b718769SNathan Scott  * All Rights Reserved.
41da177e4SLinus Torvalds  *
57b718769SNathan Scott  * This program is free software; you can redistribute it and/or
67b718769SNathan Scott  * modify it under the terms of the GNU General Public License as
71da177e4SLinus Torvalds  * published by the Free Software Foundation.
81da177e4SLinus Torvalds  *
97b718769SNathan Scott  * This program is distributed in the hope that it would be useful,
107b718769SNathan Scott  * but WITHOUT ANY WARRANTY; without even the implied warranty of
117b718769SNathan Scott  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
127b718769SNathan Scott  * GNU General Public License for more details.
131da177e4SLinus Torvalds  *
147b718769SNathan Scott  * You should have received a copy of the GNU General Public License
157b718769SNathan Scott  * along with this program; if not, write the Free Software Foundation,
167b718769SNathan Scott  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
171da177e4SLinus Torvalds  */
181da177e4SLinus Torvalds #ifndef __XFS_QUOTA_H__
191da177e4SLinus Torvalds #define __XFS_QUOTA_H__
201da177e4SLinus Torvalds 
21fcafb71bSChristoph Hellwig struct xfs_trans;
22fcafb71bSChristoph Hellwig 
231da177e4SLinus Torvalds /*
241da177e4SLinus Torvalds  * The ondisk form of a dquot structure.
251da177e4SLinus Torvalds  */
261da177e4SLinus Torvalds #define XFS_DQUOT_MAGIC		0x4451		/* 'DQ' */
271da177e4SLinus Torvalds #define XFS_DQUOT_VERSION	(u_int8_t)0x01	/* latest version number */
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds /*
301da177e4SLinus Torvalds  * uid_t and gid_t are hard-coded to 32 bits in the inode.
311da177e4SLinus Torvalds  * Hence, an 'id' in a dquot is 32 bits..
321da177e4SLinus Torvalds  */
33c310ab6cSNathan Scott typedef __uint32_t	xfs_dqid_t;
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds /*
361da177e4SLinus Torvalds  * Even though users may not have quota limits occupying all 64-bits,
371da177e4SLinus Torvalds  * they may need 64-bit accounting. Hence, 64-bit quota-counters,
381da177e4SLinus Torvalds  * and quota-limits. This is a waste in the common case, but hey ...
391da177e4SLinus Torvalds  */
401da177e4SLinus Torvalds typedef __uint64_t	xfs_qcnt_t;
411da177e4SLinus Torvalds typedef __uint16_t	xfs_qwarncnt_t;
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds /*
441da177e4SLinus Torvalds  * This is the main portion of the on-disk representation of quota
451da177e4SLinus Torvalds  * information for a user. This is the q_core of the xfs_dquot_t that
461da177e4SLinus Torvalds  * is kept in kernel memory. We pad this with some more expansion room
471da177e4SLinus Torvalds  * to construct the on disk structure.
481da177e4SLinus Torvalds  */
491da177e4SLinus Torvalds typedef struct	xfs_disk_dquot {
501149d96aSChristoph Hellwig 	__be16		d_magic;	/* dquot magic = XFS_DQUOT_MAGIC */
511149d96aSChristoph Hellwig 	__u8		d_version;	/* dquot version */
521149d96aSChristoph Hellwig 	__u8		d_flags;	/* XFS_DQ_USER/PROJ/GROUP */
531149d96aSChristoph Hellwig 	__be32		d_id;		/* user,project,group id */
541149d96aSChristoph Hellwig 	__be64		d_blk_hardlimit;/* absolute limit on disk blks */
551149d96aSChristoph Hellwig 	__be64		d_blk_softlimit;/* preferred limit on disk blks */
561149d96aSChristoph Hellwig 	__be64		d_ino_hardlimit;/* maximum # allocated inodes */
571149d96aSChristoph Hellwig 	__be64		d_ino_softlimit;/* preferred inode limit */
581149d96aSChristoph Hellwig 	__be64		d_bcount;	/* disk blocks owned by the user */
591149d96aSChristoph Hellwig 	__be64		d_icount;	/* inodes owned by the user */
601149d96aSChristoph Hellwig 	__be32		d_itimer;	/* zero if within inode limits if not,
611da177e4SLinus Torvalds 					   this is when we refuse service */
621149d96aSChristoph Hellwig 	__be32		d_btimer;	/* similar to above; for disk blocks */
631149d96aSChristoph Hellwig 	__be16		d_iwarns;	/* warnings issued wrt num inodes */
641149d96aSChristoph Hellwig 	__be16		d_bwarns;	/* warnings issued wrt disk blocks */
651149d96aSChristoph Hellwig 	__be32		d_pad0;		/* 64 bit align */
661149d96aSChristoph Hellwig 	__be64		d_rtb_hardlimit;/* absolute limit on realtime blks */
671149d96aSChristoph Hellwig 	__be64		d_rtb_softlimit;/* preferred limit on RT disk blks */
681149d96aSChristoph Hellwig 	__be64		d_rtbcount;	/* realtime blocks owned */
691149d96aSChristoph Hellwig 	__be32		d_rtbtimer;	/* similar to above; for RT disk blocks */
701149d96aSChristoph Hellwig 	__be16		d_rtbwarns;	/* warnings issued wrt RT disk blocks */
711149d96aSChristoph Hellwig 	__be16		d_pad;
721da177e4SLinus Torvalds } xfs_disk_dquot_t;
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /*
751da177e4SLinus Torvalds  * This is what goes on disk. This is separated from the xfs_disk_dquot because
761da177e4SLinus Torvalds  * carrying the unnecessary padding would be a waste of memory.
771da177e4SLinus Torvalds  */
781da177e4SLinus Torvalds typedef struct xfs_dqblk {
791da177e4SLinus Torvalds 	xfs_disk_dquot_t  dd_diskdq;	/* portion that lives incore as well */
803fe58f30SChristoph Hellwig 	char		  dd_fill[4];	/* filling for posterity */
813fe58f30SChristoph Hellwig 
823fe58f30SChristoph Hellwig 	/*
833fe58f30SChristoph Hellwig 	 * These two are only present on filesystems with the CRC bits set.
843fe58f30SChristoph Hellwig 	 */
853fe58f30SChristoph Hellwig 	__be32		  dd_crc;	/* checksum */
863fe58f30SChristoph Hellwig 	__be64		  dd_lsn;	/* last modification in log */
873fe58f30SChristoph Hellwig 	uuid_t		  dd_uuid;	/* location information */
881da177e4SLinus Torvalds } xfs_dqblk_t;
891da177e4SLinus Torvalds 
906fcdc59dSDave Chinner #define XFS_DQUOT_CRC_OFF	offsetof(struct xfs_dqblk, dd_crc)
916fcdc59dSDave Chinner 
921da177e4SLinus Torvalds /*
931da177e4SLinus Torvalds  * flags for q_flags field in the dquot.
941da177e4SLinus Torvalds  */
951da177e4SLinus Torvalds #define XFS_DQ_USER		0x0001		/* a user quota */
96c8ad20ffSNathan Scott #define XFS_DQ_PROJ		0x0002		/* project quota */
971da177e4SLinus Torvalds #define XFS_DQ_GROUP		0x0004		/* a group quota */
98df6771bdSChristoph Hellwig #define XFS_DQ_DIRTY		0x0008		/* dquot is dirty */
9992678554SChristoph Hellwig #define XFS_DQ_FREEING		0x0010		/* dquot is beeing torn down */
1001da177e4SLinus Torvalds 
101c8ad20ffSNathan Scott #define XFS_DQ_ALLTYPES		(XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
102c8ad20ffSNathan Scott 
1030b1b213fSChristoph Hellwig #define XFS_DQ_FLAGS \
1040b1b213fSChristoph Hellwig 	{ XFS_DQ_USER,		"USER" }, \
1050b1b213fSChristoph Hellwig 	{ XFS_DQ_PROJ,		"PROJ" }, \
1060b1b213fSChristoph Hellwig 	{ XFS_DQ_GROUP,		"GROUP" }, \
10792678554SChristoph Hellwig 	{ XFS_DQ_DIRTY,		"DIRTY" }, \
10892678554SChristoph Hellwig 	{ XFS_DQ_FREEING,	"FREEING" }
1090b1b213fSChristoph Hellwig 
1101da177e4SLinus Torvalds /*
1111da177e4SLinus Torvalds  * In the worst case, when both user and group quotas are on,
1121da177e4SLinus Torvalds  * we can have a max of three dquots changing in a single transaction.
1131da177e4SLinus Torvalds  */
1141da177e4SLinus Torvalds #define XFS_DQUOT_LOGRES(mp)	(sizeof(xfs_disk_dquot_t) * 3)
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 
1171da177e4SLinus Torvalds /*
1181da177e4SLinus Torvalds  * These are the structures used to lay out dquots and quotaoff
1191da177e4SLinus Torvalds  * records on the log. Quite similar to those of inodes.
1201da177e4SLinus Torvalds  */
1211da177e4SLinus Torvalds 
1221da177e4SLinus Torvalds /*
1231da177e4SLinus Torvalds  * log format struct for dquots.
1241da177e4SLinus Torvalds  * The first two fields must be the type and size fitting into
1251da177e4SLinus Torvalds  * 32 bits : log_recovery code assumes that.
1261da177e4SLinus Torvalds  */
1271da177e4SLinus Torvalds typedef struct xfs_dq_logformat {
1281da177e4SLinus Torvalds 	__uint16_t		qlf_type;      /* dquot log item type */
1291da177e4SLinus Torvalds 	__uint16_t		qlf_size;      /* size of this item */
130c8ad20ffSNathan Scott 	xfs_dqid_t		qlf_id;	       /* usr/grp/proj id : 32 bits */
1311da177e4SLinus Torvalds 	__int64_t		qlf_blkno;     /* blkno of dquot buffer */
1321da177e4SLinus Torvalds 	__int32_t		qlf_len;       /* len of dquot buffer */
1331da177e4SLinus Torvalds 	__uint32_t		qlf_boffset;   /* off of dquot in buffer */
1341da177e4SLinus Torvalds } xfs_dq_logformat_t;
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds /*
1371da177e4SLinus Torvalds  * log format struct for QUOTAOFF records.
1381da177e4SLinus Torvalds  * The first two fields must be the type and size fitting into
1391da177e4SLinus Torvalds  * 32 bits : log_recovery code assumes that.
1401da177e4SLinus Torvalds  * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
1411da177e4SLinus Torvalds  * to the first and ensures that the first logitem is taken out of the AIL
1421da177e4SLinus Torvalds  * only when the last one is securely committed.
1431da177e4SLinus Torvalds  */
1441da177e4SLinus Torvalds typedef struct xfs_qoff_logformat {
1451da177e4SLinus Torvalds 	unsigned short		qf_type;	/* quotaoff log item type */
1461da177e4SLinus Torvalds 	unsigned short		qf_size;	/* size of this item */
1471da177e4SLinus Torvalds 	unsigned int		qf_flags;	/* USR and/or GRP */
1481da177e4SLinus Torvalds 	char			qf_pad[12];	/* padding for future */
1491da177e4SLinus Torvalds } xfs_qoff_logformat_t;
1501da177e4SLinus Torvalds 
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds /*
1531da177e4SLinus Torvalds  * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
1541da177e4SLinus Torvalds  */
1551da177e4SLinus Torvalds #define XFS_UQUOTA_ACCT	0x0001  /* user quota accounting ON */
1561da177e4SLinus Torvalds #define XFS_UQUOTA_ENFD	0x0002  /* user quota limits enforced */
1571da177e4SLinus Torvalds #define XFS_UQUOTA_CHKD	0x0004  /* quotacheck run on usr quotas */
158c8ad20ffSNathan Scott #define XFS_PQUOTA_ACCT	0x0008  /* project quota accounting ON */
159c8ad20ffSNathan Scott #define XFS_OQUOTA_ENFD	0x0010  /* other (grp/prj) quota limits enforced */
160c8ad20ffSNathan Scott #define XFS_OQUOTA_CHKD	0x0020  /* quotacheck run on other (grp/prj) quotas */
1611da177e4SLinus Torvalds #define XFS_GQUOTA_ACCT	0x0040  /* group quota accounting ON */
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds /*
164*83e782e1SChandra Seetharaman  * Conversion to and from the combined OQUOTA flag (if necessary)
165*83e782e1SChandra Seetharaman  * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
166*83e782e1SChandra Seetharaman  */
167*83e782e1SChandra Seetharaman #define XFS_GQUOTA_ENFD	0x0080  /* group quota limits enforced */
168*83e782e1SChandra Seetharaman #define XFS_GQUOTA_CHKD	0x0100  /* quotacheck run on group quotas */
169*83e782e1SChandra Seetharaman #define XFS_PQUOTA_ENFD	0x0200  /* project quota limits enforced */
170*83e782e1SChandra Seetharaman #define XFS_PQUOTA_CHKD	0x0400  /* quotacheck run on project quotas */
171*83e782e1SChandra Seetharaman 
172*83e782e1SChandra Seetharaman /*
1734cd4a034STim Shimmin  * Quota Accounting/Enforcement flags
1744cd4a034STim Shimmin  */
1754cd4a034STim Shimmin #define XFS_ALL_QUOTA_ACCT	\
1764cd4a034STim Shimmin 		(XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
177*83e782e1SChandra Seetharaman #define XFS_ALL_QUOTA_ENFD	\
178*83e782e1SChandra Seetharaman 		(XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
179*83e782e1SChandra Seetharaman #define XFS_ALL_QUOTA_CHKD	\
180*83e782e1SChandra Seetharaman 		(XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
1814cd4a034STim Shimmin 
1824cd4a034STim Shimmin #define XFS_IS_QUOTA_RUNNING(mp)	((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
1834cd4a034STim Shimmin #define XFS_IS_UQUOTA_RUNNING(mp)	((mp)->m_qflags & XFS_UQUOTA_ACCT)
1844cd4a034STim Shimmin #define XFS_IS_PQUOTA_RUNNING(mp)	((mp)->m_qflags & XFS_PQUOTA_ACCT)
1854cd4a034STim Shimmin #define XFS_IS_GQUOTA_RUNNING(mp)	((mp)->m_qflags & XFS_GQUOTA_ACCT)
186e6d29426SKouta Ooizumi #define XFS_IS_UQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_UQUOTA_ENFD)
187*83e782e1SChandra Seetharaman #define XFS_IS_GQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_GQUOTA_ENFD)
188*83e782e1SChandra Seetharaman #define XFS_IS_PQUOTA_ENFORCED(mp)	((mp)->m_qflags & XFS_PQUOTA_ENFD)
1894cd4a034STim Shimmin 
1904cd4a034STim Shimmin /*
1911da177e4SLinus Torvalds  * Incore only flags for quotaoff - these bits get cleared when quota(s)
1921da177e4SLinus Torvalds  * are in the process of getting turned off. These flags are in m_qflags but
1931da177e4SLinus Torvalds  * never in sb_qflags.
1941da177e4SLinus Torvalds  */
195*83e782e1SChandra Seetharaman #define XFS_UQUOTA_ACTIVE	0x1000  /* uquotas are being turned off */
196*83e782e1SChandra Seetharaman #define XFS_GQUOTA_ACTIVE	0x2000  /* gquotas are being turned off */
197*83e782e1SChandra Seetharaman #define XFS_PQUOTA_ACTIVE	0x4000  /* pquotas are being turned off */
1984177af3aSChandra Seetharaman #define XFS_ALL_QUOTA_ACTIVE	\
199*83e782e1SChandra Seetharaman 	(XFS_UQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE)
2001da177e4SLinus Torvalds 
2011da177e4SLinus Torvalds /*
2021da177e4SLinus Torvalds  * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees
2031da177e4SLinus Torvalds  * quota will be not be switched off as long as that inode lock is held.
2041da177e4SLinus Torvalds  */
2051da177e4SLinus Torvalds #define XFS_IS_QUOTA_ON(mp)	((mp)->m_qflags & (XFS_UQUOTA_ACTIVE | \
206c8ad20ffSNathan Scott 						   XFS_GQUOTA_ACTIVE | \
207c8ad20ffSNathan Scott 						   XFS_PQUOTA_ACTIVE))
208c8ad20ffSNathan Scott #define XFS_IS_OQUOTA_ON(mp)	((mp)->m_qflags & (XFS_GQUOTA_ACTIVE | \
209c8ad20ffSNathan Scott 						   XFS_PQUOTA_ACTIVE))
2101da177e4SLinus Torvalds #define XFS_IS_UQUOTA_ON(mp)	((mp)->m_qflags & XFS_UQUOTA_ACTIVE)
2111da177e4SLinus Torvalds #define XFS_IS_GQUOTA_ON(mp)	((mp)->m_qflags & XFS_GQUOTA_ACTIVE)
212c8ad20ffSNathan Scott #define XFS_IS_PQUOTA_ON(mp)	((mp)->m_qflags & XFS_PQUOTA_ACTIVE)
2131da177e4SLinus Torvalds 
2141da177e4SLinus Torvalds /*
2151da177e4SLinus Torvalds  * Flags to tell various functions what to do. Not all of these are meaningful
2161da177e4SLinus Torvalds  * to a single function. None of these XFS_QMOPT_* flags are meant to have
2171da177e4SLinus Torvalds  * persistent values (ie. their values can and will change between versions)
2181da177e4SLinus Torvalds  */
2191da177e4SLinus Torvalds #define XFS_QMOPT_DQALLOC	0x0000002 /* alloc dquot ondisk if needed */
2201da177e4SLinus Torvalds #define XFS_QMOPT_UQUOTA	0x0000004 /* user dquot requested */
221c8ad20ffSNathan Scott #define XFS_QMOPT_PQUOTA	0x0000008 /* project dquot requested */
2221da177e4SLinus Torvalds #define XFS_QMOPT_FORCE_RES	0x0000010 /* ignore quota limits */
2231da177e4SLinus Torvalds #define XFS_QMOPT_SBVERSION	0x0000040 /* change superblock version num */
2249a2a7de2SNathan Scott #define XFS_QMOPT_DOWARN        0x0000400 /* increase warning cnt if needed */
2259a2a7de2SNathan Scott #define XFS_QMOPT_DQREPAIR	0x0001000 /* repair dquot if damaged */
226c8ad20ffSNathan Scott #define XFS_QMOPT_GQUOTA	0x0002000 /* group dquot requested */
2279a2a7de2SNathan Scott #define XFS_QMOPT_ENOSPC	0x0004000 /* enospc instead of edquot (prj) */
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds /*
2301da177e4SLinus Torvalds  * flags to xfs_trans_mod_dquot to indicate which field needs to be
2311da177e4SLinus Torvalds  * modified.
2321da177e4SLinus Torvalds  */
2331da177e4SLinus Torvalds #define XFS_QMOPT_RES_REGBLKS	0x0010000
2341da177e4SLinus Torvalds #define XFS_QMOPT_RES_RTBLKS	0x0020000
2351da177e4SLinus Torvalds #define XFS_QMOPT_BCOUNT	0x0040000
2361da177e4SLinus Torvalds #define XFS_QMOPT_ICOUNT	0x0080000
2371da177e4SLinus Torvalds #define XFS_QMOPT_RTBCOUNT	0x0100000
2381da177e4SLinus Torvalds #define XFS_QMOPT_DELBCOUNT	0x0200000
2391da177e4SLinus Torvalds #define XFS_QMOPT_DELRTBCOUNT	0x0400000
2401da177e4SLinus Torvalds #define XFS_QMOPT_RES_INOS	0x0800000
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds /*
2431da177e4SLinus Torvalds  * flags for dqalloc.
2441da177e4SLinus Torvalds  */
24520026d92SDave Chinner #define XFS_QMOPT_INHERIT	0x1000000
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds /*
2481da177e4SLinus Torvalds  * flags to xfs_trans_mod_dquot.
2491da177e4SLinus Torvalds  */
2501da177e4SLinus Torvalds #define XFS_TRANS_DQ_RES_BLKS	XFS_QMOPT_RES_REGBLKS
2511da177e4SLinus Torvalds #define XFS_TRANS_DQ_RES_RTBLKS	XFS_QMOPT_RES_RTBLKS
2521da177e4SLinus Torvalds #define XFS_TRANS_DQ_RES_INOS	XFS_QMOPT_RES_INOS
2531da177e4SLinus Torvalds #define XFS_TRANS_DQ_BCOUNT	XFS_QMOPT_BCOUNT
2541da177e4SLinus Torvalds #define XFS_TRANS_DQ_DELBCOUNT	XFS_QMOPT_DELBCOUNT
2551da177e4SLinus Torvalds #define XFS_TRANS_DQ_ICOUNT	XFS_QMOPT_ICOUNT
2561da177e4SLinus Torvalds #define XFS_TRANS_DQ_RTBCOUNT	XFS_QMOPT_RTBCOUNT
2571da177e4SLinus Torvalds #define XFS_TRANS_DQ_DELRTBCOUNT XFS_QMOPT_DELRTBCOUNT
2581da177e4SLinus Torvalds 
2591da177e4SLinus Torvalds 
260c8ad20ffSNathan Scott #define XFS_QMOPT_QUOTALL	\
261c8ad20ffSNathan Scott 		(XFS_QMOPT_UQUOTA | XFS_QMOPT_PQUOTA | XFS_QMOPT_GQUOTA)
2621da177e4SLinus Torvalds #define XFS_QMOPT_RESBLK_MASK	(XFS_QMOPT_RES_REGBLKS | XFS_QMOPT_RES_RTBLKS)
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds #ifdef __KERNEL__
2651da177e4SLinus Torvalds /*
2661da177e4SLinus Torvalds  * This check is done typically without holding the inode lock;
267c41564b5SNathan Scott  * that may seem racy, but it is harmless in the context that it is used.
2681da177e4SLinus Torvalds  * The inode cannot go inactive as long a reference is kept, and
2691da177e4SLinus Torvalds  * therefore if dquot(s) were attached, they'll stay consistent.
2701da177e4SLinus Torvalds  * If, for example, the ownership of the inode changes while
2711da177e4SLinus Torvalds  * we didn't have the inode locked, the appropriate dquot(s) will be
2721da177e4SLinus Torvalds  * attached atomically.
2731da177e4SLinus Torvalds  */
2741da177e4SLinus Torvalds #define XFS_NOT_DQATTACHED(mp, ip) ((XFS_IS_UQUOTA_ON(mp) &&\
2751da177e4SLinus Torvalds 				     (ip)->i_udquot == NULL) || \
276c8ad20ffSNathan Scott 				    (XFS_IS_OQUOTA_ON(mp) && \
2771da177e4SLinus Torvalds 				     (ip)->i_gdquot == NULL))
2781da177e4SLinus Torvalds 
279c8ad20ffSNathan Scott #define XFS_QM_NEED_QUOTACHECK(mp) \
280c8ad20ffSNathan Scott 	((XFS_IS_UQUOTA_ON(mp) && \
281c8ad20ffSNathan Scott 		(mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
2821da177e4SLinus Torvalds 	 (XFS_IS_GQUOTA_ON(mp) && \
283*83e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
284c8ad20ffSNathan Scott 	 (XFS_IS_PQUOTA_ON(mp) && \
285*83e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
286c8ad20ffSNathan Scott 
287c8ad20ffSNathan Scott #define XFS_MOUNT_QUOTA_SET1	(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
288*83e782e1SChandra Seetharaman 				 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
289*83e782e1SChandra Seetharaman 				 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD)
290c8ad20ffSNathan Scott 
291c8ad20ffSNathan Scott #define XFS_MOUNT_QUOTA_SET2	(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
292*83e782e1SChandra Seetharaman 				 XFS_UQUOTA_CHKD|XFS_PQUOTA_ACCT|\
293*83e782e1SChandra Seetharaman 				 XFS_PQUOTA_ENFD|XFS_PQUOTA_CHKD)
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds #define XFS_MOUNT_QUOTA_ALL	(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
296*83e782e1SChandra Seetharaman 				 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
297*83e782e1SChandra Seetharaman 				 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
298*83e782e1SChandra Seetharaman 				 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
299*83e782e1SChandra Seetharaman 				 XFS_PQUOTA_CHKD)
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds /*
3031da177e4SLinus Torvalds  * The structure kept inside the xfs_trans_t keep track of dquot changes
3041da177e4SLinus Torvalds  * within a transaction and apply them later.
3051da177e4SLinus Torvalds  */
3061da177e4SLinus Torvalds typedef struct xfs_dqtrx {
3071da177e4SLinus Torvalds 	struct xfs_dquot *qt_dquot;	  /* the dquot this refers to */
3081da177e4SLinus Torvalds 	ulong		qt_blk_res;	  /* blks reserved on a dquot */
3091da177e4SLinus Torvalds 	ulong		qt_blk_res_used;  /* blks used from the reservation */
3101da177e4SLinus Torvalds 	ulong		qt_ino_res;	  /* inode reserved on a dquot */
3111da177e4SLinus Torvalds 	ulong		qt_ino_res_used;  /* inodes used from the reservation */
3121da177e4SLinus Torvalds 	long		qt_bcount_delta;  /* dquot blk count changes */
3131da177e4SLinus Torvalds 	long		qt_delbcnt_delta; /* delayed dquot blk count changes */
3141da177e4SLinus Torvalds 	long		qt_icount_delta;  /* dquot inode count changes */
3151da177e4SLinus Torvalds 	ulong		qt_rtblk_res;	  /* # blks reserved on a dquot */
3161da177e4SLinus Torvalds 	ulong		qt_rtblk_res_used;/* # blks used from reservation */
3171da177e4SLinus Torvalds 	long		qt_rtbcount_delta;/* dquot realtime blk changes */
3181da177e4SLinus Torvalds 	long		qt_delrtb_delta;  /* delayed RT blk count changes */
3191da177e4SLinus Torvalds } xfs_dqtrx_t;
3201da177e4SLinus Torvalds 
3217d095257SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA
3227d095257SChristoph Hellwig extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
3237d095257SChristoph Hellwig extern void xfs_trans_free_dqinfo(struct xfs_trans *);
3247d095257SChristoph Hellwig extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
3257d095257SChristoph Hellwig 		uint, long);
3267d095257SChristoph Hellwig extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
3277d095257SChristoph Hellwig extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
3287d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
3291da177e4SLinus Torvalds 		struct xfs_inode *, long, long, uint);
3307d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
3317d095257SChristoph Hellwig 		struct xfs_mount *, struct xfs_dquot *,
3327d095257SChristoph Hellwig 		struct xfs_dquot *, long, long, uint);
3331da177e4SLinus Torvalds 
3347d095257SChristoph Hellwig extern int xfs_qm_vop_dqalloc(struct xfs_inode *, uid_t, gid_t, prid_t, uint,
3357d095257SChristoph Hellwig 		struct xfs_dquot **, struct xfs_dquot **);
3367d095257SChristoph Hellwig extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
3377d095257SChristoph Hellwig 		struct xfs_dquot *, struct xfs_dquot *);
3387d095257SChristoph Hellwig extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
3397d095257SChristoph Hellwig extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
3407d095257SChristoph Hellwig 		struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
3417d095257SChristoph Hellwig extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
3427d095257SChristoph Hellwig 		struct xfs_dquot *, struct xfs_dquot *, uint);
3437d095257SChristoph Hellwig extern int xfs_qm_dqattach(struct xfs_inode *, uint);
3447d095257SChristoph Hellwig extern int xfs_qm_dqattach_locked(struct xfs_inode *, uint);
3457d095257SChristoph Hellwig extern void xfs_qm_dqdetach(struct xfs_inode *);
3467d095257SChristoph Hellwig extern void xfs_qm_dqrele(struct xfs_dquot *);
3477d095257SChristoph Hellwig extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
3487d095257SChristoph Hellwig extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
3497d095257SChristoph Hellwig extern void xfs_qm_mount_quotas(struct xfs_mount *);
3507d095257SChristoph Hellwig extern void xfs_qm_unmount(struct xfs_mount *);
3517d095257SChristoph Hellwig extern void xfs_qm_unmount_quotas(struct xfs_mount *);
3521da177e4SLinus Torvalds 
3537d095257SChristoph Hellwig #else
354493b87e5SChristoph Hellwig static inline int
355493b87e5SChristoph Hellwig xfs_qm_vop_dqalloc(struct xfs_inode *ip, uid_t uid, gid_t gid, prid_t prid,
356493b87e5SChristoph Hellwig 		uint flags, struct xfs_dquot **udqp, struct xfs_dquot **gdqp)
357493b87e5SChristoph Hellwig {
358493b87e5SChristoph Hellwig 	*udqp = NULL;
359493b87e5SChristoph Hellwig 	*gdqp = NULL;
360493b87e5SChristoph Hellwig 	return 0;
361493b87e5SChristoph Hellwig }
3627d095257SChristoph Hellwig #define xfs_trans_dup_dqinfo(tp, tp2)
3637d095257SChristoph Hellwig #define xfs_trans_free_dqinfo(tp)
3647d095257SChristoph Hellwig #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
3657d095257SChristoph Hellwig #define xfs_trans_apply_dquot_deltas(tp)
3667d095257SChristoph Hellwig #define xfs_trans_unreserve_and_mod_dquots(tp)
3675d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
3685d2bf8a5SChristoph Hellwig 		struct xfs_inode *ip, long nblks, long ninos, uint flags)
3695d2bf8a5SChristoph Hellwig {
3705d2bf8a5SChristoph Hellwig 	return 0;
3715d2bf8a5SChristoph Hellwig }
3725d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
3735d2bf8a5SChristoph Hellwig 		struct xfs_mount *mp, struct xfs_dquot *udqp,
3745d2bf8a5SChristoph Hellwig 		struct xfs_dquot *gdqp, long nblks, long nions, uint flags)
3755d2bf8a5SChristoph Hellwig {
3765d2bf8a5SChristoph Hellwig 	return 0;
3775d2bf8a5SChristoph Hellwig }
3787d095257SChristoph Hellwig #define xfs_qm_vop_create_dqattach(tp, ip, u, g)
3797d095257SChristoph Hellwig #define xfs_qm_vop_rename_dqattach(it)					(0)
3807d095257SChristoph Hellwig #define xfs_qm_vop_chown(tp, ip, old, new)				(NULL)
3817d095257SChristoph Hellwig #define xfs_qm_vop_chown_reserve(tp, ip, u, g, fl)			(0)
3827d095257SChristoph Hellwig #define xfs_qm_dqattach(ip, fl)						(0)
3837d095257SChristoph Hellwig #define xfs_qm_dqattach_locked(ip, fl)					(0)
3847d095257SChristoph Hellwig #define xfs_qm_dqdetach(ip)
3857d095257SChristoph Hellwig #define xfs_qm_dqrele(d)
3867d095257SChristoph Hellwig #define xfs_qm_statvfs(ip, s)
3877d095257SChristoph Hellwig #define xfs_qm_newmount(mp, a, b)					(0)
3887d095257SChristoph Hellwig #define xfs_qm_mount_quotas(mp)
3897d095257SChristoph Hellwig #define xfs_qm_unmount(mp)
3905d2bf8a5SChristoph Hellwig #define xfs_qm_unmount_quotas(mp)
3917d095257SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */
3921da177e4SLinus Torvalds 
3937d095257SChristoph Hellwig #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
3947d095257SChristoph Hellwig 	xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
3957d095257SChristoph Hellwig #define xfs_trans_reserve_quota(tp, mp, ud, gd, nb, ni, f) \
3967d095257SChristoph Hellwig 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, nb, ni, \
3971da177e4SLinus Torvalds 				f | XFS_QMOPT_RES_REGBLKS)
3981da177e4SLinus Torvalds 
399a0fa2b67SDave Chinner extern int xfs_qm_dqcheck(struct xfs_mount *, xfs_disk_dquot_t *,
400a0fa2b67SDave Chinner 				xfs_dqid_t, uint, uint, char *);
4014cd4a034STim Shimmin extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
4021da177e4SLinus Torvalds 
4033fe58f30SChristoph Hellwig extern const struct xfs_buf_ops xfs_dquot_buf_ops;
4043fe58f30SChristoph Hellwig 
4051da177e4SLinus Torvalds #endif	/* __KERNEL__ */
4061da177e4SLinus Torvalds #endif	/* __XFS_QUOTA_H__ */
407