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
{ template <typename
> class DeepCopyRequest
; }
22 class ProgressContext
;
23 template <typename
> class InstanceWatcher
;
24 template <typename
> class Threads
;
26 namespace image_sync
{ struct SyncPointHandler
; }
28 template <typename ImageCtxT
= librbd::ImageCtx
>
29 class ImageSync
: public CancelableRequest
{
31 static ImageSync
* create(
32 Threads
<ImageCtxT
>* threads
,
33 ImageCtxT
*local_image_ctx
,
34 ImageCtxT
*remote_image_ctx
,
35 const std::string
&local_mirror_uuid
,
36 image_sync::SyncPointHandler
* sync_point_handler
,
37 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
38 ProgressContext
*progress_ctx
,
40 return new ImageSync(threads
, local_image_ctx
, remote_image_ctx
,
41 local_mirror_uuid
, sync_point_handler
,
42 instance_watcher
, progress_ctx
, on_finish
);
46 Threads
<ImageCtxT
>* threads
,
47 ImageCtxT
*local_image_ctx
,
48 ImageCtxT
*remote_image_ctx
,
49 const std::string
&local_mirror_uuid
,
50 image_sync::SyncPointHandler
* sync_point_handler
,
51 InstanceWatcher
<ImageCtxT
> *instance_watcher
,
52 ProgressContext
*progress_ctx
,
54 ~ImageSync() override
;
57 void cancel() override
;
60 void finish(int r
) override
;
72 * PRUNE_CATCH_UP_SYNC_POINT
75 * CREATE_SYNC_POINT (skip if already exists and
78 * COPY_IMAGE . . . . . . . . . . . . . .
82 * | . (image sync canceled)
87 * <finish> < . . . . . . . . . . . . . .
92 class ImageCopyProgressHandler
;
94 Threads
<ImageCtxT
>* m_threads
;
95 ImageCtxT
*m_local_image_ctx
;
96 ImageCtxT
*m_remote_image_ctx
;
97 std::string m_local_mirror_uuid
;
98 image_sync::SyncPointHandler
* m_sync_point_handler
;
99 InstanceWatcher
<ImageCtxT
> *m_instance_watcher
;
100 ProgressContext
*m_progress_ctx
;
103 bool m_canceled
= false;
105 librbd::DeepCopyRequest
<ImageCtxT
> *m_image_copy_request
= nullptr;
106 ImageCopyProgressHandler
*m_image_copy_prog_handler
= nullptr;
108 bool m_updating_sync_point
= false;
109 Context
*m_update_sync_ctx
= nullptr;
110 double m_update_sync_point_interval
;
111 uint64_t m_image_copy_object_no
= 0;
112 uint64_t m_image_copy_object_count
= 0;
114 librbd::SnapSeqs m_snap_seqs_copy
;
115 image_sync::SyncPoints m_sync_points_copy
;
119 void send_notify_sync_request();
120 void handle_notify_sync_request(int r
);
122 void send_prune_catch_up_sync_point();
123 void handle_prune_catch_up_sync_point(int r
);
125 void send_create_sync_point();
126 void handle_create_sync_point(int r
);
128 void send_update_max_object_count();
129 void handle_update_max_object_count(int r
);
131 void send_copy_image();
132 void handle_copy_image(int r
);
133 void handle_copy_image_update_progress(uint64_t object_no
,
134 uint64_t object_count
);
135 void send_update_sync_point();
136 void handle_update_sync_point(int r
);
138 void send_flush_sync_point();
139 void handle_flush_sync_point(int r
);
141 void send_prune_sync_points();
142 void handle_prune_sync_points(int r
);
144 void update_progress(const std::string
&description
);
147 } // namespace mirror
150 extern template class rbd::mirror::ImageSync
<librbd::ImageCtx
>;
152 #endif // RBD_MIRROR_IMAGE_SYNC_H