]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / BootstrapRequest.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_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/ceph_mutex.h"
10 #include "common/Timer.h"
11 #include "cls/rbd/cls_rbd_types.h"
12 #include "librbd/mirror/Types.h"
13 #include "tools/rbd_mirror/CancelableRequest.h"
14 #include "tools/rbd_mirror/Types.h"
15 #include <string>
16
17 class Context;
18
19 namespace journal { class CacheManagerHandler; }
20 namespace librbd { class ImageCtx; }
21
22 namespace rbd {
23 namespace mirror {
24
25 class ProgressContext;
26
27 template <typename> class ImageSync;
28 template <typename> class InstanceWatcher;
29 struct PoolMetaCache;
30 template <typename> struct Threads;
31
32 namespace image_replayer {
33
34 template <typename> class StateBuilder;
35
36 template <typename ImageCtxT = librbd::ImageCtx>
37 class BootstrapRequest : public CancelableRequest {
38 public:
39 typedef rbd::mirror::ProgressContext ProgressContext;
40
41 static BootstrapRequest* create(
42 Threads<ImageCtxT>* threads,
43 librados::IoCtx& local_io_ctx,
44 librados::IoCtx& remote_io_ctx,
45 InstanceWatcher<ImageCtxT>* instance_watcher,
46 const std::string& global_image_id,
47 const std::string& local_mirror_uuid,
48 const RemotePoolMeta& remote_pool_meta,
49 ::journal::CacheManagerHandler* cache_manager_handler,
50 PoolMetaCache* pool_meta_cache,
51 ProgressContext* progress_ctx,
52 StateBuilder<ImageCtxT>** state_builder,
53 bool* do_resync,
54 Context* on_finish) {
55 return new BootstrapRequest(
56 threads, local_io_ctx, remote_io_ctx, instance_watcher, global_image_id,
57 local_mirror_uuid, remote_pool_meta, cache_manager_handler,
58 pool_meta_cache, progress_ctx, state_builder, do_resync, on_finish);
59 }
60
61 BootstrapRequest(
62 Threads<ImageCtxT>* threads,
63 librados::IoCtx& local_io_ctx,
64 librados::IoCtx& remote_io_ctx,
65 InstanceWatcher<ImageCtxT>* instance_watcher,
66 const std::string& global_image_id,
67 const std::string& local_mirror_uuid,
68 const RemotePoolMeta& remote_pool_meta,
69 ::journal::CacheManagerHandler* cache_manager_handler,
70 PoolMetaCache* pool_meta_cache,
71 ProgressContext* progress_ctx,
72 StateBuilder<ImageCtxT>** state_builder,
73 bool* do_resync,
74 Context* on_finish);
75
76 bool is_syncing() const;
77
78 void send() override;
79 void cancel() override;
80
81 std::string get_local_image_name() const;
82
83 private:
84 /**
85 * @verbatim
86 *
87 * <start>
88 * |
89 * v (error)
90 * PREPARE_LOCAL_IMAGE * * * * * * * * * * * * * * * * * *
91 * | *
92 * v (error) *
93 * PREPARE_REMOTE_IMAGE * * * * * * * * * * * * * * * * * *
94 * | *
95 * v (error) *
96 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * *
97 * | *
98 * | *
99 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * *
100 * | | ^ * *
101 * | | . * *
102 * | v . (image DNE) * *
103 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * *
104 * | * *
105 * | * *
106 * v * *
107 * PREPARE_REPLAY * * * * * * * * * * * * * * *
108 * | * *
109 * | * *
110 * v (skip if not needed) * *
111 * IMAGE_SYNC * * * * * * * * * * * * * * * * *
112 * | * *
113 * | * *
114 * /---------/ * *
115 * | * *
116 * v * *
117 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
118 * | *
119 * v *
120 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
121 *
122 * @endverbatim
123 */
124 Threads<ImageCtxT>* m_threads;
125 librados::IoCtx &m_local_io_ctx;
126 librados::IoCtx &m_remote_io_ctx;
127 InstanceWatcher<ImageCtxT> *m_instance_watcher;
128 std::string m_global_image_id;
129 std::string m_local_mirror_uuid;
130 RemotePoolMeta m_remote_pool_meta;
131 ::journal::CacheManagerHandler *m_cache_manager_handler;
132 PoolMetaCache* m_pool_meta_cache;
133 ProgressContext *m_progress_ctx;
134 StateBuilder<ImageCtxT>** m_state_builder;
135 bool *m_do_resync;
136
137 mutable ceph::mutex m_lock;
138 bool m_canceled = false;
139
140 int m_ret_val = 0;
141
142 std::string m_local_image_name;
143 std::string m_prepare_local_image_name;
144
145 bool m_syncing = false;
146 ImageSync<ImageCtxT> *m_image_sync = nullptr;
147
148 void prepare_local_image();
149 void handle_prepare_local_image(int r);
150
151 void prepare_remote_image();
152 void handle_prepare_remote_image(int r);
153
154 void open_remote_image();
155 void handle_open_remote_image(int r);
156
157 void open_local_image();
158 void handle_open_local_image(int r);
159
160 void create_local_image();
161 void handle_create_local_image(int r);
162
163 void prepare_replay();
164 void handle_prepare_replay(int r);
165
166 void image_sync();
167 void handle_image_sync(int r);
168
169 void close_remote_image();
170 void handle_close_remote_image(int r);
171
172 void update_progress(const std::string &description);
173 };
174
175 } // namespace image_replayer
176 } // namespace mirror
177 } // namespace rbd
178
179 extern template class rbd::mirror::image_replayer::BootstrapRequest<librbd::ImageCtx>;
180
181 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H