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