]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/ImageSync.h
0662732327068777c303c1e3c2296fc96be0dbfb
[ceph.git] / ceph / src / tools / rbd_mirror / ImageSync.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RBD_MIRROR_IMAGE_SYNC_H
5 #define RBD_MIRROR_IMAGE_SYNC_H
6
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"
13
14 class Context;
15 class ContextWQ;
16 namespace journal { class Journaler; }
17 namespace librbd { class ProgressContext; }
18 namespace librbd { template <typename> class DeepCopyRequest; }
19
20 namespace rbd {
21 namespace mirror {
22
23 class ProgressContext;
24 template <typename> class InstanceWatcher;
25 template <typename> class Threads;
26
27 namespace image_sync { struct SyncPointHandler; }
28
29 template <typename ImageCtxT = librbd::ImageCtx>
30 class ImageSync : public CancelableRequest {
31 public:
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,
40 Context *on_finish) {
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);
44 }
45
46 ImageSync(
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,
54 Context *on_finish);
55 ~ImageSync() override;
56
57 void send() override;
58 void cancel() override;
59
60 protected:
61 void finish(int r) override;
62
63 private:
64 /**
65 * @verbatim
66 *
67 * <start>
68 * |
69 * v
70 * NOTIFY_SYNC_REQUEST
71 * |
72 * v
73 * PRUNE_CATCH_UP_SYNC_POINT
74 * |
75 * v
76 * CREATE_SYNC_POINT (skip if already exists and
77 * | not disconnected)
78 * v
79 * COPY_IMAGE . . . . . . . . . . . . . .
80 * | .
81 * v .
82 * FLUSH_SYNC_POINT .
83 * | . (image sync canceled)
84 * v .
85 * PRUNE_SYNC_POINTS .
86 * | .
87 * v .
88 * <finish> < . . . . . . . . . . . . . .
89 *
90 * @endverbatim
91 */
92
93 class ImageCopyProgressContext;
94
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;
102
103 ceph::mutex m_lock;
104 bool m_canceled = false;
105
106 librbd::DeepCopyRequest<ImageCtxT> *m_image_copy_request = nullptr;
107 librbd::ProgressContext *m_image_copy_prog_ctx = nullptr;
108
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;
114
115 librbd::SnapSeqs m_snap_seqs_copy;
116 image_sync::SyncPoints m_sync_points_copy;
117
118 int m_ret_val = 0;
119
120 void send_notify_sync_request();
121 void handle_notify_sync_request(int r);
122
123 void send_prune_catch_up_sync_point();
124 void handle_prune_catch_up_sync_point(int r);
125
126 void send_create_sync_point();
127 void handle_create_sync_point(int r);
128
129 void send_update_max_object_count();
130 void handle_update_max_object_count(int r);
131
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);
138
139 void send_flush_sync_point();
140 void handle_flush_sync_point(int r);
141
142 void send_prune_sync_points();
143 void handle_prune_sync_points(int r);
144
145 void update_progress(const std::string &description);
146 };
147
148 } // namespace mirror
149 } // namespace rbd
150
151 extern template class rbd::mirror::ImageSync<librbd::ImageCtx>;
152
153 #endif // RBD_MIRROR_IMAGE_SYNC_H