/
BootstrapRequest.h
223 lines (190 loc) · 7.25 KB
/
BootstrapRequest.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#ifndef RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
#define RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
#include "include/int_types.h"
#include "include/rados/librados.hpp"
#include "common/Mutex.h"
#include "cls/journal/cls_journal_types.h"
#include "librbd/journal/TypeTraits.h"
#include "tools/rbd_mirror/BaseRequest.h"
#include "tools/rbd_mirror/types.h"
#include <list>
#include <string>
class Context;
class ContextWQ;
class Mutex;
class SafeTimer;
namespace journal { class Journaler; }
namespace librbd { class ImageCtx; }
namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
namespace rbd {
namespace mirror {
class ProgressContext;
namespace image_replayer {
template <typename ImageCtxT = librbd::ImageCtx>
class BootstrapRequest : public BaseRequest {
public:
typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
typedef typename TypeTraits::Journaler Journaler;
typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
typedef rbd::mirror::ProgressContext ProgressContext;
static BootstrapRequest* create(
librados::IoCtx &local_io_ctx,
librados::IoCtx &remote_io_ctx,
ImageSyncThrottlerRef<ImageCtxT> image_sync_throttler,
ImageCtxT **local_image_ctx,
const std::string &local_image_name,
const std::string &remote_image_id,
const std::string &global_image_id,
ContextWQ *work_queue, SafeTimer *timer,
Mutex *timer_lock,
const std::string &local_mirror_uuid,
const std::string &remote_mirror_uuid,
Journaler *journaler,
MirrorPeerClientMeta *client_meta,
Context *on_finish,
ProgressContext *progress_ctx = nullptr) {
return new BootstrapRequest(local_io_ctx, remote_io_ctx,
image_sync_throttler, local_image_ctx,
local_image_name, remote_image_id,
global_image_id, work_queue, timer, timer_lock,
local_mirror_uuid, remote_mirror_uuid,
journaler, client_meta, on_finish,
progress_ctx);
}
BootstrapRequest(librados::IoCtx &local_io_ctx,
librados::IoCtx &remote_io_ctx,
ImageSyncThrottlerRef<ImageCtxT> image_sync_throttler,
ImageCtxT **local_image_ctx,
const std::string &local_image_name,
const std::string &remote_image_id,
const std::string &global_image_id, ContextWQ *work_queue,
SafeTimer *timer, Mutex *timer_lock,
const std::string &local_mirror_uuid,
const std::string &remote_mirror_uuid, Journaler *journaler,
MirrorPeerClientMeta *client_meta, Context *on_finish,
ProgressContext *progress_ctx = nullptr);
~BootstrapRequest();
void send();
void cancel();
private:
/**
* @verbatim
*
* <start>
* |
* v
* GET_LOCAL_IMAGE_ID * * * * * * * * * * * *
* | *
* v *
* GET_REMOTE_TAG_CLASS * * * * * * * * * * *
* | *
* v *
* GET_CLIENT * * * * * * * * * * * * * * * *
* | *
* v (skip if not needed) * (error)
* UNREGISTER_CLIENT * * * * * * * * * * * *
* | *
* v (skip if not needed) * (error)
* REGISTER_CLIENT * * * * * * * * * * * * *
* | *
* v *
* OPEN_REMOTE_IMAGE * * * * * * * * * * * *
* | *
* v *
* OPEN_LOCAL_IMAGE * * * * * * * * * * * * *
* | . ^ *
* | . | *
* | . \-----------------------\ *
* | . | *
* | . (image sync requested) | *
* | . . > REMOVE_LOCAL_IMAGE * * * * *
* | . | | *
* | . (image doesn't | | *
* | . exist) v | *
* | . . > CREATE_LOCAL_IMAGE * * * * *
* | | | *
* | \-----------------/ *
* | *
* v (skip if not needed) *
* UPDATE_CLIENT * * * * * * * * *
* | * *
* v (skip if not needed) * *
* GET_REMOTE_TAGS * * * * * * * *
* | * *
* v (skip if not needed) v *
* IMAGE_SYNC * * * > CLOSE_LOCAL_IMAGE *
* | | *
* | /-------------------/ *
* | | *
* v v *
* CLOSE_REMOTE_IMAGE < * * * * * * * * * * *
* |
* v
* <finish>
*
* @endverbatim
*/
typedef std::list<cls::journal::Tag> Tags;
librados::IoCtx &m_local_io_ctx;
librados::IoCtx &m_remote_io_ctx;
ImageSyncThrottlerRef<ImageCtxT> m_image_sync_throttler;
ImageCtxT **m_local_image_ctx;
std::string m_local_image_name;
std::string m_local_image_id;
std::string m_remote_image_id;
std::string m_global_image_id;
ContextWQ *m_work_queue;
SafeTimer *m_timer;
Mutex *m_timer_lock;
std::string m_local_mirror_uuid;
std::string m_remote_mirror_uuid;
Journaler *m_journaler;
MirrorPeerClientMeta *m_client_meta;
ProgressContext *m_progress_ctx;
Mutex m_lock;
bool m_canceled = false;
Tags m_remote_tags;
cls::journal::Client m_client;
uint64_t m_remote_tag_class = 0;
ImageCtxT *m_remote_image_ctx = nullptr;
bool m_created_local_image = false;
int m_ret_val = 0;
bufferlist m_out_bl;
void get_local_image_id();
void handle_get_local_image_id(int r);
void get_remote_tag_class();
void handle_get_remote_tag_class(int r);
void get_client();
void handle_get_client(int r);
void unregister_client();
void handle_unregister_client(int r);
void register_client();
void handle_register_client(int r);
void open_remote_image();
void handle_open_remote_image(int r);
void open_local_image();
void handle_open_local_image(int r);
void remove_local_image();
void handle_remove_local_image(int r);
void create_local_image();
void handle_create_local_image(int r);
void update_client();
void handle_update_client(int r);
void get_remote_tags();
void handle_get_remote_tags(int r);
void image_sync();
void handle_image_sync(int r);
void close_local_image();
void handle_close_local_image(int r);
void close_remote_image();
void handle_close_remote_image(int r);
bool decode_client_meta();
void update_progress(const std::string &description);
};
} // namespace image_replayer
} // namespace mirror
} // namespace rbd
extern template class rbd::mirror::image_replayer::BootstrapRequest<librbd::ImageCtx>;
#endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H