Skip to content

Commit bcdfeb2

Browse files
Yan, ZhengSage Weil
authored andcommitted
ceph: remove xattr when null value is given to setxattr()
For the setxattr request, introduce a new flag CEPH_XATTR_REMOVE to distinguish null value case from the zero-length value case. Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
1 parent fbc0b97 commit bcdfeb2

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎fs/ceph/xattr.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define XATTR_CEPH_PREFIX "ceph."
1313
#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
1414

15+
static int __remove_xattr(struct ceph_inode_info *ci,
16+
struct ceph_inode_xattr *xattr);
17+
1518
/*
1619
* List of handlers for synthetic system.* attributes. Other
1720
* attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
359362
kfree(val);
360363
return err;
361364
}
365+
if (update_xattr < 0) {
366+
if (xattr)
367+
__remove_xattr(ci, xattr);
368+
kfree(name);
369+
return 0;
370+
}
362371
}
363372

364373
if (!xattr) {
@@ -862,6 +871,9 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
862871

863872
dout("setxattr value=%.*s\n", (int)size, value);
864873

874+
if (!value)
875+
flags |= CEPH_XATTR_REMOVE;
876+
865877
/* do request */
866878
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
867879
USE_AUTH_MDS);
@@ -965,8 +977,8 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
965977
goto retry;
966978
}
967979

968-
err = __set_xattr(ci, newname, name_len, newval,
969-
val_len, flags, 1, &xattr);
980+
err = __set_xattr(ci, newname, name_len, newval, val_len,
981+
flags, value ? 1 : -1, &xattr);
970982

971983
if (!err) {
972984
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);

‎include/linux/ceph/ceph_fs.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ extern const char *ceph_mds_op_name(int op);
373373
/*
374374
* Ceph setxattr request flags.
375375
*/
376-
#define CEPH_XATTR_CREATE 1
377-
#define CEPH_XATTR_REPLACE 2
376+
#define CEPH_XATTR_CREATE (1 << 0)
377+
#define CEPH_XATTR_REPLACE (1 << 1)
378+
#define CEPH_XATTR_REMOVE (1 << 31)
378379

379380
union ceph_mds_request_args {
380381
struct {

0 commit comments

Comments
 (0)