]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_rbd_client: Add cls rbd client interface to support rbd metadata
authorHaomai Wang <haomaiwang@gmail.com>
Mon, 9 Mar 2015 02:40:54 +0000 (10:40 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Fri, 13 Mar 2015 14:51:34 +0000 (22:51 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/cls/rbd/cls_rbd_client.cc
src/cls/rbd/cls_rbd_client.h

index 0ccf405175921da1b5658c45bf1becf36e7ee764..bd6f78921c949e70beae5edd300a84f9bb632336 100644 (file)
@@ -749,5 +749,42 @@ namespace librbd {
       rados_op->exec("rbd", "object_map_update", in);
     }
 
+    int metadata_set(librados::IoCtx *ioctx, const std::string &oid,
+                     const std::string &key, const std::string &data)
+    {
+      bufferlist in;
+      ::encode(key, in);
+      ::encode(data, in);
+      bufferlist out;
+      return ioctx->exec(oid, "rbd", "metadata_set", in, out);
+    }
+
+    int metadata_remove(librados::IoCtx *ioctx, const std::string &oid,
+                        const std::string &key)
+    {
+      bufferlist in;
+      ::encode(key, in);
+      bufferlist out;
+      return ioctx->exec(oid, "rbd", "metadata_remove", in, out);
+    }
+
+    int metadata_list(librados::IoCtx *ioctx, const std::string &oid,
+                     map<string, string> *pairs)
+    {
+      assert(pairs);
+      bufferlist in, out;
+      int r = ioctx->exec(oid, "rbd", "metadata_list", in, out);
+      if (r < 0)
+        return r;
+
+      bufferlist::iterator iter = out.begin();
+      try {
+        ::decode(*pairs, iter);
+      } catch (const buffer::error &err) {
+        return -EBADMSG;
+      }
+
+      return 0;
+    }
   } // namespace cls_client
 } // namespace librbd
index bf5b9693a01b696e878ee18cb1fad9ce244716bc..c3a44bfc2cdde1314636893b9eaec6cbd98cbf0d 100644 (file)
@@ -119,6 +119,14 @@ namespace librbd {
                           uint8_t new_object_state,
                           const boost::optional<uint8_t> &current_object_state);
 
+    // operations on the rbd_object_map.$image_id object
+    int metadata_set(librados::IoCtx *ioctx, const std::string &oid,
+                     const std::string &key, const std::string &data);
+    int metadata_remove(librados::IoCtx *ioctx, const std::string &oid,
+                        const std::string &key);
+    int metadata_list(librados::IoCtx *ioctx, const std::string &oid,
+                      map<string, string> *pairs);
+
     // class operations on the old format, kept for
     // backwards compatability
     int old_snapshot_add(librados::IoCtx *ioctx, const std::string &oid,