From: Jason Dillaman Date: Fri, 5 Feb 2016 04:42:25 +0000 (-0500) Subject: librbd: partial implementation of journal client / tag allocation X-Git-Tag: v10.0.4~28^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9418f055bd72f5838d95dadec07ae3cae8328de8;p=ceph.git librbd: partial implementation of journal client / tag allocation Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index 8454a390b5b..a5976716171 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -97,9 +97,9 @@ int Journal::create(librados::IoCtx &io_ctx, const std::string &image_id, CephContext *cct = reinterpret_cast(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::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; diff --git a/src/test/librbd/test_mock_Journal.cc b/src/test/librbd/test_mock_Journal.cc index 56fd1e62f4e..c849e6084c7 100644 --- a/src/test/librbd/test_mock_Journal.cc +++ b/src/test/librbd/test_mock_Journal.cc @@ -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);