forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/fs/xfs/scrub/quota.c
....@@ -9,37 +9,26 @@
99 #include "xfs_format.h"
1010 #include "xfs_trans_resv.h"
1111 #include "xfs_mount.h"
12
-#include "xfs_defer.h"
13
-#include "xfs_btree.h"
14
-#include "xfs_bit.h"
1512 #include "xfs_log_format.h"
1613 #include "xfs_trans.h"
17
-#include "xfs_sb.h"
1814 #include "xfs_inode.h"
19
-#include "xfs_inode_fork.h"
20
-#include "xfs_alloc.h"
21
-#include "xfs_bmap.h"
2215 #include "xfs_quota.h"
2316 #include "xfs_qm.h"
24
-#include "xfs_dquot.h"
25
-#include "xfs_dquot_item.h"
26
-#include "scrub/xfs_scrub.h"
2717 #include "scrub/scrub.h"
2818 #include "scrub/common.h"
29
-#include "scrub/trace.h"
3019
3120 /* Convert a scrub type code to a DQ flag, or return 0 if error. */
32
-static inline uint
21
+static inline xfs_dqtype_t
3322 xchk_quota_to_dqtype(
3423 struct xfs_scrub *sc)
3524 {
3625 switch (sc->sm->sm_type) {
3726 case XFS_SCRUB_TYPE_UQUOTA:
38
- return XFS_DQ_USER;
27
+ return XFS_DQTYPE_USER;
3928 case XFS_SCRUB_TYPE_GQUOTA:
40
- return XFS_DQ_GROUP;
29
+ return XFS_DQTYPE_GROUP;
4130 case XFS_SCRUB_TYPE_PQUOTA:
42
- return XFS_DQ_PROJ;
31
+ return XFS_DQTYPE_PROJ;
4332 default:
4433 return 0;
4534 }
....@@ -51,7 +40,7 @@
5140 struct xfs_scrub *sc,
5241 struct xfs_inode *ip)
5342 {
54
- uint dqtype;
43
+ xfs_dqtype_t dqtype;
5544 int error;
5645
5746 if (!XFS_IS_QUOTA_RUNNING(sc->mp) || !XFS_IS_QUOTA_ON(sc->mp))
....@@ -60,7 +49,7 @@
6049 dqtype = xchk_quota_to_dqtype(sc);
6150 if (dqtype == 0)
6251 return -EINVAL;
63
- sc->has_quotaofflock = true;
52
+ sc->flags |= XCHK_HAS_QUOTAOFFLOCK;
6453 mutex_lock(&sc->mp->m_quotainfo->qi_quotaofflock);
6554 if (!xfs_this_quota_on(sc->mp, dqtype))
6655 return -ENOENT;
....@@ -84,52 +73,29 @@
8473 STATIC int
8574 xchk_quota_item(
8675 struct xfs_dquot *dq,
87
- uint dqtype,
76
+ xfs_dqtype_t dqtype,
8877 void *priv)
8978 {
9079 struct xchk_quota_info *sqi = priv;
9180 struct xfs_scrub *sc = sqi->sc;
9281 struct xfs_mount *mp = sc->mp;
93
- struct xfs_disk_dquot *d = &dq->q_core;
9482 struct xfs_quotainfo *qi = mp->m_quotainfo;
9583 xfs_fileoff_t offset;
96
- unsigned long long bsoft;
97
- unsigned long long isoft;
98
- unsigned long long rsoft;
99
- unsigned long long bhard;
100
- unsigned long long ihard;
101
- unsigned long long rhard;
102
- unsigned long long bcount;
103
- unsigned long long icount;
104
- unsigned long long rcount;
10584 xfs_ino_t fs_icount;
106
- xfs_dqid_t id = be32_to_cpu(d->d_id);
85
+ int error = 0;
86
+
87
+ if (xchk_should_terminate(sc, &error))
88
+ return error;
10789
10890 /*
10991 * Except for the root dquot, the actual dquot we got must either have
11092 * the same or higher id as we saw before.
11193 */
112
- offset = id / qi->qi_dqperchunk;
113
- if (id && id <= sqi->last_id)
94
+ offset = dq->q_id / qi->qi_dqperchunk;
95
+ if (dq->q_id && dq->q_id <= sqi->last_id)
11496 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
11597
116
- sqi->last_id = id;
117
-
118
- /* Did we get the dquot type we wanted? */
119
- if (dqtype != (d->d_flags & XFS_DQ_ALLTYPES))
120
- xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
121
-
122
- if (d->d_pad0 != cpu_to_be32(0) || d->d_pad != cpu_to_be16(0))
123
- xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
124
-
125
- /* Check the limits. */
126
- bhard = be64_to_cpu(d->d_blk_hardlimit);
127
- ihard = be64_to_cpu(d->d_ino_hardlimit);
128
- rhard = be64_to_cpu(d->d_rtb_hardlimit);
129
-
130
- bsoft = be64_to_cpu(d->d_blk_softlimit);
131
- isoft = be64_to_cpu(d->d_ino_softlimit);
132
- rsoft = be64_to_cpu(d->d_rtb_softlimit);
98
+ sqi->last_id = dq->q_id;
13399
134100 /*
135101 * Warn if the hard limits are larger than the fs.
....@@ -139,25 +105,22 @@
139105 * Complain about corruption if the soft limit is greater than
140106 * the hard limit.
141107 */
142
- if (bhard > mp->m_sb.sb_dblocks)
108
+ if (dq->q_blk.hardlimit > mp->m_sb.sb_dblocks)
143109 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
144
- if (bsoft > bhard)
110
+ if (dq->q_blk.softlimit > dq->q_blk.hardlimit)
145111 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
146112
147
- if (ihard > mp->m_maxicount)
113
+ if (dq->q_ino.hardlimit > M_IGEO(mp)->maxicount)
148114 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
149
- if (isoft > ihard)
115
+ if (dq->q_ino.softlimit > dq->q_ino.hardlimit)
150116 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
151117
152
- if (rhard > mp->m_sb.sb_rblocks)
118
+ if (dq->q_rtb.hardlimit > mp->m_sb.sb_rblocks)
153119 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
154
- if (rsoft > rhard)
120
+ if (dq->q_rtb.softlimit > dq->q_rtb.hardlimit)
155121 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
156122
157123 /* Check the resource counts. */
158
- bcount = be64_to_cpu(d->d_bcount);
159
- icount = be64_to_cpu(d->d_icount);
160
- rcount = be64_to_cpu(d->d_rtbcount);
161124 fs_icount = percpu_counter_sum(&mp->m_icount);
162125
163126 /*
....@@ -166,15 +129,15 @@
166129 * if there are no quota limits.
167130 */
168131 if (xfs_sb_version_hasreflink(&mp->m_sb)) {
169
- if (mp->m_sb.sb_dblocks < bcount)
132
+ if (mp->m_sb.sb_dblocks < dq->q_blk.count)
170133 xchk_fblock_set_warning(sc, XFS_DATA_FORK,
171134 offset);
172135 } else {
173
- if (mp->m_sb.sb_dblocks < bcount)
136
+ if (mp->m_sb.sb_dblocks < dq->q_blk.count)
174137 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK,
175138 offset);
176139 }
177
- if (icount > fs_icount || rcount > mp->m_sb.sb_rblocks)
140
+ if (dq->q_ino.count > fs_icount || dq->q_rtb.count > mp->m_sb.sb_rblocks)
178141 xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
179142
180143 /*
....@@ -182,12 +145,24 @@
182145 * lower limit than the actual usage. However, we flag it for
183146 * admin review.
184147 */
185
- if (id != 0 && bhard != 0 && bcount > bhard)
148
+ if (dq->q_id == 0)
149
+ goto out;
150
+
151
+ if (dq->q_blk.hardlimit != 0 &&
152
+ dq->q_blk.count > dq->q_blk.hardlimit)
186153 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
187
- if (id != 0 && ihard != 0 && icount > ihard)
154
+
155
+ if (dq->q_ino.hardlimit != 0 &&
156
+ dq->q_ino.count > dq->q_ino.hardlimit)
188157 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
189
- if (id != 0 && rhard != 0 && rcount > rhard)
158
+
159
+ if (dq->q_rtb.hardlimit != 0 &&
160
+ dq->q_rtb.count > dq->q_rtb.hardlimit)
190161 xchk_fblock_set_warning(sc, XFS_DATA_FORK, offset);
162
+
163
+out:
164
+ if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
165
+ return -EFSCORRUPTED;
191166
192167 return 0;
193168 }
....@@ -239,7 +214,7 @@
239214 struct xchk_quota_info sqi;
240215 struct xfs_mount *mp = sc->mp;
241216 struct xfs_quotainfo *qi = mp->m_quotainfo;
242
- uint dqtype;
217
+ xfs_dqtype_t dqtype;
243218 int error = 0;
244219
245220 dqtype = xchk_quota_to_dqtype(sc);