]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/ImageSync.h
update sources to v12.1.0
[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) .
93 * v
94 * PRUNE_SYNC_POINTS . (image sync canceled)
95 * | .
96 * v .
97 * <finish> < . . . . . . . . . . . . . .
98 *
99 * @endverbatim
100 */
101
102 typedef std::vector<librados::snap_t> SnapIds;
103 typedef std::map<librados::snap_t, SnapIds> SnapMap;
104
105 ImageCtxT *m_local_image_ctx;
106 ImageCtxT *m_remote_image_ctx;
107 SafeTimer *m_timer;
108 Mutex *m_timer_lock;
109 std::string m_mirror_uuid;
110 Journaler *m_journaler;
111 MirrorPeerClientMeta *m_client_meta;
112 ContextWQ *m_work_queue;
31f18b77 113 InstanceWatcher<ImageCtxT> *m_instance_watcher;
7c673cae
FG
114 ProgressContext *m_progress_ctx;
115
116 SnapMap m_snap_map;
117
118 Mutex m_lock;
119 bool m_canceled = false;
120
121 image_sync::SnapshotCopyRequest<ImageCtxT> *m_snapshot_copy_request = nullptr;
122 image_sync::ImageCopyRequest<ImageCtxT> *m_image_copy_request = nullptr;
123 decltype(ImageCtxT::object_map) m_object_map = nullptr;
124
31f18b77
FG
125 void send_notify_sync_request();
126 void handle_notify_sync_request(int r);
127
7c673cae
FG
128 void send_prune_catch_up_sync_point();
129 void handle_prune_catch_up_sync_point(int r);
130
131 void send_create_sync_point();
132 void handle_create_sync_point(int r);
133
134 void send_copy_snapshots();
135 void handle_copy_snapshots(int r);
136
137 void send_copy_image();
138 void handle_copy_image(int r);
139
140 void send_copy_object_map();
141 void handle_copy_object_map(int r);
142
143 void send_refresh_object_map();
144 void handle_refresh_object_map(int r);
145
146 void send_prune_sync_points();
147 void handle_prune_sync_points(int r);
148
149 void update_progress(const std::string &description);
150};
151
152} // namespace mirror
153} // namespace rbd
154
155extern template class rbd::mirror::ImageSync<librbd::ImageCtx>;
156
157#endif // RBD_MIRROR_IMAGE_SYNC_H