]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/CreateImageRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / CreateImageRequest.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 RBD_MIRROR_IMAGE_REPLAYER_CREATE_IMAGE_REQUEST_H
5 #define RBD_MIRROR_IMAGE_REPLAYER_CREATE_IMAGE_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/types.h"
9 #include "include/rados/librados.hpp"
10 #include "cls/rbd/cls_rbd_types.h"
11 #include "librbd/Types.h"
12 #include <string>
13
14 class Context;
15 namespace librbd { class ImageCtx; }
16 namespace librbd { class ImageOptions; }
17
18 namespace rbd {
19 namespace mirror {
20
21 class PoolMetaCache;
22 template <typename> struct Threads;
23
24 namespace image_replayer {
25
26 template <typename ImageCtxT = librbd::ImageCtx>
27 class CreateImageRequest {
28 public:
29 static CreateImageRequest *create(
30 Threads<ImageCtxT> *threads,
31 librados::IoCtx &local_io_ctx,
32 const std::string &global_image_id,
33 const std::string &remote_mirror_uuid,
34 const std::string &local_image_name,
35 const std::string &local_image_id,
36 ImageCtxT *remote_image_ctx,
37 PoolMetaCache* pool_meta_cache,
38 cls::rbd::MirrorImageMode mirror_image_mode,
39 Context *on_finish) {
40 return new CreateImageRequest(threads, local_io_ctx, global_image_id,
41 remote_mirror_uuid, local_image_name,
42 local_image_id, remote_image_ctx,
43 pool_meta_cache, mirror_image_mode,
44 on_finish);
45 }
46
47 CreateImageRequest(
48 Threads<ImageCtxT> *threads, librados::IoCtx &local_io_ctx,
49 const std::string &global_image_id,
50 const std::string &remote_mirror_uuid,
51 const std::string &local_image_name,
52 const std::string &local_image_id,
53 ImageCtxT *remote_image_ctx,
54 PoolMetaCache* pool_meta_cache,
55 cls::rbd::MirrorImageMode mirror_image_mode,
56 Context *on_finish);
57
58 void send();
59
60 private:
61 /**
62 * @verbatim
63 *
64 * <start> * * * * * * * * * * * * * * * * * * * * * * * * * * * *
65 * | *
66 * | (non-clone) *
67 * |\------------> CREATE_IMAGE ---------------------\ * (error)
68 * | | *
69 * | (clone) | *
70 * \-------------> GET_PARENT_GLOBAL_IMAGE_ID * * * | * * * *
71 * | | * *
72 * v | *
73 * GET_LOCAL_PARENT_IMAGE_ID * * * * | * * * *
74 * | | * *
75 * v | *
76 * OPEN_REMOTE_PARENT * * * * * * * | * * * *
77 * | | * *
78 * v | *
79 * CLONE_IMAGE | *
80 * | | *
81 * v | *
82 * CLOSE_REMOTE_PARENT | *
83 * | v *
84 * \------------------------> <finish> < * *
85 * @endverbatim
86 */
87
88 Threads<ImageCtxT> *m_threads;
89 librados::IoCtx &m_local_io_ctx;
90 std::string m_global_image_id;
91 std::string m_remote_mirror_uuid;
92 std::string m_local_image_name;
93 std::string m_local_image_id;
94 ImageCtxT *m_remote_image_ctx;
95 PoolMetaCache* m_pool_meta_cache;
96 cls::rbd::MirrorImageMode m_mirror_image_mode;
97 Context *m_on_finish;
98
99 librados::IoCtx m_remote_parent_io_ctx;
100 ImageCtxT *m_remote_parent_image_ctx = nullptr;
101 cls::rbd::ParentImageSpec m_remote_parent_spec;
102
103 librados::IoCtx m_local_parent_io_ctx;
104 cls::rbd::ParentImageSpec m_local_parent_spec;
105
106 bufferlist m_out_bl;
107 std::string m_parent_global_image_id;
108 std::string m_parent_pool_name;
109 int m_ret_val = 0;
110
111 void create_image();
112 void handle_create_image(int r);
113
114 void get_parent_global_image_id();
115 void handle_get_parent_global_image_id(int r);
116
117 void get_local_parent_image_id();
118 void handle_get_local_parent_image_id(int r);
119
120 void open_remote_parent_image();
121 void handle_open_remote_parent_image(int r);
122
123 void clone_image();
124 void handle_clone_image(int r);
125
126 void close_remote_parent_image();
127 void handle_close_remote_parent_image(int r);
128
129 void error(int r);
130 void finish(int r);
131
132 int validate_parent();
133
134 void populate_image_options(librbd::ImageOptions* image_options);
135
136 };
137
138 } // namespace image_replayer
139 } // namespace mirror
140 } // namespace rbd
141
142 extern template class rbd::mirror::image_replayer::CreateImageRequest<librbd::ImageCtx>;
143
144 #endif // RBD_MIRROR_IMAGE_REPLAYER_CREATE_IMAGE_REQUEST_H