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