]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/ImageSync.h
update source to Ceph Pacific 16.2.2
[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 namespace journal { class Journaler; }
16 namespace librbd { template <typename> class DeepCopyRequest; }
17
18 namespace rbd {
19 namespace mirror {
20
21 class ProgressContext;
22 template <typename> class InstanceWatcher;
23 template <typename> class Threads;
24
25 namespace image_sync { struct SyncPointHandler; }
26
27 template <typename ImageCtxT = librbd::ImageCtx>
28 class ImageSync : public CancelableRequest {
29 public:
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,
38 Context *on_finish) {
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);
42 }
43
44 ImageSync(
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,
52 Context *on_finish);
53 ~ImageSync() override;
54
55 void send() override;
56 void cancel() override;
57
58 protected:
59 void finish(int r) override;
60
61 private:
62 /**
63 * @verbatim
64 *
65 * <start>
66 * |
67 * v
68 * NOTIFY_SYNC_REQUEST
69 * |
70 * v
71 * PRUNE_CATCH_UP_SYNC_POINT
72 * |
73 * v
74 * CREATE_SYNC_POINT (skip if already exists and
75 * | not disconnected)
76 * v
77 * COPY_IMAGE . . . . . . . . . . . . . .
78 * | .
79 * v .
80 * FLUSH_SYNC_POINT .
81 * | . (image sync canceled)
82 * v .
83 * PRUNE_SYNC_POINTS .
84 * | .
85 * v .
86 * <finish> < . . . . . . . . . . . . . .
87 *
88 * @endverbatim
89 */
90
91 class ImageCopyProgressHandler;
92
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;
100
101 ceph::mutex m_lock;
102 bool m_canceled = false;
103
104 librbd::DeepCopyRequest<ImageCtxT> *m_image_copy_request = nullptr;
105 ImageCopyProgressHandler *m_image_copy_prog_handler = nullptr;
106
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;
112
113 librbd::SnapSeqs m_snap_seqs_copy;
114 image_sync::SyncPoints m_sync_points_copy;
115
116 int m_ret_val = 0;
117
118 void send_notify_sync_request();
119 void handle_notify_sync_request(int r);
120
121 void send_prune_catch_up_sync_point();
122 void handle_prune_catch_up_sync_point(int r);
123
124 void send_create_sync_point();
125 void handle_create_sync_point(int r);
126
127 void send_update_max_object_count();
128 void handle_update_max_object_count(int r);
129
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);
136
137 void send_flush_sync_point();
138 void handle_flush_sync_point(int r);
139
140 void send_prune_sync_points();
141 void handle_prune_sync_points(int r);
142
143 void update_progress(const std::string &description);
144 };
145
146 } // namespace mirror
147 } // namespace rbd
148
149 extern template class rbd::mirror::ImageSync<librbd::ImageCtx>;
150
151 #endif // RBD_MIRROR_IMAGE_SYNC_H