hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/xfs/xfs_qm.c
....@@ -13,19 +13,16 @@
1313 #include "xfs_sb.h"
1414 #include "xfs_mount.h"
1515 #include "xfs_inode.h"
16
-#include "xfs_ialloc.h"
17
-#include "xfs_itable.h"
16
+#include "xfs_iwalk.h"
1817 #include "xfs_quota.h"
19
-#include "xfs_error.h"
2018 #include "xfs_bmap.h"
21
-#include "xfs_bmap_btree.h"
2219 #include "xfs_bmap_util.h"
2320 #include "xfs_trans.h"
2421 #include "xfs_trans_space.h"
2522 #include "xfs_qm.h"
2623 #include "xfs_trace.h"
2724 #include "xfs_icache.h"
28
-#include "xfs_cksum.h"
25
+#include "xfs_error.h"
2926
3027 /*
3128 * The global quota manager. There is only one of these for the entire
....@@ -33,10 +30,10 @@
3330 * quota functionality, including maintaining the freelist and hash
3431 * tables of dquots.
3532 */
36
-STATIC int xfs_qm_init_quotainos(xfs_mount_t *);
37
-STATIC int xfs_qm_init_quotainfo(xfs_mount_t *);
33
+STATIC int xfs_qm_init_quotainos(struct xfs_mount *mp);
34
+STATIC int xfs_qm_init_quotainfo(struct xfs_mount *mp);
3835
39
-STATIC void xfs_qm_destroy_quotainos(xfs_quotainfo_t *qi);
36
+STATIC void xfs_qm_destroy_quotainos(struct xfs_quotainfo *qi);
4037 STATIC void xfs_qm_dqfree_one(struct xfs_dquot *dqp);
4138 /*
4239 * We use the batch lookup interface to iterate over the dquots as it
....@@ -50,7 +47,7 @@
5047 STATIC int
5148 xfs_qm_dquot_walk(
5249 struct xfs_mount *mp,
53
- int type,
50
+ xfs_dqtype_t type,
5451 int (*execute)(struct xfs_dquot *dqp, void *data),
5552 void *data)
5653 {
....@@ -82,7 +79,7 @@
8279 for (i = 0; i < nr_found; i++) {
8380 struct xfs_dquot *dqp = batch[i];
8481
85
- next_index = be32_to_cpu(dqp->q_core.d_id) + 1;
82
+ next_index = dqp->q_id + 1;
8683
8784 error = execute(batch[i], data);
8885 if (error == -EAGAIN) {
....@@ -124,14 +121,13 @@
124121 {
125122 struct xfs_mount *mp = dqp->q_mount;
126123 struct xfs_quotainfo *qi = mp->m_quotainfo;
124
+ int error = -EAGAIN;
127125
128126 xfs_dqlock(dqp);
129
- if ((dqp->dq_flags & XFS_DQ_FREEING) || dqp->q_nrefs != 0) {
130
- xfs_dqunlock(dqp);
131
- return -EAGAIN;
132
- }
127
+ if ((dqp->q_flags & XFS_DQFLAG_FREEING) || dqp->q_nrefs != 0)
128
+ goto out_unlock;
133129
134
- dqp->dq_flags |= XFS_DQ_FREEING;
130
+ dqp->q_flags |= XFS_DQFLAG_FREEING;
135131
136132 xfs_dqflock(dqp);
137133
....@@ -142,7 +138,6 @@
142138 */
143139 if (XFS_DQ_IS_DIRTY(dqp)) {
144140 struct xfs_buf *bp = NULL;
145
- int error;
146141
147142 /*
148143 * We don't care about getting disk errors here. We need
....@@ -152,6 +147,9 @@
152147 if (!error) {
153148 error = xfs_bwrite(bp);
154149 xfs_buf_relse(bp);
150
+ } else if (error == -EAGAIN) {
151
+ dqp->q_flags &= ~XFS_DQFLAG_FREEING;
152
+ goto out_unlock;
155153 }
156154 xfs_dqflock(dqp);
157155 }
....@@ -163,8 +161,7 @@
163161 xfs_dqfunlock(dqp);
164162 xfs_dqunlock(dqp);
165163
166
- radix_tree_delete(xfs_dquot_tree(qi, dqp->q_core.d_flags),
167
- be32_to_cpu(dqp->q_core.d_id));
164
+ radix_tree_delete(xfs_dquot_tree(qi, xfs_dquot_type(dqp)), dqp->q_id);
168165 qi->qi_dquots--;
169166
170167 /*
....@@ -177,6 +174,10 @@
177174
178175 xfs_qm_dqdestroy(dqp);
179176 return 0;
177
+
178
+out_unlock:
179
+ xfs_dqunlock(dqp);
180
+ return error;
180181 }
181182
182183 /*
....@@ -188,11 +189,11 @@
188189 uint flags)
189190 {
190191 if (flags & XFS_QMOPT_UQUOTA)
191
- xfs_qm_dquot_walk(mp, XFS_DQ_USER, xfs_qm_dqpurge, NULL);
192
+ xfs_qm_dquot_walk(mp, XFS_DQTYPE_USER, xfs_qm_dqpurge, NULL);
192193 if (flags & XFS_QMOPT_GQUOTA)
193
- xfs_qm_dquot_walk(mp, XFS_DQ_GROUP, xfs_qm_dqpurge, NULL);
194
+ xfs_qm_dquot_walk(mp, XFS_DQTYPE_GROUP, xfs_qm_dqpurge, NULL);
194195 if (flags & XFS_QMOPT_PQUOTA)
195
- xfs_qm_dquot_walk(mp, XFS_DQ_PROJ, xfs_qm_dqpurge, NULL);
196
+ xfs_qm_dquot_walk(mp, XFS_DQTYPE_PROJ, xfs_qm_dqpurge, NULL);
196197 }
197198
198199 /*
....@@ -247,14 +248,13 @@
247248
248249 STATIC int
249250 xfs_qm_dqattach_one(
250
- xfs_inode_t *ip,
251
- xfs_dqid_t id,
252
- uint type,
253
- bool doalloc,
254
- xfs_dquot_t **IO_idqpp)
251
+ struct xfs_inode *ip,
252
+ xfs_dqtype_t type,
253
+ bool doalloc,
254
+ struct xfs_dquot **IO_idqpp)
255255 {
256
- xfs_dquot_t *dqp;
257
- int error;
256
+ struct xfs_dquot *dqp;
257
+ int error;
258258
259259 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
260260 error = 0;
....@@ -329,7 +329,7 @@
329329 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
330330
331331 if (XFS_IS_UQUOTA_ON(mp) && !ip->i_udquot) {
332
- error = xfs_qm_dqattach_one(ip, ip->i_d.di_uid, XFS_DQ_USER,
332
+ error = xfs_qm_dqattach_one(ip, XFS_DQTYPE_USER,
333333 doalloc, &ip->i_udquot);
334334 if (error)
335335 goto done;
....@@ -337,7 +337,7 @@
337337 }
338338
339339 if (XFS_IS_GQUOTA_ON(mp) && !ip->i_gdquot) {
340
- error = xfs_qm_dqattach_one(ip, ip->i_d.di_gid, XFS_DQ_GROUP,
340
+ error = xfs_qm_dqattach_one(ip, XFS_DQTYPE_GROUP,
341341 doalloc, &ip->i_gdquot);
342342 if (error)
343343 goto done;
....@@ -345,7 +345,7 @@
345345 }
346346
347347 if (XFS_IS_PQUOTA_ON(mp) && !ip->i_pdquot) {
348
- error = xfs_qm_dqattach_one(ip, xfs_get_projid(ip), XFS_DQ_PROJ,
348
+ error = xfs_qm_dqattach_one(ip, XFS_DQTYPE_PROJ,
349349 doalloc, &ip->i_pdquot);
350350 if (error)
351351 goto done;
....@@ -472,7 +472,7 @@
472472 /*
473473 * Prevent lookups now that we are past the point of no return.
474474 */
475
- dqp->dq_flags |= XFS_DQ_FREEING;
475
+ dqp->q_flags |= XFS_DQFLAG_FREEING;
476476 xfs_dqunlock(dqp);
477477
478478 ASSERT(dqp->q_nrefs == 0);
....@@ -543,32 +543,30 @@
543543
544544 STATIC void
545545 xfs_qm_set_defquota(
546
- xfs_mount_t *mp,
547
- uint type,
548
- xfs_quotainfo_t *qinf)
546
+ struct xfs_mount *mp,
547
+ xfs_dqtype_t type,
548
+ struct xfs_quotainfo *qinf)
549549 {
550
- xfs_dquot_t *dqp;
551
- struct xfs_def_quota *defq;
552
- struct xfs_disk_dquot *ddqp;
550
+ struct xfs_dquot *dqp;
551
+ struct xfs_def_quota *defq;
553552 int error;
554553
555554 error = xfs_qm_dqget_uncached(mp, 0, type, &dqp);
556555 if (error)
557556 return;
558557
559
- ddqp = &dqp->q_core;
560
- defq = xfs_get_defquota(dqp, qinf);
558
+ defq = xfs_get_defquota(qinf, xfs_dquot_type(dqp));
561559
562560 /*
563561 * Timers and warnings have been already set, let's just set the
564562 * default limits for this quota type
565563 */
566
- defq->bhardlimit = be64_to_cpu(ddqp->d_blk_hardlimit);
567
- defq->bsoftlimit = be64_to_cpu(ddqp->d_blk_softlimit);
568
- defq->ihardlimit = be64_to_cpu(ddqp->d_ino_hardlimit);
569
- defq->isoftlimit = be64_to_cpu(ddqp->d_ino_softlimit);
570
- defq->rtbhardlimit = be64_to_cpu(ddqp->d_rtb_hardlimit);
571
- defq->rtbsoftlimit = be64_to_cpu(ddqp->d_rtb_softlimit);
564
+ defq->blk.hard = dqp->q_blk.hardlimit;
565
+ defq->blk.soft = dqp->q_blk.softlimit;
566
+ defq->ino.hard = dqp->q_ino.hardlimit;
567
+ defq->ino.soft = dqp->q_ino.softlimit;
568
+ defq->rtb.hard = dqp->q_rtb.hardlimit;
569
+ defq->rtb.soft = dqp->q_rtb.softlimit;
572570 xfs_qm_dqdestroy(dqp);
573571 }
574572
....@@ -576,19 +574,21 @@
576574 static void
577575 xfs_qm_init_timelimits(
578576 struct xfs_mount *mp,
579
- struct xfs_quotainfo *qinf)
577
+ xfs_dqtype_t type)
580578 {
581
- struct xfs_disk_dquot *ddqp;
579
+ struct xfs_quotainfo *qinf = mp->m_quotainfo;
580
+ struct xfs_def_quota *defq;
582581 struct xfs_dquot *dqp;
583
- uint type;
584582 int error;
585583
586
- qinf->qi_btimelimit = XFS_QM_BTIMELIMIT;
587
- qinf->qi_itimelimit = XFS_QM_ITIMELIMIT;
588
- qinf->qi_rtbtimelimit = XFS_QM_RTBTIMELIMIT;
589
- qinf->qi_bwarnlimit = XFS_QM_BWARNLIMIT;
590
- qinf->qi_iwarnlimit = XFS_QM_IWARNLIMIT;
591
- qinf->qi_rtbwarnlimit = XFS_QM_RTBWARNLIMIT;
584
+ defq = xfs_get_defquota(qinf, type);
585
+
586
+ defq->blk.time = XFS_QM_BTIMELIMIT;
587
+ defq->ino.time = XFS_QM_ITIMELIMIT;
588
+ defq->rtb.time = XFS_QM_RTBTIMELIMIT;
589
+ defq->blk.warn = XFS_QM_BWARNLIMIT;
590
+ defq->ino.warn = XFS_QM_IWARNLIMIT;
591
+ defq->rtb.warn = XFS_QM_RTBWARNLIMIT;
592592
593593 /*
594594 * We try to get the limits from the superuser's limits fields.
....@@ -596,39 +596,28 @@
596596 *
597597 * Since we may not have done a quotacheck by this point, just read
598598 * the dquot without attaching it to any hashtables or lists.
599
- *
600
- * Timers and warnings are globally set by the first timer found in
601
- * user/group/proj quota types, otherwise a default value is used.
602
- * This should be split into different fields per quota type.
603599 */
604
- if (XFS_IS_UQUOTA_RUNNING(mp))
605
- type = XFS_DQ_USER;
606
- else if (XFS_IS_GQUOTA_RUNNING(mp))
607
- type = XFS_DQ_GROUP;
608
- else
609
- type = XFS_DQ_PROJ;
610600 error = xfs_qm_dqget_uncached(mp, 0, type, &dqp);
611601 if (error)
612602 return;
613603
614
- ddqp = &dqp->q_core;
615604 /*
616605 * The warnings and timers set the grace period given to
617606 * a user or group before he or she can not perform any
618607 * more writing. If it is zero, a default is used.
619608 */
620
- if (ddqp->d_btimer)
621
- qinf->qi_btimelimit = be32_to_cpu(ddqp->d_btimer);
622
- if (ddqp->d_itimer)
623
- qinf->qi_itimelimit = be32_to_cpu(ddqp->d_itimer);
624
- if (ddqp->d_rtbtimer)
625
- qinf->qi_rtbtimelimit = be32_to_cpu(ddqp->d_rtbtimer);
626
- if (ddqp->d_bwarns)
627
- qinf->qi_bwarnlimit = be16_to_cpu(ddqp->d_bwarns);
628
- if (ddqp->d_iwarns)
629
- qinf->qi_iwarnlimit = be16_to_cpu(ddqp->d_iwarns);
630
- if (ddqp->d_rtbwarns)
631
- qinf->qi_rtbwarnlimit = be16_to_cpu(ddqp->d_rtbwarns);
609
+ if (dqp->q_blk.timer)
610
+ defq->blk.time = dqp->q_blk.timer;
611
+ if (dqp->q_ino.timer)
612
+ defq->ino.time = dqp->q_ino.timer;
613
+ if (dqp->q_rtb.timer)
614
+ defq->rtb.time = dqp->q_rtb.timer;
615
+ if (dqp->q_blk.warnings)
616
+ defq->blk.warn = dqp->q_blk.warnings;
617
+ if (dqp->q_ino.warnings)
618
+ defq->ino.warn = dqp->q_ino.warnings;
619
+ if (dqp->q_rtb.warnings)
620
+ defq->rtb.warn = dqp->q_rtb.warnings;
632621
633622 xfs_qm_dqdestroy(dqp);
634623 }
....@@ -646,7 +635,7 @@
646635
647636 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
648637
649
- qinf = mp->m_quotainfo = kmem_zalloc(sizeof(xfs_quotainfo_t), KM_SLEEP);
638
+ qinf = mp->m_quotainfo = kmem_zalloc(sizeof(struct xfs_quotainfo), 0);
650639
651640 error = list_lru_init(&qinf->qi_lru);
652641 if (error)
....@@ -671,17 +660,30 @@
671660 /* Precalc some constants */
672661 qinf->qi_dqchunklen = XFS_FSB_TO_BB(mp, XFS_DQUOT_CLUSTER_SIZE_FSB);
673662 qinf->qi_dqperchunk = xfs_calc_dquots_per_chunk(qinf->qi_dqchunklen);
663
+ if (xfs_sb_version_hasbigtime(&mp->m_sb)) {
664
+ qinf->qi_expiry_min =
665
+ xfs_dq_bigtime_to_unix(XFS_DQ_BIGTIME_EXPIRY_MIN);
666
+ qinf->qi_expiry_max =
667
+ xfs_dq_bigtime_to_unix(XFS_DQ_BIGTIME_EXPIRY_MAX);
668
+ } else {
669
+ qinf->qi_expiry_min = XFS_DQ_LEGACY_EXPIRY_MIN;
670
+ qinf->qi_expiry_max = XFS_DQ_LEGACY_EXPIRY_MAX;
671
+ }
672
+ trace_xfs_quota_expiry_range(mp, qinf->qi_expiry_min,
673
+ qinf->qi_expiry_max);
674674
675675 mp->m_qflags |= (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_CHKD);
676676
677
- xfs_qm_init_timelimits(mp, qinf);
677
+ xfs_qm_init_timelimits(mp, XFS_DQTYPE_USER);
678
+ xfs_qm_init_timelimits(mp, XFS_DQTYPE_GROUP);
679
+ xfs_qm_init_timelimits(mp, XFS_DQTYPE_PROJ);
678680
679681 if (XFS_IS_UQUOTA_RUNNING(mp))
680
- xfs_qm_set_defquota(mp, XFS_DQ_USER, qinf);
682
+ xfs_qm_set_defquota(mp, XFS_DQTYPE_USER, qinf);
681683 if (XFS_IS_GQUOTA_RUNNING(mp))
682
- xfs_qm_set_defquota(mp, XFS_DQ_GROUP, qinf);
684
+ xfs_qm_set_defquota(mp, XFS_DQTYPE_GROUP, qinf);
683685 if (XFS_IS_PQUOTA_RUNNING(mp))
684
- xfs_qm_set_defquota(mp, XFS_DQ_PROJ, qinf);
686
+ xfs_qm_set_defquota(mp, XFS_DQTYPE_PROJ, qinf);
685687
686688 qinf->qi_shrinker.count_objects = xfs_qm_shrink_count;
687689 qinf->qi_shrinker.scan_objects = xfs_qm_shrink_scan;
....@@ -713,9 +715,9 @@
713715 */
714716 void
715717 xfs_qm_destroy_quotainfo(
716
- xfs_mount_t *mp)
718
+ struct xfs_mount *mp)
717719 {
718
- xfs_quotainfo_t *qi;
720
+ struct xfs_quotainfo *qi;
719721
720722 qi = mp->m_quotainfo;
721723 ASSERT(qi != NULL);
....@@ -758,11 +760,15 @@
758760 if ((flags & XFS_QMOPT_PQUOTA) &&
759761 (mp->m_sb.sb_gquotino != NULLFSINO)) {
760762 ino = mp->m_sb.sb_gquotino;
761
- ASSERT(mp->m_sb.sb_pquotino == NULLFSINO);
763
+ if (XFS_IS_CORRUPT(mp,
764
+ mp->m_sb.sb_pquotino != NULLFSINO))
765
+ return -EFSCORRUPTED;
762766 } else if ((flags & XFS_QMOPT_GQUOTA) &&
763767 (mp->m_sb.sb_pquotino != NULLFSINO)) {
764768 ino = mp->m_sb.sb_pquotino;
765
- ASSERT(mp->m_sb.sb_gquotino == NULLFSINO);
769
+ if (XFS_IS_CORRUPT(mp,
770
+ mp->m_sb.sb_gquotino != NULLFSINO))
771
+ return -EFSCORRUPTED;
766772 }
767773 if (ino != NULLFSINO) {
768774 error = xfs_iget(mp, NULL, ino, 0, 0, ip);
....@@ -775,7 +781,8 @@
775781 }
776782
777783 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_create,
778
- XFS_QM_QINOCREATE_SPACE_RES(mp), 0, 0, &tp);
784
+ need_alloc ? XFS_QM_QINOCREATE_SPACE_RES(mp) : 0,
785
+ 0, 0, &tp);
779786 if (error)
780787 return error;
781788
....@@ -826,14 +833,13 @@
826833
827834 STATIC void
828835 xfs_qm_reset_dqcounts(
829
- xfs_mount_t *mp,
830
- xfs_buf_t *bp,
831
- xfs_dqid_t id,
832
- uint type)
836
+ struct xfs_mount *mp,
837
+ struct xfs_buf *bp,
838
+ xfs_dqid_t id,
839
+ xfs_dqtype_t type)
833840 {
834841 struct xfs_dqblk *dqb;
835842 int j;
836
- xfs_failaddr_t fa;
837843
838844 trace_xfs_reset_dqcounts(bp, _RET_IP_);
839845
....@@ -858,24 +864,34 @@
858864 * find uninitialised dquot blks. See comment in
859865 * xfs_dquot_verify.
860866 */
861
- fa = xfs_dqblk_verify(mp, &dqb[j], id + j, type);
862
- if (fa)
867
+ if (xfs_dqblk_verify(mp, &dqb[j], id + j) ||
868
+ (dqb[j].dd_diskdq.d_type & XFS_DQTYPE_REC_MASK) != type)
863869 xfs_dqblk_repair(mp, &dqb[j], id + j, type);
864870
865871 /*
866872 * Reset type in case we are reusing group quota file for
867873 * project quotas or vice versa
868874 */
869
- ddq->d_flags = type;
875
+ ddq->d_type = type;
870876 ddq->d_bcount = 0;
871877 ddq->d_icount = 0;
872878 ddq->d_rtbcount = 0;
873
- ddq->d_btimer = 0;
874
- ddq->d_itimer = 0;
875
- ddq->d_rtbtimer = 0;
876
- ddq->d_bwarns = 0;
877
- ddq->d_iwarns = 0;
878
- ddq->d_rtbwarns = 0;
879
+
880
+ /*
881
+ * dquot id 0 stores the default grace period and the maximum
882
+ * warning limit that were set by the administrator, so we
883
+ * should not reset them.
884
+ */
885
+ if (ddq->d_id != 0) {
886
+ ddq->d_btimer = 0;
887
+ ddq->d_itimer = 0;
888
+ ddq->d_rtbtimer = 0;
889
+ ddq->d_bwarns = 0;
890
+ ddq->d_iwarns = 0;
891
+ ddq->d_rtbwarns = 0;
892
+ if (xfs_sb_version_hasbigtime(&mp->m_sb))
893
+ ddq->d_type |= XFS_DQTYPE_BIGTIME;
894
+ }
879895
880896 if (xfs_sb_version_hascrc(&mp->m_sb)) {
881897 xfs_update_cksum((char *)&dqb[j],
....@@ -891,17 +907,13 @@
891907 xfs_dqid_t firstid,
892908 xfs_fsblock_t bno,
893909 xfs_filblks_t blkcnt,
894
- uint flags,
910
+ xfs_dqtype_t type,
895911 struct list_head *buffer_list)
896912 {
897913 struct xfs_buf *bp;
898
- int error;
899
- int type;
914
+ int error = 0;
900915
901916 ASSERT(blkcnt > 0);
902
- type = flags & XFS_QMOPT_UQUOTA ? XFS_DQ_USER :
903
- (flags & XFS_QMOPT_PQUOTA ? XFS_DQ_PROJ : XFS_DQ_GROUP);
904
- error = 0;
905917
906918 /*
907919 * Blkcnt arg can be a very big number, and might even be
....@@ -961,7 +973,7 @@
961973 xfs_qm_reset_dqcounts_buf(
962974 struct xfs_mount *mp,
963975 struct xfs_inode *qip,
964
- uint flags,
976
+ xfs_dqtype_t type,
965977 struct list_head *buffer_list)
966978 {
967979 struct xfs_bmbt_irec *map;
....@@ -982,7 +994,7 @@
982994 if (qip->i_d.di_nblocks == 0)
983995 return 0;
984996
985
- map = kmem_alloc(XFS_DQITER_MAP_SIZE * sizeof(*map), KM_SLEEP);
997
+ map = kmem_alloc(XFS_DQITER_MAP_SIZE * sizeof(*map), 0);
986998
987999 lblkno = 0;
9881000 maxlblkcnt = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
....@@ -1037,7 +1049,7 @@
10371049 error = xfs_qm_reset_dqcounts_all(mp, firstid,
10381050 map[i].br_startblock,
10391051 map[i].br_blockcount,
1040
- flags, buffer_list);
1052
+ type, buffer_list);
10411053 if (error)
10421054 goto out;
10431055 }
....@@ -1059,7 +1071,7 @@
10591071 STATIC int
10601072 xfs_qm_quotacheck_dqadjust(
10611073 struct xfs_inode *ip,
1062
- uint type,
1074
+ xfs_dqtype_t type,
10631075 xfs_qcnt_t nblks,
10641076 xfs_qcnt_t rtblks)
10651077 {
....@@ -1085,15 +1097,15 @@
10851097 * Adjust the inode count and the block count to reflect this inode's
10861098 * resource usage.
10871099 */
1088
- be64_add_cpu(&dqp->q_core.d_icount, 1);
1089
- dqp->q_res_icount++;
1100
+ dqp->q_ino.count++;
1101
+ dqp->q_ino.reserved++;
10901102 if (nblks) {
1091
- be64_add_cpu(&dqp->q_core.d_bcount, nblks);
1092
- dqp->q_res_bcount += nblks;
1103
+ dqp->q_blk.count += nblks;
1104
+ dqp->q_blk.reserved += nblks;
10931105 }
10941106 if (rtblks) {
1095
- be64_add_cpu(&dqp->q_core.d_rtbcount, rtblks);
1096
- dqp->q_res_rtbcount += rtblks;
1107
+ dqp->q_rtb.count += rtblks;
1108
+ dqp->q_rtb.reserved += rtblks;
10971109 }
10981110
10991111 /*
....@@ -1101,12 +1113,12 @@
11011113 *
11021114 * There are no timers for the default values set in the root dquot.
11031115 */
1104
- if (dqp->q_core.d_id) {
1105
- xfs_qm_adjust_dqlimits(mp, dqp);
1106
- xfs_qm_adjust_dqtimers(mp, &dqp->q_core);
1116
+ if (dqp->q_id) {
1117
+ xfs_qm_adjust_dqlimits(dqp);
1118
+ xfs_qm_adjust_dqtimers(dqp);
11071119 }
11081120
1109
- dqp->dq_flags |= XFS_DQ_DIRTY;
1121
+ dqp->q_flags |= XFS_DQFLAG_DIRTY;
11101122 xfs_qm_dqput(dqp);
11111123 return 0;
11121124 }
....@@ -1118,17 +1130,15 @@
11181130 /* ARGSUSED */
11191131 STATIC int
11201132 xfs_qm_dqusage_adjust(
1121
- xfs_mount_t *mp, /* mount point for filesystem */
1122
- xfs_ino_t ino, /* inode number to get data for */
1123
- void __user *buffer, /* not used */
1124
- int ubsize, /* not used */
1125
- int *ubused, /* not used */
1126
- int *res) /* result code value */
1133
+ struct xfs_mount *mp,
1134
+ struct xfs_trans *tp,
1135
+ xfs_ino_t ino,
1136
+ void *data)
11271137 {
1128
- xfs_inode_t *ip;
1129
- xfs_qcnt_t nblks;
1130
- xfs_filblks_t rtblks = 0; /* total rt blks */
1131
- int error;
1138
+ struct xfs_inode *ip;
1139
+ xfs_qcnt_t nblks;
1140
+ xfs_filblks_t rtblks = 0; /* total rt blks */
1141
+ int error;
11321142
11331143 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
11341144
....@@ -1136,20 +1146,18 @@
11361146 * rootino must have its resources accounted for, not so with the quota
11371147 * inodes.
11381148 */
1139
- if (xfs_is_quota_inode(&mp->m_sb, ino)) {
1140
- *res = BULKSTAT_RV_NOTHING;
1141
- return -EINVAL;
1142
- }
1149
+ if (xfs_is_quota_inode(&mp->m_sb, ino))
1150
+ return 0;
11431151
11441152 /*
11451153 * We don't _need_ to take the ilock EXCL here because quotacheck runs
11461154 * at mount time and therefore nobody will be racing chown/chproj.
11471155 */
1148
- error = xfs_iget(mp, NULL, ino, XFS_IGET_DONTCACHE, 0, &ip);
1149
- if (error) {
1150
- *res = BULKSTAT_RV_NOTHING;
1156
+ error = xfs_iget(mp, tp, ino, XFS_IGET_DONTCACHE, 0, &ip);
1157
+ if (error == -EINVAL || error == -ENOENT)
1158
+ return 0;
1159
+ if (error)
11511160 return error;
1152
- }
11531161
11541162 ASSERT(ip->i_delayed_blks == 0);
11551163
....@@ -1157,7 +1165,7 @@
11571165 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
11581166
11591167 if (!(ifp->if_flags & XFS_IFEXTENTS)) {
1160
- error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK);
1168
+ error = xfs_iread_extents(tp, ip, XFS_DATA_FORK);
11611169 if (error)
11621170 goto error0;
11631171 }
....@@ -1180,33 +1188,28 @@
11801188 * and quotaoffs don't race. (Quotachecks happen at mount time only).
11811189 */
11821190 if (XFS_IS_UQUOTA_ON(mp)) {
1183
- error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQ_USER, nblks,
1191
+ error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQTYPE_USER, nblks,
11841192 rtblks);
11851193 if (error)
11861194 goto error0;
11871195 }
11881196
11891197 if (XFS_IS_GQUOTA_ON(mp)) {
1190
- error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQ_GROUP, nblks,
1198
+ error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQTYPE_GROUP, nblks,
11911199 rtblks);
11921200 if (error)
11931201 goto error0;
11941202 }
11951203
11961204 if (XFS_IS_PQUOTA_ON(mp)) {
1197
- error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQ_PROJ, nblks,
1205
+ error = xfs_qm_quotacheck_dqadjust(ip, XFS_DQTYPE_PROJ, nblks,
11981206 rtblks);
11991207 if (error)
12001208 goto error0;
12011209 }
12021210
1203
- xfs_irele(ip);
1204
- *res = BULKSTAT_RV_DIDONE;
1205
- return 0;
1206
-
12071211 error0:
12081212 xfs_irele(ip);
1209
- *res = BULKSTAT_RV_GIVEUP;
12101213 return error;
12111214 }
12121215
....@@ -1221,7 +1224,7 @@
12211224 int error = 0;
12221225
12231226 xfs_dqlock(dqp);
1224
- if (dqp->dq_flags & XFS_DQ_FREEING)
1227
+ if (dqp->q_flags & XFS_DQFLAG_FREEING)
12251228 goto out_unlock;
12261229 if (!XFS_DQ_IS_DIRTY(dqp))
12271230 goto out_unlock;
....@@ -1270,18 +1273,13 @@
12701273 xfs_qm_quotacheck(
12711274 xfs_mount_t *mp)
12721275 {
1273
- int done, count, error, error2;
1274
- xfs_ino_t lastino;
1275
- size_t structsz;
1276
+ int error, error2;
12761277 uint flags;
12771278 LIST_HEAD (buffer_list);
12781279 struct xfs_inode *uip = mp->m_quotainfo->qi_uquotaip;
12791280 struct xfs_inode *gip = mp->m_quotainfo->qi_gquotaip;
12801281 struct xfs_inode *pip = mp->m_quotainfo->qi_pquotaip;
12811282
1282
- count = INT_MAX;
1283
- structsz = 1;
1284
- lastino = 0;
12851283 flags = 0;
12861284
12871285 ASSERT(uip || gip || pip);
....@@ -1295,7 +1293,7 @@
12951293 * We don't log our changes till later.
12961294 */
12971295 if (uip) {
1298
- error = xfs_qm_reset_dqcounts_buf(mp, uip, XFS_QMOPT_UQUOTA,
1296
+ error = xfs_qm_reset_dqcounts_buf(mp, uip, XFS_DQTYPE_USER,
12991297 &buffer_list);
13001298 if (error)
13011299 goto error_return;
....@@ -1303,7 +1301,7 @@
13031301 }
13041302
13051303 if (gip) {
1306
- error = xfs_qm_reset_dqcounts_buf(mp, gip, XFS_QMOPT_GQUOTA,
1304
+ error = xfs_qm_reset_dqcounts_buf(mp, gip, XFS_DQTYPE_GROUP,
13071305 &buffer_list);
13081306 if (error)
13091307 goto error_return;
....@@ -1311,42 +1309,41 @@
13111309 }
13121310
13131311 if (pip) {
1314
- error = xfs_qm_reset_dqcounts_buf(mp, pip, XFS_QMOPT_PQUOTA,
1312
+ error = xfs_qm_reset_dqcounts_buf(mp, pip, XFS_DQTYPE_PROJ,
13151313 &buffer_list);
13161314 if (error)
13171315 goto error_return;
13181316 flags |= XFS_PQUOTA_CHKD;
13191317 }
13201318
1321
- do {
1319
+ error = xfs_iwalk_threaded(mp, 0, 0, xfs_qm_dqusage_adjust, 0, true,
1320
+ NULL);
1321
+ if (error) {
13221322 /*
1323
- * Iterate thru all the inodes in the file system,
1324
- * adjusting the corresponding dquot counters in core.
1323
+ * The inode walk may have partially populated the dquot
1324
+ * caches. We must purge them before disabling quota and
1325
+ * tearing down the quotainfo, or else the dquots will leak.
13251326 */
1326
- error = xfs_bulkstat(mp, &lastino, &count,
1327
- xfs_qm_dqusage_adjust,
1328
- structsz, NULL, &done);
1329
- if (error)
1330
- break;
1331
-
1332
- } while (!done);
1327
+ xfs_qm_dqpurge_all(mp, XFS_QMOPT_QUOTALL);
1328
+ goto error_return;
1329
+ }
13331330
13341331 /*
13351332 * We've made all the changes that we need to make incore. Flush them
13361333 * down to disk buffers if everything was updated successfully.
13371334 */
13381335 if (XFS_IS_UQUOTA_ON(mp)) {
1339
- error = xfs_qm_dquot_walk(mp, XFS_DQ_USER, xfs_qm_flush_one,
1336
+ error = xfs_qm_dquot_walk(mp, XFS_DQTYPE_USER, xfs_qm_flush_one,
13401337 &buffer_list);
13411338 }
13421339 if (XFS_IS_GQUOTA_ON(mp)) {
1343
- error2 = xfs_qm_dquot_walk(mp, XFS_DQ_GROUP, xfs_qm_flush_one,
1340
+ error2 = xfs_qm_dquot_walk(mp, XFS_DQTYPE_GROUP, xfs_qm_flush_one,
13441341 &buffer_list);
13451342 if (!error)
13461343 error = error2;
13471344 }
13481345 if (XFS_IS_PQUOTA_ON(mp)) {
1349
- error2 = xfs_qm_dquot_walk(mp, XFS_DQ_PROJ, xfs_qm_flush_one,
1346
+ error2 = xfs_qm_dquot_walk(mp, XFS_DQTYPE_PROJ, xfs_qm_flush_one,
13501347 &buffer_list);
13511348 if (!error)
13521349 error = error2;
....@@ -1585,7 +1582,7 @@
15851582
15861583 STATIC void
15871584 xfs_qm_destroy_quotainos(
1588
- xfs_quotainfo_t *qi)
1585
+ struct xfs_quotainfo *qi)
15891586 {
15901587 if (qi->qi_uquotaip) {
15911588 xfs_irele(qi->qi_uquotaip);
....@@ -1609,8 +1606,7 @@
16091606 struct xfs_quotainfo *qi = mp->m_quotainfo;
16101607
16111608 mutex_lock(&qi->qi_tree_lock);
1612
- radix_tree_delete(xfs_dquot_tree(qi, dqp->q_core.d_flags),
1613
- be32_to_cpu(dqp->q_core.d_id));
1609
+ radix_tree_delete(xfs_dquot_tree(qi, xfs_dquot_type(dqp)), dqp->q_id);
16141610
16151611 qi->qi_dquots--;
16161612 mutex_unlock(&qi->qi_tree_lock);
....@@ -1634,8 +1630,8 @@
16341630 int
16351631 xfs_qm_vop_dqalloc(
16361632 struct xfs_inode *ip,
1637
- xfs_dqid_t uid,
1638
- xfs_dqid_t gid,
1633
+ kuid_t uid,
1634
+ kgid_t gid,
16391635 prid_t prid,
16401636 uint flags,
16411637 struct xfs_dquot **O_udqpp,
....@@ -1643,6 +1639,8 @@
16431639 struct xfs_dquot **O_pdqpp)
16441640 {
16451641 struct xfs_mount *mp = ip->i_mount;
1642
+ struct inode *inode = VFS_I(ip);
1643
+ struct user_namespace *user_ns = inode->i_sb->s_user_ns;
16461644 struct xfs_dquot *uq = NULL;
16471645 struct xfs_dquot *gq = NULL;
16481646 struct xfs_dquot *pq = NULL;
....@@ -1656,7 +1654,7 @@
16561654 xfs_ilock(ip, lockflags);
16571655
16581656 if ((flags & XFS_QMOPT_INHERIT) && XFS_INHERIT_GID(ip))
1659
- gid = ip->i_d.di_gid;
1657
+ gid = inode->i_gid;
16601658
16611659 /*
16621660 * Attach the dquot(s) to this inode, doing a dquot allocation
....@@ -1671,7 +1669,8 @@
16711669 }
16721670
16731671 if ((flags & XFS_QMOPT_UQUOTA) && XFS_IS_UQUOTA_ON(mp)) {
1674
- if (ip->i_d.di_uid != uid) {
1672
+ ASSERT(O_udqpp);
1673
+ if (!uid_eq(inode->i_uid, uid)) {
16751674 /*
16761675 * What we need is the dquot that has this uid, and
16771676 * if we send the inode to dqget, the uid of the inode
....@@ -1682,7 +1681,8 @@
16821681 * holding ilock.
16831682 */
16841683 xfs_iunlock(ip, lockflags);
1685
- error = xfs_qm_dqget(mp, uid, XFS_DQ_USER, true, &uq);
1684
+ error = xfs_qm_dqget(mp, from_kuid(user_ns, uid),
1685
+ XFS_DQTYPE_USER, true, &uq);
16861686 if (error) {
16871687 ASSERT(error != -ENOENT);
16881688 return error;
....@@ -1703,9 +1703,11 @@
17031703 }
17041704 }
17051705 if ((flags & XFS_QMOPT_GQUOTA) && XFS_IS_GQUOTA_ON(mp)) {
1706
- if (ip->i_d.di_gid != gid) {
1706
+ ASSERT(O_gdqpp);
1707
+ if (!gid_eq(inode->i_gid, gid)) {
17071708 xfs_iunlock(ip, lockflags);
1708
- error = xfs_qm_dqget(mp, gid, XFS_DQ_GROUP, true, &gq);
1709
+ error = xfs_qm_dqget(mp, from_kgid(user_ns, gid),
1710
+ XFS_DQTYPE_GROUP, true, &gq);
17091711 if (error) {
17101712 ASSERT(error != -ENOENT);
17111713 goto error_rele;
....@@ -1719,10 +1721,11 @@
17191721 }
17201722 }
17211723 if ((flags & XFS_QMOPT_PQUOTA) && XFS_IS_PQUOTA_ON(mp)) {
1722
- if (xfs_get_projid(ip) != prid) {
1724
+ ASSERT(O_pdqpp);
1725
+ if (ip->i_d.di_projid != prid) {
17231726 xfs_iunlock(ip, lockflags);
1724
- error = xfs_qm_dqget(mp, (xfs_dqid_t)prid, XFS_DQ_PROJ,
1725
- true, &pq);
1727
+ error = xfs_qm_dqget(mp, prid,
1728
+ XFS_DQTYPE_PROJ, true, &pq);
17261729 if (error) {
17271730 ASSERT(error != -ENOENT);
17281731 goto error_rele;
....@@ -1735,8 +1738,7 @@
17351738 pq = xfs_qm_dqhold(ip->i_pdquot);
17361739 }
17371740 }
1738
- if (uq)
1739
- trace_xfs_dquot_dqalloc(ip);
1741
+ trace_xfs_dquot_dqalloc(ip);
17401742
17411743 xfs_iunlock(ip, lockflags);
17421744 if (O_udqpp)
....@@ -1763,14 +1765,14 @@
17631765 * Actually transfer ownership, and do dquot modifications.
17641766 * These were already reserved.
17651767 */
1766
-xfs_dquot_t *
1768
+struct xfs_dquot *
17671769 xfs_qm_vop_chown(
1768
- xfs_trans_t *tp,
1769
- xfs_inode_t *ip,
1770
- xfs_dquot_t **IO_olddq,
1771
- xfs_dquot_t *newdq)
1770
+ struct xfs_trans *tp,
1771
+ struct xfs_inode *ip,
1772
+ struct xfs_dquot **IO_olddq,
1773
+ struct xfs_dquot *newdq)
17721774 {
1773
- xfs_dquot_t *prevdq;
1775
+ struct xfs_dquot *prevdq;
17741776 uint bfield = XFS_IS_REALTIME_INODE(ip) ?
17751777 XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT;
17761778
....@@ -1789,6 +1791,29 @@
17891791 /* the sparkling new dquot */
17901792 xfs_trans_mod_dquot(tp, newdq, bfield, ip->i_d.di_nblocks);
17911793 xfs_trans_mod_dquot(tp, newdq, XFS_TRANS_DQ_ICOUNT, 1);
1794
+
1795
+ /*
1796
+ * Back when we made quota reservations for the chown, we reserved the
1797
+ * ondisk blocks + delalloc blocks with the new dquot. Now that we've
1798
+ * switched the dquots, decrease the new dquot's block reservation
1799
+ * (having already bumped up the real counter) so that we don't have
1800
+ * any reservation to give back when we commit.
1801
+ */
1802
+ xfs_trans_mod_dquot(tp, newdq, XFS_TRANS_DQ_RES_BLKS,
1803
+ -ip->i_delayed_blks);
1804
+
1805
+ /*
1806
+ * Give the incore reservation for delalloc blocks back to the old
1807
+ * dquot. We don't normally handle delalloc quota reservations
1808
+ * transactionally, so just lock the dquot and subtract from the
1809
+ * reservation. Dirty the transaction because it's too late to turn
1810
+ * back now.
1811
+ */
1812
+ tp->t_flags |= XFS_TRANS_DIRTY;
1813
+ xfs_dqlock(prevdq);
1814
+ ASSERT(prevdq->q_blk.reserved >= ip->i_delayed_blks);
1815
+ prevdq->q_blk.reserved -= ip->i_delayed_blks;
1816
+ xfs_dqunlock(prevdq);
17921817
17931818 /*
17941819 * Take an extra reference, because the inode is going to keep
....@@ -1812,86 +1837,39 @@
18121837 uint flags)
18131838 {
18141839 struct xfs_mount *mp = ip->i_mount;
1815
- uint delblks, blkflags, prjflags = 0;
1816
- struct xfs_dquot *udq_unres = NULL;
1817
- struct xfs_dquot *gdq_unres = NULL;
1818
- struct xfs_dquot *pdq_unres = NULL;
1840
+ unsigned int blkflags;
18191841 struct xfs_dquot *udq_delblks = NULL;
18201842 struct xfs_dquot *gdq_delblks = NULL;
18211843 struct xfs_dquot *pdq_delblks = NULL;
1822
- int error;
1823
-
18241844
18251845 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
18261846 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
18271847
1828
- delblks = ip->i_delayed_blks;
18291848 blkflags = XFS_IS_REALTIME_INODE(ip) ?
18301849 XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS;
18311850
18321851 if (XFS_IS_UQUOTA_ON(mp) && udqp &&
1833
- ip->i_d.di_uid != be32_to_cpu(udqp->q_core.d_id)) {
1852
+ i_uid_read(VFS_I(ip)) != udqp->q_id)
18341853 udq_delblks = udqp;
1835
- /*
1836
- * If there are delayed allocation blocks, then we have to
1837
- * unreserve those from the old dquot, and add them to the
1838
- * new dquot.
1839
- */
1840
- if (delblks) {
1841
- ASSERT(ip->i_udquot);
1842
- udq_unres = ip->i_udquot;
1843
- }
1844
- }
1854
+
18451855 if (XFS_IS_GQUOTA_ON(ip->i_mount) && gdqp &&
1846
- ip->i_d.di_gid != be32_to_cpu(gdqp->q_core.d_id)) {
1856
+ i_gid_read(VFS_I(ip)) != gdqp->q_id)
18471857 gdq_delblks = gdqp;
1848
- if (delblks) {
1849
- ASSERT(ip->i_gdquot);
1850
- gdq_unres = ip->i_gdquot;
1851
- }
1852
- }
18531858
18541859 if (XFS_IS_PQUOTA_ON(ip->i_mount) && pdqp &&
1855
- xfs_get_projid(ip) != be32_to_cpu(pdqp->q_core.d_id)) {
1856
- prjflags = XFS_QMOPT_ENOSPC;
1860
+ ip->i_d.di_projid != pdqp->q_id)
18571861 pdq_delblks = pdqp;
1858
- if (delblks) {
1859
- ASSERT(ip->i_pdquot);
1860
- pdq_unres = ip->i_pdquot;
1861
- }
1862
- }
1863
-
1864
- error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount,
1865
- udq_delblks, gdq_delblks, pdq_delblks,
1866
- ip->i_d.di_nblocks, 1,
1867
- flags | blkflags | prjflags);
1868
- if (error)
1869
- return error;
18701862
18711863 /*
1872
- * Do the delayed blks reservations/unreservations now. Since, these
1873
- * are done without the help of a transaction, if a reservation fails
1874
- * its previous reservations won't be automatically undone by trans
1875
- * code. So, we have to do it manually here.
1864
+ * Reserve enough quota to handle blocks on disk and reserved for a
1865
+ * delayed allocation. We'll actually transfer the delalloc
1866
+ * reservation between dquots at chown time, even though that part is
1867
+ * only semi-transactional.
18761868 */
1877
- if (delblks) {
1878
- /*
1879
- * Do the reservations first. Unreservation can't fail.
1880
- */
1881
- ASSERT(udq_delblks || gdq_delblks || pdq_delblks);
1882
- ASSERT(udq_unres || gdq_unres || pdq_unres);
1883
- error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
1884
- udq_delblks, gdq_delblks, pdq_delblks,
1885
- (xfs_qcnt_t)delblks, 0,
1886
- flags | blkflags | prjflags);
1887
- if (error)
1888
- return error;
1889
- xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
1890
- udq_unres, gdq_unres, pdq_unres,
1891
- -((xfs_qcnt_t)delblks), 0, blkflags);
1892
- }
1893
-
1894
- return 0;
1869
+ return xfs_trans_reserve_quota_bydquots(tp, ip->i_mount, udq_delblks,
1870
+ gdq_delblks, pdq_delblks,
1871
+ ip->i_d.di_nblocks + ip->i_delayed_blks,
1872
+ 1, blkflags | flags);
18951873 }
18961874
18971875 int
....@@ -1936,24 +1914,24 @@
19361914 return;
19371915
19381916 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
1939
- ASSERT(XFS_IS_QUOTA_RUNNING(mp));
19401917
19411918 if (udqp && XFS_IS_UQUOTA_ON(mp)) {
19421919 ASSERT(ip->i_udquot == NULL);
1943
- ASSERT(ip->i_d.di_uid == be32_to_cpu(udqp->q_core.d_id));
1920
+ ASSERT(i_uid_read(VFS_I(ip)) == udqp->q_id);
19441921
19451922 ip->i_udquot = xfs_qm_dqhold(udqp);
19461923 xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1);
19471924 }
19481925 if (gdqp && XFS_IS_GQUOTA_ON(mp)) {
19491926 ASSERT(ip->i_gdquot == NULL);
1950
- ASSERT(ip->i_d.di_gid == be32_to_cpu(gdqp->q_core.d_id));
1927
+ ASSERT(i_gid_read(VFS_I(ip)) == gdqp->q_id);
1928
+
19511929 ip->i_gdquot = xfs_qm_dqhold(gdqp);
19521930 xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1);
19531931 }
19541932 if (pdqp && XFS_IS_PQUOTA_ON(mp)) {
19551933 ASSERT(ip->i_pdquot == NULL);
1956
- ASSERT(xfs_get_projid(ip) == be32_to_cpu(pdqp->q_core.d_id));
1934
+ ASSERT(ip->i_d.di_projid == pdqp->q_id);
19571935
19581936 ip->i_pdquot = xfs_qm_dqhold(pdqp);
19591937 xfs_trans_mod_dquot(tp, pdqp, XFS_TRANS_DQ_ICOUNT, 1);