]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: split xfs_da3_node_read
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:46 +0000 (11:29 -0500)
Source kernel commit: 02c57f0a8b07f5c8a393530ff29b2f6fbe17c825

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 <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_attr.c
libxfs/xfs_da_btree.c
libxfs/xfs_da_btree.h

index f360b688fd56223b678f03c495721d41e11f1953..ccf58703de01055533af6f744cc3c2c14d0a6a19 100644 (file)
@@ -1265,10 +1265,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
        ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
        for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
                if (blk->disk_blkno) {
-                       error = xfs_da3_node_read(state->args->trans,
-                                               state->args->dp,
-                                               blk->blkno, blk->disk_blkno,
-                                               &blk->bp, XFS_ATTR_FORK);
+                       error = xfs_da3_node_read_mapped(state->args->trans,
+                                       state->args->dp, blk->disk_blkno,
+                                       &blk->bp, XFS_ATTR_FORK);
                        if (error)
                                return error;
                } else {
@@ -1284,10 +1283,9 @@ xfs_attr_refillstate(xfs_da_state_t *state)
        ASSERT((path->active >= 0) && (path->active < XFS_DA_NODE_MAXDEPTH));
        for (blk = path->blk, level = 0; level < path->active; blk++, level++) {
                if (blk->disk_blkno) {
-                       error = xfs_da3_node_read(state->args->trans,
-                                               state->args->dp,
-                                               blk->blkno, blk->disk_blkno,
-                                               &blk->bp, XFS_ATTR_FORK);
+                       error = xfs_da3_node_read_mapped(state->args->trans,
+                                       state->args->dp, blk->disk_blkno,
+                                       &blk->bp, XFS_ATTR_FORK);
                        if (error)
                                return error;
                } else {
index 00f3709161f3182013622b4196bb3c33ba19c363..63c896641d7750f2275588f4b6a4243bb267fa48 100644 (file)
@@ -328,46 +328,66 @@ const struct xfs_buf_ops xfs_da3_node_buf_ops = {
        .verify_struct = xfs_da3_node_verify_struct,
 };
 
+static int
+xfs_da3_node_set_type(
+       struct xfs_trans        *tp,
+       struct xfs_buf          *bp)
+{
+       struct xfs_da_blkinfo   *info = bp->b_addr;
+
+       switch (be16_to_cpu(info->magic)) {
+       case XFS_DA_NODE_MAGIC:
+       case XFS_DA3_NODE_MAGIC:
+               xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF);
+               return 0;
+       case XFS_ATTR_LEAF_MAGIC:
+       case XFS_ATTR3_LEAF_MAGIC:
+               xfs_trans_buf_set_type(tp, bp, XFS_BLFT_ATTR_LEAF_BUF);
+               return 0;
+       case XFS_DIR2_LEAFN_MAGIC:
+       case XFS_DIR3_LEAFN_MAGIC:
+               xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_LEAFN_BUF);
+               return 0;
+       default:
+               XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, tp->t_mountp,
+                               info, sizeof(*info));
+               xfs_trans_brelse(tp, bp);
+               return -EFSCORRUPTED;
+       }
+}
+
 int
 xfs_da3_node_read(
        struct xfs_trans        *tp,
        struct xfs_inode        *dp,
        xfs_dablk_t             bno,
-       xfs_daddr_t             mappedbno,
        struct xfs_buf          **bpp,
-       int                     which_fork)
+       int                     whichfork)
 {
-       int                     err;
+       int                     error;
 
-       err = xfs_da_read_buf(tp, dp, bno, mappedbno, bpp,
-                                       which_fork, &xfs_da3_node_buf_ops);
-       if (!err && tp && *bpp) {
-               struct xfs_da_blkinfo   *info = (*bpp)->b_addr;
-               int                     type;
+       error = xfs_da_read_buf(tp, dp, bno, -1, bpp, whichfork,
+                       &xfs_da3_node_buf_ops);
+       if (error || !*bpp || !tp)
+               return error;
+       return xfs_da3_node_set_type(tp, *bpp);
+}
 
-               switch (be16_to_cpu(info->magic)) {
-               case XFS_DA_NODE_MAGIC:
-               case XFS_DA3_NODE_MAGIC:
-                       type = XFS_BLFT_DA_NODE_BUF;
-                       break;
-               case XFS_ATTR_LEAF_MAGIC:
-               case XFS_ATTR3_LEAF_MAGIC:
-                       type = XFS_BLFT_ATTR_LEAF_BUF;
-                       break;
-               case XFS_DIR2_LEAFN_MAGIC:
-               case XFS_DIR3_LEAFN_MAGIC:
-                       type = XFS_BLFT_DIR_LEAFN_BUF;
-                       break;
-               default:
-                       XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW,
-                                       tp->t_mountp, info, sizeof(*info));
-                       xfs_trans_brelse(tp, *bpp);
-                       *bpp = NULL;
-                       return -EFSCORRUPTED;
-               }
-               xfs_trans_buf_set_type(tp, *bpp, type);
-       }
-       return err;
+int
+xfs_da3_node_read_mapped(
+       struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
+       xfs_daddr_t             mappedbno,
+       struct xfs_buf          **bpp,
+       int                     whichfork)
+{
+       int                     error;
+
+       error = xfs_da_read_buf(tp, dp, 0, mappedbno, bpp, whichfork,
+                       &xfs_da3_node_buf_ops);
+       if (error || !*bpp || !tp)
+               return error;
+       return xfs_da3_node_set_type(tp, *bpp);
 }
 
 /*========================================================================
@@ -1163,8 +1183,7 @@ xfs_da3_root_join(
         */
        child = be32_to_cpu(oldroothdr.btree[0].before);
        ASSERT(child != 0);
-       error = xfs_da3_node_read(args->trans, dp, child, -1, &bp,
-                                            args->whichfork);
+       error = xfs_da3_node_read(args->trans, dp, child, &bp, args->whichfork);
        if (error)
                return error;
        xfs_da_blkinfo_onlychild_validate(bp->b_addr, oldroothdr.level);
@@ -1278,8 +1297,8 @@ xfs_da3_node_toosmall(
                        blkno = nodehdr.back;
                if (blkno == 0)
                        continue;
-               error = xfs_da3_node_read(state->args->trans, dp,
-                                       blkno, -1, &bp, state->args->whichfork);
+               error = xfs_da3_node_read(state->args->trans, dp, blkno, &bp,
+                               state->args->whichfork);
                if (error)
                        return error;
 
@@ -1567,7 +1586,7 @@ xfs_da3_node_lookup_int(
                 */
                blk->blkno = blkno;
                error = xfs_da3_node_read(args->trans, args->dp, blkno,
-                                       -1, &blk->bp, args->whichfork);
+                                       &blk->bp, args->whichfork);
                if (error) {
                        blk->blkno = 0;
                        state->path.active--;
@@ -1801,7 +1820,7 @@ xfs_da3_blk_link(
                if (old_info->back) {
                        error = xfs_da3_node_read(args->trans, dp,
                                                be32_to_cpu(old_info->back),
-                                               -1, &bp, args->whichfork);
+                                               &bp, args->whichfork);
                        if (error)
                                return error;
                        ASSERT(bp != NULL);
@@ -1822,7 +1841,7 @@ xfs_da3_blk_link(
                if (old_info->forw) {
                        error = xfs_da3_node_read(args->trans, dp,
                                                be32_to_cpu(old_info->forw),
-                                               -1, &bp, args->whichfork);
+                                               &bp, args->whichfork);
                        if (error)
                                return error;
                        ASSERT(bp != NULL);
@@ -1881,7 +1900,7 @@ xfs_da3_blk_unlink(
                if (drop_info->back) {
                        error = xfs_da3_node_read(args->trans, args->dp,
                                                be32_to_cpu(drop_info->back),
-                                               -1, &bp, args->whichfork);
+                                               &bp, args->whichfork);
                        if (error)
                                return error;
                        ASSERT(bp != NULL);
@@ -1898,7 +1917,7 @@ xfs_da3_blk_unlink(
                if (drop_info->forw) {
                        error = xfs_da3_node_read(args->trans, args->dp,
                                                be32_to_cpu(drop_info->forw),
-                                               -1, &bp, args->whichfork);
+                                               &bp, args->whichfork);
                        if (error)
                                return error;
                        ASSERT(bp != NULL);
@@ -1982,7 +2001,7 @@ xfs_da3_path_shift(
                /*
                 * Read the next child block into a local buffer.
                 */
-               error = xfs_da3_node_read(args->trans, dp, blkno, -1, &bp,
+               error = xfs_da3_node_read(args->trans, dp, blkno, &bp,
                                          args->whichfork);
                if (error)
                        return error;
@@ -2260,7 +2279,7 @@ xfs_da3_swap_lastblock(
         * Read the last block in the btree space.
         */
        last_blkno = (xfs_dablk_t)lastoff - args->geo->fsbcount;
-       error = xfs_da3_node_read(tp, dp, last_blkno, -1, &last_buf, w);
+       error = xfs_da3_node_read(tp, dp, last_blkno, &last_buf, w);
        if (error)
                return error;
        /*
@@ -2297,7 +2316,7 @@ xfs_da3_swap_lastblock(
         * If the moved block has a left sibling, fix up the pointers.
         */
        if ((sib_blkno = be32_to_cpu(dead_info->back))) {
-               error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
+               error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
                if (error)
                        goto done;
                sib_info = sib_buf->b_addr;
@@ -2317,7 +2336,7 @@ xfs_da3_swap_lastblock(
         * If the moved block has a right sibling, fix up the pointers.
         */
        if ((sib_blkno = be32_to_cpu(dead_info->forw))) {
-               error = xfs_da3_node_read(tp, dp, sib_blkno, -1, &sib_buf, w);
+               error = xfs_da3_node_read(tp, dp, sib_blkno, &sib_buf, w);
                if (error)
                        goto done;
                sib_info = sib_buf->b_addr;
@@ -2339,7 +2358,7 @@ xfs_da3_swap_lastblock(
         * Walk down the tree looking for the parent of the moved block.
         */
        for (;;) {
-               error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
+               error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
                if (error)
                        goto done;
                par_node = par_buf->b_addr;
@@ -2385,7 +2404,7 @@ xfs_da3_swap_lastblock(
                        error = -EFSCORRUPTED;
                        goto done;
                }
-               error = xfs_da3_node_read(tp, dp, par_blkno, -1, &par_buf, w);
+               error = xfs_da3_node_read(tp, dp, par_blkno, &par_buf, w);
                if (error)
                        goto done;
                par_node = par_buf->b_addr;
index a8c69c2125945323da3a51b861309802208932e9..25bcbfa9016fd2802a8ecc323d8fbb06f61ecbe6 100644 (file)
@@ -188,8 +188,10 @@ int        xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
 int    xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
                                       xfs_da_state_blk_t *new_blk);
 int    xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
-                        xfs_dablk_t bno, xfs_daddr_t mappedbno,
-                        struct xfs_buf **bpp, int which_fork);
+                       xfs_dablk_t bno, struct xfs_buf **bpp, int whichfork);
+int    xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp,
+                       xfs_daddr_t mappedbno, struct xfs_buf **bpp,
+                       int whichfork);
 
 /*
  * Utility routines.