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