From: Jason Dillaman Date: Thu, 25 Feb 2016 19:43:37 +0000 (-0500) Subject: librbd: update journal client and tag data structures X-Git-Tag: v10.1.0~187^2~11 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=dbcbaa6e5c4ec89d5d207cab360f0932007f864f;p=ceph-ci.git librbd: update journal client and tag data structures The mirror peer now holds remote's image id as well as a collection of bootstrap sync points. The tag now contains uuids to map back to the owning pool. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index c07ba02b9f7..af82c6cf5fb 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -119,16 +119,9 @@ int Journal::create(librados::IoCtx &io_ctx, const std::string &image_id, return r; } - 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); + ::encode(journal::TagData(), tag_data); C_SaferCond tag_ctx; cls::journal::Tag tag; diff --git a/src/librbd/journal/Types.cc b/src/librbd/journal/Types.cc index f082e0268c8..2be074d267a 100644 --- a/src/librbd/journal/Types.cc +++ b/src/librbd/journal/Types.cc @@ -333,25 +333,49 @@ void ImageClientMeta::dump(Formatter *f) const { f->dump_unsigned("tag_class", tag_class); } +void MirrorPeerSyncPoint::encode(bufferlist& bl) const { + ::encode(snap_name, bl); + ::encode(object_number, bl); +} + +void MirrorPeerSyncPoint::decode(__u8 version, bufferlist::iterator& it) { + ::decode(snap_name, it); + ::decode(object_number, it); +} + +void MirrorPeerSyncPoint::dump(Formatter *f) const { + f->dump_string("snap_name", snap_name); + if (object_number) { + f->dump_unsigned("object_number", *object_number); + } +} + void MirrorPeerClientMeta::encode(bufferlist& bl) const { - ::encode(cluster_id, bl); - ::encode(pool_id, bl); ::encode(image_id, bl); - ::encode(snap_name, bl); + ::encode(static_cast(sync_points.size()), bl); + for (auto &sync_point : sync_points) { + sync_point.encode(bl); + } } void MirrorPeerClientMeta::decode(__u8 version, bufferlist::iterator& it) { - ::decode(cluster_id, it); - ::decode(pool_id, it); ::decode(image_id, it); - ::decode(snap_name, it); + + uint32_t sync_point_count; + ::decode(sync_point_count, it); + sync_points.resize(sync_point_count); + for (auto &sync_point : sync_points) { + sync_point.decode(version, it); + } } void MirrorPeerClientMeta::dump(Formatter *f) const { - f->dump_string("cluster_id", cluster_id.c_str()); - f->dump_int("pool_id", pool_id); - f->dump_string("image_id", image_id.c_str()); - f->dump_string("snap_name", snap_name.c_str()); + f->dump_string("image_id", image_id); + f->open_array_section("sync_points"); + for (auto &sync_point : sync_points) { + sync_point.dump(f); + } + f->close_section(); } void CliClientMeta::encode(bufferlist& bl) const { @@ -417,39 +441,41 @@ void ClientData::generate_test_instances(std::list &o) { o.push_back(new ClientData(ImageClientMeta())); o.push_back(new ClientData(ImageClientMeta(123))); o.push_back(new ClientData(MirrorPeerClientMeta())); - o.push_back(new ClientData(MirrorPeerClientMeta("cluster_id", 123, "image_id"))); + o.push_back(new ClientData(MirrorPeerClientMeta("image_id", {{"snap 1", 123}}))); o.push_back(new ClientData(CliClientMeta())); } // Journal Tag void TagData::encode(bufferlist& bl) const { - ::encode(cluster_id, bl); - ::encode(pool_id, bl); - ::encode(image_id, bl); + ::encode(mirror_uuid, bl); + ::encode(predecessor_mirror_uuid, bl); + ::encode(predecessor_commit_valid, bl); ::encode(predecessor_tag_tid, bl); ::encode(predecessor_entry_tid, bl); } void TagData::decode(bufferlist::iterator& it) { - ::decode(cluster_id, it); - ::decode(pool_id, it); - ::decode(image_id, it); + ::decode(mirror_uuid, it); + ::decode(predecessor_mirror_uuid, it); + ::decode(predecessor_commit_valid, it); ::decode(predecessor_tag_tid, it); ::decode(predecessor_entry_tid, it); } void TagData::dump(Formatter *f) const { - f->dump_string("cluster_id", cluster_id.c_str()); - f->dump_int("pool_id", pool_id); - f->dump_string("image_id", image_id.c_str()); + f->dump_string("mirror_uuid", mirror_uuid); + f->dump_string("predecessor_mirror_uuid", predecessor_mirror_uuid); + f->dump_string("predecessor_commit_valid", + predecessor_commit_valid ? "true" : "false"); f->dump_unsigned("predecessor_tag_tid", predecessor_tag_tid); f->dump_unsigned("predecessor_entry_tid", predecessor_entry_tid); } void TagData::generate_test_instances(std::list &o) { o.push_back(new TagData()); - o.push_back(new TagData("cluster_id", 123, "image_id")); + o.push_back(new TagData("mirror-uuid")); + o.push_back(new TagData("mirror-uuid", "remote-mirror-uuid", true, 123, 234)); } } // namespace journal diff --git a/src/librbd/journal/Types.h b/src/librbd/journal/Types.h index 5e3a5c0e161..e355060065b 100644 --- a/src/librbd/journal/Types.h +++ b/src/librbd/journal/Types.h @@ -9,6 +9,9 @@ #include "include/encoding.h" #include "include/types.h" #include +#include +#include +#include #include namespace ceph { @@ -316,21 +319,37 @@ struct ImageClientMeta { void dump(Formatter *f) const; }; +struct MirrorPeerSyncPoint { + typedef boost::optional ObjectNumber; + + std::string snap_name; + ObjectNumber object_number; + + MirrorPeerSyncPoint() : object_number(boost::none) { + } + MirrorPeerSyncPoint(const std::string &snap_name, + const ObjectNumber &object_number) + : snap_name(snap_name), object_number(object_number) { + } + + void encode(bufferlist& bl) const; + void decode(__u8 version, bufferlist::iterator& it); + void dump(Formatter *f) const; +}; + struct MirrorPeerClientMeta { + typedef std::list SyncPoints; + static const ClientMetaType TYPE = MIRROR_PEER_CLIENT_META_TYPE; - std::string cluster_id; - int64_t pool_id = 0; std::string image_id; - std::string snap_name; + SyncPoints sync_points; MirrorPeerClientMeta() { } - MirrorPeerClientMeta(const std::string &cluster_id, int64_t pool_id, - const std::string &image_id, - const std::string &snap_name = "") - : cluster_id(cluster_id), pool_id(pool_id), image_id(image_id), - snap_name(snap_name) { + MirrorPeerClientMeta(const std::string &image_id, + const SyncPoints &sync_points = SyncPoints()) + : image_id(image_id), sync_points(sync_points) { } void encode(bufferlist& bl) const; @@ -380,19 +399,27 @@ struct ClientData { struct TagData { // owner of the tag (exclusive lock epoch) - std::string cluster_id; - int64_t pool_id = 0; - std::string image_id; + std::string mirror_uuid; // empty if local // mapping to last committed record of previous tag + std::string predecessor_mirror_uuid; // empty if local + bool predecessor_commit_valid = false; uint64_t predecessor_tag_tid = 0; uint64_t predecessor_entry_tid = 0; TagData() { } - TagData(const std::string &cluster_id, int64_t pool_id, - const std::string &image_id) - : cluster_id(cluster_id), pool_id(pool_id), image_id(image_id) { + TagData(const std::string &mirror_uuid) : mirror_uuid(mirror_uuid) { + } + TagData(const std::string &mirror_uuid, + const std::string &predecessor_mirror_uuid, + bool predecessor_commit_valid, + uint64_t predecessor_tag_tid, uint64_t predecessor_entry_tid) + : mirror_uuid(mirror_uuid), + predecessor_mirror_uuid(predecessor_mirror_uuid), + predecessor_commit_valid(predecessor_commit_valid), + predecessor_tag_tid(predecessor_tag_tid), + predecessor_entry_tid(predecessor_entry_tid) { } void encode(bufferlist& bl) const;