1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H
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"
25 template<typename
> class RefreshParentRequest
;
27 template<typename ImageCtxT
= ImageCtx
>
28 class RefreshRequest
{
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
,
36 RefreshRequest(ImageCtxT
&image_ctx
, bool acquiring_lock
,
37 bool skip_open_parent
, Context
*on_finish
);
46 * <start> < * * * * * * * * * * * * * * * * * * * * * * * * * * (ENOENT)
49 * * |-----> V1_READ_HEADER -------------> GET_MIGRATION_HEADER (skip if not
52 * * \-----> V2_GET_MUTABLE_METADATA V1_GET_SNAPSHOTS
55 * * | * * * V1_GET_LOCKS
58 * * V2_GET_PARENT <apply>
61 * * * * * * GET_MIGRATION_HEADER (skip if not |
62 * (ENOENT) | migrating) |
67 * V2_GET_POOL_METADATA |
69 * v (skip if not enabled) |
70 * V2_GET_OP_FEATURES |
79 * V2_GET_SNAPSHOTS (skip if no snaps) |
82 * V2_REFRESH_PARENT (skip if no parent or |
83 * | refresh not needed) |
85 * V2_INIT_EXCLUSIVE_LOCK (skip if lock |
86 * | active or disabled) |
88 * V2_OPEN_OBJECT_MAP (skip if map |
89 * | active or disabled) |
91 * V2_OPEN_JOURNAL (skip if journal |
92 * | active or disabled) |
94 * V2_BLOCK_WRITES (skip if journal not |
100 * V2_FINALIZE_REFRESH_PARENT (skip if refresh |
103 * * * * * > V2_SHUT_DOWN_EXCLUSIVE_LOCK (skip if lock |
104 * | active or enabled) |
106 * V2_CLOSE_JOURNAL (skip if journal inactive |
109 * V2_CLOSE_OBJECT_MAP (skip if map inactive |
112 * \-------------------\/--------------------/
115 * FLUSH (skip if no new
123 enum LegacySnapshot
{
124 LEGACY_SNAPSHOT_DISABLED
,
125 LEGACY_SNAPSHOT_ENABLED
,
126 LEGACY_SNAPSHOT_ENABLED_NO_TIMESTAMP
129 ImageCtxT
&m_image_ctx
;
130 bool m_acquiring_lock
;
131 bool m_skip_open_parent_image
;
132 Context
*m_on_finish
;
134 cls::rbd::MigrationSpec m_migration_spec
;
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
;
144 bool m_legacy_parent
= false;
145 LegacySnapshot m_legacy_snapshot
= LEGACY_SNAPSHOT_DISABLED
;
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 uint32_t m_read_only_flags
= 0U;
154 bool m_read_only
= false;
156 librados::IoCtx m_pool_metadata_io_ctx
;
157 std::map
<std::string
, bufferlist
> m_metadata
;
159 std::string m_object_prefix
;
160 ParentImageInfo m_parent_md
;
161 bool m_head_parent_overlap
= false;
162 cls::rbd::GroupSpec m_group_spec
;
164 ::SnapContext m_snapc
;
165 std::vector
<cls::rbd::SnapshotInfo
> m_snap_infos
;
166 std::vector
<ParentImageInfo
> m_snap_parents
;
167 std::vector
<uint8_t> m_snap_protection
;
168 std::vector
<uint64_t> m_snap_flags
;
170 std::map
<rados::cls::lock::locker_id_t
,
171 rados::cls::lock::locker_info_t
> m_lockers
;
172 std::string m_lock_tag
;
173 bool m_exclusive_locked
= false;
175 bool m_blocked_writes
= false;
176 bool m_incomplete_update
= false;
178 void send_get_migration_header();
179 Context
*handle_get_migration_header(int *result
);
181 void send_v1_read_header();
182 Context
*handle_v1_read_header(int *result
);
184 void send_v1_get_snapshots();
185 Context
*handle_v1_get_snapshots(int *result
);
187 void send_v1_get_locks();
188 Context
*handle_v1_get_locks(int *result
);
190 void send_v1_apply();
191 Context
*handle_v1_apply(int *result
);
193 void send_v2_get_mutable_metadata();
194 Context
*handle_v2_get_mutable_metadata(int *result
);
196 void send_v2_get_parent();
197 Context
*handle_v2_get_parent(int *result
);
199 void send_v2_get_metadata();
200 Context
*handle_v2_get_metadata(int *result
);
202 void send_v2_get_pool_metadata();
203 Context
*handle_v2_get_pool_metadata(int *result
);
205 void send_v2_get_op_features();
206 Context
*handle_v2_get_op_features(int *result
);
208 void send_v2_get_group();
209 Context
*handle_v2_get_group(int *result
);
211 void send_v2_get_snapshots();
212 Context
*handle_v2_get_snapshots(int *result
);
214 void send_v2_get_snapshots_legacy();
215 Context
*handle_v2_get_snapshots_legacy(int *result
);
217 void send_v2_refresh_parent();
218 Context
*handle_v2_refresh_parent(int *result
);
220 void send_v2_init_exclusive_lock();
221 Context
*handle_v2_init_exclusive_lock(int *result
);
223 void send_v2_open_journal();
224 Context
*handle_v2_open_journal(int *result
);
226 void send_v2_block_writes();
227 Context
*handle_v2_block_writes(int *result
);
229 void send_v2_open_object_map();
230 Context
*handle_v2_open_object_map(int *result
);
232 void send_v2_apply();
233 Context
*handle_v2_apply(int *result
);
235 Context
*send_v2_finalize_refresh_parent();
236 Context
*handle_v2_finalize_refresh_parent(int *result
);
238 Context
*send_v2_shut_down_exclusive_lock();
239 Context
*handle_v2_shut_down_exclusive_lock(int *result
);
241 Context
*send_v2_close_journal();
242 Context
*handle_v2_close_journal(int *result
);
244 Context
*send_v2_close_object_map();
245 Context
*handle_v2_close_object_map(int *result
);
247 Context
*send_flush_aio();
248 Context
*handle_flush_aio(int *result
);
250 Context
*handle_error(int *result
);
252 void save_result(int *result
) {
253 if (m_error_result
== 0 && *result
< 0) {
254 m_error_result
= *result
;
259 int get_parent_info(uint64_t snap_id
, ParentImageInfo
*parent_md
,
260 MigrationInfo
*migration_info
);
261 int get_migration_info(ParentImageInfo
*parent_md
,
262 MigrationInfo
*migration_info
,
263 bool* migration_info_valid
);
267 } // namespace librbd
269 extern template class librbd::image::RefreshRequest
<librbd::ImageCtx
>;
271 #endif // CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H