Skip to contentSkip to conversation

ceph: properly handle XATTR_CREATE and XATTR_REPLACE

PATCH In review Yan, Zheng 5 participants 19 messages Feb 11, 2014 – Feb 14, 2014

Subsystems (2)
lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 1/5 ceph: properly handle XATTR_CREATE and XATTR_REPLACE

return -EEXIST if XATTR_CREATE is set and xattr alread exists. return -ENODATA if XATTR_REPLACE is set but xattr does not exist.

---
 fs/ceph/xattr.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
fs/ceph/xattr.c +26 -12
index 898b656..28f9793 100644
@@ -319,8 +319,7 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
 static int __set_xattr(struct ceph_inode_info *ci,
 			   const char *name, int name_len,
 			   const char *val, int val_len,
-			   int dirty,
-			   int should_free_name, int should_free_val,
+			   int flags, int update_xattr,
 			   struct ceph_inode_xattr **newxattr)
 {
 	struct rb_node **p;
@@ -349,12 +348,25 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		xattr = NULL;
 	}
 
+	if (update_xattr) {
+		int err = 0;
+		if (xattr && (flags & XATTR_CREATE))
+			err = -EEXIST;
+		else if (!xattr && (flags & XATTR_REPLACE))
+			err = -ENODATA;
+		if (err) {
+			kfree(name);
+			kfree(val);
+			return err;
+		}
+	}
+
 	if (!xattr) {
 		new = 1;
 		xattr = *newxattr;
 		xattr->name = name;
 		xattr->name_len = name_len;
-		xattr->should_free_name = should_free_name;
+		xattr->should_free_name = update_xattr;
 
 		ci->i_xattrs.count++;
 		dout("__set_xattr count=%d\n", ci->i_xattrs.count);
@@ -364,7 +376,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		if (xattr->should_free_val)
 			kfree((void *)xattr->val);
 
-		if (should_free_name) {
+		if (update_xattr) {
 			kfree((void *)name);
 			name = xattr->name;
 		}
@@ -379,8 +391,8 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		xattr->val = "";
 
 	xattr->val_len = val_len;
-	xattr->dirty = dirty;
-	xattr->should_free_val = (val && should_free_val);
+	xattr->dirty = update_xattr;
+	xattr->should_free_val = (val && update_xattr);
 
 	if (new) {
 		rb_link_node(&xattr->node, parent, p);
@@ -588,7 +600,7 @@ start:
 			p += len;
 
 			err = __set_xattr(ci, name, namelen, val, len,
-					  0, 0, 0, &xattrs[numattr]);
+					  0, 0, &xattrs[numattr]);
 
 			if (err < 0)
 				goto bad;
@@ -892,7 +904,7 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	int issued;
 	int err;
-	int dirty;
+	int dirty = 0;
 	int name_len = strlen(name);
 	int val_len = size;
 	char *newname = NULL;
@@ -954,11 +966,13 @@ retry:
 	}
 
 	err = __set_xattr(ci, newname, name_len, newval,
-			  val_len, 1, 1, 1, &xattr);
+			  val_len, flags, 1, &xattr);
 
-	dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
-	ci->i_xattrs.dirty = true;
-	inode->i_ctime = CURRENT_TIME;
+	if (!err) {
+		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
+		ci->i_xattrs.dirty = true;
+		inode->i_ctime = CURRENT_TIME;
+	}
 
 	spin_unlock(&ci->i_ceph_lock);
 	if (dirty)
Signature · 1 line
1.8.5.3
author
#1 lore raw

PATCH 2/5 ceph: remove zero-size xattr

---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +9 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+			  struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
 			kfree(val);
 			return err;
 		}
+		if (!val_len) {
+			if (xattr)
+				__remove_xattr(ci, xattr);
+			kfree(name);
+			return 0;
+		}
 	}
 
 	if (!xattr) {
Signature · 1 line
1.8.5.3
#2 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 32 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +9 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+			  struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
 			kfree(val);
 			return err;
 		}
+		if (!val_len) {
+			if (xattr)
+				__remove_xattr(ci, xattr);
+			kfree(name);
+			return 0;
+		}
 	}
 
 	if (!xattr) {
#3 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 11 lines · Alex Elder
Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

That is how other FS behave, at least for ext* and btrfs.

Regards
Yan, Zheng

Quoted 49 lines

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 22 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +3 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+                       struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
                      kfree(val);
                      return err;

fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 373

Quoted 10 lines
fs/ceph/xattr.c +6 -0
              }
+             if (!val_len) {
+                     if (xattr)
+                             __remove_xattr(ci, xattr);
+                     kfree(name);
+                     return 0;
+             }
      }
 
      if (!xattr) {

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 7 lines · Zheng
Quoted 6 lines · Alex Elder
Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

Quoted 7 lines
Quoted 5 lines

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

That is how other FS behave, at least for ext* and btrfs.

I haven't tested this, I'm just glancing through code. But it looks to me like a zero-length value is OK, but a null value pointer means it should be deleted. Note in btrfs_setxattr(), for example, the same bit of code I referenced before:

if (size == 0)
value = ""; /* empty EA, do not remove */

And ext4 seems to delete for a null value, but handle an xattr whose value *length* is zero. Same with XFS.

So again, I haven't verified through testing, but my reading of the code (though rusty) still seems to show that an attribute can have an empty (zero-size) value.

-Alex

Quoted 52 lines

Regards
Yan, Zheng

Quoted 49 lines

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 22 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +3 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+                       struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
                      kfree(val);
                      return err;

fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 373

Quoted 10 lines
fs/ceph/xattr.c +6 -0
              }
+             if (!val_len) {
+                     if (xattr)
+                             __remove_xattr(ci, xattr);
+                     kfree(name);
+                     return 0;
+             }
      }
 
      if (!xattr) {

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#5 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 25 lines · Alex Elder
Quoted 7 lines · Zheng
Quoted 6 lines · Alex Elder
Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

Quoted 7 lines
Quoted 5 lines

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

That is how other FS behave, at least for ext* and btrfs.

I haven't tested this, I'm just glancing through code. But it looks to me like a zero-length value is OK, but a null value pointer means it should be deleted. Note in btrfs_setxattr(), for example, the same bit of code I referenced before:

if (size == 0)
value = ""; /* empty EA, do not remove */

Quoted 6 lines

And ext4 seems to delete for a null value, but handle an xattr whose value *length* is zero. Same with XFS.

So again, I haven't verified through testing, but my reading of the code (though rusty) still seems to show that an attribute can have an empty (zero-size) value.

You are right, Thanks. how about below patch?

---
From f11d5da84230e4993333a063019bad68c67b50d4 Mon Sep 17 00:00:00 2001
From: "Yan, Zheng" <[email protected]>
Date: Tue, 11 Feb 2014 13:04:19 +0800
Subject: [PATCH 2/5] 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.

---
 fs/ceph/xattr.c              | 16 ++++++++++++++--
 include/linux/ceph/ceph_fs.h |  5 +++--
 2 files changed, 17 insertions(+), 4 deletions(-)
fs/ceph/xattr.c +14 -2
index 28f9793..f6becf6 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+			  struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
 			kfree(val);
 			return err;
 		}
+		if (update_xattr < 0) {
+			if (xattr)
+				__remove_xattr(ci, xattr);
+			kfree(name);
+			return 0;
+		}
 	}
 
 	if (!xattr) {
@@ -862,6 +871,9 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
 
 	dout("setxattr value=%.*s\n", (int)size, value);
 
+	if (!value)
+		flags |= CEPH_XATTR_REMOVE;
+
 	/* do request */
 	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
 				       USE_AUTH_MDS);
@@ -965,8 +977,8 @@ retry:
 		goto retry;
 	}
 
-	err = __set_xattr(ci, newname, name_len, newval,
-			  val_len, flags, 1, &xattr);
+	err = __set_xattr(ci, newname, name_len, newval, val_len,
+			  flags, val ? 1 : -1, &xattr);
 
 	if (!err) {
 		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
include/linux/ceph/ceph_fs.h +3 -2
index 2623cff..25bfb0e 100644
@@ -373,8 +373,9 @@ extern const char *ceph_mds_op_name(int op);
 /*
  * Ceph setxattr request flags.
  */
-#define CEPH_XATTR_CREATE  1
-#define CEPH_XATTR_REPLACE 2
+#define CEPH_XATTR_CREATE  (1 << 0)
+#define CEPH_XATTR_REPLACE (1 << 1)
+#define CEPH_XATTR_REMOVE  (1 << 31)
 
 union ceph_mds_request_args {
 	struct {
Signature · 1 line
1.8.5.3
Quoted 56 lines

-Alex

Quoted 52 lines

Regards
Yan, Zheng

Quoted 49 lines

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 22 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +3 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+                       struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
                      kfree(val);
                      return err;

fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 373

Quoted 10 lines
fs/ceph/xattr.c +6 -0
              }
+             if (!val_len) {
+                     if (xattr)
+                             __remove_xattr(ci, xattr);
+                     kfree(name);
+                     return 0;
+             }
      }
 
      if (!xattr) {

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 78 lines · Zheng
Quoted 25 lines · Alex Elder
Quoted 7 lines · Zheng
Quoted 6 lines · Alex Elder
Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

Quoted 7 lines
Quoted 5 lines

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

That is how other FS behave, at least for ext* and btrfs.

I haven't tested this, I'm just glancing through code. But it looks to me like a zero-length value is OK, but a null value pointer means it should be deleted. Note in btrfs_setxattr(), for example, the same bit of code I referenced before:

if (size == 0)
value = ""; /* empty EA, do not remove */

Quoted 6 lines

And ext4 seems to delete for a null value, but handle an xattr whose value *length* is zero. Same with XFS.

So again, I haven't verified through testing, but my reading of the code (though rusty) still seems to show that an attribute can have an empty (zero-size) value.

You are right, Thanks. how about below patch?

---

Quoted 1 line

From f11d5da84230e4993333a063019bad68c67b50d4 Mon Sep 17 00:00:00 2001

From: "Yan, Zheng" <[email protected]>
Date: Tue, 11 Feb 2014 13:04:19 +0800
Subject: [PATCH 2/5] 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.

---
 fs/ceph/xattr.c              | 16 ++++++++++++++--
 include/linux/ceph/ceph_fs.h |  5 +++--
 2 files changed, 17 insertions(+), 4 deletions(-)
fs/ceph/xattr.c +9 -0
index 28f9793..f6becf6 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+			  struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
 			kfree(val);
 			return err;
 		}
+		if (update_xattr < 0) {
+			if (xattr)
+				__remove_xattr(ci, xattr);
+			kfree(name);
+			return 0;
+		}
 	}
 
 	if (!xattr) {

fs/ceph/xattr.c static int ceph_sync_setxattr(struct dentry *dentry, const char *name, · line 878

Quoted 8 lines
fs/ceph/xattr.c +3 -0
@@ -862,6 +871,9 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
 
 	dout("setxattr value=%.*s\n", (int)size, value);
 
+	if (!value)
+		flags |= CEPH_XATTR_REMOVE;
+
 	/* do request */
 	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,

How about just turning this into a REMOVEXATTR request in the !value case?

sage

Quoted 105 lines
fs/ceph/xattr.c +2 -2
 				       USE_AUTH_MDS);
@@ -965,8 +977,8 @@ retry:
 		goto retry;
 	}
 
-	err = __set_xattr(ci, newname, name_len, newval,
-			  val_len, flags, 1, &xattr);
+	err = __set_xattr(ci, newname, name_len, newval, val_len,
+			  flags, val ? 1 : -1, &xattr);
 
 	if (!err) {
 		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
include/linux/ceph/ceph_fs.h +3 -2
index 2623cff..25bfb0e 100644
@@ -373,8 +373,9 @@ extern const char *ceph_mds_op_name(int op);
 /*
  * Ceph setxattr request flags.
  */
-#define CEPH_XATTR_CREATE  1
-#define CEPH_XATTR_REPLACE 2
+#define CEPH_XATTR_CREATE  (1 << 0)
+#define CEPH_XATTR_REPLACE (1 << 1)
+#define CEPH_XATTR_REMOVE  (1 << 31)
 
 union ceph_mds_request_args {
 	struct {
Signature · 1 line
1.8.5.3
Quoted 56 lines

-Alex

Quoted 52 lines

Regards
Yan, Zheng

Quoted 49 lines

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 22 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +3 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+                       struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
                      kfree(val);
                      return err;

fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 373

Quoted 10 lines
fs/ceph/xattr.c +6 -0
              }
+             if (!val_len) {
+                     if (xattr)
+                             __remove_xattr(ci, xattr);
+                     kfree(name);
+                     return 0;
+             }
      }
 
      if (!xattr) {

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#7 lore raw

Re: [PATCH 2/5] ceph: remove zero-size xattr

Quoted 82 lines · Sage Weil
Quoted 81 lines · Zheng
Quoted 25 lines · Alex Elder
Quoted 7 lines · Zheng
Quoted 6 lines · Alex Elder
Quoted 1 line · Zheng

You really need to explain better under what circumstances a zero-size xattr is getting removed.

Quoted 7 lines
Quoted 5 lines

But apparently it's only when you're updating an xattr (not building it up from a blob from storage).

Why are you doing this? Why can't an xattr exist with an empty value?

That is how other FS behave, at least for ext* and btrfs.

I haven't tested this, I'm just glancing through code. But it looks to me like a zero-length value is OK, but a null value pointer means it should be deleted. Note in btrfs_setxattr(), for example, the same bit of code I referenced before:

if (size == 0)
value = ""; /* empty EA, do not remove */

Quoted 6 lines

And ext4 seems to delete for a null value, but handle an xattr whose value *length* is zero. Same with XFS.

So again, I haven't verified through testing, but my reading of the code (though rusty) still seems to show that an attribute can have an empty (zero-size) value.

You are right, Thanks. how about below patch?

---

Quoted 1 line

From f11d5da84230e4993333a063019bad68c67b50d4 Mon Sep 17 00:00:00 2001

From: "Yan, Zheng" <[email protected]>
Date: Tue, 11 Feb 2014 13:04:19 +0800
Subject: [PATCH 2/5] 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.

---
 fs/ceph/xattr.c              | 16 ++++++++++++++--
 include/linux/ceph/ceph_fs.h |  5 +++--
 2 files changed, 17 insertions(+), 4 deletions(-)
fs/ceph/xattr.c +9 -0
index 28f9793..f6becf6 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+			  struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
 			kfree(val);
 			return err;
 		}
+		if (update_xattr < 0) {
+			if (xattr)
+				__remove_xattr(ci, xattr);
+			kfree(name);
+			return 0;
+		}
 	}
 
 	if (!xattr) {
@@ -862,6 +871,9 @@ static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
 
 	dout("setxattr value=%.*s\n", (int)size, value);
 
Quoted 8 lines

fs/ceph/xattr.c static int ceph_sync_setxattr(struct dentry *dentry, const char *name, · line 878

Quoted 5 lines
fs/ceph/xattr.c +3 -0
+	if (!value)
+		flags |= CEPH_XATTR_REMOVE;
+
 	/* do request */
 	req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,

How about just turning this into a REMOVEXATTR request in the !value case?

REMOVEXATTR request doesn't respect the CEPH_XATTR_REPLACE flag.

Regards
Yan, Zheng

Quoted 107 lines

sage

Quoted 105 lines
fs/ceph/xattr.c +2 -2
 				       USE_AUTH_MDS);
@@ -965,8 +977,8 @@ retry:
 		goto retry;
 	}
 
-	err = __set_xattr(ci, newname, name_len, newval,
-			  val_len, flags, 1, &xattr);
+	err = __set_xattr(ci, newname, name_len, newval, val_len,
+			  flags, val ? 1 : -1, &xattr);
 
 	if (!err) {
 		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
include/linux/ceph/ceph_fs.h +3 -2
index 2623cff..25bfb0e 100644
@@ -373,8 +373,9 @@ extern const char *ceph_mds_op_name(int op);
 /*
  * Ceph setxattr request flags.
  */
-#define CEPH_XATTR_CREATE  1
-#define CEPH_XATTR_REPLACE 2
+#define CEPH_XATTR_CREATE  (1 << 0)
+#define CEPH_XATTR_REPLACE (1 << 1)
+#define CEPH_XATTR_REMOVE  (1 << 31)
 
 union ceph_mds_request_args {
 	struct {
Signature · 1 line
1.8.5.3
Quoted 56 lines

-Alex

Quoted 52 lines

Regards
Yan, Zheng

Quoted 49 lines

Looking at generic_setxattr() in "fs/xattr.c" we see:
if (size == 0)
value = ""; /* empty EA, do not remove */

The code you have below looks OK, but it seems that you shouldn't be doing this.

Am I missing something?

-Alex

Quoted 22 lines
---
 fs/ceph/xattr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/ceph/xattr.c +3 -0
index 28f9793..6ed0e5a 100644
@@ -12,6 +12,9 @@
 #define XATTR_CEPH_PREFIX "ceph."
 #define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
 
+static int __remove_xattr(struct ceph_inode_info *ci,
+                       struct ceph_inode_xattr *xattr);
+
 /*
  * List of handlers for synthetic system.* attributes. Other
  * attributes are handled directly.
@@ -359,6 +362,12 @@ static int __set_xattr(struct ceph_inode_info *ci,
                      kfree(val);
                      return err;

fs/ceph/xattr.c static int __set_xattr(struct ceph_inode_info *ci, · line 373

Quoted 10 lines
fs/ceph/xattr.c +6 -0
              }
+             if (!val_len) {
+                     if (xattr)
+                             __remove_xattr(ci, xattr);
+                     kfree(name);
+                     return 0;
+             }
      }
 
      if (!xattr) {

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#8 lore raw

PATCH 3/5 ceph: fix ceph_removexattr()

In reply to Yan, Zheng
---
 fs/ceph/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/xattr.c +1 -1
index 6ed0e5a..79f9c12 100644
@@ -463,7 +463,7 @@ static int __remove_xattr(struct ceph_inode_info *ci,
 			  struct ceph_inode_xattr *xattr)
 {
 	if (!xattr)
-		return -EOPNOTSUPP;
+		return -ENODATA;
 
 	rb_erase(&xattr->node, &ci->i_xattrs.index);
 
Signature · 1 line
1.8.5.3
Reviewed-by on v1 3/5
#9 lore raw

Re: [PATCH 3/5] ceph: fix ceph_removexattr()

Quoted 1 line · Zheng

You need a better explanation than "fix."

We have the ENODATA thing (versus ENOATTR), but again what you have is fine.

Quoted 9 lines
---
 fs/ceph/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/xattr.c +0 -0
index 6ed0e5a..79f9c12 100644

fs/ceph/xattr.c static int __remove_xattr(struct ceph_inode_info *ci, · line 466

Quoted 5 lines
fs/ceph/xattr.c +1 -1
@@ -463,7 +463,7 @@ static int __remove_xattr(struct ceph_inode_info *ci,
 			  struct ceph_inode_xattr *xattr)
 {
 	if (!xattr)
-		return -EOPNOTSUPP;
+		return -ENODATA;

It seems like this could be a void function, and the (one) caller could check for null before making the call.

Either way though, this looks good.

Quoted 4 lines
fs/ceph/xattr.c +0 -0
 	rb_erase(&xattr->node, &ci->i_xattrs.index);
 
 
author
#10 lore raw

PATCH 4/5 ceph: add missing init_acl() for mkdir() and atomic_open()

In reply to Yan, Zheng
---
 fs/ceph/dir.c  | 9 +++++----
 fs/ceph/file.c | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/ceph/dir.c +5 -4
index 6da4df8..3bbd0eb 100644
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
@@ -776,7 +775,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +1 -0
index dfd2ce3..09c7afe 100644
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);
 			*opened |= FILE_CREATED;
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
Signature · 1 line
1.8.5.3
Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and atomic_open()

On 02/10/2014 11:30 PM, Yan, Zheng wrote:

This looks OK to me but you should get another opinion, I haven't really given it as thorough a review as I normally do.

Quoted 23 lines
---
 fs/ceph/dir.c  | 9 +++++----
 fs/ceph/file.c | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/ceph/dir.c +2 -3
index 6da4df8..3bbd0eb 100644
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }

fs/ceph/dir.c static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) · line 780

Quoted 7 lines
fs/ceph/dir.c +3 -1
@@ -776,7 +775,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else

Do symlinks have ACLs? (I don't know, I just notice that ceph_symlink() doesn't call ceph_init_acl() on the symlink.)

fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 290

Quoted 13 lines
fs/ceph/dir.c +0 -0
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +1 -0
index dfd2ce3..09c7afe 100644
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);
 			*opened |= FILE_CREATED;

This seems OK but I have to admit I don't know this path through the code and I don't have time to really dig into it right now.

Quoted 3 lines
fs/ceph/file.c +0 -0
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
#12 lore raw

Re: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and atomic_open()

In reply to Yan, Zheng

On Tue, Feb 11, 2014 at 01:30:11PM +0800, Yan Zheng wrote:

This looks good, but there maybe some hiccups, see below.

The symlink also need ceph_init_acl() as Alex mentioned, I have add it in the patch.

Quoted 11 lines
---
 fs/ceph/dir.c  | 9 +++++----
 fs/ceph/file.c | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/ceph/dir.c +0 -0
index 6da4df8..3bbd0eb 100644

fs/ceph/dir.c static int ceph_mknod(struct inode *dir, struct dentry *dentry, · line 700

Quoted 9 lines
fs/ceph/dir.c +2 -3
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);

ceph_init_acl() may fail, we shoud take care of the return value.

Quoted 18 lines
fs/ceph/dir.c +3 -1
 	return err;
 }
@@ -776,7 +775,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +0 -0
index dfd2ce3..09c7afe 100644

fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 289

Quoted 4 lines
fs/ceph/file.c +1 -0
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);

Same to above.

Quoted 10 lines
fs/ceph/file.c +0 -0
 			*opened |= FILE_CREATED;
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
Signature · 6 lines
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards,
Guangliang
author
#13 lore raw

Re: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and atomic_open()

Quoted 6 lines · Guangliang Zhao

On Tue, Feb 11, 2014 at 01:30:11PM +0800, Yan Zheng wrote:

This looks good, but there maybe some hiccups, see below.

The symlink also need ceph_init_acl() as Alex mentioned, I have add it in the patch.

will update my patch.

Quoted 14 lines
Quoted 14 lines
---
 fs/ceph/dir.c  | 9 +++++----
 fs/ceph/file.c | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)
fs/ceph/dir.c +0 -0
index 6da4df8..3bbd0eb 100644
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
Quoted 9 lines

fs/ceph/dir.c static int ceph_mknod(struct inode *dir, struct dentry *dentry, · line 700

Quoted 7 lines
fs/ceph/dir.c +2 -3
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);

ceph_init_acl() may fail, we shoud take care of the return value.

I remove the error handling intentionally because creating inode and initializing ACL are not atomic in current implementation. A better approach is initializing the ACL on the metadata server, but it requires more works.

Regards
Yan, Zheng

Quoted 37 lines
Quoted 19 lines
fs/ceph/dir.c +3 -1
 	return err;
 }
@@ -776,7 +775,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +0 -0
index dfd2ce3..09c7afe 100644

fs/ceph/file.c int ceph_atomic_open(struct inode *dir, struct dentry *dentry, · line 289

Quoted 4 lines
fs/ceph/file.c +1 -0
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);

Same to above.

Quoted 10 lines
fs/ceph/file.c +0 -0
 			*opened |= FILE_CREATED;
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
Signature · 6 lines
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author
#14 lore raw

Re: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and atomic_open()

In reply to Guangliang Zhao

updated patch

---
From 9c517a5af5af472a0bee9c900b7df400b10f3098 Mon Sep 17 00:00:00 2001
From: "Yan, Zheng" <[email protected]>
Date: Tue, 11 Feb 2014 12:55:05 +0800
Subject: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and
atomic_open()

---
 fs/ceph/dir.c  | 13 ++++++++-----
 fs/ceph/file.c |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)
fs/ceph/dir.c +8 -5
index 6da4df8..2e3b30d 100644
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
@@ -735,7 +734,9 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,
 	if (!err && !req->r_reply_info.head->is_dentry)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
-	if (err)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
@@ -776,7 +777,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +1 -0
index dfd2ce3..09c7afe 100644
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);
 			*opened |= FILE_CREATED;
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
Signature · 1 line
1.8.5.3
Reviewed-by
#15 lore raw

Re: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and atomic_open()

Quoted 1 line · Zheng

updated patch

This looks OK, but I just finished reviewing a separate patch that seems to do this... One or the other. Provided you resolve that:

Quoted 64 lines

---
From 9c517a5af5af472a0bee9c900b7df400b10f3098 Mon Sep 17 00:00:00 2001
From: "Yan, Zheng" <[email protected]>
Date: Tue, 11 Feb 2014 12:55:05 +0800
Subject: [PATCH 4/5] ceph: add missing init_acl() for mkdir() and
atomic_open()

---
 fs/ceph/dir.c  | 13 ++++++++-----
 fs/ceph/file.c |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)
fs/ceph/dir.c +8 -5
index 6da4df8..2e3b30d 100644
@@ -695,9 +695,8 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,
 	ceph_mdsc_put_request(req);
 
 	if (!err)
-		err = ceph_init_acl(dentry, dentry->d_inode, dir);
-
-	if (err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
@@ -735,7 +734,9 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,
 	if (!err && !req->r_reply_info.head->is_dentry)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
-	if (err)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
@@ -776,7 +777,9 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 		err = ceph_handle_notrace_create(dir, dentry);
 	ceph_mdsc_put_request(req);
 out:
-	if (err < 0)
+	if (!err)
+		ceph_init_acl(dentry, dentry->d_inode, dir);
+	else
 		d_drop(dentry);
 	return err;
 }
fs/ceph/file.c +1 -0
index dfd2ce3..09c7afe 100644
@@ -286,6 +286,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
 	} else {
 		dout("atomic_open finish_open on dn %p\n", dn);
 		if (req->r_op == CEPH_MDS_OP_CREATE && req->r_reply_info.has_create_ino) {
+			ceph_init_acl(dentry, dentry->d_inode, dir);
 			*opened |= FILE_CREATED;
 		}
 		err = finish_open(file, dentry, ceph_open, opened);
author
#16 lore raw

PATCH 5/5 ceph: fix ceph_set_acl()

In reply to Yan, Zheng

If acl is equivalent to file mode permission bits, ceph_set_acl() needs to remove any existing acl xattr. Use __ceph_setxattr() to handle both setting and removing acl xattr cases, it doesn't return -ENODATA when there is no acl xattr.

---
 fs/ceph/acl.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ceph/acl.c +1 -5
index 4c2d452..accc9f2 100644
@@ -160,11 +160,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 			goto out_dput;
 	}
 
-	if (value)
-		ret = __ceph_setxattr(dentry, name, value, size, 0);
-	else
-		ret = __ceph_removexattr(dentry, name);
-
+	ret = __ceph_setxattr(dentry, name, value, size, 0);
 	if (ret) {
 		if (new_mode != old_mode) {
 			newattrs.ia_mode = old_mode;
Signature · 1 line
1.8.5.3
Reviewed-by on v1 5/5
#17 lore raw

Re: [PATCH 5/5] ceph: fix ceph_set_acl()

Quoted 4 lines · Zheng

If acl is equivalent to file mode permission bits, ceph_set_acl() needs to remove any existing acl xattr. Use __ceph_setxattr() to handle both setting and removing acl xattr cases, it doesn't return -ENODATA when there is no acl xattr.

This looks good, however (continuing with our other discussion) I assume that __set_xattr() will use a null value rather than 0 value_len to determine whether to remove the xattr.

And I'll continue to suggest better descriptions. (I realize English is not your native language but I really think the description is important, to be able to verify the code change matches what the developer intended it to do.) The problem here is that ceph_set_acl() could return -ENODATA if it attempted to remove a non-existent ACL attribute,
and that shouldn't happen. (Right?)

PS Note that ceph_set_acl() can be made static, and its
only caller, ceph_init_acl() has its return value ignored in all cases. So in some respects this change not matter much.

Quoted 23 lines
---
 fs/ceph/acl.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/ceph/acl.c +1 -5
index 4c2d452..accc9f2 100644
@@ -160,11 +160,7 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 			goto out_dput;
 	}
 
-	if (value)
-		ret = __ceph_setxattr(dentry, name, value, size, 0);
-	else
-		ret = __ceph_removexattr(dentry, name);
-
+	ret = __ceph_setxattr(dentry, name, value, size, 0);
 	if (ret) {
 		if (new_mode != old_mode) {
 			newattrs.ia_mode = old_mode;
Reviewed-by on v1 1/5
#18 lore raw
In reply to Yan, Zheng
Quoted 2 lines · Zheng

return -EEXIST if XATTR_CREATE is set and xattr alread exists. return -ENODATA if XATTR_REPLACE is set but xattr does not exist.

(I have a set of changes to this source file that I never got in; I'll see if I can dig them up and post them for review too, as long as the file is getting some attention.)

My man page says this second case should return ENOATTR, and although that has the same numeric value as ENODATA, that could someday change.

That being said, I see "fs/xattr.c uses ENODATA, so I suppose what you've got is fine. (Maybe somebody should fix the man page to resolve the discrepancy.)

I have one other comment at the end--basically that you're fixing a bug in addition to what you've mentioned above. Please at least mention that in your explanation.

Otherwise this looks good.

Quoted 86 lines
---
 fs/ceph/xattr.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
fs/ceph/xattr.c +20 -8
index 898b656..28f9793 100644
@@ -319,8 +319,7 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
 static int __set_xattr(struct ceph_inode_info *ci,
 			   const char *name, int name_len,
 			   const char *val, int val_len,
-			   int dirty,
-			   int should_free_name, int should_free_val,
+			   int flags, int update_xattr,
 			   struct ceph_inode_xattr **newxattr)
 {
 	struct rb_node **p;
@@ -349,12 +348,25 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		xattr = NULL;
 	}
 
+	if (update_xattr) {
+		int err = 0;
+		if (xattr && (flags & XATTR_CREATE))
+			err = -EEXIST;
+		else if (!xattr && (flags & XATTR_REPLACE))
+			err = -ENODATA;
+		if (err) {
+			kfree(name);
+			kfree(val);
+			return err;
+		}
+	}
+
 	if (!xattr) {
 		new = 1;
 		xattr = *newxattr;
 		xattr->name = name;
 		xattr->name_len = name_len;
-		xattr->should_free_name = should_free_name;
+		xattr->should_free_name = update_xattr;
 
 		ci->i_xattrs.count++;
 		dout("__set_xattr count=%d\n", ci->i_xattrs.count);
@@ -364,7 +376,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		if (xattr->should_free_val)
 			kfree((void *)xattr->val);
 
-		if (should_free_name) {
+		if (update_xattr) {
 			kfree((void *)name);
 			name = xattr->name;
 		}
@@ -379,8 +391,8 @@ static int __set_xattr(struct ceph_inode_info *ci,
 		xattr->val = "";
 
 	xattr->val_len = val_len;
-	xattr->dirty = dirty;
-	xattr->should_free_val = (val && should_free_val);
+	xattr->dirty = update_xattr;
+	xattr->should_free_val = (val && update_xattr);
 
 	if (new) {
 		rb_link_node(&xattr->node, parent, p);
@@ -588,7 +600,7 @@ start:
 			p += len;
 
 			err = __set_xattr(ci, name, namelen, val, len,
-					  0, 0, 0, &xattrs[numattr]);
+					  0, 0, &xattrs[numattr]);
 
 			if (err < 0)
 				goto bad;
@@ -892,7 +904,7 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
 	struct ceph_inode_info *ci = ceph_inode(inode);
 	int issued;
 	int err;
-	int dirty;
+	int dirty = 0;
 	int name_len = strlen(name);
 	int val_len = size;
 	char *newname = NULL;

fs/ceph/xattr.c retry: · line 970

Quoted 6 lines
fs/ceph/xattr.c +1 -1
@@ -954,11 +966,13 @@ retry:
 	}
 
 	err = __set_xattr(ci, newname, name_len, newval,
-			  val_len, 1, 1, 1, &xattr);
+			  val_len, flags, 1, &xattr);
 

The following is a good change (only mark ceph inode dirty if __set_xattr() succeeds), but it is a change of behavior that should be called attention to in the explanation at the top of this patch (and possibly separated into its own patch).

Quoted 12 lines
fs/ceph/xattr.c +5 -3
-	dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
-	ci->i_xattrs.dirty = true;
-	inode->i_ctime = CURRENT_TIME;
+	if (!err) {
+		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
+		ci->i_xattrs.dirty = true;
+		inode->i_ctime = CURRENT_TIME;
+	}
 
 	spin_unlock(&ci->i_ceph_lock);
 	if (dirty)