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