]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add rmxattr
authorYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 22 Oct 2010 21:32:55 +0000 (14:32 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 22 Oct 2010 21:33:17 +0000 (14:33 -0700)
src/include/librados.h
src/include/librados.hpp
src/librados.cc
src/osdc/Objecter.h
src/rados.cc

index bade6e909727c677c9e507496150edd98e7d0aaf..e55d25a91e239182758edebe61c23d0299899415 100644 (file)
@@ -84,6 +84,7 @@ int rados_trunc(rados_pool_t pool, const char *oid, size_t size);
 /* attrs */
 int rados_getxattr(rados_pool_t pool, const char *o, const char *name, char *buf, size_t len);
 int rados_setxattr(rados_pool_t pool, const char *o, const char *name, const char *buf, size_t len);
+int rados_rmxattr(rados_pool_t pool, const char *o, const char *name);
 
 /* misc */
 int rados_stat(rados_pool_t pool, const char *o, uint64_t *psize, time_t *pmtime);
index 8b172527b2e3fa23523f0937c08fcd58cdad076a..1469f9cf5696c49fbf858a088c00b01ed80b45f3 100644 (file)
@@ -77,6 +77,7 @@ public:
 
   int getxattr(pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
   int setxattr(pool_t pool, const std::string& oid, const char *name, bufferlist& bl);
+  int rmxattr(pool_t pool, const std::string& oid, const char *name);
   int getxattrs(pool_t pool, const std::string& oid, std::map<std::string, bufferlist>& attrset);
   int stat(pool_t pool, const std::string& oid, uint64_t *psize, time_t *pmtime);
 
index 34e7c73da553a0d1a0f9fc3f4deb020bb6a7e91a..c20a7cfbb137f0f668f11ef188ffb1dc14f10687 100644 (file)
@@ -144,6 +144,7 @@ public:
   int getxattr(PoolCtx& pool, const object_t& oid, const char *name, bufferlist& bl);
   int setxattr(PoolCtx& pool, const object_t& oid, const char *name, bufferlist& bl);
   int getxattrs(PoolCtx& pool, const object_t& oid, map<string, bufferlist>& attrset);
+  int rmxattr(PoolCtx& pool, const object_t& oid, const char *name);
 
   int list_pools(std::list<string>& ls);
   int get_pool_stats(std::list<string>& ls, map<string,pool_stat_t>& result);
@@ -1180,6 +1181,39 @@ int RadosClient::getxattr(PoolCtx& pool, const object_t& oid, const char *name,
   return bl.length();
 }
 
+int RadosClient::rmxattr(PoolCtx& pool, const object_t& oid, const char *name)
+{
+  utime_t ut = g_clock.now();
+
+  /* can't write to a snapshot */
+  if (pool.snap_seq != CEPH_NOSNAP)
+    return -EINVAL;
+
+  Mutex mylock("RadosClient::rmxattr::mylock");
+  Cond cond;
+  bool done;
+  int r;
+
+  Context *onack = new C_SafeCond(&mylock, &cond, &done, &r);
+
+  lock.Lock();
+  ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, pool.poolid);
+  objecter->removexattr(oid, layout, name,
+                 pool.snapc, ut, 0,
+                 onack, NULL);
+  lock.Unlock();
+
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+
+  if (r < 0)
+    return r;
+
+  return 0;
+}
+
 int RadosClient::setxattr(PoolCtx& pool, const object_t& oid, const char *name, bufferlist& bl)
 {
   utime_t ut = g_clock.now();
@@ -1457,6 +1491,14 @@ int Rados::setxattr(rados_pool_t pool, const string& o, const char *name, buffer
   return client->setxattr(*(RadosClient::PoolCtx *)pool, oid, name, bl);
 }
 
+int Rados::rmxattr(rados_pool_t pool, const string& o, const char *name)
+{
+  if (!client)
+    return -EINVAL;
+  object_t oid(o);
+  return client->rmxattr(*(RadosClient::PoolCtx *)pool, oid, name);
+}
+
 int Rados::stat(rados_pool_t pool, const string& o, uint64_t *psize, time_t *pmtime)
 {
   if (!client)
@@ -1983,6 +2025,13 @@ extern "C" int rados_setxattr(rados_pool_t pool, const char *o, const char *name
   return radosp->setxattr(*ctx, oid, name, bl);
 }
 
+extern "C" int rados_rmxattr(rados_pool_t pool, const char *o, const char *name)
+{
+  RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
+  object_t oid(o);
+  return radosp->rmxattr(*ctx, oid, name);
+}
+
 extern "C" int rados_stat(rados_pool_t pool, const char *o, uint64_t *psize, time_t *pmtime)
 {
   RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
index 279fb8fc64276567982f59e59ee91f10c939efa8..cd9e883d8ecdaba8cab85a1fc0319bc1ee93fae8 100644 (file)
@@ -726,7 +726,21 @@ private:
     o->snapc = snapc;
     return op_submit(o);
   }
-
+  tid_t removexattr(const object_t& oid, ceph_object_layout ol,
+             const char *name, const SnapContext& snapc,
+             utime_t mtime, int flags,
+              Context *onack, Context *oncommit) {
+    vector<OSDOp> ops(1);
+    ops[0].op.op = CEPH_OSD_OP_RMXATTR;
+    ops[0].op.xattr.name_len = (name ? strlen(name) : 0);
+    ops[0].op.xattr.value_len = 0;
+    if (name)
+      ops[0].data.append(name);
+    Op *o = new Op(oid, ol, ops, flags | CEPH_OSD_FLAG_WRITE, onack, oncommit);
+    o->mtime = mtime;
+    o->snapc = snapc;
+    return op_submit(o);
+  }
 
   void list_objects(ListContext *p, Context *onfinish);
 
index 67b6894eff4b2ae45de98a0bfd72d14a03acf687..c35f47abeb1bd75656ba1a64103eb99cf9487958 100644 (file)
@@ -50,6 +50,8 @@ void usage()
   cerr << "   listxattr objname\n";
   cerr << "   getxattr objname attr\n";
   cerr << "   setxattr objname attr val\n";
+  cerr << "   getxattr objname attr\n";
+  cerr << "   rmxattr objname attr\n";
   cerr << "   ls          -- list objects in pool\n\n";
   cerr << "   chown 123   -- change the pool owner to auid 123\n";
 
@@ -323,6 +325,18 @@ int main(int argc, const char **argv)
     }
     string s(bl.c_str(), bl.length());
     cout << s << std::endl;
+  } else if (strcmp(nargs[0], "rmxattr") == 0) {
+    if (!pool || nargs.size() < 3)
+      usage();
+
+    string oid(nargs[1]);
+    string attr_name(nargs[2]);
+
+    ret = rados.rmxattr(p, oid, attr_name.c_str());
+    if (ret < 0) {
+      cerr << "error removing xattr " << pool << "/" << oid << "/" << attr_name << ": " << strerror_r(-ret, buf, sizeof(buf)) << std::endl;
+      goto out;
+    }
   } else if (strcmp(nargs[0], "listxattr") == 0) {
     if (!pool || nargs.size() < 2)
       usage();