2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <linux/capability.h>
26 #include "xfs_trans.h"
30 #include "xfs_alloc.h"
31 #include "xfs_dmapi.h"
32 #include "xfs_quota.h"
33 #include "xfs_mount.h"
34 #include "xfs_bmap_btree.h"
35 #include "xfs_alloc_btree.h"
36 #include "xfs_ialloc_btree.h"
37 #include "xfs_dir2_sf.h"
38 #include "xfs_attr_sf.h"
39 #include "xfs_dinode.h"
40 #include "xfs_inode.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_itable.h"
44 #include "xfs_btree.h"
45 #include "xfs_rtalloc.h"
46 #include "xfs_error.h"
50 #include "xfs_buf_item.h"
51 #include "xfs_utils.h"
55 # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args)
57 # define qdprintk(s, args...) do { } while (0)
60 STATIC
int xfs_qm_scall_trunc_qfiles(xfs_mount_t
*, uint
);
61 STATIC
int xfs_qm_scall_getquota(xfs_mount_t
*, xfs_dqid_t
, uint
,
63 STATIC
int xfs_qm_scall_getqstat(xfs_mount_t
*, fs_quota_stat_t
*);
64 STATIC
int xfs_qm_scall_setqlim(xfs_mount_t
*, xfs_dqid_t
, uint
,
66 STATIC
int xfs_qm_scall_quotaon(xfs_mount_t
*, uint
);
67 STATIC
int xfs_qm_scall_quotaoff(xfs_mount_t
*, uint
, boolean_t
);
68 STATIC
int xfs_qm_log_quotaoff(xfs_mount_t
*, xfs_qoff_logitem_t
**, uint
);
69 STATIC
int xfs_qm_log_quotaoff_end(xfs_mount_t
*, xfs_qoff_logitem_t
*,
71 STATIC uint
xfs_qm_import_flags(uint
);
72 STATIC uint
xfs_qm_export_flags(uint
);
73 STATIC uint
xfs_qm_import_qtype_flags(uint
);
74 STATIC uint
xfs_qm_export_qtype_flags(uint
);
75 STATIC
void xfs_qm_export_dquot(xfs_mount_t
*, xfs_disk_dquot_t
*,
80 * The main distribution switch of all XFS quotactl system calls.
94 mp
= XFS_VFSTOM(vfsp
);
96 ASSERT(addr
!= NULL
|| cmd
== Q_XQUOTASYNC
);
99 * The following commands are valid even when quotaoff.
104 * Truncate quota files. quota must be off.
106 if (XFS_IS_QUOTA_ON(mp
))
107 return XFS_ERROR(EINVAL
);
108 if (vfsp
->vfs_flag
& VFS_RDONLY
)
109 return XFS_ERROR(EROFS
);
110 return (xfs_qm_scall_trunc_qfiles(mp
,
111 xfs_qm_import_qtype_flags(*(uint
*)addr
)));
115 * Get quota status information.
117 return (xfs_qm_scall_getqstat(mp
, (fs_quota_stat_t
*)addr
));
121 * QUOTAON - enabling quota enforcement.
122 * Quota accounting must be turned on at mount time.
124 if (vfsp
->vfs_flag
& VFS_RDONLY
)
125 return XFS_ERROR(EROFS
);
126 return (xfs_qm_scall_quotaon(mp
,
127 xfs_qm_import_flags(*(uint
*)addr
)));
130 if (vfsp
->vfs_flag
& VFS_RDONLY
)
131 return XFS_ERROR(EROFS
);
135 return (xfs_sync_inodes(mp
, SYNC_DELWRI
, NULL
));
141 if (! XFS_IS_QUOTA_ON(mp
))
142 return XFS_ERROR(ESRCH
);
146 if (vfsp
->vfs_flag
& VFS_RDONLY
)
147 return XFS_ERROR(EROFS
);
148 error
= xfs_qm_scall_quotaoff(mp
,
149 xfs_qm_import_flags(*(uint
*)addr
),
154 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
155 (fs_disk_quota_t
*)addr
);
158 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
159 (fs_disk_quota_t
*)addr
);
162 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_PROJ
,
163 (fs_disk_quota_t
*)addr
);
167 if (vfsp
->vfs_flag
& VFS_RDONLY
)
168 return XFS_ERROR(EROFS
);
169 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
170 (fs_disk_quota_t
*)addr
);
173 if (vfsp
->vfs_flag
& VFS_RDONLY
)
174 return XFS_ERROR(EROFS
);
175 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
176 (fs_disk_quota_t
*)addr
);
179 if (vfsp
->vfs_flag
& VFS_RDONLY
)
180 return XFS_ERROR(EROFS
);
181 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_PROJ
,
182 (fs_disk_quota_t
*)addr
);
186 error
= XFS_ERROR(EINVAL
);
194 * Turn off quota accounting and/or enforcement for all udquots and/or
195 * gdquots. Called only at unmount time.
197 * This assumes that there are no dquots of this file system cached
198 * incore, and modifies the ondisk dquot directly. Therefore, for example,
199 * it is an error to call this twice, without purging the cache.
202 xfs_qm_scall_quotaoff(
210 uint inactivate_flags
;
211 xfs_qoff_logitem_t
*qoffstart
;
214 if (!force
&& !capable(CAP_SYS_ADMIN
))
215 return XFS_ERROR(EPERM
);
217 * No file system can have quotas enabled on disk but not in core.
218 * Note that quota utilities (like quotaoff) _expect_
219 * errno == EEXIST here.
221 if ((mp
->m_qflags
& flags
) == 0)
222 return XFS_ERROR(EEXIST
);
225 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
228 * We don't want to deal with two quotaoffs messing up each other,
229 * so we're going to serialize it. quotaoff isn't exactly a performance
231 * If quotaoff, then we must be dealing with the root filesystem.
233 ASSERT(mp
->m_quotainfo
);
235 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
237 ASSERT(mp
->m_quotainfo
);
240 * If we're just turning off quota enforcement, change mp and go.
242 if ((flags
& XFS_ALL_QUOTA_ACCT
) == 0) {
243 mp
->m_qflags
&= ~(flags
);
246 mp
->m_sb
.sb_qflags
= mp
->m_qflags
;
247 XFS_SB_UNLOCK(mp
, s
);
248 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
250 /* XXX what to do if error ? Revert back to old vals incore ? */
251 error
= xfs_qm_write_sb_changes(mp
, XFS_SB_QFLAGS
);
256 inactivate_flags
= 0;
258 * If accounting is off, we must turn enforcement off, clear the
259 * quota 'CHKD' certificate to make it known that we have to
260 * do a quotacheck the next time this quota is turned on.
262 if (flags
& XFS_UQUOTA_ACCT
) {
263 dqtype
|= XFS_QMOPT_UQUOTA
;
264 flags
|= (XFS_UQUOTA_CHKD
| XFS_UQUOTA_ENFD
);
265 inactivate_flags
|= XFS_UQUOTA_ACTIVE
;
267 if (flags
& XFS_GQUOTA_ACCT
) {
268 dqtype
|= XFS_QMOPT_GQUOTA
;
269 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
270 inactivate_flags
|= XFS_GQUOTA_ACTIVE
;
271 } else if (flags
& XFS_PQUOTA_ACCT
) {
272 dqtype
|= XFS_QMOPT_PQUOTA
;
273 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
274 inactivate_flags
|= XFS_PQUOTA_ACTIVE
;
278 * Nothing to do? Don't complain. This happens when we're just
279 * turning off quota enforcement.
281 if ((mp
->m_qflags
& flags
) == 0) {
282 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
287 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
290 xfs_qm_log_quotaoff(mp
, &qoffstart
, flags
);
293 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
294 * to take care of the race between dqget and quotaoff. We don't take
295 * any special locks to reset these bits. All processes need to check
296 * these bits *after* taking inode lock(s) to see if the particular
297 * quota type is in the process of being turned off. If *ACTIVE, it is
298 * guaranteed that all dquot structures and all quotainode ptrs will all
299 * stay valid as long as that inode is kept locked.
301 * There is no turning back after this.
303 mp
->m_qflags
&= ~inactivate_flags
;
306 * Give back all the dquot reference(s) held by inodes.
307 * Here we go thru every single incore inode in this file system, and
308 * do a dqrele on the i_udquot/i_gdquot that it may have.
309 * Essentially, as long as somebody has an inode locked, this guarantees
310 * that quotas will not be turned off. This is handy because in a
311 * transaction once we lock the inode(s) and check for quotaon, we can
312 * depend on the quota inodes (and other things) being valid as long as
313 * we keep the lock(s).
315 xfs_qm_dqrele_all_inodes(mp
, flags
);
318 * Next we make the changes in the quota flag in the mount struct.
319 * This isn't protected by a particular lock directly, because we
320 * don't want to take a mrlock everytime we depend on quotas being on.
322 mp
->m_qflags
&= ~(flags
);
325 * Go through all the dquots of this file system and purge them,
326 * according to what was turned off. We may not be able to get rid
327 * of all dquots, because dquots can have temporary references that
328 * are not attached to inodes. eg. xfs_setattr, xfs_create.
329 * So, if we couldn't purge all the dquots from the filesystem,
330 * we can't get rid of the incore data structures.
332 while ((nculprits
= xfs_qm_dqpurge_all(mp
, dqtype
|XFS_QMOPT_QUOTAOFF
)))
333 delay(10 * nculprits
);
336 * Transactions that had started before ACTIVE state bit was cleared
337 * could have logged many dquots, so they'd have higher LSNs than
338 * the first QUOTAOFF log record does. If we happen to crash when
339 * the tail of the log has gone past the QUOTAOFF record, but
340 * before the last dquot modification, those dquots __will__
341 * recover, and that's not good.
343 * So, we have QUOTAOFF start and end logitems; the start
344 * logitem won't get overwritten until the end logitem appears...
346 xfs_qm_log_quotaoff_end(mp
, qoffstart
, flags
);
349 * If quotas is completely disabled, close shop.
351 if (((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET1
) ||
352 ((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET2
)) {
353 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
354 xfs_qm_destroy_quotainfo(mp
);
359 * Release our quotainode references, and vn_purge them,
360 * if we don't need them anymore.
362 if ((dqtype
& XFS_QMOPT_UQUOTA
) && XFS_QI_UQIP(mp
)) {
363 XFS_PURGE_INODE(XFS_QI_UQIP(mp
));
364 XFS_QI_UQIP(mp
) = NULL
;
366 if ((dqtype
& (XFS_QMOPT_GQUOTA
|XFS_QMOPT_PQUOTA
)) && XFS_QI_GQIP(mp
)) {
367 XFS_PURGE_INODE(XFS_QI_GQIP(mp
));
368 XFS_QI_GQIP(mp
) = NULL
;
370 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
376 xfs_qm_scall_trunc_qfiles(
383 if (!capable(CAP_SYS_ADMIN
))
384 return XFS_ERROR(EPERM
);
386 if (!XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) || flags
== 0) {
387 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags
, mp
->m_qflags
);
388 return XFS_ERROR(EINVAL
);
391 if ((flags
& XFS_DQ_USER
) && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
392 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
, 0, 0, &qip
, 0);
394 (void) xfs_truncate_file(mp
, qip
);
395 VN_RELE(XFS_ITOV(qip
));
399 if ((flags
& (XFS_DQ_GROUP
|XFS_DQ_PROJ
)) &&
400 mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
401 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
, 0, 0, &qip
, 0);
403 (void) xfs_truncate_file(mp
, qip
);
404 VN_RELE(XFS_ITOV(qip
));
413 * Switch on (a given) quota enforcement for a filesystem. This takes
414 * effect immediately.
415 * (Switching on quota accounting must be done at mount time.)
418 xfs_qm_scall_quotaon(
428 if (!capable(CAP_SYS_ADMIN
))
429 return XFS_ERROR(EPERM
);
431 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
433 * Switching on quota accounting must be done at mount time.
435 accflags
= flags
& XFS_ALL_QUOTA_ACCT
;
436 flags
&= ~(XFS_ALL_QUOTA_ACCT
);
441 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp
->m_qflags
);
442 return XFS_ERROR(EINVAL
);
445 /* No fs can turn on quotas with a delayed effect */
446 ASSERT((flags
& XFS_ALL_QUOTA_ACCT
) == 0);
449 * Can't enforce without accounting. We check the superblock
450 * qflags here instead of m_qflags because rootfs can have
451 * quota acct on ondisk without m_qflags' knowing.
453 if (((flags
& XFS_UQUOTA_ACCT
) == 0 &&
454 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) == 0 &&
455 (flags
& XFS_UQUOTA_ENFD
))
457 ((flags
& XFS_PQUOTA_ACCT
) == 0 &&
458 (mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) == 0 &&
459 (flags
& XFS_OQUOTA_ENFD
))
461 ((flags
& XFS_GQUOTA_ACCT
) == 0 &&
462 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) == 0 &&
463 (flags
& XFS_OQUOTA_ENFD
))) {
464 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
465 flags
, mp
->m_sb
.sb_qflags
);
466 return XFS_ERROR(EINVAL
);
469 * If everything's upto-date incore, then don't waste time.
471 if ((mp
->m_qflags
& flags
) == flags
)
472 return XFS_ERROR(EEXIST
);
475 * Change sb_qflags on disk but not incore mp->qflags
476 * if this is the root filesystem.
479 qf
= mp
->m_sb
.sb_qflags
;
480 mp
->m_sb
.sb_qflags
= qf
| flags
;
481 XFS_SB_UNLOCK(mp
, s
);
484 * There's nothing to change if it's the same.
486 if ((qf
& flags
) == flags
&& sbflags
== 0)
487 return XFS_ERROR(EEXIST
);
488 sbflags
|= XFS_SB_QFLAGS
;
490 if ((error
= xfs_qm_write_sb_changes(mp
, sbflags
)))
493 * If we aren't trying to switch on quota enforcement, we are done.
495 if (((mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) !=
496 (mp
->m_qflags
& XFS_UQUOTA_ACCT
)) ||
497 ((mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) !=
498 (mp
->m_qflags
& XFS_PQUOTA_ACCT
)) ||
499 ((mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) !=
500 (mp
->m_qflags
& XFS_GQUOTA_ACCT
)) ||
501 (flags
& XFS_ALL_QUOTA_ENFD
) == 0)
504 if (! XFS_IS_QUOTA_RUNNING(mp
))
505 return XFS_ERROR(ESRCH
);
508 * Switch on quota enforcement in core.
510 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
511 mp
->m_qflags
|= (flags
& XFS_ALL_QUOTA_ENFD
);
512 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
519 * Return quota status information, such as uquota-off, enforcements, etc.
522 xfs_qm_scall_getqstat(
524 fs_quota_stat_t
*out
)
526 xfs_inode_t
*uip
, *gip
;
527 boolean_t tempuqip
, tempgqip
;
530 tempuqip
= tempgqip
= B_FALSE
;
531 memset(out
, 0, sizeof(fs_quota_stat_t
));
533 out
->qs_version
= FS_QSTAT_VERSION
;
534 if (! XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
)) {
535 out
->qs_uquota
.qfs_ino
= NULLFSINO
;
536 out
->qs_gquota
.qfs_ino
= NULLFSINO
;
539 out
->qs_flags
= (__uint16_t
) xfs_qm_export_flags(mp
->m_qflags
&
541 XFS_ALL_QUOTA_ENFD
));
543 out
->qs_uquota
.qfs_ino
= mp
->m_sb
.sb_uquotino
;
544 out
->qs_gquota
.qfs_ino
= mp
->m_sb
.sb_gquotino
;
546 if (mp
->m_quotainfo
) {
547 uip
= mp
->m_quotainfo
->qi_uquotaip
;
548 gip
= mp
->m_quotainfo
->qi_gquotaip
;
550 if (!uip
&& mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
551 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
,
555 if (!gip
&& mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
556 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
,
561 out
->qs_uquota
.qfs_nblks
= uip
->i_d
.di_nblocks
;
562 out
->qs_uquota
.qfs_nextents
= uip
->i_d
.di_nextents
;
564 VN_RELE(XFS_ITOV(uip
));
567 out
->qs_gquota
.qfs_nblks
= gip
->i_d
.di_nblocks
;
568 out
->qs_gquota
.qfs_nextents
= gip
->i_d
.di_nextents
;
570 VN_RELE(XFS_ITOV(gip
));
572 if (mp
->m_quotainfo
) {
573 out
->qs_incoredqs
= XFS_QI_MPLNDQUOTS(mp
);
574 out
->qs_btimelimit
= XFS_QI_BTIMELIMIT(mp
);
575 out
->qs_itimelimit
= XFS_QI_ITIMELIMIT(mp
);
576 out
->qs_rtbtimelimit
= XFS_QI_RTBTIMELIMIT(mp
);
577 out
->qs_bwarnlimit
= XFS_QI_BWARNLIMIT(mp
);
578 out
->qs_iwarnlimit
= XFS_QI_IWARNLIMIT(mp
);
584 * Adjust quota limits, and start/stop timers accordingly.
587 xfs_qm_scall_setqlim(
591 fs_disk_quota_t
*newlim
)
593 xfs_disk_dquot_t
*ddq
;
597 xfs_qcnt_t hard
, soft
;
599 if (!capable(CAP_SYS_ADMIN
))
600 return XFS_ERROR(EPERM
);
602 if ((newlim
->d_fieldmask
&
603 (FS_DQ_LIMIT_MASK
|FS_DQ_TIMER_MASK
|FS_DQ_WARNS_MASK
)) == 0)
606 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_SETQLIM
);
607 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_disk_dquot_t
) + 128,
608 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
609 xfs_trans_cancel(tp
, 0);
614 * We don't want to race with a quotaoff so take the quotaoff lock.
615 * (We don't hold an inode lock, so there's nothing else to stop
616 * a quotaoff from happening). (XXXThis doesn't currently happen
617 * because we take the vfslock before calling xfs_qm_sysent).
619 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
622 * Get the dquot (locked), and join it to the transaction.
623 * Allocate the dquot if this doesn't exist.
625 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, XFS_QMOPT_DQALLOC
, &dqp
))) {
626 xfs_trans_cancel(tp
, XFS_TRANS_ABORT
);
627 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
628 ASSERT(error
!= ENOENT
);
631 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: AFT DQGET");
632 xfs_trans_dqjoin(tp
, dqp
);
636 * Make sure that hardlimits are >= soft limits before changing.
638 hard
= (newlim
->d_fieldmask
& FS_DQ_BHARD
) ?
639 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_hardlimit
) :
640 be64_to_cpu(ddq
->d_blk_hardlimit
);
641 soft
= (newlim
->d_fieldmask
& FS_DQ_BSOFT
) ?
642 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_softlimit
) :
643 be64_to_cpu(ddq
->d_blk_softlimit
);
644 if (hard
== 0 || hard
>= soft
) {
645 ddq
->d_blk_hardlimit
= cpu_to_be64(hard
);
646 ddq
->d_blk_softlimit
= cpu_to_be64(soft
);
648 mp
->m_quotainfo
->qi_bhardlimit
= hard
;
649 mp
->m_quotainfo
->qi_bsoftlimit
= soft
;
652 qdprintk("blkhard %Ld < blksoft %Ld\n", hard
, soft
);
654 hard
= (newlim
->d_fieldmask
& FS_DQ_RTBHARD
) ?
655 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_hardlimit
) :
656 be64_to_cpu(ddq
->d_rtb_hardlimit
);
657 soft
= (newlim
->d_fieldmask
& FS_DQ_RTBSOFT
) ?
658 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_softlimit
) :
659 be64_to_cpu(ddq
->d_rtb_softlimit
);
660 if (hard
== 0 || hard
>= soft
) {
661 ddq
->d_rtb_hardlimit
= cpu_to_be64(hard
);
662 ddq
->d_rtb_softlimit
= cpu_to_be64(soft
);
664 mp
->m_quotainfo
->qi_rtbhardlimit
= hard
;
665 mp
->m_quotainfo
->qi_rtbsoftlimit
= soft
;
668 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard
, soft
);
671 hard
= (newlim
->d_fieldmask
& FS_DQ_IHARD
) ?
672 (xfs_qcnt_t
) newlim
->d_ino_hardlimit
:
673 be64_to_cpu(ddq
->d_ino_hardlimit
);
674 soft
= (newlim
->d_fieldmask
& FS_DQ_ISOFT
) ?
675 (xfs_qcnt_t
) newlim
->d_ino_softlimit
:
676 be64_to_cpu(ddq
->d_ino_softlimit
);
677 if (hard
== 0 || hard
>= soft
) {
678 ddq
->d_ino_hardlimit
= cpu_to_be64(hard
);
679 ddq
->d_ino_softlimit
= cpu_to_be64(soft
);
681 mp
->m_quotainfo
->qi_ihardlimit
= hard
;
682 mp
->m_quotainfo
->qi_isoftlimit
= soft
;
685 qdprintk("ihard %Ld < isoft %Ld\n", hard
, soft
);
689 * Update warnings counter(s) if requested
691 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
692 ddq
->d_bwarns
= cpu_to_be16(newlim
->d_bwarns
);
693 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
694 ddq
->d_iwarns
= cpu_to_be16(newlim
->d_iwarns
);
695 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
696 ddq
->d_rtbwarns
= cpu_to_be16(newlim
->d_rtbwarns
);
700 * Timelimits for the super user set the relative time
701 * the other users can be over quota for this file system.
702 * If it is zero a default is used. Ditto for the default
703 * soft and hard limit values (already done, above), and
706 if (newlim
->d_fieldmask
& FS_DQ_BTIMER
) {
707 mp
->m_quotainfo
->qi_btimelimit
= newlim
->d_btimer
;
708 ddq
->d_btimer
= cpu_to_be32(newlim
->d_btimer
);
710 if (newlim
->d_fieldmask
& FS_DQ_ITIMER
) {
711 mp
->m_quotainfo
->qi_itimelimit
= newlim
->d_itimer
;
712 ddq
->d_itimer
= cpu_to_be32(newlim
->d_itimer
);
714 if (newlim
->d_fieldmask
& FS_DQ_RTBTIMER
) {
715 mp
->m_quotainfo
->qi_rtbtimelimit
= newlim
->d_rtbtimer
;
716 ddq
->d_rtbtimer
= cpu_to_be32(newlim
->d_rtbtimer
);
718 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
719 mp
->m_quotainfo
->qi_bwarnlimit
= newlim
->d_bwarns
;
720 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
721 mp
->m_quotainfo
->qi_iwarnlimit
= newlim
->d_iwarns
;
722 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
723 mp
->m_quotainfo
->qi_rtbwarnlimit
= newlim
->d_rtbwarns
;
726 * If the user is now over quota, start the timelimit.
727 * The user will not be 'warned'.
728 * Note that we keep the timers ticking, whether enforcement
729 * is on or off. We don't really want to bother with iterating
730 * over all ondisk dquots and turning the timers on/off.
732 xfs_qm_adjust_dqtimers(mp
, ddq
);
734 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
735 xfs_trans_log_dquot(tp
, dqp
);
737 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: COMMIT");
738 xfs_trans_commit(tp
, 0, NULL
);
741 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
747 xfs_qm_scall_getquota(
751 fs_disk_quota_t
*out
)
757 * Try to get the dquot. We don't want it allocated on disk, so
758 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
759 * exist, we'll get ENOENT back.
761 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, 0, &dqp
))) {
765 xfs_dqtrace_entry(dqp
, "Q_GETQUOTA SUCCESS");
767 * If everything's NULL, this dquot doesn't quite exist as far as
768 * our utility programs are concerned.
770 if (XFS_IS_DQUOT_UNINITIALIZED(dqp
)) {
772 return XFS_ERROR(ENOENT
);
774 /* xfs_qm_dqprint(dqp); */
776 * Convert the disk dquot to the exportable format
778 xfs_qm_export_dquot(mp
, &dqp
->q_core
, out
);
780 return (error
? XFS_ERROR(EFAULT
) : 0);
785 xfs_qm_log_quotaoff_end(
787 xfs_qoff_logitem_t
*startqoff
,
792 xfs_qoff_logitem_t
*qoffi
;
794 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF_END
);
796 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_qoff_logitem_t
) * 2,
797 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
798 xfs_trans_cancel(tp
, 0);
802 qoffi
= xfs_trans_get_qoff_item(tp
, startqoff
,
803 flags
& XFS_ALL_QUOTA_ACCT
);
804 xfs_trans_log_quotaoff_item(tp
, qoffi
);
807 * We have to make sure that the transaction is secure on disk before we
808 * return and actually stop quota accounting. So, make it synchronous.
809 * We don't care about quotoff's performance.
811 xfs_trans_set_sync(tp
);
812 error
= xfs_trans_commit(tp
, 0, NULL
);
820 xfs_qoff_logitem_t
**qoffstartp
,
826 xfs_qoff_logitem_t
*qoffi
=NULL
;
829 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF
);
830 if ((error
= xfs_trans_reserve(tp
, 0,
831 sizeof(xfs_qoff_logitem_t
) * 2 +
832 mp
->m_sb
.sb_sectsize
+ 128,
835 XFS_DEFAULT_LOG_COUNT
))) {
839 qoffi
= xfs_trans_get_qoff_item(tp
, NULL
, flags
& XFS_ALL_QUOTA_ACCT
);
840 xfs_trans_log_quotaoff_item(tp
, qoffi
);
843 oldsbqflag
= mp
->m_sb
.sb_qflags
;
844 mp
->m_sb
.sb_qflags
= (mp
->m_qflags
& ~(flags
)) & XFS_MOUNT_QUOTA_ALL
;
845 XFS_SB_UNLOCK(mp
, s
);
847 xfs_mod_sb(tp
, XFS_SB_QFLAGS
);
850 * We have to make sure that the transaction is secure on disk before we
851 * return and actually stop quota accounting. So, make it synchronous.
852 * We don't care about quotoff's performance.
854 xfs_trans_set_sync(tp
);
855 error
= xfs_trans_commit(tp
, 0, NULL
);
859 xfs_trans_cancel(tp
, 0);
861 * No one else is modifying sb_qflags, so this is OK.
862 * We still hold the quotaofflock.
865 mp
->m_sb
.sb_qflags
= oldsbqflag
;
866 XFS_SB_UNLOCK(mp
, s
);
874 * Translate an internal style on-disk-dquot to the exportable format.
875 * The main differences are that the counters/limits are all in Basic
876 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
877 * to be converted to the native endianness.
882 xfs_disk_dquot_t
*src
,
883 struct fs_disk_quota
*dst
)
885 memset(dst
, 0, sizeof(*dst
));
886 dst
->d_version
= FS_DQUOT_VERSION
; /* different from src->d_version */
887 dst
->d_flags
= xfs_qm_export_qtype_flags(src
->d_flags
);
888 dst
->d_id
= be32_to_cpu(src
->d_id
);
889 dst
->d_blk_hardlimit
=
890 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_blk_hardlimit
));
891 dst
->d_blk_softlimit
=
892 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_blk_softlimit
));
893 dst
->d_ino_hardlimit
= be64_to_cpu(src
->d_ino_hardlimit
);
894 dst
->d_ino_softlimit
= be64_to_cpu(src
->d_ino_softlimit
);
895 dst
->d_bcount
= XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_bcount
));
896 dst
->d_icount
= be64_to_cpu(src
->d_icount
);
897 dst
->d_btimer
= be32_to_cpu(src
->d_btimer
);
898 dst
->d_itimer
= be32_to_cpu(src
->d_itimer
);
899 dst
->d_iwarns
= be16_to_cpu(src
->d_iwarns
);
900 dst
->d_bwarns
= be16_to_cpu(src
->d_bwarns
);
901 dst
->d_rtb_hardlimit
=
902 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtb_hardlimit
));
903 dst
->d_rtb_softlimit
=
904 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtb_softlimit
));
905 dst
->d_rtbcount
= XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtbcount
));
906 dst
->d_rtbtimer
= be32_to_cpu(src
->d_rtbtimer
);
907 dst
->d_rtbwarns
= be16_to_cpu(src
->d_rtbwarns
);
910 * Internally, we don't reset all the timers when quota enforcement
911 * gets turned off. No need to confuse the user level code,
912 * so return zeroes in that case.
914 if (! XFS_IS_QUOTA_ENFORCED(mp
)) {
921 if (XFS_IS_QUOTA_ENFORCED(mp
) && dst
->d_id
!= 0) {
922 if (((int) dst
->d_bcount
>= (int) dst
->d_blk_softlimit
) &&
923 (dst
->d_blk_softlimit
> 0)) {
924 ASSERT(dst
->d_btimer
!= 0);
926 if (((int) dst
->d_icount
>= (int) dst
->d_ino_softlimit
) &&
927 (dst
->d_ino_softlimit
> 0)) {
928 ASSERT(dst
->d_itimer
!= 0);
935 xfs_qm_import_qtype_flags(
941 * Can't be more than one, or none.
943 if (((uflags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ==
944 (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ||
945 ((uflags
& (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ==
946 (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ||
947 ((uflags
& (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ==
948 (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ||
949 ((uflags
& (XFS_GROUP_QUOTA
|XFS_USER_QUOTA
|XFS_PROJ_QUOTA
)) == 0))
952 oflags
|= (uflags
& XFS_USER_QUOTA
) ? XFS_DQ_USER
: 0;
953 oflags
|= (uflags
& XFS_PROJ_QUOTA
) ? XFS_DQ_PROJ
: 0;
954 oflags
|= (uflags
& XFS_GROUP_QUOTA
) ? XFS_DQ_GROUP
: 0;
959 xfs_qm_export_qtype_flags(
963 * Can't be more than one, or none.
965 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
)) !=
966 (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
));
967 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
)) !=
968 (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
));
969 ASSERT((flags
& (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
)) !=
970 (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
));
971 ASSERT((flags
& (XFS_PROJ_QUOTA
|XFS_USER_QUOTA
|XFS_GROUP_QUOTA
)) != 0);
973 return (flags
& XFS_DQ_USER
) ?
974 XFS_USER_QUOTA
: (flags
& XFS_DQ_PROJ
) ?
975 XFS_PROJ_QUOTA
: XFS_GROUP_QUOTA
;
984 if (uflags
& XFS_QUOTA_UDQ_ACCT
)
985 flags
|= XFS_UQUOTA_ACCT
;
986 if (uflags
& XFS_QUOTA_PDQ_ACCT
)
987 flags
|= XFS_PQUOTA_ACCT
;
988 if (uflags
& XFS_QUOTA_GDQ_ACCT
)
989 flags
|= XFS_GQUOTA_ACCT
;
990 if (uflags
& XFS_QUOTA_UDQ_ENFD
)
991 flags
|= XFS_UQUOTA_ENFD
;
992 if (uflags
& (XFS_QUOTA_PDQ_ENFD
|XFS_QUOTA_GDQ_ENFD
))
993 flags
|= XFS_OQUOTA_ENFD
;
1005 if (flags
& XFS_UQUOTA_ACCT
)
1006 uflags
|= XFS_QUOTA_UDQ_ACCT
;
1007 if (flags
& XFS_PQUOTA_ACCT
)
1008 uflags
|= XFS_QUOTA_PDQ_ACCT
;
1009 if (flags
& XFS_GQUOTA_ACCT
)
1010 uflags
|= XFS_QUOTA_GDQ_ACCT
;
1011 if (flags
& XFS_UQUOTA_ENFD
)
1012 uflags
|= XFS_QUOTA_UDQ_ENFD
;
1013 if (flags
& (XFS_OQUOTA_ENFD
)) {
1014 uflags
|= (flags
& XFS_GQUOTA_ACCT
) ?
1015 XFS_QUOTA_GDQ_ENFD
: XFS_QUOTA_PDQ_ENFD
;
1022 * Go thru all the inodes in the file system, releasing their dquots.
1023 * Note that the mount structure gets modified to indicate that quotas are off
1024 * AFTER this, in the case of quotaoff. This also gets called from
1028 xfs_qm_dqrele_all_inodes(
1029 struct xfs_mount
*mp
,
1032 xfs_inode_t
*ip
, *topino
;
1035 boolean_t vnode_refd
;
1037 ASSERT(mp
->m_quotainfo
);
1039 XFS_MOUNT_ILOCK(mp
);
1043 XFS_MOUNT_IUNLOCK(mp
);
1047 /* Skip markers inserted by xfs_sync */
1048 if (ip
->i_mount
== NULL
) {
1052 /* Root inode, rbmip and rsumip have associated blocks */
1053 if (ip
== XFS_QI_UQIP(mp
) || ip
== XFS_QI_GQIP(mp
)) {
1054 ASSERT(ip
->i_udquot
== NULL
);
1055 ASSERT(ip
->i_gdquot
== NULL
);
1059 vp
= XFS_ITOV_NULL(ip
);
1061 ASSERT(ip
->i_udquot
== NULL
);
1062 ASSERT(ip
->i_gdquot
== NULL
);
1066 vnode_refd
= B_FALSE
;
1067 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1068 ireclaims
= mp
->m_ireclaims
;
1069 topino
= mp
->m_inodes
;
1074 XFS_MOUNT_IUNLOCK(mp
);
1075 /* XXX restart limit ? */
1076 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1077 vnode_refd
= B_TRUE
;
1079 ireclaims
= mp
->m_ireclaims
;
1080 topino
= mp
->m_inodes
;
1081 XFS_MOUNT_IUNLOCK(mp
);
1085 * We don't keep the mountlock across the dqrele() call,
1086 * since it can take a while..
1088 if ((flags
& XFS_UQUOTA_ACCT
) && ip
->i_udquot
) {
1089 xfs_qm_dqrele(ip
->i_udquot
);
1090 ip
->i_udquot
= NULL
;
1092 if (flags
& (XFS_PQUOTA_ACCT
|XFS_GQUOTA_ACCT
) && ip
->i_gdquot
) {
1093 xfs_qm_dqrele(ip
->i_gdquot
);
1094 ip
->i_gdquot
= NULL
;
1096 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1098 * Wait until we've dropped the ilock and mountlock to
1099 * do the vn_rele. Or be condemned to an eternity in the
1100 * inactive code in hell.
1104 XFS_MOUNT_ILOCK(mp
);
1106 * If an inode was inserted or removed, we gotta
1109 if (topino
!= mp
->m_inodes
|| mp
->m_ireclaims
!= ireclaims
) {
1110 /* XXX use a sentinel */
1114 } while (ip
!= mp
->m_inodes
);
1116 XFS_MOUNT_IUNLOCK(mp
);
1119 /*------------------------------------------------------------------------*/
1122 * This contains all the test functions for XFS disk quotas.
1123 * Currently it does a quota accounting check. ie. it walks through
1124 * all inodes in the file system, calculating the dquot accounting fields,
1125 * and prints out any inconsistencies.
1127 xfs_dqhash_t
*qmtest_udqtab
;
1128 xfs_dqhash_t
*qmtest_gdqtab
;
1129 int qmtest_hashmask
;
1131 mutex_t qcheck_lock
;
1133 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1134 (__psunsigned_t)(id)) & \
1135 (qmtest_hashmask - 1))
1137 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1139 DQTEST_HASHVAL(mp, id)) : \
1141 DQTEST_HASHVAL(mp, id)))
1143 #define DQTEST_LIST_PRINT(l, NXT, title) \
1145 xfs_dqtest_t *dqp; int i = 0;\
1146 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1147 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1148 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1149 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1150 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1151 dqp->d_bcount, dqp->d_icount); } \
1154 typedef struct dqtest
{
1155 xfs_dqmarker_t q_lists
;
1156 xfs_dqhash_t
*q_hash
; /* the hashchain header */
1157 xfs_mount_t
*q_mount
; /* filesystem this relates to */
1158 xfs_dqid_t d_id
; /* user id or group id */
1159 xfs_qcnt_t d_bcount
; /* # disk blocks owned by the user */
1160 xfs_qcnt_t d_icount
; /* # inodes owned by the user */
1164 xfs_qm_hashinsert(xfs_dqhash_t
*h
, xfs_dqtest_t
*dqp
)
1167 if (((d
) = (h
)->qh_next
))
1168 (d
)->HL_PREVP
= &((dqp
)->HL_NEXT
);
1170 (dqp
)->HL_PREVP
= &((h
)->qh_next
);
1171 (h
)->qh_next
= (xfs_dquot_t
*)dqp
;
1176 xfs_qm_dqtest_print(
1179 cmn_err(CE_DEBUG
, "-----------DQTEST DQUOT----------------");
1180 cmn_err(CE_DEBUG
, "---- dquot ID = %d", d
->d_id
);
1181 cmn_err(CE_DEBUG
, "---- fs = 0x%p", d
->q_mount
);
1182 cmn_err(CE_DEBUG
, "---- bcount = %Lu (0x%x)",
1183 d
->d_bcount
, (int)d
->d_bcount
);
1184 cmn_err(CE_DEBUG
, "---- icount = %Lu (0x%x)",
1185 d
->d_icount
, (int)d
->d_icount
);
1186 cmn_err(CE_DEBUG
, "---------------------------");
1190 xfs_qm_dqtest_failed(
1200 cmn_err(CE_DEBUG
, "quotacheck failed id=%d, err=%d\nreason: %s",
1201 d
->d_id
, error
, reason
);
1203 cmn_err(CE_DEBUG
, "quotacheck failed id=%d (%s) [%d != %d]",
1204 d
->d_id
, reason
, (int)a
, (int)b
);
1205 xfs_qm_dqtest_print(d
);
1207 xfs_qm_dqprint(dqp
);
1216 if (be64_to_cpu(dqp
->q_core
.d_icount
) != d
->d_icount
) {
1217 xfs_qm_dqtest_failed(d
, dqp
, "icount mismatch",
1218 be64_to_cpu(dqp
->q_core
.d_icount
),
1222 if (be64_to_cpu(dqp
->q_core
.d_bcount
) != d
->d_bcount
) {
1223 xfs_qm_dqtest_failed(d
, dqp
, "bcount mismatch",
1224 be64_to_cpu(dqp
->q_core
.d_bcount
),
1228 if (dqp
->q_core
.d_blk_softlimit
&&
1229 be64_to_cpu(dqp
->q_core
.d_bcount
) >=
1230 be64_to_cpu(dqp
->q_core
.d_blk_softlimit
)) {
1231 if (!dqp
->q_core
.d_btimer
&& dqp
->q_core
.d_id
) {
1233 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1234 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1238 if (dqp
->q_core
.d_ino_softlimit
&&
1239 be64_to_cpu(dqp
->q_core
.d_icount
) >=
1240 be64_to_cpu(dqp
->q_core
.d_ino_softlimit
)) {
1241 if (!dqp
->q_core
.d_itimer
&& dqp
->q_core
.d_id
) {
1243 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1244 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1250 cmn_err(CE_DEBUG
, "%d [%s] [0x%p] qchecked",
1251 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1264 /* xfs_qm_dqtest_print(d); */
1265 if ((error
= xfs_qm_dqget(d
->q_mount
, NULL
, d
->d_id
, d
->dq_flags
, 0,
1267 xfs_qm_dqtest_failed(d
, NULL
, "dqget failed", 0, 0, error
);
1270 xfs_dqtest_cmp2(d
, dqp
);
1275 xfs_qm_internalqcheck_dqget(
1279 xfs_dqtest_t
**O_dq
)
1284 h
= DQTEST_HASH(mp
, id
, type
);
1285 for (d
= (xfs_dqtest_t
*) h
->qh_next
; d
!= NULL
;
1286 d
= (xfs_dqtest_t
*) d
->HL_NEXT
) {
1287 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1288 if (d
->d_id
== id
&& mp
== d
->q_mount
) {
1293 d
= kmem_zalloc(sizeof(xfs_dqtest_t
), KM_SLEEP
);
1298 xfs_qm_hashinsert(h
, d
);
1304 xfs_qm_internalqcheck_get_dquots(
1312 if (XFS_IS_UQUOTA_ON(mp
))
1313 xfs_qm_internalqcheck_dqget(mp
, uid
, XFS_DQ_USER
, ud
);
1314 if (XFS_IS_GQUOTA_ON(mp
))
1315 xfs_qm_internalqcheck_dqget(mp
, gid
, XFS_DQ_GROUP
, gd
);
1316 else if (XFS_IS_PQUOTA_ON(mp
))
1317 xfs_qm_internalqcheck_dqget(mp
, projid
, XFS_DQ_PROJ
, gd
);
1322 xfs_qm_internalqcheck_dqadjust(
1327 d
->d_bcount
+= (xfs_qcnt_t
)ip
->i_d
.di_nblocks
;
1331 xfs_qm_internalqcheck_adjust(
1332 xfs_mount_t
*mp
, /* mount point for filesystem */
1333 xfs_ino_t ino
, /* inode number to get data for */
1334 void __user
*buffer
, /* not used */
1335 int ubsize
, /* not used */
1336 void *private_data
, /* not used */
1337 xfs_daddr_t bno
, /* starting block of inode cluster */
1338 int *ubused
, /* not used */
1339 void *dip
, /* not used */
1340 int *res
) /* bulkstat result code */
1343 xfs_dqtest_t
*ud
, *gd
;
1345 boolean_t ipreleased
;
1348 ASSERT(XFS_IS_QUOTA_RUNNING(mp
));
1350 if (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
) {
1351 *res
= BULKSTAT_RV_NOTHING
;
1352 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1353 (unsigned long long) ino
,
1354 (unsigned long long) mp
->m_sb
.sb_uquotino
,
1355 (unsigned long long) mp
->m_sb
.sb_gquotino
);
1356 return XFS_ERROR(EINVAL
);
1358 ipreleased
= B_FALSE
;
1360 lock_flags
= XFS_ILOCK_SHARED
;
1361 if ((error
= xfs_iget(mp
, NULL
, ino
, 0, lock_flags
, &ip
, bno
))) {
1362 *res
= BULKSTAT_RV_NOTHING
;
1366 if (ip
->i_d
.di_mode
== 0) {
1367 xfs_iput_new(ip
, lock_flags
);
1368 *res
= BULKSTAT_RV_NOTHING
;
1369 return XFS_ERROR(ENOENT
);
1373 * This inode can have blocks after eof which can get released
1374 * when we send it to inactive. Since we don't check the dquot
1375 * until the after all our calculations are done, we must get rid
1379 xfs_iput(ip
, lock_flags
);
1380 ipreleased
= B_TRUE
;
1383 xfs_qm_internalqcheck_get_dquots(mp
,
1384 (xfs_dqid_t
) ip
->i_d
.di_uid
,
1385 (xfs_dqid_t
) ip
->i_d
.di_projid
,
1386 (xfs_dqid_t
) ip
->i_d
.di_gid
,
1388 if (XFS_IS_UQUOTA_ON(mp
)) {
1390 xfs_qm_internalqcheck_dqadjust(ip
, ud
);
1392 if (XFS_IS_OQUOTA_ON(mp
)) {
1394 xfs_qm_internalqcheck_dqadjust(ip
, gd
);
1396 xfs_iput(ip
, lock_flags
);
1397 *res
= BULKSTAT_RV_DIDONE
;
1402 /* PRIVATE, debugging */
1404 xfs_qm_internalqcheck(
1410 xfs_dqtest_t
*d
, *e
;
1415 qmtest_hashmask
= 32;
1420 if (! XFS_IS_QUOTA_ON(mp
))
1421 return XFS_ERROR(ESRCH
);
1423 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1424 XFS_bflush(mp
->m_ddev_targp
);
1425 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1426 XFS_bflush(mp
->m_ddev_targp
);
1428 mutex_lock(&qcheck_lock
);
1429 /* There should be absolutely no quota activity while this
1431 qmtest_udqtab
= kmem_zalloc(qmtest_hashmask
*
1432 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1433 qmtest_gdqtab
= kmem_zalloc(qmtest_hashmask
*
1434 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1437 * Iterate thru all the inodes in the file system,
1438 * adjusting the corresponding dquot counters
1440 if ((error
= xfs_bulkstat(mp
, &lastino
, &count
,
1441 xfs_qm_internalqcheck_adjust
, NULL
,
1442 0, NULL
, BULKSTAT_FG_IGET
, &done
))) {
1447 cmn_err(CE_DEBUG
, "Bulkstat returned error 0x%x", error
);
1449 cmn_err(CE_DEBUG
, "Checking results against system dquots");
1450 for (i
= 0; i
< qmtest_hashmask
; i
++) {
1451 h1
= &qmtest_udqtab
[i
];
1452 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1454 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1455 kmem_free(d
, sizeof(xfs_dqtest_t
));
1458 h1
= &qmtest_gdqtab
[i
];
1459 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1461 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1462 kmem_free(d
, sizeof(xfs_dqtest_t
));
1467 if (qmtest_nfails
) {
1468 cmn_err(CE_DEBUG
, "******** quotacheck failed ********");
1469 cmn_err(CE_DEBUG
, "failures = %d", qmtest_nfails
);
1471 cmn_err(CE_DEBUG
, "******** quotacheck successful! ********");
1473 kmem_free(qmtest_udqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1474 kmem_free(qmtest_gdqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1475 mutex_unlock(&qcheck_lock
);
1476 return (qmtest_nfails
);