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/journal/TypeTraits.h"
10 #include "common/Mutex.h"
11 #include "tools/rbd_mirror/BaseRequest.h"
19 namespace journal { class Journaler; }
20 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
25 class ProgressContext;
27 template <typename> class InstanceWatcher;
29 namespace image_sync { template <typename> class ImageCopyRequest; }
30 namespace image_sync { template <typename> class SnapshotCopyRequest; }
32 template <typename ImageCtxT = librbd::ImageCtx>
33 class ImageSync : public BaseRequest {
35 typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits;
36 typedef typename TypeTraits::Journaler Journaler;
37 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta;
39 static ImageSync* create(ImageCtxT *local_image_ctx,
40 ImageCtxT *remote_image_ctx, SafeTimer *timer,
41 Mutex *timer_lock, const std::string &mirror_uuid,
43 MirrorPeerClientMeta *client_meta,
44 ContextWQ *work_queue,
45 InstanceWatcher<ImageCtxT> *instance_watcher,
47 ProgressContext *progress_ctx = nullptr) {
48 return new ImageSync(local_image_ctx, remote_image_ctx, timer, timer_lock,
49 mirror_uuid, journaler, client_meta, work_queue,
50 instance_watcher, on_finish, progress_ctx);
53 ImageSync(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx,
54 SafeTimer *timer, Mutex *timer_lock, const std::string &mirror_uuid,
55 Journaler *journaler, MirrorPeerClientMeta *client_meta,
56 ContextWQ *work_queue, InstanceWatcher<ImageCtxT> *instance_watcher,
57 Context *on_finish, ProgressContext *progress_ctx = nullptr);
58 ~ImageSync() override;
61 void cancel() override;
64 void finish(int r) override;
76 * PRUNE_CATCH_UP_SYNC_POINT
79 * CREATE_SYNC_POINT (skip if already exists and
85 * COPY_IMAGE . . . . . . . . . . . . . .
88 * COPY_OBJECT_MAP (skip if object .
91 * REFRESH_OBJECT_MAP (skip if object .
94 * PRUNE_SYNC_POINTS . (image sync canceled)
97 * <finish> < . . . . . . . . . . . . . .
102 typedef std::vector<librados::snap_t> SnapIds;
103 typedef std::map<librados::snap_t, SnapIds> SnapMap;
105 ImageCtxT *m_local_image_ctx;
106 ImageCtxT *m_remote_image_ctx;
109 std::string m_mirror_uuid;
110 Journaler *m_journaler;
111 MirrorPeerClientMeta *m_client_meta;
112 ContextWQ *m_work_queue;
113 InstanceWatcher<ImageCtxT> *m_instance_watcher;
114 ProgressContext *m_progress_ctx;
119 bool m_canceled = false;
121 image_sync::SnapshotCopyRequest<ImageCtxT> *m_snapshot_copy_request = nullptr;
122 image_sync::ImageCopyRequest<ImageCtxT> *m_image_copy_request = nullptr;
123 decltype(ImageCtxT::object_map) m_object_map = nullptr;
125 void send_notify_sync_request();
126 void handle_notify_sync_request(int r);
128 void send_prune_catch_up_sync_point();
129 void handle_prune_catch_up_sync_point(int r);
131 void send_create_sync_point();
132 void handle_create_sync_point(int r);
134 void send_copy_snapshots();
135 void handle_copy_snapshots(int r);
137 void send_copy_image();
138 void handle_copy_image(int r);
140 void send_copy_object_map();
141 void handle_copy_object_map(int r);
143 void send_refresh_object_map();
144 void handle_refresh_object_map(int r);
146 void send_prune_sync_points();
147 void handle_prune_sync_points(int r);
149 void update_progress(const std::string &description);
152 } // namespace mirror
155 extern template class rbd::mirror::ImageSync<librbd::ImageCtx>;
157 #endif // RBD_MIRROR_IMAGE_SYNC_H