Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / cls / rbd / cls_rbd.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef __CEPH_CLS_RBD_H
4 #define __CEPH_CLS_RBD_H
5
6 #include "include/types.h"
7 #include "include/buffer_fwd.h"
8 #include "include/rbd_types.h"
9 #include "common/Formatter.h"
10 #include "cls/rbd/cls_rbd_types.h"
11
12 /// information about our parent image, if any
13 struct cls_rbd_parent {
14   int64_t pool;        ///< parent pool id
15   string id;           ///< parent image id
16   snapid_t snapid;     ///< parent snapid we refer to
17   uint64_t overlap;    ///< portion of this image mapped onto parent (bytes)
18
19   /// true if our parent pointer information is defined
20   bool exists() const {
21     return snapid != CEPH_NOSNAP && pool >= 0 && id.length() > 0 && overlap > 0;
22   }
23
24   cls_rbd_parent() : pool(-1), snapid(CEPH_NOSNAP), overlap(0) {}
25
26   void encode(bufferlist& bl) const {
27     ENCODE_START(1, 1, bl);
28     ::encode(pool, bl);
29     ::encode(id, bl);
30     ::encode(snapid, bl);
31     ::encode(overlap, bl);
32     ENCODE_FINISH(bl);
33   }
34   void decode(bufferlist::iterator& bl) {
35     DECODE_START(1, bl);
36     ::decode(pool, bl);
37     ::decode(id, bl);
38     ::decode(snapid, bl);
39     ::decode(overlap, bl);
40     DECODE_FINISH(bl);
41   }
42   void dump(Formatter *f) const {
43     f->dump_int("pool", pool);
44     f->dump_string("id", id);
45     f->dump_unsigned("snapid", snapid);
46     f->dump_unsigned("overlap", overlap);
47   }
48   static void generate_test_instances(list<cls_rbd_parent*>& o) {
49     o.push_back(new cls_rbd_parent);
50     cls_rbd_parent *t = new cls_rbd_parent;
51     t->pool = 1;
52     t->id = "foo";
53     t->snapid = 3;
54     t->overlap = 500;
55     o.push_back(t);
56   }
57 };
58 WRITE_CLASS_ENCODER(cls_rbd_parent)
59
60 struct cls_rbd_snap {
61   snapid_t id;
62   string name;
63   uint64_t image_size;
64   uint64_t features;
65   uint8_t protection_status;
66   cls_rbd_parent parent;
67   uint64_t flags;
68   utime_t timestamp;
69   cls::rbd::SnapshotNamespaceOnDisk snapshot_namespace = {
70     cls::rbd::UserSnapshotNamespace{}};
71
72   /// true if we have a parent
73   bool has_parent() const {
74     return parent.exists();
75   }
76
77   cls_rbd_snap() : id(CEPH_NOSNAP), image_size(0), features(0),
78                    protection_status(RBD_PROTECTION_STATUS_UNPROTECTED),
79                    flags(0), timestamp(utime_t())
80     {}
81   void encode(bufferlist& bl) const {
82     ENCODE_START(6, 1, bl);
83     ::encode(id, bl);
84     ::encode(name, bl);
85     ::encode(image_size, bl);
86     ::encode(features, bl);
87     ::encode(parent, bl);
88     ::encode(protection_status, bl);
89     ::encode(flags, bl);
90     ::encode(snapshot_namespace, bl);
91     ::encode(timestamp, bl);
92     ENCODE_FINISH(bl);
93   }
94   void decode(bufferlist::iterator& p) {
95     DECODE_START(6, p);
96     ::decode(id, p);
97     ::decode(name, p);
98     ::decode(image_size, p);
99     ::decode(features, p);
100     if (struct_v >= 2) {
101       ::decode(parent, p);
102     }
103     if (struct_v >= 3) {
104       ::decode(protection_status, p);
105     }
106     if (struct_v >= 4) {
107       ::decode(flags, p);
108     }
109     if (struct_v >= 5) {
110       ::decode(snapshot_namespace, p);
111     }
112     if (struct_v >= 6) {
113       ::decode(timestamp, p);
114     }
115     DECODE_FINISH(p);
116   }
117   void dump(Formatter *f) const {
118     f->dump_unsigned("id", id);
119     f->dump_string("name", name);
120     f->dump_unsigned("image_size", image_size);
121     f->dump_unsigned("features", features);
122     if (has_parent()) {
123       f->open_object_section("parent");
124       parent.dump(f);
125       f->close_section();
126     }
127     switch (protection_status) {
128     case RBD_PROTECTION_STATUS_UNPROTECTED:
129       f->dump_string("protection_status", "unprotected");
130       break;
131     case RBD_PROTECTION_STATUS_UNPROTECTING:
132       f->dump_string("protection_status", "unprotecting");
133       break;
134     case RBD_PROTECTION_STATUS_PROTECTED:
135       f->dump_string("protection_status", "protected");
136       break;
137     default:
138       ceph_abort();
139     }
140   }
141   static void generate_test_instances(list<cls_rbd_snap*>& o) {
142     o.push_back(new cls_rbd_snap);
143     cls_rbd_snap *t = new cls_rbd_snap;
144     t->id = 1;
145     t->name = "snap";
146     t->image_size = 123456;
147     t->features = 123;
148     t->flags = 31;
149     o.push_back(t);
150     t = new cls_rbd_snap;
151     t->id = 2;
152     t->name = "snap2";
153     t->image_size = 12345678;
154     t->features = 1234;
155     t->parent.pool = 1;
156     t->parent.id = "parent";
157     t->parent.snapid = 456;
158     t->parent.overlap = 12345;
159     t->protection_status = RBD_PROTECTION_STATUS_PROTECTED;
160     t->flags = 14;
161     t->timestamp = utime_t();
162     o.push_back(t);
163   }
164 };
165 WRITE_CLASS_ENCODER(cls_rbd_snap)
166
167 #endif