]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/image/RefreshRequest.h
import ceph nautilus 14.2.2
[ceph.git] / ceph / src / librbd / image / RefreshRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/buffer.h"
9 #include "include/utime.h"
10 #include "common/snap_types.h"
11 #include "cls/lock/cls_lock_types.h"
12 #include "librbd/ImageCtx.h"
13 #include "librbd/Types.h"
14 #include <string>
15 #include <vector>
16
17 class Context;
18
19 namespace librbd {
20
21 class ImageCtx;
22
23 namespace image {
24
25 template<typename> class RefreshParentRequest;
26
27 template<typename ImageCtxT = ImageCtx>
28 class RefreshRequest {
29 public:
30 static RefreshRequest *create(ImageCtxT &image_ctx, bool acquiring_lock,
31 bool skip_open_parent, Context *on_finish) {
32 return new RefreshRequest(image_ctx, acquiring_lock, skip_open_parent,
33 on_finish);
34 }
35
36 RefreshRequest(ImageCtxT &image_ctx, bool acquiring_lock,
37 bool skip_open_parent, Context *on_finish);
38 ~RefreshRequest();
39
40 void send();
41
42 private:
43 /**
44 * @verbatim
45 *
46 * <start> < * * * * * * * * * * * * * * * * * * * * * * * * * * (ENOENT)
47 * ^ | *
48 * * | (v1) *
49 * * |-----> V1_READ_HEADER -------------> GET_MIGRATION_HEADER (skip if not
50 * * | | migrating)
51 * * | (v2) v
52 * * \-----> V2_GET_MUTABLE_METADATA V1_GET_SNAPSHOTS
53 * * | |
54 * * | -EOPNOTSUPP v
55 * * | * * * V1_GET_LOCKS
56 * * | * * |
57 * * v v * v
58 * * V2_GET_PARENT <apply>
59 * * | |
60 * * v |
61 * * * * * * GET_MIGRATION_HEADER (skip if not |
62 * (ENOENT) | migrating) |
63 * v |
64 * V2_GET_METADATA |
65 * | |
66 * v |
67 * V2_GET_POOL_METADATA |
68 * | |
69 * v (skip if not enabled) |
70 * V2_GET_OP_FEATURES |
71 * | |
72 * v |
73 * V2_GET_GROUP |
74 * | |
75 * | -EOPNOTSUPP |
76 * | * * * * |
77 * | * * |
78 * v v * |
79 * V2_GET_SNAPSHOTS (skip if no snaps) |
80 * | |
81 * v |
82 * V2_REFRESH_PARENT (skip if no parent or |
83 * | refresh not needed) |
84 * v |
85 * V2_INIT_EXCLUSIVE_LOCK (skip if lock |
86 * | active or disabled) |
87 * v |
88 * V2_OPEN_OBJECT_MAP (skip if map |
89 * | active or disabled) |
90 * v |
91 * V2_OPEN_JOURNAL (skip if journal |
92 * | active or disabled) |
93 * v |
94 * V2_BLOCK_WRITES (skip if journal not |
95 * | disabled) |
96 * v |
97 * <apply> |
98 * | |
99 * v |
100 * V2_FINALIZE_REFRESH_PARENT (skip if refresh |
101 * | not needed) |
102 * (error) v |
103 * * * * * > V2_SHUT_DOWN_EXCLUSIVE_LOCK (skip if lock |
104 * | active or enabled) |
105 * v |
106 * V2_CLOSE_JOURNAL (skip if journal inactive |
107 * | or enabled) |
108 * v |
109 * V2_CLOSE_OBJECT_MAP (skip if map inactive |
110 * | or enabled) |
111 * | |
112 * \-------------------\/--------------------/
113 * |
114 * v
115 * FLUSH (skip if no new
116 * | snapshots)
117 * v
118 * <finish>
119 *
120 * @endverbatim
121 */
122
123 enum LegacySnapshot {
124 LEGACY_SNAPSHOT_DISABLED,
125 LEGACY_SNAPSHOT_ENABLED,
126 LEGACY_SNAPSHOT_ENABLED_NO_TIMESTAMP
127 };
128
129 ImageCtxT &m_image_ctx;
130 bool m_acquiring_lock;
131 bool m_skip_open_parent_image;
132 Context *m_on_finish;
133
134 cls::rbd::MigrationSpec m_migration_spec;
135 int m_error_result;
136 bool m_flush_aio;
137 decltype(m_image_ctx.exclusive_lock) m_exclusive_lock;
138 decltype(m_image_ctx.object_map) m_object_map;
139 decltype(m_image_ctx.journal) m_journal;
140 RefreshParentRequest<ImageCtxT> *m_refresh_parent;
141
142 bufferlist m_out_bl;
143
144 bool m_legacy_parent = false;
145 LegacySnapshot m_legacy_snapshot = LEGACY_SNAPSHOT_DISABLED;
146
147 uint8_t m_order = 0;
148 uint64_t m_size = 0;
149 uint64_t m_features = 0;
150 uint64_t m_incompatible_features = 0;
151 uint64_t m_flags = 0;
152 uint64_t m_op_features = 0;
153
154 librados::IoCtx m_pool_metadata_io_ctx;
155 std::string m_last_metadata_key;
156 std::map<std::string, bufferlist> m_metadata;
157
158 std::string m_object_prefix;
159 ParentImageInfo m_parent_md;
160 bool m_head_parent_overlap = false;
161 cls::rbd::GroupSpec m_group_spec;
162
163 ::SnapContext m_snapc;
164 std::vector<cls::rbd::SnapshotInfo> m_snap_infos;
165 std::vector<ParentImageInfo> m_snap_parents;
166 std::vector<uint8_t> m_snap_protection;
167 std::vector<uint64_t> m_snap_flags;
168
169 std::map<rados::cls::lock::locker_id_t,
170 rados::cls::lock::locker_info_t> m_lockers;
171 std::string m_lock_tag;
172 bool m_exclusive_locked = false;
173
174 bool m_blocked_writes = false;
175 bool m_incomplete_update = false;
176
177 void send_get_migration_header();
178 Context *handle_get_migration_header(int *result);
179
180 void send_v1_read_header();
181 Context *handle_v1_read_header(int *result);
182
183 void send_v1_get_snapshots();
184 Context *handle_v1_get_snapshots(int *result);
185
186 void send_v1_get_locks();
187 Context *handle_v1_get_locks(int *result);
188
189 void send_v1_apply();
190 Context *handle_v1_apply(int *result);
191
192 void send_v2_get_mutable_metadata();
193 Context *handle_v2_get_mutable_metadata(int *result);
194
195 void send_v2_get_parent();
196 Context *handle_v2_get_parent(int *result);
197
198 void send_v2_get_metadata();
199 Context *handle_v2_get_metadata(int *result);
200
201 void send_v2_get_pool_metadata();
202 Context *handle_v2_get_pool_metadata(int *result);
203
204 void send_v2_get_op_features();
205 Context *handle_v2_get_op_features(int *result);
206
207 void send_v2_get_group();
208 Context *handle_v2_get_group(int *result);
209
210 void send_v2_get_snapshots();
211 Context *handle_v2_get_snapshots(int *result);
212
213 void send_v2_get_snapshots_legacy();
214 Context *handle_v2_get_snapshots_legacy(int *result);
215
216 void send_v2_refresh_parent();
217 Context *handle_v2_refresh_parent(int *result);
218
219 void send_v2_init_exclusive_lock();
220 Context *handle_v2_init_exclusive_lock(int *result);
221
222 void send_v2_open_journal();
223 Context *handle_v2_open_journal(int *result);
224
225 void send_v2_block_writes();
226 Context *handle_v2_block_writes(int *result);
227
228 void send_v2_open_object_map();
229 Context *handle_v2_open_object_map(int *result);
230
231 void send_v2_apply();
232 Context *handle_v2_apply(int *result);
233
234 Context *send_v2_finalize_refresh_parent();
235 Context *handle_v2_finalize_refresh_parent(int *result);
236
237 Context *send_v2_shut_down_exclusive_lock();
238 Context *handle_v2_shut_down_exclusive_lock(int *result);
239
240 Context *send_v2_close_journal();
241 Context *handle_v2_close_journal(int *result);
242
243 Context *send_v2_close_object_map();
244 Context *handle_v2_close_object_map(int *result);
245
246 Context *send_flush_aio();
247 Context *handle_flush_aio(int *result);
248
249 Context *handle_error(int *result);
250
251 void save_result(int *result) {
252 if (m_error_result == 0 && *result < 0) {
253 m_error_result = *result;
254 }
255 }
256
257 void apply();
258 int get_parent_info(uint64_t snap_id, ParentImageInfo *parent_md,
259 MigrationInfo *migration_info);
260 bool get_migration_info(ParentImageInfo *parent_md,
261 MigrationInfo *migration_info);
262 };
263
264 } // namespace image
265 } // namespace librbd
266
267 extern template class librbd::image::RefreshRequest<librbd::ImageCtx>;
268
269 #endif // CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H