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.
91 ASSERT(addr
!= NULL
|| cmd
== Q_XQUOTASYNC
);
94 * The following commands are valid even when quotaoff.
99 * Truncate quota files. quota must be off.
101 if (XFS_IS_QUOTA_ON(mp
))
102 return XFS_ERROR(EINVAL
);
103 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
104 return XFS_ERROR(EROFS
);
105 return (xfs_qm_scall_trunc_qfiles(mp
,
106 xfs_qm_import_qtype_flags(*(uint
*)addr
)));
110 * Get quota status information.
112 return (xfs_qm_scall_getqstat(mp
, (fs_quota_stat_t
*)addr
));
116 * QUOTAON - enabling quota enforcement.
117 * Quota accounting must be turned on at mount time.
119 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
120 return XFS_ERROR(EROFS
);
121 return (xfs_qm_scall_quotaon(mp
,
122 xfs_qm_import_flags(*(uint
*)addr
)));
125 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
126 return XFS_ERROR(EROFS
);
130 return (xfs_sync_inodes(mp
, SYNC_DELWRI
, NULL
));
136 if (! XFS_IS_QUOTA_ON(mp
))
137 return XFS_ERROR(ESRCH
);
141 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
142 return XFS_ERROR(EROFS
);
143 error
= xfs_qm_scall_quotaoff(mp
,
144 xfs_qm_import_flags(*(uint
*)addr
),
149 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
150 (fs_disk_quota_t
*)addr
);
153 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
154 (fs_disk_quota_t
*)addr
);
157 error
= xfs_qm_scall_getquota(mp
, (xfs_dqid_t
)id
, XFS_DQ_PROJ
,
158 (fs_disk_quota_t
*)addr
);
162 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
163 return XFS_ERROR(EROFS
);
164 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_USER
,
165 (fs_disk_quota_t
*)addr
);
168 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
169 return XFS_ERROR(EROFS
);
170 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_GROUP
,
171 (fs_disk_quota_t
*)addr
);
174 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
175 return XFS_ERROR(EROFS
);
176 error
= xfs_qm_scall_setqlim(mp
, (xfs_dqid_t
)id
, XFS_DQ_PROJ
,
177 (fs_disk_quota_t
*)addr
);
181 error
= XFS_ERROR(EINVAL
);
189 * Turn off quota accounting and/or enforcement for all udquots and/or
190 * gdquots. Called only at unmount time.
192 * This assumes that there are no dquots of this file system cached
193 * incore, and modifies the ondisk dquot directly. Therefore, for example,
194 * it is an error to call this twice, without purging the cache.
197 xfs_qm_scall_quotaoff(
205 uint inactivate_flags
;
206 xfs_qoff_logitem_t
*qoffstart
;
209 if (!force
&& !capable(CAP_SYS_ADMIN
))
210 return XFS_ERROR(EPERM
);
212 * No file system can have quotas enabled on disk but not in core.
213 * Note that quota utilities (like quotaoff) _expect_
214 * errno == EEXIST here.
216 if ((mp
->m_qflags
& flags
) == 0)
217 return XFS_ERROR(EEXIST
);
220 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
223 * We don't want to deal with two quotaoffs messing up each other,
224 * so we're going to serialize it. quotaoff isn't exactly a performance
226 * If quotaoff, then we must be dealing with the root filesystem.
228 ASSERT(mp
->m_quotainfo
);
230 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
232 ASSERT(mp
->m_quotainfo
);
235 * If we're just turning off quota enforcement, change mp and go.
237 if ((flags
& XFS_ALL_QUOTA_ACCT
) == 0) {
238 mp
->m_qflags
&= ~(flags
);
241 mp
->m_sb
.sb_qflags
= mp
->m_qflags
;
242 XFS_SB_UNLOCK(mp
, s
);
243 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
245 /* XXX what to do if error ? Revert back to old vals incore ? */
246 error
= xfs_qm_write_sb_changes(mp
, XFS_SB_QFLAGS
);
251 inactivate_flags
= 0;
253 * If accounting is off, we must turn enforcement off, clear the
254 * quota 'CHKD' certificate to make it known that we have to
255 * do a quotacheck the next time this quota is turned on.
257 if (flags
& XFS_UQUOTA_ACCT
) {
258 dqtype
|= XFS_QMOPT_UQUOTA
;
259 flags
|= (XFS_UQUOTA_CHKD
| XFS_UQUOTA_ENFD
);
260 inactivate_flags
|= XFS_UQUOTA_ACTIVE
;
262 if (flags
& XFS_GQUOTA_ACCT
) {
263 dqtype
|= XFS_QMOPT_GQUOTA
;
264 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
265 inactivate_flags
|= XFS_GQUOTA_ACTIVE
;
266 } else if (flags
& XFS_PQUOTA_ACCT
) {
267 dqtype
|= XFS_QMOPT_PQUOTA
;
268 flags
|= (XFS_OQUOTA_CHKD
| XFS_OQUOTA_ENFD
);
269 inactivate_flags
|= XFS_PQUOTA_ACTIVE
;
273 * Nothing to do? Don't complain. This happens when we're just
274 * turning off quota enforcement.
276 if ((mp
->m_qflags
& flags
) == 0) {
277 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
282 * Write the LI_QUOTAOFF log record, and do SB changes atomically,
285 xfs_qm_log_quotaoff(mp
, &qoffstart
, flags
);
288 * Next we clear the XFS_MOUNT_*DQ_ACTIVE bit(s) in the mount struct
289 * to take care of the race between dqget and quotaoff. We don't take
290 * any special locks to reset these bits. All processes need to check
291 * these bits *after* taking inode lock(s) to see if the particular
292 * quota type is in the process of being turned off. If *ACTIVE, it is
293 * guaranteed that all dquot structures and all quotainode ptrs will all
294 * stay valid as long as that inode is kept locked.
296 * There is no turning back after this.
298 mp
->m_qflags
&= ~inactivate_flags
;
301 * Give back all the dquot reference(s) held by inodes.
302 * Here we go thru every single incore inode in this file system, and
303 * do a dqrele on the i_udquot/i_gdquot that it may have.
304 * Essentially, as long as somebody has an inode locked, this guarantees
305 * that quotas will not be turned off. This is handy because in a
306 * transaction once we lock the inode(s) and check for quotaon, we can
307 * depend on the quota inodes (and other things) being valid as long as
308 * we keep the lock(s).
310 xfs_qm_dqrele_all_inodes(mp
, flags
);
313 * Next we make the changes in the quota flag in the mount struct.
314 * This isn't protected by a particular lock directly, because we
315 * don't want to take a mrlock everytime we depend on quotas being on.
317 mp
->m_qflags
&= ~(flags
);
320 * Go through all the dquots of this file system and purge them,
321 * according to what was turned off. We may not be able to get rid
322 * of all dquots, because dquots can have temporary references that
323 * are not attached to inodes. eg. xfs_setattr, xfs_create.
324 * So, if we couldn't purge all the dquots from the filesystem,
325 * we can't get rid of the incore data structures.
327 while ((nculprits
= xfs_qm_dqpurge_all(mp
, dqtype
|XFS_QMOPT_QUOTAOFF
)))
328 delay(10 * nculprits
);
331 * Transactions that had started before ACTIVE state bit was cleared
332 * could have logged many dquots, so they'd have higher LSNs than
333 * the first QUOTAOFF log record does. If we happen to crash when
334 * the tail of the log has gone past the QUOTAOFF record, but
335 * before the last dquot modification, those dquots __will__
336 * recover, and that's not good.
338 * So, we have QUOTAOFF start and end logitems; the start
339 * logitem won't get overwritten until the end logitem appears...
341 xfs_qm_log_quotaoff_end(mp
, qoffstart
, flags
);
344 * If quotas is completely disabled, close shop.
346 if (((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET1
) ||
347 ((flags
& XFS_MOUNT_QUOTA_ALL
) == XFS_MOUNT_QUOTA_SET2
)) {
348 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
349 xfs_qm_destroy_quotainfo(mp
);
354 * Release our quotainode references, and vn_purge them,
355 * if we don't need them anymore.
357 if ((dqtype
& XFS_QMOPT_UQUOTA
) && XFS_QI_UQIP(mp
)) {
358 XFS_PURGE_INODE(XFS_QI_UQIP(mp
));
359 XFS_QI_UQIP(mp
) = NULL
;
361 if ((dqtype
& (XFS_QMOPT_GQUOTA
|XFS_QMOPT_PQUOTA
)) && XFS_QI_GQIP(mp
)) {
362 XFS_PURGE_INODE(XFS_QI_GQIP(mp
));
363 XFS_QI_GQIP(mp
) = NULL
;
365 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
371 xfs_qm_scall_trunc_qfiles(
378 if (!capable(CAP_SYS_ADMIN
))
379 return XFS_ERROR(EPERM
);
381 if (!XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) || flags
== 0) {
382 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags
, mp
->m_qflags
);
383 return XFS_ERROR(EINVAL
);
386 if ((flags
& XFS_DQ_USER
) && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
387 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
, 0, 0, &qip
, 0);
389 (void) xfs_truncate_file(mp
, qip
);
390 VN_RELE(XFS_ITOV(qip
));
394 if ((flags
& (XFS_DQ_GROUP
|XFS_DQ_PROJ
)) &&
395 mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
396 error
= xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
, 0, 0, &qip
, 0);
398 (void) xfs_truncate_file(mp
, qip
);
399 VN_RELE(XFS_ITOV(qip
));
408 * Switch on (a given) quota enforcement for a filesystem. This takes
409 * effect immediately.
410 * (Switching on quota accounting must be done at mount time.)
413 xfs_qm_scall_quotaon(
423 if (!capable(CAP_SYS_ADMIN
))
424 return XFS_ERROR(EPERM
);
426 flags
&= (XFS_ALL_QUOTA_ACCT
| XFS_ALL_QUOTA_ENFD
);
428 * Switching on quota accounting must be done at mount time.
430 accflags
= flags
& XFS_ALL_QUOTA_ACCT
;
431 flags
&= ~(XFS_ALL_QUOTA_ACCT
);
436 qdprintk("quotaon: zero flags, m_qflags=%x\n", mp
->m_qflags
);
437 return XFS_ERROR(EINVAL
);
440 /* No fs can turn on quotas with a delayed effect */
441 ASSERT((flags
& XFS_ALL_QUOTA_ACCT
) == 0);
444 * Can't enforce without accounting. We check the superblock
445 * qflags here instead of m_qflags because rootfs can have
446 * quota acct on ondisk without m_qflags' knowing.
448 if (((flags
& XFS_UQUOTA_ACCT
) == 0 &&
449 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) == 0 &&
450 (flags
& XFS_UQUOTA_ENFD
))
452 ((flags
& XFS_PQUOTA_ACCT
) == 0 &&
453 (mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) == 0 &&
454 (flags
& XFS_GQUOTA_ACCT
) == 0 &&
455 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) == 0 &&
456 (flags
& XFS_OQUOTA_ENFD
))) {
457 qdprintk("Can't enforce without acct, flags=%x sbflags=%x\n",
458 flags
, mp
->m_sb
.sb_qflags
);
459 return XFS_ERROR(EINVAL
);
462 * If everything's upto-date incore, then don't waste time.
464 if ((mp
->m_qflags
& flags
) == flags
)
465 return XFS_ERROR(EEXIST
);
468 * Change sb_qflags on disk but not incore mp->qflags
469 * if this is the root filesystem.
472 qf
= mp
->m_sb
.sb_qflags
;
473 mp
->m_sb
.sb_qflags
= qf
| flags
;
474 XFS_SB_UNLOCK(mp
, s
);
477 * There's nothing to change if it's the same.
479 if ((qf
& flags
) == flags
&& sbflags
== 0)
480 return XFS_ERROR(EEXIST
);
481 sbflags
|= XFS_SB_QFLAGS
;
483 if ((error
= xfs_qm_write_sb_changes(mp
, sbflags
)))
486 * If we aren't trying to switch on quota enforcement, we are done.
488 if (((mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) !=
489 (mp
->m_qflags
& XFS_UQUOTA_ACCT
)) ||
490 ((mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) !=
491 (mp
->m_qflags
& XFS_PQUOTA_ACCT
)) ||
492 ((mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) !=
493 (mp
->m_qflags
& XFS_GQUOTA_ACCT
)) ||
494 (flags
& XFS_ALL_QUOTA_ENFD
) == 0)
497 if (! XFS_IS_QUOTA_RUNNING(mp
))
498 return XFS_ERROR(ESRCH
);
501 * Switch on quota enforcement in core.
503 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
504 mp
->m_qflags
|= (flags
& XFS_ALL_QUOTA_ENFD
);
505 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
512 * Return quota status information, such as uquota-off, enforcements, etc.
515 xfs_qm_scall_getqstat(
517 fs_quota_stat_t
*out
)
519 xfs_inode_t
*uip
, *gip
;
520 boolean_t tempuqip
, tempgqip
;
523 tempuqip
= tempgqip
= B_FALSE
;
524 memset(out
, 0, sizeof(fs_quota_stat_t
));
526 out
->qs_version
= FS_QSTAT_VERSION
;
527 if (! XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
)) {
528 out
->qs_uquota
.qfs_ino
= NULLFSINO
;
529 out
->qs_gquota
.qfs_ino
= NULLFSINO
;
532 out
->qs_flags
= (__uint16_t
) xfs_qm_export_flags(mp
->m_qflags
&
534 XFS_ALL_QUOTA_ENFD
));
536 out
->qs_uquota
.qfs_ino
= mp
->m_sb
.sb_uquotino
;
537 out
->qs_gquota
.qfs_ino
= mp
->m_sb
.sb_gquotino
;
539 if (mp
->m_quotainfo
) {
540 uip
= mp
->m_quotainfo
->qi_uquotaip
;
541 gip
= mp
->m_quotainfo
->qi_gquotaip
;
543 if (!uip
&& mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
544 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_uquotino
,
548 if (!gip
&& mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
549 if (xfs_iget(mp
, NULL
, mp
->m_sb
.sb_gquotino
,
554 out
->qs_uquota
.qfs_nblks
= uip
->i_d
.di_nblocks
;
555 out
->qs_uquota
.qfs_nextents
= uip
->i_d
.di_nextents
;
557 VN_RELE(XFS_ITOV(uip
));
560 out
->qs_gquota
.qfs_nblks
= gip
->i_d
.di_nblocks
;
561 out
->qs_gquota
.qfs_nextents
= gip
->i_d
.di_nextents
;
563 VN_RELE(XFS_ITOV(gip
));
565 if (mp
->m_quotainfo
) {
566 out
->qs_incoredqs
= XFS_QI_MPLNDQUOTS(mp
);
567 out
->qs_btimelimit
= XFS_QI_BTIMELIMIT(mp
);
568 out
->qs_itimelimit
= XFS_QI_ITIMELIMIT(mp
);
569 out
->qs_rtbtimelimit
= XFS_QI_RTBTIMELIMIT(mp
);
570 out
->qs_bwarnlimit
= XFS_QI_BWARNLIMIT(mp
);
571 out
->qs_iwarnlimit
= XFS_QI_IWARNLIMIT(mp
);
577 * Adjust quota limits, and start/stop timers accordingly.
580 xfs_qm_scall_setqlim(
584 fs_disk_quota_t
*newlim
)
586 xfs_disk_dquot_t
*ddq
;
590 xfs_qcnt_t hard
, soft
;
592 if (!capable(CAP_SYS_ADMIN
))
593 return XFS_ERROR(EPERM
);
595 if ((newlim
->d_fieldmask
&
596 (FS_DQ_LIMIT_MASK
|FS_DQ_TIMER_MASK
|FS_DQ_WARNS_MASK
)) == 0)
599 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_SETQLIM
);
600 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_disk_dquot_t
) + 128,
601 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
602 xfs_trans_cancel(tp
, 0);
607 * We don't want to race with a quotaoff so take the quotaoff lock.
608 * (We don't hold an inode lock, so there's nothing else to stop
609 * a quotaoff from happening). (XXXThis doesn't currently happen
610 * because we take the vfslock before calling xfs_qm_sysent).
612 mutex_lock(&(XFS_QI_QOFFLOCK(mp
)));
615 * Get the dquot (locked), and join it to the transaction.
616 * Allocate the dquot if this doesn't exist.
618 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, XFS_QMOPT_DQALLOC
, &dqp
))) {
619 xfs_trans_cancel(tp
, XFS_TRANS_ABORT
);
620 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
621 ASSERT(error
!= ENOENT
);
624 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: AFT DQGET");
625 xfs_trans_dqjoin(tp
, dqp
);
629 * Make sure that hardlimits are >= soft limits before changing.
631 hard
= (newlim
->d_fieldmask
& FS_DQ_BHARD
) ?
632 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_hardlimit
) :
633 be64_to_cpu(ddq
->d_blk_hardlimit
);
634 soft
= (newlim
->d_fieldmask
& FS_DQ_BSOFT
) ?
635 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_blk_softlimit
) :
636 be64_to_cpu(ddq
->d_blk_softlimit
);
637 if (hard
== 0 || hard
>= soft
) {
638 ddq
->d_blk_hardlimit
= cpu_to_be64(hard
);
639 ddq
->d_blk_softlimit
= cpu_to_be64(soft
);
641 mp
->m_quotainfo
->qi_bhardlimit
= hard
;
642 mp
->m_quotainfo
->qi_bsoftlimit
= soft
;
645 qdprintk("blkhard %Ld < blksoft %Ld\n", hard
, soft
);
647 hard
= (newlim
->d_fieldmask
& FS_DQ_RTBHARD
) ?
648 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_hardlimit
) :
649 be64_to_cpu(ddq
->d_rtb_hardlimit
);
650 soft
= (newlim
->d_fieldmask
& FS_DQ_RTBSOFT
) ?
651 (xfs_qcnt_t
) XFS_BB_TO_FSB(mp
, newlim
->d_rtb_softlimit
) :
652 be64_to_cpu(ddq
->d_rtb_softlimit
);
653 if (hard
== 0 || hard
>= soft
) {
654 ddq
->d_rtb_hardlimit
= cpu_to_be64(hard
);
655 ddq
->d_rtb_softlimit
= cpu_to_be64(soft
);
657 mp
->m_quotainfo
->qi_rtbhardlimit
= hard
;
658 mp
->m_quotainfo
->qi_rtbsoftlimit
= soft
;
661 qdprintk("rtbhard %Ld < rtbsoft %Ld\n", hard
, soft
);
664 hard
= (newlim
->d_fieldmask
& FS_DQ_IHARD
) ?
665 (xfs_qcnt_t
) newlim
->d_ino_hardlimit
:
666 be64_to_cpu(ddq
->d_ino_hardlimit
);
667 soft
= (newlim
->d_fieldmask
& FS_DQ_ISOFT
) ?
668 (xfs_qcnt_t
) newlim
->d_ino_softlimit
:
669 be64_to_cpu(ddq
->d_ino_softlimit
);
670 if (hard
== 0 || hard
>= soft
) {
671 ddq
->d_ino_hardlimit
= cpu_to_be64(hard
);
672 ddq
->d_ino_softlimit
= cpu_to_be64(soft
);
674 mp
->m_quotainfo
->qi_ihardlimit
= hard
;
675 mp
->m_quotainfo
->qi_isoftlimit
= soft
;
678 qdprintk("ihard %Ld < isoft %Ld\n", hard
, soft
);
682 * Update warnings counter(s) if requested
684 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
685 ddq
->d_bwarns
= cpu_to_be16(newlim
->d_bwarns
);
686 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
687 ddq
->d_iwarns
= cpu_to_be16(newlim
->d_iwarns
);
688 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
689 ddq
->d_rtbwarns
= cpu_to_be16(newlim
->d_rtbwarns
);
693 * Timelimits for the super user set the relative time
694 * the other users can be over quota for this file system.
695 * If it is zero a default is used. Ditto for the default
696 * soft and hard limit values (already done, above), and
699 if (newlim
->d_fieldmask
& FS_DQ_BTIMER
) {
700 mp
->m_quotainfo
->qi_btimelimit
= newlim
->d_btimer
;
701 ddq
->d_btimer
= cpu_to_be32(newlim
->d_btimer
);
703 if (newlim
->d_fieldmask
& FS_DQ_ITIMER
) {
704 mp
->m_quotainfo
->qi_itimelimit
= newlim
->d_itimer
;
705 ddq
->d_itimer
= cpu_to_be32(newlim
->d_itimer
);
707 if (newlim
->d_fieldmask
& FS_DQ_RTBTIMER
) {
708 mp
->m_quotainfo
->qi_rtbtimelimit
= newlim
->d_rtbtimer
;
709 ddq
->d_rtbtimer
= cpu_to_be32(newlim
->d_rtbtimer
);
711 if (newlim
->d_fieldmask
& FS_DQ_BWARNS
)
712 mp
->m_quotainfo
->qi_bwarnlimit
= newlim
->d_bwarns
;
713 if (newlim
->d_fieldmask
& FS_DQ_IWARNS
)
714 mp
->m_quotainfo
->qi_iwarnlimit
= newlim
->d_iwarns
;
715 if (newlim
->d_fieldmask
& FS_DQ_RTBWARNS
)
716 mp
->m_quotainfo
->qi_rtbwarnlimit
= newlim
->d_rtbwarns
;
719 * If the user is now over quota, start the timelimit.
720 * The user will not be 'warned'.
721 * Note that we keep the timers ticking, whether enforcement
722 * is on or off. We don't really want to bother with iterating
723 * over all ondisk dquots and turning the timers on/off.
725 xfs_qm_adjust_dqtimers(mp
, ddq
);
727 dqp
->dq_flags
|= XFS_DQ_DIRTY
;
728 xfs_trans_log_dquot(tp
, dqp
);
730 xfs_dqtrace_entry(dqp
, "Q_SETQLIM: COMMIT");
731 xfs_trans_commit(tp
, 0);
734 mutex_unlock(&(XFS_QI_QOFFLOCK(mp
)));
740 xfs_qm_scall_getquota(
744 fs_disk_quota_t
*out
)
750 * Try to get the dquot. We don't want it allocated on disk, so
751 * we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't
752 * exist, we'll get ENOENT back.
754 if ((error
= xfs_qm_dqget(mp
, NULL
, id
, type
, 0, &dqp
))) {
758 xfs_dqtrace_entry(dqp
, "Q_GETQUOTA SUCCESS");
760 * If everything's NULL, this dquot doesn't quite exist as far as
761 * our utility programs are concerned.
763 if (XFS_IS_DQUOT_UNINITIALIZED(dqp
)) {
765 return XFS_ERROR(ENOENT
);
767 /* xfs_qm_dqprint(dqp); */
769 * Convert the disk dquot to the exportable format
771 xfs_qm_export_dquot(mp
, &dqp
->q_core
, out
);
773 return (error
? XFS_ERROR(EFAULT
) : 0);
778 xfs_qm_log_quotaoff_end(
780 xfs_qoff_logitem_t
*startqoff
,
785 xfs_qoff_logitem_t
*qoffi
;
787 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF_END
);
789 if ((error
= xfs_trans_reserve(tp
, 0, sizeof(xfs_qoff_logitem_t
) * 2,
790 0, 0, XFS_DEFAULT_LOG_COUNT
))) {
791 xfs_trans_cancel(tp
, 0);
795 qoffi
= xfs_trans_get_qoff_item(tp
, startqoff
,
796 flags
& XFS_ALL_QUOTA_ACCT
);
797 xfs_trans_log_quotaoff_item(tp
, qoffi
);
800 * We have to make sure that the transaction is secure on disk before we
801 * return and actually stop quota accounting. So, make it synchronous.
802 * We don't care about quotoff's performance.
804 xfs_trans_set_sync(tp
);
805 error
= xfs_trans_commit(tp
, 0);
813 xfs_qoff_logitem_t
**qoffstartp
,
819 xfs_qoff_logitem_t
*qoffi
=NULL
;
822 tp
= xfs_trans_alloc(mp
, XFS_TRANS_QM_QUOTAOFF
);
823 if ((error
= xfs_trans_reserve(tp
, 0,
824 sizeof(xfs_qoff_logitem_t
) * 2 +
825 mp
->m_sb
.sb_sectsize
+ 128,
828 XFS_DEFAULT_LOG_COUNT
))) {
832 qoffi
= xfs_trans_get_qoff_item(tp
, NULL
, flags
& XFS_ALL_QUOTA_ACCT
);
833 xfs_trans_log_quotaoff_item(tp
, qoffi
);
836 oldsbqflag
= mp
->m_sb
.sb_qflags
;
837 mp
->m_sb
.sb_qflags
= (mp
->m_qflags
& ~(flags
)) & XFS_MOUNT_QUOTA_ALL
;
838 XFS_SB_UNLOCK(mp
, s
);
840 xfs_mod_sb(tp
, XFS_SB_QFLAGS
);
843 * We have to make sure that the transaction is secure on disk before we
844 * return and actually stop quota accounting. So, make it synchronous.
845 * We don't care about quotoff's performance.
847 xfs_trans_set_sync(tp
);
848 error
= xfs_trans_commit(tp
, 0);
852 xfs_trans_cancel(tp
, 0);
854 * No one else is modifying sb_qflags, so this is OK.
855 * We still hold the quotaofflock.
858 mp
->m_sb
.sb_qflags
= oldsbqflag
;
859 XFS_SB_UNLOCK(mp
, s
);
867 * Translate an internal style on-disk-dquot to the exportable format.
868 * The main differences are that the counters/limits are all in Basic
869 * Blocks (BBs) instead of the internal FSBs, and all on-disk data has
870 * to be converted to the native endianness.
875 xfs_disk_dquot_t
*src
,
876 struct fs_disk_quota
*dst
)
878 memset(dst
, 0, sizeof(*dst
));
879 dst
->d_version
= FS_DQUOT_VERSION
; /* different from src->d_version */
880 dst
->d_flags
= xfs_qm_export_qtype_flags(src
->d_flags
);
881 dst
->d_id
= be32_to_cpu(src
->d_id
);
882 dst
->d_blk_hardlimit
=
883 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_blk_hardlimit
));
884 dst
->d_blk_softlimit
=
885 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_blk_softlimit
));
886 dst
->d_ino_hardlimit
= be64_to_cpu(src
->d_ino_hardlimit
);
887 dst
->d_ino_softlimit
= be64_to_cpu(src
->d_ino_softlimit
);
888 dst
->d_bcount
= XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_bcount
));
889 dst
->d_icount
= be64_to_cpu(src
->d_icount
);
890 dst
->d_btimer
= be32_to_cpu(src
->d_btimer
);
891 dst
->d_itimer
= be32_to_cpu(src
->d_itimer
);
892 dst
->d_iwarns
= be16_to_cpu(src
->d_iwarns
);
893 dst
->d_bwarns
= be16_to_cpu(src
->d_bwarns
);
894 dst
->d_rtb_hardlimit
=
895 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtb_hardlimit
));
896 dst
->d_rtb_softlimit
=
897 XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtb_softlimit
));
898 dst
->d_rtbcount
= XFS_FSB_TO_BB(mp
, be64_to_cpu(src
->d_rtbcount
));
899 dst
->d_rtbtimer
= be32_to_cpu(src
->d_rtbtimer
);
900 dst
->d_rtbwarns
= be16_to_cpu(src
->d_rtbwarns
);
903 * Internally, we don't reset all the timers when quota enforcement
904 * gets turned off. No need to confuse the user level code,
905 * so return zeroes in that case.
907 if ((!XFS_IS_UQUOTA_ENFORCED(mp
) && src
->d_flags
== XFS_DQ_USER
) ||
908 (!XFS_IS_OQUOTA_ENFORCED(mp
) &&
909 (src
->d_flags
& (XFS_DQ_PROJ
| XFS_DQ_GROUP
)))) {
916 if (((XFS_IS_UQUOTA_ENFORCED(mp
) && dst
->d_flags
== XFS_USER_QUOTA
) ||
917 (XFS_IS_OQUOTA_ENFORCED(mp
) &&
918 (dst
->d_flags
& (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
)))) &&
920 if (((int) dst
->d_bcount
>= (int) dst
->d_blk_softlimit
) &&
921 (dst
->d_blk_softlimit
> 0)) {
922 ASSERT(dst
->d_btimer
!= 0);
924 if (((int) dst
->d_icount
>= (int) dst
->d_ino_softlimit
) &&
925 (dst
->d_ino_softlimit
> 0)) {
926 ASSERT(dst
->d_itimer
!= 0);
933 xfs_qm_import_qtype_flags(
939 * Can't be more than one, or none.
941 if (((uflags
& (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ==
942 (XFS_GROUP_QUOTA
| XFS_USER_QUOTA
)) ||
943 ((uflags
& (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ==
944 (XFS_GROUP_QUOTA
| XFS_PROJ_QUOTA
)) ||
945 ((uflags
& (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ==
946 (XFS_USER_QUOTA
| XFS_PROJ_QUOTA
)) ||
947 ((uflags
& (XFS_GROUP_QUOTA
|XFS_USER_QUOTA
|XFS_PROJ_QUOTA
)) == 0))
950 oflags
|= (uflags
& XFS_USER_QUOTA
) ? XFS_DQ_USER
: 0;
951 oflags
|= (uflags
& XFS_PROJ_QUOTA
) ? XFS_DQ_PROJ
: 0;
952 oflags
|= (uflags
& XFS_GROUP_QUOTA
) ? XFS_DQ_GROUP
: 0;
957 xfs_qm_export_qtype_flags(
961 * Can't be more than one, or none.
963 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
)) !=
964 (XFS_PROJ_QUOTA
| XFS_USER_QUOTA
));
965 ASSERT((flags
& (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
)) !=
966 (XFS_PROJ_QUOTA
| XFS_GROUP_QUOTA
));
967 ASSERT((flags
& (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
)) !=
968 (XFS_USER_QUOTA
| XFS_GROUP_QUOTA
));
969 ASSERT((flags
& (XFS_PROJ_QUOTA
|XFS_USER_QUOTA
|XFS_GROUP_QUOTA
)) != 0);
971 return (flags
& XFS_DQ_USER
) ?
972 XFS_USER_QUOTA
: (flags
& XFS_DQ_PROJ
) ?
973 XFS_PROJ_QUOTA
: XFS_GROUP_QUOTA
;
982 if (uflags
& XFS_QUOTA_UDQ_ACCT
)
983 flags
|= XFS_UQUOTA_ACCT
;
984 if (uflags
& XFS_QUOTA_PDQ_ACCT
)
985 flags
|= XFS_PQUOTA_ACCT
;
986 if (uflags
& XFS_QUOTA_GDQ_ACCT
)
987 flags
|= XFS_GQUOTA_ACCT
;
988 if (uflags
& XFS_QUOTA_UDQ_ENFD
)
989 flags
|= XFS_UQUOTA_ENFD
;
990 if (uflags
& (XFS_QUOTA_PDQ_ENFD
|XFS_QUOTA_GDQ_ENFD
))
991 flags
|= XFS_OQUOTA_ENFD
;
1003 if (flags
& XFS_UQUOTA_ACCT
)
1004 uflags
|= XFS_QUOTA_UDQ_ACCT
;
1005 if (flags
& XFS_PQUOTA_ACCT
)
1006 uflags
|= XFS_QUOTA_PDQ_ACCT
;
1007 if (flags
& XFS_GQUOTA_ACCT
)
1008 uflags
|= XFS_QUOTA_GDQ_ACCT
;
1009 if (flags
& XFS_UQUOTA_ENFD
)
1010 uflags
|= XFS_QUOTA_UDQ_ENFD
;
1011 if (flags
& (XFS_OQUOTA_ENFD
)) {
1012 uflags
|= (flags
& XFS_GQUOTA_ACCT
) ?
1013 XFS_QUOTA_GDQ_ENFD
: XFS_QUOTA_PDQ_ENFD
;
1020 * Go thru all the inodes in the file system, releasing their dquots.
1021 * Note that the mount structure gets modified to indicate that quotas are off
1022 * AFTER this, in the case of quotaoff. This also gets called from
1026 xfs_qm_dqrele_all_inodes(
1027 struct xfs_mount
*mp
,
1030 xfs_inode_t
*ip
, *topino
;
1033 boolean_t vnode_refd
;
1035 ASSERT(mp
->m_quotainfo
);
1037 XFS_MOUNT_ILOCK(mp
);
1041 XFS_MOUNT_IUNLOCK(mp
);
1045 /* Skip markers inserted by xfs_sync */
1046 if (ip
->i_mount
== NULL
) {
1050 /* Root inode, rbmip and rsumip have associated blocks */
1051 if (ip
== XFS_QI_UQIP(mp
) || ip
== XFS_QI_GQIP(mp
)) {
1052 ASSERT(ip
->i_udquot
== NULL
);
1053 ASSERT(ip
->i_gdquot
== NULL
);
1057 vp
= XFS_ITOV_NULL(ip
);
1059 ASSERT(ip
->i_udquot
== NULL
);
1060 ASSERT(ip
->i_gdquot
== NULL
);
1064 vnode_refd
= B_FALSE
;
1065 if (xfs_ilock_nowait(ip
, XFS_ILOCK_EXCL
) == 0) {
1066 ireclaims
= mp
->m_ireclaims
;
1067 topino
= mp
->m_inodes
;
1072 XFS_MOUNT_IUNLOCK(mp
);
1073 /* XXX restart limit ? */
1074 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
1075 vnode_refd
= B_TRUE
;
1077 ireclaims
= mp
->m_ireclaims
;
1078 topino
= mp
->m_inodes
;
1079 XFS_MOUNT_IUNLOCK(mp
);
1083 * We don't keep the mountlock across the dqrele() call,
1084 * since it can take a while..
1086 if ((flags
& XFS_UQUOTA_ACCT
) && ip
->i_udquot
) {
1087 xfs_qm_dqrele(ip
->i_udquot
);
1088 ip
->i_udquot
= NULL
;
1090 if (flags
& (XFS_PQUOTA_ACCT
|XFS_GQUOTA_ACCT
) && ip
->i_gdquot
) {
1091 xfs_qm_dqrele(ip
->i_gdquot
);
1092 ip
->i_gdquot
= NULL
;
1094 xfs_iunlock(ip
, XFS_ILOCK_EXCL
);
1096 * Wait until we've dropped the ilock and mountlock to
1097 * do the vn_rele. Or be condemned to an eternity in the
1098 * inactive code in hell.
1102 XFS_MOUNT_ILOCK(mp
);
1104 * If an inode was inserted or removed, we gotta
1107 if (topino
!= mp
->m_inodes
|| mp
->m_ireclaims
!= ireclaims
) {
1108 /* XXX use a sentinel */
1112 } while (ip
!= mp
->m_inodes
);
1114 XFS_MOUNT_IUNLOCK(mp
);
1117 /*------------------------------------------------------------------------*/
1120 * This contains all the test functions for XFS disk quotas.
1121 * Currently it does a quota accounting check. ie. it walks through
1122 * all inodes in the file system, calculating the dquot accounting fields,
1123 * and prints out any inconsistencies.
1125 xfs_dqhash_t
*qmtest_udqtab
;
1126 xfs_dqhash_t
*qmtest_gdqtab
;
1127 int qmtest_hashmask
;
1129 mutex_t qcheck_lock
;
1131 #define DQTEST_HASHVAL(mp, id) (((__psunsigned_t)(mp) + \
1132 (__psunsigned_t)(id)) & \
1133 (qmtest_hashmask - 1))
1135 #define DQTEST_HASH(mp, id, type) ((type & XFS_DQ_USER) ? \
1137 DQTEST_HASHVAL(mp, id)) : \
1139 DQTEST_HASHVAL(mp, id)))
1141 #define DQTEST_LIST_PRINT(l, NXT, title) \
1143 xfs_dqtest_t *dqp; int i = 0;\
1144 cmn_err(CE_DEBUG, "%s (#%d)", title, (int) (l)->qh_nelems); \
1145 for (dqp = (xfs_dqtest_t *)(l)->qh_next; dqp != NULL; \
1146 dqp = (xfs_dqtest_t *)dqp->NXT) { \
1147 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" bcnt = %d, icnt = %d", \
1148 ++i, dqp->d_id, DQFLAGTO_TYPESTR(dqp), \
1149 dqp->d_bcount, dqp->d_icount); } \
1152 typedef struct dqtest
{
1153 xfs_dqmarker_t q_lists
;
1154 xfs_dqhash_t
*q_hash
; /* the hashchain header */
1155 xfs_mount_t
*q_mount
; /* filesystem this relates to */
1156 xfs_dqid_t d_id
; /* user id or group id */
1157 xfs_qcnt_t d_bcount
; /* # disk blocks owned by the user */
1158 xfs_qcnt_t d_icount
; /* # inodes owned by the user */
1162 xfs_qm_hashinsert(xfs_dqhash_t
*h
, xfs_dqtest_t
*dqp
)
1165 if (((d
) = (h
)->qh_next
))
1166 (d
)->HL_PREVP
= &((dqp
)->HL_NEXT
);
1168 (dqp
)->HL_PREVP
= &((h
)->qh_next
);
1169 (h
)->qh_next
= (xfs_dquot_t
*)dqp
;
1174 xfs_qm_dqtest_print(
1177 cmn_err(CE_DEBUG
, "-----------DQTEST DQUOT----------------");
1178 cmn_err(CE_DEBUG
, "---- dquot ID = %d", d
->d_id
);
1179 cmn_err(CE_DEBUG
, "---- fs = 0x%p", d
->q_mount
);
1180 cmn_err(CE_DEBUG
, "---- bcount = %Lu (0x%x)",
1181 d
->d_bcount
, (int)d
->d_bcount
);
1182 cmn_err(CE_DEBUG
, "---- icount = %Lu (0x%x)",
1183 d
->d_icount
, (int)d
->d_icount
);
1184 cmn_err(CE_DEBUG
, "---------------------------");
1188 xfs_qm_dqtest_failed(
1198 cmn_err(CE_DEBUG
, "quotacheck failed id=%d, err=%d\nreason: %s",
1199 d
->d_id
, error
, reason
);
1201 cmn_err(CE_DEBUG
, "quotacheck failed id=%d (%s) [%d != %d]",
1202 d
->d_id
, reason
, (int)a
, (int)b
);
1203 xfs_qm_dqtest_print(d
);
1205 xfs_qm_dqprint(dqp
);
1214 if (be64_to_cpu(dqp
->q_core
.d_icount
) != d
->d_icount
) {
1215 xfs_qm_dqtest_failed(d
, dqp
, "icount mismatch",
1216 be64_to_cpu(dqp
->q_core
.d_icount
),
1220 if (be64_to_cpu(dqp
->q_core
.d_bcount
) != d
->d_bcount
) {
1221 xfs_qm_dqtest_failed(d
, dqp
, "bcount mismatch",
1222 be64_to_cpu(dqp
->q_core
.d_bcount
),
1226 if (dqp
->q_core
.d_blk_softlimit
&&
1227 be64_to_cpu(dqp
->q_core
.d_bcount
) >=
1228 be64_to_cpu(dqp
->q_core
.d_blk_softlimit
)) {
1229 if (!dqp
->q_core
.d_btimer
&& dqp
->q_core
.d_id
) {
1231 "%d [%s] [0x%p] BLK TIMER NOT STARTED",
1232 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1236 if (dqp
->q_core
.d_ino_softlimit
&&
1237 be64_to_cpu(dqp
->q_core
.d_icount
) >=
1238 be64_to_cpu(dqp
->q_core
.d_ino_softlimit
)) {
1239 if (!dqp
->q_core
.d_itimer
&& dqp
->q_core
.d_id
) {
1241 "%d [%s] [0x%p] INO TIMER NOT STARTED",
1242 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1248 cmn_err(CE_DEBUG
, "%d [%s] [0x%p] qchecked",
1249 d
->d_id
, DQFLAGTO_TYPESTR(d
), d
->q_mount
);
1262 /* xfs_qm_dqtest_print(d); */
1263 if ((error
= xfs_qm_dqget(d
->q_mount
, NULL
, d
->d_id
, d
->dq_flags
, 0,
1265 xfs_qm_dqtest_failed(d
, NULL
, "dqget failed", 0, 0, error
);
1268 xfs_dqtest_cmp2(d
, dqp
);
1273 xfs_qm_internalqcheck_dqget(
1277 xfs_dqtest_t
**O_dq
)
1282 h
= DQTEST_HASH(mp
, id
, type
);
1283 for (d
= (xfs_dqtest_t
*) h
->qh_next
; d
!= NULL
;
1284 d
= (xfs_dqtest_t
*) d
->HL_NEXT
) {
1285 /* DQTEST_LIST_PRINT(h, HL_NEXT, "@@@@@ dqtestlist @@@@@"); */
1286 if (d
->d_id
== id
&& mp
== d
->q_mount
) {
1291 d
= kmem_zalloc(sizeof(xfs_dqtest_t
), KM_SLEEP
);
1296 xfs_qm_hashinsert(h
, d
);
1302 xfs_qm_internalqcheck_get_dquots(
1310 if (XFS_IS_UQUOTA_ON(mp
))
1311 xfs_qm_internalqcheck_dqget(mp
, uid
, XFS_DQ_USER
, ud
);
1312 if (XFS_IS_GQUOTA_ON(mp
))
1313 xfs_qm_internalqcheck_dqget(mp
, gid
, XFS_DQ_GROUP
, gd
);
1314 else if (XFS_IS_PQUOTA_ON(mp
))
1315 xfs_qm_internalqcheck_dqget(mp
, projid
, XFS_DQ_PROJ
, gd
);
1320 xfs_qm_internalqcheck_dqadjust(
1325 d
->d_bcount
+= (xfs_qcnt_t
)ip
->i_d
.di_nblocks
;
1329 xfs_qm_internalqcheck_adjust(
1330 xfs_mount_t
*mp
, /* mount point for filesystem */
1331 xfs_ino_t ino
, /* inode number to get data for */
1332 void __user
*buffer
, /* not used */
1333 int ubsize
, /* not used */
1334 void *private_data
, /* not used */
1335 xfs_daddr_t bno
, /* starting block of inode cluster */
1336 int *ubused
, /* not used */
1337 void *dip
, /* not used */
1338 int *res
) /* bulkstat result code */
1341 xfs_dqtest_t
*ud
, *gd
;
1343 boolean_t ipreleased
;
1346 ASSERT(XFS_IS_QUOTA_RUNNING(mp
));
1348 if (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
) {
1349 *res
= BULKSTAT_RV_NOTHING
;
1350 qdprintk("internalqcheck: ino=%llu, uqino=%llu, gqino=%llu\n",
1351 (unsigned long long) ino
,
1352 (unsigned long long) mp
->m_sb
.sb_uquotino
,
1353 (unsigned long long) mp
->m_sb
.sb_gquotino
);
1354 return XFS_ERROR(EINVAL
);
1356 ipreleased
= B_FALSE
;
1358 lock_flags
= XFS_ILOCK_SHARED
;
1359 if ((error
= xfs_iget(mp
, NULL
, ino
, 0, lock_flags
, &ip
, bno
))) {
1360 *res
= BULKSTAT_RV_NOTHING
;
1364 if (ip
->i_d
.di_mode
== 0) {
1365 xfs_iput_new(ip
, lock_flags
);
1366 *res
= BULKSTAT_RV_NOTHING
;
1367 return XFS_ERROR(ENOENT
);
1371 * This inode can have blocks after eof which can get released
1372 * when we send it to inactive. Since we don't check the dquot
1373 * until the after all our calculations are done, we must get rid
1377 xfs_iput(ip
, lock_flags
);
1378 ipreleased
= B_TRUE
;
1381 xfs_qm_internalqcheck_get_dquots(mp
,
1382 (xfs_dqid_t
) ip
->i_d
.di_uid
,
1383 (xfs_dqid_t
) ip
->i_d
.di_projid
,
1384 (xfs_dqid_t
) ip
->i_d
.di_gid
,
1386 if (XFS_IS_UQUOTA_ON(mp
)) {
1388 xfs_qm_internalqcheck_dqadjust(ip
, ud
);
1390 if (XFS_IS_OQUOTA_ON(mp
)) {
1392 xfs_qm_internalqcheck_dqadjust(ip
, gd
);
1394 xfs_iput(ip
, lock_flags
);
1395 *res
= BULKSTAT_RV_DIDONE
;
1400 /* PRIVATE, debugging */
1402 xfs_qm_internalqcheck(
1408 xfs_dqtest_t
*d
, *e
;
1413 qmtest_hashmask
= 32;
1418 if (! XFS_IS_QUOTA_ON(mp
))
1419 return XFS_ERROR(ESRCH
);
1421 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1422 XFS_bflush(mp
->m_ddev_targp
);
1423 xfs_log_force(mp
, (xfs_lsn_t
)0, XFS_LOG_FORCE
| XFS_LOG_SYNC
);
1424 XFS_bflush(mp
->m_ddev_targp
);
1426 mutex_lock(&qcheck_lock
);
1427 /* There should be absolutely no quota activity while this
1429 qmtest_udqtab
= kmem_zalloc(qmtest_hashmask
*
1430 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1431 qmtest_gdqtab
= kmem_zalloc(qmtest_hashmask
*
1432 sizeof(xfs_dqhash_t
), KM_SLEEP
);
1435 * Iterate thru all the inodes in the file system,
1436 * adjusting the corresponding dquot counters
1438 if ((error
= xfs_bulkstat(mp
, &lastino
, &count
,
1439 xfs_qm_internalqcheck_adjust
, NULL
,
1440 0, NULL
, BULKSTAT_FG_IGET
, &done
))) {
1445 cmn_err(CE_DEBUG
, "Bulkstat returned error 0x%x", error
);
1447 cmn_err(CE_DEBUG
, "Checking results against system dquots");
1448 for (i
= 0; i
< qmtest_hashmask
; i
++) {
1449 h1
= &qmtest_udqtab
[i
];
1450 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1452 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1453 kmem_free(d
, sizeof(xfs_dqtest_t
));
1456 h1
= &qmtest_gdqtab
[i
];
1457 for (d
= (xfs_dqtest_t
*) h1
->qh_next
; d
!= NULL
; ) {
1459 e
= (xfs_dqtest_t
*) d
->HL_NEXT
;
1460 kmem_free(d
, sizeof(xfs_dqtest_t
));
1465 if (qmtest_nfails
) {
1466 cmn_err(CE_DEBUG
, "******** quotacheck failed ********");
1467 cmn_err(CE_DEBUG
, "failures = %d", qmtest_nfails
);
1469 cmn_err(CE_DEBUG
, "******** quotacheck successful! ********");
1471 kmem_free(qmtest_udqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1472 kmem_free(qmtest_gdqtab
, qmtest_hashmask
* sizeof(xfs_dqhash_t
));
1473 mutex_unlock(&qcheck_lock
);
1474 return (qmtest_nfails
);