From 4e73ca4532215ca1d5f60d107f2b5a4f002e13d3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 15 Jun 2012 17:41:04 -0700 Subject: [PATCH] cls_rbd: include dumpers, test instances for our types Signed-off-by: Sage Weil --- src/Makefile.am | 1 + src/cls_rbd.cc | 82 +++----------------------- src/librbd/cls_rbd.h | 121 ++++++++++++++++++++++++++++++++++++++ src/test/encoding/types.h | 4 ++ 4 files changed, 133 insertions(+), 75 deletions(-) create mode 100644 src/librbd/cls_rbd.h diff --git a/src/Makefile.am b/src/Makefile.am index a00aa829f0938..e3e9cf9ad1651 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1369,6 +1369,7 @@ noinst_HEADERS = \ librados/IoCtxImpl.h\ librados/PoolAsyncCompletionImpl.h\ librados/RadosClient.h\ + librbd/cls_rbd.h\ librbd/cls_rbd_client.h\ librbd/LibrbdWriteback.h\ logrotate.conf\ diff --git a/src/cls_rbd.cc b/src/cls_rbd.cc index 9641b230e3d0f..7d9252b70c363 100644 --- a/src/cls_rbd.cc +++ b/src/cls_rbd.cc @@ -26,11 +26,6 @@ * in each one that they take an input and an output bufferlist. */ -#include "include/types.h" -#include "objclass/objclass.h" - -#include "include/rbd_types.h" - #include #include #include @@ -40,6 +35,13 @@ #include #include +#include "include/types.h" +#include "objclass/objclass.h" +#include "include/rbd_types.h" + +#include "librbd/cls_rbd.h" + + CLS_VER(2,0) CLS_NAME(rbd) @@ -76,76 +78,6 @@ cls_method_handle_t h_assign_bid; #define RBD_LOCK_SHARED "shared" -/// information about our parent image, if any -struct cls_rbd_parent { - int64_t pool; ///< parent pool id - string id; ///< parent image id - snapid_t snapid; ///< parent snapid we refer to - uint64_t overlap; ///< portion of this image mapped onto parent - - /// true if our parent pointer information is defined - bool exists() const { - return snapid != CEPH_NOSNAP && pool >= 0 && id.length() > 0; - } - - cls_rbd_parent() : pool(-1), snapid(CEPH_NOSNAP), size(0) {} - - void encode(bufferlist& bl) const { - ENCODE_START(1, 1, bl); - ::encode(pool, bl); - ::encode(id, bl); - ::encode(snapid, bl); - ::encode(overlap, bl); - ENCODE_FINISH(bl); - } - void decode(bufferlist::iterator& bl) { - DECODE_START(1, bl); - ::decode(pool, bl); - ::decode(id, bl); - ::decode(snapid, bl); - ::decode(overlap, bl); - DECODE_FINISH(bl); - } -}; -WRITE_CLASS_ENCODER(cls_rbd_parent) - -struct cls_rbd_snap { - snapid_t id; - string name; - uint64_t image_size; - uint64_t features; - cls_rbd_parent parent; - - /// true if we have a parent - bool has_parent() const { - return parent.exists(); - } - - cls_rbd_snap() : id(CEPH_NOSNAP), image_size(0), features(0) {} - void encode(bufferlist& bl) const { - ENCODE_START(2, 1, bl); - ::encode(id, bl); - ::encode(name, bl); - ::encode(image_size, bl); - ::encode(features, bl); - ::encode(parent, bl); - ENCODE_FINISH(bl); - } - void decode(bufferlist::iterator& p) { - DECODE_START(2, p); - ::decode(id, p); - ::decode(name, p); - ::decode(image_size, p); - ::decode(features, p); - if (struct_v >= 2) { - ::decode(parent, p); - } - DECODE_FINISH(p); - } -}; -WRITE_CLASS_ENCODER(cls_rbd_snap) - - static int snap_read_header(cls_method_context_t hctx, bufferlist& bl) { unsigned snap_count = 0; diff --git a/src/librbd/cls_rbd.h b/src/librbd/cls_rbd.h new file mode 100644 index 0000000000000..c542d4fd7d0dd --- /dev/null +++ b/src/librbd/cls_rbd.h @@ -0,0 +1,121 @@ +#ifndef __CEPH_CLS_RBD_H +#define __CEPH_CLS_RBD_H + +#include "include/types.h" +#include "include/buffer.h" +#include "common/Formatter.h" + +/// information about our parent image, if any +struct cls_rbd_parent { + int64_t pool; ///< parent pool id + string id; ///< parent image id + snapid_t snapid; ///< parent snapid we refer to + uint64_t overlap; ///< portion of this image mapped onto parent + + /// true if our parent pointer information is defined + bool exists() const { + return snapid != CEPH_NOSNAP && pool >= 0 && id.length() > 0; + } + + cls_rbd_parent() : pool(-1), snapid(CEPH_NOSNAP), overlap(0) {} + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(pool, bl); + ::encode(id, bl); + ::encode(snapid, bl); + ::encode(overlap, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(pool, bl); + ::decode(id, bl); + ::decode(snapid, bl); + ::decode(overlap, bl); + DECODE_FINISH(bl); + } + void dump(Formatter *f) const { + f->dump_int("pool", pool); + f->dump_string("id", id); + f->dump_unsigned("snapid", snapid); + f->dump_unsigned("overlap", overlap); + } + static void generate_test_instances(list& o) { + o.push_back(new cls_rbd_parent); + cls_rbd_parent *t = new cls_rbd_parent; + t->pool = 1; + t->id = "foo"; + t->snapid = 3; + o.push_back(t); + } +}; +WRITE_CLASS_ENCODER(cls_rbd_parent) + +struct cls_rbd_snap { + snapid_t id; + string name; + uint64_t image_size; + uint64_t features; + cls_rbd_parent parent; + + /// true if we have a parent + bool has_parent() const { + return parent.exists(); + } + + cls_rbd_snap() : id(CEPH_NOSNAP), image_size(0), features(0) {} + void encode(bufferlist& bl) const { + ENCODE_START(2, 1, bl); + ::encode(id, bl); + ::encode(name, bl); + ::encode(image_size, bl); + ::encode(features, bl); + ::encode(parent, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& p) { + DECODE_START(2, p); + ::decode(id, p); + ::decode(name, p); + ::decode(image_size, p); + ::decode(features, p); + if (struct_v >= 2) { + ::decode(parent, p); + } + DECODE_FINISH(p); + } + void dump(Formatter *f) const { + f->dump_unsigned("id", id); + f->dump_string("name", name); + f->dump_unsigned("image_size", image_size); + f->dump_unsigned("features", features); + if (has_parent()) { + f->open_object_section("parent"); + parent.dump(f); + f->close_section(); + } + } + static void generate_test_instances(list& o) { + o.push_back(new cls_rbd_snap); + cls_rbd_snap *t = new cls_rbd_snap; + t->id = 1; + t->name = "snap"; + t->image_size = 123456; + t->features = 123; + o.push_back(t); + t = new cls_rbd_snap; + t->id = 2; + t->name = "snap2"; + t->image_size = 12345678; + t->features = 1234; + t->parent.pool = 1; + t->parent.id = "parent"; + t->parent.snapid = 456; + t->parent.overlap = 12345; + o.push_back(t); + } +}; +WRITE_CLASS_ENCODER(cls_rbd_snap) + +#endif diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index d8647ef12627c..c2b358b6e5c35 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -132,6 +132,10 @@ TYPE(rgw_obj) TYPE(rgw_log_entry) TYPE(rgw_intent_log_entry) +#include "librbd/cls_rbd.h" +TYPE(cls_rbd_parent) +TYPE(cls_rbd_snap) + #endif // --- messages --- -- 2.39.5