2024-03-06 01:23:27

by Xiubo Li

[permalink] [raw]
Subject: [PATCH] ceph: return -ENODATA when xattr doesn't exist for removexattr

From: Xiubo Li <[email protected]>

The POSIX says we should return -ENODATA when the corresponding
attribute doesn't exist when removing it. While there is one
exception for the acl ones in the local filesystems, for exmaple
for xfs, which will treat it as success.

While in the MDS side there have two ways to remove the xattr:
sending a CEPH_MDS_OP_SETXATTR request by setting the 'flags' with
CEPH_XATTR_REMOVE and just issued a CEPH_MDS_OP_RMXATTR request
directly.

For the first one it will always return 0 when the corresponding
xattr doesn't exist, while for the later one it will return
-ENODATA instead, this should be fixed in MDS to make them to be
consistent.

URL: https://tracker.ceph.com/issues/64679
Signed-off-by: Xiubo Li <[email protected]>
---
fs/ceph/acl.c | 9 ++++++++-
fs/ceph/xattr.c | 5 ++---
2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index 1564eacc253d..836b92526fa2 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -158,7 +158,14 @@ int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
goto out_free;
}

- ceph_set_cached_acl(inode, type, acl);
+ /*
+ * If the attribute didn't exist to start with that's fine.
+ */
+ if (!acl && ret == -ENODATA)
+ ret = 0;
+
+ if (!ret)
+ ceph_set_cached_acl(inode, type, acl);

out_free:
kfree(value);
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index e066a556eccb..08b14eea66e9 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -613,11 +613,10 @@ static int __set_xattr(struct ceph_inode_info *ci,
return err;
}
if (update_xattr < 0) {
- if (xattr)
- __remove_xattr(ci, xattr);
+ err = __remove_xattr(ci, xattr);
kfree(name);
kfree(*newxattr);
- return 0;
+ return err;
}
}

--
2.43.0