]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_CREATE_REQUEST_H | |
5 | #define CEPH_LIBRBD_IMAGE_CREATE_REQUEST_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/buffer.h" | |
7c673cae | 9 | #include "include/rados/librados.hpp" |
7c673cae | 10 | #include "include/rbd/librbd.hpp" |
11fdf7f2 | 11 | #include "cls/rbd/cls_rbd_types.h" |
7c673cae | 12 | #include "librbd/ImageCtx.h" |
7c673cae | 13 | |
11fdf7f2 | 14 | class ConfigProxy; |
7c673cae | 15 | class Context; |
11fdf7f2 | 16 | class ContextWQ; |
7c673cae FG |
17 | |
18 | using librados::IoCtx; | |
19 | ||
11fdf7f2 | 20 | namespace journal { class Journaler; } |
7c673cae FG |
21 | |
22 | namespace librbd { | |
23 | namespace image { | |
24 | ||
25 | template <typename ImageCtxT = ImageCtx> | |
26 | class CreateRequest { | |
27 | public: | |
11fdf7f2 TL |
28 | static CreateRequest *create(const ConfigProxy& config, IoCtx &ioctx, |
29 | const std::string &image_name, | |
7c673cae FG |
30 | const std::string &image_id, uint64_t size, |
31 | const ImageOptions &image_options, | |
32 | const std::string &non_primary_global_image_id, | |
33 | const std::string &primary_mirror_uuid, | |
34 | bool skip_mirror_enable, | |
35 | ContextWQ *op_work_queue, Context *on_finish) { | |
11fdf7f2 TL |
36 | return new CreateRequest(config, ioctx, image_name, image_id, size, |
37 | image_options, non_primary_global_image_id, | |
38 | primary_mirror_uuid, skip_mirror_enable, | |
39 | op_work_queue, on_finish); | |
7c673cae FG |
40 | } |
41 | ||
42 | static int validate_order(CephContext *cct, uint8_t order); | |
43 | ||
44 | void send(); | |
45 | ||
46 | private: | |
47 | /** | |
48 | * @verbatim | |
49 | * | |
50 | * <start> . . . . > . . . . . | |
51 | * | . | |
52 | * v . | |
91327a77 | 53 | * VALIDATE DATA POOL v (pool validation |
7c673cae FG |
54 | * | . disabled) |
55 | * v . | |
11fdf7f2 | 56 | * (error: bottom up) ADD IMAGE TO DIRECTORY < . . . . |
7c673cae FG |
57 | * _______<_______ | |
58 | * | | v | |
11fdf7f2 | 59 | * | | CREATE ID OBJECT |
7c673cae | 60 | * | | / | |
11fdf7f2 | 61 | * | REMOVE FROM DIR <-------/ v |
7c673cae FG |
62 | * | | NEGOTIATE FEATURES (when using default features) |
63 | * | | | | |
64 | * | | v (stripingv2 disabled) | |
65 | * | | CREATE IMAGE. . . . > . . . . | |
66 | * v | / | . | |
11fdf7f2 | 67 | * | REMOVE ID OBJ <---------/ v . |
7c673cae FG |
68 | * | | SET STRIPE UNIT COUNT . |
69 | * | | / | \ . . . . . > . . . . | |
70 | * | REMOVE HEADER OBJ<------/ v /. (object-map | |
71 | * | |\ OBJECT MAP RESIZE . . < . . * v disabled) | |
72 | * | | \ / | \ . . . . . > . . . . | |
73 | * | | *<-----------/ v /. (journaling | |
74 | * | | FETCH MIRROR MODE. . < . . * v disabled) | |
75 | * | | / | . | |
76 | * | REMOVE OBJECT MAP<--------/ v . | |
77 | * | |\ JOURNAL CREATE . | |
78 | * | | \ / | . | |
79 | * v | *<------------/ v . | |
80 | * | | MIRROR IMAGE ENABLE . | |
81 | * | | / | . | |
82 | * | JOURNAL REMOVE*<-------/ | . | |
83 | * | v . | |
84 | * |_____________>___________________<finish> . . . . < . . . . | |
85 | * | |
86 | * @endverbatim | |
87 | */ | |
88 | ||
11fdf7f2 TL |
89 | CreateRequest(const ConfigProxy& config, IoCtx &ioctx, |
90 | const std::string &image_name, | |
7c673cae FG |
91 | const std::string &image_id, uint64_t size, |
92 | const ImageOptions &image_options, | |
93 | const std::string &non_primary_global_image_id, | |
94 | const std::string &primary_mirror_uuid, | |
95 | bool skip_mirror_enable, | |
96 | ContextWQ *op_work_queue, Context *on_finish); | |
97 | ||
11fdf7f2 TL |
98 | const ConfigProxy& m_config; |
99 | IoCtx m_io_ctx; | |
7c673cae FG |
100 | IoCtx m_data_io_ctx; |
101 | std::string m_image_name; | |
102 | std::string m_image_id; | |
103 | uint64_t m_size; | |
104 | uint8_t m_order = 0; | |
105 | uint64_t m_features = 0; | |
106 | uint64_t m_stripe_unit = 0; | |
107 | uint64_t m_stripe_count = 0; | |
108 | uint8_t m_journal_order = 0; | |
109 | uint8_t m_journal_splay_width = 0; | |
110 | std::string m_journal_pool; | |
111 | std::string m_data_pool; | |
112 | int64_t m_data_pool_id = -1; | |
113 | const std::string m_non_primary_global_image_id; | |
114 | const std::string m_primary_mirror_uuid; | |
115 | bool m_skip_mirror_enable; | |
116 | bool m_negotiate_features = false; | |
117 | ||
118 | ContextWQ *m_op_work_queue; | |
119 | Context *m_on_finish; | |
120 | ||
121 | CephContext *m_cct; | |
11fdf7f2 | 122 | int m_r_saved = 0; // used to return actual error after cleanup |
7c673cae FG |
123 | bool m_force_non_primary; |
124 | file_layout_t m_layout; | |
125 | std::string m_id_obj, m_header_obj, m_objmap_name; | |
126 | ||
127 | bufferlist m_outbl; | |
11fdf7f2 | 128 | rbd_mirror_mode_t m_mirror_mode = RBD_MIRROR_MODE_DISABLED; |
7c673cae FG |
129 | cls::rbd::MirrorImage m_mirror_image_internal; |
130 | ||
91327a77 AA |
131 | void validate_data_pool(); |
132 | void handle_validate_data_pool(int r); | |
7c673cae | 133 | |
7c673cae FG |
134 | void add_image_to_directory(); |
135 | void handle_add_image_to_directory(int r); | |
136 | ||
11fdf7f2 TL |
137 | void create_id_object(); |
138 | void handle_create_id_object(int r); | |
139 | ||
7c673cae FG |
140 | void negotiate_features(); |
141 | void handle_negotiate_features(int r); | |
142 | ||
143 | void create_image(); | |
144 | void handle_create_image(int r); | |
145 | ||
146 | void set_stripe_unit_count(); | |
147 | void handle_set_stripe_unit_count(int r); | |
148 | ||
149 | void object_map_resize(); | |
150 | void handle_object_map_resize(int r); | |
151 | ||
152 | void fetch_mirror_mode(); | |
153 | void handle_fetch_mirror_mode(int r); | |
154 | ||
155 | void journal_create(); | |
156 | void handle_journal_create(int r); | |
157 | ||
158 | void mirror_image_enable(); | |
159 | void handle_mirror_image_enable(int r); | |
160 | ||
161 | void complete(int r); | |
162 | ||
163 | // cleanup | |
164 | void journal_remove(); | |
165 | void handle_journal_remove(int r); | |
166 | ||
167 | void remove_object_map(); | |
168 | void handle_remove_object_map(int r); | |
169 | ||
170 | void remove_header_object(); | |
171 | void handle_remove_header_object(int r); | |
172 | ||
11fdf7f2 TL |
173 | void remove_id_object(); |
174 | void handle_remove_id_object(int r); | |
175 | ||
7c673cae FG |
176 | void remove_from_dir(); |
177 | void handle_remove_from_dir(int r); | |
178 | ||
7c673cae FG |
179 | }; |
180 | ||
181 | } //namespace image | |
182 | } //namespace librbd | |
183 | ||
184 | extern template class librbd::image::CreateRequest<librbd::ImageCtx>; | |
185 | ||
186 | #endif // CEPH_LIBRBD_IMAGE_CREATE_REQUEST_H |