Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 "include/rbd/librbd.hpp"
9 #include "librbd/internal.h"
10
11 class Context;
12
13 using librados::IoCtx;
14
15 namespace librbd {
16 namespace image {
17
18 template <typename ImageCtxT = ImageCtx>
19 class CloneRequest {
20 public:
21   static CloneRequest *create(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name,
22                               const std::string &c_id, ImageOptions c_options,
23                               const std::string &non_primary_global_image_id,
24                               const std::string &primary_mirror_uuid,
25                               ContextWQ *op_work_queue, Context *on_finish) {
26     return new CloneRequest(p_imctx, c_ioctx, c_name, c_id, c_options,
27                              non_primary_global_image_id, primary_mirror_uuid,
28                              op_work_queue, on_finish);
29   }
30
31   void send();
32 private:
33   /**
34    * @verbatim
35    *
36    *                                  <start>
37    *                                     |
38    *                                     v
39    *                             VALIDATE PARENT
40    *                                     |
41    *                                     v
42    * (error: bottom up)           VALIDATE CHILD
43    *  _______<_______                    |
44    * |               |                   v
45    * |               |             CREATE IMAGE
46    * |               |                   |
47    * |               |                   v          (parent_md exists)
48    * |               |              OPEN IMAGE. . . . . > . . . .
49    * v               |               /   |                      .
50    * |         REMOVE IMAGE<--------/    v                      .
51    * |               |           SET PARENT IN HEADER           .
52    * |          CLOSE IMAGE          /   |                      .
53    * |               ^-------<------/    v                      .
54    * |               |\           UPDATE DIR_CHILDREN. . < . . . 
55    * |               | \              /  |
56    * |               |  *<-----------/   v
57    * |               |                REFRESH
58    * |               |                /  |                     
59    * |   CLEAN DIR_CHILDREN <--------/   v            (meta is empty)
60    * |               |\         GET META IN PARENT  . . . . . . .
61    * |               | \              /  |                      .
62    * v               |  *<-----------/   v     (journaling disabled)           .
63    * |               |          SET META IN CHILD . . . . . . . v
64    * |               |               /   |                      .
65    * |               -------<-------/    v       (no need to enable mirror)             .
66    * |               |            GET MIRROR MODE . . . . . . . v
67    * |               |               /   |                      .
68    * |               -------<-------/    v                      .
69    * |               |          ENABLE MIRROR MODE              v
70    * |               |               /   |                      .
71    * |               -------<-------/    v                      .
72    * |                               CLOSE IMAGE . . . . .< . . .
73    * |                                   |
74    * |                                   v
75    * |_____________>__________________<finish>
76    *
77    * @endverbatim
78    */
79
80   CloneRequest(ImageCtxT *p_imctx, IoCtx &c_ioctx, const std::string &c_name,
81                               const std::string &c_id,
82                               ImageOptions c_options,
83                               const std::string &non_primary_global_image_id,
84                               const std::string &primary_mirror_uuid,
85                               ContextWQ *op_work_queue, Context *on_finish);
86
87   ImageCtxT *m_p_imctx;
88   IoCtx &m_ioctx;
89   std::string m_name;
90   std::string m_id;
91   ImageOptions m_opts;
92   ParentSpec m_pspec;
93   ImageCtxT *m_imctx;
94   cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
95   const std::string m_non_primary_global_image_id;
96   const std::string m_primary_mirror_uuid;
97   NoOpProgressContext m_no_op;
98   ContextWQ *m_op_work_queue;
99   Context *m_on_finish;
100
101   CephContext *m_cct;
102   bool m_use_p_features;
103   uint64_t m_p_features;
104   uint64_t m_features;
105   map<string, bufferlist> m_pairs;
106   bufferlist m_out_bl;
107   uint64_t m_size;
108   int m_r_saved = 0;
109   bool m_is_primary;
110   bool m_force_non_primary;
111
112   void validate_options();
113
114   void send_validate_parent();
115   void handle_validate_parent(int r);
116
117   void send_validate_child();
118   void handle_validate_child(int r);
119
120   void send_create();
121   void handle_create(int r);
122
123   void send_open();
124   void handle_open(int r);
125
126   void send_set_parent();
127   void handle_set_parent(int r);
128
129   void send_add_child();
130   void handle_add_child(int r);
131
132   void send_refresh();
133   void handle_refresh(int r);
134
135   void send_metadata_list();
136   void handle_metadata_list(int r);
137
138   void send_metadata_set();
139   void handle_metadata_set(int r);
140
141   void get_mirror_mode();
142   void handle_get_mirror_mode(int r);
143
144   void send_enable_mirror();
145   void handle_enable_mirror(int r);
146
147   void send_close();
148   void handle_close(int r);
149
150   void send_remove();
151   void handle_remove(int r);
152
153   void send_remove_child();
154   void handle_remove_child(int r);
155
156   void complete(int r);
157 };
158
159 } //namespace image
160 } //namespace librbd
161
162 extern template class librbd::image::CloneRequest<librbd::ImageCtx>;
163
164 #endif // CEPH_LIBRBD_IMAGE_CLONE_REQUEST_H