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_SYNC_H
5 #define RBD_MIRROR_IMAGE_SYNC_H
7 #include "include/int_types.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/Types.h"
10 #include "common/ceph_mutex.h"
11 #include "tools/rbd_mirror/CancelableRequest.h"
12 #include "tools/rbd_mirror/image_sync/Types.h"
15 namespace journal
{ class Journaler
; }
16 namespace librbd
{ template <typename
> class DeepCopyRequest
; }
21 class ProgressContext
;
22 template <typename
> class InstanceWatcher
;
23 template <typename
> class Threads
;
25 namespace image_sync
{ struct SyncPointHandler
; }
27 template <typename ImageCtxT
= librbd::ImageCtx
>
28 class ImageSync
: public CancelableRequest
{
30 static ImageSync
* create(
31 Threads
<ImageCtxT
>* threads
,
32 ImageCtxT
*local_image_ctx
,
33 ImageCtxT
*remote_image_ctx
,
34 const std::string
&local_mirror_uuid
,
35 image_sync::SyncPointHandler
* sync_point_handler
,
36 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
37 ProgressContext
*progress_ctx
,
39 return new ImageSync(threads
, local_image_ctx
, remote_image_ctx
,
40 local_mirror_uuid
, sync_point_handler
,
41 instance_watcher
, progress_ctx
, on_finish
);
45 Threads
<ImageCtxT
>* threads
,
46 ImageCtxT
*local_image_ctx
,
47 ImageCtxT
*remote_image_ctx
,
48 const std::string
&local_mirror_uuid
,
49 image_sync::SyncPointHandler
* sync_point_handler
,
50 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
51 ProgressContext
*progress_ctx
,
53 ~ImageSync() override
;
56 void cancel() override
;
59 void finish(int r
) override
;
71 * PRUNE_CATCH_UP_SYNC_POINT
74 * CREATE_SYNC_POINT (skip if already exists and
77 * COPY_IMAGE . . . . . . . . . . . . . .
81 * | . (image sync canceled)
86 * <finish> < . . . . . . . . . . . . . .
91 class ImageCopyProgressHandler
;
93 Threads
<ImageCtxT
>* m_threads
;
94 ImageCtxT
*m_local_image_ctx
;
95 ImageCtxT
*m_remote_image_ctx
;
96 std::string m_local_mirror_uuid
;
97 image_sync::SyncPointHandler
* m_sync_point_handler
;
98 InstanceWatcher
<ImageCtxT
> *m_instance_watcher
;
99 ProgressContext
*m_progress_ctx
;
102 bool m_canceled
= false;
104 librbd::DeepCopyRequest
<ImageCtxT
> *m_image_copy_request
= nullptr;
105 ImageCopyProgressHandler
*m_image_copy_prog_handler
= nullptr;
107 bool m_updating_sync_point
= false;
108 Context
*m_update_sync_ctx
= nullptr;
109 double m_update_sync_point_interval
;
110 uint64_t m_image_copy_object_no
= 0;
111 uint64_t m_image_copy_object_count
= 0;
113 librbd::SnapSeqs m_snap_seqs_copy
;
114 image_sync::SyncPoints m_sync_points_copy
;
118 void send_notify_sync_request();
119 void handle_notify_sync_request(int r
);
121 void send_prune_catch_up_sync_point();
122 void handle_prune_catch_up_sync_point(int r
);
124 void send_create_sync_point();
125 void handle_create_sync_point(int r
);
127 void send_update_max_object_count();
128 void handle_update_max_object_count(int r
);
130 void send_copy_image();
131 void handle_copy_image(int r
);
132 void handle_copy_image_update_progress(uint64_t object_no
,
133 uint64_t object_count
);
134 void send_update_sync_point();
135 void handle_update_sync_point(int r
);
137 void send_flush_sync_point();
138 void handle_flush_sync_point(int r
);
140 void send_prune_sync_points();
141 void handle_prune_sync_points(int r
);
143 void update_progress(const std::string
&description
);
146 } // namespace mirror
149 extern template class rbd::mirror::ImageSync
<librbd::ImageCtx
>;
151 #endif // RBD_MIRROR_IMAGE_SYNC_H