2 * Copyright (c) 2000-2003 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/
37 #include "xfs_trans.h"
41 #include "xfs_alloc.h"
42 #include "xfs_dmapi.h"
43 #include "xfs_quota.h"
44 #include "xfs_mount.h"
45 #include "xfs_alloc_btree.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_btree.h"
49 #include "xfs_ialloc.h"
50 #include "xfs_attr_sf.h"
51 #include "xfs_dir_sf.h"
52 #include "xfs_dir2_sf.h"
53 #include "xfs_dinode.h"
54 #include "xfs_inode.h"
57 #include "xfs_rtalloc.h"
58 #include "xfs_error.h"
59 #include "xfs_itable.h"
65 #include "xfs_buf_item.h"
66 #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);
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);
154 if (! XFS_IS_QUOTA_ON(mp))
155 return XFS_ERROR(ESRCH);
159 if (vfsp->vfs_flag & VFS_RDONLY)
160 return XFS_ERROR(EROFS);
161 error = xfs_qm_scall_quotaoff(mp,
162 xfs_qm_import_flags(*(uint *)addr),
167 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_USER,
168 (fs_disk_quota_t *)addr);
171 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_GROUP,
172 (fs_disk_quota_t *)addr);
175 error = xfs_qm_scall_getquota(mp, (xfs_dqid_t)id, XFS_DQ_PROJ,
176 (fs_disk_quota_t *)addr);
180 if (vfsp->vfs_flag & VFS_RDONLY)
181 return XFS_ERROR(EROFS);
182 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_USER,
183 (fs_disk_quota_t *)addr);
186 if (vfsp->vfs_flag & VFS_RDONLY)
187 return XFS_ERROR(EROFS);
188 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_GROUP,
189 (fs_disk_quota_t *)addr);
192 if (vfsp->vfs_flag & VFS_RDONLY)
193 return XFS_ERROR(EROFS);
194 error = xfs_qm_scall_setqlim(mp, (xfs_dqid_t)id, XFS_DQ_PROJ,
195 (fs_disk_quota_t *)addr);
199 error = XFS_ERROR(EINVAL);
207 * Turn off quota accounting and/or enforcement for all udquots and/or
208 * gdquots. Called only at unmount time.
210 * This assumes that there are no dquots of this file system cached
211 * incore, and modifies the ondisk dquot directly. Therefore, for example,
212 * it is an error to call this twice, without purging the cache.
215 xfs_qm_scall_quotaoff(
223 uint inactivate_flags;
224 xfs_qoff_logitem_t *qoffstart;
227 if (!force && !capable(CAP_SYS_ADMIN))
228 return XFS_ERROR(EPERM);
230 * No file system can have quotas enabled on disk but not in core.
231 * Note that quota utilities (like quotaoff) _expect_
232 * errno == EEXIST here.
234 if ((mp->m_qflags & flags) == 0)
235 return XFS_ERROR(EEXIST);
238 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
241 * We don't want to deal with two quotaoffs messing up each other,
242 * so we're going to serialize it. quotaoff isn't exactly a performance
244 * If quotaoff, then we must be dealing with the root filesystem.
246 ASSERT(mp->m_quotainfo);
248 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
250 ASSERT(mp->m_quotainfo);
253 * If we're just turning off quota enforcement, change mp and go.
255 if ((flags & XFS_ALL_QUOTA_ACCT) == 0) {
256 mp->m_qflags &= ~(flags);
259 mp->m_sb.sb_qflags = mp->m_qflags;
260 XFS_SB_UNLOCK(mp, s);
261 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
263 /* XXX what to do if error ? Revert back to old vals incore ? */
264 error = xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS);
269 inactivate_flags = 0;
271 * If accounting is off, we must turn enforcement off, clear the
272 * quota 'CHKD' certificate to make it known that we have to
273 * do a quotacheck the next time this quota is turned on.
275 if (flags & XFS_UQUOTA_ACCT) {
276 dqtype |= XFS_QMOPT_UQUOTA;
277 flags |= (XFS_UQUOTA_CHKD | XFS_UQUOTA_ENFD);
278 inactivate_flags |= XFS_UQUOTA_ACTIVE;
280 if (flags & XFS_GQUOTA_ACCT) {
281 dqtype |= XFS_QMOPT_GQUOTA;
282 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
283 inactivate_flags |= XFS_GQUOTA_ACTIVE;
284 } else if (flags & XFS_PQUOTA_ACCT) {
285 dqtype |= XFS_QMOPT_PQUOTA;
286 flags |= (XFS_OQUOTA_CHKD | XFS_OQUOTA_ENFD);
287 inactivate_flags |= XFS_PQUOTA_ACTIVE;
291 * Nothing to do? Don't complain. This happens when we're just
292 * turning off quota enforcement.
294 if ((mp->m_qflags & flags) == 0) {
295 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
300 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
303 xfs_qm_log_quotaoff(mp, &qoffstart, flags);
306 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
307 * to take care of the race between dqget and quotaoff. We don't take
308 * any special locks to reset these bits. All processes need to check
309 * these bits *after* taking inode lock(s) to see if the particular
310 * quota type is in the process of being turned off. If *ACTIVE, it is
311 * guaranteed that all dquot structures and all quotainode ptrs will all
312 * stay valid as long as that inode is kept locked.
314 * There is no turning back after this.
316 mp->m_qflags &= ~inactivate_flags;
319 * Give back all the dquot reference(s) held by inodes.
320 * Here we go thru every single incore inode in this file system, and
321 * do a dqrele on the i_udquot/i_gdquot that it may have.
322 * Essentially, as long as somebody has an inode locked, this guarantees
323 * that quotas will not be turned off. This is handy because in a
324 * transaction once we lock the inode(s) and check for quotaon, we can
325 * depend on the quota inodes (and other things) being valid as long as
326 * we keep the lock(s).
328 xfs_qm_dqrele_all_inodes(mp, flags);
331 * Next we make the changes in the quota flag in the mount struct.
332 * This isn't protected by a particular lock directly, because we
333 * don't want to take a mrlock everytime we depend on quotas being on.
335 mp->m_qflags &= ~(flags);
338 * Go through all the dquots of this file system and purge them,
339 * according to what was turned off. We may not be able to get rid
340 * of all dquots, because dquots can have temporary references that
341 * are not attached to inodes. eg. xfs_setattr, xfs_create.
342 * So, if we couldn't purge all the dquots from the filesystem,
343 * we can't get rid of the incore data structures.
345 while ((nculprits = xfs_qm_dqpurge_all(mp, dqtype|XFS_QMOPT_QUOTAOFF)))
346 delay(10 * nculprits);
349 * Transactions that had started before ACTIVE state bit was cleared
350 * could have logged many dquots, so they'd have higher LSNs than
351 * the first QUOTAOFF log record does. If we happen to crash when
352 * the tail of the log has gone past the QUOTAOFF record, but
353 * before the last dquot modification, those dquots __will__
354 * recover, and that's not good.
356 * So, we have QUOTAOFF start and end logitems; the start
357 * logitem won't get overwritten until the end logitem appears...
359 xfs_qm_log_quotaoff_end(mp, qoffstart, flags);
362 * If quotas is completely disabled, close shop.
364 if (((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET1) ||
365 ((flags & XFS_MOUNT_QUOTA_ALL) == XFS_MOUNT_QUOTA_SET2)) {
366 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
367 xfs_qm_destroy_quotainfo(mp);
372 * Release our quotainode references, and vn_purge them,
373 * if we don't need them anymore.
375 if ((dqtype & XFS_QMOPT_UQUOTA) && XFS_QI_UQIP(mp)) {
376 XFS_PURGE_INODE(XFS_QI_UQIP(mp));
377 XFS_QI_UQIP(mp) = NULL;
379 if ((dqtype & (XFS_QMOPT_GQUOTA|XFS_QMOPT_PQUOTA)) && XFS_QI_GQIP(mp)) {
380 XFS_PURGE_INODE(XFS_QI_GQIP(mp));
381 XFS_QI_GQIP(mp) = NULL;
383 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
389 xfs_qm_scall_trunc_qfiles(
396 if (!capable(CAP_SYS_ADMIN))
397 return XFS_ERROR(EPERM);
399 if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
400 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags);
401 return XFS_ERROR(EINVAL);
404 if ((flags & XFS_DQ_USER) && mp->m_sb.sb_uquotino != NULLFSINO) {
405 error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, 0, 0, &qip, 0);
407 (void) xfs_truncate_file(mp, qip);
408 VN_RELE(XFS_ITOV(qip));
412 if ((flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) &&
413 mp->m_sb.sb_gquotino != NULLFSINO) {
414 error = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, 0, 0, &qip, 0);
416 (void) xfs_truncate_file(mp, qip);
417 VN_RELE(XFS_ITOV(qip));
426 * Switch on (a given) quota enforcement for a filesystem. This takes
427 * effect immediately.
428 * (Switching on quota accounting must be done at mount time.)
431 xfs_qm_scall_quotaon(
441 if (!capable(CAP_SYS_ADMIN))
442 return XFS_ERROR(EPERM);
444 flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
446 * Switching on quota accounting must be done at mount time.
448 accflags = flags & XFS_ALL_QUOTA_ACCT;
449 flags &= ~(XFS_ALL_QUOTA_ACCT);
454 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp->m_qflags);
455 return XFS_ERROR(EINVAL);
458 /* No fs can turn on quotas with a delayed effect */
459 ASSERT((flags & XFS_ALL_QUOTA_ACCT) == 0);
462 * Can't enforce without accounting. We check the superblock
463 * qflags here instead of m_qflags because rootfs can have
464 * quota acct on ondisk without m_qflags' knowing.
466 if (((flags & XFS_UQUOTA_ACCT) == 0 &&
467 (mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) == 0 &&
468 (flags & XFS_UQUOTA_ENFD))
470 ((flags & XFS_PQUOTA_ACCT) == 0 &&
471 (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) == 0 &&
472 (flags & XFS_OQUOTA_ENFD))
474 ((flags & XFS_GQUOTA_ACCT) == 0 &&
475 (mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) == 0 &&
476 (flags & XFS_OQUOTA_ENFD))) {
477 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
478 flags, mp->m_sb.sb_qflags);
479 return XFS_ERROR(EINVAL);
482 * If everything's upto-date incore, then don't waste time.
484 if ((mp->m_qflags & flags) == flags)
485 return XFS_ERROR(EEXIST);
488 * Change sb_qflags on disk but not incore mp->qflags
489 * if this is the root filesystem.
492 qf = mp->m_sb.sb_qflags;
493 mp->m_sb.sb_qflags = qf | flags;
494 XFS_SB_UNLOCK(mp, s);
497 * There's nothing to change if it's the same.
499 if ((qf & flags) == flags && sbflags == 0)
500 return XFS_ERROR(EEXIST);
501 sbflags |= XFS_SB_QFLAGS;
503 if ((error = xfs_qm_write_sb_changes(mp, sbflags)))
506 * If we aren't trying to switch on quota enforcement, we are done.
508 if (((mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT) !=
509 (mp->m_qflags & XFS_UQUOTA_ACCT)) ||
510 ((mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT) !=
511 (mp->m_qflags & XFS_PQUOTA_ACCT)) ||
512 ((mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT) !=
513 (mp->m_qflags & XFS_GQUOTA_ACCT)) ||
514 (flags & XFS_ALL_QUOTA_ENFD) == 0)
517 if (! XFS_IS_QUOTA_RUNNING(mp))
518 return XFS_ERROR(ESRCH);
521 * Switch on quota enforcement in core.
523 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
524 mp->m_qflags |= (flags & XFS_ALL_QUOTA_ENFD);
525 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
532 * Return quota status information, such as uquota-off, enforcements, etc.
535 xfs_qm_scall_getqstat(
537 fs_quota_stat_t *out)
539 xfs_inode_t *uip, *gip;
540 boolean_t tempuqip, tempgqip;
543 tempuqip = tempgqip = B_FALSE;
544 memset(out, 0, sizeof(fs_quota_stat_t));
546 out->qs_version = FS_QSTAT_VERSION;
547 if (! XFS_SB_VERSION_HASQUOTA(&mp->m_sb)) {
548 out->qs_uquota.qfs_ino = NULLFSINO;
549 out->qs_gquota.qfs_ino = NULLFSINO;
552 out->qs_flags = (__uint16_t) xfs_qm_export_flags(mp->m_qflags &
554 XFS_ALL_QUOTA_ENFD));
556 out->qs_uquota.qfs_ino = mp->m_sb.sb_uquotino;
557 out->qs_gquota.qfs_ino = mp->m_sb.sb_gquotino;
559 if (mp->m_quotainfo) {
560 uip = mp->m_quotainfo->qi_uquotaip;
561 gip = mp->m_quotainfo->qi_gquotaip;
563 if (!uip && mp->m_sb.sb_uquotino != NULLFSINO) {
564 if (xfs_iget(mp, NULL, mp->m_sb.sb_uquotino,
568 if (!gip && mp->m_sb.sb_gquotino != NULLFSINO) {
569 if (xfs_iget(mp, NULL, mp->m_sb.sb_gquotino,
574 out->qs_uquota.qfs_nblks = uip->i_d.di_nblocks;
575 out->qs_uquota.qfs_nextents = uip->i_d.di_nextents;
577 VN_RELE(XFS_ITOV(uip));
580 out->qs_gquota.qfs_nblks = gip->i_d.di_nblocks;
581 out->qs_gquota.qfs_nextents = gip->i_d.di_nextents;
583 VN_RELE(XFS_ITOV(gip));
585 if (mp->m_quotainfo) {
586 out->qs_incoredqs = XFS_QI_MPLNDQUOTS(mp);
587 out->qs_btimelimit = XFS_QI_BTIMELIMIT(mp);
588 out->qs_itimelimit = XFS_QI_ITIMELIMIT(mp);
589 out->qs_rtbtimelimit = XFS_QI_RTBTIMELIMIT(mp);
590 out->qs_bwarnlimit = XFS_QI_BWARNLIMIT(mp);
591 out->qs_iwarnlimit = XFS_QI_IWARNLIMIT(mp);
597 * Adjust quota limits, and start/stop timers accordingly.
600 xfs_qm_scall_setqlim(
604 fs_disk_quota_t *newlim)
606 xfs_disk_dquot_t *ddq;
610 xfs_qcnt_t hard, soft;
612 if (!capable(CAP_SYS_ADMIN))
613 return XFS_ERROR(EPERM);
615 if ((newlim->d_fieldmask &
616 (FS_DQ_LIMIT_MASK|FS_DQ_TIMER_MASK|FS_DQ_WARNS_MASK)) == 0)
619 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SETQLIM);
620 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_disk_dquot_t) + 128,
621 0, 0, XFS_DEFAULT_LOG_COUNT))) {
622 xfs_trans_cancel(tp, 0);
627 * We don't want to race with a quotaoff so take the quotaoff lock.
628 * (We don't hold an inode lock, so there's nothing else to stop
629 * a quotaoff from happening). (XXXThis doesn't currently happen
630 * because we take the vfslock before calling xfs_qm_sysent).
632 mutex_lock(&(XFS_QI_QOFFLOCK(mp)), PINOD);
635 * Get the dquot (locked), and join it to the transaction.
636 * Allocate the dquot if this doesn't exist.
638 if ((error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp))) {
639 xfs_trans_cancel(tp, XFS_TRANS_ABORT);
640 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
641 ASSERT(error != ENOENT);
644 xfs_dqtrace_entry(dqp, "Q_SETQLIM: AFT DQGET");
645 xfs_trans_dqjoin(tp, dqp);
649 * Make sure that hardlimits are >= soft limits before changing.
651 hard = (newlim->d_fieldmask & FS_DQ_BHARD) ?
652 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) :
653 INT_GET(ddq->d_blk_hardlimit, ARCH_CONVERT);
654 soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ?
655 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) :
656 INT_GET(ddq->d_blk_softlimit, ARCH_CONVERT);
657 if (hard == 0 || hard >= soft) {
658 INT_SET(ddq->d_blk_hardlimit, ARCH_CONVERT, hard);
659 INT_SET(ddq->d_blk_softlimit, ARCH_CONVERT, soft);
661 mp->m_quotainfo->qi_bhardlimit = hard;
662 mp->m_quotainfo->qi_bsoftlimit = soft;
665 qdprintk("blkhard %Ld < blksoft %Ld\n", hard, soft);
667 hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ?
668 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) :
669 INT_GET(ddq->d_rtb_hardlimit, ARCH_CONVERT);
670 soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ?
671 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) :
672 INT_GET(ddq->d_rtb_softlimit, ARCH_CONVERT);
673 if (hard == 0 || hard >= soft) {
674 INT_SET(ddq->d_rtb_hardlimit, ARCH_CONVERT, hard);
675 INT_SET(ddq->d_rtb_softlimit, ARCH_CONVERT, soft);
677 mp->m_quotainfo->qi_rtbhardlimit = hard;
678 mp->m_quotainfo->qi_rtbsoftlimit = soft;
681 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard, soft);
684 hard = (newlim->d_fieldmask & FS_DQ_IHARD) ?
685 (xfs_qcnt_t) newlim->d_ino_hardlimit :
686 INT_GET(ddq->d_ino_hardlimit, ARCH_CONVERT);
687 soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ?
688 (xfs_qcnt_t) newlim->d_ino_softlimit :
689 INT_GET(ddq->d_ino_softlimit, ARCH_CONVERT);
690 if (hard == 0 || hard >= soft) {
691 INT_SET(ddq->d_ino_hardlimit, ARCH_CONVERT, hard);
692 INT_SET(ddq->d_ino_softlimit, ARCH_CONVERT, soft);
694 mp->m_quotainfo->qi_ihardlimit = hard;
695 mp->m_quotainfo->qi_isoftlimit = soft;
698 qdprintk("ihard %Ld < isoft %Ld\n", hard, soft);
702 * Update warnings counter(s) if requested
704 if (newlim->d_fieldmask & FS_DQ_BWARNS)
705 INT_SET(ddq->d_bwarns, ARCH_CONVERT, newlim->d_bwarns);
706 if (newlim->d_fieldmask & FS_DQ_IWARNS)
707 INT_SET(ddq->d_iwarns, ARCH_CONVERT, newlim->d_iwarns);
708 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
709 INT_SET(ddq->d_rtbwarns, ARCH_CONVERT, newlim->d_rtbwarns);
713 * Timelimits for the super user set the relative time
714 * the other users can be over quota for this file system.
715 * If it is zero a default is used. Ditto for the default
716 * soft and hard limit values (already done, above), and
719 if (newlim->d_fieldmask & FS_DQ_BTIMER) {
720 mp->m_quotainfo->qi_btimelimit = newlim->d_btimer;
721 INT_SET(ddq->d_btimer, ARCH_CONVERT, newlim->d_btimer);
723 if (newlim->d_fieldmask & FS_DQ_ITIMER) {
724 mp->m_quotainfo->qi_itimelimit = newlim->d_itimer;
725 INT_SET(ddq->d_itimer, ARCH_CONVERT, newlim->d_itimer);
727 if (newlim->d_fieldmask & FS_DQ_RTBTIMER) {
728 mp->m_quotainfo->qi_rtbtimelimit = newlim->d_rtbtimer;
729 INT_SET(ddq->d_rtbtimer, ARCH_CONVERT, newlim->d_rtbtimer);
731 if (newlim->d_fieldmask & FS_DQ_BWARNS)
732 mp->m_quotainfo->qi_bwarnlimit = newlim->d_bwarns;
733 if (newlim->d_fieldmask & FS_DQ_IWARNS)
734 mp->m_quotainfo->qi_iwarnlimit = newlim->d_iwarns;
735 if (newlim->d_fieldmask & FS_DQ_RTBWARNS)
736 mp->m_quotainfo->qi_rtbwarnlimit = newlim->d_rtbwarns;
739 * If the user is now over quota, start the timelimit.
740 * The user will not be 'warned'.
741 * Note that we keep the timers ticking, whether enforcement
742 * is on or off. We don't really want to bother with iterating
743 * over all ondisk dquots and turning the timers on/off.
745 xfs_qm_adjust_dqtimers(mp, ddq);
747 dqp->dq_flags |= XFS_DQ_DIRTY;
748 xfs_trans_log_dquot(tp, dqp);
750 xfs_dqtrace_entry(dqp, "Q_SETQLIM: COMMIT");
751 xfs_trans_commit(tp, 0, NULL);
754 mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
760 xfs_qm_scall_getquota(
764 fs_disk_quota_t *out)
770 * Try to get the dquot. We don't want it allocated on disk, so
771 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
772 * exist, we'll get ENOENT back.
774 if ((error = xfs_qm_dqget(mp, NULL, id, type, 0, &dqp))) {
778 xfs_dqtrace_entry(dqp, "Q_GETQUOTA SUCCESS");
780 * If everything's NULL, this dquot doesn't quite exist as far as
781 * our utility programs are concerned.
783 if (XFS_IS_DQUOT_UNINITIALIZED(dqp)) {
785 return XFS_ERROR(ENOENT);
787 /* xfs_qm_dqprint(dqp); */
789 * Convert the disk dquot to the exportable format
791 xfs_qm_export_dquot(mp, &dqp->q_core, out);
793 return (error ? XFS_ERROR(EFAULT) : 0);
798 xfs_qm_log_quotaoff_end(
800 xfs_qoff_logitem_t *startqoff,
805 xfs_qoff_logitem_t *qoffi;
807 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF_END);
809 if ((error = xfs_trans_reserve(tp, 0, sizeof(xfs_qoff_logitem_t) * 2,
810 0, 0, XFS_DEFAULT_LOG_COUNT))) {
811 xfs_trans_cancel(tp, 0);
815 qoffi = xfs_trans_get_qoff_item(tp, startqoff,
816 flags & XFS_ALL_QUOTA_ACCT);
817 xfs_trans_log_quotaoff_item(tp, qoffi);
820 * We have to make sure that the transaction is secure on disk before we
821 * return and actually stop quota accounting. So, make it synchronous.
822 * We don't care about quotoff's performance.
824 xfs_trans_set_sync(tp);
825 error = xfs_trans_commit(tp, 0, NULL);
833 xfs_qoff_logitem_t **qoffstartp,
839 xfs_qoff_logitem_t *qoffi=NULL;
842 tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QUOTAOFF);
843 if ((error = xfs_trans_reserve(tp, 0,
844 sizeof(xfs_qoff_logitem_t) * 2 +
845 mp->m_sb.sb_sectsize + 128,
848 XFS_DEFAULT_LOG_COUNT))) {
852 qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT);
853 xfs_trans_log_quotaoff_item(tp, qoffi);
856 oldsbqflag = mp->m_sb.sb_qflags;
857 mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL;
858 XFS_SB_UNLOCK(mp, s);
860 xfs_mod_sb(tp, XFS_SB_QFLAGS);
863 * We have to make sure that the transaction is secure on disk before we
864 * return and actually stop quota accounting. So, make it synchronous.
865 * We don't care about quotoff's performance.
867 xfs_trans_set_sync(tp);
868 error = xfs_trans_commit(tp, 0, NULL);
872 xfs_trans_cancel(tp, 0);
874 * No one else is modifying sb_qflags, so this is OK.
875 * We still hold the quotaofflock.
878 mp->m_sb.sb_qflags = oldsbqflag;
879 XFS_SB_UNLOCK(mp, s);
887 * Translate an internal style on-disk-dquot to the exportable format.
888 * The main differences are that the counters/limits are all in Basic
889 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
890 * to be converted to the native endianness.
895 xfs_disk_dquot_t *src,
896 struct fs_disk_quota *dst)
898 memset(dst, 0, sizeof(*dst));
899 dst->d_version = FS_DQUOT_VERSION; /* different from src->d_version */
901 xfs_qm_export_qtype_flags(INT_GET(src->d_flags, ARCH_CONVERT));
902 dst->d_id = INT_GET(src->d_id, ARCH_CONVERT);
903 dst->d_blk_hardlimit = (__uint64_t)
904 XFS_FSB_TO_BB(mp, INT_GET(src->d_blk_hardlimit, ARCH_CONVERT));
905 dst->d_blk_softlimit = (__uint64_t)
906 XFS_FSB_TO_BB(mp, INT_GET(src->d_blk_softlimit, ARCH_CONVERT));
907 dst->d_ino_hardlimit = (__uint64_t)
908 INT_GET(src->d_ino_hardlimit, ARCH_CONVERT);
909 dst->d_ino_softlimit = (__uint64_t)
910 INT_GET(src->d_ino_softlimit, ARCH_CONVERT);
911 dst->d_bcount = (__uint64_t)
912 XFS_FSB_TO_BB(mp, INT_GET(src->d_bcount, ARCH_CONVERT));
913 dst->d_icount = (__uint64_t) INT_GET(src->d_icount, ARCH_CONVERT);
914 dst->d_btimer = (__uint32_t) INT_GET(src->d_btimer, ARCH_CONVERT);
915 dst->d_itimer = (__uint32_t) INT_GET(src->d_itimer, ARCH_CONVERT);
916 dst->d_iwarns = INT_GET(src->d_iwarns, ARCH_CONVERT);
917 dst->d_bwarns = INT_GET(src->d_bwarns, ARCH_CONVERT);
919 dst->d_rtb_hardlimit = (__uint64_t)
920 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtb_hardlimit, ARCH_CONVERT));
921 dst->d_rtb_softlimit = (__uint64_t)
922 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtb_softlimit, ARCH_CONVERT));
923 dst->d_rtbcount = (__uint64_t)
924 XFS_FSB_TO_BB(mp, INT_GET(src->d_rtbcount, ARCH_CONVERT));
925 dst->d_rtbtimer = (__uint32_t) INT_GET(src->d_rtbtimer, ARCH_CONVERT);
926 dst->d_rtbwarns = INT_GET(src->d_rtbwarns, ARCH_CONVERT);
929 * Internally, we don't reset all the timers when quota enforcement
930 * gets turned off. No need to confuse the userlevel code,
931 * so return zeroes in that case.
933 if (! XFS_IS_QUOTA_ENFORCED(mp)) {
940 if (XFS_IS_QUOTA_ENFORCED(mp) && dst->d_id != 0) {
941 if (((int) dst->d_bcount >= (int) dst->d_blk_softlimit) &&
942 (dst->d_blk_softlimit > 0)) {
943 ASSERT(dst->d_btimer != 0);
945 if (((int) dst->d_icount >= (int) dst->d_ino_softlimit) &&
946 (dst->d_ino_softlimit > 0)) {
947 ASSERT(dst->d_itimer != 0);
954 xfs_qm_import_qtype_flags(
960 * Can't be more than one, or none.
962 if (((uflags & (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) ==
963 (XFS_GROUP_QUOTA | XFS_USER_QUOTA)) ||
964 ((uflags & (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) ==
965 (XFS_GROUP_QUOTA | XFS_PROJ_QUOTA)) ||
966 ((uflags & (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) ==
967 (XFS_USER_QUOTA | XFS_PROJ_QUOTA)) ||
968 ((uflags & (XFS_GROUP_QUOTA|XFS_USER_QUOTA|XFS_PROJ_QUOTA)) == 0))
971 oflags |= (uflags & XFS_USER_QUOTA) ? XFS_DQ_USER : 0;
972 oflags |= (uflags & XFS_PROJ_QUOTA) ? XFS_DQ_PROJ : 0;
973 oflags |= (uflags & XFS_GROUP_QUOTA) ? XFS_DQ_GROUP: 0;
978 xfs_qm_export_qtype_flags(
982 * Can't be more than one, or none.
984 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_USER_QUOTA)) !=
985 (XFS_PROJ_QUOTA | XFS_USER_QUOTA));
986 ASSERT((flags & (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA)) !=
987 (XFS_PROJ_QUOTA | XFS_GROUP_QUOTA));
988 ASSERT((flags & (XFS_USER_QUOTA | XFS_GROUP_QUOTA)) !=
989 (XFS_USER_QUOTA | XFS_GROUP_QUOTA));
990 ASSERT((flags & (XFS_PROJ_QUOTA|XFS_USER_QUOTA|XFS_GROUP_QUOTA)) != 0);
992 return (flags & XFS_DQ_USER) ?
993 XFS_USER_QUOTA : (flags & XFS_DQ_PROJ) ?
994 XFS_PROJ_QUOTA : XFS_GROUP_QUOTA;
1003 if (uflags & XFS_QUOTA_UDQ_ACCT)
1004 flags |= XFS_UQUOTA_ACCT;
1005 if (uflags & XFS_QUOTA_PDQ_ACCT)
1006 flags |= XFS_PQUOTA_ACCT;
1007 if (uflags & XFS_QUOTA_GDQ_ACCT)
1008 flags |= XFS_GQUOTA_ACCT;
1009 if (uflags & XFS_QUOTA_UDQ_ENFD)
1010 flags |= XFS_UQUOTA_ENFD;
1011 if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
1012 flags |= XFS_OQUOTA_ENFD;
1018 xfs_qm_export_flags(
1024 if (flags & XFS_UQUOTA_ACCT)
1025 uflags |= XFS_QUOTA_UDQ_ACCT;
1026 if (flags & XFS_PQUOTA_ACCT)
1027 uflags |= XFS_QUOTA_PDQ_ACCT;
1028 if (flags & XFS_GQUOTA_ACCT)
1029 uflags |= XFS_QUOTA_GDQ_ACCT;
1030 if (flags & XFS_UQUOTA_ENFD)
1031 uflags |= XFS_QUOTA_UDQ_ENFD;
1032 if (flags & (XFS_OQUOTA_ENFD)) {
1033 uflags |= (flags & XFS_GQUOTA_ACCT) ?
1034 XFS_QUOTA_GDQ_ENFD : XFS_QUOTA_PDQ_ENFD;
1041 * Go thru all the inodes in the file system, releasing their dquots.
1042 * Note that the mount structure gets modified to indicate that quotas are off
1043 * AFTER this, in the case of quotaoff. This also gets called from
1047 xfs_qm_dqrele_all_inodes(
1048 struct xfs_mount *mp,
1051 xfs_inode_t *ip, *topino;
1054 boolean_t vnode_refd;
1056 ASSERT(mp->m_quotainfo);
1058 XFS_MOUNT_ILOCK(mp);
1062 XFS_MOUNT_IUNLOCK(mp);
1066 /* Skip markers inserted by xfs_sync */
1067 if (ip->i_mount == NULL) {
1071 /* Root inode, rbmip and rsumip have associated blocks */
1072 if (ip == XFS_QI_UQIP(mp) || ip == XFS_QI_GQIP(mp)) {
1073 ASSERT(ip->i_udquot == NULL);
1074 ASSERT(ip->i_gdquot == NULL);
1078 vp = XFS_ITOV_NULL(ip);
1080 ASSERT(ip->i_udquot == NULL);
1081 ASSERT(ip->i_gdquot == NULL);
1085 vnode_refd = B_FALSE;
1086 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1087 ireclaims = mp->m_ireclaims;
1088 topino = mp->m_inodes;
1093 XFS_MOUNT_IUNLOCK(mp);
1094 /* XXX restart limit ? */
1095 xfs_ilock(ip, XFS_ILOCK_EXCL);
1096 vnode_refd = B_TRUE;
1098 ireclaims = mp->m_ireclaims;
1099 topino = mp->m_inodes;
1100 XFS_MOUNT_IUNLOCK(mp);
1104 * We don't keep the mountlock across the dqrele() call,
1105 * since it can take a while..
1107 if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) {
1108 xfs_qm_dqrele(ip->i_udquot);
1109 ip->i_udquot = NULL;
1111 if (flags & (XFS_PQUOTA_ACCT|XFS_GQUOTA_ACCT) && ip->i_gdquot) {
1112 xfs_qm_dqrele(ip->i_gdquot);
1113 ip->i_gdquot = NULL;
1115 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1117 * Wait until we've dropped the ilock and mountlock to
1118 * do the vn_rele. Or be condemned to an eternity in the
1119 * inactive code in hell.
1123 XFS_MOUNT_ILOCK(mp);
1125 * If an inode was inserted or removed, we gotta
1128 if (topino != mp->m_inodes || mp->m_ireclaims != ireclaims) {
1129 /* XXX use a sentinel */
1133 } while (ip != mp->m_inodes);
1135 XFS_MOUNT_IUNLOCK(mp);
1138 /*------------------------------------------------------------------------*/
1141 * This contains all the test functions for XFS disk quotas.
1142 * Currently it does a quota accounting check. ie. it walks through
1143 * all inodes in the file system, calculating the dquot accounting fields,
1144 * and prints out any inconsistencies.
1146 xfs_dqhash_t *qmtest_udqtab;
1147 xfs_dqhash_t *qmtest_gdqtab;
1148 int qmtest_hashmask;
1150 mutex_t qcheck_lock;
1152 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1153 (__psunsigned_t)(id)) & \
1154 (qmtest_hashmask - 1))
1156 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1158 DQTEST_HASHVAL(mp, id)) : \
1160 DQTEST_HASHVAL(mp, id)))
1162 #define DQTEST_LIST_PRINT(l, NXT, title) \
1164 xfs_dqtest_t *dqp; int i = 0;\
1165 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1166 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1167 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1168 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1169 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1170 dqp->d_bcount, dqp->d_icount); } \
1173 typedef struct dqtest {
1174 xfs_dqmarker_t q_lists;
1175 xfs_dqhash_t *q_hash; /* the hashchain header */
1176 xfs_mount_t *q_mount; /* filesystem this relates to */
1177 xfs_dqid_t d_id; /* user id or group id */
1178 xfs_qcnt_t d_bcount; /* # disk blocks owned by the user */
1179 xfs_qcnt_t d_icount; /* # inodes owned by the user */
1183 xfs_qm_hashinsert(xfs_dqhash_t *h, xfs_dqtest_t *dqp)
1186 if (((d) = (h)->qh_next))
1187 (d)->HL_PREVP = &((dqp)->HL_NEXT);
1189 (dqp)->HL_PREVP = &((h)->qh_next);
1190 (h)->qh_next = (xfs_dquot_t *)dqp;
1195 xfs_qm_dqtest_print(
1198 cmn_err(CE_DEBUG, "-----------DQTEST DQUOT----------------");
1199 cmn_err(CE_DEBUG, "---- dquot ID = %d", d->d_id);
1200 cmn_err(CE_DEBUG, "---- fs = 0x%p", d->q_mount);
1201 cmn_err(CE_DEBUG, "---- bcount = %Lu (0x%x)",
1202 d->d_bcount, (int)d->d_bcount);
1203 cmn_err(CE_DEBUG, "---- icount = %Lu (0x%x)",
1204 d->d_icount, (int)d->d_icount);
1205 cmn_err(CE_DEBUG, "---------------------------");
1209 xfs_qm_dqtest_failed(
1219 cmn_err(CE_DEBUG, "quotacheck failed id=%d, err=%d\nreason: %s",
1220 INT_GET(d->d_id, ARCH_CONVERT), error, reason);
1222 cmn_err(CE_DEBUG, "quotacheck failed id=%d (%s) [%d != %d]",
1223 INT_GET(d->d_id, ARCH_CONVERT), reason, (int)a, (int)b);
1224 xfs_qm_dqtest_print(d);
1226 xfs_qm_dqprint(dqp);
1235 if (INT_GET(dqp->q_core.d_icount, ARCH_CONVERT) != d->d_icount) {
1236 xfs_qm_dqtest_failed(d, dqp, "icount mismatch",
1237 INT_GET(dqp->q_core.d_icount, ARCH_CONVERT),
1241 if (INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT) != d->d_bcount) {
1242 xfs_qm_dqtest_failed(d, dqp, "bcount mismatch",
1243 INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT),
1247 if (INT_GET(dqp->q_core.d_blk_softlimit, ARCH_CONVERT) &&
1248 INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT) >=
1249 INT_GET(dqp->q_core.d_blk_softlimit, ARCH_CONVERT)) {
1250 if (!dqp->q_core.d_btimer && dqp->q_core.d_id) {
1252 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1253 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1257 if (INT_GET(dqp->q_core.d_ino_softlimit, ARCH_CONVERT) &&
1258 INT_GET(dqp->q_core.d_icount, ARCH_CONVERT) >=
1259 INT_GET(dqp->q_core.d_ino_softlimit, ARCH_CONVERT)) {
1260 if (!dqp->q_core.d_itimer && dqp->q_core.d_id) {
1262 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1263 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1269 cmn_err(CE_DEBUG, "%d [%s] [0x%p] qchecked",
1270 d->d_id, DQFLAGTO_TYPESTR(d), d->q_mount);
1283 /* xfs_qm_dqtest_print(d); */
1284 if ((error = xfs_qm_dqget(d->q_mount, NULL, d->d_id, d->dq_flags, 0,
1286 xfs_qm_dqtest_failed(d, NULL, "dqget failed", 0, 0, error);
1289 xfs_dqtest_cmp2(d, dqp);
1294 xfs_qm_internalqcheck_dqget(
1298 xfs_dqtest_t **O_dq)
1303 h = DQTEST_HASH(mp, id, type);
1304 for (d = (xfs_dqtest_t *) h->qh_next; d != NULL;
1305 d = (xfs_dqtest_t *) d->HL_NEXT) {
1306 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1307 if (d->d_id == id && mp == d->q_mount) {
1312 d = kmem_zalloc(sizeof(xfs_dqtest_t), KM_SLEEP);
1317 xfs_qm_hashinsert(h, d);
1323 xfs_qm_internalqcheck_get_dquots(
1331 if (XFS_IS_UQUOTA_ON(mp))
1332 xfs_qm_internalqcheck_dqget(mp, uid, XFS_DQ_USER, ud);
1333 if (XFS_IS_GQUOTA_ON(mp))
1334 xfs_qm_internalqcheck_dqget(mp, gid, XFS_DQ_GROUP, gd);
1335 else if (XFS_IS_PQUOTA_ON(mp))
1336 xfs_qm_internalqcheck_dqget(mp, projid, XFS_DQ_PROJ, gd);
1341 xfs_qm_internalqcheck_dqadjust(
1346 d->d_bcount += (xfs_qcnt_t)ip->i_d.di_nblocks;
1350 xfs_qm_internalqcheck_adjust(
1351 xfs_mount_t *mp, /* mount point for filesystem */
1352 xfs_ino_t ino, /* inode number to get data for */
1353 void __user *buffer, /* not used */
1354 int ubsize, /* not used */
1355 void *private_data, /* not used */
1356 xfs_daddr_t bno, /* starting block of inode cluster */
1357 int *ubused, /* not used */
1358 void *dip, /* not used */
1359 int *res) /* bulkstat result code */
1362 xfs_dqtest_t *ud, *gd;
1364 boolean_t ipreleased;
1367 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
1369 if (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino) {
1370 *res = BULKSTAT_RV_NOTHING;
1371 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1372 (unsigned long long) ino,
1373 (unsigned long long) mp->m_sb.sb_uquotino,
1374 (unsigned long long) mp->m_sb.sb_gquotino);
1375 return XFS_ERROR(EINVAL);
1377 ipreleased = B_FALSE;
1379 lock_flags = XFS_ILOCK_SHARED;
1380 if ((error = xfs_iget(mp, NULL, ino, 0, lock_flags, &ip, bno))) {
1381 *res = BULKSTAT_RV_NOTHING;
1385 if (ip->i_d.di_mode == 0) {
1386 xfs_iput_new(ip, lock_flags);
1387 *res = BULKSTAT_RV_NOTHING;
1388 return XFS_ERROR(ENOENT);
1392 * This inode can have blocks after eof which can get released
1393 * when we send it to inactive. Since we don't check the dquot
1394 * until the after all our calculations are done, we must get rid
1398 xfs_iput(ip, lock_flags);
1399 ipreleased = B_TRUE;
1402 xfs_qm_internalqcheck_get_dquots(mp,
1403 (xfs_dqid_t) ip->i_d.di_uid,
1404 (xfs_dqid_t) ip->i_d.di_projid,
1405 (xfs_dqid_t) ip->i_d.di_gid,
1407 if (XFS_IS_UQUOTA_ON(mp)) {
1409 xfs_qm_internalqcheck_dqadjust(ip, ud);
1411 if (XFS_IS_OQUOTA_ON(mp)) {
1413 xfs_qm_internalqcheck_dqadjust(ip, gd);
1415 xfs_iput(ip, lock_flags);
1416 *res = BULKSTAT_RV_DIDONE;
1421 /* PRIVATE, debugging */
1423 xfs_qm_internalqcheck(
1429 xfs_dqtest_t *d, *e;
1434 qmtest_hashmask = 32;
1439 if (! XFS_IS_QUOTA_ON(mp))
1440 return XFS_ERROR(ESRCH);
1442 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1443 XFS_bflush(mp->m_ddev_targp);
1444 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
1445 XFS_bflush(mp->m_ddev_targp);
1447 mutex_lock(&qcheck_lock, PINOD);
1448 /* There should be absolutely no quota activity while this
1450 qmtest_udqtab = kmem_zalloc(qmtest_hashmask *
1451 sizeof(xfs_dqhash_t), KM_SLEEP);
1452 qmtest_gdqtab = kmem_zalloc(qmtest_hashmask *
1453 sizeof(xfs_dqhash_t), KM_SLEEP);
1456 * Iterate thru all the inodes in the file system,
1457 * adjusting the corresponding dquot counters
1459 if ((error = xfs_bulkstat(mp, &lastino, &count,
1460 xfs_qm_internalqcheck_adjust, NULL,
1461 0, NULL, BULKSTAT_FG_IGET, &done))) {
1466 cmn_err(CE_DEBUG, "Bulkstat returned error 0x%x", error);
1468 cmn_err(CE_DEBUG, "Checking results against system dquots");
1469 for (i = 0; i < qmtest_hashmask; i++) {
1470 h1 = &qmtest_udqtab[i];
1471 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1473 e = (xfs_dqtest_t *) d->HL_NEXT;
1474 kmem_free(d, sizeof(xfs_dqtest_t));
1477 h1 = &qmtest_gdqtab[i];
1478 for (d = (xfs_dqtest_t *) h1->qh_next; d != NULL; ) {
1480 e = (xfs_dqtest_t *) d->HL_NEXT;
1481 kmem_free(d, sizeof(xfs_dqtest_t));
1486 if (qmtest_nfails) {
1487 cmn_err(CE_DEBUG, "******** quotacheck failed ********");
1488 cmn_err(CE_DEBUG, "failures = %d", qmtest_nfails);
1490 cmn_err(CE_DEBUG, "******** quotacheck successful! ********");
1492 kmem_free(qmtest_udqtab, qmtest_hashmask * sizeof(xfs_dqhash_t));
1493 kmem_free(qmtest_gdqtab, qmtest_hashmask * sizeof(xfs_dqhash_t));
1494 mutex_unlock(&qcheck_lock);
1495 return (qmtest_nfails);