xref: /linux/fs/xfs/xfs_quota.h (revision 7aab1b28879d2280c9a0e50000e4ae153cfac55a)
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 
2176456fc2SDave Chinner #include "xfs_quota_defs.h"
2276456fc2SDave Chinner 
2376456fc2SDave Chinner /*
2476456fc2SDave Chinner  * Kernel only quota definitions and functions
2576456fc2SDave Chinner  */
2676456fc2SDave Chinner 
27fcafb71bSChristoph Hellwig struct xfs_trans;
28fcafb71bSChristoph Hellwig 
291da177e4SLinus Torvalds /*
301da177e4SLinus Torvalds  * This check is done typically without holding the inode lock;
31c41564b5SNathan Scott  * that may seem racy, but it is harmless in the context that it is used.
321da177e4SLinus Torvalds  * The inode cannot go inactive as long a reference is kept, and
331da177e4SLinus Torvalds  * therefore if dquot(s) were attached, they'll stay consistent.
341da177e4SLinus Torvalds  * If, for example, the ownership of the inode changes while
351da177e4SLinus Torvalds  * we didn't have the inode locked, the appropriate dquot(s) will be
361da177e4SLinus Torvalds  * attached atomically.
371da177e4SLinus Torvalds  */
3892f8ff73SChandra Seetharaman #define XFS_NOT_DQATTACHED(mp, ip) \
3992f8ff73SChandra Seetharaman 	((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
4092f8ff73SChandra Seetharaman 	 (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
4192f8ff73SChandra Seetharaman 	 (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
421da177e4SLinus Torvalds 
43c8ad20ffSNathan Scott #define XFS_QM_NEED_QUOTACHECK(mp) \
44c8ad20ffSNathan Scott 	((XFS_IS_UQUOTA_ON(mp) && \
45c8ad20ffSNathan Scott 		(mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
461da177e4SLinus Torvalds 	 (XFS_IS_GQUOTA_ON(mp) && \
4783e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
48c8ad20ffSNathan Scott 	 (XFS_IS_PQUOTA_ON(mp) && \
4983e782e1SChandra Seetharaman 		(mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
50c8ad20ffSNathan Scott 
511da177e4SLinus Torvalds #define XFS_MOUNT_QUOTA_ALL	(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
5283e782e1SChandra Seetharaman 				 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
5383e782e1SChandra Seetharaman 				 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
5483e782e1SChandra Seetharaman 				 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
5583e782e1SChandra Seetharaman 				 XFS_PQUOTA_CHKD)
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds /*
591da177e4SLinus Torvalds  * The structure kept inside the xfs_trans_t keep track of dquot changes
601da177e4SLinus Torvalds  * within a transaction and apply them later.
611da177e4SLinus Torvalds  */
621da177e4SLinus Torvalds typedef struct xfs_dqtrx {
631da177e4SLinus Torvalds 	struct xfs_dquot *qt_dquot;	  /* the dquot this refers to */
641da177e4SLinus Torvalds 	ulong		qt_blk_res;	  /* blks reserved on a dquot */
651da177e4SLinus Torvalds 	ulong		qt_blk_res_used;  /* blks used from the reservation */
661da177e4SLinus Torvalds 	ulong		qt_ino_res;	  /* inode reserved on a dquot */
671da177e4SLinus Torvalds 	ulong		qt_ino_res_used;  /* inodes used from the reservation */
681da177e4SLinus Torvalds 	long		qt_bcount_delta;  /* dquot blk count changes */
691da177e4SLinus Torvalds 	long		qt_delbcnt_delta; /* delayed dquot blk count changes */
701da177e4SLinus Torvalds 	long		qt_icount_delta;  /* dquot inode count changes */
711da177e4SLinus Torvalds 	ulong		qt_rtblk_res;	  /* # blks reserved on a dquot */
721da177e4SLinus Torvalds 	ulong		qt_rtblk_res_used;/* # blks used from reservation */
731da177e4SLinus Torvalds 	long		qt_rtbcount_delta;/* dquot realtime blk changes */
741da177e4SLinus Torvalds 	long		qt_delrtb_delta;  /* delayed RT blk count changes */
751da177e4SLinus Torvalds } xfs_dqtrx_t;
761da177e4SLinus Torvalds 
777d095257SChristoph Hellwig #ifdef CONFIG_XFS_QUOTA
787d095257SChristoph Hellwig extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
797d095257SChristoph Hellwig extern void xfs_trans_free_dqinfo(struct xfs_trans *);
807d095257SChristoph Hellwig extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
817d095257SChristoph Hellwig 		uint, long);
827d095257SChristoph Hellwig extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
837d095257SChristoph Hellwig extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
847d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_nblks(struct xfs_trans *,
851da177e4SLinus Torvalds 		struct xfs_inode *, long, long, uint);
867d095257SChristoph Hellwig extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
877d095257SChristoph Hellwig 		struct xfs_mount *, struct xfs_dquot *,
8892f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *, long, long, uint);
891da177e4SLinus Torvalds 
90*7aab1b28SDwight Engen extern int xfs_qm_vop_dqalloc(struct xfs_inode *, xfs_dqid_t, xfs_dqid_t,
91*7aab1b28SDwight Engen 		prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
92*7aab1b28SDwight Engen 		struct xfs_dquot **);
937d095257SChristoph Hellwig extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
9492f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
957d095257SChristoph Hellwig extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
967d095257SChristoph Hellwig extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
977d095257SChristoph Hellwig 		struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
987d095257SChristoph Hellwig extern int xfs_qm_vop_chown_reserve(struct xfs_trans *, struct xfs_inode *,
9992f8ff73SChandra Seetharaman 		struct xfs_dquot *, struct xfs_dquot *,
10092f8ff73SChandra Seetharaman 		struct xfs_dquot *, uint);
1017d095257SChristoph Hellwig extern int xfs_qm_dqattach(struct xfs_inode *, uint);
1027d095257SChristoph Hellwig extern int xfs_qm_dqattach_locked(struct xfs_inode *, uint);
1037d095257SChristoph Hellwig extern void xfs_qm_dqdetach(struct xfs_inode *);
1047d095257SChristoph Hellwig extern void xfs_qm_dqrele(struct xfs_dquot *);
1057d095257SChristoph Hellwig extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
1067d095257SChristoph Hellwig extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
1077d095257SChristoph Hellwig extern void xfs_qm_mount_quotas(struct xfs_mount *);
1087d095257SChristoph Hellwig extern void xfs_qm_unmount(struct xfs_mount *);
1097d095257SChristoph Hellwig extern void xfs_qm_unmount_quotas(struct xfs_mount *);
1101da177e4SLinus Torvalds 
1117d095257SChristoph Hellwig #else
112493b87e5SChristoph Hellwig static inline int
113*7aab1b28SDwight Engen xfs_qm_vop_dqalloc(struct xfs_inode *ip, xfs_dqid_t uid, xfs_dqid_t gid,
114*7aab1b28SDwight Engen 		prid_t prid, uint flags, struct xfs_dquot **udqp,
115*7aab1b28SDwight Engen 		struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
116493b87e5SChristoph Hellwig {
117493b87e5SChristoph Hellwig 	*udqp = NULL;
118493b87e5SChristoph Hellwig 	*gdqp = NULL;
11992f8ff73SChandra Seetharaman 	*pdqp = NULL;
120493b87e5SChristoph Hellwig 	return 0;
121493b87e5SChristoph Hellwig }
1227d095257SChristoph Hellwig #define xfs_trans_dup_dqinfo(tp, tp2)
1237d095257SChristoph Hellwig #define xfs_trans_free_dqinfo(tp)
1247d095257SChristoph Hellwig #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta)
1257d095257SChristoph Hellwig #define xfs_trans_apply_dquot_deltas(tp)
1267d095257SChristoph Hellwig #define xfs_trans_unreserve_and_mod_dquots(tp)
1275d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
1285d2bf8a5SChristoph Hellwig 		struct xfs_inode *ip, long nblks, long ninos, uint flags)
1295d2bf8a5SChristoph Hellwig {
1305d2bf8a5SChristoph Hellwig 	return 0;
1315d2bf8a5SChristoph Hellwig }
1325d2bf8a5SChristoph Hellwig static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
1335d2bf8a5SChristoph Hellwig 		struct xfs_mount *mp, struct xfs_dquot *udqp,
13492f8ff73SChandra Seetharaman 		struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
13592f8ff73SChandra Seetharaman 		long nblks, long nions, uint flags)
1365d2bf8a5SChristoph Hellwig {
1375d2bf8a5SChristoph Hellwig 	return 0;
1385d2bf8a5SChristoph Hellwig }
13992f8ff73SChandra Seetharaman #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
1407d095257SChristoph Hellwig #define xfs_qm_vop_rename_dqattach(it)					(0)
1417d095257SChristoph Hellwig #define xfs_qm_vop_chown(tp, ip, old, new)				(NULL)
14292f8ff73SChandra Seetharaman #define xfs_qm_vop_chown_reserve(tp, ip, u, g, p, fl)			(0)
1437d095257SChristoph Hellwig #define xfs_qm_dqattach(ip, fl)						(0)
1447d095257SChristoph Hellwig #define xfs_qm_dqattach_locked(ip, fl)					(0)
1457d095257SChristoph Hellwig #define xfs_qm_dqdetach(ip)
1467d095257SChristoph Hellwig #define xfs_qm_dqrele(d)
1477d095257SChristoph Hellwig #define xfs_qm_statvfs(ip, s)
1487d095257SChristoph Hellwig #define xfs_qm_newmount(mp, a, b)					(0)
1497d095257SChristoph Hellwig #define xfs_qm_mount_quotas(mp)
1507d095257SChristoph Hellwig #define xfs_qm_unmount(mp)
1515d2bf8a5SChristoph Hellwig #define xfs_qm_unmount_quotas(mp)
1527d095257SChristoph Hellwig #endif /* CONFIG_XFS_QUOTA */
1531da177e4SLinus Torvalds 
1547d095257SChristoph Hellwig #define xfs_trans_unreserve_quota_nblks(tp, ip, nblks, ninos, flags) \
1557d095257SChristoph Hellwig 	xfs_trans_reserve_quota_nblks(tp, ip, -(nblks), -(ninos), flags)
15692f8ff73SChandra Seetharaman #define xfs_trans_reserve_quota(tp, mp, ud, gd, pd, nb, ni, f) \
15792f8ff73SChandra Seetharaman 	xfs_trans_reserve_quota_bydquots(tp, mp, ud, gd, pd, nb, ni, \
1581da177e4SLinus Torvalds 				f | XFS_QMOPT_RES_REGBLKS)
1591da177e4SLinus Torvalds 
160a0fa2b67SDave Chinner extern int xfs_qm_dqcheck(struct xfs_mount *, xfs_disk_dquot_t *,
161a0fa2b67SDave Chinner 				xfs_dqid_t, uint, uint, char *);
1624cd4a034STim Shimmin extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
1631da177e4SLinus Torvalds 
1643fe58f30SChristoph Hellwig extern const struct xfs_buf_ops xfs_dquot_buf_ops;
1653fe58f30SChristoph Hellwig 
1661da177e4SLinus Torvalds #endif	/* __XFS_QUOTA_H__ */
167