Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / image / RemoveRequest.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_REMOVE_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_REMOVE_REQUEST_H
6
7 #include "librbd/image/TypeTraits.h"
8
9 class Context;
10 class ContextWQ;
11 class SafeTimer;
12
13 namespace librbd {
14
15 class ImageCtx;
16 class ProgressContext;
17
18 namespace image {
19
20 template<typename ImageCtxT = ImageCtx>
21 class RemoveRequest {
22 private:
23   // mock unit testing support
24   typedef ::librbd::image::TypeTraits<ImageCtxT> TypeTraits;
25   typedef typename TypeTraits::ContextWQ ContextWQ;
26 public:
27   static RemoveRequest *create(librados::IoCtx &ioctx,
28                                const std::string &image_name,
29                                const std::string &image_id,
30                                bool force, bool from_trash_remove,
31                                ProgressContext &prog_ctx,
32                                ContextWQ *op_work_queue,
33                                Context *on_finish) {
34     return new RemoveRequest(ioctx, image_name, image_id, force,
35                              from_trash_remove, prog_ctx, op_work_queue,
36                              on_finish);
37   }
38
39   void send();
40
41 private:
42   /**
43    * @verbatim
44    *
45    *                                  <start>
46    *                                     |
47    *                                     v
48    *                                OPEN IMAGE------------------\
49    *                                     |                      |
50    *                                     v                      |
51    *       error                   CHECK EXCLUSIVE LOCK---\     |
52    * /-------<-------\                   |                |     |
53    * |               |                   |            (acquired)|
54    * |               |                   v                |     |
55    * |               |            AQUIRE EXCLUSIVE LOCK   |     |
56    * |               |               /   |                |     |
57    * |               |------<-------/    |                |     |
58    * |               |                   v                |     |
59    * |               |            VALIDATE IMAGE REMOVAL<-/     |
60    * |               |                /  |                      v
61    * |               \------<--------/   |                      |
62    * |                                   v                      |
63    * |                              TRIM IMAGE                  |
64    * |                                   |                      |
65    * v                                   v                      |
66    * |                            REMOVE CHILD                  |
67    * |                                   |                      |
68    * |                                   v                      v
69    * \--------->------------------>CLOSE IMAGE                  |
70    *                                     |                      |
71    *       error                         v                      |
72    * /------<--------\              REMOVE HEADER<--------------/
73    * |               |                /  |
74    * |               |-------<-------/   |
75    * |               |                   v
76    * |               |              REMOVE JOURNAL
77    * |               |                /  |
78    * |               |-------<-------/   |
79    * |               |                   v
80    * v               ^          REMOVE OBJECTMAP
81    * |               |                /  |
82    * |               |-------<-------/   |
83    * |               |                   v
84    * |               |            REMOVE MIRROR IMAGE
85    * |               |                /  |
86    * |               |-------<-------/   |
87    * |               |                   v
88    * |               |            REMOVE ID OBJECT
89    * |               |                /  |
90    * |               |-------<-------/   |
91    * |               |                   v
92    * |               |              REMOVE IMAGE
93    * |               |                /  |
94    * |               \-------<-------/   |
95    * |                                   v
96    * \------------------>------------<finish>
97    *
98    * @endverbatim
99    */
100
101   RemoveRequest(librados::IoCtx &ioctx, const std::string &image_name,
102                 const std::string &image_id, bool force, bool from_trash_remove,
103                 ProgressContext &prog_ctx, ContextWQ *op_work_queue,
104                 Context *on_finish);
105
106   librados::IoCtx &m_ioctx;
107   std::string m_image_name;
108   std::string m_image_id;
109   bool m_force;
110   bool m_from_trash_remove;
111   ProgressContext &m_prog_ctx;
112   ContextWQ *m_op_work_queue;
113   Context *m_on_finish;
114
115   CephContext *m_cct;
116   std::string m_header_oid;
117   bool m_old_format = false;
118   bool m_unknown_format = true;
119   ImageCtxT *m_image_ctx;
120
121   decltype(m_image_ctx->exclusive_lock) m_exclusive_lock = nullptr;
122
123   int m_ret_val = 0;
124   bufferlist m_out_bl;
125   std::list<obj_watch_t> m_watchers;
126   std::list<obj_watch_t> m_mirror_watchers;
127
128   void open_image();
129   void handle_open_image(int r);
130
131   void send_journal_remove();
132   void handle_journal_remove(int r);
133
134   void send_object_map_remove();
135   void handle_object_map_remove(int r);
136
137   void mirror_image_remove();
138   void handle_mirror_image_remove(int r);
139
140   void check_exclusive_lock();
141
142   void acquire_exclusive_lock();
143   void handle_exclusive_lock(int r);
144   void handle_exclusive_lock_force(int r);
145
146   void validate_image_removal();
147   void check_image_snaps();
148
149   void list_image_watchers();
150   void handle_list_image_watchers(int r);
151
152   void get_mirror_image();
153   void handle_get_mirror_image(int r);
154
155   void list_mirror_watchers();
156   void handle_list_mirror_watchers(int r);
157
158   void check_image_watchers();
159
160   void check_group();
161   void handle_check_group(int r);
162
163   void trim_image();
164   void handle_trim_image(int r);
165
166   void remove_child();
167   void handle_remove_child(int r);
168
169   void send_disable_mirror();
170   void handle_disable_mirror(int r);
171
172   void send_close_image(int r);
173   void handle_send_close_image(int r);
174
175   void remove_header();
176   void handle_remove_header(int r);
177
178   void remove_header_v2();
179   void handle_remove_header_v2(int r);
180
181   void remove_image();
182
183   void remove_v1_image();
184   void handle_remove_v1_image(int r);
185
186   void remove_v2_image();
187
188   void dir_get_image_id();
189   void handle_dir_get_image_id(int r);
190
191   void dir_get_image_name();
192   void handle_dir_get_image_name(int r);
193
194   void remove_id_object();
195   void handle_remove_id_object(int r);
196
197   void dir_remove_image();
198   void handle_dir_remove_image(int r);
199
200   void finish(int r);
201 };
202
203 } // namespace image
204 } // namespace librbd
205
206 extern template class librbd::image::RemoveRequest<librbd::ImageCtx>;
207
208 #endif // CEPH_LIBRBD_IMAGE_REMOVE_REQUEST_H