From 3589809b7b2a494809d2322c9b3286526c1006f0 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 16 Jan 2018 12:01:34 -0500 Subject: [PATCH] cls/rbd: add child reference counter to snapshot Signed-off-by: Jason Dillaman --- src/cls/rbd/cls_rbd.cc | 2 +- src/cls/rbd/cls_rbd.h | 23 +++++++++++++---------- src/cls/rbd/cls_rbd_types.cc | 8 +++++--- src/cls/rbd/cls_rbd_types.h | 6 ++++-- src/librbd/image/RefreshRequest.cc | 4 ++-- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/cls/rbd/cls_rbd.cc b/src/cls/rbd/cls_rbd.cc index cd53eafc7df..301a8540bde 100644 --- a/src/cls/rbd/cls_rbd.cc +++ b/src/cls/rbd/cls_rbd.cc @@ -1709,7 +1709,7 @@ int snapshot_get(cls_method_context_t hctx, bufferlist *in, bufferlist *out) cls::rbd::SnapshotInfo snapshot_info{snap.id, snap.snapshot_namespace, snap.name, snap.image_size, - snap.timestamp}; + snap.timestamp, snap.child_count}; encode(snapshot_info, *out); return 0; } diff --git a/src/cls/rbd/cls_rbd.h b/src/cls/rbd/cls_rbd.h index 970ec1dee5d..72a8152d6bb 100644 --- a/src/cls/rbd/cls_rbd.h +++ b/src/cls/rbd/cls_rbd.h @@ -59,27 +59,24 @@ struct cls_rbd_parent { WRITE_CLASS_ENCODER(cls_rbd_parent) struct cls_rbd_snap { - snapid_t id; + snapid_t id = CEPH_NOSNAP; string name; - uint64_t image_size; - uint8_t protection_status; + uint64_t image_size = 0; + uint8_t protection_status = RBD_PROTECTION_STATUS_UNPROTECTED; cls_rbd_parent parent; - uint64_t flags; + uint64_t flags = 0; utime_t timestamp; cls::rbd::SnapshotNamespace snapshot_namespace = { cls::rbd::UserSnapshotNamespace{}}; + uint32_t child_count = 0; /// true if we have a parent bool has_parent() const { return parent.exists(); } - cls_rbd_snap() : id(CEPH_NOSNAP), image_size(0), - protection_status(RBD_PROTECTION_STATUS_UNPROTECTED), - flags(0), timestamp(utime_t()) - {} void encode(bufferlist& bl) const { - ENCODE_START(6, 1, bl); + ENCODE_START(7, 1, bl); encode(id, bl); encode(name, bl); encode(image_size, bl); @@ -90,10 +87,11 @@ struct cls_rbd_snap { encode(flags, bl); encode(snapshot_namespace, bl); encode(timestamp, bl); + encode(child_count, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& p) { - DECODE_START(6, p); + DECODE_START(7, p); decode(id, p); decode(name, p); decode(image_size, p); @@ -114,6 +112,9 @@ struct cls_rbd_snap { if (struct_v >= 6) { decode(timestamp, p); } + if (struct_v >= 7) { + decode(child_count, p); + } DECODE_FINISH(p); } void dump(Formatter *f) const { @@ -138,6 +139,7 @@ struct cls_rbd_snap { default: ceph_abort(); } + f->dump_unsigned("child_count", child_count); } static void generate_test_instances(list& o) { o.push_back(new cls_rbd_snap); @@ -146,6 +148,7 @@ struct cls_rbd_snap { t->name = "snap"; t->image_size = 123456; t->flags = 31; + t->child_count = 543; o.push_back(t); t = new cls_rbd_snap; t->id = 2; diff --git a/src/cls/rbd/cls_rbd_types.cc b/src/cls/rbd/cls_rbd_types.cc index a6390eb25f7..c6f5196a06e 100644 --- a/src/cls/rbd/cls_rbd_types.cc +++ b/src/cls/rbd/cls_rbd_types.cc @@ -436,6 +436,7 @@ void SnapshotInfo::encode(bufferlist& bl) const { encode(name, bl); encode(image_size, bl); encode(timestamp, bl); + encode(child_count, bl); ENCODE_FINISH(bl); } @@ -446,6 +447,7 @@ void SnapshotInfo::decode(bufferlist::iterator& it) { decode(name, it); decode(image_size, it); decode(timestamp, it); + decode(child_count, it); DECODE_FINISH(it); } @@ -462,12 +464,12 @@ void SnapshotInfo::dump(Formatter *f) const { void SnapshotInfo::generate_test_instances(std::list &o) { o.push_back(new SnapshotInfo(1ULL, UserSnapshotNamespace{}, "snap1", 123, - {123456, 0})); + {123456, 0}, 12)); o.push_back(new SnapshotInfo(2ULL, GroupSnapshotNamespace{567, "group1", "snap1"}, - "snap1", 123, {123456, 0})); + "snap1", 123, {123456, 0}, 987)); o.push_back(new SnapshotInfo(3ULL, TrashSnapshotNamespace{"snap1"}, - "12345", 123, {123456, 0})); + "12345", 123, {123456, 0}, 429)); } void SnapshotNamespace::encode(bufferlist& bl) const { diff --git a/src/cls/rbd/cls_rbd_types.h b/src/cls/rbd/cls_rbd_types.h index 78dde1a6f5e..2d2a2a138db 100644 --- a/src/cls/rbd/cls_rbd_types.h +++ b/src/cls/rbd/cls_rbd_types.h @@ -376,15 +376,17 @@ struct SnapshotInfo { std::string name; uint64_t image_size = 0; utime_t timestamp; + uint32_t child_count = 0; SnapshotInfo() { } SnapshotInfo(snapid_t id, const cls::rbd::SnapshotNamespace& snapshot_namespace, const std::string& name, uint64_t image_size, - const utime_t& timestamp) + const utime_t& timestamp, uint32_t child_count) : id(id), snapshot_namespace(snapshot_namespace), - name(name), image_size(image_size), timestamp(timestamp) { + name(name), image_size(image_size), timestamp(timestamp), + child_count(child_count) { } void encode(bufferlist& bl) const; diff --git a/src/librbd/image/RefreshRequest.cc b/src/librbd/image/RefreshRequest.cc index 0d225f8ec8a..94363fc8ddf 100644 --- a/src/librbd/image/RefreshRequest.cc +++ b/src/librbd/image/RefreshRequest.cc @@ -157,7 +157,7 @@ Context *RefreshRequest::handle_v1_get_snapshots(int *result) { for (size_t i = 0; i < m_snapc.snaps.size(); ++i) { m_snap_infos.push_back({m_snapc.snaps[i], {cls::rbd::UserSnapshotNamespace{}}, - snap_names[i], snap_sizes[i], {}}); + snap_names[i], snap_sizes[i], {}, 0}); } send_v1_get_locks(); @@ -600,7 +600,7 @@ Context *RefreshRequest::handle_v2_get_snapshots_legacy(int *result) { for (size_t i = 0; i < m_snapc.snaps.size(); ++i) { m_snap_infos.push_back({m_snapc.snaps[i], {cls::rbd::UserSnapshotNamespace{}}, - snap_names[i], snap_sizes[i], {}}); + snap_names[i], snap_sizes[i], {}, 0}); } send_v2_get_snap_timestamps(); -- 2.39.5