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
);
49 * |-----> V1_READ_HEADER ---> V1_GET_SNAPSHOTS ---> V1_GET_LOCKS
52 * \-----> V2_GET_MUTABLE_METADATA <apply>
64 * V2_GET_SNAPSHOTS (skip if no snaps) |
67 * V2_GET_SNAP_TIMESTAMPS |
70 * V2_GET_SNAP_NAMESPACES |
73 * V2_REFRESH_PARENT (skip if no parent or |
74 * | refresh not needed) |
76 * V2_INIT_EXCLUSIVE_LOCK (skip if lock |
77 * | active or disabled) |
79 * V2_OPEN_OBJECT_MAP (skip if map |
80 * | active or disabled) |
82 * V2_OPEN_JOURNAL (skip if journal |
83 * | active or disabled) |
85 * V2_BLOCK_WRITES (skip if journal not |
91 * V2_FINALIZE_REFRESH_PARENT (skip if refresh |
94 * * * * * > V2_SHUT_DOWN_EXCLUSIVE_LOCK (skip if lock |
95 * | active or enabled) |
97 * V2_CLOSE_JOURNAL (skip if journal inactive |
100 * V2_CLOSE_OBJECT_MAP (skip if map inactive |
103 * \-------------------\/--------------------/
106 * FLUSH (skip if no new
114 ImageCtxT
&m_image_ctx
;
115 bool m_acquiring_lock
;
116 bool m_skip_open_parent_image
;
117 Context
*m_on_finish
;
121 decltype(m_image_ctx
.exclusive_lock
) m_exclusive_lock
;
122 decltype(m_image_ctx
.object_map
) m_object_map
;
123 decltype(m_image_ctx
.journal
) m_journal
;
124 RefreshParentRequest
<ImageCtxT
> *m_refresh_parent
;
131 uint64_t m_incompatible_features
;
134 std::string m_last_metadata_key
;
135 std::map
<std::string
, bufferlist
> m_metadata
;
137 std::string m_object_prefix
;
138 ParentInfo m_parent_md
;
139 cls::rbd::GroupSpec m_group_spec
;
141 ::SnapContext m_snapc
;
142 std::vector
<std::string
> m_snap_names
;
143 std::vector
<cls::rbd::SnapshotNamespace
> m_snap_namespaces
;
144 std::vector
<uint64_t> m_snap_sizes
;
145 std::vector
<ParentInfo
> m_snap_parents
;
146 std::vector
<uint8_t> m_snap_protection
;
147 std::vector
<uint64_t> m_snap_flags
;
148 std::vector
<utime_t
> m_snap_timestamps
;
150 std::map
<rados::cls::lock::locker_id_t
,
151 rados::cls::lock::locker_info_t
> m_lockers
;
152 std::string m_lock_tag
;
153 bool m_exclusive_locked
;
155 bool m_blocked_writes
= false;
156 bool m_incomplete_update
= false;
158 void send_v1_read_header();
159 Context
*handle_v1_read_header(int *result
);
161 void send_v1_get_snapshots();
162 Context
*handle_v1_get_snapshots(int *result
);
164 void send_v1_get_locks();
165 Context
*handle_v1_get_locks(int *result
);
167 void send_v1_apply();
168 Context
*handle_v1_apply(int *result
);
170 void send_v2_get_mutable_metadata();
171 Context
*handle_v2_get_mutable_metadata(int *result
);
173 void send_v2_get_metadata();
174 Context
*handle_v2_get_metadata(int *result
);
176 void send_v2_get_flags();
177 Context
*handle_v2_get_flags(int *result
);
179 void send_v2_get_group();
180 Context
*handle_v2_get_group(int *result
);
182 void send_v2_get_snapshots();
183 Context
*handle_v2_get_snapshots(int *result
);
185 void send_v2_get_snap_namespaces();
186 Context
*handle_v2_get_snap_namespaces(int *result
);
188 void send_v2_get_snap_timestamps();
189 Context
*handle_v2_get_snap_timestamps(int *result
);
191 void send_v2_refresh_parent();
192 Context
*handle_v2_refresh_parent(int *result
);
194 void send_v2_init_exclusive_lock();
195 Context
*handle_v2_init_exclusive_lock(int *result
);
197 void send_v2_open_journal();
198 Context
*handle_v2_open_journal(int *result
);
200 void send_v2_block_writes();
201 Context
*handle_v2_block_writes(int *result
);
203 void send_v2_open_object_map();
204 Context
*handle_v2_open_object_map(int *result
);
206 void send_v2_apply();
207 Context
*handle_v2_apply(int *result
);
209 Context
*send_v2_finalize_refresh_parent();
210 Context
*handle_v2_finalize_refresh_parent(int *result
);
212 Context
*send_v2_shut_down_exclusive_lock();
213 Context
*handle_v2_shut_down_exclusive_lock(int *result
);
215 Context
*send_v2_close_journal();
216 Context
*handle_v2_close_journal(int *result
);
218 Context
*send_v2_close_object_map();
219 Context
*handle_v2_close_object_map(int *result
);
221 Context
*send_flush_aio();
222 Context
*handle_flush_aio(int *result
);
224 Context
*handle_error(int *result
);
226 void save_result(int *result
) {
227 if (m_error_result
== 0 && *result
< 0) {
228 m_error_result
= *result
;
233 int get_parent_info(uint64_t snap_id
, ParentInfo
*parent_md
);
237 } // namespace librbd
239 extern template class librbd::image::RefreshRequest
<librbd::ImageCtx
>;
241 #endif // CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H