]> Pileus Git - ~andy/linux/blobdiff - fs/xfs/xfs_attr.c
xfs: factor and verify attr leaf reads
[~andy/linux] / fs / xfs / xfs_attr.c
index 0ca1f0be62d262f8eb23873f48c81ab864995fe8..d644915367e3fbf7a4188cfa0f141c542f6f28d5 100644 (file)
@@ -903,11 +903,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
         */
        dp = args->dp;
        args->blkno = 0;
-       error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
-                                            XFS_ATTR_FORK);
+       error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
        if (error)
-               return(error);
-       ASSERT(bp != NULL);
+               return error;
 
        /*
         * Look up the given attribute in the leaf block.  Figure out if
@@ -1031,12 +1029,12 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                 * Read in the block containing the "old" attr, then
                 * remove the "old" attr from that block (neat, huh!)
                 */
-               error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1,
-                                                    &bp, XFS_ATTR_FORK);
+               error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno,
+                                          -1, &bp);
                if (error)
-                       return(error);
-               ASSERT(bp != NULL);
-               (void)xfs_attr_leaf_remove(bp, args);
+                       return error;
+
+               xfs_attr_leaf_remove(bp, args);
 
                /*
                 * If the result is small enough, shrink it all into the inode.
@@ -1100,20 +1098,17 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
         */
        dp = args->dp;
        args->blkno = 0;
-       error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
-                                            XFS_ATTR_FORK);
-       if (error) {
-               return(error);
-       }
+       error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
+       if (error)
+               return error;
 
-       ASSERT(bp != NULL);
        error = xfs_attr_leaf_lookup_int(bp, args);
        if (error == ENOATTR) {
                xfs_trans_brelse(args->trans, bp);
                return(error);
        }
 
-       (void)xfs_attr_leaf_remove(bp, args);
+       xfs_attr_leaf_remove(bp, args);
 
        /*
         * If the result is small enough, shrink it all into the inode.
@@ -1155,12 +1150,12 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
        struct xfs_buf *bp;
        int error;
 
+       trace_xfs_attr_leaf_get(args);
+
        args->blkno = 0;
-       error = xfs_da_read_buf(args->trans, args->dp, args->blkno, -1, &bp,
-                                            XFS_ATTR_FORK);
+       error = xfs_attr_leaf_read(args->trans, args->dp, args->blkno, -1, &bp);
        if (error)
-               return(error);
-       ASSERT(bp != NULL);
+               return error;
 
        error = xfs_attr_leaf_lookup_int(bp, args);
        if (error != EEXIST)  {
@@ -1181,22 +1176,15 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
 STATIC int
 xfs_attr_leaf_list(xfs_attr_list_context_t *context)
 {
-       xfs_attr_leafblock_t *leaf;
        int error;
        struct xfs_buf *bp;
 
+       trace_xfs_attr_leaf_list(context);
+
        context->cursor->blkno = 0;
-       error = xfs_da_read_buf(NULL, context->dp, 0, -1, &bp, XFS_ATTR_FORK);
+       error = xfs_attr_leaf_read(NULL, context->dp, 0, -1, &bp);
        if (error)
                return XFS_ERROR(error);
-       ASSERT(bp != NULL);
-       leaf = bp->b_addr;
-       if (unlikely(leaf->hdr.info.magic != cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
-               XFS_CORRUPTION_ERROR("xfs_attr_leaf_list", XFS_ERRLEVEL_LOW,
-                                    context->dp->i_mount, leaf);
-               xfs_trans_brelse(NULL, bp);
-               return XFS_ERROR(EFSCORRUPTED);
-       }
 
        error = xfs_attr_leaf_list_int(bp, context);
        xfs_trans_brelse(NULL, bp);
@@ -1600,12 +1588,9 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                ASSERT(state->path.blk[0].bp);
                state->path.blk[0].bp = NULL;
 
-               error = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
-                                                    XFS_ATTR_FORK);
+               error = xfs_attr_leaf_read(args->trans, args->dp, 0, -1, &bp);
                if (error)
                        goto out;
-               ASSERT((((xfs_attr_leafblock_t *)bp->b_addr)->hdr.info.magic) ==
-                      cpu_to_be16(XFS_ATTR_LEAF_MAGIC));
 
                if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
                        xfs_bmap_init(args->flist, args->firstblock);
@@ -1653,6 +1638,8 @@ xfs_attr_fillstate(xfs_da_state_t *state)
        xfs_da_state_blk_t *blk;
        int level;
 
+       trace_xfs_attr_fillstate(state->args);
+
        /*
         * Roll down the "path" in the state structure, storing the on-disk
         * block number for those buffers in the "path".
@@ -1699,6 +1686,8 @@ xfs_attr_refillstate(xfs_da_state_t *state)
        xfs_da_state_blk_t *blk;
        int level, error;
 
+       trace_xfs_attr_refillstate(state->args);
+
        /*
         * Roll down the "path" in the state structure, storing the on-disk
         * block number for those buffers in the "path".
@@ -1710,7 +1699,7 @@ xfs_attr_refillstate(xfs_da_state_t *state)
                        error = xfs_da_read_buf(state->args->trans,
                                                state->args->dp,
                                                blk->blkno, blk->disk_blkno,
-                                               &blk->bp, XFS_ATTR_FORK);
+                                               &blk->bp, XFS_ATTR_FORK, NULL);
                        if (error)
                                return(error);
                } else {
@@ -1729,7 +1718,7 @@ xfs_attr_refillstate(xfs_da_state_t *state)
                        error = xfs_da_read_buf(state->args->trans,
                                                state->args->dp,
                                                blk->blkno, blk->disk_blkno,
-                                               &blk->bp, XFS_ATTR_FORK);
+                                               &blk->bp, XFS_ATTR_FORK, NULL);
                        if (error)
                                return(error);
                } else {
@@ -1755,6 +1744,8 @@ xfs_attr_node_get(xfs_da_args_t *args)
        int error, retval;
        int i;
 
+       trace_xfs_attr_node_get(args);
+
        state = xfs_da_state_alloc();
        state->args = args;
        state->mp = args->dp->i_mount;
@@ -1804,6 +1795,8 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
        int error, i;
        struct xfs_buf *bp;
 
+       trace_xfs_attr_node_list(context);
+
        cursor = context->cursor;
        cursor->initted = 1;
 
@@ -1815,7 +1808,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
        bp = NULL;
        if (cursor->blkno > 0) {
                error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
-                                             &bp, XFS_ATTR_FORK);
+                                             &bp, XFS_ATTR_FORK, NULL);
                if ((error != 0) && (error != EFSCORRUPTED))
                        return(error);
                if (bp) {
@@ -1858,7 +1851,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                for (;;) {
                        error = xfs_da_read_buf(NULL, context->dp,
                                                      cursor->blkno, -1, &bp,
-                                                     XFS_ATTR_FORK);
+                                                     XFS_ATTR_FORK, NULL);
                        if (error)
                                return(error);
                        if (unlikely(bp == NULL)) {
@@ -1907,14 +1900,6 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
         */
        for (;;) {
                leaf = bp->b_addr;
-               if (unlikely(leaf->hdr.info.magic !=
-                            cpu_to_be16(XFS_ATTR_LEAF_MAGIC))) {
-                       XFS_CORRUPTION_ERROR("xfs_attr_node_list(4)",
-                                            XFS_ERRLEVEL_LOW,
-                                            context->dp->i_mount, leaf);
-                       xfs_trans_brelse(NULL, bp);
-                       return(XFS_ERROR(EFSCORRUPTED));
-               }
                error = xfs_attr_leaf_list_int(bp, context);
                if (error) {
                        xfs_trans_brelse(NULL, bp);
@@ -1924,16 +1909,10 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
                        break;
                cursor->blkno = be32_to_cpu(leaf->hdr.info.forw);
                xfs_trans_brelse(NULL, bp);
-               error = xfs_da_read_buf(NULL, context->dp, cursor->blkno, -1,
-                                             &bp, XFS_ATTR_FORK);
+               error = xfs_attr_leaf_read(NULL, context->dp, cursor->blkno, -1,
+                                          &bp);
                if (error)
-                       return(error);
-               if (unlikely((bp == NULL))) {
-                       XFS_ERROR_REPORT("xfs_attr_node_list(5)",
-                                        XFS_ERRLEVEL_LOW,
-                                        context->dp->i_mount);
-                       return(XFS_ERROR(EFSCORRUPTED));
-               }
+                       return error;
        }
        xfs_trans_brelse(NULL, bp);
        return(0);
@@ -1959,6 +1938,8 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
        int nmap, error, tmp, valuelen, blkcnt, i;
        xfs_dablk_t lblkno;
 
+       trace_xfs_attr_rmtval_get(args);
+
        ASSERT(!(args->flags & ATTR_KERNOVAL));
 
        mp = args->dp->i_mount;
@@ -1980,7 +1961,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
                        dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
                        blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
                        error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
-                                                  dblkno, blkcnt, 0, &bp);
+                                                  dblkno, blkcnt, 0, &bp, NULL);
                        if (error)
                                return(error);
 
@@ -2014,6 +1995,8 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
        xfs_dablk_t lblkno;
        int blkcnt, valuelen, nmap, error, tmp, committed;
 
+       trace_xfs_attr_rmtval_set(args);
+
        dp = args->dp;
        mp = dp->i_mount;
        src = args->value;
@@ -2143,6 +2126,8 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
        xfs_dablk_t lblkno;
        int valuelen, blkcnt, nmap, error, done, committed;
 
+       trace_xfs_attr_rmtval_remove(args);
+
        mp = args->dp->i_mount;
 
        /*