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
23 #include "xfs_trans.h"
28 #include "xfs_alloc.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_quota.h"
31 #include "xfs_mount.h"
32 #include "xfs_bmap_btree.h"
33 #include "xfs_alloc_btree.h"
34 #include "xfs_ialloc_btree.h"
35 #include "xfs_dir_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_attr_sf.h"
38 #include "xfs_dinode.h"
39 #include "xfs_inode.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_itable.h"
43 #include "xfs_btree.h"
44 #include "xfs_rtalloc.h"
45 #include "xfs_error.h"
51 #include "xfs_buf_item.h"
52 #include "xfs_utils.h"
56 # define qdprintk(s, args...) cmn_err(CE_DEBUG, s, ## args)
58 # define qdprintk(s, args...) do { } while (0)
61 STATIC
int xfs_qm_scall_trunc_qfiles(xfs_mount_t
*, uint
);
62 STATIC
int xfs_qm_scall_getquota(xfs_mount_t
*, xfs_dqid_t
, uint
,
64 STATIC
int xfs_qm_scall_getqstat(xfs_mount_t
*, fs_quota_stat_t
*);
65 STATIC
int xfs_qm_scall_setqlim(xfs_mount_t
*, xfs_dqid_t
, uint
,
67 STATIC
int xfs_qm_scall_quotaon(xfs_mount_t
*, uint
);
68 STATIC
int xfs_qm_scall_quotaoff(xfs_mount_t
*, uint
, boolean_t
);
69 STATIC
int xfs_qm_log_quotaoff(xfs_mount_t
*, xfs_qoff_logitem_t
**, uint
);
70 STATIC
int xfs_qm_log_quotaoff_end(xfs_mount_t
*, xfs_qoff_logitem_t
*,
72 STATIC uint
xfs_qm_import_flags(uint
);
73 STATIC uint
xfs_qm_export_flags(uint
);
74 STATIC uint
xfs_qm_import_qtype_flags(uint
);
75 STATIC uint
xfs_qm_export_qtype_flags(uint
);
76 STATIC
void xfs_qm_export_dquot(xfs_mount_t
*, xfs_disk_dquot_t
*,
81 * The main distribution switch of all XFS quotactl system calls.
95 mp
= XFS_VFSTOM(vfsp
);
97 ASSERT(addr
!= NULL
|| cmd
== Q_XQUOTASYNC
);
100 * The following commands are valid even when quotaoff.
105 * Truncate quota files. quota must be off.
107 if (XFS_IS_QUOTA_ON(mp
))
108 return XFS_ERROR(EINVAL
);
109 if (vfsp
->vfs_flag
& VFS_RDONLY
)
110 return XFS_ERROR(EROFS
);
111 return (xfs_qm_scall_trunc_qfiles(mp
,
112 xfs_qm_import_qtype_flags(*(uint
*)addr
)));
116 * Get quota status information.
118 return (xfs_qm_scall_getqstat(mp
, (fs_quota_stat_t
*)addr
));
122 * QUOTAON - enabling quota enforcement.
123 * Quota accounting must be turned on at mount time.
125 if (vfsp
->vfs_flag
& VFS_RDONLY
)
126 return XFS_ERROR(EROFS
);
127 return (xfs_qm_scall_quotaon(mp
,
128 xfs_qm_import_flags(*(uint
*)addr
)));
131 if (vfsp
->vfs_flag
& VFS_RDONLY
)
132 return XFS_ERROR(EROFS
);
136 return (xfs_sync_inodes(mp
, SYNC_DELWRI
, 0, NULL
));
142 if (! XFS_IS_QUOTA_ON(mp
))
143 return XFS_ERROR(ESRCH
);
147 if (vfsp
->vfs_flag
& VFS_RDONLY
)
148 return XFS_ERROR(EROFS
);
149 error
= xfs_qm_scall_quotaoff(mp
,
150 xfs_qm_import_flags(*(uint
*)addr
),
155 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
156 (fs_disk_quota_t
*)addr
);
159 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
160 (fs_disk_quota_t
*)addr
);
163 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_PROJ
,
164 (fs_disk_quota_t
*)addr
);
168 if (vfsp
->vfs_flag
& VFS_RDONLY
)
169 return XFS_ERROR(EROFS
);
170 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
171 (fs_disk_quota_t
*)addr
);
174 if (vfsp
->vfs_flag
& VFS_RDONLY
)
175 return XFS_ERROR(EROFS
);
176 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
177 (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_PROJ
,
183 (fs_disk_quota_t
*)addr
);
187 error
= XFS_ERROR(EINVAL
);
195 * Turn off quota accounting and/or enforcement for all udquots and/or
196 * gdquots. Called only at unmount time.
198 * This assumes that there are no dquots of this file system cached
199 * incore, and modifies the ondisk dquot directly. Therefore, for example,
200 * it is an error to call this twice, without purging the cache.
203 xfs_qm_scall_quotaoff(
211 uint inactivate_flags
;
212 xfs_qoff_logitem_t
*qoffstart
;
215 if (!force
&& !capable(CAP_SYS_ADMIN
))
216 return XFS_ERROR(EPERM
);
218 * No file system can have quotas enabled on disk but not in core.
219 * Note that quota utilities (like quotaoff) _expect_
220 * errno == EEXIST here.
222 if ((mp
->m_qflags
& flags
) == 0)
223 return XFS_ERROR(EEXIST
);
226 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
229 * We don't want to deal with two quotaoffs messing up each other,
230 * so we're going to serialize it. quotaoff isn't exactly a performance
232 * If quotaoff, then we must be dealing with the root filesystem.
234 ASSERT(mp
->m_quotainfo
);
236 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
238 ASSERT(mp
->m_quotainfo
);
241 * If we're just turning off quota enforcement, change mp and go.
243 if ((flags
& XFS_ALL_QUOTA_ACCT
) == 0) {
244 mp
->m_qflags
&= ~(flags
);
247 mp
->m_sb
.sb_qflags
= mp
->m_qflags
;
248 XFS_SB_UNLOCK(mp
, s
);
249 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
251 /* XXX what to do if error ? Revert back to old vals incore ? */
252 error
= xfs_qm_write_sb_changes(mp
, XFS_SB_QFLAGS
);
257 inactivate_flags
= 0;
259 * If accounting is off, we must turn enforcement off, clear the
260 * quota 'CHKD' certificate to make it known that we have to
261 * do a quotacheck the next time this quota is turned on.
263 if (flags
& XFS_UQUOTA_ACCT
) {
264 dqtype
|= XFS_QMOPT_UQUOTA
;
265 flags
|= (XFS_UQUOTA_CHKD
| XFS_UQUOTA_ENFD
);
266 inactivate_flags
|= XFS_UQUOTA_ACTIVE
;
268 if (flags
& XFS_GQUOTA_ACCT
) {
269 dqtype
|= XFS_QMOPT_GQUOTA
;
270 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
271 inactivate_flags
|= XFS_GQUOTA_ACTIVE
;
272 } else if (flags
& XFS_PQUOTA_ACCT
) {
273 dqtype
|= XFS_QMOPT_PQUOTA
;
274 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
275 inactivate_flags
|= XFS_PQUOTA_ACTIVE
;
279 * Nothing to do? Don't complain. This happens when we're just
280 * turning off quota enforcement.
282 if ((mp
->m_qflags
& flags
) == 0) {
283 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
288 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
291 xfs_qm_log_quotaoff(mp
, &qoffstart
, flags
);
294 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
295 * to take care of the race between dqget and quotaoff. We don't take
296 * any special locks to reset these bits. All processes need to check
297 * these bits *after* taking inode lock(s) to see if the particular
298 * quota type is in the process of being turned off. If *ACTIVE, it is
299 * guaranteed that all dquot structures and all quotainode ptrs will all
300 * stay valid as long as that inode is kept locked.
302 * There is no turning back after this.
304 mp
->m_qflags
&= ~inactivate_flags
;
307 * Give back all the dquot reference(s) held by inodes.
308 * Here we go thru every single incore inode in this file system, and
309 * do a dqrele on the i_udquot/i_gdquot that it may have.
310 * Essentially, as long as somebody has an inode locked, this guarantees
311 * that quotas will not be turned off. This is handy because in a
312 * transaction once we lock the inode(s) and check for quotaon, we can
313 * depend on the quota inodes (and other things) being valid as long as
314 * we keep the lock(s).
316 xfs_qm_dqrele_all_inodes(mp
, flags
);
319 * Next we make the changes in the quota flag in the mount struct.
320 * This isn't protected by a particular lock directly, because we
321 * don't want to take a mrlock everytime we depend on quotas being on.
323 mp
->m_qflags
&= ~(flags
);
326 * Go through all the dquots of this file system and purge them,
327 * according to what was turned off. We may not be able to get rid
328 * of all dquots, because dquots can have temporary references that
329 * are not attached to inodes. eg. xfs_setattr, xfs_create.
330 * So, if we couldn't purge all the dquots from the filesystem,
331 * we can't get rid of the incore data structures.
333 while ((nculprits
= xfs_qm_dqpurge_all(mp
, dqtype
|XFS_QMOPT_QUOTAOFF
)))
334 delay(10 * nculprits
);
337 * Transactions that had started before ACTIVE state bit was cleared
338 * could have logged many dquots, so they'd have higher LSNs than
339 * the first QUOTAOFF log record does. If we happen to crash when
340 * the tail of the log has gone past the QUOTAOFF record, but
341 * before the last dquot modification, those dquots __will__
342 * recover, and that's not good.
344 * So, we have QUOTAOFF start and end logitems; the start
345 * logitem won't get overwritten until the end logitem appears...
347 xfs_qm_log_quotaoff_end(mp
, qoffstart
, flags
);
350 * If quotas is completely disabled, close shop.
352 if (((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET1
) ||
353 ((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET2
)) {
354 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
355 xfs_qm_destroy_quotainfo(mp
);
360 * Release our quotainode references, and vn_purge them,
361 * if we don't need them anymore.
363 if ((dqtype
& XFS_QMOPT_UQUOTA
) && XFS_QI_UQIP(mp
)) {
364 XFS_PURGE_INODE(XFS_QI_UQIP(mp
));
365 XFS_QI_UQIP(mp
) = NULL
;
367 if ((dqtype
& (XFS_QMOPT_GQUOTA
|XFS_QMOPT_PQUOTA
)) && XFS_QI_GQIP(mp
)) {
368 XFS_PURGE_INODE(XFS_QI_GQIP(mp
));
369 XFS_QI_GQIP(mp
) = NULL
;
371 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
377 xfs_qm_scall_trunc_qfiles(
384 if (!capable(CAP_SYS_ADMIN
))
385 return XFS_ERROR(EPERM
);
387 if (!XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) || flags
== 0) {
388 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags
, mp
->m_qflags
);
389 return XFS_ERROR(EINVAL
);
392 if ((flags
& XFS_DQ_USER
) && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
393 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
, 0, 0, &qip
, 0);
395 (void) xfs_truncate_file(mp
, qip
);
396 VN_RELE(XFS_ITOV(qip
));
400 if ((flags
& (XFS_DQ_GROUP
|XFS_DQ_PROJ
)) &&
401 mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
402 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
, 0, 0, &qip
, 0);
404 (void) xfs_truncate_file(mp
, qip
);
405 VN_RELE(XFS_ITOV(qip
));
414 * Switch on (a given) quota enforcement for a filesystem. This takes
415 * effect immediately.
416 * (Switching on quota accounting must be done at mount time.)
419 xfs_qm_scall_quotaon(
429 if (!capable(CAP_SYS_ADMIN
))
430 return XFS_ERROR(EPERM
);
432 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
434 * Switching on quota accounting must be done at mount time.
436 accflags
= flags
& XFS_ALL_QUOTA_ACCT
;
437 flags
&= ~(XFS_ALL_QUOTA_ACCT
);
442 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp
->m_qflags
);
443 return XFS_ERROR(EINVAL
);
446 /* No fs can turn on quotas with a delayed effect */
447 ASSERT((flags
& XFS_ALL_QUOTA_ACCT
) == 0);
450 * Can't enforce without accounting. We check the superblock
451 * qflags here instead of m_qflags because rootfs can have
452 * quota acct on ondisk without m_qflags' knowing.
454 if (((flags
& XFS_UQUOTA_ACCT
) == 0 &&
455 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) == 0 &&
456 (flags
& XFS_UQUOTA_ENFD
))
458 ((flags
& XFS_PQUOTA_ACCT
) == 0 &&
459 (mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) == 0 &&
460 (flags
& XFS_OQUOTA_ENFD
))
462 ((flags
& XFS_GQUOTA_ACCT
) == 0 &&
463 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) == 0 &&
464 (flags
& XFS_OQUOTA_ENFD
))) {
465 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
466 flags
, mp
->m_sb
.sb_qflags
);
467 return XFS_ERROR(EINVAL
);
470 * If everything's upto-date incore, then don't waste time.
472 if ((mp
->m_qflags
& flags
) == flags
)
473 return XFS_ERROR(EEXIST
);
476 * Change sb_qflags on disk but not incore mp->qflags
477 * if this is the root filesystem.
480 qf
= mp
->m_sb
.sb_qflags
;
481 mp
->m_sb
.sb_qflags
= qf
| flags
;
482 XFS_SB_UNLOCK(mp
, s
);
485 * There's nothing to change if it's the same.
487 if ((qf
& flags
) == flags
&& sbflags
== 0)
488 return XFS_ERROR(EEXIST
);
489 sbflags
|= XFS_SB_QFLAGS
;
491 if ((error
= xfs_qm_write_sb_changes(mp
, sbflags
)))
494 * If we aren't trying to switch on quota enforcement, we are done.
496 if (((mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) !=
497 (mp
->m_qflags
& XFS_UQUOTA_ACCT
)) ||
498 ((mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) !=
499 (mp
->m_qflags
& XFS_PQUOTA_ACCT
)) ||
500 ((mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) !=
501 (mp
->m_qflags
& XFS_GQUOTA_ACCT
)) ||
502 (flags
& XFS_ALL_QUOTA_ENFD
) == 0)
505 if (! XFS_IS_QUOTA_RUNNING(mp
))
506 return XFS_ERROR(ESRCH
);
509 * Switch on quota enforcement in core.
511 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
512 mp
->m_qflags
|= (flags
& XFS_ALL_QUOTA_ENFD
);
513 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
520 * Return quota status information, such as uquota-off, enforcements, etc.
523 xfs_qm_scall_getqstat(
525 fs_quota_stat_t
*out
)
527 xfs_inode_t
*uip
, *gip
;
528 boolean_t tempuqip
, tempgqip
;
531 tempuqip
= tempgqip
= B_FALSE
;
532 memset(out
, 0, sizeof(fs_quota_stat_t
));
534 out
->qs_version
= FS_QSTAT_VERSION
;
535 if (! XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
)) {
536 out
->qs_uquota
.qfs_ino
= NULLFSINO
;
537 out
->qs_gquota
.qfs_ino
= NULLFSINO
;
540 out
->qs_flags
= (__uint16_t
) xfs_qm_export_flags(mp
->m_qflags
&
542 XFS_ALL_QUOTA_ENFD
));
544 out
->qs_uquota
.qfs_ino
= mp
->m_sb
.sb_uquotino
;
545 out
->qs_gquota
.qfs_ino
= mp
->m_sb
.sb_gquotino
;
547 if (mp
->m_quotainfo
) {
548 uip
= mp
->m_quotainfo
->qi_uquotaip
;
549 gip
= mp
->m_quotainfo
->qi_gquotaip
;
551 if (!uip
&& mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
552 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
,
556 if (!gip
&& mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
557 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
,
562 out
->qs_uquota
.qfs_nblks
= uip
->i_d
.di_nblocks
;
563 out
->qs_uquota
.qfs_nextents
= uip
->i_d
.di_nextents
;
565 VN_RELE(XFS_ITOV(uip
));
568 out
->qs_gquota
.qfs_nblks
= gip
->i_d
.di_nblocks
;
569 out
->qs_gquota
.qfs_nextents
= gip
->i_d
.di_nextents
;
571 VN_RELE(XFS_ITOV(gip
));
573 if (mp
->m_quotainfo
) {
574 out
->qs_incoredqs
= XFS_QI_MPLNDQUOTS(mp
);
575 out
->qs_btimelimit
= XFS_QI_BTIMELIMIT(mp
);
576 out
->qs_itimelimit
= XFS_QI_ITIMELIMIT(mp
);
577 out
->qs_rtbtimelimit
= XFS_QI_RTBTIMELIMIT(mp
);
578 out
->qs_bwarnlimit
= XFS_QI_BWARNLIMIT(mp
);
579 out
->qs_iwarnlimit
= XFS_QI_IWARNLIMIT(mp
);
585 * Adjust quota limits, and start/stop timers accordingly.
588 xfs_qm_scall_setqlim(
592 fs_disk_quota_t
*newlim
)
594 xfs_disk_dquot_t
*ddq
;
598 xfs_qcnt_t hard
, soft
;
600 if (!capable(CAP_SYS_ADMIN
))
601 return XFS_ERROR(EPERM
);
603 if ((newlim
->d_fieldmask
&
604 (FS_DQ_LIMIT_MASK
|FS_DQ_TIMER_MASK
|FS_DQ_WARNS_MASK
)) == 0)
607 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_SETQLIM
);
608 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_disk_dquot_t
) + 128,
609 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
610 xfs_trans_cancel(tp
, 0);
615 * We don't want to race with a quotaoff so take the quotaoff lock.
616 * (We don't hold an inode lock, so there's nothing else to stop
617 * a quotaoff from happening). (XXXThis doesn't currently happen
618 * because we take the vfslock before calling xfs_qm_sysent).
620 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)), PINOD
);
623 * Get the dquot (locked), and join it to the transaction.
624 * Allocate the dquot if this doesn't exist.
626 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, XFS_QMOPT_DQALLOC
, &dqp
))) {
627 xfs_trans_cancel(tp
, XFS_TRANS_ABORT
);
628 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
629 ASSERT(error
!= ENOENT
);
632 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: AFT DQGET");
633 xfs_trans_dqjoin(tp
, dqp
);
637 * Make sure that hardlimits are >= soft limits before changing.
639 hard
= (newlim
->d_fieldmask
& FS_DQ_BHARD
) ?
640 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_hardlimit
) :
641 INT_GET(ddq
->d_blk_hardlimit
, ARCH_CONVERT
);
642 soft
= (newlim
->d_fieldmask
& FS_DQ_BSOFT
) ?
643 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_softlimit
) :
644 INT_GET(ddq
->d_blk_softlimit
, ARCH_CONVERT
);
645 if (hard
== 0 || hard
>= soft
) {
646 INT_SET(ddq
->d_blk_hardlimit
, ARCH_CONVERT
, hard
);
647 INT_SET(ddq
->d_blk_softlimit
, ARCH_CONVERT
, soft
);
649 mp
->m_quotainfo
->qi_bhardlimit
= hard
;
650 mp
->m_quotainfo
->qi_bsoftlimit
= soft
;
653 qdprintk("blkhard %Ld < blksoft %Ld\n", hard
, soft
);
655 hard
= (newlim
->d_fieldmask
& FS_DQ_RTBHARD
) ?
656 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_hardlimit
) :
657 INT_GET(ddq
->d_rtb_hardlimit
, ARCH_CONVERT
);
658 soft
= (newlim
->d_fieldmask
& FS_DQ_RTBSOFT
) ?
659 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_softlimit
) :
660 INT_GET(ddq
->d_rtb_softlimit
, ARCH_CONVERT
);
661 if (hard
== 0 || hard
>= soft
) {
662 INT_SET(ddq
->d_rtb_hardlimit
, ARCH_CONVERT
, hard
);
663 INT_SET(ddq
->d_rtb_softlimit
, ARCH_CONVERT
, soft
);
665 mp
->m_quotainfo
->qi_rtbhardlimit
= hard
;
666 mp
->m_quotainfo
->qi_rtbsoftlimit
= soft
;
669 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard
, soft
);
672 hard
= (newlim
->d_fieldmask
& FS_DQ_IHARD
) ?
673 (xfs_qcnt_t
) newlim
->d_ino_hardlimit
:
674 INT_GET(ddq
->d_ino_hardlimit
, ARCH_CONVERT
);
675 soft
= (newlim
->d_fieldmask
& FS_DQ_ISOFT
) ?
676 (xfs_qcnt_t
) newlim
->d_ino_softlimit
:
677 INT_GET(ddq
->d_ino_softlimit
, ARCH_CONVERT
);
678 if (hard
== 0 || hard
>= soft
) {
679 INT_SET(ddq
->d_ino_hardlimit
, ARCH_CONVERT
, hard
);
680 INT_SET(ddq
->d_ino_softlimit
, ARCH_CONVERT
, soft
);
682 mp
->m_quotainfo
->qi_ihardlimit
= hard
;
683 mp
->m_quotainfo
->qi_isoftlimit
= soft
;
686 qdprintk("ihard %Ld < isoft %Ld\n", hard
, soft
);
690 * Update warnings counter(s) if requested
692 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
693 INT_SET(ddq
->d_bwarns
, ARCH_CONVERT
, newlim
->d_bwarns
);
694 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
695 INT_SET(ddq
->d_iwarns
, ARCH_CONVERT
, newlim
->d_iwarns
);
696 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
697 INT_SET(ddq
->d_rtbwarns
, ARCH_CONVERT
, newlim
->d_rtbwarns
);
701 * Timelimits for the super user set the relative time
702 * the other users can be over quota for this file system.
703 * If it is zero a default is used. Ditto for the default
704 * soft and hard limit values (already done, above), and
707 if (newlim
->d_fieldmask
& FS_DQ_BTIMER
) {
708 mp
->m_quotainfo
->qi_btimelimit
= newlim
->d_btimer
;
709 INT_SET(ddq
->d_btimer
, ARCH_CONVERT
, newlim
->d_btimer
);
711 if (newlim
->d_fieldmask
& FS_DQ_ITIMER
) {
712 mp
->m_quotainfo
->qi_itimelimit
= newlim
->d_itimer
;
713 INT_SET(ddq
->d_itimer
, ARCH_CONVERT
, newlim
->d_itimer
);
715 if (newlim
->d_fieldmask
& FS_DQ_RTBTIMER
) {
716 mp
->m_quotainfo
->qi_rtbtimelimit
= newlim
->d_rtbtimer
;
717 INT_SET(ddq
->d_rtbtimer
, ARCH_CONVERT
, newlim
->d_rtbtimer
);
719 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
720 mp
->m_quotainfo
->qi_bwarnlimit
= newlim
->d_bwarns
;
721 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
722 mp
->m_quotainfo
->qi_iwarnlimit
= newlim
->d_iwarns
;
723 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
724 mp
->m_quotainfo
->qi_rtbwarnlimit
= newlim
->d_rtbwarns
;
727 * If the user is now over quota, start the timelimit.
728 * The user will not be 'warned'.
729 * Note that we keep the timers ticking, whether enforcement
730 * is on or off. We don't really want to bother with iterating
731 * over all ondisk dquots and turning the timers on/off.
733 xfs_qm_adjust_dqtimers(mp
, ddq
);
735 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
736 xfs_trans_log_dquot(tp
, dqp
);
738 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: COMMIT");
739 xfs_trans_commit(tp
, 0, NULL
);
742 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
748 xfs_qm_scall_getquota(
752 fs_disk_quota_t
*out
)
758 * Try to get the dquot. We don't want it allocated on disk, so
759 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
760 * exist, we'll get ENOENT back.
762 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, 0, &dqp
))) {
766 xfs_dqtrace_entry(dqp
, "Q_GETQUOTA SUCCESS");
768 * If everything's NULL, this dquot doesn't quite exist as far as
769 * our utility programs are concerned.
771 if (XFS_IS_DQUOT_UNINITIALIZED(dqp
)) {
773 return XFS_ERROR(ENOENT
);
775 /* xfs_qm_dqprint(dqp); */
777 * Convert the disk dquot to the exportable format
779 xfs_qm_export_dquot(mp
, &dqp
->q_core
, out
);
781 return (error
? XFS_ERROR(EFAULT
) : 0);
786 xfs_qm_log_quotaoff_end(
788 xfs_qoff_logitem_t
*startqoff
,
793 xfs_qoff_logitem_t
*qoffi
;
795 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF_END
);
797 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_qoff_logitem_t
) * 2,
798 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
799 xfs_trans_cancel(tp
, 0);
803 qoffi
= xfs_trans_get_qoff_item(tp
, startqoff
,
804 flags
& XFS_ALL_QUOTA_ACCT
);
805 xfs_trans_log_quotaoff_item(tp
, qoffi
);
808 * We have to make sure that the transaction is secure on disk before we
809 * return and actually stop quota accounting. So, make it synchronous.
810 * We don't care about quotoff's performance.
812 xfs_trans_set_sync(tp
);
813 error
= xfs_trans_commit(tp
, 0, NULL
);
821 xfs_qoff_logitem_t
**qoffstartp
,
827 xfs_qoff_logitem_t
*qoffi
=NULL
;
830 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF
);
831 if ((error
= xfs_trans_reserve(tp
, 0,
832 sizeof(xfs_qoff_logitem_t
) * 2 +
833 mp
->m_sb
.sb_sectsize
+ 128,
836 XFS_DEFAULT_LOG_COUNT
))) {
840 qoffi
= xfs_trans_get_qoff_item(tp
, NULL
, flags
& XFS_ALL_QUOTA_ACCT
);
841 xfs_trans_log_quotaoff_item(tp
, qoffi
);
844 oldsbqflag
= mp
->m_sb
.sb_qflags
;
845 mp
->m_sb
.sb_qflags
= (mp
->m_qflags
& ~(flags
)) & XFS_MOUNT_QUOTA_ALL
;
846 XFS_SB_UNLOCK(mp
, s
);
848 xfs_mod_sb(tp
, XFS_SB_QFLAGS
);
851 * We have to make sure that the transaction is secure on disk before we
852 * return and actually stop quota accounting. So, make it synchronous.
853 * We don't care about quotoff's performance.
855 xfs_trans_set_sync(tp
);
856 error
= xfs_trans_commit(tp
, 0, NULL
);
860 xfs_trans_cancel(tp
, 0);
862 * No one else is modifying sb_qflags, so this is OK.
863 * We still hold the quotaofflock.
866 mp
->m_sb
.sb_qflags
= oldsbqflag
;
867 XFS_SB_UNLOCK(mp
, s
);
875 * Translate an internal style on-disk-dquot to the exportable format.
876 * The main differences are that the counters/limits are all in Basic
877 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
878 * to be converted to the native endianness.
883 xfs_disk_dquot_t
*src
,
884 struct fs_disk_quota
*dst
)
886 memset(dst
, 0, sizeof(*dst
));
887 dst
->d_version
= FS_DQUOT_VERSION
; /* different from src->d_version */
889 xfs_qm_export_qtype_flags(INT_GET(src
->d_flags
, ARCH_CONVERT
));
890 dst
->d_id
= INT_GET(src
->d_id
, ARCH_CONVERT
);
891 dst
->d_blk_hardlimit
= (__uint64_t
)
892 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_blk_hardlimit
, ARCH_CONVERT
));
893 dst
->d_blk_softlimit
= (__uint64_t
)
894 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_blk_softlimit
, ARCH_CONVERT
));
895 dst
->d_ino_hardlimit
= (__uint64_t
)
896 INT_GET(src
->d_ino_hardlimit
, ARCH_CONVERT
);
897 dst
->d_ino_softlimit
= (__uint64_t
)
898 INT_GET(src
->d_ino_softlimit
, ARCH_CONVERT
);
899 dst
->d_bcount
= (__uint64_t
)
900 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_bcount
, ARCH_CONVERT
));
901 dst
->d_icount
= (__uint64_t
) INT_GET(src
->d_icount
, ARCH_CONVERT
);
902 dst
->d_btimer
= (__uint32_t
) INT_GET(src
->d_btimer
, ARCH_CONVERT
);
903 dst
->d_itimer
= (__uint32_t
) INT_GET(src
->d_itimer
, ARCH_CONVERT
);
904 dst
->d_iwarns
= INT_GET(src
->d_iwarns
, ARCH_CONVERT
);
905 dst
->d_bwarns
= INT_GET(src
->d_bwarns
, ARCH_CONVERT
);
907 dst
->d_rtb_hardlimit
= (__uint64_t
)
908 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtb_hardlimit
, ARCH_CONVERT
));
909 dst
->d_rtb_softlimit
= (__uint64_t
)
910 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtb_softlimit
, ARCH_CONVERT
));
911 dst
->d_rtbcount
= (__uint64_t
)
912 XFS_FSB_TO_BB(mp
, INT_GET(src
->d_rtbcount
, ARCH_CONVERT
));
913 dst
->d_rtbtimer
= (__uint32_t
) INT_GET(src
->d_rtbtimer
, ARCH_CONVERT
);
914 dst
->d_rtbwarns
= INT_GET(src
->d_rtbwarns
, ARCH_CONVERT
);
917 * Internally, we don't reset all the timers when quota enforcement
918 * gets turned off. No need to confuse the userlevel code,
919 * so return zeroes in that case.
921 if (! XFS_IS_QUOTA_ENFORCED(mp
)) {
928 if (XFS_IS_QUOTA_ENFORCED(mp
) && dst
->d_id
!= 0) {
929 if (((int) dst
->d_bcount
>= (int) dst
->d_blk_softlimit
) &&
930 (dst
->d_blk_softlimit
> 0)) {
931 ASSERT(dst
->d_btimer
!= 0);
933 if (((int) dst
->d_icount
>= (int) dst
->d_ino_softlimit
) &&
934 (dst
->d_ino_softlimit
> 0)) {
935 ASSERT(dst
->d_itimer
!= 0);
942 xfs_qm_import_qtype_flags(
948 * Can't be more than one, or none.
950 if (((uflags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ==
951 (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ||
952 ((uflags
& (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ==
953 (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ||
954 ((uflags
& (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ==
955 (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ||
956 ((uflags
& (XFS_GROUP_QUOTA
|XFS_USER_QUOTA
|XFS_PROJ_QUOTA
)) == 0))
959 oflags
|= (uflags
& XFS_USER_QUOTA
) ? XFS_DQ_USER
: 0;
960 oflags
|= (uflags
& XFS_PROJ_QUOTA
) ? XFS_DQ_PROJ
: 0;
961 oflags
|= (uflags
& XFS_GROUP_QUOTA
) ? XFS_DQ_GROUP
: 0;
966 xfs_qm_export_qtype_flags(
970 * Can't be more than one, or none.
972 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
)) !=
973 (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
));
974 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
)) !=
975 (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
));
976 ASSERT((flags
& (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
)) !=
977 (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
));
978 ASSERT((flags
& (XFS_PROJ_QUOTA
|XFS_USER_QUOTA
|XFS_GROUP_QUOTA
)) != 0);
980 return (flags
& XFS_DQ_USER
) ?
981 XFS_USER_QUOTA
: (flags
& XFS_DQ_PROJ
) ?
982 XFS_PROJ_QUOTA
: XFS_GROUP_QUOTA
;
991 if (uflags
& XFS_QUOTA_UDQ_ACCT
)
992 flags
|= XFS_UQUOTA_ACCT
;
993 if (uflags
& XFS_QUOTA_PDQ_ACCT
)
994 flags
|= XFS_PQUOTA_ACCT
;
995 if (uflags
& XFS_QUOTA_GDQ_ACCT
)
996 flags
|= XFS_GQUOTA_ACCT
;
997 if (uflags
& XFS_QUOTA_UDQ_ENFD
)
998 flags
|= XFS_UQUOTA_ENFD
;
999 if (uflags
& (XFS_QUOTA_PDQ_ENFD
|XFS_QUOTA_GDQ_ENFD
))
1000 flags
|= XFS_OQUOTA_ENFD
;
1006 xfs_qm_export_flags(
1012 if (flags
& XFS_UQUOTA_ACCT
)
1013 uflags
|= XFS_QUOTA_UDQ_ACCT
;
1014 if (flags
& XFS_PQUOTA_ACCT
)
1015 uflags
|= XFS_QUOTA_PDQ_ACCT
;
1016 if (flags
& XFS_GQUOTA_ACCT
)
1017 uflags
|= XFS_QUOTA_GDQ_ACCT
;
1018 if (flags
& XFS_UQUOTA_ENFD
)
1019 uflags
|= XFS_QUOTA_UDQ_ENFD
;
1020 if (flags
& (XFS_OQUOTA_ENFD
)) {
1021 uflags
|= (flags
& XFS_GQUOTA_ACCT
) ?
1022 XFS_QUOTA_GDQ_ENFD
: XFS_QUOTA_PDQ_ENFD
;
1029 * Go thru all the inodes in the file system, releasing their dquots.
1030 * Note that the mount structure gets modified to indicate that quotas are off
1031 * AFTER this, in the case of quotaoff. This also gets called from
1035 xfs_qm_dqrele_all_inodes(
1036 struct xfs_mount
*mp
,
1039 xfs_inode_t
*ip
, *topino
;
1042 boolean_t vnode_refd
;
1044 ASSERT(mp
->m_quotainfo
);
1046 XFS_MOUNT_ILOCK(mp
);
1050 XFS_MOUNT_IUNLOCK(mp
);
1054 /* Skip markers inserted by xfs_sync */
1055 if (ip
->i_mount
== NULL
) {
1059 /* Root inode, rbmip and rsumip have associated blocks */
1060 if (ip
== XFS_QI_UQIP(mp
) || ip
== XFS_QI_GQIP(mp
)) {
1061 ASSERT(ip
->i_udquot
== NULL
);
1062 ASSERT(ip
->i_gdquot
== NULL
);
1066 vp
= XFS_ITOV_NULL(ip
);
1068 ASSERT(ip
->i_udquot
== NULL
);
1069 ASSERT(ip
->i_gdquot
== NULL
);
1073 vnode_refd
= B_FALSE
;
1074 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1075 ireclaims
= mp
->m_ireclaims
;
1076 topino
= mp
->m_inodes
;
1081 XFS_MOUNT_IUNLOCK(mp
);
1082 /* XXX restart limit ? */
1083 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1084 vnode_refd
= B_TRUE
;
1086 ireclaims
= mp
->m_ireclaims
;
1087 topino
= mp
->m_inodes
;
1088 XFS_MOUNT_IUNLOCK(mp
);
1092 * We don't keep the mountlock across the dqrele() call,
1093 * since it can take a while..
1095 if ((flags
& XFS_UQUOTA_ACCT
) && ip
->i_udquot
) {
1096 xfs_qm_dqrele(ip
->i_udquot
);
1097 ip
->i_udquot
= NULL
;
1099 if (flags
& (XFS_PQUOTA_ACCT
|XFS_GQUOTA_ACCT
) && ip
->i_gdquot
) {
1100 xfs_qm_dqrele(ip
->i_gdquot
);
1101 ip
->i_gdquot
= NULL
;
1103 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1105 * Wait until we've dropped the ilock and mountlock to
1106 * do the vn_rele. Or be condemned to an eternity in the
1107 * inactive code in hell.
1111 XFS_MOUNT_ILOCK(mp
);
1113 * If an inode was inserted or removed, we gotta
1116 if (topino
!= mp
->m_inodes
|| mp
->m_ireclaims
!= ireclaims
) {
1117 /* XXX use a sentinel */
1121 } while (ip
!= mp
->m_inodes
);
1123 XFS_MOUNT_IUNLOCK(mp
);
1126 /*------------------------------------------------------------------------*/
1129 * This contains all the test functions for XFS disk quotas.
1130 * Currently it does a quota accounting check. ie. it walks through
1131 * all inodes in the file system, calculating the dquot accounting fields,
1132 * and prints out any inconsistencies.
1134 xfs_dqhash_t
*qmtest_udqtab
;
1135 xfs_dqhash_t
*qmtest_gdqtab
;
1136 int qmtest_hashmask
;
1138 mutex_t qcheck_lock
;
1140 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1141 (__psunsigned_t)(id)) & \
1142 (qmtest_hashmask - 1))
1144 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1146 DQTEST_HASHVAL(mp, id)) : \
1148 DQTEST_HASHVAL(mp, id)))
1150 #define DQTEST_LIST_PRINT(l, NXT, title) \
1152 xfs_dqtest_t *dqp; int i = 0;\
1153 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1154 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1155 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1156 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1157 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1158 dqp->d_bcount, dqp->d_icount); } \
1161 typedef struct dqtest
{
1162 xfs_dqmarker_t q_lists
;
1163 xfs_dqhash_t
*q_hash
; /* the hashchain header */
1164 xfs_mount_t
*q_mount
; /* filesystem this relates to */
1165 xfs_dqid_t d_id
; /* user id or group id */
1166 xfs_qcnt_t d_bcount
; /* # disk blocks owned by the user */
1167 xfs_qcnt_t d_icount
; /* # inodes owned by the user */
1171 xfs_qm_hashinsert(xfs_dqhash_t
*h
, xfs_dqtest_t
*dqp
)
1174 if (((d
) = (h
)->qh_next
))
1175 (d
)->HL_PREVP
= &((dqp
)->HL_NEXT
);
1177 (dqp
)->HL_PREVP
= &((h
)->qh_next
);
1178 (h
)->qh_next
= (xfs_dquot_t
*)dqp
;
1183 xfs_qm_dqtest_print(
1186 cmn_err(CE_DEBUG
, "-----------DQTEST DQUOT----------------");
1187 cmn_err(CE_DEBUG
, "---- dquot ID = %d", d
->d_id
);
1188 cmn_err(CE_DEBUG
, "---- fs = 0x%p", d
->q_mount
);
1189 cmn_err(CE_DEBUG
, "---- bcount = %Lu (0x%x)",
1190 d
->d_bcount
, (int)d
->d_bcount
);
1191 cmn_err(CE_DEBUG
, "---- icount = %Lu (0x%x)",
1192 d
->d_icount
, (int)d
->d_icount
);
1193 cmn_err(CE_DEBUG
, "---------------------------");
1197 xfs_qm_dqtest_failed(
1207 cmn_err(CE_DEBUG
, "quotacheck failed id=%d, err=%d\nreason: %s",
1208 INT_GET(d
->d_id
, ARCH_CONVERT
), error
, reason
);
1210 cmn_err(CE_DEBUG
, "quotacheck failed id=%d (%s) [%d != %d]",
1211 INT_GET(d
->d_id
, ARCH_CONVERT
), reason
, (int)a
, (int)b
);
1212 xfs_qm_dqtest_print(d
);
1214 xfs_qm_dqprint(dqp
);
1223 if (INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
) != d
->d_icount
) {
1224 xfs_qm_dqtest_failed(d
, dqp
, "icount mismatch",
1225 INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
),
1229 if (INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
) != d
->d_bcount
) {
1230 xfs_qm_dqtest_failed(d
, dqp
, "bcount mismatch",
1231 INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
),
1235 if (INT_GET(dqp
->q_core
.d_blk_softlimit
, ARCH_CONVERT
) &&
1236 INT_GET(dqp
->q_core
.d_bcount
, ARCH_CONVERT
) >=
1237 INT_GET(dqp
->q_core
.d_blk_softlimit
, ARCH_CONVERT
)) {
1238 if (!dqp
->q_core
.d_btimer
&& dqp
->q_core
.d_id
) {
1240 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1241 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1245 if (INT_GET(dqp
->q_core
.d_ino_softlimit
, ARCH_CONVERT
) &&
1246 INT_GET(dqp
->q_core
.d_icount
, ARCH_CONVERT
) >=
1247 INT_GET(dqp
->q_core
.d_ino_softlimit
, ARCH_CONVERT
)) {
1248 if (!dqp
->q_core
.d_itimer
&& dqp
->q_core
.d_id
) {
1250 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1251 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1257 cmn_err(CE_DEBUG
, "%d [%s] [0x%p] qchecked",
1258 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1271 /* xfs_qm_dqtest_print(d); */
1272 if ((error
= xfs_qm_dqget(d
->q_mount
, NULL
, d
->d_id
, d
->dq_flags
, 0,
1274 xfs_qm_dqtest_failed(d
, NULL
, "dqget failed", 0, 0, error
);
1277 xfs_dqtest_cmp2(d
, dqp
);
1282 xfs_qm_internalqcheck_dqget(
1286 xfs_dqtest_t
**O_dq
)
1291 h
= DQTEST_HASH(mp
, id
, type
);
1292 for (d
= (xfs_dqtest_t
*) h
->qh_next
; d
!= NULL
;
1293 d
= (xfs_dqtest_t
*) d
->HL_NEXT
) {
1294 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1295 if (d
->d_id
== id
&& mp
== d
->q_mount
) {
1300 d
= kmem_zalloc(sizeof(xfs_dqtest_t
), KM_SLEEP
);
1305 xfs_qm_hashinsert(h
, d
);
1311 xfs_qm_internalqcheck_get_dquots(
1319 if (XFS_IS_UQUOTA_ON(mp
))
1320 xfs_qm_internalqcheck_dqget(mp
, uid
, XFS_DQ_USER
, ud
);
1321 if (XFS_IS_GQUOTA_ON(mp
))
1322 xfs_qm_internalqcheck_dqget(mp
, gid
, XFS_DQ_GROUP
, gd
);
1323 else if (XFS_IS_PQUOTA_ON(mp
))
1324 xfs_qm_internalqcheck_dqget(mp
, projid
, XFS_DQ_PROJ
, gd
);
1329 xfs_qm_internalqcheck_dqadjust(
1334 d
->d_bcount
+= (xfs_qcnt_t
)ip
->i_d
.di_nblocks
;
1338 xfs_qm_internalqcheck_adjust(
1339 xfs_mount_t
*mp
, /* mount point for filesystem */
1340 xfs_ino_t ino
, /* inode number to get data for */
1341 void __user
*buffer
, /* not used */
1342 int ubsize
, /* not used */
1343 void *private_data
, /* not used */
1344 xfs_daddr_t bno
, /* starting block of inode cluster */
1345 int *ubused
, /* not used */
1346 void *dip
, /* not used */
1347 int *res
) /* bulkstat result code */
1350 xfs_dqtest_t
*ud
, *gd
;
1352 boolean_t ipreleased
;
1355 ASSERT(XFS_IS_QUOTA_RUNNING(mp
));
1357 if (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
) {
1358 *res
= BULKSTAT_RV_NOTHING
;
1359 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1360 (unsigned long long) ino
,
1361 (unsigned long long) mp
->m_sb
.sb_uquotino
,
1362 (unsigned long long) mp
->m_sb
.sb_gquotino
);
1363 return XFS_ERROR(EINVAL
);
1365 ipreleased
= B_FALSE
;
1367 lock_flags
= XFS_ILOCK_SHARED
;
1368 if ((error
= xfs_iget(mp
, NULL
, ino
, 0, lock_flags
, &ip
, bno
))) {
1369 *res
= BULKSTAT_RV_NOTHING
;
1373 if (ip
->i_d
.di_mode
== 0) {
1374 xfs_iput_new(ip
, lock_flags
);
1375 *res
= BULKSTAT_RV_NOTHING
;
1376 return XFS_ERROR(ENOENT
);
1380 * This inode can have blocks after eof which can get released
1381 * when we send it to inactive. Since we don't check the dquot
1382 * until the after all our calculations are done, we must get rid
1386 xfs_iput(ip
, lock_flags
);
1387 ipreleased
= B_TRUE
;
1390 xfs_qm_internalqcheck_get_dquots(mp
,
1391 (xfs_dqid_t
) ip
->i_d
.di_uid
,
1392 (xfs_dqid_t
) ip
->i_d
.di_projid
,
1393 (xfs_dqid_t
) ip
->i_d
.di_gid
,
1395 if (XFS_IS_UQUOTA_ON(mp
)) {
1397 xfs_qm_internalqcheck_dqadjust(ip
, ud
);
1399 if (XFS_IS_OQUOTA_ON(mp
)) {
1401 xfs_qm_internalqcheck_dqadjust(ip
, gd
);
1403 xfs_iput(ip
, lock_flags
);
1404 *res
= BULKSTAT_RV_DIDONE
;
1409 /* PRIVATE, debugging */
1411 xfs_qm_internalqcheck(
1417 xfs_dqtest_t
*d
, *e
;
1422 qmtest_hashmask
= 32;
1427 if (! XFS_IS_QUOTA_ON(mp
))
1428 return XFS_ERROR(ESRCH
);
1430 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1431 XFS_bflush(mp
->m_ddev_targp
);
1432 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1433 XFS_bflush(mp
->m_ddev_targp
);
1435 mutex_lock(&qcheck_lock
, PINOD
);
1436 /* There should be absolutely no quota activity while this
1438 qmtest_udqtab
= kmem_zalloc(qmtest_hashmask
*
1439 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1440 qmtest_gdqtab
= kmem_zalloc(qmtest_hashmask
*
1441 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1444 * Iterate thru all the inodes in the file system,
1445 * adjusting the corresponding dquot counters
1447 if ((error
= xfs_bulkstat(mp
, &lastino
, &count
,
1448 xfs_qm_internalqcheck_adjust
, NULL
,
1449 0, NULL
, BULKSTAT_FG_IGET
, &done
))) {
1454 cmn_err(CE_DEBUG
, "Bulkstat returned error 0x%x", error
);
1456 cmn_err(CE_DEBUG
, "Checking results against system dquots");
1457 for (i
= 0; i
< qmtest_hashmask
; i
++) {
1458 h1
= &qmtest_udqtab
[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
));
1465 h1
= &qmtest_gdqtab
[i
];
1466 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1468 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1469 kmem_free(d
, sizeof(xfs_dqtest_t
));
1474 if (qmtest_nfails
) {
1475 cmn_err(CE_DEBUG
, "******** quotacheck failed ********");
1476 cmn_err(CE_DEBUG
, "failures = %d", qmtest_nfails
);
1478 cmn_err(CE_DEBUG
, "******** quotacheck successful! ********");
1480 kmem_free(qmtest_udqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1481 kmem_free(qmtest_gdqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1482 mutex_unlock(&qcheck_lock
);
1483 return (qmtest_nfails
);