backlight: Allow drivers to update the core, and generate events on changes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / xfs / quota / xfs_qm_syscalls.c
blob4e4276b956e8c5f925490dec8e4dfb320ed071a2
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/capability.h>
21 #include "xfs.h"
22 #include "xfs_fs.h"
23 #include "xfs_bit.h"
24 #include "xfs_log.h"
25 #include "xfs_inum.h"
26 #include "xfs_trans.h"
27 #include "xfs_sb.h"
28 #include "xfs_ag.h"
29 #include "xfs_dir2.h"
30 #include "xfs_alloc.h"
31 #include "xfs_dmapi.h"
32 #include "xfs_quota.h"
33 #include "xfs_mount.h"
34 #include "xfs_bmap_btree.h"
35 #include "xfs_alloc_btree.h"
36 #include "xfs_ialloc_btree.h"
37 #include "xfs_dir2_sf.h"
38 #include "xfs_attr_sf.h"
39 #include "xfs_dinode.h"
40 #include "xfs_inode.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_itable.h"
43 #include "xfs_bmap.h"
44 #include "xfs_btree.h"
45 #include "xfs_rtalloc.h"
46 #include "xfs_error.h"
47 #include "xfs_rw.h"
48 #include "xfs_attr.h"
49 #include "xfs_buf_item.h"
50 #include "xfs_utils.h"
51 #include "xfs_qm.h"
53 #ifdef DEBUG
54 # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args)
55 #else
56 # define qdprintk(s, args...) do { } while (0)
57 #endif
59 STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint);
60 STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *,
61 uint);
62 STATIC uint xfs_qm_export_flags(uint);
63 STATIC uint xfs_qm_export_qtype_flags(uint);
64 STATIC void xfs_qm_export_dquot(xfs_mount_t *, xfs_disk_dquot_t *,
65 fs_disk_quota_t *);
69 * Turn off quota accounting and/or enforcement for all udquots and/or
70 * gdquots. Called only at unmount time.
72 * This assumes that there are no dquots of this file system cached
73 * incore, and modifies the ondisk dquot directly. Therefore, for example,
74 * it is an error to call this twice, without purging the cache.
76 int
77 xfs_qm_scall_quotaoff(
78 xfs_mount_t *mp,
79 uint flags)
81 uint dqtype;
82 int error;
83 uint inactivate_flags;
84 xfs_qoff_logitem_t *qoffstart;
85 int nculprits;
88 * No file system can have quotas enabled on disk but not in core.
89 * Note that quota utilities (like quotaoff) _expect_
90 * errno == EEXIST here.
92 if ((mp->m_qflags & flags) == 0)
93 return XFS_ERROR(EEXIST);
94 error = 0;
96 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
99 * We don't want to deal with two quotaoffs messing up each other,
100 * so we're going to serialize it. quotaoff isn't exactly a performance
101 * critical thing.
102 * If quotaoff, then we must be dealing with the root filesystem.
104 ASSERT(mp->m_quotainfo);
105 if (mp->m_quotainfo)
106 mutex_lock(&(XFS_QI_QOFFLOCK(mp)));
108 ASSERT(mp->m_quotainfo);
111 * If we're just turning off quota enforcement, change mp and go.
113 if ((flags & XFS_ALL_QUOTA_ACCT) == 0) {
114 mp->m_qflags &= ~(flags);
116 spin_lock(&mp->m_sb_lock);
117 mp->m_sb.sb_qflags = mp->m_qflags;
118 spin_unlock(&mp->m_sb_lock);
119 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
121 /* XXX what to do if error ? Revert back to old vals incore ? */
122 error = xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS);
123 return (error);
126 dqtype = 0;
127 inactivate_flags = 0;
129 * If accounting is off, we must turn enforcement off, clear the
130 * quota 'CHKD' certificate to make it known that we have to
131 * do a quotacheck the next time this quota is turned on.
133 if (flags & XFS_UQUOTA_ACCT) {
134 dqtype |= XFS_QMOPT_UQUOTA;
135 flags |= (XFS_UQUOTA_CHKD | XFS_UQUOTA_ENFD);
136 inactivate_flags |= XFS_UQUOTA_ACTIVE;
138 if (flags & XFS_GQUOTA_ACCT) {
139 dqtype |= XFS_QMOPT_GQUOTA;
140 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
141 inactivate_flags |= XFS_GQUOTA_ACTIVE;
142 } else if (flags & XFS_PQUOTA_ACCT) {
143 dqtype |= XFS_QMOPT_PQUOTA;
144 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
145 inactivate_flags |= XFS_PQUOTA_ACTIVE;
149 * Nothing to do? Don't complain. This happens when we're just
150 * turning off quota enforcement.
152 if ((mp->m_qflags & flags) == 0) {
153 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
154 return (0);
158 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
159 * and synchronously. If we fail to write, we should abort the
160 * operation as it cannot be recovered safely if we crash.
162 error = xfs_qm_log_quotaoff(mp, &qoffstart, flags);
163 if (error)
164 goto out_error;
167 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
168 * to take care of the race between dqget and quotaoff. We don't take
169 * any special locks to reset these bits. All processes need to check
170 * these bits *after* taking inode lock(s) to see if the particular
171 * quota type is in the process of being turned off. If *ACTIVE, it is
172 * guaranteed that all dquot structures and all quotainode ptrs will all
173 * stay valid as long as that inode is kept locked.
175 * There is no turning back after this.
177 mp->m_qflags &= ~inactivate_flags;
180 * Give back all the dquot reference(s) held by inodes.
181 * Here we go thru every single incore inode in this file system, and
182 * do a dqrele on the i_udquot/i_gdquot that it may have.
183 * Essentially, as long as somebody has an inode locked, this guarantees
184 * that quotas will not be turned off. This is handy because in a
185 * transaction once we lock the inode(s) and check for quotaon, we can
186 * depend on the quota inodes (and other things) being valid as long as
187 * we keep the lock(s).
189 xfs_qm_dqrele_all_inodes(mp, flags);
192 * Next we make the changes in the quota flag in the mount struct.
193 * This isn't protected by a particular lock directly, because we
194 * don't want to take a mrlock everytime we depend on quotas being on.
196 mp->m_qflags &= ~(flags);
199 * Go through all the dquots of this file system and purge them,
200 * according to what was turned off. We may not be able to get rid
201 * of all dquots, because dquots can have temporary references that
202 * are not attached to inodes. eg. xfs_setattr, xfs_create.
203 * So, if we couldn't purge all the dquots from the filesystem,
204 * we can't get rid of the incore data structures.
206 while ((nculprits = xfs_qm_dqpurge_all(mp, dqtype|XFS_QMOPT_QUOTAOFF)))
207 delay(10 * nculprits);
210 * Transactions that had started before ACTIVE state bit was cleared
211 * could have logged many dquots, so they'd have higher LSNs than
212 * the first QUOTAOFF log record does. If we happen to crash when
213 * the tail of the log has gone past the QUOTAOFF record, but
214 * before the last dquot modification, those dquots __will__
215 * recover, and that's not good.
217 * So, we have QUOTAOFF start and end logitems; the start
218 * logitem won't get overwritten until the end logitem appears...
220 error = xfs_qm_log_quotaoff_end(mp, qoffstart, flags);
221 if (error) {
222 /* We're screwed now. Shutdown is the only option. */
223 xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
224 goto out_error;
228 * If quotas is completely disabled, close shop.
230 if (((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET1) ||
231 ((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET2)) {
232 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
233 xfs_qm_destroy_quotainfo(mp);
234 return (0);
238 * Release our quotainode references, and vn_purge them,
239 * if we don't need them anymore.
241 if ((dqtype & XFS_QMOPT_UQUOTA) && XFS_QI_UQIP(mp)) {
242 IRELE(XFS_QI_UQIP(mp));
243 XFS_QI_UQIP(mp) = NULL;
245 if ((dqtype & (XFS_QMOPT_GQUOTA|XFS_QMOPT_PQUOTA)) && XFS_QI_GQIP(mp)) {
246 IRELE(XFS_QI_GQIP(mp));
247 XFS_QI_GQIP(mp) = NULL;
249 out_error:
250 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
252 return (error);
256 xfs_qm_scall_trunc_qfiles(
257 xfs_mount_t *mp,
258 uint flags)
260 int error = 0, error2 = 0;
261 xfs_inode_t *qip;
263 if (!xfs_sb_version_hasquota(&mp->m_sb) || flags == 0) {
264 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags);
265 return XFS_ERROR(EINVAL);
268 if ((flags & XFS_DQ_USER) && mp->m_sb.sb_uquotino != NULLFSINO) {
269 error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, 0, 0, &qip, 0);
270 if (!error) {
271 error = xfs_truncate_file(mp, qip);
272 IRELE(qip);
276 if ((flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) &&
277 mp->m_sb.sb_gquotino != NULLFSINO) {
278 error2 = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, 0, 0, &qip, 0);
279 if (!error2) {
280 error2 = xfs_truncate_file(mp, qip);
281 IRELE(qip);
285 return error ? error : error2;
290 * Switch on (a given) quota enforcement for a filesystem. This takes
291 * effect immediately.
292 * (Switching on quota accounting must be done at mount time.)
295 xfs_qm_scall_quotaon(
296 xfs_mount_t *mp,
297 uint flags)
299 int error;
300 uint qf;
301 uint accflags;
302 __int64_t sbflags;
304 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
306 * Switching on quota accounting must be done at mount time.
308 accflags = flags & XFS_ALL_QUOTA_ACCT;
309 flags &= ~(XFS_ALL_QUOTA_ACCT);
311 sbflags = 0;
313 if (flags == 0) {
314 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp->m_qflags);
315 return XFS_ERROR(EINVAL);
318 /* No fs can turn on quotas with a delayed effect */
319 ASSERT((flags & XFS_ALL_QUOTA_ACCT) == 0);
322 * Can't enforce without accounting. We check the superblock
323 * qflags here instead of m_qflags because rootfs can have
324 * quota acct on ondisk without m_qflags' knowing.
326 if (((flags & XFS_UQUOTA_ACCT) == 0 &&
327 (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 &&
328 (flags & XFS_UQUOTA_ENFD))
330 ((flags & XFS_PQUOTA_ACCT) == 0 &&
331 (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 &&
332 (flags & XFS_GQUOTA_ACCT) == 0 &&
333 (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 &&
334 (flags & XFS_OQUOTA_ENFD))) {
335 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
336 flags, mp->m_sb.sb_qflags);
337 return XFS_ERROR(EINVAL);
340 * If everything's upto-date incore, then don't waste time.
342 if ((mp->m_qflags & flags) == flags)
343 return XFS_ERROR(EEXIST);
346 * Change sb_qflags on disk but not incore mp->qflags
347 * if this is the root filesystem.
349 spin_lock(&mp->m_sb_lock);
350 qf = mp->m_sb.sb_qflags;
351 mp->m_sb.sb_qflags = qf | flags;
352 spin_unlock(&mp->m_sb_lock);
355 * There's nothing to change if it's the same.
357 if ((qf & flags) == flags && sbflags == 0)
358 return XFS_ERROR(EEXIST);
359 sbflags |= XFS_SB_QFLAGS;
361 if ((error = xfs_qm_write_sb_changes(mp, sbflags)))
362 return (error);
364 * If we aren't trying to switch on quota enforcement, we are done.
366 if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) !=
367 (mp->m_qflags & XFS_UQUOTA_ACCT)) ||
368 ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) !=
369 (mp->m_qflags & XFS_PQUOTA_ACCT)) ||
370 ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) !=
371 (mp->m_qflags & XFS_GQUOTA_ACCT)) ||
372 (flags & XFS_ALL_QUOTA_ENFD) == 0)
373 return (0);
375 if (! XFS_IS_QUOTA_RUNNING(mp))
376 return XFS_ERROR(ESRCH);
379 * Switch on quota enforcement in core.
381 mutex_lock(&(XFS_QI_QOFFLOCK(mp)));
382 mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD);
383 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
385 return (0);
390 * Return quota status information, such as uquota-off, enforcements, etc.
393 xfs_qm_scall_getqstat(
394 xfs_mount_t *mp,
395 fs_quota_stat_t *out)
397 xfs_inode_t *uip, *gip;
398 boolean_t tempuqip, tempgqip;
400 uip = gip = NULL;
401 tempuqip = tempgqip = B_FALSE;
402 memset(out, 0, sizeof(fs_quota_stat_t));
404 out->qs_version = FS_QSTAT_VERSION;
405 if (!xfs_sb_version_hasquota(&mp->m_sb)) {
406 out->qs_uquota.qfs_ino = NULLFSINO;
407 out->qs_gquota.qfs_ino = NULLFSINO;
408 return (0);
410 out->qs_flags = (__uint16_t) xfs_qm_export_flags(mp->m_qflags &
411 (XFS_ALL_QUOTA_ACCT|
412 XFS_ALL_QUOTA_ENFD));
413 out->qs_pad = 0;
414 out->qs_uquota.qfs_ino = mp->m_sb.sb_uquotino;
415 out->qs_gquota.qfs_ino = mp->m_sb.sb_gquotino;
417 if (mp->m_quotainfo) {
418 uip = mp->m_quotainfo->qi_uquotaip;
419 gip = mp->m_quotainfo->qi_gquotaip;
421 if (!uip && mp->m_sb.sb_uquotino != NULLFSINO) {
422 if (xfs_iget(mp, NULL, mp->m_sb.sb_uquotino,
423 0, 0, &uip, 0) == 0)
424 tempuqip = B_TRUE;
426 if (!gip && mp->m_sb.sb_gquotino != NULLFSINO) {
427 if (xfs_iget(mp, NULL, mp->m_sb.sb_gquotino,
428 0, 0, &gip, 0) == 0)
429 tempgqip = B_TRUE;
431 if (uip) {
432 out->qs_uquota.qfs_nblks = uip->i_d.di_nblocks;
433 out->qs_uquota.qfs_nextents = uip->i_d.di_nextents;
434 if (tempuqip)
435 IRELE(uip);
437 if (gip) {
438 out->qs_gquota.qfs_nblks = gip->i_d.di_nblocks;
439 out->qs_gquota.qfs_nextents = gip->i_d.di_nextents;
440 if (tempgqip)
441 IRELE(gip);
443 if (mp->m_quotainfo) {
444 out->qs_incoredqs = XFS_QI_MPLNDQUOTS(mp);
445 out->qs_btimelimit = XFS_QI_BTIMELIMIT(mp);
446 out->qs_itimelimit = XFS_QI_ITIMELIMIT(mp);
447 out->qs_rtbtimelimit = XFS_QI_RTBTIMELIMIT(mp);
448 out->qs_bwarnlimit = XFS_QI_BWARNLIMIT(mp);
449 out->qs_iwarnlimit = XFS_QI_IWARNLIMIT(mp);
451 return (0);
455 * Adjust quota limits, and start/stop timers accordingly.
458 xfs_qm_scall_setqlim(
459 xfs_mount_t *mp,
460 xfs_dqid_t id,
461 uint type,
462 fs_disk_quota_t *newlim)
464 xfs_disk_dquot_t *ddq;
465 xfs_dquot_t *dqp;
466 xfs_trans_t *tp;
467 int error;
468 xfs_qcnt_t hard, soft;
470 if ((newlim->d_fieldmask &
471 (FS_DQ_LIMIT_MASK|FS_DQ_TIMER_MASK|FS_DQ_WARNS_MASK)) == 0)
472 return (0);
474 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM);
475 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_disk_dquot_t) + 128,
476 0, 0, XFS_DEFAULT_LOG_COUNT))) {
477 xfs_trans_cancel(tp, 0);
478 return (error);
482 * We don't want to race with a quotaoff so take the quotaoff lock.
483 * (We don't hold an inode lock, so there's nothing else to stop
484 * a quotaoff from happening). (XXXThis doesn't currently happen
485 * because we take the vfslock before calling xfs_qm_sysent).
487 mutex_lock(&(XFS_QI_QOFFLOCK(mp)));
490 * Get the dquot (locked), and join it to the transaction.
491 * Allocate the dquot if this doesn't exist.
493 if ((error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp))) {
494 xfs_trans_cancel(tp, XFS_TRANS_ABORT);
495 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
496 ASSERT(error != ENOENT);
497 return (error);
499 xfs_dqtrace_entry(dqp, "Q_SETQLIM: AFT DQGET");
500 xfs_trans_dqjoin(tp, dqp);
501 ddq = &dqp->q_core;
504 * Make sure that hardlimits are >= soft limits before changing.
506 hard = (newlim->d_fieldmask & FS_DQ_BHARD) ?
507 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) :
508 be64_to_cpu(ddq->d_blk_hardlimit);
509 soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ?
510 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) :
511 be64_to_cpu(ddq->d_blk_softlimit);
512 if (hard == 0 || hard >= soft) {
513 ddq->d_blk_hardlimit = cpu_to_be64(hard);
514 ddq->d_blk_softlimit = cpu_to_be64(soft);
515 if (id == 0) {
516 mp->m_quotainfo->qi_bhardlimit = hard;
517 mp->m_quotainfo->qi_bsoftlimit = soft;
519 } else {
520 qdprintk("blkhard %Ld < blksoft %Ld\n", hard, soft);
522 hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ?
523 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) :
524 be64_to_cpu(ddq->d_rtb_hardlimit);
525 soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ?
526 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) :
527 be64_to_cpu(ddq->d_rtb_softlimit);
528 if (hard == 0 || hard >= soft) {
529 ddq->d_rtb_hardlimit = cpu_to_be64(hard);
530 ddq->d_rtb_softlimit = cpu_to_be64(soft);
531 if (id == 0) {
532 mp->m_quotainfo->qi_rtbhardlimit = hard;
533 mp->m_quotainfo->qi_rtbsoftlimit = soft;
535 } else {
536 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard, soft);
539 hard = (newlim->d_fieldmask & FS_DQ_IHARD) ?
540 (xfs_qcnt_t) newlim->d_ino_hardlimit :
541 be64_to_cpu(ddq->d_ino_hardlimit);
542 soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ?
543 (xfs_qcnt_t) newlim->d_ino_softlimit :
544 be64_to_cpu(ddq->d_ino_softlimit);
545 if (hard == 0 || hard >= soft) {
546 ddq->d_ino_hardlimit = cpu_to_be64(hard);
547 ddq->d_ino_softlimit = cpu_to_be64(soft);
548 if (id == 0) {
549 mp->m_quotainfo->qi_ihardlimit = hard;
550 mp->m_quotainfo->qi_isoftlimit = soft;
552 } else {
553 qdprintk("ihard %Ld < isoft %Ld\n", hard, soft);
557 * Update warnings counter(s) if requested
559 if (newlim->d_fieldmask & FS_DQ_BWARNS)
560 ddq->d_bwarns = cpu_to_be16(newlim->d_bwarns);
561 if (newlim->d_fieldmask & FS_DQ_IWARNS)
562 ddq->d_iwarns = cpu_to_be16(newlim->d_iwarns);
563 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
564 ddq->d_rtbwarns = cpu_to_be16(newlim->d_rtbwarns);
566 if (id == 0) {
568 * Timelimits for the super user set the relative time
569 * the other users can be over quota for this file system.
570 * If it is zero a default is used. Ditto for the default
571 * soft and hard limit values (already done, above), and
572 * for warnings.
574 if (newlim->d_fieldmask & FS_DQ_BTIMER) {
575 mp->m_quotainfo->qi_btimelimit = newlim->d_btimer;
576 ddq->d_btimer = cpu_to_be32(newlim->d_btimer);
578 if (newlim->d_fieldmask & FS_DQ_ITIMER) {
579 mp->m_quotainfo->qi_itimelimit = newlim->d_itimer;
580 ddq->d_itimer = cpu_to_be32(newlim->d_itimer);
582 if (newlim->d_fieldmask & FS_DQ_RTBTIMER) {
583 mp->m_quotainfo->qi_rtbtimelimit = newlim->d_rtbtimer;
584 ddq->d_rtbtimer = cpu_to_be32(newlim->d_rtbtimer);
586 if (newlim->d_fieldmask & FS_DQ_BWARNS)
587 mp->m_quotainfo->qi_bwarnlimit = newlim->d_bwarns;
588 if (newlim->d_fieldmask & FS_DQ_IWARNS)
589 mp->m_quotainfo->qi_iwarnlimit = newlim->d_iwarns;
590 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
591 mp->m_quotainfo->qi_rtbwarnlimit = newlim->d_rtbwarns;
592 } else {
594 * If the user is now over quota, start the timelimit.
595 * The user will not be 'warned'.
596 * Note that we keep the timers ticking, whether enforcement
597 * is on or off. We don't really want to bother with iterating
598 * over all ondisk dquots and turning the timers on/off.
600 xfs_qm_adjust_dqtimers(mp, ddq);
602 dqp->dq_flags |= XFS_DQ_DIRTY;
603 xfs_trans_log_dquot(tp, dqp);
605 xfs_dqtrace_entry(dqp, "Q_SETQLIM: COMMIT");
606 error = xfs_trans_commit(tp, 0);
607 xfs_qm_dqprint(dqp);
608 xfs_qm_dqrele(dqp);
609 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
611 return error;
615 xfs_qm_scall_getquota(
616 xfs_mount_t *mp,
617 xfs_dqid_t id,
618 uint type,
619 fs_disk_quota_t *out)
621 xfs_dquot_t *dqp;
622 int error;
625 * Try to get the dquot. We don't want it allocated on disk, so
626 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
627 * exist, we'll get ENOENT back.
629 if ((error = xfs_qm_dqget(mp, NULL, id, type, 0, &dqp))) {
630 return (error);
633 xfs_dqtrace_entry(dqp, "Q_GETQUOTA SUCCESS");
635 * If everything's NULL, this dquot doesn't quite exist as far as
636 * our utility programs are concerned.
638 if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
639 xfs_qm_dqput(dqp);
640 return XFS_ERROR(ENOENT);
642 /* xfs_qm_dqprint(dqp); */
644 * Convert the disk dquot to the exportable format
646 xfs_qm_export_dquot(mp, &dqp->q_core, out);
647 xfs_qm_dqput(dqp);
648 return (error ? XFS_ERROR(EFAULT) : 0);
652 STATIC int
653 xfs_qm_log_quotaoff_end(
654 xfs_mount_t *mp,
655 xfs_qoff_logitem_t *startqoff,
656 uint flags)
658 xfs_trans_t *tp;
659 int error;
660 xfs_qoff_logitem_t *qoffi;
662 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END);
664 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_qoff_logitem_t) * 2,
665 0, 0, XFS_DEFAULT_LOG_COUNT))) {
666 xfs_trans_cancel(tp, 0);
667 return (error);
670 qoffi = xfs_trans_get_qoff_item(tp, startqoff,
671 flags & XFS_ALL_QUOTA_ACCT);
672 xfs_trans_log_quotaoff_item(tp, qoffi);
675 * We have to make sure that the transaction is secure on disk before we
676 * return and actually stop quota accounting. So, make it synchronous.
677 * We don't care about quotoff's performance.
679 xfs_trans_set_sync(tp);
680 error = xfs_trans_commit(tp, 0);
681 return (error);
685 STATIC int
686 xfs_qm_log_quotaoff(
687 xfs_mount_t *mp,
688 xfs_qoff_logitem_t **qoffstartp,
689 uint flags)
691 xfs_trans_t *tp;
692 int error;
693 xfs_qoff_logitem_t *qoffi=NULL;
694 uint oldsbqflag=0;
696 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF);
697 if ((error = xfs_trans_reserve(tp, 0,
698 sizeof(xfs_qoff_logitem_t) * 2 +
699 mp->m_sb.sb_sectsize + 128,
702 XFS_DEFAULT_LOG_COUNT))) {
703 goto error0;
706 qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT);
707 xfs_trans_log_quotaoff_item(tp, qoffi);
709 spin_lock(&mp->m_sb_lock);
710 oldsbqflag = mp->m_sb.sb_qflags;
711 mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL;
712 spin_unlock(&mp->m_sb_lock);
714 xfs_mod_sb(tp, XFS_SB_QFLAGS);
717 * We have to make sure that the transaction is secure on disk before we
718 * return and actually stop quota accounting. So, make it synchronous.
719 * We don't care about quotoff's performance.
721 xfs_trans_set_sync(tp);
722 error = xfs_trans_commit(tp, 0);
724 error0:
725 if (error) {
726 xfs_trans_cancel(tp, 0);
728 * No one else is modifying sb_qflags, so this is OK.
729 * We still hold the quotaofflock.
731 spin_lock(&mp->m_sb_lock);
732 mp->m_sb.sb_qflags = oldsbqflag;
733 spin_unlock(&mp->m_sb_lock);
735 *qoffstartp = qoffi;
736 return (error);
741 * Translate an internal style on-disk-dquot to the exportable format.
742 * The main differences are that the counters/limits are all in Basic
743 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
744 * to be converted to the native endianness.
746 STATIC void
747 xfs_qm_export_dquot(
748 xfs_mount_t *mp,
749 xfs_disk_dquot_t *src,
750 struct fs_disk_quota *dst)
752 memset(dst, 0, sizeof(*dst));
753 dst->d_version = FS_DQUOT_VERSION; /* different from src->d_version */
754 dst->d_flags = xfs_qm_export_qtype_flags(src->d_flags);
755 dst->d_id = be32_to_cpu(src->d_id);
756 dst->d_blk_hardlimit =
757 XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_hardlimit));
758 dst->d_blk_softlimit =
759 XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_blk_softlimit));
760 dst->d_ino_hardlimit = be64_to_cpu(src->d_ino_hardlimit);
761 dst->d_ino_softlimit = be64_to_cpu(src->d_ino_softlimit);
762 dst->d_bcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_bcount));
763 dst->d_icount = be64_to_cpu(src->d_icount);
764 dst->d_btimer = be32_to_cpu(src->d_btimer);
765 dst->d_itimer = be32_to_cpu(src->d_itimer);
766 dst->d_iwarns = be16_to_cpu(src->d_iwarns);
767 dst->d_bwarns = be16_to_cpu(src->d_bwarns);
768 dst->d_rtb_hardlimit =
769 XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_hardlimit));
770 dst->d_rtb_softlimit =
771 XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtb_softlimit));
772 dst->d_rtbcount = XFS_FSB_TO_BB(mp, be64_to_cpu(src->d_rtbcount));
773 dst->d_rtbtimer = be32_to_cpu(src->d_rtbtimer);
774 dst->d_rtbwarns = be16_to_cpu(src->d_rtbwarns);
777 * Internally, we don't reset all the timers when quota enforcement
778 * gets turned off. No need to confuse the user level code,
779 * so return zeroes in that case.
781 if ((!XFS_IS_UQUOTA_ENFORCED(mp) && src->d_flags == XFS_DQ_USER) ||
782 (!XFS_IS_OQUOTA_ENFORCED(mp) &&
783 (src->d_flags & (XFS_DQ_PROJ | XFS_DQ_GROUP)))) {
784 dst->d_btimer = 0;
785 dst->d_itimer = 0;
786 dst->d_rtbtimer = 0;
789 #ifdef DEBUG
790 if (((XFS_IS_UQUOTA_ENFORCED(mp) && dst->d_flags == XFS_USER_QUOTA) ||
791 (XFS_IS_OQUOTA_ENFORCED(mp) &&
792 (dst->d_flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)))) &&
793 dst->d_id != 0) {
794 if (((int) dst->d_bcount >= (int) dst->d_blk_softlimit) &&
795 (dst->d_blk_softlimit > 0)) {
796 ASSERT(dst->d_btimer != 0);
798 if (((int) dst->d_icount >= (int) dst->d_ino_softlimit) &&
799 (dst->d_ino_softlimit > 0)) {
800 ASSERT(dst->d_itimer != 0);
803 #endif
806 STATIC uint
807 xfs_qm_export_qtype_flags(
808 uint flags)
811 * Can't be more than one, or none.
813 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_USER_QUOTA)) !=
814 (XFS_PROJ_QUOTA | XFS_USER_QUOTA));
815 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)) !=
816 (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA));
817 ASSERT((flags & (XFS_USER_QUOTA | XFS_GROUP_QUOTA)) !=
818 (XFS_USER_QUOTA | XFS_GROUP_QUOTA));
819 ASSERT((flags & (XFS_PROJ_QUOTA|XFS_USER_QUOTA|XFS_GROUP_QUOTA)) != 0);
821 return (flags & XFS_DQ_USER) ?
822 XFS_USER_QUOTA : (flags & XFS_DQ_PROJ) ?
823 XFS_PROJ_QUOTA : XFS_GROUP_QUOTA;
826 STATIC uint
827 xfs_qm_export_flags(
828 uint flags)
830 uint uflags;
832 uflags = 0;
833 if (flags & XFS_UQUOTA_ACCT)
834 uflags |= XFS_QUOTA_UDQ_ACCT;
835 if (flags & XFS_PQUOTA_ACCT)
836 uflags |= XFS_QUOTA_PDQ_ACCT;
837 if (flags & XFS_GQUOTA_ACCT)
838 uflags |= XFS_QUOTA_GDQ_ACCT;
839 if (flags & XFS_UQUOTA_ENFD)
840 uflags |= XFS_QUOTA_UDQ_ENFD;
841 if (flags & (XFS_OQUOTA_ENFD)) {
842 uflags |= (flags & XFS_GQUOTA_ACCT) ?
843 XFS_QUOTA_GDQ_ENFD : XFS_QUOTA_PDQ_ENFD;
845 return (uflags);
849 STATIC int
850 xfs_dqrele_inode(
851 struct xfs_inode *ip,
852 struct xfs_perag *pag,
853 int flags)
855 int error;
857 /* skip quota inodes */
858 if (ip == XFS_QI_UQIP(ip->i_mount) || ip == XFS_QI_GQIP(ip->i_mount)) {
859 ASSERT(ip->i_udquot == NULL);
860 ASSERT(ip->i_gdquot == NULL);
861 read_unlock(&pag->pag_ici_lock);
862 return 0;
865 error = xfs_sync_inode_valid(ip, pag);
866 if (error)
867 return error;
869 xfs_ilock(ip, XFS_ILOCK_EXCL);
870 if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) {
871 xfs_qm_dqrele(ip->i_udquot);
872 ip->i_udquot = NULL;
874 if (flags & (XFS_PQUOTA_ACCT|XFS_GQUOTA_ACCT) && ip->i_gdquot) {
875 xfs_qm_dqrele(ip->i_gdquot);
876 ip->i_gdquot = NULL;
878 xfs_iput(ip, XFS_ILOCK_EXCL);
879 IRELE(ip);
881 return 0;
886 * Go thru all the inodes in the file system, releasing their dquots.
888 * Note that the mount structure gets modified to indicate that quotas are off
889 * AFTER this, in the case of quotaoff.
891 void
892 xfs_qm_dqrele_all_inodes(
893 struct xfs_mount *mp,
894 uint flags)
896 ASSERT(mp->m_quotainfo);
897 xfs_inode_ag_iterator(mp, xfs_dqrele_inode, flags, XFS_ICI_NO_TAG);
900 /*------------------------------------------------------------------------*/
901 #ifdef DEBUG
903 * This contains all the test functions for XFS disk quotas.
904 * Currently it does a quota accounting check. ie. it walks through
905 * all inodes in the file system, calculating the dquot accounting fields,
906 * and prints out any inconsistencies.
908 xfs_dqhash_t *qmtest_udqtab;
909 xfs_dqhash_t *qmtest_gdqtab;
910 int qmtest_hashmask;
911 int qmtest_nfails;
912 struct mutex qcheck_lock;
914 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
915 (__psunsigned_t)(id)) & \
916 (qmtest_hashmask - 1))
918 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
919 (qmtest_udqtab + \
920 DQTEST_HASHVAL(mp, id)) : \
921 (qmtest_gdqtab + \
922 DQTEST_HASHVAL(mp, id)))
924 #define DQTEST_LIST_PRINT(l, NXT, title) \
926 xfs_dqtest_t *dqp; int i = 0;\
927 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
928 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
929 dqp = (xfs_dqtest_t *)dqp->NXT) { \
930 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
931 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
932 dqp->d_bcount, dqp->d_icount); } \
935 typedef struct dqtest {
936 xfs_dqmarker_t q_lists;
937 xfs_dqhash_t *q_hash; /* the hashchain header */
938 xfs_mount_t *q_mount; /* filesystem this relates to */
939 xfs_dqid_t d_id; /* user id or group id */
940 xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */
941 xfs_qcnt_t d_icount; /* # inodes owned by the user */
942 } xfs_dqtest_t;
944 STATIC void
945 xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp)
947 xfs_dquot_t *d;
948 if (((d) = (h)->qh_next))
949 (d)->HL_PREVP = &((dqp)->HL_NEXT);
950 (dqp)->HL_NEXT = d;
951 (dqp)->HL_PREVP = &((h)->qh_next);
952 (h)->qh_next = (xfs_dquot_t *)dqp;
953 (h)->qh_version++;
954 (h)->qh_nelems++;
956 STATIC void
957 xfs_qm_dqtest_print(
958 xfs_dqtest_t *d)
960 cmn_err(CE_DEBUG, "-----------DQTEST DQUOT----------------");
961 cmn_err(CE_DEBUG, "---- dquot ID = %d", d->d_id);
962 cmn_err(CE_DEBUG, "---- fs = 0x%p", d->q_mount);
963 cmn_err(CE_DEBUG, "---- bcount = %Lu (0x%x)",
964 d->d_bcount, (int)d->d_bcount);
965 cmn_err(CE_DEBUG, "---- icount = %Lu (0x%x)",
966 d->d_icount, (int)d->d_icount);
967 cmn_err(CE_DEBUG, "---------------------------");
970 STATIC void
971 xfs_qm_dqtest_failed(
972 xfs_dqtest_t *d,
973 xfs_dquot_t *dqp,
974 char *reason,
975 xfs_qcnt_t a,
976 xfs_qcnt_t b,
977 int error)
979 qmtest_nfails++;
980 if (error)
981 cmn_err(CE_DEBUG, "quotacheck failed id=%d, err=%d\nreason: %s",
982 d->d_id, error, reason);
983 else
984 cmn_err(CE_DEBUG, "quotacheck failed id=%d (%s) [%d != %d]",
985 d->d_id, reason, (int)a, (int)b);
986 xfs_qm_dqtest_print(d);
987 if (dqp)
988 xfs_qm_dqprint(dqp);
991 STATIC int
992 xfs_dqtest_cmp2(
993 xfs_dqtest_t *d,
994 xfs_dquot_t *dqp)
996 int err = 0;
997 if (be64_to_cpu(dqp->q_core.d_icount) != d->d_icount) {
998 xfs_qm_dqtest_failed(d, dqp, "icount mismatch",
999 be64_to_cpu(dqp->q_core.d_icount),
1000 d->d_icount, 0);
1001 err++;
1003 if (be64_to_cpu(dqp->q_core.d_bcount) != d->d_bcount) {
1004 xfs_qm_dqtest_failed(d, dqp, "bcount mismatch",
1005 be64_to_cpu(dqp->q_core.d_bcount),
1006 d->d_bcount, 0);
1007 err++;
1009 if (dqp->q_core.d_blk_softlimit &&
1010 be64_to_cpu(dqp->q_core.d_bcount) >=
1011 be64_to_cpu(dqp->q_core.d_blk_softlimit)) {
1012 if (!dqp->q_core.d_btimer && dqp->q_core.d_id) {
1013 cmn_err(CE_DEBUG,
1014 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1015 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1016 err++;
1019 if (dqp->q_core.d_ino_softlimit &&
1020 be64_to_cpu(dqp->q_core.d_icount) >=
1021 be64_to_cpu(dqp->q_core.d_ino_softlimit)) {
1022 if (!dqp->q_core.d_itimer && dqp->q_core.d_id) {
1023 cmn_err(CE_DEBUG,
1024 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1025 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1026 err++;
1029 #ifdef QUOTADEBUG
1030 if (!err) {
1031 cmn_err(CE_DEBUG, "%d [%s] [0x%p] qchecked",
1032 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1034 #endif
1035 return (err);
1038 STATIC void
1039 xfs_dqtest_cmp(
1040 xfs_dqtest_t *d)
1042 xfs_dquot_t *dqp;
1043 int error;
1045 /* xfs_qm_dqtest_print(d); */
1046 if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0,
1047 &dqp))) {
1048 xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error);
1049 return;
1051 xfs_dqtest_cmp2(d, dqp);
1052 xfs_qm_dqput(dqp);
1055 STATIC int
1056 xfs_qm_internalqcheck_dqget(
1057 xfs_mount_t *mp,
1058 xfs_dqid_t id,
1059 uint type,
1060 xfs_dqtest_t **O_dq)
1062 xfs_dqtest_t *d;
1063 xfs_dqhash_t *h;
1065 h = DQTEST_HASH(mp, id, type);
1066 for (d = (xfs_dqtest_t *) h->qh_next; d != NULL;
1067 d = (xfs_dqtest_t *) d->HL_NEXT) {
1068 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1069 if (d->d_id == id && mp == d->q_mount) {
1070 *O_dq = d;
1071 return (0);
1074 d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP);
1075 d->dq_flags = type;
1076 d->d_id = id;
1077 d->q_mount = mp;
1078 d->q_hash = h;
1079 xfs_qm_hashinsert(h, d);
1080 *O_dq = d;
1081 return (0);
1084 STATIC void
1085 xfs_qm_internalqcheck_get_dquots(
1086 xfs_mount_t *mp,
1087 xfs_dqid_t uid,
1088 xfs_dqid_t projid,
1089 xfs_dqid_t gid,
1090 xfs_dqtest_t **ud,
1091 xfs_dqtest_t **gd)
1093 if (XFS_IS_UQUOTA_ON(mp))
1094 xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud);
1095 if (XFS_IS_GQUOTA_ON(mp))
1096 xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd);
1097 else if (XFS_IS_PQUOTA_ON(mp))
1098 xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd);
1102 STATIC void
1103 xfs_qm_internalqcheck_dqadjust(
1104 xfs_inode_t *ip,
1105 xfs_dqtest_t *d)
1107 d->d_icount++;
1108 d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks;
1111 STATIC int
1112 xfs_qm_internalqcheck_adjust(
1113 xfs_mount_t *mp, /* mount point for filesystem */
1114 xfs_ino_t ino, /* inode number to get data for */
1115 void __user *buffer, /* not used */
1116 int ubsize, /* not used */
1117 void *private_data, /* not used */
1118 xfs_daddr_t bno, /* starting block of inode cluster */
1119 int *ubused, /* not used */
1120 void *dip, /* not used */
1121 int *res) /* bulkstat result code */
1123 xfs_inode_t *ip;
1124 xfs_dqtest_t *ud, *gd;
1125 uint lock_flags;
1126 boolean_t ipreleased;
1127 int error;
1129 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
1131 if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) {
1132 *res = BULKSTAT_RV_NOTHING;
1133 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1134 (unsigned long long) ino,
1135 (unsigned long long) mp->m_sb.sb_uquotino,
1136 (unsigned long long) mp->m_sb.sb_gquotino);
1137 return XFS_ERROR(EINVAL);
1139 ipreleased = B_FALSE;
1140 again:
1141 lock_flags = XFS_ILOCK_SHARED;
1142 if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip, bno))) {
1143 *res = BULKSTAT_RV_NOTHING;
1144 return (error);
1148 * This inode can have blocks after eof which can get released
1149 * when we send it to inactive. Since we don't check the dquot
1150 * until the after all our calculations are done, we must get rid
1151 * of those now.
1153 if (! ipreleased) {
1154 xfs_iput(ip, lock_flags);
1155 ipreleased = B_TRUE;
1156 goto again;
1158 xfs_qm_internalqcheck_get_dquots(mp,
1159 (xfs_dqid_t) ip->i_d.di_uid,
1160 (xfs_dqid_t) ip->i_d.di_projid,
1161 (xfs_dqid_t) ip->i_d.di_gid,
1162 &ud, &gd);
1163 if (XFS_IS_UQUOTA_ON(mp)) {
1164 ASSERT(ud);
1165 xfs_qm_internalqcheck_dqadjust(ip, ud);
1167 if (XFS_IS_OQUOTA_ON(mp)) {
1168 ASSERT(gd);
1169 xfs_qm_internalqcheck_dqadjust(ip, gd);
1171 xfs_iput(ip, lock_flags);
1172 *res = BULKSTAT_RV_DIDONE;
1173 return (0);
1177 /* PRIVATE, debugging */
1179 xfs_qm_internalqcheck(
1180 xfs_mount_t *mp)
1182 xfs_ino_t lastino;
1183 int done, count;
1184 int i;
1185 xfs_dqtest_t *d, *e;
1186 xfs_dqhash_t *h1;
1187 int error;
1189 lastino = 0;
1190 qmtest_hashmask = 32;
1191 count = 5;
1192 done = 0;
1193 qmtest_nfails = 0;
1195 if (! XFS_IS_QUOTA_ON(mp))
1196 return XFS_ERROR(ESRCH);
1198 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1199 XFS_bflush(mp->m_ddev_targp);
1200 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1201 XFS_bflush(mp->m_ddev_targp);
1203 mutex_lock(&qcheck_lock);
1204 /* There should be absolutely no quota activity while this
1205 is going on. */
1206 qmtest_udqtab = kmem_zalloc(qmtest_hashmask *
1207 sizeof(xfs_dqhash_t), KM_SLEEP);
1208 qmtest_gdqtab = kmem_zalloc(qmtest_hashmask *
1209 sizeof(xfs_dqhash_t), KM_SLEEP);
1210 do {
1212 * Iterate thru all the inodes in the file system,
1213 * adjusting the corresponding dquot counters
1215 if ((error = xfs_bulkstat(mp, &lastino, &count,
1216 xfs_qm_internalqcheck_adjust, NULL,
1217 0, NULL, BULKSTAT_FG_IGET, &done))) {
1218 break;
1220 } while (! done);
1221 if (error) {
1222 cmn_err(CE_DEBUG, "Bulkstat returned error 0x%x", error);
1224 cmn_err(CE_DEBUG, "Checking results against system dquots");
1225 for (i = 0; i < qmtest_hashmask; i++) {
1226 h1 = &qmtest_udqtab[i];
1227 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1228 xfs_dqtest_cmp(d);
1229 e = (xfs_dqtest_t *) d->HL_NEXT;
1230 kmem_free(d);
1231 d = e;
1233 h1 = &qmtest_gdqtab[i];
1234 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1235 xfs_dqtest_cmp(d);
1236 e = (xfs_dqtest_t *) d->HL_NEXT;
1237 kmem_free(d);
1238 d = e;
1242 if (qmtest_nfails) {
1243 cmn_err(CE_DEBUG, "******** quotacheck failed ********");
1244 cmn_err(CE_DEBUG, "failures = %d", qmtest_nfails);
1245 } else {
1246 cmn_err(CE_DEBUG, "******** quotacheck successful! ********");
1248 kmem_free(qmtest_udqtab);
1249 kmem_free(qmtest_gdqtab);
1250 mutex_unlock(&qcheck_lock);
1251 return (qmtest_nfails);
1254 #endif /* DEBUG */