Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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>
47    *    |
48    *    | (v1)
49    *    |-----> V1_READ_HEADER ---> V1_GET_SNAPSHOTS ---> V1_GET_LOCKS
50    *    |                                                     |
51    *    | (v2)                                                v
52    *    \-----> V2_GET_MUTABLE_METADATA                    <apply>
53    *                |                                         |
54    *                v                                         |
55    *            V2_GET_FLAGS                                  |
56    *                |                                         |
57    *                v                                         |
58    *            V2_GET_GROUP                                  |
59    *                |                                         |
60    *                v                                         |
61    *            V2_GET_SNAPSHOTS (skip if no snaps)           |
62    *                |                                         |
63    *                v                                         |
64    *            V2_GET_SNAP_TIMESTAMPS                        |
65    *                |                                         |
66    *                v                                         |
67    *            V2_GET_SNAP_NAMESPACES                        |
68    *                |                                         |
69    *                v                                         |
70    *            V2_REFRESH_PARENT (skip if no parent or       |
71    *                |              refresh not needed)        |
72    *                v                                         |
73    *            V2_INIT_EXCLUSIVE_LOCK (skip if lock          |
74    *                |                   active or disabled)   |
75    *                v                                         |
76    *            V2_OPEN_OBJECT_MAP (skip if map               |
77    *                |               active or disabled)       |
78    *                v                                         |
79    *            V2_OPEN_JOURNAL (skip if journal              |
80    *                |            active or disabled)          |
81    *                v                                         |
82    *            V2_BLOCK_WRITES (skip if journal not          |
83    *                |            disabled)                    |
84    *                v                                         |
85    *             <apply>                                      |
86    *                |                                         |
87    *                v                                         |
88    *            V2_FINALIZE_REFRESH_PARENT (skip if refresh   |
89    *                |                       not needed)       |
90    *  (error)       v                                         |
91    *  * * * * > V2_SHUT_DOWN_EXCLUSIVE_LOCK (skip if lock     |
92    *                |                      active or enabled) |
93    *                v                                         |
94    *            V2_CLOSE_JOURNAL (skip if journal inactive    |
95    *                |             or enabled)                 |
96    *                v                                         |
97    *            V2_CLOSE_OBJECT_MAP (skip if map inactive     |
98    *                |                or enabled)              |
99    *                |                                         |
100    *                \-------------------\/--------------------/
101    *                                    |
102    *                                    v
103    *                                  FLUSH (skip if no new
104    *                                    |    snapshots)
105    *                                    v
106    *                                 <finish>
107    *
108    * @endverbatim
109    */
110
111   ImageCtxT &m_image_ctx;
112   bool m_acquiring_lock;
113   bool m_skip_open_parent_image;
114   Context *m_on_finish;
115
116   int m_error_result;
117   bool m_flush_aio;
118   decltype(m_image_ctx.exclusive_lock) m_exclusive_lock;
119   decltype(m_image_ctx.object_map) m_object_map;
120   decltype(m_image_ctx.journal) m_journal;
121   RefreshParentRequest<ImageCtxT> *m_refresh_parent;
122
123   bufferlist m_out_bl;
124
125   uint8_t m_order;
126   uint64_t m_size;
127   uint64_t m_features;
128   uint64_t m_incompatible_features;
129   uint64_t m_flags;
130   std::string m_object_prefix;
131   ParentInfo m_parent_md;
132   cls::rbd::GroupSpec m_group_spec;
133
134   ::SnapContext m_snapc;
135   std::vector<std::string> m_snap_names;
136   std::vector<cls::rbd::SnapshotNamespace> m_snap_namespaces;
137   std::vector<uint64_t> m_snap_sizes;
138   std::vector<ParentInfo> m_snap_parents;
139   std::vector<uint8_t> m_snap_protection;
140   std::vector<uint64_t> m_snap_flags;
141   std::vector<utime_t> m_snap_timestamps;
142
143   std::map<rados::cls::lock::locker_id_t,
144            rados::cls::lock::locker_info_t> m_lockers;
145   std::string m_lock_tag;
146   bool m_exclusive_locked;
147
148   bool m_blocked_writes = false;
149   bool m_incomplete_update = false;
150
151   void send_v1_read_header();
152   Context *handle_v1_read_header(int *result);
153
154   void send_v1_get_snapshots();
155   Context *handle_v1_get_snapshots(int *result);
156
157   void send_v1_get_locks();
158   Context *handle_v1_get_locks(int *result);
159
160   void send_v1_apply();
161   Context *handle_v1_apply(int *result);
162
163   void send_v2_get_mutable_metadata();
164   Context *handle_v2_get_mutable_metadata(int *result);
165
166   void send_v2_get_flags();
167   Context *handle_v2_get_flags(int *result);
168
169   void send_v2_get_group();
170   Context *handle_v2_get_group(int *result);
171
172   void send_v2_get_snapshots();
173   Context *handle_v2_get_snapshots(int *result);
174
175   void send_v2_get_snap_namespaces();
176   Context *handle_v2_get_snap_namespaces(int *result);
177
178   void send_v2_get_snap_timestamps();
179   Context *handle_v2_get_snap_timestamps(int *result);
180
181   void send_v2_refresh_parent();
182   Context *handle_v2_refresh_parent(int *result);
183
184   void send_v2_init_exclusive_lock();
185   Context *handle_v2_init_exclusive_lock(int *result);
186
187   void send_v2_open_journal();
188   Context *handle_v2_open_journal(int *result);
189
190   void send_v2_block_writes();
191   Context *handle_v2_block_writes(int *result);
192
193   void send_v2_open_object_map();
194   Context *handle_v2_open_object_map(int *result);
195
196   void send_v2_apply();
197   Context *handle_v2_apply(int *result);
198
199   Context *send_v2_finalize_refresh_parent();
200   Context *handle_v2_finalize_refresh_parent(int *result);
201
202   Context *send_v2_shut_down_exclusive_lock();
203   Context *handle_v2_shut_down_exclusive_lock(int *result);
204
205   Context *send_v2_close_journal();
206   Context *handle_v2_close_journal(int *result);
207
208   Context *send_v2_close_object_map();
209   Context *handle_v2_close_object_map(int *result);
210
211   Context *send_flush_aio();
212   Context *handle_flush_aio(int *result);
213
214   Context *handle_error(int *result);
215
216   void save_result(int *result) {
217     if (m_error_result == 0 && *result < 0) {
218       m_error_result = *result;
219     }
220   }
221
222   void apply();
223   int get_parent_info(uint64_t snap_id, ParentInfo *parent_md);
224 };
225
226 } // namespace image
227 } // namespace librbd
228
229 extern template class librbd::image::RefreshRequest<librbd::ImageCtx>;
230
231 #endif // CEPH_LIBRBD_IMAGE_REFRESH_REQUEST_H