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