]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/image/CloneRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / image / CloneRequest.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_CLONE_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_CLONE_REQUEST_H
6
7 #include "cls/rbd/cls_rbd_types.h"
8 #include "common/config_fwd.h"
9 #include "librbd/internal.h"
10 #include "include/rbd/librbd.hpp"
11
12 class Context;
13
14 using librados::IoCtx;
15
16 namespace librbd {
17
18 namespace asio { struct ContextWQ; }
19
20 namespace image {
21
22 template <typename ImageCtxT = ImageCtx>
23 class CloneRequest {
24 public:
25 static CloneRequest *create(
26 ConfigProxy& config, IoCtx& parent_io_ctx,
27 const std::string& parent_image_id,
28 const std::string& parent_snap_name,
29 const cls::rbd::SnapshotNamespace& parent_snap_namespace,
30 uint64_t parent_snap_id,
31 IoCtx &c_ioctx, const std::string &c_name,
32 const std::string &c_id, ImageOptions c_options,
33 cls::rbd::MirrorImageMode mirror_image_mode,
34 const std::string &non_primary_global_image_id,
35 const std::string &primary_mirror_uuid,
36 asio::ContextWQ *op_work_queue, Context *on_finish) {
37 return new CloneRequest(config, parent_io_ctx, parent_image_id,
38 parent_snap_name, parent_snap_namespace,
39 parent_snap_id, c_ioctx, c_name, c_id, c_options,
40 mirror_image_mode, non_primary_global_image_id,
41 primary_mirror_uuid, op_work_queue, on_finish);
42 }
43
44 CloneRequest(ConfigProxy& config, IoCtx& parent_io_ctx,
45 const std::string& parent_image_id,
46 const std::string& parent_snap_name,
47 const cls::rbd::SnapshotNamespace& parent_snap_namespace,
48 uint64_t parent_snap_id,
49 IoCtx &c_ioctx, const std::string &c_name,
50 const std::string &c_id, ImageOptions c_options,
51 cls::rbd::MirrorImageMode mirror_image_mode,
52 const std::string &non_primary_global_image_id,
53 const std::string &primary_mirror_uuid,
54 asio::ContextWQ *op_work_queue, Context *on_finish);
55
56 void send();
57
58 private:
59 /**
60 * @verbatim
61 *
62 * <start>
63 * |
64 * v
65 * OPEN PARENT
66 * |
67 * v
68 * VALIDATE CHILD <finish>
69 * | ^
70 * v |
71 * CREATE CHILD * * * * * * * * * > CLOSE PARENT
72 * | ^
73 * v |
74 * OPEN CHILD * * * * * * * * * * > REMOVE CHILD
75 * | ^
76 * v |
77 * ATTACH PARENT * * * * * * * * > CLOSE CHILD
78 * | ^
79 * v *
80 * ATTACH CHILD * * * * * * * * * * * *
81 * | *
82 * v *
83 * COPY META DATA * * * * * * * * * * ^
84 * | *
85 * v (skip if not needed) *
86 * GET MIRROR MODE * * * * * * * * * ^
87 * | *
88 * v (skip if not needed) *
89 * SET MIRROR ENABLED * * * * * * * * *
90 * |
91 * v
92 * CLOSE CHILD
93 * |
94 * v
95 * CLOSE PARENT
96 * |
97 * v
98 * <finish>
99 *
100 * @endverbatim
101 */
102
103 ConfigProxy& m_config;
104 IoCtx &m_parent_io_ctx;
105 std::string m_parent_image_id;
106 std::string m_parent_snap_name;
107 cls::rbd::SnapshotNamespace m_parent_snap_namespace;
108 uint64_t m_parent_snap_id;
109 ImageCtxT *m_parent_image_ctx;
110
111 IoCtx &m_ioctx;
112 std::string m_name;
113 std::string m_id;
114 ImageOptions m_opts;
115 cls::rbd::ParentImageSpec m_pspec;
116 ImageCtxT *m_imctx;
117 cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
118 cls::rbd::MirrorImageMode m_mirror_image_mode;
119 const std::string m_non_primary_global_image_id;
120 const std::string m_primary_mirror_uuid;
121 NoOpProgressContext m_no_op;
122 asio::ContextWQ *m_op_work_queue;
123 Context *m_on_finish;
124
125 CephContext *m_cct;
126 uint64_t m_clone_format = 2;
127 bool m_use_p_features;
128 uint64_t m_features;
129 bufferlist m_out_bl;
130 uint64_t m_size;
131 int m_r_saved = 0;
132
133 void validate_options();
134
135 void open_parent();
136 void handle_open_parent(int r);
137
138 void validate_parent();
139
140 void validate_child();
141 void handle_validate_child(int r);
142
143 void create_child();
144 void handle_create_child(int r);
145
146 void open_child();
147 void handle_open_child(int r);
148
149 void attach_parent();
150 void handle_attach_parent(int r);
151
152 void attach_child();
153 void handle_attach_child(int r);
154
155 void copy_metadata();
156 void handle_copy_metadata(int r);
157
158 void get_mirror_mode();
159 void handle_get_mirror_mode(int r);
160
161 void enable_mirror();
162 void handle_enable_mirror(int r);
163
164 void close_child();
165 void handle_close_child(int r);
166
167 void remove_child();
168 void handle_remove_child(int r);
169
170 void close_parent();
171 void handle_close_parent(int r);
172
173 void complete(int r);
174 };
175
176 } //namespace image
177 } //namespace librbd
178
179 extern template class librbd::image::CloneRequest<librbd::ImageCtx>;
180
181 #endif // CEPH_LIBRBD_IMAGE_CLONE_REQUEST_H