.. | .. |
---|
15 | 15 | #include "xfs_da_format.h" |
---|
16 | 16 | #include "xfs_da_btree.h" |
---|
17 | 17 | #include "xfs_inode.h" |
---|
18 | | -#include "xfs_alloc.h" |
---|
19 | 18 | #include "xfs_attr_remote.h" |
---|
20 | 19 | #include "xfs_trans.h" |
---|
21 | | -#include "xfs_inode_item.h" |
---|
22 | 20 | #include "xfs_bmap.h" |
---|
23 | 21 | #include "xfs_attr.h" |
---|
24 | 22 | #include "xfs_attr_leaf.h" |
---|
25 | | -#include "xfs_error.h" |
---|
26 | 23 | #include "xfs_quota.h" |
---|
27 | | -#include "xfs_trace.h" |
---|
28 | 24 | #include "xfs_dir2.h" |
---|
29 | | -#include "xfs_defer.h" |
---|
| 25 | +#include "xfs_error.h" |
---|
30 | 26 | |
---|
31 | 27 | /* |
---|
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. |
---|
34 | 32 | */ |
---|
35 | 33 | STATIC int |
---|
36 | | -xfs_attr3_leaf_freextent( |
---|
37 | | - struct xfs_trans **trans, |
---|
| 34 | +xfs_attr3_rmt_stale( |
---|
38 | 35 | struct xfs_inode *dp, |
---|
39 | 36 | xfs_dablk_t blkno, |
---|
40 | 37 | int blkcnt) |
---|
41 | 38 | { |
---|
42 | 39 | 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; |
---|
48 | 40 | int nmap; |
---|
49 | 41 | int error; |
---|
50 | 42 | |
---|
.. | .. |
---|
52 | 44 | * Roll through the "value", invalidating the attribute value's |
---|
53 | 45 | * blocks. |
---|
54 | 46 | */ |
---|
55 | | - tblkno = blkno; |
---|
56 | | - tblkcnt = blkcnt; |
---|
57 | | - while (tblkcnt > 0) { |
---|
| 47 | + while (blkcnt > 0) { |
---|
58 | 48 | /* |
---|
59 | 49 | * Try to remember where we decided to put the value. |
---|
60 | 50 | */ |
---|
61 | 51 | nmap = 1; |
---|
62 | | - error = xfs_bmapi_read(dp, (xfs_fileoff_t)tblkno, tblkcnt, |
---|
| 52 | + error = xfs_bmapi_read(dp, (xfs_fileoff_t)blkno, blkcnt, |
---|
63 | 53 | &map, &nmap, XFS_BMAPI_ATTRFORK); |
---|
64 | | - if (error) { |
---|
| 54 | + if (error) |
---|
65 | 55 | 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; |
---|
69 | 58 | |
---|
70 | 59 | /* |
---|
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. |
---|
73 | 63 | */ |
---|
74 | | - if (map.br_startblock != HOLESTARTBLOCK) { |
---|
| 64 | + error = xfs_attr_rmtval_stale(dp, &map, 0); |
---|
| 65 | + if (error) |
---|
| 66 | + return error; |
---|
75 | 67 | |
---|
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; |
---|
96 | 70 | } |
---|
97 | 71 | |
---|
98 | 72 | return 0; |
---|
.. | .. |
---|
106 | 80 | */ |
---|
107 | 81 | STATIC int |
---|
108 | 82 | 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) |
---|
112 | 86 | { |
---|
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; |
---|
116 | 91 | 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; |
---|
125 | 94 | |
---|
126 | | - leaf = bp->b_addr; |
---|
127 | 95 | xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf); |
---|
128 | 96 | |
---|
129 | 97 | /* |
---|
130 | | - * Count the number of "remote" value extents. |
---|
| 98 | + * Find the remote value extents for this leaf and invalidate their |
---|
| 99 | + * incore buffers. |
---|
131 | 100 | */ |
---|
132 | | - count = 0; |
---|
133 | 101 | entry = xfs_attr3_leaf_entryp(leaf); |
---|
134 | 102 | 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; |
---|
141 | 118 | } |
---|
142 | 119 | |
---|
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: |
---|
189 | 122 | return error; |
---|
190 | 123 | } |
---|
191 | 124 | |
---|
.. | .. |
---|
195 | 128 | */ |
---|
196 | 129 | STATIC int |
---|
197 | 130 | 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) |
---|
202 | 135 | { |
---|
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; |
---|
210 | 141 | struct xfs_da3_icnode_hdr ichdr; |
---|
| 142 | + int error, i; |
---|
211 | 143 | |
---|
212 | 144 | /* |
---|
213 | 145 | * Since this code is recursive (gasp!) we must protect ourselves. |
---|
214 | 146 | */ |
---|
215 | 147 | if (level > XFS_DA_NODE_MAXDEPTH) { |
---|
| 148 | + xfs_buf_mark_corrupt(bp); |
---|
216 | 149 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ |
---|
217 | | - return -EIO; |
---|
| 150 | + return -EFSCORRUPTED; |
---|
218 | 151 | } |
---|
219 | 152 | |
---|
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); |
---|
222 | 154 | parent_blkno = bp->b_bn; |
---|
223 | 155 | if (!ichdr.count) { |
---|
224 | 156 | xfs_trans_brelse(*trans, bp); |
---|
225 | 157 | return 0; |
---|
226 | 158 | } |
---|
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); |
---|
229 | 160 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ |
---|
230 | 161 | |
---|
231 | 162 | /* |
---|
.. | .. |
---|
240 | 171 | * traversal of the tree so we may deal with many blocks |
---|
241 | 172 | * before we come back to this one. |
---|
242 | 173 | */ |
---|
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, |
---|
244 | 175 | XFS_ATTR_FORK); |
---|
245 | 176 | if (error) |
---|
246 | 177 | return error; |
---|
.. | .. |
---|
263 | 194 | error = xfs_attr3_leaf_inactive(trans, dp, child_bp); |
---|
264 | 195 | break; |
---|
265 | 196 | default: |
---|
266 | | - error = -EIO; |
---|
| 197 | + xfs_buf_mark_corrupt(child_bp); |
---|
267 | 198 | xfs_trans_brelse(*trans, child_bp); |
---|
| 199 | + error = -EFSCORRUPTED; |
---|
268 | 200 | break; |
---|
269 | 201 | } |
---|
270 | 202 | if (error) |
---|
.. | .. |
---|
273 | 205 | /* |
---|
274 | 206 | * Remove the subsidiary block from the cache and from the log. |
---|
275 | 207 | */ |
---|
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); |
---|
278 | 212 | if (error) |
---|
279 | 213 | return error; |
---|
| 214 | + error = bp->b_error; |
---|
| 215 | + if (error) { |
---|
| 216 | + xfs_trans_brelse(*trans, child_bp); |
---|
| 217 | + return error; |
---|
| 218 | + } |
---|
280 | 219 | xfs_trans_binval(*trans, child_bp); |
---|
281 | 220 | |
---|
282 | 221 | /* |
---|
.. | .. |
---|
284 | 223 | * child block number. |
---|
285 | 224 | */ |
---|
286 | 225 | 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); |
---|
289 | 230 | if (error) |
---|
290 | 231 | 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); |
---|
294 | 235 | xfs_trans_brelse(*trans, bp); |
---|
295 | 236 | } |
---|
296 | 237 | /* |
---|
.. | .. |
---|
315 | 256 | struct xfs_trans **trans, |
---|
316 | 257 | struct xfs_inode *dp) |
---|
317 | 258 | { |
---|
| 259 | + struct xfs_mount *mp = dp->i_mount; |
---|
318 | 260 | struct xfs_da_blkinfo *info; |
---|
319 | 261 | struct xfs_buf *bp; |
---|
320 | 262 | xfs_daddr_t blkno; |
---|
.. | .. |
---|
326 | 268 | * the extents in reverse order the extent containing |
---|
327 | 269 | * block 0 must still be there. |
---|
328 | 270 | */ |
---|
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); |
---|
330 | 272 | if (error) |
---|
331 | 273 | return error; |
---|
332 | 274 | blkno = bp->b_bn; |
---|
.. | .. |
---|
346 | 288 | error = xfs_attr3_leaf_inactive(trans, dp, bp); |
---|
347 | 289 | break; |
---|
348 | 290 | default: |
---|
349 | | - error = -EIO; |
---|
| 291 | + error = -EFSCORRUPTED; |
---|
| 292 | + xfs_buf_mark_corrupt(bp); |
---|
350 | 293 | xfs_trans_brelse(*trans, bp); |
---|
351 | 294 | break; |
---|
352 | 295 | } |
---|
.. | .. |
---|
356 | 299 | /* |
---|
357 | 300 | * Invalidate the incore copy of the root block. |
---|
358 | 301 | */ |
---|
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); |
---|
360 | 304 | if (error) |
---|
361 | 305 | return error; |
---|
| 306 | + error = bp->b_error; |
---|
| 307 | + if (error) { |
---|
| 308 | + xfs_trans_brelse(*trans, bp); |
---|
| 309 | + return error; |
---|
| 310 | + } |
---|
362 | 311 | xfs_trans_binval(*trans, bp); /* remove from cache */ |
---|
363 | 312 | /* |
---|
364 | 313 | * Commit the invalidate and start the next transaction. |
---|
.. | .. |
---|
418 | 367 | * removal below. |
---|
419 | 368 | */ |
---|
420 | 369 | 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) { |
---|
422 | 371 | error = xfs_attr3_root_inactive(&trans, dp); |
---|
423 | 372 | if (error) |
---|
424 | 373 | goto out_cancel; |
---|
.. | .. |
---|
439 | 388 | xfs_trans_cancel(trans); |
---|
440 | 389 | out_destroy_fork: |
---|
441 | 390 | /* 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 | + } |
---|
444 | 396 | if (lock_mode) |
---|
445 | 397 | xfs_iunlock(dp, lock_mode); |
---|
446 | 398 | return error; |
---|