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