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