]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: remove xattr when null value is given to setxattr() 1216/head
authorYan, Zheng <zheng.z.yan@intel.com>
Tue, 11 Feb 2014 05:32:23 +0000 (13:32 +0800)
committerYan, Zheng <zheng.z.yan@intel.com>
Thu, 13 Feb 2014 04:20:41 +0000 (12:20 +0800)
setxattr() should remove xattr if parameter 'value' is NULL. To
distinguish it from the zero-length value case, introduce a new
flag CEPH_XATTR_REMOVE for the setxattr request.

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
src/client/Client.cc
src/include/ceph_fs.h
src/mds/Server.cc

index b336453b2ce461a3e1f461bbc8b052c38bfaae56..91e27d6c2fe0e2a6a2c60d4a00312117ddca8e4e 100644 (file)
@@ -7167,6 +7167,9 @@ int Client::_setxattr(Inode *in, const char *name, const void *value, size_t siz
       strncmp(name, "ceph.", 5))
     return -EOPNOTSUPP;
 
+  if (!value)
+    flags |= CEPH_XATTR_REMOVE;
+
   MetaRequest *req = new MetaRequest(CEPH_MDS_OP_SETXATTR);
   filepath path;
   in->make_nosnap_relative_path(path);
index 003f03cd1d8f49f4766c69d360060e5798ebc0f6..f075da4e8f0fd5cd6d7019e9c2cb827ac119bb08 100644 (file)
@@ -354,8 +354,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 {
index 36c11402840c537a714da3a98d74cec4c35541d5..dd7caf9122f12787a82cb8ea75578b7d28c341ba 100644 (file)
@@ -3799,9 +3799,11 @@ void Server::handle_client_setxattr(MDRequest *mdr)
   pi->ctime = ceph_clock_now(g_ceph_context);
   pi->xattr_version++;
   px->erase(name);
-  (*px)[name] = buffer::create(len);
-  if (len)
-    req->get_data().copy(0, len, (*px)[name].c_str());
+  if (!(flags & CEPH_XATTR_REMOVE)) {
+    (*px)[name] = buffer::create(len);
+    if (len)
+      req->get_data().copy(0, len, (*px)[name].c_str());
+  }
 
   // log + wait
   mdr->ls = mdlog->get_current_segment();