Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 "librbd/Types.h"
11 #include <string>
12
13 class Context;
14 class ContextWQ;
15 namespace librbd { class ImageCtx; }
16
17 namespace rbd {
18 namespace mirror {
19 namespace image_replayer {
20
21 template <typename ImageCtxT = librbd::ImageCtx>
22 class CreateImageRequest {
23 public:
24   static CreateImageRequest *create(librados::IoCtx &local_io_ctx,
25                                     ContextWQ *work_queue,
26                                     const std::string &global_image_id,
27                                     const std::string &remote_mirror_uuid,
28                                     const std::string &local_image_name,
29                                     const std::string &local_image_id,
30                                     ImageCtxT *remote_image_ctx,
31                                     Context *on_finish) {
32     return new CreateImageRequest(local_io_ctx, work_queue, global_image_id,
33                                   remote_mirror_uuid, local_image_name,
34                                   local_image_id, remote_image_ctx, on_finish);
35   }
36
37   CreateImageRequest(librados::IoCtx &local_io_ctx, ContextWQ *work_queue,
38                      const std::string &global_image_id,
39                      const std::string &remote_mirror_uuid,
40                      const std::string &local_image_name,
41                      const std::string &local_image_id,
42                      ImageCtxT *remote_image_ctx,
43                      Context *on_finish);
44
45   void send();
46
47 private:
48   /**
49    * @verbatim
50    *
51    * <start>  * * * * * * * * * * * * * * * * * * * * * * * * * * * *
52    *    |                                                           *
53    *    | (non-clone)                                               *
54    *    |\------------> CREATE_IMAGE ---------------------\         * (error)
55    *    |                                                 |         *
56    *    | (clone)                                         |         *
57    *    \-------------> GET_PARENT_GLOBAL_IMAGE_ID  * * * | * * *   *
58    *                        |                             |       * *
59    *                        v                             |         *
60    *                    GET_LOCAL_PARENT_IMAGE_ID * * * * | * * *   *
61    *                        |                             |       * *
62    *                        v                             |         *
63    *                    OPEN_REMOTE_PARENT  * * * * * * * | * * *   *
64    *                        |                             |       * *
65    *                        v                             |         *
66    *                    OPEN_LOCAL_PARENT * * * * * * *   |         *
67    *                        |                         *   |         *
68    *                        v                         *   |         *
69    *                    SET_LOCAL_PARENT_SNAP         *   |         *
70    *                        |         *               *   |         *
71    *                        v         *               *   |         *
72    *                    CLONE_IMAGE   *               *   |         *
73    *                        |         *               *   |         *
74    *                        v         v               *   |         *
75    *                    CLOSE_LOCAL_PARENT            *   |         *
76    *                        |                         *   |         *
77    *                        v                         *   |         *
78    *                    CLOSE_REMOTE_PARENT < * * * * *   |         *
79    *                        |                             v         *
80    *                        \------------------------> <finish> < * *
81    * @endverbatim
82    */
83
84   librados::IoCtx &m_local_io_ctx;
85   ContextWQ *m_work_queue;
86   std::string m_global_image_id;
87   std::string m_remote_mirror_uuid;
88   std::string m_local_image_name;
89   std::string m_local_image_id;
90   ImageCtxT *m_remote_image_ctx;
91   Context *m_on_finish;
92
93   librados::IoCtx m_remote_parent_io_ctx;
94   ImageCtxT *m_remote_parent_image_ctx = nullptr;
95   librbd::ParentSpec m_remote_parent_spec;
96
97   librados::IoCtx m_local_parent_io_ctx;
98   ImageCtxT *m_local_parent_image_ctx = nullptr;
99   librbd::ParentSpec m_local_parent_spec;
100
101   bufferlist m_out_bl;
102   std::string m_parent_global_image_id;
103   std::string m_parent_pool_name;
104   std::string m_parent_snap_name;
105   int m_ret_val = 0;
106
107   void create_image();
108   void handle_create_image(int r);
109
110   void get_parent_global_image_id();
111   void handle_get_parent_global_image_id(int r);
112
113   void get_local_parent_image_id();
114   void handle_get_local_parent_image_id(int r);
115
116   void open_remote_parent_image();
117   void handle_open_remote_parent_image(int r);
118
119   void open_local_parent_image();
120   void handle_open_local_parent_image(int r);
121
122   void set_local_parent_snap();
123   void handle_set_local_parent_snap(int r);
124
125   void clone_image();
126   void handle_clone_image(int r);
127
128   void close_local_parent_image();
129   void handle_close_local_parent_image(int r);
130
131   void close_remote_parent_image();
132   void handle_close_remote_parent_image(int r);
133
134   void error(int r);
135   void finish(int r);
136
137   int validate_parent();
138
139 };
140
141 } // namespace image_replayer
142 } // namespace mirror
143 } // namespace rbd
144
145 extern template class rbd::mirror::image_replayer::CreateImageRequest<librbd::ImageCtx>;
146
147 #endif // RBD_MIRROR_IMAGE_REPLAYER_CREATE_IMAGE_REQUEST_H