1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2008, Christoph Hellwig
7 #include "xfs_shared.h"
8 #include "xfs_format.h"
9 #include "xfs_log_format.h"
10 #include "xfs_trans_resv.h"
11 #include "xfs_mount.h"
12 #include "xfs_inode.h"
13 #include "xfs_quota.h"
14 #include "xfs_trans.h"
15 #include "xfs_icache.h"
21 struct qc_type_state *tstate,
26 struct xfs_quotainfo *q = mp->m_quotainfo;
30 if (!ip && ino == NULLFSINO)
33 if (xfs_iget(mp, NULL, ino, 0, 0, &ip))
37 tstate->flags |= QCI_SYSFILE;
38 tstate->blocks = ip->i_d.di_nblocks;
39 tstate->nextents = ip->i_d.di_nextents;
40 tstate->spc_timelimit = q->qi_btimelimit;
41 tstate->ino_timelimit = q->qi_itimelimit;
42 tstate->rt_spc_timelimit = q->qi_rtbtimelimit;
43 tstate->spc_warnlimit = q->qi_bwarnlimit;
44 tstate->ino_warnlimit = q->qi_iwarnlimit;
45 tstate->rt_spc_warnlimit = q->qi_rtbwarnlimit;
51 * Return quota status information, such as enforcements, quota file inode
55 xfs_fs_get_quota_state(
56 struct super_block *sb,
57 struct qc_state *state)
59 struct xfs_mount *mp = XFS_M(sb);
60 struct xfs_quotainfo *q = mp->m_quotainfo;
62 memset(state, 0, sizeof(*state));
63 if (!XFS_IS_QUOTA_RUNNING(mp))
65 state->s_incoredqs = q->qi_dquots;
66 if (XFS_IS_UQUOTA_RUNNING(mp))
67 state->s_state[USRQUOTA].flags |= QCI_ACCT_ENABLED;
68 if (XFS_IS_UQUOTA_ENFORCED(mp))
69 state->s_state[USRQUOTA].flags |= QCI_LIMITS_ENFORCED;
70 if (XFS_IS_GQUOTA_RUNNING(mp))
71 state->s_state[GRPQUOTA].flags |= QCI_ACCT_ENABLED;
72 if (XFS_IS_GQUOTA_ENFORCED(mp))
73 state->s_state[GRPQUOTA].flags |= QCI_LIMITS_ENFORCED;
74 if (XFS_IS_PQUOTA_RUNNING(mp))
75 state->s_state[PRJQUOTA].flags |= QCI_ACCT_ENABLED;
76 if (XFS_IS_PQUOTA_ENFORCED(mp))
77 state->s_state[PRJQUOTA].flags |= QCI_LIMITS_ENFORCED;
79 xfs_qm_fill_state(&state->s_state[USRQUOTA], mp, q->qi_uquotaip,
80 mp->m_sb.sb_uquotino);
81 xfs_qm_fill_state(&state->s_state[GRPQUOTA], mp, q->qi_gquotaip,
82 mp->m_sb.sb_gquotino);
83 xfs_qm_fill_state(&state->s_state[PRJQUOTA], mp, q->qi_pquotaip,
84 mp->m_sb.sb_pquotino);
89 xfs_quota_type(int type)
101 #define XFS_QC_SETINFO_MASK (QC_TIMER_MASK | QC_WARNS_MASK)
104 * Adjust quota timers & warnings
108 struct super_block *sb,
110 struct qc_info *info)
112 struct xfs_mount *mp = XFS_M(sb);
113 struct qc_dqblk newlim;
117 if (!XFS_IS_QUOTA_RUNNING(mp))
119 if (!XFS_IS_QUOTA_ON(mp))
121 if (info->i_fieldmask & ~XFS_QC_SETINFO_MASK)
123 if ((info->i_fieldmask & XFS_QC_SETINFO_MASK) == 0)
126 newlim.d_fieldmask = info->i_fieldmask;
127 newlim.d_spc_timer = info->i_spc_timelimit;
128 newlim.d_ino_timer = info->i_ino_timelimit;
129 newlim.d_rt_spc_timer = info->i_rt_spc_timelimit;
130 newlim.d_ino_warns = info->i_ino_warnlimit;
131 newlim.d_spc_warns = info->i_spc_warnlimit;
132 newlim.d_rt_spc_warns = info->i_rt_spc_warnlimit;
134 return xfs_qm_scall_setqlim(mp, 0, xfs_quota_type(type), &newlim);
138 xfs_quota_flags(unsigned int uflags)
140 unsigned int flags = 0;
142 if (uflags & FS_QUOTA_UDQ_ACCT)
143 flags |= XFS_UQUOTA_ACCT;
144 if (uflags & FS_QUOTA_PDQ_ACCT)
145 flags |= XFS_PQUOTA_ACCT;
146 if (uflags & FS_QUOTA_GDQ_ACCT)
147 flags |= XFS_GQUOTA_ACCT;
148 if (uflags & FS_QUOTA_UDQ_ENFD)
149 flags |= XFS_UQUOTA_ENFD;
150 if (uflags & FS_QUOTA_GDQ_ENFD)
151 flags |= XFS_GQUOTA_ENFD;
152 if (uflags & FS_QUOTA_PDQ_ENFD)
153 flags |= XFS_PQUOTA_ENFD;
160 struct super_block *sb,
163 struct xfs_mount *mp = XFS_M(sb);
167 if (!XFS_IS_QUOTA_RUNNING(mp))
170 return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags));
175 struct super_block *sb,
178 struct xfs_mount *mp = XFS_M(sb);
182 if (!XFS_IS_QUOTA_RUNNING(mp))
184 if (!XFS_IS_QUOTA_ON(mp))
187 return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags));
192 struct super_block *sb,
195 struct xfs_mount *mp = XFS_M(sb);
196 unsigned int flags = 0;
201 if (XFS_IS_QUOTA_ON(mp))
204 if (uflags & FS_USER_QUOTA)
205 flags |= XFS_DQ_USER;
206 if (uflags & FS_GROUP_QUOTA)
207 flags |= XFS_DQ_GROUP;
208 if (uflags & FS_PROJ_QUOTA)
209 flags |= XFS_DQ_PROJ;
211 return xfs_qm_scall_trunc_qfiles(mp, flags);
216 struct super_block *sb,
218 struct qc_dqblk *qdq)
220 struct xfs_mount *mp = XFS_M(sb);
223 if (!XFS_IS_QUOTA_RUNNING(mp))
225 if (!XFS_IS_QUOTA_ON(mp))
228 id = from_kqid(&init_user_ns, qid);
229 return xfs_qm_scall_getquota(mp, id, xfs_quota_type(qid.type), qdq);
232 /* Return quota info for active quota >= this qid */
234 xfs_fs_get_nextdqblk(
235 struct super_block *sb,
237 struct qc_dqblk *qdq)
240 struct xfs_mount *mp = XFS_M(sb);
243 if (!XFS_IS_QUOTA_RUNNING(mp))
245 if (!XFS_IS_QUOTA_ON(mp))
248 id = from_kqid(&init_user_ns, *qid);
249 ret = xfs_qm_scall_getquota_next(mp, &id, xfs_quota_type(qid->type),
254 /* ID may be different, so convert back what we got */
255 *qid = make_kqid(current_user_ns(), qid->type, id);
261 struct super_block *sb,
263 struct qc_dqblk *qdq)
265 struct xfs_mount *mp = XFS_M(sb);
269 if (!XFS_IS_QUOTA_RUNNING(mp))
271 if (!XFS_IS_QUOTA_ON(mp))
274 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
275 xfs_quota_type(qid.type), qdq);
278 const struct quotactl_ops xfs_quotactl_operations = {
279 .get_state = xfs_fs_get_quota_state,
280 .set_info = xfs_fs_set_info,
281 .quota_enable = xfs_quota_enable,
282 .quota_disable = xfs_quota_disable,
283 .rm_xquota = xfs_fs_rm_xquota,
284 .get_dqblk = xfs_fs_get_dqblk,
285 .get_nextdqblk = xfs_fs_get_nextdqblk,
286 .set_dqblk = xfs_fs_set_dqblk,