Skip to content

Commit 02c57f0

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: split xfs_da3_node_read
Split xfs_da3_node_read into one variant that always looks up the daddr and doesn't accept holes, and one that already has a daddr at hand. This is in preparation of splitting up xfs_da_read_buf in a similar way. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent f3fcb31 commit 02c57f0

File tree

5 files changed

+82
-63
lines changed

5 files changed

+82
-63
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,10 +1266,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
12661266
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
12671267
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
12681268
if (blk->disk_blkno) {
1269-
error = xfs_da3_node_read(state->args->trans,
1270-
state->args->dp,
1271-
blk->blkno, blk->disk_blkno,
1272-
&blk->bp, XFS_ATTR_FORK);
1269+
error = xfs_da3_node_read_mapped(state->args->trans,
1270+
state->args->dp, blk->disk_blkno,
1271+
&blk->bp, XFS_ATTR_FORK);
12731272
if (error)
12741273
return error;
12751274
} else {
@@ -1285,10 +1284,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
12851284
ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
12861285
for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
12871286
if (blk->disk_blkno) {
1288-
error = xfs_da3_node_read(state->args->trans,
1289-
state->args->dp,
1290-
blk->blkno, blk->disk_blkno,
1291-
&blk->bp, XFS_ATTR_FORK);
1287+
error = xfs_da3_node_read_mapped(state->args->trans,
1288+
state->args->dp, blk->disk_blkno,
1289+
&blk->bp, XFS_ATTR_FORK);
12921290
if (error)
12931291
return error;
12941292
} else {

fs/xfs/libxfs/xfs_da_btree.c

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -331,46 +331,66 @@ const struct xfs_buf_ops xfs_da3_node_buf_ops = {
331331
.verify_struct = xfs_da3_node_verify_struct,
332332
};
333333

334+
static int
335+
xfs_da3_node_set_type(
336+
struct xfs_trans *tp,
337+
struct xfs_buf *bp)
338+
{
339+
struct xfs_da_blkinfo *info = bp->b_addr;
340+
341+
switch (be16_to_cpu(info->magic)) {
342+
case XFS_DA_NODE_MAGIC:
343+
case XFS_DA3_NODE_MAGIC:
344+
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF);
345+
return 0;
346+
case XFS_ATTR_LEAF_MAGIC:
347+
case XFS_ATTR3_LEAF_MAGIC:
348+
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_ATTR_LEAF_BUF);
349+
return 0;
350+
case XFS_DIR2_LEAFN_MAGIC:
351+
case XFS_DIR3_LEAFN_MAGIC:
352+
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_LEAFN_BUF);
353+
return 0;
354+
default:
355+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, tp->t_mountp,
356+
info, sizeof(*info));
357+
xfs_trans_brelse(tp, bp);
358+
return -EFSCORRUPTED;
359+
}
360+
}
361+
334362
int
335363
xfs_da3_node_read(
336364
struct xfs_trans *tp,
337365
struct xfs_inode *dp,
338366
xfs_dablk_t bno,
339-
xfs_daddr_t mappedbno,
340367
struct xfs_buf **bpp,
341-
int which_fork)
368+
int whichfork)
342369
{
343-
int err;
370+
int error;
344371

345-
err = xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
346-
which_fork, &xfs_da3_node_buf_ops);
347-
if (!err && tp && *bpp) {
348-
struct xfs_da_blkinfo *info = (*bpp)->b_addr;
349-
int type;
372+
error = xfs_da_read_buf(tp, dp, bno, -1, bpp, whichfork,
373+
&xfs_da3_node_buf_ops);
374+
if (error || !*bpp || !tp)
375+
return error;
376+
return xfs_da3_node_set_type(tp, *bpp);
377+
}
350378

351-
switch (be16_to_cpu(info->magic)) {
352-
case XFS_DA_NODE_MAGIC:
353-
case XFS_DA3_NODE_MAGIC:
354-
type = XFS_BLFT_DA_NODE_BUF;
355-
break;
356-
case XFS_ATTR_LEAF_MAGIC:
357-
case XFS_ATTR3_LEAF_MAGIC:
358-
type = XFS_BLFT_ATTR_LEAF_BUF;
359-
break;
360-
case XFS_DIR2_LEAFN_MAGIC:
361-
case XFS_DIR3_LEAFN_MAGIC:
362-
type = XFS_BLFT_DIR_LEAFN_BUF;
363-
break;
364-
default:
365-
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW,
366-
tp->t_mountp, info, sizeof(*info));
367-
xfs_trans_brelse(tp, *bpp);
368-
*bpp = NULL;
369-
return -EFSCORRUPTED;
370-
}
371-
xfs_trans_buf_set_type(tp, *bpp, type);
372-
}
373-
return err;
379+
int
380+
xfs_da3_node_read_mapped(
381+
struct xfs_trans *tp,
382+
struct xfs_inode *dp,
383+
xfs_daddr_t mappedbno,
384+
struct xfs_buf **bpp,
385+
int whichfork)
386+
{
387+
int error;
388+
389+
error = xfs_da_read_buf(tp, dp, 0, mappedbno, bpp, whichfork,
390+
&xfs_da3_node_buf_ops);
391+
if (error || !*bpp || !tp)
392+
return error;
393+
return xfs_da3_node_set_type(tp, *bpp);
374394
}
375395

376396
/*========================================================================
@@ -1166,8 +1186,7 @@ xfs_da3_root_join(
11661186
*/
11671187
child = be32_to_cpu(oldroothdr.btree[0].before);
11681188
ASSERT(child != 0);
1169-
error = xfs_da3_node_read(args->trans, dp, child, -1, &bp,
1170-
args->whichfork);
1189+
error = xfs_da3_node_read(args->trans, dp, child, &bp, args->whichfork);
11711190
if (error)
11721191
return error;
11731192
xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level);
@@ -1281,8 +1300,8 @@ xfs_da3_node_toosmall(
12811300
blkno = nodehdr.back;
12821301
if (blkno == 0)
12831302
continue;
1284-
error = xfs_da3_node_read(state->args->trans, dp,
1285-
blkno, -1, &bp, state->args->whichfork);
1303+
error = xfs_da3_node_read(state->args->trans, dp, blkno, &bp,
1304+
state->args->whichfork);
12861305
if (error)
12871306
return error;
12881307

@@ -1570,7 +1589,7 @@ xfs_da3_node_lookup_int(
15701589
*/
15711590
blk->blkno = blkno;
15721591
error = xfs_da3_node_read(args->trans, args->dp, blkno,
1573-
-1, &blk->bp, args->whichfork);
1592+
&blk->bp, args->whichfork);
15741593
if (error) {
15751594
blk->blkno = 0;
15761595
state->path.active--;
@@ -1804,7 +1823,7 @@ xfs_da3_blk_link(
18041823
if (old_info->back) {
18051824
error = xfs_da3_node_read(args->trans, dp,
18061825
be32_to_cpu(old_info->back),
1807-
-1, &bp, args->whichfork);
1826+
&bp, args->whichfork);
18081827
if (error)
18091828
return error;
18101829
ASSERT(bp != NULL);
@@ -1825,7 +1844,7 @@ xfs_da3_blk_link(
18251844
if (old_info->forw) {
18261845
error = xfs_da3_node_read(args->trans, dp,
18271846
be32_to_cpu(old_info->forw),
1828-
-1, &bp, args->whichfork);
1847+
&bp, args->whichfork);
18291848
if (error)
18301849
return error;
18311850
ASSERT(bp != NULL);
@@ -1884,7 +1903,7 @@ xfs_da3_blk_unlink(
18841903
if (drop_info->back) {
18851904
error = xfs_da3_node_read(args->trans, args->dp,
18861905
be32_to_cpu(drop_info->back),
1887-
-1, &bp, args->whichfork);
1906+
&bp, args->whichfork);
18881907
if (error)
18891908
return error;
18901909
ASSERT(bp != NULL);
@@ -1901,7 +1920,7 @@ xfs_da3_blk_unlink(
19011920
if (drop_info->forw) {
19021921
error = xfs_da3_node_read(args->trans, args->dp,
19031922
be32_to_cpu(drop_info->forw),
1904-
-1, &bp, args->whichfork);
1923+
&bp, args->whichfork);
19051924
if (error)
19061925
return error;
19071926
ASSERT(bp != NULL);
@@ -1985,7 +2004,7 @@ xfs_da3_path_shift(
19852004
/*
19862005
* Read the next child block into a local buffer.
19872006
*/
1988-
error = xfs_da3_node_read(args->trans, dp, blkno, -1, &bp,
2007+
error = xfs_da3_node_read(args->trans, dp, blkno, &bp,
19892008
args->whichfork);
19902009
if (error)
19912010
return error;
@@ -2263,7 +2282,7 @@ xfs_da3_swap_lastblock(
22632282
* Read the last block in the btree space.
22642283
*/
22652284
last_blkno = (xfs_dablk_t)lastoff - args->geo->fsbcount;
2266-
error = xfs_da3_node_read(tp, dp, last_blkno, -1, &last_buf, w);
2285+
error = xfs_da3_node_read(tp, dp, last_blkno, &last_buf, w);
22672286
if (error)
22682287
return error;
22692288
/*
@@ -2300,7 +2319,7 @@ xfs_da3_swap_lastblock(
23002319
* If the moved block has a left sibling, fix up the pointers.
23012320
*/
23022321
if ((sib_blkno = be32_to_cpu(dead_info->back))) {
2303-
error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
2322+
error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
23042323
if (error)
23052324
goto done;
23062325
sib_info = sib_buf->b_addr;
@@ -2320,7 +2339,7 @@ xfs_da3_swap_lastblock(
23202339
* If the moved block has a right sibling, fix up the pointers.
23212340
*/
23222341
if ((sib_blkno = be32_to_cpu(dead_info->forw))) {
2323-
error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
2342+
error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
23242343
if (error)
23252344
goto done;
23262345
sib_info = sib_buf->b_addr;
@@ -2342,7 +2361,7 @@ xfs_da3_swap_lastblock(
23422361
* Walk down the tree looking for the parent of the moved block.
23432362
*/
23442363
for (;;) {
2345-
error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
2364+
error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
23462365
if (error)
23472366
goto done;
23482367
par_node = par_buf->b_addr;
@@ -2388,7 +2407,7 @@ xfs_da3_swap_lastblock(
23882407
error = -EFSCORRUPTED;
23892408
goto done;
23902409
}
2391-
error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
2410+
error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
23922411
if (error)
23932412
goto done;
23942413
par_node = par_buf->b_addr;

fs/xfs/libxfs/xfs_da_btree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
188188
int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
189189
xfs_da_state_blk_t *new_blk);
190190
int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
191-
xfs_dablk_t bno, xfs_daddr_t mappedbno,
192-
struct xfs_buf **bpp, int which_fork);
191+
xfs_dablk_t bno, struct xfs_buf **bpp, int whichfork);
192+
int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp,
193+
xfs_daddr_t mappedbno, struct xfs_buf **bpp,
194+
int whichfork);
193195

194196
/*
195197
* Utility routines.

fs/xfs/xfs_attr_inactive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ xfs_attr3_node_inactive(
233233
* traversal of the tree so we may deal with many blocks
234234
* before we come back to this one.
235235
*/
236-
error = xfs_da3_node_read(*trans, dp, child_fsb, -1, &child_bp,
236+
error = xfs_da3_node_read(*trans, dp, child_fsb, &child_bp,
237237
XFS_ATTR_FORK);
238238
if (error)
239239
return error;
@@ -280,8 +280,8 @@ xfs_attr3_node_inactive(
280280
if (i + 1 < ichdr.count) {
281281
struct xfs_da3_icnode_hdr phdr;
282282

283-
error = xfs_da3_node_read(*trans, dp, 0, parent_blkno,
284-
&bp, XFS_ATTR_FORK);
283+
error = xfs_da3_node_read_mapped(*trans, dp,
284+
parent_blkno, &bp, XFS_ATTR_FORK);
285285
if (error)
286286
return error;
287287
xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr,
@@ -322,7 +322,7 @@ xfs_attr3_root_inactive(
322322
* the extents in reverse order the extent containing
323323
* block 0 must still be there.
324324
*/
325-
error = xfs_da3_node_read(*trans, dp, 0, -1, &bp, XFS_ATTR_FORK);
325+
error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK);
326326
if (error)
327327
return error;
328328
blkno = bp->b_bn;

fs/xfs/xfs_attr_list.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ xfs_attr_node_list_lookup(
223223
ASSERT(*pbp == NULL);
224224
cursor->blkno = 0;
225225
for (;;) {
226-
error = xfs_da3_node_read(tp, dp, cursor->blkno, -1, &bp,
226+
error = xfs_da3_node_read(tp, dp, cursor->blkno, &bp,
227227
XFS_ATTR_FORK);
228228
if (error)
229229
return error;
@@ -309,8 +309,8 @@ xfs_attr_node_list(
309309
*/
310310
bp = NULL;
311311
if (cursor->blkno > 0) {
312-
error = xfs_da3_node_read(context->tp, dp, cursor->blkno, -1,
313-
&bp, XFS_ATTR_FORK);
312+
error = xfs_da3_node_read(context->tp, dp, cursor->blkno, &bp,
313+
XFS_ATTR_FORK);
314314
if ((error != 0) && (error != -EFSCORRUPTED))
315315
return error;
316316
if (bp) {

0 commit comments

Comments
 (0)