Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
4ce3121f NS |
3 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
1da177e4 | 5 | */ |
16f7e0fe | 6 | |
16f7e0fe | 7 | |
1da177e4 LT |
8 | #include "xfs.h" |
9 | #include "xfs_fs.h" | |
70a9883c | 10 | #include "xfs_shared.h" |
239880ef DC |
11 | #include "xfs_format.h" |
12 | #include "xfs_log_format.h" | |
13 | #include "xfs_trans_resv.h" | |
1da177e4 | 14 | #include "xfs_sb.h" |
1da177e4 | 15 | #include "xfs_mount.h" |
1da177e4 | 16 | #include "xfs_inode.h" |
239880ef | 17 | #include "xfs_trans.h" |
a4fbe6ab | 18 | #include "xfs_quota.h" |
1da177e4 | 19 | #include "xfs_qm.h" |
6d8b79cf | 20 | #include "xfs_icache.h" |
1da177e4 | 21 | |
fcafb71b | 22 | int |
1da177e4 LT |
23 | xfs_qm_scall_quotaoff( |
24 | xfs_mount_t *mp, | |
fcafb71b | 25 | uint flags) |
1da177e4 | 26 | { |
1da177e4 LT |
27 | /* |
28 | * No file system can have quotas enabled on disk but not in core. | |
29 | * Note that quota utilities (like quotaoff) _expect_ | |
2451337d | 30 | * errno == -EEXIST here. |
1da177e4 LT |
31 | */ |
32 | if ((mp->m_qflags & flags) == 0) | |
2451337d | 33 | return -EEXIST; |
1da177e4 LT |
34 | |
35 | /* | |
40b52225 CH |
36 | * We do not support actually turning off quota accounting any more. |
37 | * Just log a warning and ignore the accounting related flags. | |
1da177e4 | 38 | */ |
40b52225 CH |
39 | if (flags & XFS_ALL_QUOTA_ACCT) |
40 | xfs_info(mp, "disabling of quota accounting not supported."); | |
1da177e4 | 41 | |
40b52225 CH |
42 | mutex_lock(&mp->m_quotainfo->qi_quotaofflock); |
43 | mp->m_qflags &= ~(flags & XFS_ALL_QUOTA_ENFD); | |
44 | spin_lock(&mp->m_sb_lock); | |
45 | mp->m_sb.sb_qflags = mp->m_qflags; | |
46 | spin_unlock(&mp->m_sb_lock); | |
47 | mutex_unlock(&mp->m_quotainfo->qi_quotaofflock); | |
1da177e4 | 48 | |
40b52225 CH |
49 | /* XXX what to do if error ? Revert back to old vals incore ? */ |
50 | return xfs_sync_sb(mp, false); | |
1da177e4 LT |
51 | } |
52 | ||
5d18898b CH |
53 | STATIC int |
54 | xfs_qm_scall_trunc_qfile( | |
55 | struct xfs_mount *mp, | |
56 | xfs_ino_t ino) | |
57 | { | |
58 | struct xfs_inode *ip; | |
59 | struct xfs_trans *tp; | |
60 | int error; | |
61 | ||
62 | if (ino == NULLFSINO) | |
63 | return 0; | |
64 | ||
65 | error = xfs_iget(mp, NULL, ino, 0, 0, &ip); | |
66 | if (error) | |
67 | return error; | |
68 | ||
69 | xfs_ilock(ip, XFS_IOLOCK_EXCL); | |
70 | ||
253f4911 | 71 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); |
5d18898b | 72 | if (error) { |
5d18898b CH |
73 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); |
74 | goto out_put; | |
75 | } | |
76 | ||
77 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
ddc3415a | 78 | xfs_trans_ijoin(tp, ip, 0); |
5d18898b | 79 | |
13d2c10b | 80 | ip->i_disk_size = 0; |
673e8e59 CH |
81 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
82 | ||
83 | error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, 0); | |
5d18898b | 84 | if (error) { |
4906e215 | 85 | xfs_trans_cancel(tp); |
5d18898b CH |
86 | goto out_unlock; |
87 | } | |
88 | ||
daf83964 | 89 | ASSERT(ip->i_df.if_nextents == 0); |
673e8e59 | 90 | |
dcd79a14 | 91 | xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); |
70393313 | 92 | error = xfs_trans_commit(tp); |
5d18898b CH |
93 | |
94 | out_unlock: | |
95 | xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); | |
96 | out_put: | |
44a8736b | 97 | xfs_irele(ip); |
5d18898b CH |
98 | return error; |
99 | } | |
100 | ||
fcafb71b | 101 | int |
1da177e4 LT |
102 | xfs_qm_scall_trunc_qfiles( |
103 | xfs_mount_t *mp, | |
104 | uint flags) | |
105 | { | |
2451337d | 106 | int error = -EINVAL; |
1da177e4 | 107 | |
38c26bfd | 108 | if (!xfs_has_quota(mp) || flags == 0 || |
41ed4a5f | 109 | (flags & ~XFS_QMOPT_QUOTALL)) { |
08e96e1a | 110 | xfs_debug(mp, "%s: flags=%x m_qflags=%x", |
8221112b | 111 | __func__, flags, mp->m_qflags); |
2451337d | 112 | return -EINVAL; |
1da177e4 LT |
113 | } |
114 | ||
41ed4a5f | 115 | if (flags & XFS_QMOPT_UQUOTA) { |
5d18898b | 116 | error = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_uquotino); |
c61a9e39 JL |
117 | if (error) |
118 | return error; | |
119 | } | |
41ed4a5f | 120 | if (flags & XFS_QMOPT_GQUOTA) { |
c61a9e39 JL |
121 | error = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_gquotino); |
122 | if (error) | |
123 | return error; | |
124 | } | |
41ed4a5f | 125 | if (flags & XFS_QMOPT_PQUOTA) |
c61a9e39 | 126 | error = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_pquotino); |
1da177e4 | 127 | |
c61a9e39 | 128 | return error; |
1da177e4 LT |
129 | } |
130 | ||
1da177e4 LT |
131 | /* |
132 | * Switch on (a given) quota enforcement for a filesystem. This takes | |
133 | * effect immediately. | |
134 | * (Switching on quota accounting must be done at mount time.) | |
135 | */ | |
fcafb71b | 136 | int |
1da177e4 LT |
137 | xfs_qm_scall_quotaon( |
138 | xfs_mount_t *mp, | |
139 | uint flags) | |
140 | { | |
141 | int error; | |
1da177e4 | 142 | uint qf; |
1da177e4 | 143 | |
1da177e4 | 144 | /* |
cd594559 KX |
145 | * Switching on quota accounting must be done at mount time, |
146 | * only consider quota enforcement stuff here. | |
1da177e4 | 147 | */ |
cd594559 | 148 | flags &= XFS_ALL_QUOTA_ENFD; |
1da177e4 | 149 | |
1da177e4 | 150 | if (flags == 0) { |
08e96e1a | 151 | xfs_debug(mp, "%s: zero flags, m_qflags=%x", |
8221112b | 152 | __func__, mp->m_qflags); |
2451337d | 153 | return -EINVAL; |
1da177e4 LT |
154 | } |
155 | ||
1da177e4 LT |
156 | /* |
157 | * Can't enforce without accounting. We check the superblock | |
158 | * qflags here instead of m_qflags because rootfs can have | |
159 | * quota acct on ondisk without m_qflags' knowing. | |
160 | */ | |
fbf64b3d | 161 | if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 && |
83e782e1 | 162 | (flags & XFS_UQUOTA_ENFD)) || |
fbf64b3d | 163 | ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 && |
83e782e1 | 164 | (flags & XFS_GQUOTA_ENFD)) || |
fbf64b3d | 165 | ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 && |
83e782e1 | 166 | (flags & XFS_PQUOTA_ENFD))) { |
8221112b | 167 | xfs_debug(mp, |
08e96e1a | 168 | "%s: Can't enforce without acct, flags=%x sbflags=%x", |
8221112b | 169 | __func__, flags, mp->m_sb.sb_qflags); |
2451337d | 170 | return -EINVAL; |
1da177e4 LT |
171 | } |
172 | /* | |
25985edc | 173 | * If everything's up to-date incore, then don't waste time. |
1da177e4 LT |
174 | */ |
175 | if ((mp->m_qflags & flags) == flags) | |
2451337d | 176 | return -EEXIST; |
1da177e4 LT |
177 | |
178 | /* | |
179 | * Change sb_qflags on disk but not incore mp->qflags | |
180 | * if this is the root filesystem. | |
181 | */ | |
3685c2a1 | 182 | spin_lock(&mp->m_sb_lock); |
1da177e4 LT |
183 | qf = mp->m_sb.sb_qflags; |
184 | mp->m_sb.sb_qflags = qf | flags; | |
3685c2a1 | 185 | spin_unlock(&mp->m_sb_lock); |
1da177e4 LT |
186 | |
187 | /* | |
188 | * There's nothing to change if it's the same. | |
189 | */ | |
4d11a402 | 190 | if ((qf & flags) == flags) |
2451337d | 191 | return -EEXIST; |
1da177e4 | 192 | |
61e63ecb DC |
193 | error = xfs_sync_sb(mp, false); |
194 | if (error) | |
d99831ff | 195 | return error; |
1da177e4 LT |
196 | /* |
197 | * If we aren't trying to switch on quota enforcement, we are done. | |
198 | */ | |
199 | if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) != | |
200 | (mp->m_qflags & XFS_UQUOTA_ACCT)) || | |
c8ad20ff NS |
201 | ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) != |
202 | (mp->m_qflags & XFS_PQUOTA_ACCT)) || | |
203 | ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) != | |
fbf64b3d | 204 | (mp->m_qflags & XFS_GQUOTA_ACCT))) |
d99831ff | 205 | return 0; |
1da177e4 | 206 | |
149e53af | 207 | if (!XFS_IS_QUOTA_ON(mp)) |
2451337d | 208 | return -ESRCH; |
1da177e4 LT |
209 | |
210 | /* | |
211 | * Switch on quota enforcement in core. | |
212 | */ | |
8a7b8a89 | 213 | mutex_lock(&mp->m_quotainfo->qi_quotaofflock); |
1da177e4 | 214 | mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD); |
8a7b8a89 | 215 | mutex_unlock(&mp->m_quotainfo->qi_quotaofflock); |
1da177e4 | 216 | |
d99831ff | 217 | return 0; |
1da177e4 LT |
218 | } |
219 | ||
14bf61ff JK |
220 | #define XFS_QC_MASK \ |
221 | (QC_LIMIT_MASK | QC_TIMER_MASK | QC_WARNS_MASK) | |
c472b432 | 222 | |
d1520dea DW |
223 | /* |
224 | * Adjust limits of this quota, and the defaults if passed in. Returns true | |
225 | * if the new limits made sense and were applied, false otherwise. | |
226 | */ | |
227 | static inline bool | |
228 | xfs_setqlim_limits( | |
229 | struct xfs_mount *mp, | |
230 | struct xfs_dquot_res *res, | |
231 | struct xfs_quota_limits *qlim, | |
232 | xfs_qcnt_t hard, | |
233 | xfs_qcnt_t soft, | |
234 | const char *tag) | |
235 | { | |
236 | /* The hard limit can't be less than the soft limit. */ | |
237 | if (hard != 0 && hard < soft) { | |
238 | xfs_debug(mp, "%shard %lld < %ssoft %lld", tag, hard, tag, | |
239 | soft); | |
240 | return false; | |
241 | } | |
242 | ||
243 | res->hardlimit = hard; | |
244 | res->softlimit = soft; | |
245 | if (qlim) { | |
246 | qlim->hard = hard; | |
247 | qlim->soft = soft; | |
248 | } | |
249 | ||
250 | return true; | |
251 | } | |
252 | ||
253 | static inline void | |
254 | xfs_setqlim_warns( | |
255 | struct xfs_dquot_res *res, | |
256 | struct xfs_quota_limits *qlim, | |
257 | int warns) | |
258 | { | |
259 | res->warnings = warns; | |
260 | if (qlim) | |
261 | qlim->warn = warns; | |
262 | } | |
263 | ||
264 | static inline void | |
265 | xfs_setqlim_timer( | |
11d8a919 | 266 | struct xfs_mount *mp, |
d1520dea DW |
267 | struct xfs_dquot_res *res, |
268 | struct xfs_quota_limits *qlim, | |
269 | s64 timer) | |
270 | { | |
11d8a919 DW |
271 | if (qlim) { |
272 | /* Set the length of the default grace period. */ | |
ccc8e771 DW |
273 | res->timer = xfs_dquot_set_grace_period(timer); |
274 | qlim->time = res->timer; | |
11d8a919 DW |
275 | } else { |
276 | /* Set the grace period expiration on a quota. */ | |
277 | res->timer = xfs_dquot_set_timeout(mp, timer); | |
278 | } | |
d1520dea DW |
279 | } |
280 | ||
1da177e4 LT |
281 | /* |
282 | * Adjust quota limits, and start/stop timers accordingly. | |
283 | */ | |
fcafb71b | 284 | int |
1da177e4 | 285 | xfs_qm_scall_setqlim( |
b1366451 | 286 | struct xfs_mount *mp, |
1da177e4 | 287 | xfs_dqid_t id, |
1a7ed271 | 288 | xfs_dqtype_t type, |
14bf61ff | 289 | struct qc_dqblk *newlim) |
1da177e4 | 290 | { |
8a7b8a89 | 291 | struct xfs_quotainfo *q = mp->m_quotainfo; |
b1366451 BF |
292 | struct xfs_dquot *dqp; |
293 | struct xfs_trans *tp; | |
be607946 | 294 | struct xfs_def_quota *defq; |
d1520dea DW |
295 | struct xfs_dquot_res *res; |
296 | struct xfs_quota_limits *qlim; | |
1da177e4 LT |
297 | int error; |
298 | xfs_qcnt_t hard, soft; | |
299 | ||
14bf61ff | 300 | if (newlim->d_fieldmask & ~XFS_QC_MASK) |
2451337d | 301 | return -EINVAL; |
14bf61ff | 302 | if ((newlim->d_fieldmask & XFS_QC_MASK) == 0) |
c472b432 | 303 | return 0; |
1da177e4 | 304 | |
1da177e4 LT |
305 | /* |
306 | * We don't want to race with a quotaoff so take the quotaoff lock. | |
f648167f DC |
307 | * We don't hold an inode lock, so there's nothing else to stop |
308 | * a quotaoff from happening. | |
1da177e4 | 309 | */ |
8a7b8a89 | 310 | mutex_lock(&q->qi_quotaofflock); |
1da177e4 LT |
311 | |
312 | /* | |
f648167f DC |
313 | * Get the dquot (locked) before we start, as we need to do a |
314 | * transaction to allocate it if it doesn't exist. Once we have the | |
315 | * dquot, unlock it so we can start the next transaction safely. We hold | |
316 | * a reference to the dquot, so it's safe to do this unlock/lock without | |
317 | * it being reclaimed in the mean time. | |
1da177e4 | 318 | */ |
30ab2dcf | 319 | error = xfs_qm_dqget(mp, id, type, true, &dqp); |
f648167f | 320 | if (error) { |
2451337d | 321 | ASSERT(error != -ENOENT); |
8a7b8a89 | 322 | goto out_unlock; |
1da177e4 | 323 | } |
be607946 | 324 | |
ce6e7e79 | 325 | defq = xfs_get_defquota(q, xfs_dquot_type(dqp)); |
f648167f DC |
326 | xfs_dqunlock(dqp); |
327 | ||
253f4911 CH |
328 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_setqlim, 0, 0, 0, &tp); |
329 | if (error) | |
f648167f | 330 | goto out_rele; |
f648167f DC |
331 | |
332 | xfs_dqlock(dqp); | |
1da177e4 | 333 | xfs_trans_dqjoin(tp, dqp); |
1da177e4 LT |
334 | |
335 | /* | |
d1520dea DW |
336 | * Update quota limits, warnings, and timers, and the defaults |
337 | * if we're touching id == 0. | |
338 | * | |
1da177e4 | 339 | * Make sure that hardlimits are >= soft limits before changing. |
d1520dea DW |
340 | * |
341 | * Update warnings counter(s) if requested. | |
342 | * | |
343 | * Timelimits for the super user set the relative time the other users | |
344 | * can be over quota for this file system. If it is zero a default is | |
345 | * used. Ditto for the default soft and hard limit values (already | |
346 | * done, above), and for warnings. | |
347 | * | |
348 | * For other IDs, userspace can bump out the grace period if over | |
349 | * the soft limit. | |
1da177e4 | 350 | */ |
d1520dea DW |
351 | |
352 | /* Blocks on the data device. */ | |
14bf61ff JK |
353 | hard = (newlim->d_fieldmask & QC_SPC_HARD) ? |
354 | (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_hardlimit) : | |
d3537cf9 | 355 | dqp->q_blk.hardlimit; |
14bf61ff JK |
356 | soft = (newlim->d_fieldmask & QC_SPC_SOFT) ? |
357 | (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_softlimit) : | |
d3537cf9 | 358 | dqp->q_blk.softlimit; |
d1520dea DW |
359 | res = &dqp->q_blk; |
360 | qlim = id == 0 ? &defq->blk : NULL; | |
361 | ||
362 | if (xfs_setqlim_limits(mp, res, qlim, hard, soft, "blk")) | |
b1366451 | 363 | xfs_dquot_set_prealloc_limits(dqp); |
d1520dea DW |
364 | if (newlim->d_fieldmask & QC_SPC_WARNS) |
365 | xfs_setqlim_warns(res, qlim, newlim->d_spc_warns); | |
366 | if (newlim->d_fieldmask & QC_SPC_TIMER) | |
11d8a919 | 367 | xfs_setqlim_timer(mp, res, qlim, newlim->d_spc_timer); |
d1520dea DW |
368 | |
369 | /* Blocks on the realtime device. */ | |
14bf61ff JK |
370 | hard = (newlim->d_fieldmask & QC_RT_SPC_HARD) ? |
371 | (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_hardlimit) : | |
d3537cf9 | 372 | dqp->q_rtb.hardlimit; |
14bf61ff JK |
373 | soft = (newlim->d_fieldmask & QC_RT_SPC_SOFT) ? |
374 | (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_softlimit) : | |
d3537cf9 | 375 | dqp->q_rtb.softlimit; |
d1520dea DW |
376 | res = &dqp->q_rtb; |
377 | qlim = id == 0 ? &defq->rtb : NULL; | |
378 | ||
379 | xfs_setqlim_limits(mp, res, qlim, hard, soft, "rtb"); | |
380 | if (newlim->d_fieldmask & QC_RT_SPC_WARNS) | |
381 | xfs_setqlim_warns(res, qlim, newlim->d_rt_spc_warns); | |
382 | if (newlim->d_fieldmask & QC_RT_SPC_TIMER) | |
11d8a919 | 383 | xfs_setqlim_timer(mp, res, qlim, newlim->d_rt_spc_timer); |
1da177e4 | 384 | |
d1520dea | 385 | /* Inodes */ |
14bf61ff | 386 | hard = (newlim->d_fieldmask & QC_INO_HARD) ? |
1da177e4 | 387 | (xfs_qcnt_t) newlim->d_ino_hardlimit : |
d3537cf9 | 388 | dqp->q_ino.hardlimit; |
14bf61ff | 389 | soft = (newlim->d_fieldmask & QC_INO_SOFT) ? |
1da177e4 | 390 | (xfs_qcnt_t) newlim->d_ino_softlimit : |
d3537cf9 | 391 | dqp->q_ino.softlimit; |
d1520dea DW |
392 | res = &dqp->q_ino; |
393 | qlim = id == 0 ? &defq->ino : NULL; | |
1da177e4 | 394 | |
d1520dea | 395 | xfs_setqlim_limits(mp, res, qlim, hard, soft, "ino"); |
14bf61ff | 396 | if (newlim->d_fieldmask & QC_INO_WARNS) |
d1520dea | 397 | xfs_setqlim_warns(res, qlim, newlim->d_ino_warns); |
df42ce64 | 398 | if (newlim->d_fieldmask & QC_INO_TIMER) |
11d8a919 | 399 | xfs_setqlim_timer(mp, res, qlim, newlim->d_ino_timer); |
df42ce64 ES |
400 | |
401 | if (id != 0) { | |
1da177e4 LT |
402 | /* |
403 | * If the user is now over quota, start the timelimit. | |
404 | * The user will not be 'warned'. | |
405 | * Note that we keep the timers ticking, whether enforcement | |
406 | * is on or off. We don't really want to bother with iterating | |
407 | * over all ondisk dquots and turning the timers on/off. | |
408 | */ | |
c8c753e1 | 409 | xfs_qm_adjust_dqtimers(dqp); |
1da177e4 | 410 | } |
985a78fd | 411 | dqp->q_flags |= XFS_DQFLAG_DIRTY; |
1da177e4 LT |
412 | xfs_trans_log_dquot(tp, dqp); |
413 | ||
70393313 | 414 | error = xfs_trans_commit(tp); |
1da177e4 | 415 | |
f648167f DC |
416 | out_rele: |
417 | xfs_qm_dqrele(dqp); | |
418 | out_unlock: | |
8a7b8a89 | 419 | mutex_unlock(&q->qi_quotaofflock); |
e5720eec | 420 | return error; |
1da177e4 LT |
421 | } |
422 | ||
2e330e76 DW |
423 | /* Fill out the quota context. */ |
424 | static void | |
425 | xfs_qm_scall_getquota_fill_qc( | |
18535a7e | 426 | struct xfs_mount *mp, |
1a7ed271 | 427 | xfs_dqtype_t type, |
2e330e76 DW |
428 | const struct xfs_dquot *dqp, |
429 | struct qc_dqblk *dst) | |
1da177e4 LT |
430 | { |
431 | memset(dst, 0, sizeof(*dst)); | |
d3537cf9 DW |
432 | dst->d_spc_hardlimit = XFS_FSB_TO_B(mp, dqp->q_blk.hardlimit); |
433 | dst->d_spc_softlimit = XFS_FSB_TO_B(mp, dqp->q_blk.softlimit); | |
19dce7ea DW |
434 | dst->d_ino_hardlimit = dqp->q_ino.hardlimit; |
435 | dst->d_ino_softlimit = dqp->q_ino.softlimit; | |
784e80f5 DW |
436 | dst->d_space = XFS_FSB_TO_B(mp, dqp->q_blk.reserved); |
437 | dst->d_ino_count = dqp->q_ino.reserved; | |
19dce7ea DW |
438 | dst->d_spc_timer = dqp->q_blk.timer; |
439 | dst->d_ino_timer = dqp->q_ino.timer; | |
c8c45fb2 DW |
440 | dst->d_ino_warns = dqp->q_ino.warnings; |
441 | dst->d_spc_warns = dqp->q_blk.warnings; | |
d3537cf9 DW |
442 | dst->d_rt_spc_hardlimit = XFS_FSB_TO_B(mp, dqp->q_rtb.hardlimit); |
443 | dst->d_rt_spc_softlimit = XFS_FSB_TO_B(mp, dqp->q_rtb.softlimit); | |
784e80f5 | 444 | dst->d_rt_space = XFS_FSB_TO_B(mp, dqp->q_rtb.reserved); |
19dce7ea | 445 | dst->d_rt_spc_timer = dqp->q_rtb.timer; |
c8c45fb2 | 446 | dst->d_rt_spc_warns = dqp->q_rtb.warnings; |
1da177e4 LT |
447 | |
448 | /* | |
449 | * Internally, we don't reset all the timers when quota enforcement | |
c41564b5 | 450 | * gets turned off. No need to confuse the user level code, |
1da177e4 LT |
451 | * so return zeroes in that case. |
452 | */ | |
dbcbc7b9 | 453 | if (!xfs_dquot_is_enforced(dqp)) { |
14bf61ff JK |
454 | dst->d_spc_timer = 0; |
455 | dst->d_ino_timer = 0; | |
456 | dst->d_rt_spc_timer = 0; | |
1da177e4 LT |
457 | } |
458 | ||
459 | #ifdef DEBUG | |
dbcbc7b9 | 460 | if (xfs_dquot_is_enforced(dqp) && dqp->q_id != 0) { |
14bf61ff JK |
461 | if ((dst->d_space > dst->d_spc_softlimit) && |
462 | (dst->d_spc_softlimit > 0)) { | |
463 | ASSERT(dst->d_spc_timer != 0); | |
1da177e4 | 464 | } |
d3537cf9 DW |
465 | if ((dst->d_ino_count > dqp->q_ino.softlimit) && |
466 | (dqp->q_ino.softlimit > 0)) { | |
14bf61ff | 467 | ASSERT(dst->d_ino_timer != 0); |
1da177e4 LT |
468 | } |
469 | } | |
470 | #endif | |
2e330e76 DW |
471 | } |
472 | ||
473 | /* Return the quota information for the dquot matching id. */ | |
474 | int | |
475 | xfs_qm_scall_getquota( | |
476 | struct xfs_mount *mp, | |
477 | xfs_dqid_t id, | |
1a7ed271 | 478 | xfs_dqtype_t type, |
2e330e76 DW |
479 | struct qc_dqblk *dst) |
480 | { | |
481 | struct xfs_dquot *dqp; | |
482 | int error; | |
483 | ||
01e8f379 DW |
484 | /* Flush inodegc work at the start of a quota reporting scan. */ |
485 | if (id == 0) | |
486 | xfs_inodegc_flush(mp); | |
487 | ||
2e330e76 | 488 | /* |
30ab2dcf DW |
489 | * Try to get the dquot. We don't want it allocated on disk, so don't |
490 | * set doalloc. If it doesn't exist, we'll get ENOENT back. | |
2e330e76 | 491 | */ |
30ab2dcf | 492 | error = xfs_qm_dqget(mp, id, type, false, &dqp); |
2e330e76 DW |
493 | if (error) |
494 | return error; | |
495 | ||
496 | /* | |
497 | * If everything's NULL, this dquot doesn't quite exist as far as | |
498 | * our utility programs are concerned. | |
499 | */ | |
500 | if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) { | |
501 | error = -ENOENT; | |
502 | goto out_put; | |
503 | } | |
504 | ||
505 | xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst); | |
506 | ||
18535a7e CH |
507 | out_put: |
508 | xfs_qm_dqput(dqp); | |
509 | return error; | |
1da177e4 LT |
510 | } |
511 | ||
2e330e76 DW |
512 | /* |
513 | * Return the quota information for the first initialized dquot whose id | |
514 | * is at least as high as id. | |
515 | */ | |
516 | int | |
517 | xfs_qm_scall_getquota_next( | |
518 | struct xfs_mount *mp, | |
519 | xfs_dqid_t *id, | |
1a7ed271 | 520 | xfs_dqtype_t type, |
2e330e76 DW |
521 | struct qc_dqblk *dst) |
522 | { | |
523 | struct xfs_dquot *dqp; | |
524 | int error; | |
525 | ||
01e8f379 DW |
526 | /* Flush inodegc work at the start of a quota reporting scan. */ |
527 | if (*id == 0) | |
528 | xfs_inodegc_flush(mp); | |
529 | ||
2e330e76 DW |
530 | error = xfs_qm_dqget_next(mp, *id, type, &dqp); |
531 | if (error) | |
532 | return error; | |
533 | ||
534 | /* Fill in the ID we actually read from disk */ | |
c51df733 | 535 | *id = dqp->q_id; |
2e330e76 DW |
536 | |
537 | xfs_qm_scall_getquota_fill_qc(mp, type, dqp, dst); | |
538 | ||
539 | xfs_qm_dqput(dqp); | |
540 | return error; | |
541 | } |