Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
0005  */
0006 #ifndef __XFS_QUOTA_H__
0007 #define __XFS_QUOTA_H__
0008 
0009 #include "xfs_quota_defs.h"
0010 
0011 /*
0012  * Kernel only quota definitions and functions
0013  */
0014 
0015 struct xfs_trans;
0016 struct xfs_buf;
0017 
0018 /*
0019  * This check is done typically without holding the inode lock;
0020  * that may seem racy, but it is harmless in the context that it is used.
0021  * The inode cannot go inactive as long a reference is kept, and
0022  * therefore if dquot(s) were attached, they'll stay consistent.
0023  * If, for example, the ownership of the inode changes while
0024  * we didn't have the inode locked, the appropriate dquot(s) will be
0025  * attached atomically.
0026  */
0027 #define XFS_NOT_DQATTACHED(mp, ip) \
0028     ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \
0029      (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \
0030      (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL))
0031 
0032 #define XFS_QM_NEED_QUOTACHECK(mp) \
0033     ((XFS_IS_UQUOTA_ON(mp) && \
0034         (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \
0035      (XFS_IS_GQUOTA_ON(mp) && \
0036         (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \
0037      (XFS_IS_PQUOTA_ON(mp) && \
0038         (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0))
0039 
0040 static inline uint
0041 xfs_quota_chkd_flag(
0042     xfs_dqtype_t        type)
0043 {
0044     switch (type) {
0045     case XFS_DQTYPE_USER:
0046         return XFS_UQUOTA_CHKD;
0047     case XFS_DQTYPE_GROUP:
0048         return XFS_GQUOTA_CHKD;
0049     case XFS_DQTYPE_PROJ:
0050         return XFS_PQUOTA_CHKD;
0051     default:
0052         return 0;
0053     }
0054 }
0055 
0056 /*
0057  * The structure kept inside the xfs_trans_t keep track of dquot changes
0058  * within a transaction and apply them later.
0059  */
0060 struct xfs_dqtrx {
0061     struct xfs_dquot *qt_dquot;   /* the dquot this refers to */
0062 
0063     uint64_t    qt_blk_res;   /* blks reserved on a dquot */
0064     int64_t     qt_bcount_delta;  /* dquot blk count changes */
0065     int64_t     qt_delbcnt_delta; /* delayed dquot blk count changes */
0066 
0067     uint64_t    qt_rtblk_res;     /* # blks reserved on a dquot */
0068     uint64_t    qt_rtblk_res_used;/* # blks used from reservation */
0069     int64_t     qt_rtbcount_delta;/* dquot realtime blk changes */
0070     int64_t     qt_delrtb_delta;  /* delayed RT blk count changes */
0071 
0072     uint64_t    qt_ino_res;   /* inode reserved on a dquot */
0073     uint64_t    qt_ino_res_used;  /* inodes used from the reservation */
0074     int64_t     qt_icount_delta;  /* dquot inode count changes */
0075 };
0076 
0077 #ifdef CONFIG_XFS_QUOTA
0078 extern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *);
0079 extern void xfs_trans_free_dqinfo(struct xfs_trans *);
0080 extern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *,
0081         uint, int64_t);
0082 extern void xfs_trans_apply_dquot_deltas(struct xfs_trans *);
0083 extern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *);
0084 int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip,
0085         int64_t dblocks, int64_t rblocks, bool force);
0086 extern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *,
0087         struct xfs_mount *, struct xfs_dquot *,
0088         struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint);
0089 int xfs_trans_reserve_quota_icreate(struct xfs_trans *tp,
0090         struct xfs_dquot *udqp, struct xfs_dquot *gdqp,
0091         struct xfs_dquot *pdqp, int64_t dblocks);
0092 
0093 extern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t,
0094         prid_t, uint, struct xfs_dquot **, struct xfs_dquot **,
0095         struct xfs_dquot **);
0096 extern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *,
0097         struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *);
0098 extern int xfs_qm_vop_rename_dqattach(struct xfs_inode **);
0099 extern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *,
0100         struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *);
0101 extern int xfs_qm_dqattach(struct xfs_inode *);
0102 extern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc);
0103 extern void xfs_qm_dqdetach(struct xfs_inode *);
0104 extern void xfs_qm_dqrele(struct xfs_dquot *);
0105 extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *);
0106 extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *);
0107 extern void xfs_qm_mount_quotas(struct xfs_mount *);
0108 extern void xfs_qm_unmount(struct xfs_mount *);
0109 extern void xfs_qm_unmount_quotas(struct xfs_mount *);
0110 
0111 static inline int
0112 xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks)
0113 {
0114     return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false);
0115 }
0116 bool xfs_inode_near_dquot_enforcement(struct xfs_inode *ip, xfs_dqtype_t type);
0117 #else
0118 static inline int
0119 xfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid,
0120         prid_t prid, uint flags, struct xfs_dquot **udqp,
0121         struct xfs_dquot **gdqp, struct xfs_dquot **pdqp)
0122 {
0123     *udqp = NULL;
0124     *gdqp = NULL;
0125     *pdqp = NULL;
0126     return 0;
0127 }
0128 #define xfs_trans_dup_dqinfo(tp, tp2)
0129 #define xfs_trans_free_dqinfo(tp)
0130 #define xfs_trans_mod_dquot_byino(tp, ip, fields, delta) do { } while (0)
0131 #define xfs_trans_apply_dquot_deltas(tp)
0132 #define xfs_trans_unreserve_and_mod_dquots(tp)
0133 static inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp,
0134         struct xfs_inode *ip, int64_t dblocks, int64_t rblocks,
0135         bool force)
0136 {
0137     return 0;
0138 }
0139 static inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp,
0140         struct xfs_mount *mp, struct xfs_dquot *udqp,
0141         struct xfs_dquot *gdqp, struct xfs_dquot *pdqp,
0142         int64_t nblks, long nions, uint flags)
0143 {
0144     return 0;
0145 }
0146 
0147 static inline int
0148 xfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks)
0149 {
0150     return 0;
0151 }
0152 
0153 static inline int
0154 xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,
0155         struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, int64_t dblocks)
0156 {
0157     return 0;
0158 }
0159 
0160 #define xfs_qm_vop_create_dqattach(tp, ip, u, g, p)
0161 #define xfs_qm_vop_rename_dqattach(it)                  (0)
0162 #define xfs_qm_vop_chown(tp, ip, old, new)              (NULL)
0163 #define xfs_qm_dqattach(ip)                     (0)
0164 #define xfs_qm_dqattach_locked(ip, fl)                  (0)
0165 #define xfs_qm_dqdetach(ip)
0166 #define xfs_qm_dqrele(d)            do { (d) = (d); } while(0)
0167 #define xfs_qm_statvfs(ip, s)           do { } while(0)
0168 #define xfs_qm_newmount(mp, a, b)                   (0)
0169 #define xfs_qm_mount_quotas(mp)
0170 #define xfs_qm_unmount(mp)
0171 #define xfs_qm_unmount_quotas(mp)
0172 #define xfs_inode_near_dquot_enforcement(ip, type)          (false)
0173 #endif /* CONFIG_XFS_QUOTA */
0174 
0175 static inline int
0176 xfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t blocks)
0177 {
0178     return xfs_quota_reserve_blkres(ip, -blocks);
0179 }
0180 
0181 extern int xfs_mount_reset_sbqflags(struct xfs_mount *);
0182 
0183 #endif  /* __XFS_QUOTA_H__ */