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"
16 namespace journal
{ class Journaler
; }
17 namespace librbd
{ class ProgressContext
; }
18 namespace librbd
{ template <typename
> class DeepCopyRequest
; }
23 class ProgressContext
;
24 template <typename
> class InstanceWatcher
;
25 template <typename
> class Threads
;
27 namespace image_sync
{ struct SyncPointHandler
; }
29 template <typename ImageCtxT
= librbd::ImageCtx
>
30 class ImageSync
: public CancelableRequest
{
32 static ImageSync
* create(
33 Threads
<ImageCtxT
>* threads
,
34 ImageCtxT
*local_image_ctx
,
35 ImageCtxT
*remote_image_ctx
,
36 const std::string
&local_mirror_uuid
,
37 image_sync::SyncPointHandler
* sync_point_handler
,
38 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
39 ProgressContext
*progress_ctx
,
41 return new ImageSync(threads
, local_image_ctx
, remote_image_ctx
,
42 local_mirror_uuid
, sync_point_handler
,
43 instance_watcher
, progress_ctx
, on_finish
);
47 Threads
<ImageCtxT
>* threads
,
48 ImageCtxT
*local_image_ctx
,
49 ImageCtxT
*remote_image_ctx
,
50 const std::string
&local_mirror_uuid
,
51 image_sync::SyncPointHandler
* sync_point_handler
,
52 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
53 ProgressContext
*progress_ctx
,
55 ~ImageSync() override
;
58 void cancel() override
;
61 void finish(int r
) override
;
73 * PRUNE_CATCH_UP_SYNC_POINT
76 * CREATE_SYNC_POINT (skip if already exists and
79 * COPY_IMAGE . . . . . . . . . . . . . .
83 * | . (image sync canceled)
88 * <finish> < . . . . . . . . . . . . . .
93 class ImageCopyProgressContext
;
95 Threads
<ImageCtxT
>* m_threads
;
96 ImageCtxT
*m_local_image_ctx
;
97 ImageCtxT
*m_remote_image_ctx
;
98 std::string m_local_mirror_uuid
;
99 image_sync::SyncPointHandler
* m_sync_point_handler
;
100 InstanceWatcher
<ImageCtxT
> *m_instance_watcher
;
101 ProgressContext
*m_progress_ctx
;
104 bool m_canceled
= false;
106 librbd::DeepCopyRequest
<ImageCtxT
> *m_image_copy_request
= nullptr;
107 librbd::ProgressContext
*m_image_copy_prog_ctx
= nullptr;
109 bool m_updating_sync_point
= false;
110 Context
*m_update_sync_ctx
= nullptr;
111 double m_update_sync_point_interval
;
112 uint64_t m_image_copy_object_no
= 0;
113 uint64_t m_image_copy_object_count
= 0;
115 librbd::SnapSeqs m_snap_seqs_copy
;
116 image_sync::SyncPoints m_sync_points_copy
;
120 void send_notify_sync_request();
121 void handle_notify_sync_request(int r
);
123 void send_prune_catch_up_sync_point();
124 void handle_prune_catch_up_sync_point(int r
);
126 void send_create_sync_point();
127 void handle_create_sync_point(int r
);
129 void send_update_max_object_count();
130 void handle_update_max_object_count(int r
);
132 void send_copy_image();
133 void handle_copy_image(int r
);
134 void handle_copy_image_update_progress(uint64_t object_no
,
135 uint64_t object_count
);
136 void send_update_sync_point();
137 void handle_update_sync_point(int r
);
139 void send_flush_sync_point();
140 void handle_flush_sync_point(int r
);
142 void send_prune_sync_points();
143 void handle_prune_sync_points(int r
);
145 void update_progress(const std::string
&description
);
148 } // namespace mirror
151 extern template class rbd::mirror::ImageSync
<librbd::ImageCtx
>;
153 #endif // RBD_MIRROR_IMAGE_SYNC_H