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 if (addr
== NULL
&& cmd
!= Q_SYNC
)
113 return XFS_ERROR(EINVAL
);
114 if (id
< 0 && cmd
!= Q_SYNC
)
115 return XFS_ERROR(EINVAL
);
118 * The following commands are valid even when quotaoff.
122 * truncate quota files. quota must be off.
125 if (XFS_IS_QUOTA_ON(mp
) || addr
== NULL
)
126 return XFS_ERROR(EINVAL
);
127 if (vfsp
->vfs_flag
& VFS_RDONLY
)
128 return XFS_ERROR(EROFS
);
129 return (xfs_qm_scall_trunc_qfiles(mp
,
130 xfs_qm_import_qtype_flags(*(uint
*)addr
)));
132 * Get quota status information.
135 return (xfs_qm_scall_getqstat(mp
, (fs_quota_stat_t
*)addr
));
138 * QUOTAON for root f/s and quota enforcement on others..
139 * Quota accounting for non-root f/s's must be turned on
144 return XFS_ERROR(EINVAL
);
145 if (vfsp
->vfs_flag
& VFS_RDONLY
)
146 return XFS_ERROR(EROFS
);
147 return (xfs_qm_scall_quotaon(mp
,
148 xfs_qm_import_flags(*(uint
*)addr
)));
150 if (vfsp
->vfs_flag
& VFS_RDONLY
)
151 return XFS_ERROR(EROFS
);
158 if (! XFS_IS_QUOTA_ON(mp
))
159 return XFS_ERROR(ESRCH
);
163 if (vfsp
->vfs_flag
& VFS_RDONLY
)
164 return XFS_ERROR(EROFS
);
165 error
= xfs_qm_scall_quotaoff(mp
,
166 xfs_qm_import_flags(*(uint
*)addr
),
171 * Defaults to XFS_GETUQUOTA.
174 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
175 (fs_disk_quota_t
*)addr
);
178 * Set limits, both hard and soft. Defaults to Q_SETUQLIM.
181 if (vfsp
->vfs_flag
& VFS_RDONLY
)
182 return XFS_ERROR(EROFS
);
183 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
184 (fs_disk_quota_t
*)addr
);
188 if (vfsp
->vfs_flag
& VFS_RDONLY
)
189 return XFS_ERROR(EROFS
);
190 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
191 (fs_disk_quota_t
*)addr
);
196 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
197 (fs_disk_quota_t
*)addr
);
201 * Quotas are entirely undefined after quotaoff in XFS quotas.
202 * For instance, there's no way to set limits when quotaoff.
206 error
= XFS_ERROR(EINVAL
);
214 * Turn off quota accounting and/or enforcement for all udquots and/or
215 * gdquots. Called only at unmount time.
217 * This assumes that there are no dquots of this file system cached
218 * incore, and modifies the ondisk dquot directly. Therefore, for example,
219 * it is an error to call this twice, without purging the cache.
222 xfs_qm_scall_quotaoff(
230 uint inactivate_flags
;
231 xfs_qoff_logitem_t
*qoffstart
;
234 if (!force
&& !capable(CAP_SYS_ADMIN
))
235 return XFS_ERROR(EPERM
);
237 * No file system can have quotas enabled on disk but not in core.
238 * Note that quota utilities (like quotaoff) _expect_
239 * errno == EEXIST here.
241 if ((mp
->m_qflags
& flags
) == 0)
242 return XFS_ERROR(EEXIST
);
245 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
248 * We don't want to deal with two quotaoffs messing up each other,
249 * so we're going to serialize it. quotaoff isn't exactly a performance
251 * If quotaoff, then we must be dealing with the root filesystem.
253 ASSERT(mp
->m_quotainfo
);
255 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
257 ASSERT(mp
->m_quotainfo
);
260 * If we're just turning off quota enforcement, change mp and go.
262 if ((flags
& XFS_ALL_QUOTA_ACCT
) == 0) {
263 mp
->m_qflags
&= ~(flags
);
266 mp
->m_sb
.sb_qflags
= mp
->m_qflags
;
267 XFS_SB_UNLOCK(mp
, s
);
268 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
270 /* XXX what to do if error ? Revert back to old vals incore ? */
271 error
= xfs_qm_write_sb_changes(mp
, XFS_SB_QFLAGS
);
276 inactivate_flags
= 0;
278 * If accounting is off, we must turn enforcement off, clear the
279 * quota 'CHKD' certificate to make it known that we have to
280 * do a quotacheck the next time this quota is turned on.
282 if (flags
& XFS_UQUOTA_ACCT
) {
283 dqtype
|= XFS_QMOPT_UQUOTA
;
284 flags
|= (XFS_UQUOTA_CHKD
| XFS_UQUOTA_ENFD
);
285 inactivate_flags
|= XFS_UQUOTA_ACTIVE
;
287 if (flags
& XFS_GQUOTA_ACCT
) {
288 dqtype
|= XFS_QMOPT_GQUOTA
;
289 flags
|= (XFS_GQUOTA_CHKD
| XFS_GQUOTA_ENFD
);
290 inactivate_flags
|= XFS_GQUOTA_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_ALL
) {
368 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
369 xfs_qm_destroy_quotainfo(mp
);
374 * Release our quotainode references, and vn_purge them,
375 * if we don't need them anymore.
377 if ((dqtype
& XFS_QMOPT_UQUOTA
) && XFS_QI_UQIP(mp
)) {
378 XFS_PURGE_INODE(XFS_QI_UQIP(mp
));
379 XFS_QI_UQIP(mp
) = NULL
;
381 if ((dqtype
& XFS_QMOPT_GQUOTA
) && XFS_QI_GQIP(mp
)) {
382 XFS_PURGE_INODE(XFS_QI_GQIP(mp
));
383 XFS_QI_GQIP(mp
) = NULL
;
385 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
391 xfs_qm_scall_trunc_qfiles(
398 if (!capable(CAP_SYS_ADMIN
))
399 return XFS_ERROR(EPERM
);
401 if (!XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) || flags
== 0) {
402 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags
, mp
->m_qflags
);
403 return XFS_ERROR(EINVAL
);
406 if ((flags
& XFS_DQ_USER
) && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
407 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
, 0, 0, &qip
, 0);
409 (void) xfs_truncate_file(mp
, qip
);
410 VN_RELE(XFS_ITOV(qip
));
414 if ((flags
& XFS_DQ_GROUP
) && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
415 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
, 0, 0, &qip
, 0);
417 (void) xfs_truncate_file(mp
, qip
);
418 VN_RELE(XFS_ITOV(qip
));
427 * Switch on (a given) quota enforcement for a filesystem. This takes
428 * effect immediately.
429 * (Switching on quota accounting must be done at mount time.)
432 xfs_qm_scall_quotaon(
442 if (!capable(CAP_SYS_ADMIN
))
443 return XFS_ERROR(EPERM
);
445 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
447 * Switching on quota accounting must be done at mount time.
449 accflags
= flags
& XFS_ALL_QUOTA_ACCT
;
450 flags
&= ~(XFS_ALL_QUOTA_ACCT
);
455 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp
->m_qflags
);
456 return XFS_ERROR(EINVAL
);
459 /* No fs can turn on quotas with a delayed effect */
460 ASSERT((flags
& XFS_ALL_QUOTA_ACCT
) == 0);
463 * Can't enforce without accounting. We check the superblock
464 * qflags here instead of m_qflags because rootfs can have
465 * quota acct on ondisk without m_qflags' knowing.
467 if (((flags
& XFS_UQUOTA_ACCT
) == 0 &&
468 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) == 0 &&
469 (flags
& XFS_UQUOTA_ENFD
))
471 ((flags
& XFS_GQUOTA_ACCT
) == 0 &&
472 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) == 0 &&
473 (flags
& XFS_GQUOTA_ENFD
))) {
474 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
475 flags
, mp
->m_sb
.sb_qflags
);
476 return XFS_ERROR(EINVAL
);
479 * If everything's upto-date incore, then don't waste time.
481 if ((mp
->m_qflags
& flags
) == flags
)
482 return XFS_ERROR(EEXIST
);
485 * Change sb_qflags on disk but not incore mp->qflags
486 * if this is the root filesystem.
489 qf
= mp
->m_sb
.sb_qflags
;
490 mp
->m_sb
.sb_qflags
= qf
| flags
;
491 XFS_SB_UNLOCK(mp
, s
);
494 * There's nothing to change if it's the same.
496 if ((qf
& flags
) == flags
&& sbflags
== 0)
497 return XFS_ERROR(EEXIST
);
498 sbflags
|= XFS_SB_QFLAGS
;
500 if ((error
= xfs_qm_write_sb_changes(mp
, sbflags
)))
503 * If we aren't trying to switch on quota enforcement, we are done.
505 if (((mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) !=
506 (mp
->m_qflags
& XFS_UQUOTA_ACCT
)) ||
507 (flags
& XFS_ALL_QUOTA_ENFD
) == 0)
510 if (! XFS_IS_QUOTA_RUNNING(mp
))
511 return XFS_ERROR(ESRCH
);
514 * Switch on quota enforcement in core.
516 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
517 mp
->m_qflags
|= (flags
& XFS_ALL_QUOTA_ENFD
);
518 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
526 * Return quota status information, such as uquota-off, enforcements, etc.
529 xfs_qm_scall_getqstat(
531 fs_quota_stat_t
*out
)
533 xfs_inode_t
*uip
, *gip
;
534 boolean_t tempuqip
, tempgqip
;
537 tempuqip
= tempgqip
= B_FALSE
;
538 memset(out
, 0, sizeof(fs_quota_stat_t
));
540 out
->qs_version
= FS_QSTAT_VERSION
;
541 if (! XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
)) {
542 out
->qs_uquota
.qfs_ino
= NULLFSINO
;
543 out
->qs_gquota
.qfs_ino
= NULLFSINO
;
546 out
->qs_flags
= (__uint16_t
) xfs_qm_export_flags(mp
->m_qflags
&
548 XFS_ALL_QUOTA_ENFD
));
550 out
->qs_uquota
.qfs_ino
= mp
->m_sb
.sb_uquotino
;
551 out
->qs_gquota
.qfs_ino
= mp
->m_sb
.sb_gquotino
;
553 if (mp
->m_quotainfo
) {
554 uip
= mp
->m_quotainfo
->qi_uquotaip
;
555 gip
= mp
->m_quotainfo
->qi_gquotaip
;
557 if (!uip
&& mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
558 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
,
562 if (!gip
&& mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
563 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
,
568 out
->qs_uquota
.qfs_nblks
= uip
->i_d
.di_nblocks
;
569 out
->qs_uquota
.qfs_nextents
= uip
->i_d
.di_nextents
;
571 VN_RELE(XFS_ITOV(uip
));
574 out
->qs_gquota
.qfs_nblks
= gip
->i_d
.di_nblocks
;
575 out
->qs_gquota
.qfs_nextents
= gip
->i_d
.di_nextents
;
577 VN_RELE(XFS_ITOV(gip
));
579 if (mp
->m_quotainfo
) {
580 out
->qs_incoredqs
= XFS_QI_MPLNDQUOTS(mp
);
581 out
->qs_btimelimit
= XFS_QI_BTIMELIMIT(mp
);
582 out
->qs_itimelimit
= XFS_QI_ITIMELIMIT(mp
);
583 out
->qs_rtbtimelimit
= XFS_QI_RTBTIMELIMIT(mp
);
584 out
->qs_bwarnlimit
= XFS_QI_BWARNLIMIT(mp
);
585 out
->qs_iwarnlimit
= XFS_QI_IWARNLIMIT(mp
);
591 * Adjust quota limits, and start/stop timers accordingly.
594 xfs_qm_scall_setqlim(
598 fs_disk_quota_t
*newlim
)
600 xfs_disk_dquot_t
*ddq
;
604 xfs_qcnt_t hard
, soft
;
606 if (!capable(CAP_SYS_ADMIN
))
607 return XFS_ERROR(EPERM
);
609 if ((newlim
->d_fieldmask
& (FS_DQ_LIMIT_MASK
|FS_DQ_TIMER_MASK
)) == 0)
612 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_SETQLIM
);
613 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_disk_dquot_t
) + 128,
614 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
615 xfs_trans_cancel(tp
, 0);
620 * We don't want to race with a quotaoff so take the quotaoff lock.
621 * (We don't hold an inode lock, so there's nothing else to stop
622 * a quotaoff from happening). (XXXThis doesn't currently happen
623 * because we take the vfslock before calling xfs_qm_sysent).
625 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
628 * Get the dquot (locked), and join it to the transaction.
629 * Allocate the dquot if this doesn't exist.
631 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, XFS_QMOPT_DQALLOC
, &dqp
))) {
632 xfs_trans_cancel(tp
, XFS_TRANS_ABORT
);
633 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
634 ASSERT(error
!= ENOENT
);
637 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: AFT DQGET");
638 xfs_trans_dqjoin(tp
, dqp
);
642 * Make sure that hardlimits are >= soft limits before changing.
644 hard
= (newlim
->d_fieldmask
& FS_DQ_BHARD
) ?
645 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_hardlimit
) :
646 INT_GET(ddq
->d_blk_hardlimit
, ARCH_CONVERT
);
647 soft
= (newlim
->d_fieldmask
& FS_DQ_BSOFT
) ?
648 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_softlimit
) :
649 INT_GET(ddq
->d_blk_softlimit
, ARCH_CONVERT
);
650 if (hard
== 0 || hard
>= soft
) {
651 INT_SET(ddq
->d_blk_hardlimit
, ARCH_CONVERT
, hard
);
652 INT_SET(ddq
->d_blk_softlimit
, ARCH_CONVERT
, soft
);
654 mp
->m_quotainfo
->qi_bhardlimit
= hard
;
655 mp
->m_quotainfo
->qi_bsoftlimit
= soft
;
658 qdprintk("blkhard %Ld < blksoft %Ld\n", hard
, soft
);
660 hard
= (newlim
->d_fieldmask
& FS_DQ_RTBHARD
) ?
661 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_hardlimit
) :
662 INT_GET(ddq
->d_rtb_hardlimit
, ARCH_CONVERT
);
663 soft
= (newlim
->d_fieldmask
& FS_DQ_RTBSOFT
) ?
664 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_softlimit
) :
665 INT_GET(ddq
->d_rtb_softlimit
, ARCH_CONVERT
);
666 if (hard
== 0 || hard
>= soft
) {
667 INT_SET(ddq
->d_rtb_hardlimit
, ARCH_CONVERT
, hard
);
668 INT_SET(ddq
->d_rtb_softlimit
, ARCH_CONVERT
, soft
);
670 mp
->m_quotainfo
->qi_rtbhardlimit
= hard
;
671 mp
->m_quotainfo
->qi_rtbsoftlimit
= soft
;
674 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard
, soft
);
677 hard
= (newlim
->d_fieldmask
& FS_DQ_IHARD
) ?
678 (xfs_qcnt_t
) newlim
->d_ino_hardlimit
:
679 INT_GET(ddq
->d_ino_hardlimit
, ARCH_CONVERT
);
680 soft
= (newlim
->d_fieldmask
& FS_DQ_ISOFT
) ?
681 (xfs_qcnt_t
) newlim
->d_ino_softlimit
:
682 INT_GET(ddq
->d_ino_softlimit
, ARCH_CONVERT
);
683 if (hard
== 0 || hard
>= soft
) {
684 INT_SET(ddq
->d_ino_hardlimit
, ARCH_CONVERT
, hard
);
685 INT_SET(ddq
->d_ino_softlimit
, ARCH_CONVERT
, soft
);
687 mp
->m_quotainfo
->qi_ihardlimit
= hard
;
688 mp
->m_quotainfo
->qi_isoftlimit
= soft
;
691 qdprintk("ihard %Ld < isoft %Ld\n", hard
, soft
);
696 * Timelimits for the super user set the relative time
697 * the other users can be over quota for this file system.
698 * If it is zero a default is used. Ditto for the default
699 * soft and hard limit values (already done, above).
701 if (newlim
->d_fieldmask
& FS_DQ_BTIMER
) {
702 mp
->m_quotainfo
->qi_btimelimit
= newlim
->d_btimer
;
703 INT_SET(ddq
->d_btimer
, ARCH_CONVERT
, newlim
->d_btimer
);
705 if (newlim
->d_fieldmask
& FS_DQ_ITIMER
) {
706 mp
->m_quotainfo
->qi_itimelimit
= newlim
->d_itimer
;
707 INT_SET(ddq
->d_itimer
, ARCH_CONVERT
, newlim
->d_itimer
);
709 if (newlim
->d_fieldmask
& FS_DQ_RTBTIMER
) {
710 mp
->m_quotainfo
->qi_rtbtimelimit
= newlim
->d_rtbtimer
;
711 INT_SET(ddq
->d_rtbtimer
, ARCH_CONVERT
, newlim
->d_rtbtimer
);
713 } else /* if (XFS_IS_QUOTA_ENFORCED(mp)) */ {
715 * If the user is now over quota, start the timelimit.
716 * The user will not be 'warned'.
717 * Note that we keep the timers ticking, whether enforcement
718 * is on or off. We don't really want to bother with iterating
719 * over all ondisk dquots and turning the timers on/off.
721 xfs_qm_adjust_dqtimers(mp
, ddq
);
723 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
724 xfs_trans_log_dquot(tp
, dqp
);
726 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: COMMIT");
727 xfs_trans_commit(tp
, 0, NULL
);
730 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
736 xfs_qm_scall_getquota(
740 fs_disk_quota_t
*out
)
746 * Try to get the dquot. We don't want it allocated on disk, so
747 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
748 * exist, we'll get ENOENT back.
750 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, 0, &dqp
))) {
754 xfs_dqtrace_entry(dqp
, "Q_GETQUOTA SUCCESS");
756 * If everything's NULL, this dquot doesn't quite exist as far as
757 * our utility programs are concerned.
759 if (XFS_IS_DQUOT_UNINITIALIZED(dqp
)) {
761 return XFS_ERROR(ENOENT
);
763 /* xfs_qm_dqprint(dqp); */
765 * Convert the disk dquot to the exportable format
767 xfs_qm_export_dquot(mp
, &dqp
->q_core
, out
);
769 return (error
? XFS_ERROR(EFAULT
) : 0);
774 xfs_qm_log_quotaoff_end(
776 xfs_qoff_logitem_t
*startqoff
,
781 xfs_qoff_logitem_t
*qoffi
;
783 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF_END
);
785 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_qoff_logitem_t
) * 2,
786 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
787 xfs_trans_cancel(tp
, 0);
791 qoffi
= xfs_trans_get_qoff_item(tp
, startqoff
,
792 flags
& XFS_ALL_QUOTA_ACCT
);
793 xfs_trans_log_quotaoff_item(tp
, qoffi
);
796 * We have to make sure that the transaction is secure on disk before we
797 * return and actually stop quota accounting. So, make it synchronous.
798 * We don't care about quotoff's performance.
800 xfs_trans_set_sync(tp
);
801 error
= xfs_trans_commit(tp
, 0, NULL
);
809 xfs_qoff_logitem_t
**qoffstartp
,
815 xfs_qoff_logitem_t
*qoffi
=NULL
;
818 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF
);
819 if ((error
= xfs_trans_reserve(tp
, 0,
820 sizeof(xfs_qoff_logitem_t
) * 2 +
821 mp
->m_sb
.sb_sectsize
+ 128,
824 XFS_DEFAULT_LOG_COUNT
))) {
828 qoffi
= xfs_trans_get_qoff_item(tp
, NULL
, flags
& XFS_ALL_QUOTA_ACCT
);
829 xfs_trans_log_quotaoff_item(tp
, qoffi
);
832 oldsbqflag
= mp
->m_sb
.sb_qflags
;
833 mp
->m_sb
.sb_qflags
= (mp
->m_qflags
& ~(flags
)) & XFS_MOUNT_QUOTA_ALL
;
834 XFS_SB_UNLOCK(mp
, s
);
836 xfs_mod_sb(tp
, XFS_SB_QFLAGS
);
839 * We have to make sure that the transaction is secure on disk before we
840 * return and actually stop quota accounting. So, make it synchronous.
841 * We don't care about quotoff's performance.
843 xfs_trans_set_sync(tp
);
844 error
= xfs_trans_commit(tp
, 0, NULL
);
848 xfs_trans_cancel(tp
, 0);
850 * No one else is modifying sb_qflags, so this is OK.
851 * We still hold the quotaofflock.
854 mp
->m_sb
.sb_qflags
= oldsbqflag
;
855 XFS_SB_UNLOCK(mp
, s
);
863 * Translate an internal style on-disk-dquot to the exportable format.
864 * The main differences are that the counters/limits are all in Basic
865 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
866 * to be converted to the native endianness.
871 xfs_disk_dquot_t
*src
,
872 struct fs_disk_quota
*dst
)
874 memset(dst
, 0, sizeof(*dst
));
875 dst
->d_version
= FS_DQUOT_VERSION
; /* different from src->d_version */
877 xfs_qm_export_qtype_flags(INT_GET(src
->d_flags
, ARCH_CONVERT
));
878 dst
->d_id
= INT_GET(src
->d_id
, ARCH_CONVERT
);
879 dst
->d_blk_hardlimit
= (__uint64_t
)
880 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_blk_hardlimit
, ARCH_CONVERT
));
881 dst
->d_blk_softlimit
= (__uint64_t
)
882 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_blk_softlimit
, ARCH_CONVERT
));
883 dst
->d_ino_hardlimit
= (__uint64_t
)
884 INT_GET(src
->d_ino_hardlimit
, ARCH_CONVERT
);
885 dst
->d_ino_softlimit
= (__uint64_t
)
886 INT_GET(src
->d_ino_softlimit
, ARCH_CONVERT
);
887 dst
->d_bcount
= (__uint64_t
)
888 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_bcount
, ARCH_CONVERT
));
889 dst
->d_icount
= (__uint64_t
) INT_GET(src
->d_icount
, ARCH_CONVERT
);
890 dst
->d_btimer
= (__uint32_t
) INT_GET(src
->d_btimer
, ARCH_CONVERT
);
891 dst
->d_itimer
= (__uint32_t
) INT_GET(src
->d_itimer
, ARCH_CONVERT
);
892 dst
->d_iwarns
= INT_GET(src
->d_iwarns
, ARCH_CONVERT
);
893 dst
->d_bwarns
= INT_GET(src
->d_bwarns
, ARCH_CONVERT
);
895 dst
->d_rtb_hardlimit
= (__uint64_t
)
896 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtb_hardlimit
, ARCH_CONVERT
));
897 dst
->d_rtb_softlimit
= (__uint64_t
)
898 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtb_softlimit
, ARCH_CONVERT
));
899 dst
->d_rtbcount
= (__uint64_t
)
900 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtbcount
, ARCH_CONVERT
));
901 dst
->d_rtbtimer
= (__uint32_t
) INT_GET(src
->d_rtbtimer
, ARCH_CONVERT
);
902 dst
->d_rtbwarns
= INT_GET(src
->d_rtbwarns
, ARCH_CONVERT
);
905 * Internally, we don't reset all the timers when quota enforcement
906 * gets turned off. No need to confuse the userlevel code,
907 * so return zeroes in that case.
909 if (! XFS_IS_QUOTA_ENFORCED(mp
)) {
916 if (XFS_IS_QUOTA_ENFORCED(mp
) && dst
->d_id
!= 0) {
917 if (((int) dst
->d_bcount
>= (int) dst
->d_blk_softlimit
) &&
918 (dst
->d_blk_softlimit
> 0)) {
919 ASSERT(dst
->d_btimer
!= 0);
921 if (((int) dst
->d_icount
>= (int) dst
->d_ino_softlimit
) &&
922 (dst
->d_ino_softlimit
> 0)) {
923 ASSERT(dst
->d_itimer
!= 0);
930 xfs_qm_import_qtype_flags(
934 * Can't be both at the same time.
936 if (((uflags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ==
937 (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ||
938 ((uflags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) == 0))
941 return (uflags
& XFS_USER_QUOTA
) ?
942 XFS_DQ_USER
: XFS_DQ_GROUP
;
946 xfs_qm_export_qtype_flags(
950 * Can't be both at the same time.
952 ASSERT((flags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) !=
953 (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
));
954 ASSERT((flags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) != 0);
956 return (flags
& XFS_DQ_USER
) ?
957 XFS_USER_QUOTA
: XFS_GROUP_QUOTA
;
966 if (uflags
& XFS_QUOTA_UDQ_ACCT
)
967 flags
|= XFS_UQUOTA_ACCT
;
968 if (uflags
& XFS_QUOTA_GDQ_ACCT
)
969 flags
|= XFS_GQUOTA_ACCT
;
970 if (uflags
& XFS_QUOTA_UDQ_ENFD
)
971 flags
|= XFS_UQUOTA_ENFD
;
972 if (uflags
& XFS_QUOTA_GDQ_ENFD
)
973 flags
|= XFS_GQUOTA_ENFD
;
985 if (flags
& XFS_UQUOTA_ACCT
)
986 uflags
|= XFS_QUOTA_UDQ_ACCT
;
987 if (flags
& XFS_GQUOTA_ACCT
)
988 uflags
|= XFS_QUOTA_GDQ_ACCT
;
989 if (flags
& XFS_UQUOTA_ENFD
)
990 uflags
|= XFS_QUOTA_UDQ_ENFD
;
991 if (flags
& XFS_GQUOTA_ENFD
)
992 uflags
|= XFS_QUOTA_GDQ_ENFD
;
998 * Go thru all the inodes in the file system, releasing their dquots.
999 * Note that the mount structure gets modified to indicate that quotas are off
1000 * AFTER this, in the case of quotaoff. This also gets called from
1004 xfs_qm_dqrele_all_inodes(
1005 struct xfs_mount
*mp
,
1009 xfs_inode_t
*ip
, *topino
;
1012 boolean_t vnode_refd
;
1014 ASSERT(mp
->m_quotainfo
);
1017 XFS_MOUNT_ILOCK(mp
);
1020 XFS_MOUNT_IUNLOCK(mp
);
1024 /* Skip markers inserted by xfs_sync */
1025 if (ip
->i_mount
== NULL
) {
1029 /* Root inode, rbmip and rsumip have associated blocks */
1030 if (ip
== XFS_QI_UQIP(mp
) || ip
== XFS_QI_GQIP(mp
)) {
1031 ASSERT(ip
->i_udquot
== NULL
);
1032 ASSERT(ip
->i_gdquot
== NULL
);
1036 vp
= XFS_ITOV_NULL(ip
);
1038 ASSERT(ip
->i_udquot
== NULL
);
1039 ASSERT(ip
->i_gdquot
== NULL
);
1043 vnode_refd
= B_FALSE
;
1044 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1046 * Sample vp mapping while holding the mplock, lest
1047 * we come across a non-existent vnode.
1050 ireclaims
= mp
->m_ireclaims
;
1051 topino
= mp
->m_inodes
;
1052 XFS_MOUNT_IUNLOCK(mp
);
1054 /* XXX restart limit ? */
1055 if ( ! (vp
= vn_get(vp
, &vmap
)))
1057 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1058 vnode_refd
= B_TRUE
;
1060 ireclaims
= mp
->m_ireclaims
;
1061 topino
= mp
->m_inodes
;
1062 XFS_MOUNT_IUNLOCK(mp
);
1066 * We don't keep the mountlock across the dqrele() call,
1067 * since it can take a while..
1069 if ((flags
& XFS_UQUOTA_ACCT
) && ip
->i_udquot
) {
1070 xfs_qm_dqrele(ip
->i_udquot
);
1071 ip
->i_udquot
= NULL
;
1073 if ((flags
& XFS_GQUOTA_ACCT
) && ip
->i_gdquot
) {
1074 xfs_qm_dqrele(ip
->i_gdquot
);
1075 ip
->i_gdquot
= NULL
;
1077 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1079 * Wait until we've dropped the ilock and mountlock to
1080 * do the vn_rele. Or be condemned to an eternity in the
1081 * inactive code in hell.
1085 XFS_MOUNT_ILOCK(mp
);
1087 * If an inode was inserted or removed, we gotta
1090 if (topino
!= mp
->m_inodes
|| mp
->m_ireclaims
!= ireclaims
) {
1091 /* XXX use a sentinel */
1092 XFS_MOUNT_IUNLOCK(mp
);
1096 } while (ip
!= mp
->m_inodes
);
1098 XFS_MOUNT_IUNLOCK(mp
);
1101 /*------------------------------------------------------------------------*/
1104 * This contains all the test functions for XFS disk quotas.
1105 * Currently it does a quota accounting check. ie. it walks through
1106 * all inodes in the file system, calculating the dquot accounting fields,
1107 * and prints out any inconsistencies.
1109 xfs_dqhash_t
*qmtest_udqtab
;
1110 xfs_dqhash_t
*qmtest_gdqtab
;
1111 int qmtest_hashmask
;
1113 mutex_t qcheck_lock
;
1115 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1116 (__psunsigned_t)(id)) & \
1117 (qmtest_hashmask - 1))
1119 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1121 DQTEST_HASHVAL(mp, id)) : \
1123 DQTEST_HASHVAL(mp, id)))
1125 #define DQTEST_LIST_PRINT(l, NXT, title) \
1127 xfs_dqtest_t *dqp; int i = 0;\
1128 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1129 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1130 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1131 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1132 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1133 dqp->d_bcount, dqp->d_icount); } \
1136 typedef struct dqtest
{
1137 xfs_dqmarker_t q_lists
;
1138 xfs_dqhash_t
*q_hash
; /* the hashchain header */
1139 xfs_mount_t
*q_mount
; /* filesystem this relates to */
1140 xfs_dqid_t d_id
; /* user id or group id */
1141 xfs_qcnt_t d_bcount
; /* # disk blocks owned by the user */
1142 xfs_qcnt_t d_icount
; /* # inodes owned by the user */
1146 xfs_qm_hashinsert(xfs_dqhash_t
*h
, xfs_dqtest_t
*dqp
)
1149 if (((d
) = (h
)->qh_next
))
1150 (d
)->HL_PREVP
= &((dqp
)->HL_NEXT
);
1152 (dqp
)->HL_PREVP
= &((h
)->qh_next
);
1153 (h
)->qh_next
= (xfs_dquot_t
*)dqp
;
1158 xfs_qm_dqtest_print(
1161 cmn_err(CE_DEBUG
, "-----------DQTEST DQUOT----------------");
1162 cmn_err(CE_DEBUG
, "---- dquot ID = %d", d
->d_id
);
1163 cmn_err(CE_DEBUG
, "---- type = %s", XFS_QM_ISUDQ(d
)? "USR" : "GRP");
1164 cmn_err(CE_DEBUG
, "---- fs = 0x%p", d
->q_mount
);
1165 cmn_err(CE_DEBUG
, "---- bcount = %Lu (0x%x)",
1166 d
->d_bcount
, (int)d
->d_bcount
);
1167 cmn_err(CE_DEBUG
, "---- icount = %Lu (0x%x)",
1168 d
->d_icount
, (int)d
->d_icount
);
1169 cmn_err(CE_DEBUG
, "---------------------------");
1173 xfs_qm_dqtest_failed(
1183 cmn_err(CE_DEBUG
, "quotacheck failed id=%d, err=%d\nreason: %s",
1184 INT_GET(d
->d_id
, ARCH_CONVERT
), error
, reason
);
1186 cmn_err(CE_DEBUG
, "quotacheck failed id=%d (%s) [%d != %d]",
1187 INT_GET(d
->d_id
, ARCH_CONVERT
), reason
, (int)a
, (int)b
);
1188 xfs_qm_dqtest_print(d
);
1190 xfs_qm_dqprint(dqp
);
1199 if (INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
) != d
->d_icount
) {
1200 xfs_qm_dqtest_failed(d
, dqp
, "icount mismatch",
1201 INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
),
1205 if (INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
) != d
->d_bcount
) {
1206 xfs_qm_dqtest_failed(d
, dqp
, "bcount mismatch",
1207 INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
),
1211 if (INT_GET(dqp
->q_core
.d_blk_softlimit
, ARCH_CONVERT
) &&
1212 INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
) >=
1213 INT_GET(dqp
->q_core
.d_blk_softlimit
, ARCH_CONVERT
)) {
1214 if (!dqp
->q_core
.d_btimer
&& dqp
->q_core
.d_id
) {
1216 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1217 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1221 if (INT_GET(dqp
->q_core
.d_ino_softlimit
, ARCH_CONVERT
) &&
1222 INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
) >=
1223 INT_GET(dqp
->q_core
.d_ino_softlimit
, ARCH_CONVERT
)) {
1224 if (!dqp
->q_core
.d_itimer
&& dqp
->q_core
.d_id
) {
1226 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1227 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1233 cmn_err(CE_DEBUG
, "%d [%s] [0x%p] qchecked",
1234 d
->d_id
, XFS_QM_ISUDQ(d
) ? "USR" : "GRP", d
->q_mount
);
1247 /* xfs_qm_dqtest_print(d); */
1248 if ((error
= xfs_qm_dqget(d
->q_mount
, NULL
, d
->d_id
, d
->dq_flags
, 0,
1250 xfs_qm_dqtest_failed(d
, NULL
, "dqget failed", 0, 0, error
);
1253 xfs_dqtest_cmp2(d
, dqp
);
1258 xfs_qm_internalqcheck_dqget(
1262 xfs_dqtest_t
**O_dq
)
1267 h
= DQTEST_HASH(mp
, id
, type
);
1268 for (d
= (xfs_dqtest_t
*) h
->qh_next
; d
!= NULL
;
1269 d
= (xfs_dqtest_t
*) d
->HL_NEXT
) {
1270 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1271 if (d
->d_id
== id
&& mp
== d
->q_mount
) {
1276 d
= kmem_zalloc(sizeof(xfs_dqtest_t
), KM_SLEEP
);
1281 xfs_qm_hashinsert(h
, d
);
1287 xfs_qm_internalqcheck_get_dquots(
1294 if (XFS_IS_UQUOTA_ON(mp
))
1295 xfs_qm_internalqcheck_dqget(mp
, uid
, XFS_DQ_USER
, ud
);
1296 if (XFS_IS_GQUOTA_ON(mp
))
1297 xfs_qm_internalqcheck_dqget(mp
, gid
, XFS_DQ_GROUP
, gd
);
1302 xfs_qm_internalqcheck_dqadjust(
1307 d
->d_bcount
+= (xfs_qcnt_t
)ip
->i_d
.di_nblocks
;
1311 xfs_qm_internalqcheck_adjust(
1312 xfs_mount_t
*mp
, /* mount point for filesystem */
1313 xfs_ino_t ino
, /* inode number to get data for */
1314 void __user
*buffer
, /* not used */
1315 int ubsize
, /* not used */
1316 void *private_data
, /* not used */
1317 xfs_daddr_t bno
, /* starting block of inode cluster */
1318 int *ubused
, /* not used */
1319 void *dip
, /* not used */
1320 int *res
) /* bulkstat result code */
1323 xfs_dqtest_t
*ud
, *gd
;
1325 boolean_t ipreleased
;
1328 ASSERT(XFS_IS_QUOTA_RUNNING(mp
));
1330 if (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
) {
1331 *res
= BULKSTAT_RV_NOTHING
;
1332 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1333 (unsigned long long) ino
,
1334 (unsigned long long) mp
->m_sb
.sb_uquotino
,
1335 (unsigned long long) mp
->m_sb
.sb_gquotino
);
1336 return XFS_ERROR(EINVAL
);
1338 ipreleased
= B_FALSE
;
1340 lock_flags
= XFS_ILOCK_SHARED
;
1341 if ((error
= xfs_iget(mp
, NULL
, ino
, 0, lock_flags
, &ip
, bno
))) {
1342 *res
= BULKSTAT_RV_NOTHING
;
1346 if (ip
->i_d
.di_mode
== 0) {
1347 xfs_iput_new(ip
, lock_flags
);
1348 *res
= BULKSTAT_RV_NOTHING
;
1349 return XFS_ERROR(ENOENT
);
1353 * This inode can have blocks after eof which can get released
1354 * when we send it to inactive. Since we don't check the dquot
1355 * until the after all our calculations are done, we must get rid
1359 xfs_iput(ip
, lock_flags
);
1360 ipreleased
= B_TRUE
;
1363 xfs_qm_internalqcheck_get_dquots(mp
,
1364 (xfs_dqid_t
) ip
->i_d
.di_uid
,
1365 (xfs_dqid_t
) ip
->i_d
.di_gid
,
1367 if (XFS_IS_UQUOTA_ON(mp
)) {
1369 xfs_qm_internalqcheck_dqadjust(ip
, ud
);
1371 if (XFS_IS_GQUOTA_ON(mp
)) {
1373 xfs_qm_internalqcheck_dqadjust(ip
, gd
);
1375 xfs_iput(ip
, lock_flags
);
1376 *res
= BULKSTAT_RV_DIDONE
;
1381 /* PRIVATE, debugging */
1383 xfs_qm_internalqcheck(
1389 xfs_dqtest_t
*d
, *e
;
1394 qmtest_hashmask
= 32;
1399 if (! XFS_IS_QUOTA_ON(mp
))
1400 return XFS_ERROR(ESRCH
);
1402 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1403 XFS_bflush(mp
->m_ddev_targp
);
1404 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1405 XFS_bflush(mp
->m_ddev_targp
);
1407 mutex_lock(&qcheck_lock
, PINOD
);
1408 /* There should be absolutely no quota activity while this
1410 qmtest_udqtab
= kmem_zalloc(qmtest_hashmask
*
1411 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1412 qmtest_gdqtab
= kmem_zalloc(qmtest_hashmask
*
1413 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1416 * Iterate thru all the inodes in the file system,
1417 * adjusting the corresponding dquot counters
1419 if ((error
= xfs_bulkstat(mp
, &lastino
, &count
,
1420 xfs_qm_internalqcheck_adjust
, NULL
,
1421 0, NULL
, BULKSTAT_FG_IGET
, &done
))) {
1426 cmn_err(CE_DEBUG
, "Bulkstat returned error 0x%x", error
);
1428 cmn_err(CE_DEBUG
, "Checking results against system dquots");
1429 for (i
= 0; i
< qmtest_hashmask
; i
++) {
1430 h1
= &qmtest_udqtab
[i
];
1431 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1433 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1434 kmem_free(d
, sizeof(xfs_dqtest_t
));
1437 h1
= &qmtest_gdqtab
[i
];
1438 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1440 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1441 kmem_free(d
, sizeof(xfs_dqtest_t
));
1446 if (qmtest_nfails
) {
1447 cmn_err(CE_DEBUG
, "******** quotacheck failed ********");
1448 cmn_err(CE_DEBUG
, "failures = %d", qmtest_nfails
);
1450 cmn_err(CE_DEBUG
, "******** quotacheck successful! ********");
1452 kmem_free(qmtest_udqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1453 kmem_free(qmtest_gdqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1454 mutex_unlock(&qcheck_lock
);
1455 return (qmtest_nfails
);