]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/instance_watcher/Types.h
update sources to v12.1.3
[ceph.git] / ceph / src / tools / rbd_mirror / instance_watcher / Types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RBD_MIRROR_INSTANCE_WATCHER_TYPES_H
5 #define RBD_MIRROR_INSTANCE_WATCHER_TYPES_H
6
7 #include <string>
8 #include <set>
9 #include <boost/variant.hpp>
10
11 #include "include/buffer_fwd.h"
12 #include "include/encoding.h"
13 #include "include/int_types.h"
14
15 namespace ceph { class Formatter; }
16
17 namespace rbd {
18 namespace mirror {
19 namespace instance_watcher {
20
21 enum NotifyOp {
22 NOTIFY_OP_IMAGE_ACQUIRE = 0,
23 NOTIFY_OP_IMAGE_RELEASE = 1,
24 NOTIFY_OP_PEER_IMAGE_REMOVED = 2,
25 NOTIFY_OP_SYNC_REQUEST = 3,
26 NOTIFY_OP_SYNC_START = 4
27 };
28
29 struct PayloadBase {
30 uint64_t request_id;
31
32 PayloadBase() : request_id(0) {
33 }
34
35 PayloadBase(uint64_t request_id) : request_id(request_id) {
36 }
37
38 void encode(bufferlist &bl) const;
39 void decode(__u8 version, bufferlist::iterator &iter);
40 void dump(Formatter *f) const;
41 };
42
43 struct ImagePayloadBase : public PayloadBase {
44 std::string global_image_id;
45
46 ImagePayloadBase() : PayloadBase() {
47 }
48
49 ImagePayloadBase(uint64_t request_id, const std::string &global_image_id)
50 : PayloadBase(request_id), global_image_id(global_image_id) {
51 }
52
53 void encode(bufferlist &bl) const;
54 void decode(__u8 version, bufferlist::iterator &iter);
55 void dump(Formatter *f) const;
56 };
57
58 struct ImageAcquirePayload : public ImagePayloadBase {
59 static const NotifyOp NOTIFY_OP = NOTIFY_OP_IMAGE_ACQUIRE;
60
61 ImageAcquirePayload() {
62 }
63 ImageAcquirePayload(uint64_t request_id, const std::string &global_image_id)
64 : ImagePayloadBase(request_id, global_image_id) {
65 }
66 };
67
68 struct ImageReleasePayload : public ImagePayloadBase {
69 static const NotifyOp NOTIFY_OP = NOTIFY_OP_IMAGE_RELEASE;
70
71 ImageReleasePayload() {
72 }
73 ImageReleasePayload(uint64_t request_id, const std::string &global_image_id)
74 : ImagePayloadBase(request_id, global_image_id) {
75 }
76 };
77
78 struct PeerImageRemovedPayload : public PayloadBase {
79 static const NotifyOp NOTIFY_OP = NOTIFY_OP_PEER_IMAGE_REMOVED;
80
81 std::string global_image_id;
82 std::string peer_mirror_uuid;
83
84 PeerImageRemovedPayload() {
85 }
86 PeerImageRemovedPayload(uint64_t request_id,
87 const std::string& global_image_id,
88 const std::string& peer_mirror_uuid)
89 : PayloadBase(request_id),
90 global_image_id(global_image_id), peer_mirror_uuid(peer_mirror_uuid) {
91 }
92
93 void encode(bufferlist &bl) const;
94 void decode(__u8 version, bufferlist::iterator &iter);
95 void dump(Formatter *f) const;
96 };
97
98 struct SyncPayloadBase : public PayloadBase {
99 std::string sync_id;
100
101 SyncPayloadBase() : PayloadBase() {
102 }
103
104 SyncPayloadBase(uint64_t request_id, const std::string &sync_id)
105 : PayloadBase(request_id), sync_id(sync_id) {
106 }
107
108 void encode(bufferlist &bl) const;
109 void decode(__u8 version, bufferlist::iterator &iter);
110 void dump(Formatter *f) const;
111 };
112
113 struct SyncRequestPayload : public SyncPayloadBase {
114 static const NotifyOp NOTIFY_OP = NOTIFY_OP_SYNC_REQUEST;
115
116 SyncRequestPayload() : SyncPayloadBase() {
117 }
118
119 SyncRequestPayload(uint64_t request_id, const std::string &sync_id)
120 : SyncPayloadBase(request_id, sync_id) {
121 }
122 };
123
124 struct SyncStartPayload : public SyncPayloadBase {
125 static const NotifyOp NOTIFY_OP = NOTIFY_OP_SYNC_START;
126
127 SyncStartPayload() : SyncPayloadBase() {
128 }
129
130 SyncStartPayload(uint64_t request_id, const std::string &sync_id)
131 : SyncPayloadBase(request_id, sync_id) {
132 }
133 };
134
135 struct UnknownPayload {
136 static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1);
137
138 UnknownPayload() {
139 }
140
141 void encode(bufferlist &bl) const;
142 void decode(__u8 version, bufferlist::iterator &iter);
143 void dump(Formatter *f) const;
144 };
145
146 typedef boost::variant<ImageAcquirePayload,
147 ImageReleasePayload,
148 PeerImageRemovedPayload,
149 SyncRequestPayload,
150 SyncStartPayload,
151 UnknownPayload> Payload;
152
153 struct NotifyMessage {
154 NotifyMessage(const Payload &payload = UnknownPayload()) : payload(payload) {
155 }
156
157 Payload payload;
158
159 void encode(bufferlist& bl) const;
160 void decode(bufferlist::iterator& it);
161 void dump(Formatter *f) const;
162
163 static void generate_test_instances(std::list<NotifyMessage *> &o);
164 };
165
166 WRITE_CLASS_ENCODER(NotifyMessage);
167
168 std::ostream &operator<<(std::ostream &out, const NotifyOp &op);
169
170 struct NotifyAckPayload {
171 std::string instance_id;
172 uint64_t request_id;
173 int ret_val;
174
175 NotifyAckPayload() : request_id(0), ret_val(0) {
176 }
177
178 NotifyAckPayload(const std::string &instance_id, uint64_t request_id,
179 int ret_val)
180 : instance_id(instance_id), request_id(request_id), ret_val(ret_val) {
181 }
182
183 void encode(bufferlist &bl) const;
184 void decode(bufferlist::iterator& it);
185 void dump(Formatter *f) const;
186 };
187
188 WRITE_CLASS_ENCODER(NotifyAckPayload);
189
190 } // namespace instance_watcher
191 } // namespace mirror
192 } // namespace librbd
193
194 using rbd::mirror::instance_watcher::encode;
195 using rbd::mirror::instance_watcher::decode;
196
197 #endif // RBD_MIRROR_INSTANCE_WATCHER_TYPES_H