diff mbox series

[v3] ceph: return -ENODATA when xattr doesn't exist for removexattr

Message ID 20240314073915.844541-1-xiubli@redhat.com (mailing list archive)
State New, archived
Headers show
Series [v3] ceph: return -ENODATA when xattr doesn't exist for removexattr | expand

Commit Message

Xiubo Li March 14, 2024, 7:39 a.m. UTC
From: Xiubo Li <xiubli@redhat.com>

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.

And at the same time added a new flags CEPH_XATTR_REMOVE2 and in
MDS side it will return -ENODATA when the xattr doesn't exist.
While the CEPH_XATTR_REMOVE will be kept to be compatible with
old cephs.

Please note this commit also fixed a bug, which is that even when
the ACL xattrs don't exist the ctime/mode still will be updated.

URL: https://tracker.ceph.com/issues/64679
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---

V3:
- Fixed failure in
https://pulpito.ceph.com/vshankar-2024-03-13_13:59:32-fs-wip-vshankar-testing-20240307.013758-testing-default-smithi/7596711/.

V2:
- Fixed the test faiures in
https://tracker.ceph.com/issues/64679#note-4.
- Added a new CEPH_XATTR_REMOVE2 flags.



 fs/ceph/acl.c                | 5 +++++
 fs/ceph/xattr.c              | 7 +++----
 include/linux/ceph/ceph_fs.h | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/fs/ceph/acl.c b/fs/ceph/acl.c
index 1564eacc253d..c0634347746f 100644
--- a/fs/ceph/acl.c
+++ b/fs/ceph/acl.c
@@ -148,6 +148,11 @@  int ceph_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
 	}
 
 	ret = __ceph_setxattr(inode, name, value, size, 0);
+	/*
+	 * If the attribute didn't exist to start with that's fine.
+	 */
+	if (!acl && ret == -ENODATA)
+		ret = 0;
 	if (ret) {
 		if (new_mode != old_mode) {
 			newattrs.ia_ctime = old_ctime;
diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index e066a556eccb..a39189484100 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;
 		}
 	}
 
@@ -1131,7 +1130,7 @@  static int ceph_sync_setxattr(struct inode *inode, const char *name,
 		if (flags & CEPH_XATTR_REPLACE)
 			op = CEPH_MDS_OP_RMXATTR;
 		else
-			flags |= CEPH_XATTR_REMOVE;
+			flags |= CEPH_XATTR_REMOVE | CEPH_XATTR_REMOVE2;
 	}
 
 	doutc(cl, "name %s value size %zu\n", name, size);
diff --git a/include/linux/ceph/ceph_fs.h b/include/linux/ceph/ceph_fs.h
index ee1d0e5f9789..c1d9c5f6ff1b 100644
--- a/include/linux/ceph/ceph_fs.h
+++ b/include/linux/ceph/ceph_fs.h
@@ -383,6 +383,7 @@  extern const char *ceph_mds_op_name(int op);
  */
 #define CEPH_XATTR_CREATE  (1 << 0)
 #define CEPH_XATTR_REPLACE (1 << 1)
+#define CEPH_XATTR_REMOVE2 (1 << 30)
 #define CEPH_XATTR_REMOVE  (1 << 31)
 
 /*