]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_rbd: include dumpers, test instances for our types
authorSage Weil <sage@inktank.com>
Sat, 16 Jun 2012 00:41:04 +0000 (17:41 -0700)
committerSage Weil <sage@inktank.com>
Tue, 19 Jun 2012 22:08:18 +0000 (15:08 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/Makefile.am
src/cls_rbd.cc
src/librbd/cls_rbd.h [new file with mode: 0644]
src/test/encoding/types.h

index a00aa829f093859c535e57eaec49ccbeccd7d17a..e3e9cf9ad165101f33dfe473e34220ba5daac30c 100644 (file)
@@ -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\
index 9641b230e3d0f64b4628fdfdedabfb682cb15bb0..7d9252b70c36306e422678c72993db68b61ca54d 100644 (file)
  * 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 <algorithm>
 #include <cstring>
 #include <cstdlib>
 #include <sstream>
 #include <vector>
 
+#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 (file)
index 0000000..c542d4f
--- /dev/null
@@ -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<cls_rbd_parent*>& 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<cls_rbd_snap*>& 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
index d8647ef12627c5ff6f98641b088979a97581c6db..c2b358b6e5c35705bdf2ca79c5fe7d28e44b7439 100644 (file)
@@ -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 ---