1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H
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"
20 namespace journal
{ class CacheManagerHandler
; }
21 namespace librbd
{ class ImageCtx
; }
26 class ProgressContext
;
28 template <typename
> class ImageSync
;
29 template <typename
> class InstanceWatcher
;
31 template <typename
> struct Threads
;
33 namespace image_replayer
{
35 template <typename
> class StateBuilder
;
37 template <typename ImageCtxT
= librbd::ImageCtx
>
38 class BootstrapRequest
: public CancelableRequest
{
40 typedef rbd::mirror::ProgressContext ProgressContext
;
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
,
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
);
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
,
77 bool is_syncing() const;
80 void cancel() override
;
82 std::string
get_local_image_name() const;
91 * PREPARE_LOCAL_IMAGE * * * * * * * * * * * * * * * * * *
94 * PREPARE_REMOTE_IMAGE * * * * * * * * * * * * * * * * * *
97 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * *
100 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * *
103 * | v . (image DNE) * *
104 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * *
108 * PREPARE_REPLAY * * * * * * * * * * * * * * *
111 * v (skip if not needed) * *
112 * IMAGE_SYNC * * * * * * * * * * * * * * * * *
118 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
121 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
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
;
138 mutable ceph::mutex m_lock
;
139 bool m_canceled
= false;
143 std::string m_local_image_name
;
144 std::string m_prepare_local_image_name
;
146 bool m_syncing
= false;
147 ImageSync
<ImageCtxT
> *m_image_sync
= nullptr;
149 void prepare_local_image();
150 void handle_prepare_local_image(int r
);
152 void prepare_remote_image();
153 void handle_prepare_remote_image(int r
);
155 void open_remote_image();
156 void handle_open_remote_image(int r
);
158 void open_local_image();
159 void handle_open_local_image(int r
);
161 void create_local_image();
162 void handle_create_local_image(int r
);
164 void prepare_replay();
165 void handle_prepare_replay(int r
);
168 void handle_image_sync(int r
);
170 void close_remote_image();
171 void handle_close_remote_image(int r
);
173 void update_progress(const std::string
&description
);
176 } // namespace image_replayer
177 } // namespace mirror
180 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
182 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H