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_def_quota
*defq
;
29 error
= xfs_qm_qino_load(mp
, type
, &ip
);
31 tstate
->ino
= NULLFSINO
;
32 return error
!= -ENOENT
? error
: 0;
35 defq
= xfs_get_defquota(mp
->m_quotainfo
, type
);
37 tstate
->ino
= ip
->i_ino
;
38 tstate
->flags
|= QCI_SYSFILE
;
39 tstate
->blocks
= ip
->i_nblocks
;
40 tstate
->nextents
= ip
->i_df
.if_nextents
;
41 tstate
->spc_timelimit
= (u32
)defq
->blk
.time
;
42 tstate
->ino_timelimit
= (u32
)defq
->ino
.time
;
43 tstate
->rt_spc_timelimit
= (u32
)defq
->rtb
.time
;
44 tstate
->spc_warnlimit
= 0;
45 tstate
->ino_warnlimit
= 0;
46 tstate
->rt_spc_warnlimit
= 0;
53 * Return quota status information, such as enforcements, quota file inode
57 xfs_fs_get_quota_state(
58 struct super_block
*sb
,
59 struct qc_state
*state
)
61 struct xfs_mount
*mp
= XFS_M(sb
);
62 struct xfs_quotainfo
*q
= mp
->m_quotainfo
;
65 memset(state
, 0, sizeof(*state
));
66 if (!XFS_IS_QUOTA_ON(mp
))
68 state
->s_incoredqs
= q
->qi_dquots
;
69 if (XFS_IS_UQUOTA_ON(mp
))
70 state
->s_state
[USRQUOTA
].flags
|= QCI_ACCT_ENABLED
;
71 if (XFS_IS_UQUOTA_ENFORCED(mp
))
72 state
->s_state
[USRQUOTA
].flags
|= QCI_LIMITS_ENFORCED
;
73 if (XFS_IS_GQUOTA_ON(mp
))
74 state
->s_state
[GRPQUOTA
].flags
|= QCI_ACCT_ENABLED
;
75 if (XFS_IS_GQUOTA_ENFORCED(mp
))
76 state
->s_state
[GRPQUOTA
].flags
|= QCI_LIMITS_ENFORCED
;
77 if (XFS_IS_PQUOTA_ON(mp
))
78 state
->s_state
[PRJQUOTA
].flags
|= QCI_ACCT_ENABLED
;
79 if (XFS_IS_PQUOTA_ENFORCED(mp
))
80 state
->s_state
[PRJQUOTA
].flags
|= QCI_LIMITS_ENFORCED
;
82 error
= xfs_qm_fill_state(&state
->s_state
[USRQUOTA
], mp
,
86 error
= xfs_qm_fill_state(&state
->s_state
[GRPQUOTA
], mp
,
90 error
= xfs_qm_fill_state(&state
->s_state
[PRJQUOTA
], mp
,
98 xfs_quota_type(int type
)
102 return XFS_DQTYPE_USER
;
104 return XFS_DQTYPE_GROUP
;
106 return XFS_DQTYPE_PROJ
;
110 #define XFS_QC_SETINFO_MASK (QC_TIMER_MASK)
113 * Adjust quota timers & warnings
117 struct super_block
*sb
,
119 struct qc_info
*info
)
121 struct xfs_mount
*mp
= XFS_M(sb
);
122 struct qc_dqblk newlim
;
126 if (!XFS_IS_QUOTA_ON(mp
))
128 if (info
->i_fieldmask
& ~XFS_QC_SETINFO_MASK
)
130 if ((info
->i_fieldmask
& XFS_QC_SETINFO_MASK
) == 0)
133 newlim
.d_fieldmask
= info
->i_fieldmask
;
134 newlim
.d_spc_timer
= info
->i_spc_timelimit
;
135 newlim
.d_ino_timer
= info
->i_ino_timelimit
;
136 newlim
.d_rt_spc_timer
= info
->i_rt_spc_timelimit
;
137 newlim
.d_ino_warns
= info
->i_ino_warnlimit
;
138 newlim
.d_spc_warns
= info
->i_spc_warnlimit
;
139 newlim
.d_rt_spc_warns
= info
->i_rt_spc_warnlimit
;
141 return xfs_qm_scall_setqlim(mp
, 0, xfs_quota_type(type
), &newlim
);
145 xfs_quota_flags(unsigned int uflags
)
147 unsigned int flags
= 0;
149 if (uflags
& FS_QUOTA_UDQ_ACCT
)
150 flags
|= XFS_UQUOTA_ACCT
;
151 if (uflags
& FS_QUOTA_PDQ_ACCT
)
152 flags
|= XFS_PQUOTA_ACCT
;
153 if (uflags
& FS_QUOTA_GDQ_ACCT
)
154 flags
|= XFS_GQUOTA_ACCT
;
155 if (uflags
& FS_QUOTA_UDQ_ENFD
)
156 flags
|= XFS_UQUOTA_ENFD
;
157 if (uflags
& FS_QUOTA_GDQ_ENFD
)
158 flags
|= XFS_GQUOTA_ENFD
;
159 if (uflags
& FS_QUOTA_PDQ_ENFD
)
160 flags
|= XFS_PQUOTA_ENFD
;
167 struct super_block
*sb
,
170 struct xfs_mount
*mp
= XFS_M(sb
);
174 if (!XFS_IS_QUOTA_ON(mp
))
177 return xfs_qm_scall_quotaon(mp
, xfs_quota_flags(uflags
));
182 struct super_block
*sb
,
185 struct xfs_mount
*mp
= XFS_M(sb
);
189 if (!XFS_IS_QUOTA_ON(mp
))
192 return xfs_qm_scall_quotaoff(mp
, xfs_quota_flags(uflags
));
197 struct super_block
*sb
,
200 struct xfs_mount
*mp
= XFS_M(sb
);
201 unsigned int flags
= 0;
206 if (XFS_IS_QUOTA_ON(mp
))
209 if (uflags
& ~(FS_USER_QUOTA
| FS_GROUP_QUOTA
| FS_PROJ_QUOTA
))
212 if (uflags
& FS_USER_QUOTA
)
213 flags
|= XFS_QMOPT_UQUOTA
;
214 if (uflags
& FS_GROUP_QUOTA
)
215 flags
|= XFS_QMOPT_GQUOTA
;
216 if (uflags
& FS_PROJ_QUOTA
)
217 flags
|= XFS_QMOPT_PQUOTA
;
219 return xfs_qm_scall_trunc_qfiles(mp
, flags
);
224 struct super_block
*sb
,
226 struct qc_dqblk
*qdq
)
228 struct xfs_mount
*mp
= XFS_M(sb
);
231 if (!XFS_IS_QUOTA_ON(mp
))
234 id
= from_kqid(&init_user_ns
, qid
);
235 return xfs_qm_scall_getquota(mp
, id
, xfs_quota_type(qid
.type
), qdq
);
238 /* Return quota info for active quota >= this qid */
240 xfs_fs_get_nextdqblk(
241 struct super_block
*sb
,
243 struct qc_dqblk
*qdq
)
246 struct xfs_mount
*mp
= XFS_M(sb
);
249 if (!XFS_IS_QUOTA_ON(mp
))
252 id
= from_kqid(&init_user_ns
, *qid
);
253 ret
= xfs_qm_scall_getquota_next(mp
, &id
, xfs_quota_type(qid
->type
),
258 /* ID may be different, so convert back what we got */
259 *qid
= make_kqid(current_user_ns(), qid
->type
, id
);
265 struct super_block
*sb
,
267 struct qc_dqblk
*qdq
)
269 struct xfs_mount
*mp
= XFS_M(sb
);
273 if (!XFS_IS_QUOTA_ON(mp
))
276 return xfs_qm_scall_setqlim(mp
, from_kqid(&init_user_ns
, qid
),
277 xfs_quota_type(qid
.type
), qdq
);
280 const struct quotactl_ops xfs_quotactl_operations
= {
281 .get_state
= xfs_fs_get_quota_state
,
282 .set_info
= xfs_fs_set_info
,
283 .quota_enable
= xfs_quota_enable
,
284 .quota_disable
= xfs_quota_disable
,
285 .rm_xquota
= xfs_fs_rm_xquota
,
286 .get_dqblk
= xfs_fs_get_dqblk
,
287 .get_nextdqblk
= xfs_fs_get_nextdqblk
,
288 .set_dqblk
= xfs_fs_set_dqblk
,