]> git.proxmox.com Git - ceph.git/blame - ceph/src/cls/rbd/cls_rbd_types.h
update sources to v12.2.3
[ceph.git] / ceph / src / cls / rbd / cls_rbd_types.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_CLS_RBD_TYPES_H
5#define CEPH_CLS_RBD_TYPES_H
6
7#include <boost/variant.hpp>
8#include "include/int_types.h"
9#include "include/buffer.h"
10#include "include/encoding.h"
11#include "include/stringify.h"
12#include "include/utime.h"
13#include <iosfwd>
14#include <string>
15
16#define RBD_GROUP_REF "rbd_group_ref"
17
18namespace ceph { class Formatter; }
19
20namespace cls {
21namespace rbd {
22
23static const uint32_t MAX_OBJECT_MAP_OBJECT_COUNT = 256000000;
24static const string RBD_GROUP_IMAGE_KEY_PREFIX = "image_";
25
26enum MirrorMode {
27 MIRROR_MODE_DISABLED = 0,
28 MIRROR_MODE_IMAGE = 1,
29 MIRROR_MODE_POOL = 2
30};
31
32enum GroupImageLinkState {
33 GROUP_IMAGE_LINK_STATE_ATTACHED,
34 GROUP_IMAGE_LINK_STATE_INCOMPLETE
35};
36
37inline void encode(const GroupImageLinkState &state, bufferlist& bl,
38 uint64_t features=0)
39{
40 ::encode(static_cast<uint8_t>(state), bl);
41}
42
43inline void decode(GroupImageLinkState &state, bufferlist::iterator& it)
44{
45 uint8_t int_state;
46 ::decode(int_state, it);
47 state = static_cast<GroupImageLinkState>(int_state);
48}
49
50struct MirrorPeer {
51 MirrorPeer() {
52 }
53 MirrorPeer(const std::string &uuid, const std::string &cluster_name,
54 const std::string &client_name, int64_t pool_id)
55 : uuid(uuid), cluster_name(cluster_name), client_name(client_name),
56 pool_id(pool_id) {
57 }
58
59 std::string uuid;
60 std::string cluster_name;
61 std::string client_name;
62 int64_t pool_id = -1;
63
64 inline bool is_valid() const {
65 return (!uuid.empty() && !cluster_name.empty() && !client_name.empty());
66 }
67
68 void encode(bufferlist &bl) const;
69 void decode(bufferlist::iterator &it);
70 void dump(Formatter *f) const;
71
72 static void generate_test_instances(std::list<MirrorPeer*> &o);
73
74 bool operator==(const MirrorPeer &rhs) const;
75};
76
77std::ostream& operator<<(std::ostream& os, const MirrorMode& mirror_mode);
78std::ostream& operator<<(std::ostream& os, const MirrorPeer& peer);
79
80WRITE_CLASS_ENCODER(MirrorPeer);
81
82enum MirrorImageState {
83 MIRROR_IMAGE_STATE_DISABLING = 0,
84 MIRROR_IMAGE_STATE_ENABLED = 1,
85 MIRROR_IMAGE_STATE_DISABLED = 2,
86};
87
88struct MirrorImage {
89 MirrorImage() {}
90 MirrorImage(const std::string &global_image_id, MirrorImageState state)
91 : global_image_id(global_image_id), state(state) {}
92
93 std::string global_image_id;
94 MirrorImageState state = MIRROR_IMAGE_STATE_DISABLING;
95
96 void encode(bufferlist &bl) const;
97 void decode(bufferlist::iterator &it);
98 void dump(Formatter *f) const;
99
100 static void generate_test_instances(std::list<MirrorImage*> &o);
101
102 bool operator==(const MirrorImage &rhs) const;
103 bool operator<(const MirrorImage &rhs) const;
104};
105
106std::ostream& operator<<(std::ostream& os, const MirrorImageState& mirror_state);
107std::ostream& operator<<(std::ostream& os, const MirrorImage& mirror_image);
108
109WRITE_CLASS_ENCODER(MirrorImage);
110
111enum MirrorImageStatusState {
112 MIRROR_IMAGE_STATUS_STATE_UNKNOWN = 0,
113 MIRROR_IMAGE_STATUS_STATE_ERROR = 1,
114 MIRROR_IMAGE_STATUS_STATE_SYNCING = 2,
115 MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY = 3,
116 MIRROR_IMAGE_STATUS_STATE_REPLAYING = 4,
117 MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY = 5,
118 MIRROR_IMAGE_STATUS_STATE_STOPPED = 6,
119};
120
121inline void encode(const MirrorImageStatusState &state, bufferlist& bl,
122 uint64_t features=0)
123{
124 ::encode(static_cast<uint8_t>(state), bl);
125}
126
127inline void decode(MirrorImageStatusState &state, bufferlist::iterator& it)
128{
129 uint8_t int_state;
130 ::decode(int_state, it);
131 state = static_cast<MirrorImageStatusState>(int_state);
132}
133
134struct MirrorImageStatus {
135 MirrorImageStatus() {}
136 MirrorImageStatus(MirrorImageStatusState state,
137 const std::string &description = "")
138 : state(state), description(description) {}
139
140 MirrorImageStatusState state = MIRROR_IMAGE_STATUS_STATE_UNKNOWN;
141 std::string description;
142 utime_t last_update;
143 bool up = false;
144
145 void encode(bufferlist &bl) const;
146 void decode(bufferlist::iterator &it);
147 void dump(Formatter *f) const;
148
149 std::string state_to_string() const;
150
151 static void generate_test_instances(std::list<MirrorImageStatus*> &o);
152
153 bool operator==(const MirrorImageStatus &rhs) const;
154};
155
156std::ostream& operator<<(std::ostream& os, const MirrorImageStatus& status);
157std::ostream& operator<<(std::ostream& os, const MirrorImageStatusState& state);
158
159WRITE_CLASS_ENCODER(MirrorImageStatus);
160
161struct GroupImageSpec {
162 GroupImageSpec() {}
163
164 GroupImageSpec(const std::string &image_id, int64_t pool_id)
165 : image_id(image_id), pool_id(pool_id) {}
166
167 static int from_key(const std::string &image_key, GroupImageSpec *spec);
168
169 std::string image_id;
170 int64_t pool_id = -1;
171
172 void encode(bufferlist &bl) const;
173 void decode(bufferlist::iterator &it);
174 void dump(Formatter *f) const;
175
176 std::string image_key();
177
178};
179
180WRITE_CLASS_ENCODER(GroupImageSpec);
181
182struct GroupImageStatus {
183 GroupImageStatus() {}
184 GroupImageStatus(const std::string &image_id,
185 int64_t pool_id,
186 GroupImageLinkState state)
187 : spec(image_id, pool_id), state(state) {}
188
189 GroupImageStatus(GroupImageSpec spec,
190 GroupImageLinkState state)
191 : spec(spec), state(state) {}
192
193 GroupImageSpec spec;
194 GroupImageLinkState state = GROUP_IMAGE_LINK_STATE_INCOMPLETE;
195
196 void encode(bufferlist &bl) const;
197 void decode(bufferlist::iterator &it);
198 void dump(Formatter *f) const;
199
200 std::string state_to_string() const;
201};
202
203WRITE_CLASS_ENCODER(GroupImageStatus);
204
205struct GroupSpec {
206 GroupSpec() {}
207 GroupSpec(const std::string &group_id, int64_t pool_id)
208 : group_id(group_id), pool_id(pool_id) {}
209
210 std::string group_id;
211 int64_t pool_id = -1;
212
213 void encode(bufferlist &bl) const;
214 void decode(bufferlist::iterator &it);
215 void dump(Formatter *f) const;
216 bool is_valid() const;
217};
218
219WRITE_CLASS_ENCODER(GroupSpec);
220
221enum SnapshotNamespaceType {
b32b8144 222 SNAPSHOT_NAMESPACE_TYPE_USER = 0
7c673cae
FG
223};
224
225struct UserSnapshotNamespace {
226 static const uint32_t SNAPSHOT_NAMESPACE_TYPE = SNAPSHOT_NAMESPACE_TYPE_USER;
227
228 UserSnapshotNamespace() {}
229
230 void encode(bufferlist& bl) const {}
231 void decode(bufferlist::iterator& it) {}
232
233 void dump(Formatter *f) const {}
234
235 inline bool operator==(const UserSnapshotNamespace& usn) const {
236 return true;
237 }
238
239 inline bool operator<(const UserSnapshotNamespace& usn) const {
240 return false;
241 }
242
243};
244
245std::ostream& operator<<(std::ostream& os, const UserSnapshotNamespace& ns);
246
7c673cae
FG
247struct UnknownSnapshotNamespace {
248 static const uint32_t SNAPSHOT_NAMESPACE_TYPE = static_cast<uint32_t>(-1);
249
250 UnknownSnapshotNamespace() {}
251
252 void encode(bufferlist& bl) const {}
253 void decode(bufferlist::iterator& it) {}
254 void dump(Formatter *f) const {}
255 inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
256 return true;
257 }
258
259 inline bool operator<(const UnknownSnapshotNamespace& usn) const {
260 return false;
261 }
262};
263
264std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns);
265
b32b8144 266typedef boost::variant<UserSnapshotNamespace, UnknownSnapshotNamespace> SnapshotNamespace;
7c673cae
FG
267
268
269struct SnapshotNamespaceOnDisk {
270
271 SnapshotNamespaceOnDisk() : snapshot_namespace(UnknownSnapshotNamespace()) {}
272 SnapshotNamespaceOnDisk(const SnapshotNamespace &sn) : snapshot_namespace(sn) {}
273
274 SnapshotNamespace snapshot_namespace;
275
276 SnapshotNamespaceType get_namespace_type() const;
277
278 void encode(bufferlist& bl) const;
279 void decode(bufferlist::iterator& it);
280 void dump(Formatter *f) const;
281
282 static void generate_test_instances(std::list<SnapshotNamespaceOnDisk *> &o);
283
284 inline bool operator==(const SnapshotNamespaceOnDisk& gsn) const {
285 return snapshot_namespace == gsn.snapshot_namespace;
286 }
287};
288WRITE_CLASS_ENCODER(SnapshotNamespaceOnDisk);
289
290enum TrashImageSource {
291 TRASH_IMAGE_SOURCE_USER = 0,
292 TRASH_IMAGE_SOURCE_MIRRORING = 1
293};
294
295inline void encode(const TrashImageSource &source, bufferlist& bl,
296 uint64_t features=0)
297{
298 ::encode(static_cast<uint8_t>(source), bl);
299}
300
301inline void decode(TrashImageSource &source, bufferlist::iterator& it)
302{
303 uint8_t int_source;
304 ::decode(int_source, it);
305 source = static_cast<TrashImageSource>(int_source);
306}
307
308struct TrashImageSpec {
309 TrashImageSource source = TRASH_IMAGE_SOURCE_USER;
310 std::string name;
311 utime_t deletion_time; // time of deletion
312 utime_t deferment_end_time;
313
314 TrashImageSpec() {}
315 TrashImageSpec(TrashImageSource source, const std::string &name,
316 utime_t deletion_time, utime_t deferment_end_time) :
317 source(source), name(name), deletion_time(deletion_time),
318 deferment_end_time(deferment_end_time) {}
319
320 void encode(bufferlist &bl) const;
321 void decode(bufferlist::iterator& it);
322 void dump(Formatter *f) const;
323};
324WRITE_CLASS_ENCODER(TrashImageSpec);
325
326} // namespace rbd
327} // namespace cls
328
329using cls::rbd::encode;
330using cls::rbd::decode;
331
332#endif // CEPH_CLS_RBD_TYPES_H