]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: remove some boilerplate from xfs_attr_set
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:22:50 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:03 +0000 (17:01 -0700)
Source kernel commit: e7420e75ef04787bc51688fc9bbca7da4d164a1e

In preparation for online/offline repair wanting to use xfs_attr_set,
move some of the boilerplate out of this function into the callers.
Repair can initialize the da_args completely, and the userspace flag
handling/twisting goes away once we move it to xfs_attr_change.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_attr.c

index 344b34aa4628ef651adf1dc3f253b367962628a7..1034579a14b30a76097e9b7bd25b315793d0b1b5 100644 (file)
@@ -947,6 +947,16 @@ xfs_attr_lookup(
        return error;
 }
 
+/*
+ * Make a change to the xattr structure.
+ *
+ * The caller must have initialized @args, attached dquots, and must not hold
+ * any ILOCKs.
+ *
+ * Returns -EEXIST for XFS_ATTRUPDATE_CREATE if the name already exists.
+ * Returns -ENOATTR for XFS_ATTRUPDATE_REMOVE if the name does not exist.
+ * Returns 0 on success, or a negative errno if something else went wrong.
+ */
 int
 xfs_attr_set(
        struct xfs_da_args      *args,
@@ -960,27 +970,7 @@ xfs_attr_set(
        int                     rmt_blks = 0;
        unsigned int            total;
 
-       if (xfs_is_shutdown(dp->i_mount))
-               return -EIO;
-
-       error = xfs_qm_dqattach(dp);
-       if (error)
-               return error;
-
-       if (!args->owner)
-               args->owner = args->dp->i_ino;
-       args->geo = mp->m_attr_geo;
-       args->whichfork = XFS_ATTR_FORK;
-       xfs_attr_sethash(args);
-
-       /*
-        * We have no control over the attribute names that userspace passes us
-        * to remove, so we have to allow the name lookup prior to attribute
-        * removal to fail as well.  Preserve the logged flag, since we need
-        * to pass that through to the logging code.
-        */
-       args->op_flags = XFS_DA_OP_OKNOENT |
-                                       (args->op_flags & XFS_DA_OP_LOGGED);
+       ASSERT(!args->trans);
 
        switch (op) {
        case XFS_ATTRUPDATE_UPSERT:
@@ -1075,6 +1065,7 @@ xfs_attr_set(
        error = xfs_trans_commit(args->trans);
 out_unlock:
        xfs_iunlock(dp, XFS_ILOCK_EXCL);
+       args->trans = NULL;
        return error;
 
 out_trans_cancel: