]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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" | |
9f95a23c TL |
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" | |
7c673cae FG |
13 | |
14 | class Context; | |
7c673cae | 15 | namespace journal { class Journaler; } |
11fdf7f2 | 16 | namespace librbd { template <typename> class DeepCopyRequest; } |
7c673cae FG |
17 | |
18 | namespace rbd { | |
19 | namespace mirror { | |
20 | ||
21 | class ProgressContext; | |
31f18b77 | 22 | template <typename> class InstanceWatcher; |
9f95a23c TL |
23 | template <typename> class Threads; |
24 | ||
25 | namespace image_sync { struct SyncPointHandler; } | |
31f18b77 | 26 | |
7c673cae | 27 | template <typename ImageCtxT = librbd::ImageCtx> |
9f95a23c | 28 | class ImageSync : public CancelableRequest { |
7c673cae | 29 | public: |
9f95a23c TL |
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); | |
7c673cae FG |
42 | } |
43 | ||
9f95a23c TL |
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); | |
7c673cae FG |
53 | ~ImageSync() override; |
54 | ||
55 | void send() override; | |
56 | void cancel() override; | |
57 | ||
31f18b77 FG |
58 | protected: |
59 | void finish(int r) override; | |
60 | ||
7c673cae FG |
61 | private: |
62 | /** | |
63 | * @verbatim | |
64 | * | |
65 | * <start> | |
66 | * | | |
67 | * v | |
31f18b77 FG |
68 | * NOTIFY_SYNC_REQUEST |
69 | * | | |
70 | * v | |
7c673cae FG |
71 | * PRUNE_CATCH_UP_SYNC_POINT |
72 | * | | |
73 | * v | |
74 | * CREATE_SYNC_POINT (skip if already exists and | |
75 | * | not disconnected) | |
76 | * v | |
7c673cae FG |
77 | * COPY_IMAGE . . . . . . . . . . . . . . |
78 | * | . | |
79 | * v . | |
11fdf7f2 TL |
80 | * FLUSH_SYNC_POINT . |
81 | * | . (image sync canceled) | |
7c673cae | 82 | * v . |
11fdf7f2 | 83 | * PRUNE_SYNC_POINTS . |
b32b8144 FG |
84 | * | . |
85 | * v . | |
7c673cae FG |
86 | * <finish> < . . . . . . . . . . . . . . |
87 | * | |
88 | * @endverbatim | |
89 | */ | |
90 | ||
1911f103 | 91 | class ImageCopyProgressHandler; |
7c673cae | 92 | |
9f95a23c | 93 | Threads<ImageCtxT>* m_threads; |
7c673cae FG |
94 | ImageCtxT *m_local_image_ctx; |
95 | ImageCtxT *m_remote_image_ctx; | |
9f95a23c TL |
96 | std::string m_local_mirror_uuid; |
97 | image_sync::SyncPointHandler* m_sync_point_handler; | |
31f18b77 | 98 | InstanceWatcher<ImageCtxT> *m_instance_watcher; |
7c673cae FG |
99 | ProgressContext *m_progress_ctx; |
100 | ||
9f95a23c | 101 | ceph::mutex m_lock; |
7c673cae FG |
102 | bool m_canceled = false; |
103 | ||
11fdf7f2 | 104 | librbd::DeepCopyRequest<ImageCtxT> *m_image_copy_request = nullptr; |
1911f103 | 105 | ImageCopyProgressHandler *m_image_copy_prog_handler = nullptr; |
11fdf7f2 TL |
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; | |
9f95a23c TL |
112 | |
113 | librbd::SnapSeqs m_snap_seqs_copy; | |
114 | image_sync::SyncPoints m_sync_points_copy; | |
11fdf7f2 TL |
115 | |
116 | int m_ret_val = 0; | |
7c673cae | 117 | |
31f18b77 FG |
118 | void send_notify_sync_request(); |
119 | void handle_notify_sync_request(int r); | |
120 | ||
7c673cae FG |
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 | ||
11fdf7f2 TL |
127 | void send_update_max_object_count(); |
128 | void handle_update_max_object_count(int r); | |
7c673cae FG |
129 | |
130 | void send_copy_image(); | |
131 | void handle_copy_image(int r); | |
11fdf7f2 TL |
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); | |
7c673cae | 136 | |
11fdf7f2 TL |
137 | void send_flush_sync_point(); |
138 | void handle_flush_sync_point(int r); | |
7c673cae FG |
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 |