]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: partial implementation of journal client / tag allocation 7529/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 5 Feb 2016 04:42:25 +0000 (23:42 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 5 Feb 2016 20:21:28 +0000 (15:21 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/Journal.cc
src/test/librbd/test_mock_Journal.cc

index 8454a390b5be57a36ace71896dc3341aadacbd74..a5976716171f47e19627cb2ff5c6401308136cfb 100644 (file)
@@ -97,9 +97,9 @@ int Journal<I>::create(librados::IoCtx &io_ctx, const std::string &image_id,
   CephContext *cct = reinterpret_cast<CephContext *>(io_ctx.cct());
   ldout(cct, 5) << __func__ << ": image=" << image_id << dendl;
 
+  librados::Rados rados(io_ctx);
   int64_t pool_id = -1;
   if (!object_pool.empty()) {
-    librados::Rados rados(io_ctx);
     IoCtx data_io_ctx;
     int r = rados.ioctx_create(object_pool.c_str(), data_io_ctx);
     if (r != 0) {
@@ -119,8 +119,32 @@ int Journal<I>::create(librados::IoCtx &io_ctx, const std::string &image_id,
     return r;
   }
 
-  // TODO register with librbd payload
-  r = journaler.register_client(bufferlist());
+  std::string cluster_id;
+  r = rados.cluster_fsid(&cluster_id);
+  if (r < 0) {
+    lderr(cct) << "failed to retrieve cluster id: " << cpp_strerror(r) << dendl;
+    return r;
+  }
+
+  // create tag class for this image's journal events
+  bufferlist tag_data;
+  ::encode(journal::TagData{cluster_id, pool_id, image_id}, tag_data);
+
+  C_SaferCond tag_ctx;
+  cls::journal::Tag tag;
+  journaler.allocate_tag(cls::journal::Tag::TAG_CLASS_NEW, tag_data,
+                         &tag, &tag_ctx);
+  r = tag_ctx.wait();
+  if (r < 0) {
+    lderr(cct) << "failed to allocate journal tag: " << cpp_strerror(r)
+               << dendl;
+  }
+
+  bufferlist client_data;
+  ::encode(journal::ClientData{journal::ImageClientMeta{tag.tag_class}},
+           client_data);
+
+  r = journaler.register_client(client_data);
   if (r < 0) {
     lderr(cct) << "failed to register client: " << cpp_strerror(r) << dendl;
     return r;
index 56fd1e62f4ee79fedcc8f880de4579fc024baab5..c849e6084c77ed8cdd9cb8064e537b05c3beb6e1 100644 (file)
@@ -6,6 +6,7 @@
 #include "test/librbd/mock/MockImageCtx.h"
 #include "common/Cond.h"
 #include "common/Mutex.h"
+#include "cls/journal/cls_journal_types.h"
 #include "librbd/Journal.h"
 #include "librbd/Utils.h"
 #include "librbd/journal/Replay.h"
@@ -119,6 +120,10 @@ struct MockJournalerProxy {
   int register_client(const bufferlist &data) {
     return -EINVAL;
   }
+  void allocate_tag(uint64_t, const bufferlist &,
+                    cls::journal::Tag*, Context *on_finish) {
+    on_finish->complete(-EINVAL);
+  }
 
   void get_metadata(uint8_t *order, uint8_t *splay_width, int64_t *pool_id) {
     MockJournaler::get_instance().get_metadata(order, splay_width, pool_id);