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_QM_H__
0007 #define __XFS_QM_H__
0008 
0009 #include "xfs_dquot_item.h"
0010 #include "xfs_dquot.h"
0011 
0012 struct xfs_inode;
0013 
0014 extern struct kmem_cache    *xfs_dqtrx_cache;
0015 
0016 /*
0017  * Number of bmaps that we ask from bmapi when doing a quotacheck.
0018  * We make this restriction to keep the memory usage to a minimum.
0019  */
0020 #define XFS_DQITER_MAP_SIZE 10
0021 
0022 #define XFS_IS_DQUOT_UNINITIALIZED(dqp) ( \
0023     !dqp->q_blk.hardlimit && \
0024     !dqp->q_blk.softlimit && \
0025     !dqp->q_rtb.hardlimit && \
0026     !dqp->q_rtb.softlimit && \
0027     !dqp->q_ino.hardlimit && \
0028     !dqp->q_ino.softlimit && \
0029     !dqp->q_blk.count && \
0030     !dqp->q_rtb.count && \
0031     !dqp->q_ino.count)
0032 
0033 struct xfs_quota_limits {
0034     xfs_qcnt_t      hard;   /* default hard limit */
0035     xfs_qcnt_t      soft;   /* default soft limit */
0036     time64_t        time;   /* limit for timers */
0037 };
0038 
0039 /* Defaults for each quota type: time limits, warn limits, usage limits */
0040 struct xfs_def_quota {
0041     struct xfs_quota_limits blk;
0042     struct xfs_quota_limits ino;
0043     struct xfs_quota_limits rtb;
0044 };
0045 
0046 /*
0047  * Various quota information for individual filesystems.
0048  * The mount structure keeps a pointer to this.
0049  */
0050 struct xfs_quotainfo {
0051     struct radix_tree_root  qi_uquota_tree;
0052     struct radix_tree_root  qi_gquota_tree;
0053     struct radix_tree_root  qi_pquota_tree;
0054     struct mutex        qi_tree_lock;
0055     struct xfs_inode    *qi_uquotaip;   /* user quota inode */
0056     struct xfs_inode    *qi_gquotaip;   /* group quota inode */
0057     struct xfs_inode    *qi_pquotaip;   /* project quota inode */
0058     struct list_lru     qi_lru;
0059     int         qi_dquots;
0060     struct mutex        qi_quotaofflock;/* to serialize quotaoff */
0061     xfs_filblks_t       qi_dqchunklen;  /* # BBs in a chunk of dqs */
0062     uint            qi_dqperchunk;  /* # ondisk dq in above chunk */
0063     struct xfs_def_quota    qi_usr_default;
0064     struct xfs_def_quota    qi_grp_default;
0065     struct xfs_def_quota    qi_prj_default;
0066     struct shrinker     qi_shrinker;
0067 
0068     /* Minimum and maximum quota expiration timestamp values. */
0069     time64_t        qi_expiry_min;
0070     time64_t        qi_expiry_max;
0071 };
0072 
0073 static inline struct radix_tree_root *
0074 xfs_dquot_tree(
0075     struct xfs_quotainfo    *qi,
0076     xfs_dqtype_t        type)
0077 {
0078     switch (type) {
0079     case XFS_DQTYPE_USER:
0080         return &qi->qi_uquota_tree;
0081     case XFS_DQTYPE_GROUP:
0082         return &qi->qi_gquota_tree;
0083     case XFS_DQTYPE_PROJ:
0084         return &qi->qi_pquota_tree;
0085     default:
0086         ASSERT(0);
0087     }
0088     return NULL;
0089 }
0090 
0091 static inline struct xfs_inode *
0092 xfs_quota_inode(struct xfs_mount *mp, xfs_dqtype_t type)
0093 {
0094     switch (type) {
0095     case XFS_DQTYPE_USER:
0096         return mp->m_quotainfo->qi_uquotaip;
0097     case XFS_DQTYPE_GROUP:
0098         return mp->m_quotainfo->qi_gquotaip;
0099     case XFS_DQTYPE_PROJ:
0100         return mp->m_quotainfo->qi_pquotaip;
0101     default:
0102         ASSERT(0);
0103     }
0104     return NULL;
0105 }
0106 
0107 extern void xfs_trans_mod_dquot(struct xfs_trans *tp, struct xfs_dquot *dqp,
0108                     uint field, int64_t delta);
0109 extern void xfs_trans_dqjoin(struct xfs_trans *, struct xfs_dquot *);
0110 extern void xfs_trans_log_dquot(struct xfs_trans *, struct xfs_dquot *);
0111 
0112 /*
0113  * We keep the usr, grp, and prj dquots separately so that locking will be
0114  * easier to do at commit time. All transactions that we know of at this point
0115  * affect no more than two dquots of one type. Hence, the TRANS_MAXDQS value.
0116  */
0117 enum {
0118     XFS_QM_TRANS_USR = 0,
0119     XFS_QM_TRANS_GRP,
0120     XFS_QM_TRANS_PRJ,
0121     XFS_QM_TRANS_DQTYPES
0122 };
0123 #define XFS_QM_TRANS_MAXDQS     2
0124 struct xfs_dquot_acct {
0125     struct xfs_dqtrx    dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS];
0126 };
0127 
0128 /*
0129  * Users are allowed to have a usage exceeding their softlimit for
0130  * a period this long.
0131  */
0132 #define XFS_QM_BTIMELIMIT   (7 * 24*60*60)          /* 1 week */
0133 #define XFS_QM_RTBTIMELIMIT (7 * 24*60*60)          /* 1 week */
0134 #define XFS_QM_ITIMELIMIT   (7 * 24*60*60)          /* 1 week */
0135 
0136 extern void     xfs_qm_destroy_quotainfo(struct xfs_mount *);
0137 
0138 /* quota ops */
0139 extern int      xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
0140 extern int      xfs_qm_scall_getquota(struct xfs_mount *mp,
0141                     xfs_dqid_t id,
0142                     xfs_dqtype_t type,
0143                     struct qc_dqblk *dst);
0144 extern int      xfs_qm_scall_getquota_next(struct xfs_mount *mp,
0145                     xfs_dqid_t *id,
0146                     xfs_dqtype_t type,
0147                     struct qc_dqblk *dst);
0148 extern int      xfs_qm_scall_setqlim(struct xfs_mount *mp,
0149                     xfs_dqid_t id,
0150                     xfs_dqtype_t type,
0151                     struct qc_dqblk *newlim);
0152 extern int      xfs_qm_scall_quotaon(struct xfs_mount *, uint);
0153 extern int      xfs_qm_scall_quotaoff(struct xfs_mount *, uint);
0154 
0155 static inline struct xfs_def_quota *
0156 xfs_get_defquota(struct xfs_quotainfo *qi, xfs_dqtype_t type)
0157 {
0158     switch (type) {
0159     case XFS_DQTYPE_USER:
0160         return &qi->qi_usr_default;
0161     case XFS_DQTYPE_GROUP:
0162         return &qi->qi_grp_default;
0163     case XFS_DQTYPE_PROJ:
0164         return &qi->qi_prj_default;
0165     default:
0166         ASSERT(0);
0167         return NULL;
0168     }
0169 }
0170 
0171 #endif /* __XFS_QM_H__ */