hc
2024-05-11 297b60346df8beafee954a0fd7c2d64f33f3b9bc
kernel/fs/xfs/xfs_attr_inactive.c
....@@ -15,36 +15,28 @@
1515 #include "xfs_da_format.h"
1616 #include "xfs_da_btree.h"
1717 #include "xfs_inode.h"
18
-#include "xfs_alloc.h"
1918 #include "xfs_attr_remote.h"
2019 #include "xfs_trans.h"
21
-#include "xfs_inode_item.h"
2220 #include "xfs_bmap.h"
2321 #include "xfs_attr.h"
2422 #include "xfs_attr_leaf.h"
25
-#include "xfs_error.h"
2623 #include "xfs_quota.h"
27
-#include "xfs_trace.h"
2824 #include "xfs_dir2.h"
29
-#include "xfs_defer.h"
25
+#include "xfs_error.h"
3026
3127 /*
32
- * Look at all the extents for this logical region,
33
- * invalidate any buffers that are incore/in transactions.
28
+ * Invalidate any incore buffers associated with this remote attribute value
29
+ * extent. We never log remote attribute value buffers, which means that they
30
+ * won't be attached to a transaction and are therefore safe to mark stale.
31
+ * The actual bunmapi will be taken care of later.
3432 */
3533 STATIC int
36
-xfs_attr3_leaf_freextent(
37
- struct xfs_trans **trans,
34
+xfs_attr3_rmt_stale(
3835 struct xfs_inode *dp,
3936 xfs_dablk_t blkno,
4037 int blkcnt)
4138 {
4239 struct xfs_bmbt_irec map;
43
- struct xfs_buf *bp;
44
- xfs_dablk_t tblkno;
45
- xfs_daddr_t dblkno;
46
- int tblkcnt;
47
- int dblkcnt;
4840 int nmap;
4941 int error;
5042
....@@ -52,47 +44,29 @@
5244 * Roll through the "value", invalidating the attribute value's
5345 * blocks.
5446 */
55
- tblkno = blkno;
56
- tblkcnt = blkcnt;
57
- while (tblkcnt > 0) {
47
+ while (blkcnt > 0) {
5848 /*
5949 * Try to remember where we decided to put the value.
6050 */
6151 nmap = 1;
62
- error = xfs_bmapi_read(dp, (xfs_fileoff_t)tblkno, tblkcnt,
52
+ error = xfs_bmapi_read(dp, (xfs_fileoff_t)blkno, blkcnt,
6353 &map, &nmap, XFS_BMAPI_ATTRFORK);
64
- if (error) {
54
+ if (error)
6555 return error;
66
- }
67
- ASSERT(nmap == 1);
68
- ASSERT(map.br_startblock != DELAYSTARTBLOCK);
56
+ if (XFS_IS_CORRUPT(dp->i_mount, nmap != 1))
57
+ return -EFSCORRUPTED;
6958
7059 /*
71
- * If it's a hole, these are already unmapped
72
- * so there's nothing to invalidate.
60
+ * Mark any incore buffers for the remote value as stale. We
61
+ * never log remote attr value buffers, so the buffer should be
62
+ * easy to kill.
7363 */
74
- if (map.br_startblock != HOLESTARTBLOCK) {
64
+ error = xfs_attr_rmtval_stale(dp, &map, 0);
65
+ if (error)
66
+ return error;
7567
76
- dblkno = XFS_FSB_TO_DADDR(dp->i_mount,
77
- map.br_startblock);
78
- dblkcnt = XFS_FSB_TO_BB(dp->i_mount,
79
- map.br_blockcount);
80
- bp = xfs_trans_get_buf(*trans,
81
- dp->i_mount->m_ddev_targp,
82
- dblkno, dblkcnt, 0);
83
- if (!bp)
84
- return -ENOMEM;
85
- xfs_trans_binval(*trans, bp);
86
- /*
87
- * Roll to next transaction.
88
- */
89
- error = xfs_trans_roll_inode(trans, dp);
90
- if (error)
91
- return error;
92
- }
93
-
94
- tblkno += map.br_blockcount;
95
- tblkcnt -= map.br_blockcount;
68
+ blkno += map.br_blockcount;
69
+ blkcnt -= map.br_blockcount;
9670 }
9771
9872 return 0;
....@@ -106,86 +80,45 @@
10680 */
10781 STATIC int
10882 xfs_attr3_leaf_inactive(
109
- struct xfs_trans **trans,
110
- struct xfs_inode *dp,
111
- struct xfs_buf *bp)
83
+ struct xfs_trans **trans,
84
+ struct xfs_inode *dp,
85
+ struct xfs_buf *bp)
11286 {
113
- struct xfs_attr_leafblock *leaf;
114
- struct xfs_attr3_icleaf_hdr ichdr;
115
- struct xfs_attr_leaf_entry *entry;
87
+ struct xfs_attr3_icleaf_hdr ichdr;
88
+ struct xfs_mount *mp = bp->b_mount;
89
+ struct xfs_attr_leafblock *leaf = bp->b_addr;
90
+ struct xfs_attr_leaf_entry *entry;
11691 struct xfs_attr_leaf_name_remote *name_rmt;
117
- struct xfs_attr_inactive_list *list;
118
- struct xfs_attr_inactive_list *lp;
119
- int error;
120
- int count;
121
- int size;
122
- int tmp;
123
- int i;
124
- struct xfs_mount *mp = bp->b_target->bt_mount;
92
+ int error = 0;
93
+ int i;
12594
126
- leaf = bp->b_addr;
12795 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
12896
12997 /*
130
- * Count the number of "remote" value extents.
98
+ * Find the remote value extents for this leaf and invalidate their
99
+ * incore buffers.
131100 */
132
- count = 0;
133101 entry = xfs_attr3_leaf_entryp(leaf);
134102 for (i = 0; i < ichdr.count; entry++, i++) {
135
- if (be16_to_cpu(entry->nameidx) &&
136
- ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
137
- name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
138
- if (name_rmt->valueblk)
139
- count++;
140
- }
103
+ int blkcnt;
104
+
105
+ if (!entry->nameidx || (entry->flags & XFS_ATTR_LOCAL))
106
+ continue;
107
+
108
+ name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
109
+ if (!name_rmt->valueblk)
110
+ continue;
111
+
112
+ blkcnt = xfs_attr3_rmt_blocks(dp->i_mount,
113
+ be32_to_cpu(name_rmt->valuelen));
114
+ error = xfs_attr3_rmt_stale(dp,
115
+ be32_to_cpu(name_rmt->valueblk), blkcnt);
116
+ if (error)
117
+ goto err;
141118 }
142119
143
- /*
144
- * If there are no "remote" values, we're done.
145
- */
146
- if (count == 0) {
147
- xfs_trans_brelse(*trans, bp);
148
- return 0;
149
- }
150
-
151
- /*
152
- * Allocate storage for a list of all the "remote" value extents.
153
- */
154
- size = count * sizeof(xfs_attr_inactive_list_t);
155
- list = kmem_alloc(size, KM_SLEEP);
156
-
157
- /*
158
- * Identify each of the "remote" value extents.
159
- */
160
- lp = list;
161
- entry = xfs_attr3_leaf_entryp(leaf);
162
- for (i = 0; i < ichdr.count; entry++, i++) {
163
- if (be16_to_cpu(entry->nameidx) &&
164
- ((entry->flags & XFS_ATTR_LOCAL) == 0)) {
165
- name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
166
- if (name_rmt->valueblk) {
167
- lp->valueblk = be32_to_cpu(name_rmt->valueblk);
168
- lp->valuelen = xfs_attr3_rmt_blocks(dp->i_mount,
169
- be32_to_cpu(name_rmt->valuelen));
170
- lp++;
171
- }
172
- }
173
- }
174
- xfs_trans_brelse(*trans, bp); /* unlock for trans. in freextent() */
175
-
176
- /*
177
- * Invalidate each of the "remote" value extents.
178
- */
179
- error = 0;
180
- for (lp = list, i = 0; i < count; i++, lp++) {
181
- tmp = xfs_attr3_leaf_freextent(trans, dp,
182
- lp->valueblk, lp->valuelen);
183
-
184
- if (error == 0)
185
- error = tmp; /* save only the 1st errno */
186
- }
187
-
188
- kmem_free(list);
120
+ xfs_trans_brelse(*trans, bp);
121
+err:
189122 return error;
190123 }
191124
....@@ -195,37 +128,35 @@
195128 */
196129 STATIC int
197130 xfs_attr3_node_inactive(
198
- struct xfs_trans **trans,
199
- struct xfs_inode *dp,
200
- struct xfs_buf *bp,
201
- int level)
131
+ struct xfs_trans **trans,
132
+ struct xfs_inode *dp,
133
+ struct xfs_buf *bp,
134
+ int level)
202135 {
203
- xfs_da_blkinfo_t *info;
204
- xfs_da_intnode_t *node;
205
- xfs_dablk_t child_fsb;
206
- xfs_daddr_t parent_blkno, child_blkno;
207
- int error, i;
208
- struct xfs_buf *child_bp;
209
- struct xfs_da_node_entry *btree;
136
+ struct xfs_mount *mp = dp->i_mount;
137
+ struct xfs_da_blkinfo *info;
138
+ xfs_dablk_t child_fsb;
139
+ xfs_daddr_t parent_blkno, child_blkno;
140
+ struct xfs_buf *child_bp;
210141 struct xfs_da3_icnode_hdr ichdr;
142
+ int error, i;
211143
212144 /*
213145 * Since this code is recursive (gasp!) we must protect ourselves.
214146 */
215147 if (level > XFS_DA_NODE_MAXDEPTH) {
148
+ xfs_buf_mark_corrupt(bp);
216149 xfs_trans_brelse(*trans, bp); /* no locks for later trans */
217
- return -EIO;
150
+ return -EFSCORRUPTED;
218151 }
219152
220
- node = bp->b_addr;
221
- dp->d_ops->node_hdr_from_disk(&ichdr, node);
153
+ xfs_da3_node_hdr_from_disk(dp->i_mount, &ichdr, bp->b_addr);
222154 parent_blkno = bp->b_bn;
223155 if (!ichdr.count) {
224156 xfs_trans_brelse(*trans, bp);
225157 return 0;
226158 }
227
- btree = dp->d_ops->node_tree_p(node);
228
- child_fsb = be32_to_cpu(btree[0].before);
159
+ child_fsb = be32_to_cpu(ichdr.btree[0].before);
229160 xfs_trans_brelse(*trans, bp); /* no locks for later trans */
230161
231162 /*
....@@ -240,7 +171,7 @@
240171 * traversal of the tree so we may deal with many blocks
241172 * before we come back to this one.
242173 */
243
- error = xfs_da3_node_read(*trans, dp, child_fsb, -1, &child_bp,
174
+ error = xfs_da3_node_read(*trans, dp, child_fsb, &child_bp,
244175 XFS_ATTR_FORK);
245176 if (error)
246177 return error;
....@@ -263,8 +194,9 @@
263194 error = xfs_attr3_leaf_inactive(trans, dp, child_bp);
264195 break;
265196 default:
266
- error = -EIO;
197
+ xfs_buf_mark_corrupt(child_bp);
267198 xfs_trans_brelse(*trans, child_bp);
199
+ error = -EFSCORRUPTED;
268200 break;
269201 }
270202 if (error)
....@@ -273,10 +205,17 @@
273205 /*
274206 * Remove the subsidiary block from the cache and from the log.
275207 */
276
- error = xfs_da_get_buf(*trans, dp, 0, child_blkno, &child_bp,
277
- XFS_ATTR_FORK);
208
+ error = xfs_trans_get_buf(*trans, mp->m_ddev_targp,
209
+ child_blkno,
210
+ XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0,
211
+ &child_bp);
278212 if (error)
279213 return error;
214
+ error = bp->b_error;
215
+ if (error) {
216
+ xfs_trans_brelse(*trans, child_bp);
217
+ return error;
218
+ }
280219 xfs_trans_binval(*trans, child_bp);
281220
282221 /*
....@@ -284,13 +223,15 @@
284223 * child block number.
285224 */
286225 if (i + 1 < ichdr.count) {
287
- error = xfs_da3_node_read(*trans, dp, 0, parent_blkno,
288
- &bp, XFS_ATTR_FORK);
226
+ struct xfs_da3_icnode_hdr phdr;
227
+
228
+ error = xfs_da3_node_read_mapped(*trans, dp,
229
+ parent_blkno, &bp, XFS_ATTR_FORK);
289230 if (error)
290231 return error;
291
- node = bp->b_addr;
292
- btree = dp->d_ops->node_tree_p(node);
293
- child_fsb = be32_to_cpu(btree[i + 1].before);
232
+ xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
233
+ bp->b_addr);
234
+ child_fsb = be32_to_cpu(phdr.btree[i + 1].before);
294235 xfs_trans_brelse(*trans, bp);
295236 }
296237 /*
....@@ -315,6 +256,7 @@
315256 struct xfs_trans **trans,
316257 struct xfs_inode *dp)
317258 {
259
+ struct xfs_mount *mp = dp->i_mount;
318260 struct xfs_da_blkinfo *info;
319261 struct xfs_buf *bp;
320262 xfs_daddr_t blkno;
....@@ -326,7 +268,7 @@
326268 * the extents in reverse order the extent containing
327269 * block 0 must still be there.
328270 */
329
- error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK);
271
+ error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK);
330272 if (error)
331273 return error;
332274 blkno = bp->b_bn;
....@@ -346,7 +288,8 @@
346288 error = xfs_attr3_leaf_inactive(trans, dp, bp);
347289 break;
348290 default:
349
- error = -EIO;
291
+ error = -EFSCORRUPTED;
292
+ xfs_buf_mark_corrupt(bp);
350293 xfs_trans_brelse(*trans, bp);
351294 break;
352295 }
....@@ -356,9 +299,15 @@
356299 /*
357300 * Invalidate the incore copy of the root block.
358301 */
359
- error = xfs_da_get_buf(*trans, dp, 0, blkno, &bp, XFS_ATTR_FORK);
302
+ error = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno,
303
+ XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0, &bp);
360304 if (error)
361305 return error;
306
+ error = bp->b_error;
307
+ if (error) {
308
+ xfs_trans_brelse(*trans, bp);
309
+ return error;
310
+ }
362311 xfs_trans_binval(*trans, bp); /* remove from cache */
363312 /*
364313 * Commit the invalidate and start the next transaction.
....@@ -418,7 +367,7 @@
418367 * removal below.
419368 */
420369 if (xfs_inode_hasattr(dp) &&
421
- dp->i_d.di_aformat != XFS_DINODE_FMT_LOCAL) {
370
+ dp->i_afp->if_format != XFS_DINODE_FMT_LOCAL) {
422371 error = xfs_attr3_root_inactive(&trans, dp);
423372 if (error)
424373 goto out_cancel;
....@@ -439,8 +388,11 @@
439388 xfs_trans_cancel(trans);
440389 out_destroy_fork:
441390 /* kill the in-core attr fork before we drop the inode lock */
442
- if (dp->i_afp)
443
- xfs_idestroy_fork(dp, XFS_ATTR_FORK);
391
+ if (dp->i_afp) {
392
+ xfs_idestroy_fork(dp->i_afp);
393
+ kmem_cache_free(xfs_ifork_zone, dp->i_afp);
394
+ dp->i_afp = NULL;
395
+ }
444396 if (lock_mode)
445397 xfs_iunlock(dp, lock_mode);
446398 return error;