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