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