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