]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_attr.c
xfs: Add helper function xfs_attr_try_sf_addname
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_attr.c
index 6ed680febf354d8d62121f04df2fcd2eedb0061d..8910d817e330fd4703fce3a892b43848cd4d11d4 100644 (file)
@@ -186,6 +186,33 @@ xfs_attr_calc_size(
        return nblks;
 }
 
+STATIC int
+xfs_attr_try_sf_addname(
+       struct xfs_inode        *dp,
+       struct xfs_da_args      *args)
+{
+
+       struct xfs_mount        *mp = dp->i_mount;
+       int                     error, error2;
+
+       error = xfs_attr_shortform_addname(args);
+       if (error == -ENOSPC)
+               return error;
+
+       /*
+        * Commit the shortform mods, and we're done.
+        * NOTE: this is also the error path (EEXIST, etc).
+        */
+       if (!error && (args->flags & ATTR_KERNOTIME) == 0)
+               xfs_trans_ichgtime(args->trans, dp, XFS_ICHGTIME_CHG);
+
+       if (mp->m_flags & XFS_MOUNT_WSYNC)
+               xfs_trans_set_sync(args->trans);
+
+       error2 = xfs_trans_commit(args->trans);
+       return error ? error : error2;
+}
+
 int
 xfs_attr_set(
        struct xfs_inode        *dp,
@@ -199,7 +226,7 @@ xfs_attr_set(
        struct xfs_da_args      args;
        struct xfs_trans_res    tres;
        int                     rsvd = (flags & ATTR_ROOT) != 0;
-       int                     error, err2, local;
+       int                     error, local;
 
        XFS_STATS_INC(mp, xs_attr_set);
 
@@ -276,30 +303,10 @@ xfs_attr_set(
                 * Try to add the attr to the attribute list in
                 * the inode.
                 */
-               error = xfs_attr_shortform_addname(&args);
+               error = xfs_attr_try_sf_addname(dp, &args);
                if (error != -ENOSPC) {
-                       /*
-                        * Commit the shortform mods, and we're done.
-                        * NOTE: this is also the error path (EEXIST, etc).
-                        */
-                       ASSERT(args.trans != NULL);
-
-                       /*
-                        * If this is a synchronous mount, make sure that
-                        * the transaction goes to disk before returning
-                        * to the user.
-                        */
-                       if (mp->m_flags & XFS_MOUNT_WSYNC)
-                               xfs_trans_set_sync(args.trans);
-
-                       if (!error && (flags & ATTR_KERNOTIME) == 0) {
-                               xfs_trans_ichgtime(args.trans, dp,
-                                                       XFS_ICHGTIME_CHG);
-                       }
-                       err2 = xfs_trans_commit(args.trans);
                        xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-                       return error ? error : err2;
+                       return error;
                }
 
                /*
@@ -315,9 +322,7 @@ xfs_attr_set(
                 * buffer and run into problems with the write verifier.
                 */
                xfs_trans_bhold(args.trans, leaf_bp);
-               xfs_defer_bjoin(args.trans->t_dfops, leaf_bp);
-               xfs_defer_ijoin(args.trans->t_dfops, dp);
-               error = xfs_defer_finish(&args.trans, args.trans->t_dfops);
+               error = xfs_defer_finish(&args.trans);
                if (error)
                        goto out;
 
@@ -582,14 +587,12 @@ xfs_attr_leaf_addname(
                 * Commit that transaction so that the node_addname() call
                 * can manage its own transactions.
                 */
-               xfs_defer_init(args->trans, args->trans->t_dfops);
                error = xfs_attr3_leaf_to_node(args);
                if (error)
-                       goto out_defer_cancel;
-               xfs_defer_ijoin(args->trans->t_dfops, dp);
-               error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                       return error;
+               error = xfs_defer_finish(&args->trans);
                if (error)
-                       goto out_defer_cancel;
+                       return error;
 
                /*
                 * Commit the current trans (including the inode) and start
@@ -671,15 +674,13 @@ xfs_attr_leaf_addname(
                 * If the result is small enough, shrink it all into the inode.
                 */
                if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-                       xfs_defer_init(args->trans, args->trans->t_dfops);
                        error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
                        /* bp is gone due to xfs_da_shrink_inode */
                        if (error)
-                               goto out_defer_cancel;
-                       xfs_defer_ijoin(args->trans->t_dfops, dp);
-                       error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                               return error;
+                       error = xfs_defer_finish(&args->trans);
                        if (error)
-                               goto out_defer_cancel;
+                               return error;
                }
 
                /*
@@ -694,9 +695,6 @@ xfs_attr_leaf_addname(
                error = xfs_attr3_leaf_clearflag(args);
        }
        return error;
-out_defer_cancel:
-       xfs_defer_cancel(args->trans->t_dfops);
-       return error;
 }
 
 /*
@@ -736,20 +734,15 @@ xfs_attr_leaf_removename(
         * If the result is small enough, shrink it all into the inode.
         */
        if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-               xfs_defer_init(args->trans, args->trans->t_dfops);
                error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
                /* bp is gone due to xfs_da_shrink_inode */
                if (error)
-                       goto out_defer_cancel;
-               xfs_defer_ijoin(args->trans->t_dfops, dp);
-               error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                       return error;
+               error = xfs_defer_finish(&args->trans);
                if (error)
-                       goto out_defer_cancel;
+                       return error;
        }
        return 0;
-out_defer_cancel:
-       xfs_defer_cancel(args->trans->t_dfops);
-       return error;
 }
 
 /*
@@ -865,15 +858,12 @@ restart:
                         */
                        xfs_da_state_free(state);
                        state = NULL;
-                       xfs_defer_init(args->trans, args->trans->t_dfops);
                        error = xfs_attr3_leaf_to_node(args);
                        if (error)
-                               goto out_defer_cancel;
-                       xfs_defer_ijoin(args->trans->t_dfops, dp);
-                       error = xfs_defer_finish(&args->trans,
-                                                args->trans->t_dfops);
+                               goto out;
+                       error = xfs_defer_finish(&args->trans);
                        if (error)
-                               goto out_defer_cancel;
+                               goto out;
 
                        /*
                         * Commit the node conversion and start the next
@@ -892,14 +882,12 @@ restart:
                 * in the index/blkno/rmtblkno/rmtblkcnt fields and
                 * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields.
                 */
-               xfs_defer_init(args->trans, args->trans->t_dfops);
                error = xfs_da3_split(state);
                if (error)
-                       goto out_defer_cancel;
-               xfs_defer_ijoin(args->trans->t_dfops, dp);
-               error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                       goto out;
+               error = xfs_defer_finish(&args->trans);
                if (error)
-                       goto out_defer_cancel;
+                       goto out;
        } else {
                /*
                 * Addition succeeded, update Btree hashvals.
@@ -990,14 +978,12 @@ restart:
                 * Check to see if the tree needs to be collapsed.
                 */
                if (retval && (state->path.active > 1)) {
-                       xfs_defer_init(args->trans, args->trans->t_dfops);
                        error = xfs_da3_join(state);
                        if (error)
-                               goto out_defer_cancel;
-                       xfs_defer_ijoin(args->trans->t_dfops, dp);
-                       error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                               goto out;
+                       error = xfs_defer_finish(&args->trans);
                        if (error)
-                               goto out_defer_cancel;
+                               goto out;
                }
 
                /*
@@ -1023,9 +1009,6 @@ out:
        if (error)
                return error;
        return retval;
-out_defer_cancel:
-       xfs_defer_cancel(args->trans->t_dfops);
-       goto out;
 }
 
 /*
@@ -1115,14 +1098,12 @@ xfs_attr_node_removename(
         * Check to see if the tree needs to be collapsed.
         */
        if (retval && (state->path.active > 1)) {
-               xfs_defer_init(args->trans, args->trans->t_dfops);
                error = xfs_da3_join(state);
                if (error)
-                       goto out_defer_cancel;
-               xfs_defer_ijoin(args->trans->t_dfops, dp);
-               error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                       goto out;
+               error = xfs_defer_finish(&args->trans);
                if (error)
-                       goto out_defer_cancel;
+                       goto out;
                /*
                 * Commit the Btree join operation and start a new trans.
                 */
@@ -1147,15 +1128,13 @@ xfs_attr_node_removename(
                        goto out;
 
                if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
-                       xfs_defer_init(args->trans, args->trans->t_dfops);
                        error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
                        /* bp is gone due to xfs_da_shrink_inode */
                        if (error)
-                               goto out_defer_cancel;
-                       xfs_defer_ijoin(args->trans->t_dfops, dp);
-                       error = xfs_defer_finish(&args->trans, args->trans->t_dfops);
+                               goto out;
+                       error = xfs_defer_finish(&args->trans);
                        if (error)
-                               goto out_defer_cancel;
+                               goto out;
                } else
                        xfs_trans_brelse(args->trans, bp);
        }
@@ -1164,9 +1143,6 @@ xfs_attr_node_removename(
 out:
        xfs_da_state_free(state);
        return error;
-out_defer_cancel:
-       xfs_defer_cancel(args->trans->t_dfops);
-       goto out;
 }
 
 /*