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 "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"
19 namespace journal
{ class CacheManagerHandler
; }
20 namespace librbd
{ class ImageCtx
; }
25 class ProgressContext
;
27 template <typename
> class ImageSync
;
28 template <typename
> class InstanceWatcher
;
30 template <typename
> struct Threads
;
32 namespace image_replayer
{
34 template <typename
> class StateBuilder
;
36 template <typename ImageCtxT
= librbd::ImageCtx
>
37 class BootstrapRequest
: public CancelableRequest
{
39 typedef rbd::mirror::ProgressContext ProgressContext
;
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
,
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
);
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
,
76 bool is_syncing() const;
79 void cancel() override
;
81 std::string
get_local_image_name() const;
90 * PREPARE_LOCAL_IMAGE * * * * * * * * * * * * * * * * * *
93 * PREPARE_REMOTE_IMAGE * * * * * * * * * * * * * * * * * *
96 * OPEN_REMOTE_IMAGE * * * * * * * * * * * * * * * * * * *
99 * \----> CREATE_LOCAL_IMAGE * * * * * * * * * * * * *
102 * | v . (image DNE) * *
103 * \----> OPEN_LOCAL_IMAGE * * * * * * * * * * * * * *
107 * PREPARE_REPLAY * * * * * * * * * * * * * * *
110 * v (skip if not needed) * *
111 * IMAGE_SYNC * * * * * * * * * * * * * * * * *
117 * CLOSE_REMOTE_IMAGE < * * * * * * * * * * * * * * * * *
120 * <finish> < * * * * * * * * * * * * * * * * * * * * * * *
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
;
137 mutable ceph::mutex m_lock
;
138 bool m_canceled
= false;
142 std::string m_local_image_name
;
143 std::string m_prepare_local_image_name
;
145 bool m_syncing
= false;
146 ImageSync
<ImageCtxT
> *m_image_sync
= nullptr;
148 void prepare_local_image();
149 void handle_prepare_local_image(int r
);
151 void prepare_remote_image();
152 void handle_prepare_remote_image(int r
);
154 void open_remote_image();
155 void handle_open_remote_image(int r
);
157 void open_local_image();
158 void handle_open_local_image(int r
);
160 void create_local_image();
161 void handle_create_local_image(int r
);
163 void prepare_replay();
164 void handle_prepare_replay(int r
);
167 void handle_image_sync(int r
);
169 void close_remote_image();
170 void handle_close_remote_image(int r
);
172 void update_progress(const std::string
&description
);
175 } // namespace image_replayer
176 } // namespace mirror
179 extern template class rbd::mirror::image_replayer::BootstrapRequest
<librbd::ImageCtx
>;
181 #endif // RBD_MIRROR_IMAGE_REPLAYER_BOOTSTRAP_REQUEST_H