]>
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" | |
9 | #include "librbd/journal/TypeTraits.h" | |
11fdf7f2 | 10 | #include "librbd/journal/Types.h" |
7c673cae FG |
11 | #include "common/Mutex.h" |
12 | #include "tools/rbd_mirror/BaseRequest.h" | |
13 | #include <map> | |
14 | #include <vector> | |
15 | ||
16 | class Context; | |
17 | class ContextWQ; | |
7c673cae | 18 | namespace journal { class Journaler; } |
11fdf7f2 TL |
19 | namespace librbd { class ProgressContext; } |
20 | namespace librbd { template <typename> class DeepCopyRequest; } | |
7c673cae FG |
21 | namespace librbd { namespace journal { struct MirrorPeerClientMeta; } } |
22 | ||
23 | namespace rbd { | |
24 | namespace mirror { | |
25 | ||
26 | class ProgressContext; | |
27 | ||
31f18b77 FG |
28 | template <typename> class InstanceWatcher; |
29 | ||
7c673cae FG |
30 | template <typename ImageCtxT = librbd::ImageCtx> |
31 | class ImageSync : public BaseRequest { | |
32 | public: | |
33 | typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits; | |
34 | typedef typename TypeTraits::Journaler Journaler; | |
35 | typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta; | |
36 | ||
37 | static ImageSync* create(ImageCtxT *local_image_ctx, | |
11fdf7f2 TL |
38 | ImageCtxT *remote_image_ctx, |
39 | SafeTimer *timer, Mutex *timer_lock, | |
40 | const std::string &mirror_uuid, | |
7c673cae FG |
41 | Journaler *journaler, |
42 | MirrorPeerClientMeta *client_meta, | |
31f18b77 FG |
43 | ContextWQ *work_queue, |
44 | InstanceWatcher<ImageCtxT> *instance_watcher, | |
45 | Context *on_finish, | |
46 | ProgressContext *progress_ctx = nullptr) { | |
7c673cae FG |
47 | return new ImageSync(local_image_ctx, remote_image_ctx, timer, timer_lock, |
48 | mirror_uuid, journaler, client_meta, work_queue, | |
31f18b77 | 49 | instance_watcher, on_finish, progress_ctx); |
7c673cae FG |
50 | } |
51 | ||
52 | ImageSync(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx, | |
53 | SafeTimer *timer, Mutex *timer_lock, const std::string &mirror_uuid, | |
54 | Journaler *journaler, MirrorPeerClientMeta *client_meta, | |
31f18b77 FG |
55 | ContextWQ *work_queue, InstanceWatcher<ImageCtxT> *instance_watcher, |
56 | Context *on_finish, ProgressContext *progress_ctx = nullptr); | |
7c673cae FG |
57 | ~ImageSync() override; |
58 | ||
59 | void send() override; | |
60 | void cancel() override; | |
61 | ||
31f18b77 FG |
62 | protected: |
63 | void finish(int r) override; | |
64 | ||
7c673cae FG |
65 | private: |
66 | /** | |
67 | * @verbatim | |
68 | * | |
69 | * <start> | |
70 | * | | |
71 | * v | |
31f18b77 FG |
72 | * NOTIFY_SYNC_REQUEST |
73 | * | | |
74 | * v | |
7c673cae FG |
75 | * PRUNE_CATCH_UP_SYNC_POINT |
76 | * | | |
77 | * v | |
78 | * CREATE_SYNC_POINT (skip if already exists and | |
79 | * | not disconnected) | |
80 | * v | |
7c673cae FG |
81 | * COPY_IMAGE . . . . . . . . . . . . . . |
82 | * | . | |
83 | * v . | |
11fdf7f2 TL |
84 | * FLUSH_SYNC_POINT . |
85 | * | . (image sync canceled) | |
7c673cae | 86 | * v . |
11fdf7f2 | 87 | * PRUNE_SYNC_POINTS . |
b32b8144 FG |
88 | * | . |
89 | * v . | |
7c673cae FG |
90 | * <finish> < . . . . . . . . . . . . . . |
91 | * | |
92 | * @endverbatim | |
93 | */ | |
94 | ||
95 | typedef std::vector<librados::snap_t> SnapIds; | |
96 | typedef std::map<librados::snap_t, SnapIds> SnapMap; | |
11fdf7f2 | 97 | class ImageCopyProgressContext; |
7c673cae FG |
98 | |
99 | ImageCtxT *m_local_image_ctx; | |
100 | ImageCtxT *m_remote_image_ctx; | |
101 | SafeTimer *m_timer; | |
102 | Mutex *m_timer_lock; | |
103 | std::string m_mirror_uuid; | |
104 | Journaler *m_journaler; | |
105 | MirrorPeerClientMeta *m_client_meta; | |
106 | ContextWQ *m_work_queue; | |
31f18b77 | 107 | InstanceWatcher<ImageCtxT> *m_instance_watcher; |
7c673cae FG |
108 | ProgressContext *m_progress_ctx; |
109 | ||
110 | SnapMap m_snap_map; | |
111 | ||
112 | Mutex m_lock; | |
113 | bool m_canceled = false; | |
114 | ||
11fdf7f2 TL |
115 | librbd::DeepCopyRequest<ImageCtxT> *m_image_copy_request = nullptr; |
116 | librbd::ProgressContext *m_image_copy_prog_ctx = nullptr; | |
117 | ||
118 | bool m_updating_sync_point = false; | |
119 | Context *m_update_sync_ctx = nullptr; | |
120 | double m_update_sync_point_interval; | |
121 | uint64_t m_image_copy_object_no = 0; | |
122 | uint64_t m_image_copy_object_count = 0; | |
123 | MirrorPeerClientMeta m_client_meta_copy; | |
124 | ||
125 | int m_ret_val = 0; | |
7c673cae | 126 | |
31f18b77 FG |
127 | void send_notify_sync_request(); |
128 | void handle_notify_sync_request(int r); | |
129 | ||
7c673cae FG |
130 | void send_prune_catch_up_sync_point(); |
131 | void handle_prune_catch_up_sync_point(int r); | |
132 | ||
133 | void send_create_sync_point(); | |
134 | void handle_create_sync_point(int r); | |
135 | ||
11fdf7f2 TL |
136 | void send_update_max_object_count(); |
137 | void handle_update_max_object_count(int r); | |
7c673cae FG |
138 | |
139 | void send_copy_image(); | |
140 | void handle_copy_image(int r); | |
11fdf7f2 TL |
141 | void handle_copy_image_update_progress(uint64_t object_no, |
142 | uint64_t object_count); | |
143 | void send_update_sync_point(); | |
144 | void handle_update_sync_point(int r); | |
7c673cae | 145 | |
11fdf7f2 TL |
146 | void send_flush_sync_point(); |
147 | void handle_flush_sync_point(int r); | |
7c673cae FG |
148 | |
149 | void send_prune_sync_points(); | |
150 | void handle_prune_sync_points(int r); | |
151 | ||
152 | void update_progress(const std::string &description); | |
153 | }; | |
154 | ||
155 | } // namespace mirror | |
156 | } // namespace rbd | |
157 | ||
158 | extern template class rbd::mirror::ImageSync<librbd::ImageCtx>; | |
159 | ||
160 | #endif // RBD_MIRROR_IMAGE_SYNC_H |