]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: make attr lookup returns consistent
authorDave Chinner <dchinner@redhat.com>
Fri, 13 Dec 2019 00:54:33 +0000 (19:54 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 13 Dec 2019 00:54:33 +0000 (19:54 -0500)
Source kernel commit: 728bcaa3e0f9820e923dabe5e4c34e87100bb995

Shortform, leaf and remote value attr value retrieval return
different values for success. This makes it more complex to handle
actual errors xfs_attr_get() as some errors mean success and some
mean failure. Make the return values consistent for success and
failure consistent for all attribute formats.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-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_attr_leaf.c
libxfs/xfs_attr_remote.c

index 04ddbfe8cf2ecd10ed8eb0d792e0b4399ce4b996..bfe102f2928aa7738ddbf95bc4f99f547aa4901f 100644 (file)
@@ -96,7 +96,10 @@ xfs_inode_hasattr(
  * Overall external interface routines.
  *========================================================================*/
 
-/* Retrieve an extended attribute and its value.  Must have ilock. */
+/*
+ * Retrieve an extended attribute and its value.  Must have ilock.
+ * Returns 0 on successful retrieval, otherwise an error.
+ */
 int
 xfs_attr_get_ilocked(
        struct xfs_inode        *ip,
@@ -146,7 +149,7 @@ xfs_attr_get(
        xfs_iunlock(ip, lock_mode);
 
        *valuelenp = args.valuelen;
-       return error == -EEXIST ? 0 : error;
+       return error;
 }
 
 /*
@@ -767,6 +770,8 @@ xfs_attr_leaf_removename(
  *
  * This leaf block cannot have a "remote" value, we only call this routine
  * if bmap_one_block() says there is only one block (ie: no remote blks).
+ *
+ * Returns 0 on successful retrieval, otherwise an error.
  */
 STATIC int
 xfs_attr_leaf_get(xfs_da_args_t *args)
@@ -788,10 +793,15 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
        }
        error = xfs_attr3_leaf_getvalue(bp, args);
        xfs_trans_brelse(args->trans, bp);
-       if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
-               error = xfs_attr_rmtval_get(args);
-       }
-       return error;
+       if (error)
+               return error;
+
+       /* check if we have to retrieve a remote attribute to get the value */
+       if (args->flags & ATTR_KERNOVAL)
+               return 0;
+       if (!args->rmtblkno)
+               return 0;
+       return xfs_attr_rmtval_get(args);
 }
 
 /*========================================================================
@@ -1267,11 +1277,13 @@ xfs_attr_refillstate(xfs_da_state_t *state)
 }
 
 /*
- * Look up a filename in a node attribute list.
+ * Retrieve the attribute data from a node attribute list.
  *
  * This routine gets called for any attribute fork that has more than one
  * block, ie: both true Btree attr lists and for single-leaf-blocks with
  * "remote" values taking up more blocks.
+ *
+ * Returns 0 on successful retrieval, otherwise an error.
  */
 STATIC int
 xfs_attr_node_get(xfs_da_args_t *args)
@@ -1293,24 +1305,27 @@ xfs_attr_node_get(xfs_da_args_t *args)
        error = xfs_da3_node_lookup_int(state, &retval);
        if (error) {
                retval = error;
-       } else if (retval == -EEXIST) {
-               blk = &state->path.blk[ state->path.active-1 ];
-               ASSERT(blk->bp != NULL);
-               ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
-
-               /*
-                * Get the value, local or "remote"
-                */
-               retval = xfs_attr3_leaf_getvalue(blk->bp, args);
-               if (!retval && (args->rmtblkno > 0)
-                   && !(args->flags & ATTR_KERNOVAL)) {
-                       retval = xfs_attr_rmtval_get(args);
-               }
+               goto out_release;
        }
+       if (retval != -EEXIST)
+               goto out_release;
+
+       /*
+        * Get the value, local or "remote"
+        */
+       blk = &state->path.blk[state->path.active - 1];
+       retval = xfs_attr3_leaf_getvalue(blk->bp, args);
+       if (retval)
+               goto out_release;
+       if (args->flags & ATTR_KERNOVAL)
+               goto out_release;
+       if (args->rmtblkno > 0)
+               retval = xfs_attr_rmtval_get(args);
 
        /*
         * If not in a transaction, we have to release all the buffers.
         */
+out_release:
        for (i = 0; i < state->path.active; i++) {
                xfs_trans_brelse(args->trans, state->path.blk[i].bp);
                state->path.blk[i].bp = NULL;
index 65100130d78f759006e26594c1411e59e21f0db3..63a7a3096a849ff8da80d388e68e3475d4e9d3c7 100644 (file)
@@ -716,9 +716,12 @@ xfs_attr_shortform_lookup(xfs_da_args_t *args)
 }
 
 /*
- * Look up a name in a shortform attribute list structure.
+ * Retreive the attribute value and length.
+ *
+ * If ATTR_KERNOVAL is specified, only the length needs to be returned.
+ * Unlike a lookup, we only return an error if the attribute does not
+ * exist or we can't retrieve the value.
  */
-/*ARGSUSED*/
 int
 xfs_attr_shortform_getvalue(xfs_da_args_t *args)
 {
@@ -739,7 +742,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
                        continue;
                if (args->flags & ATTR_KERNOVAL) {
                        args->valuelen = sfe->valuelen;
-                       return -EEXIST;
+                       return 0;
                }
                if (args->valuelen < sfe->valuelen) {
                        args->valuelen = sfe->valuelen;
@@ -748,7 +751,7 @@ xfs_attr_shortform_getvalue(xfs_da_args_t *args)
                args->valuelen = sfe->valuelen;
                memcpy(args->value, &sfe->nameval[args->namelen],
                                                    args->valuelen);
-               return -EEXIST;
+               return 0;
        }
        return -ENOATTR;
 }
@@ -2346,6 +2349,10 @@ xfs_attr3_leaf_lookup_int(
 /*
  * Get the value associated with an attribute name from a leaf attribute
  * list structure.
+ *
+ * If ATTR_KERNOVAL is specified, only the length needs to be returned.
+ * Unlike a lookup, we only return an error if the attribute does not
+ * exist or we can't retrieve the value.
  */
 int
 xfs_attr3_leaf_getvalue(
index 9c588340ba3312a0f952ea00562363ab7295d134..7234f86c114646575219aa3a7a79d00eb5b85373 100644 (file)
@@ -356,6 +356,8 @@ xfs_attr_rmtval_copyin(
 /*
  * Read the value associated with an attribute from the out-of-line buffer
  * that we stored it in.
+ *
+ * Returns 0 on successful retrieval, otherwise an error.
  */
 int
 xfs_attr_rmtval_get(