2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #include "xfs_trans.h"
43 #include "xfs_alloc.h"
44 #include "xfs_dmapi.h"
45 #include "xfs_quota.h"
46 #include "xfs_mount.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_alloc_btree.h"
49 #include "xfs_ialloc_btree.h"
50 #include "xfs_dir_sf.h"
51 #include "xfs_dir2_sf.h"
52 #include "xfs_attr_sf.h"
53 #include "xfs_dinode.h"
54 #include "xfs_inode.h"
55 #include "xfs_ialloc.h"
56 #include "xfs_itable.h"
58 #include "xfs_btree.h"
59 #include "xfs_rtalloc.h"
60 #include "xfs_error.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
71 # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args)
73 # define qdprintk(s, args...) do { } while (0)
76 STATIC int xfs_qm_scall_trunc_qfiles(xfs_mount_t *, uint);
77 STATIC int xfs_qm_scall_getquota(xfs_mount_t *, xfs_dqid_t, uint,
79 STATIC int xfs_qm_scall_getqstat(xfs_mount_t *, fs_quota_stat_t *);
80 STATIC int xfs_qm_scall_setqlim(xfs_mount_t *, xfs_dqid_t, uint,
82 STATIC int xfs_qm_scall_quotaon(xfs_mount_t *, uint);
83 STATIC int xfs_qm_scall_quotaoff(xfs_mount_t *, uint, boolean_t);
84 STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint);
85 STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *,
87 STATIC uint xfs_qm_import_flags(uint);
88 STATIC uint xfs_qm_export_flags(uint);
89 STATIC uint xfs_qm_import_qtype_flags(uint);
90 STATIC uint xfs_qm_export_qtype_flags(uint);
91 STATIC void xfs_qm_export_dquot(xfs_mount_t *, xfs_disk_dquot_t *,
96 * The main distribution switch of all XFS quotactl system calls.
100 struct bhv_desc *bdp,
109 vfsp = bhvtovfs(bdp);
110 mp = XFS_VFSTOM(vfsp);
112 ASSERT(addr != NULL || cmd == Q_XQUOTASYNC);
115 * The following commands are valid even when quotaoff.
120 * Truncate quota files. quota must be off.
122 if (XFS_IS_QUOTA_ON(mp))
123 return XFS_ERROR(EINVAL);
124 if (vfsp->vfs_flag & VFS_RDONLY)
125 return XFS_ERROR(EROFS);
126 return (xfs_qm_scall_trunc_qfiles(mp,
127 xfs_qm_import_qtype_flags(*(uint *)addr)));
131 * Get quota status information.
133 return (xfs_qm_scall_getqstat(mp, (fs_quota_stat_t *)addr));
137 * QUOTAON - enabling quota enforcement.
138 * Quota accounting must be turned on at mount time.
140 if (vfsp->vfs_flag & VFS_RDONLY)
141 return XFS_ERROR(EROFS);
142 return (xfs_qm_scall_quotaon(mp,
143 xfs_qm_import_flags(*(uint *)addr)));
146 if (vfsp->vfs_flag & VFS_RDONLY)
147 return XFS_ERROR(EROFS);
151 return (xfs_sync_inodes(mp, SYNC_DELWRI, 0, NULL));
157 if (! XFS_IS_QUOTA_ON(mp))
158 return XFS_ERROR(ESRCH);
162 if (vfsp->vfs_flag & VFS_RDONLY)
163 return XFS_ERROR(EROFS);
164 error = xfs_qm_scall_quotaoff(mp,
165 xfs_qm_import_flags(*(uint *)addr),
170 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_USER,
171 (fs_disk_quota_t *)addr);
174 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_GROUP,
175 (fs_disk_quota_t *)addr);
178 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_PROJ,
179 (fs_disk_quota_t *)addr);
183 if (vfsp->vfs_flag & VFS_RDONLY)
184 return XFS_ERROR(EROFS);
185 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_USER,
186 (fs_disk_quota_t *)addr);
189 if (vfsp->vfs_flag & VFS_RDONLY)
190 return XFS_ERROR(EROFS);
191 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_GROUP,
192 (fs_disk_quota_t *)addr);
195 if (vfsp->vfs_flag & VFS_RDONLY)
196 return XFS_ERROR(EROFS);
197 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_PROJ,
198 (fs_disk_quota_t *)addr);
202 error = XFS_ERROR(EINVAL);
210 * Turn off quota accounting and/or enforcement for all udquots and/or
211 * gdquots. Called only at unmount time.
213 * This assumes that there are no dquots of this file system cached
214 * incore, and modifies the ondisk dquot directly. Therefore, for example,
215 * it is an error to call this twice, without purging the cache.
218 xfs_qm_scall_quotaoff(
226 uint inactivate_flags;
227 xfs_qoff_logitem_t *qoffstart;
230 if (!force && !capable(CAP_SYS_ADMIN))
231 return XFS_ERROR(EPERM);
233 * No file system can have quotas enabled on disk but not in core.
234 * Note that quota utilities (like quotaoff) _expect_
235 * errno == EEXIST here.
237 if ((mp->m_qflags & flags) == 0)
238 return XFS_ERROR(EEXIST);
241 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
244 * We don't want to deal with two quotaoffs messing up each other,
245 * so we're going to serialize it. quotaoff isn't exactly a performance
247 * If quotaoff, then we must be dealing with the root filesystem.
249 ASSERT(mp->m_quotainfo);
251 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
253 ASSERT(mp->m_quotainfo);
256 * If we're just turning off quota enforcement, change mp and go.
258 if ((flags & XFS_ALL_QUOTA_ACCT) == 0) {
259 mp->m_qflags &= ~(flags);
262 mp->m_sb.sb_qflags = mp->m_qflags;
263 XFS_SB_UNLOCK(mp, s);
264 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
266 /* XXX what to do if error ? Revert back to old vals incore ? */
267 error = xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS);
272 inactivate_flags = 0;
274 * If accounting is off, we must turn enforcement off, clear the
275 * quota 'CHKD' certificate to make it known that we have to
276 * do a quotacheck the next time this quota is turned on.
278 if (flags & XFS_UQUOTA_ACCT) {
279 dqtype |= XFS_QMOPT_UQUOTA;
280 flags |= (XFS_UQUOTA_CHKD | XFS_UQUOTA_ENFD);
281 inactivate_flags |= XFS_UQUOTA_ACTIVE;
283 if (flags & XFS_GQUOTA_ACCT) {
284 dqtype |= XFS_QMOPT_GQUOTA;
285 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
286 inactivate_flags |= XFS_GQUOTA_ACTIVE;
287 } else if (flags & XFS_PQUOTA_ACCT) {
288 dqtype |= XFS_QMOPT_PQUOTA;
289 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
290 inactivate_flags |= XFS_PQUOTA_ACTIVE;
294 * Nothing to do? Don't complain. This happens when we're just
295 * turning off quota enforcement.
297 if ((mp->m_qflags & flags) == 0) {
298 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
303 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
306 xfs_qm_log_quotaoff(mp, &qoffstart, flags);
309 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
310 * to take care of the race between dqget and quotaoff. We don't take
311 * any special locks to reset these bits. All processes need to check
312 * these bits *after* taking inode lock(s) to see if the particular
313 * quota type is in the process of being turned off. If *ACTIVE, it is
314 * guaranteed that all dquot structures and all quotainode ptrs will all
315 * stay valid as long as that inode is kept locked.
317 * There is no turning back after this.
319 mp->m_qflags &= ~inactivate_flags;
322 * Give back all the dquot reference(s) held by inodes.
323 * Here we go thru every single incore inode in this file system, and
324 * do a dqrele on the i_udquot/i_gdquot that it may have.
325 * Essentially, as long as somebody has an inode locked, this guarantees
326 * that quotas will not be turned off. This is handy because in a
327 * transaction once we lock the inode(s) and check for quotaon, we can
328 * depend on the quota inodes (and other things) being valid as long as
329 * we keep the lock(s).
331 xfs_qm_dqrele_all_inodes(mp, flags);
334 * Next we make the changes in the quota flag in the mount struct.
335 * This isn't protected by a particular lock directly, because we
336 * don't want to take a mrlock everytime we depend on quotas being on.
338 mp->m_qflags &= ~(flags);
341 * Go through all the dquots of this file system and purge them,
342 * according to what was turned off. We may not be able to get rid
343 * of all dquots, because dquots can have temporary references that
344 * are not attached to inodes. eg. xfs_setattr, xfs_create.
345 * So, if we couldn't purge all the dquots from the filesystem,
346 * we can't get rid of the incore data structures.
348 while ((nculprits = xfs_qm_dqpurge_all(mp, dqtype|XFS_QMOPT_QUOTAOFF)))
349 delay(10 * nculprits);
352 * Transactions that had started before ACTIVE state bit was cleared
353 * could have logged many dquots, so they'd have higher LSNs than
354 * the first QUOTAOFF log record does. If we happen to crash when
355 * the tail of the log has gone past the QUOTAOFF record, but
356 * before the last dquot modification, those dquots __will__
357 * recover, and that's not good.
359 * So, we have QUOTAOFF start and end logitems; the start
360 * logitem won't get overwritten until the end logitem appears...
362 xfs_qm_log_quotaoff_end(mp, qoffstart, flags);
365 * If quotas is completely disabled, close shop.
367 if (((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET1) ||
368 ((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET2)) {
369 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
370 xfs_qm_destroy_quotainfo(mp);
375 * Release our quotainode references, and vn_purge them,
376 * if we don't need them anymore.
378 if ((dqtype & XFS_QMOPT_UQUOTA) && XFS_QI_UQIP(mp)) {
379 XFS_PURGE_INODE(XFS_QI_UQIP(mp));
380 XFS_QI_UQIP(mp) = NULL;
382 if ((dqtype & (XFS_QMOPT_GQUOTA|XFS_QMOPT_PQUOTA)) && XFS_QI_GQIP(mp)) {
383 XFS_PURGE_INODE(XFS_QI_GQIP(mp));
384 XFS_QI_GQIP(mp) = NULL;
386 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
392 xfs_qm_scall_trunc_qfiles(
399 if (!capable(CAP_SYS_ADMIN))
400 return XFS_ERROR(EPERM);
402 if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
403 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags);
404 return XFS_ERROR(EINVAL);
407 if ((flags & XFS_DQ_USER) && mp->m_sb.sb_uquotino != NULLFSINO) {
408 error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, 0, 0, &qip, 0);
410 (void) xfs_truncate_file(mp, qip);
411 VN_RELE(XFS_ITOV(qip));
415 if ((flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) &&
416 mp->m_sb.sb_gquotino != NULLFSINO) {
417 error = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, 0, 0, &qip, 0);
419 (void) xfs_truncate_file(mp, qip);
420 VN_RELE(XFS_ITOV(qip));
429 * Switch on (a given) quota enforcement for a filesystem. This takes
430 * effect immediately.
431 * (Switching on quota accounting must be done at mount time.)
434 xfs_qm_scall_quotaon(
444 if (!capable(CAP_SYS_ADMIN))
445 return XFS_ERROR(EPERM);
447 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
449 * Switching on quota accounting must be done at mount time.
451 accflags = flags & XFS_ALL_QUOTA_ACCT;
452 flags &= ~(XFS_ALL_QUOTA_ACCT);
457 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp->m_qflags);
458 return XFS_ERROR(EINVAL);
461 /* No fs can turn on quotas with a delayed effect */
462 ASSERT((flags & XFS_ALL_QUOTA_ACCT) == 0);
465 * Can't enforce without accounting. We check the superblock
466 * qflags here instead of m_qflags because rootfs can have
467 * quota acct on ondisk without m_qflags' knowing.
469 if (((flags & XFS_UQUOTA_ACCT) == 0 &&
470 (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 &&
471 (flags & XFS_UQUOTA_ENFD))
473 ((flags & XFS_PQUOTA_ACCT) == 0 &&
474 (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 &&
475 (flags & XFS_OQUOTA_ENFD))
477 ((flags & XFS_GQUOTA_ACCT) == 0 &&
478 (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 &&
479 (flags & XFS_OQUOTA_ENFD))) {
480 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
481 flags, mp->m_sb.sb_qflags);
482 return XFS_ERROR(EINVAL);
485 * If everything's upto-date incore, then don't waste time.
487 if ((mp->m_qflags & flags) == flags)
488 return XFS_ERROR(EEXIST);
491 * Change sb_qflags on disk but not incore mp->qflags
492 * if this is the root filesystem.
495 qf = mp->m_sb.sb_qflags;
496 mp->m_sb.sb_qflags = qf | flags;
497 XFS_SB_UNLOCK(mp, s);
500 * There's nothing to change if it's the same.
502 if ((qf & flags) == flags && sbflags == 0)
503 return XFS_ERROR(EEXIST);
504 sbflags |= XFS_SB_QFLAGS;
506 if ((error = xfs_qm_write_sb_changes(mp, sbflags)))
509 * If we aren't trying to switch on quota enforcement, we are done.
511 if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) !=
512 (mp->m_qflags & XFS_UQUOTA_ACCT)) ||
513 ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) !=
514 (mp->m_qflags & XFS_PQUOTA_ACCT)) ||
515 ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) !=
516 (mp->m_qflags & XFS_GQUOTA_ACCT)) ||
517 (flags & XFS_ALL_QUOTA_ENFD) == 0)
520 if (! XFS_IS_QUOTA_RUNNING(mp))
521 return XFS_ERROR(ESRCH);
524 * Switch on quota enforcement in core.
526 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
527 mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD);
528 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
535 * Return quota status information, such as uquota-off, enforcements, etc.
538 xfs_qm_scall_getqstat(
540 fs_quota_stat_t *out)
542 xfs_inode_t *uip, *gip;
543 boolean_t tempuqip, tempgqip;
546 tempuqip = tempgqip = B_FALSE;
547 memset(out, 0, sizeof(fs_quota_stat_t));
549 out->qs_version = FS_QSTAT_VERSION;
550 if (! XFS_SB_VERSION_HASQUOTA(&mp->m_sb)) {
551 out->qs_uquota.qfs_ino = NULLFSINO;
552 out->qs_gquota.qfs_ino = NULLFSINO;
555 out->qs_flags = (__uint16_t) xfs_qm_export_flags(mp->m_qflags &
557 XFS_ALL_QUOTA_ENFD));
559 out->qs_uquota.qfs_ino = mp->m_sb.sb_uquotino;
560 out->qs_gquota.qfs_ino = mp->m_sb.sb_gquotino;
562 if (mp->m_quotainfo) {
563 uip = mp->m_quotainfo->qi_uquotaip;
564 gip = mp->m_quotainfo->qi_gquotaip;
566 if (!uip && mp->m_sb.sb_uquotino != NULLFSINO) {
567 if (xfs_iget(mp, NULL, mp->m_sb.sb_uquotino,
571 if (!gip && mp->m_sb.sb_gquotino != NULLFSINO) {
572 if (xfs_iget(mp, NULL, mp->m_sb.sb_gquotino,
577 out->qs_uquota.qfs_nblks = uip->i_d.di_nblocks;
578 out->qs_uquota.qfs_nextents = uip->i_d.di_nextents;
580 VN_RELE(XFS_ITOV(uip));
583 out->qs_gquota.qfs_nblks = gip->i_d.di_nblocks;
584 out->qs_gquota.qfs_nextents = gip->i_d.di_nextents;
586 VN_RELE(XFS_ITOV(gip));
588 if (mp->m_quotainfo) {
589 out->qs_incoredqs = XFS_QI_MPLNDQUOTS(mp);
590 out->qs_btimelimit = XFS_QI_BTIMELIMIT(mp);
591 out->qs_itimelimit = XFS_QI_ITIMELIMIT(mp);
592 out->qs_rtbtimelimit = XFS_QI_RTBTIMELIMIT(mp);
593 out->qs_bwarnlimit = XFS_QI_BWARNLIMIT(mp);
594 out->qs_iwarnlimit = XFS_QI_IWARNLIMIT(mp);
600 * Adjust quota limits, and start/stop timers accordingly.
603 xfs_qm_scall_setqlim(
607 fs_disk_quota_t *newlim)
609 xfs_disk_dquot_t *ddq;
613 xfs_qcnt_t hard, soft;
615 if (!capable(CAP_SYS_ADMIN))
616 return XFS_ERROR(EPERM);
618 if ((newlim->d_fieldmask &
619 (FS_DQ_LIMIT_MASK|FS_DQ_TIMER_MASK|FS_DQ_WARNS_MASK)) == 0)
622 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM);
623 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_disk_dquot_t) + 128,
624 0, 0, XFS_DEFAULT_LOG_COUNT))) {
625 xfs_trans_cancel(tp, 0);
630 * We don't want to race with a quotaoff so take the quotaoff lock.
631 * (We don't hold an inode lock, so there's nothing else to stop
632 * a quotaoff from happening). (XXXThis doesn't currently happen
633 * because we take the vfslock before calling xfs_qm_sysent).
635 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
638 * Get the dquot (locked), and join it to the transaction.
639 * Allocate the dquot if this doesn't exist.
641 if ((error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp))) {
642 xfs_trans_cancel(tp, XFS_TRANS_ABORT);
643 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
644 ASSERT(error != ENOENT);
647 xfs_dqtrace_entry(dqp, "Q_SETQLIM: AFT DQGET");
648 xfs_trans_dqjoin(tp, dqp);
652 * Make sure that hardlimits are >= soft limits before changing.
654 hard = (newlim->d_fieldmask & FS_DQ_BHARD) ?
655 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) :
656 INT_GET(ddq->d_blk_hardlimit, ARCH_CONVERT);
657 soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ?
658 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) :
659 INT_GET(ddq->d_blk_softlimit, ARCH_CONVERT);
660 if (hard == 0 || hard >= soft) {
661 INT_SET(ddq->d_blk_hardlimit, ARCH_CONVERT, hard);
662 INT_SET(ddq->d_blk_softlimit, ARCH_CONVERT, soft);
664 mp->m_quotainfo->qi_bhardlimit = hard;
665 mp->m_quotainfo->qi_bsoftlimit = soft;
668 qdprintk("blkhard %Ld < blksoft %Ld\n", hard, soft);
670 hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ?
671 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) :
672 INT_GET(ddq->d_rtb_hardlimit, ARCH_CONVERT);
673 soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ?
674 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) :
675 INT_GET(ddq->d_rtb_softlimit, ARCH_CONVERT);
676 if (hard == 0 || hard >= soft) {
677 INT_SET(ddq->d_rtb_hardlimit, ARCH_CONVERT, hard);
678 INT_SET(ddq->d_rtb_softlimit, ARCH_CONVERT, soft);
680 mp->m_quotainfo->qi_rtbhardlimit = hard;
681 mp->m_quotainfo->qi_rtbsoftlimit = soft;
684 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard, soft);
687 hard = (newlim->d_fieldmask & FS_DQ_IHARD) ?
688 (xfs_qcnt_t) newlim->d_ino_hardlimit :
689 INT_GET(ddq->d_ino_hardlimit, ARCH_CONVERT);
690 soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ?
691 (xfs_qcnt_t) newlim->d_ino_softlimit :
692 INT_GET(ddq->d_ino_softlimit, ARCH_CONVERT);
693 if (hard == 0 || hard >= soft) {
694 INT_SET(ddq->d_ino_hardlimit, ARCH_CONVERT, hard);
695 INT_SET(ddq->d_ino_softlimit, ARCH_CONVERT, soft);
697 mp->m_quotainfo->qi_ihardlimit = hard;
698 mp->m_quotainfo->qi_isoftlimit = soft;
701 qdprintk("ihard %Ld < isoft %Ld\n", hard, soft);
705 * Update warnings counter(s) if requested
707 if (newlim->d_fieldmask & FS_DQ_BWARNS)
708 INT_SET(ddq->d_bwarns, ARCH_CONVERT, newlim->d_bwarns);
709 if (newlim->d_fieldmask & FS_DQ_IWARNS)
710 INT_SET(ddq->d_iwarns, ARCH_CONVERT, newlim->d_iwarns);
711 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
712 INT_SET(ddq->d_rtbwarns, ARCH_CONVERT, newlim->d_rtbwarns);
716 * Timelimits for the super user set the relative time
717 * the other users can be over quota for this file system.
718 * If it is zero a default is used. Ditto for the default
719 * soft and hard limit values (already done, above), and
722 if (newlim->d_fieldmask & FS_DQ_BTIMER) {
723 mp->m_quotainfo->qi_btimelimit = newlim->d_btimer;
724 INT_SET(ddq->d_btimer, ARCH_CONVERT, newlim->d_btimer);
726 if (newlim->d_fieldmask & FS_DQ_ITIMER) {
727 mp->m_quotainfo->qi_itimelimit = newlim->d_itimer;
728 INT_SET(ddq->d_itimer, ARCH_CONVERT, newlim->d_itimer);
730 if (newlim->d_fieldmask & FS_DQ_RTBTIMER) {
731 mp->m_quotainfo->qi_rtbtimelimit = newlim->d_rtbtimer;
732 INT_SET(ddq->d_rtbtimer, ARCH_CONVERT, newlim->d_rtbtimer);
734 if (newlim->d_fieldmask & FS_DQ_BWARNS)
735 mp->m_quotainfo->qi_bwarnlimit = newlim->d_bwarns;
736 if (newlim->d_fieldmask & FS_DQ_IWARNS)
737 mp->m_quotainfo->qi_iwarnlimit = newlim->d_iwarns;
738 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
739 mp->m_quotainfo->qi_rtbwarnlimit = newlim->d_rtbwarns;
742 * If the user is now over quota, start the timelimit.
743 * The user will not be 'warned'.
744 * Note that we keep the timers ticking, whether enforcement
745 * is on or off. We don't really want to bother with iterating
746 * over all ondisk dquots and turning the timers on/off.
748 xfs_qm_adjust_dqtimers(mp, ddq);
750 dqp->dq_flags |= XFS_DQ_DIRTY;
751 xfs_trans_log_dquot(tp, dqp);
753 xfs_dqtrace_entry(dqp, "Q_SETQLIM: COMMIT");
754 xfs_trans_commit(tp, 0, NULL);
757 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
763 xfs_qm_scall_getquota(
767 fs_disk_quota_t *out)
773 * Try to get the dquot. We don't want it allocated on disk, so
774 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
775 * exist, we'll get ENOENT back.
777 if ((error = xfs_qm_dqget(mp, NULL, id, type, 0, &dqp))) {
781 xfs_dqtrace_entry(dqp, "Q_GETQUOTA SUCCESS");
783 * If everything's NULL, this dquot doesn't quite exist as far as
784 * our utility programs are concerned.
786 if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
788 return XFS_ERROR(ENOENT);
790 /* xfs_qm_dqprint(dqp); */
792 * Convert the disk dquot to the exportable format
794 xfs_qm_export_dquot(mp, &dqp->q_core, out);
796 return (error ? XFS_ERROR(EFAULT) : 0);
801 xfs_qm_log_quotaoff_end(
803 xfs_qoff_logitem_t *startqoff,
808 xfs_qoff_logitem_t *qoffi;
810 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END);
812 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_qoff_logitem_t) * 2,
813 0, 0, XFS_DEFAULT_LOG_COUNT))) {
814 xfs_trans_cancel(tp, 0);
818 qoffi = xfs_trans_get_qoff_item(tp, startqoff,
819 flags & XFS_ALL_QUOTA_ACCT);
820 xfs_trans_log_quotaoff_item(tp, qoffi);
823 * We have to make sure that the transaction is secure on disk before we
824 * return and actually stop quota accounting. So, make it synchronous.
825 * We don't care about quotoff's performance.
827 xfs_trans_set_sync(tp);
828 error = xfs_trans_commit(tp, 0, NULL);
836 xfs_qoff_logitem_t **qoffstartp,
842 xfs_qoff_logitem_t *qoffi=NULL;
845 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF);
846 if ((error = xfs_trans_reserve(tp, 0,
847 sizeof(xfs_qoff_logitem_t) * 2 +
848 mp->m_sb.sb_sectsize + 128,
851 XFS_DEFAULT_LOG_COUNT))) {
855 qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT);
856 xfs_trans_log_quotaoff_item(tp, qoffi);
859 oldsbqflag = mp->m_sb.sb_qflags;
860 mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL;
861 XFS_SB_UNLOCK(mp, s);
863 xfs_mod_sb(tp, XFS_SB_QFLAGS);
866 * We have to make sure that the transaction is secure on disk before we
867 * return and actually stop quota accounting. So, make it synchronous.
868 * We don't care about quotoff's performance.
870 xfs_trans_set_sync(tp);
871 error = xfs_trans_commit(tp, 0, NULL);
875 xfs_trans_cancel(tp, 0);
877 * No one else is modifying sb_qflags, so this is OK.
878 * We still hold the quotaofflock.
881 mp->m_sb.sb_qflags = oldsbqflag;
882 XFS_SB_UNLOCK(mp, s);
890 * Translate an internal style on-disk-dquot to the exportable format.
891 * The main differences are that the counters/limits are all in Basic
892 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
893 * to be converted to the native endianness.
898 xfs_disk_dquot_t *src,
899 struct fs_disk_quota *dst)
901 memset(dst, 0, sizeof(*dst));
902 dst->d_version = FS_DQUOT_VERSION; /* different from src->d_version */
904 xfs_qm_export_qtype_flags(INT_GET(src->d_flags, ARCH_CONVERT));
905 dst->d_id = INT_GET(src->d_id, ARCH_CONVERT);
906 dst->d_blk_hardlimit = (__uint64_t)
907 XFS_FSB_TO_BB(mp, INT_GET(src->d_blk_hardlimit, ARCH_CONVERT));
908 dst->d_blk_softlimit = (__uint64_t)
909 XFS_FSB_TO_BB(mp, INT_GET(src->d_blk_softlimit, ARCH_CONVERT));
910 dst->d_ino_hardlimit = (__uint64_t)
911 INT_GET(src->d_ino_hardlimit, ARCH_CONVERT);
912 dst->d_ino_softlimit = (__uint64_t)
913 INT_GET(src->d_ino_softlimit, ARCH_CONVERT);
914 dst->d_bcount = (__uint64_t)
915 XFS_FSB_TO_BB(mp, INT_GET(src->d_bcount, ARCH_CONVERT));
916 dst->d_icount = (__uint64_t) INT_GET(src->d_icount, ARCH_CONVERT);
917 dst->d_btimer = (__uint32_t) INT_GET(src->d_btimer, ARCH_CONVERT);
918 dst->d_itimer = (__uint32_t) INT_GET(src->d_itimer, ARCH_CONVERT);
919 dst->d_iwarns = INT_GET(src->d_iwarns, ARCH_CONVERT);
920 dst->d_bwarns = INT_GET(src->d_bwarns, ARCH_CONVERT);
922 dst->d_rtb_hardlimit = (__uint64_t)
923 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtb_hardlimit, ARCH_CONVERT));
924 dst->d_rtb_softlimit = (__uint64_t)
925 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtb_softlimit, ARCH_CONVERT));
926 dst->d_rtbcount = (__uint64_t)
927 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtbcount, ARCH_CONVERT));
928 dst->d_rtbtimer = (__uint32_t) INT_GET(src->d_rtbtimer, ARCH_CONVERT);
929 dst->d_rtbwarns = INT_GET(src->d_rtbwarns, ARCH_CONVERT);
932 * Internally, we don't reset all the timers when quota enforcement
933 * gets turned off. No need to confuse the userlevel code,
934 * so return zeroes in that case.
936 if (! XFS_IS_QUOTA_ENFORCED(mp)) {
943 if (XFS_IS_QUOTA_ENFORCED(mp) && dst->d_id != 0) {
944 if (((int) dst->d_bcount >= (int) dst->d_blk_softlimit) &&
945 (dst->d_blk_softlimit > 0)) {
946 ASSERT(dst->d_btimer != 0);
948 if (((int) dst->d_icount >= (int) dst->d_ino_softlimit) &&
949 (dst->d_ino_softlimit > 0)) {
950 ASSERT(dst->d_itimer != 0);
957 xfs_qm_import_qtype_flags(
963 * Can't be more than one, or none.
965 if (((uflags & (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) ==
966 (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) ||
967 ((uflags & (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) ==
968 (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) ||
969 ((uflags & (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) ==
970 (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) ||
971 ((uflags & (XFS_GROUP_QUOTA|XFS_USER_QUOTA|XFS_PROJ_QUOTA)) == 0))
974 oflags |= (uflags & XFS_USER_QUOTA) ? XFS_DQ_USER : 0;
975 oflags |= (uflags & XFS_PROJ_QUOTA) ? XFS_DQ_PROJ : 0;
976 oflags |= (uflags & XFS_GROUP_QUOTA) ? XFS_DQ_GROUP: 0;
981 xfs_qm_export_qtype_flags(
985 * Can't be more than one, or none.
987 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_USER_QUOTA)) !=
988 (XFS_PROJ_QUOTA | XFS_USER_QUOTA));
989 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)) !=
990 (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA));
991 ASSERT((flags & (XFS_USER_QUOTA | XFS_GROUP_QUOTA)) !=
992 (XFS_USER_QUOTA | XFS_GROUP_QUOTA));
993 ASSERT((flags & (XFS_PROJ_QUOTA|XFS_USER_QUOTA|XFS_GROUP_QUOTA)) != 0);
995 return (flags & XFS_DQ_USER) ?
996 XFS_USER_QUOTA : (flags & XFS_DQ_PROJ) ?
997 XFS_PROJ_QUOTA : XFS_GROUP_QUOTA;
1001 xfs_qm_import_flags(
1006 if (uflags & XFS_QUOTA_UDQ_ACCT)
1007 flags |= XFS_UQUOTA_ACCT;
1008 if (uflags & XFS_QUOTA_PDQ_ACCT)
1009 flags |= XFS_PQUOTA_ACCT;
1010 if (uflags & XFS_QUOTA_GDQ_ACCT)
1011 flags |= XFS_GQUOTA_ACCT;
1012 if (uflags & XFS_QUOTA_UDQ_ENFD)
1013 flags |= XFS_UQUOTA_ENFD;
1014 if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
1015 flags |= XFS_OQUOTA_ENFD;
1021 xfs_qm_export_flags(
1027 if (flags & XFS_UQUOTA_ACCT)
1028 uflags |= XFS_QUOTA_UDQ_ACCT;
1029 if (flags & XFS_PQUOTA_ACCT)
1030 uflags |= XFS_QUOTA_PDQ_ACCT;
1031 if (flags & XFS_GQUOTA_ACCT)
1032 uflags |= XFS_QUOTA_GDQ_ACCT;
1033 if (flags & XFS_UQUOTA_ENFD)
1034 uflags |= XFS_QUOTA_UDQ_ENFD;
1035 if (flags & (XFS_OQUOTA_ENFD)) {
1036 uflags |= (flags & XFS_GQUOTA_ACCT) ?
1037 XFS_QUOTA_GDQ_ENFD : XFS_QUOTA_PDQ_ENFD;
1044 * Go thru all the inodes in the file system, releasing their dquots.
1045 * Note that the mount structure gets modified to indicate that quotas are off
1046 * AFTER this, in the case of quotaoff. This also gets called from
1050 xfs_qm_dqrele_all_inodes(
1051 struct xfs_mount *mp,
1054 xfs_inode_t *ip, *topino;
1057 boolean_t vnode_refd;
1059 ASSERT(mp->m_quotainfo);
1061 XFS_MOUNT_ILOCK(mp);
1065 XFS_MOUNT_IUNLOCK(mp);
1069 /* Skip markers inserted by xfs_sync */
1070 if (ip->i_mount == NULL) {
1074 /* Root inode, rbmip and rsumip have associated blocks */
1075 if (ip == XFS_QI_UQIP(mp) || ip == XFS_QI_GQIP(mp)) {
1076 ASSERT(ip->i_udquot == NULL);
1077 ASSERT(ip->i_gdquot == NULL);
1081 vp = XFS_ITOV_NULL(ip);
1083 ASSERT(ip->i_udquot == NULL);
1084 ASSERT(ip->i_gdquot == NULL);
1088 vnode_refd = B_FALSE;
1089 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1090 ireclaims = mp->m_ireclaims;
1091 topino = mp->m_inodes;
1096 XFS_MOUNT_IUNLOCK(mp);
1097 /* XXX restart limit ? */
1098 xfs_ilock(ip, XFS_ILOCK_EXCL);
1099 vnode_refd = B_TRUE;
1101 ireclaims = mp->m_ireclaims;
1102 topino = mp->m_inodes;
1103 XFS_MOUNT_IUNLOCK(mp);
1107 * We don't keep the mountlock across the dqrele() call,
1108 * since it can take a while..
1110 if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) {
1111 xfs_qm_dqrele(ip->i_udquot);
1112 ip->i_udquot = NULL;
1114 if (flags & (XFS_PQUOTA_ACCT|XFS_GQUOTA_ACCT) && ip->i_gdquot) {
1115 xfs_qm_dqrele(ip->i_gdquot);
1116 ip->i_gdquot = NULL;
1118 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1120 * Wait until we've dropped the ilock and mountlock to
1121 * do the vn_rele. Or be condemned to an eternity in the
1122 * inactive code in hell.
1126 XFS_MOUNT_ILOCK(mp);
1128 * If an inode was inserted or removed, we gotta
1131 if (topino != mp->m_inodes || mp->m_ireclaims != ireclaims) {
1132 /* XXX use a sentinel */
1136 } while (ip != mp->m_inodes);
1138 XFS_MOUNT_IUNLOCK(mp);
1141 /*------------------------------------------------------------------------*/
1144 * This contains all the test functions for XFS disk quotas.
1145 * Currently it does a quota accounting check. ie. it walks through
1146 * all inodes in the file system, calculating the dquot accounting fields,
1147 * and prints out any inconsistencies.
1149 xfs_dqhash_t *qmtest_udqtab;
1150 xfs_dqhash_t *qmtest_gdqtab;
1151 int qmtest_hashmask;
1153 mutex_t qcheck_lock;
1155 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1156 (__psunsigned_t)(id)) & \
1157 (qmtest_hashmask - 1))
1159 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1161 DQTEST_HASHVAL(mp, id)) : \
1163 DQTEST_HASHVAL(mp, id)))
1165 #define DQTEST_LIST_PRINT(l, NXT, title) \
1167 xfs_dqtest_t *dqp; int i = 0;\
1168 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1169 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1170 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1171 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1172 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1173 dqp->d_bcount, dqp->d_icount); } \
1176 typedef struct dqtest {
1177 xfs_dqmarker_t q_lists;
1178 xfs_dqhash_t *q_hash; /* the hashchain header */
1179 xfs_mount_t *q_mount; /* filesystem this relates to */
1180 xfs_dqid_t d_id; /* user id or group id */
1181 xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */
1182 xfs_qcnt_t d_icount; /* # inodes owned by the user */
1186 xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp)
1189 if (((d) = (h)->qh_next))
1190 (d)->HL_PREVP = &((dqp)->HL_NEXT);
1192 (dqp)->HL_PREVP = &((h)->qh_next);
1193 (h)->qh_next = (xfs_dquot_t *)dqp;
1198 xfs_qm_dqtest_print(
1201 cmn_err(CE_DEBUG, "-----------DQTEST DQUOT----------------");
1202 cmn_err(CE_DEBUG, "---- dquot ID = %d", d->d_id);
1203 cmn_err(CE_DEBUG, "---- fs = 0x%p", d->q_mount);
1204 cmn_err(CE_DEBUG, "---- bcount = %Lu (0x%x)",
1205 d->d_bcount, (int)d->d_bcount);
1206 cmn_err(CE_DEBUG, "---- icount = %Lu (0x%x)",
1207 d->d_icount, (int)d->d_icount);
1208 cmn_err(CE_DEBUG, "---------------------------");
1212 xfs_qm_dqtest_failed(
1222 cmn_err(CE_DEBUG, "quotacheck failed id=%d, err=%d\nreason: %s",
1223 INT_GET(d->d_id, ARCH_CONVERT), error, reason);
1225 cmn_err(CE_DEBUG, "quotacheck failed id=%d (%s) [%d != %d]",
1226 INT_GET(d->d_id, ARCH_CONVERT), reason, (int)a, (int)b);
1227 xfs_qm_dqtest_print(d);
1229 xfs_qm_dqprint(dqp);
1238 if (INT_GET(dqp->q_core.d_icount, ARCH_CONVERT) != d->d_icount) {
1239 xfs_qm_dqtest_failed(d, dqp, "icount mismatch",
1240 INT_GET(dqp->q_core.d_icount, ARCH_CONVERT),
1244 if (INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT) != d->d_bcount) {
1245 xfs_qm_dqtest_failed(d, dqp, "bcount mismatch",
1246 INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT),
1250 if (INT_GET(dqp->q_core.d_blk_softlimit, ARCH_CONVERT) &&
1251 INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT) >=
1252 INT_GET(dqp->q_core.d_blk_softlimit, ARCH_CONVERT)) {
1253 if (!dqp->q_core.d_btimer && dqp->q_core.d_id) {
1255 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1256 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1260 if (INT_GET(dqp->q_core.d_ino_softlimit, ARCH_CONVERT) &&
1261 INT_GET(dqp->q_core.d_icount, ARCH_CONVERT) >=
1262 INT_GET(dqp->q_core.d_ino_softlimit, ARCH_CONVERT)) {
1263 if (!dqp->q_core.d_itimer && dqp->q_core.d_id) {
1265 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1266 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1272 cmn_err(CE_DEBUG, "%d [%s] [0x%p] qchecked",
1273 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1286 /* xfs_qm_dqtest_print(d); */
1287 if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0,
1289 xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error);
1292 xfs_dqtest_cmp2(d, dqp);
1297 xfs_qm_internalqcheck_dqget(
1301 xfs_dqtest_t **O_dq)
1306 h = DQTEST_HASH(mp, id, type);
1307 for (d = (xfs_dqtest_t *) h->qh_next; d != NULL;
1308 d = (xfs_dqtest_t *) d->HL_NEXT) {
1309 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1310 if (d->d_id == id && mp == d->q_mount) {
1315 d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP);
1320 xfs_qm_hashinsert(h, d);
1326 xfs_qm_internalqcheck_get_dquots(
1334 if (XFS_IS_UQUOTA_ON(mp))
1335 xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud);
1336 if (XFS_IS_GQUOTA_ON(mp))
1337 xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd);
1338 else if (XFS_IS_PQUOTA_ON(mp))
1339 xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd);
1344 xfs_qm_internalqcheck_dqadjust(
1349 d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks;
1353 xfs_qm_internalqcheck_adjust(
1354 xfs_mount_t *mp, /* mount point for filesystem */
1355 xfs_ino_t ino, /* inode number to get data for */
1356 void __user *buffer, /* not used */
1357 int ubsize, /* not used */
1358 void *private_data, /* not used */
1359 xfs_daddr_t bno, /* starting block of inode cluster */
1360 int *ubused, /* not used */
1361 void *dip, /* not used */
1362 int *res) /* bulkstat result code */
1365 xfs_dqtest_t *ud, *gd;
1367 boolean_t ipreleased;
1370 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
1372 if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) {
1373 *res = BULKSTAT_RV_NOTHING;
1374 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1375 (unsigned long long) ino,
1376 (unsigned long long) mp->m_sb.sb_uquotino,
1377 (unsigned long long) mp->m_sb.sb_gquotino);
1378 return XFS_ERROR(EINVAL);
1380 ipreleased = B_FALSE;
1382 lock_flags = XFS_ILOCK_SHARED;
1383 if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip, bno))) {
1384 *res = BULKSTAT_RV_NOTHING;
1388 if (ip->i_d.di_mode == 0) {
1389 xfs_iput_new(ip, lock_flags);
1390 *res = BULKSTAT_RV_NOTHING;
1391 return XFS_ERROR(ENOENT);
1395 * This inode can have blocks after eof which can get released
1396 * when we send it to inactive. Since we don't check the dquot
1397 * until the after all our calculations are done, we must get rid
1401 xfs_iput(ip, lock_flags);
1402 ipreleased = B_TRUE;
1405 xfs_qm_internalqcheck_get_dquots(mp,
1406 (xfs_dqid_t) ip->i_d.di_uid,
1407 (xfs_dqid_t) ip->i_d.di_projid,
1408 (xfs_dqid_t) ip->i_d.di_gid,
1410 if (XFS_IS_UQUOTA_ON(mp)) {
1412 xfs_qm_internalqcheck_dqadjust(ip, ud);
1414 if (XFS_IS_OQUOTA_ON(mp)) {
1416 xfs_qm_internalqcheck_dqadjust(ip, gd);
1418 xfs_iput(ip, lock_flags);
1419 *res = BULKSTAT_RV_DIDONE;
1424 /* PRIVATE, debugging */
1426 xfs_qm_internalqcheck(
1432 xfs_dqtest_t *d, *e;
1437 qmtest_hashmask = 32;
1442 if (! XFS_IS_QUOTA_ON(mp))
1443 return XFS_ERROR(ESRCH);
1445 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1446 XFS_bflush(mp->m_ddev_targp);
1447 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1448 XFS_bflush(mp->m_ddev_targp);
1450 mutex_lock(&qcheck_lock, PINOD);
1451 /* There should be absolutely no quota activity while this
1453 qmtest_udqtab = kmem_zalloc(qmtest_hashmask *
1454 sizeof(xfs_dqhash_t), KM_SLEEP);
1455 qmtest_gdqtab = kmem_zalloc(qmtest_hashmask *
1456 sizeof(xfs_dqhash_t), KM_SLEEP);
1459 * Iterate thru all the inodes in the file system,
1460 * adjusting the corresponding dquot counters
1462 if ((error = xfs_bulkstat(mp, &lastino, &count,
1463 xfs_qm_internalqcheck_adjust, NULL,
1464 0, NULL, BULKSTAT_FG_IGET, &done))) {
1469 cmn_err(CE_DEBUG, "Bulkstat returned error 0x%x", error);
1471 cmn_err(CE_DEBUG, "Checking results against system dquots");
1472 for (i = 0; i < qmtest_hashmask; i++) {
1473 h1 = &qmtest_udqtab[i];
1474 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1476 e = (xfs_dqtest_t *) d->HL_NEXT;
1477 kmem_free(d, sizeof(xfs_dqtest_t));
1480 h1 = &qmtest_gdqtab[i];
1481 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1483 e = (xfs_dqtest_t *) d->HL_NEXT;
1484 kmem_free(d, sizeof(xfs_dqtest_t));
1489 if (qmtest_nfails) {
1490 cmn_err(CE_DEBUG, "******** quotacheck failed ********");
1491 cmn_err(CE_DEBUG, "failures = %d", qmtest_nfails);
1493 cmn_err(CE_DEBUG, "******** quotacheck successful! ********");
1495 kmem_free(qmtest_udqtab, qmtest_hashmask * sizeof(xfs_dqhash_t));
1496 kmem_free(qmtest_gdqtab, qmtest_hashmask * sizeof(xfs_dqhash_t));
1497 mutex_unlock(&qcheck_lock);
1498 return (qmtest_nfails);