Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / image / OpenRequest.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_OPEN_REQUEST_H
5 #define CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H
6
7 #include "include/buffer.h"
8 #include <map>
9 #include <string>
10
11 class Context;
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace image {
18
19 template <typename ImageCtxT = ImageCtx>
20 class OpenRequest {
21 public:
22   static OpenRequest *create(ImageCtxT *image_ctx, bool skip_open_parent,
23                              Context *on_finish) {
24     return new OpenRequest(image_ctx, skip_open_parent, on_finish);
25   }
26
27   void send();
28
29 private:
30   /**
31    * @verbatim
32    *
33    * <start>
34    *    |
35    *    | (v1)
36    *    |-----> V1_DETECT_HEADER
37    *    |           |
38    *    |           \-------------------------------\
39    *    | (v2)                                      |
40    *    \-----> V2_DETECT_HEADER                    |
41    *                |                               |
42    *                v                               |
43    *            V2_GET_ID|NAME                      |
44    *                |                               |
45    *                v                               |
46    *            V2_GET_NAME_FROM_TRASH              |
47    *                |                               |
48    *                v                               |
49    *            V2_GET_IMMUTABLE_METADATA           |
50    *                |                               |
51    *                v                               |
52    *            V2_GET_STRIPE_UNIT_COUNT            |
53    *                |                               |
54    *                v                               |
55    *            V2_GET_CREATE_TIMESTAMP             |
56    *                |                               |
57    *                v                               |
58    *            V2_GET_DATA_POOL                    |
59    *                |                               |
60    *                v                               |
61    *      /---> V2_APPLY_METADATA -------------> REGISTER_WATCH (skip if
62    *      |         |                               |            read-only)
63    *      \---------/                               v
64    *                                             REFRESH
65    *                                                |
66    *                                                v
67    *                                             SET_SNAP (skip if no snap)
68    *                                                |
69    *                                                v
70    *                                             <finish>
71    *                                                ^
72    *     (on error)                                 |
73    *    * * * * * * > CLOSE ------------------------/
74    *
75    * @endverbatim
76    */
77
78   OpenRequest(ImageCtxT *image_ctx, bool skip_open_parent, Context *on_finish);
79
80   ImageCtxT *m_image_ctx;
81   bool m_skip_open_parent_image;
82   Context *m_on_finish;
83
84   bufferlist m_out_bl;
85   int m_error_result;
86
87   std::string m_last_metadata_key;
88   std::map<std::string, bufferlist> m_metadata;
89
90   void send_v1_detect_header();
91   Context *handle_v1_detect_header(int *result);
92
93   void send_v2_detect_header();
94   Context *handle_v2_detect_header(int *result);
95
96   void send_v2_get_id();
97   Context *handle_v2_get_id(int *result);
98
99   void send_v2_get_name();
100   Context *handle_v2_get_name(int *result);
101
102   void send_v2_get_name_from_trash();
103   Context *handle_v2_get_name_from_trash(int *result);
104
105   void send_v2_get_immutable_metadata();
106   Context *handle_v2_get_immutable_metadata(int *result);
107
108   void send_v2_get_stripe_unit_count();
109   Context *handle_v2_get_stripe_unit_count(int *result);
110
111   void send_v2_get_create_timestamp();
112   Context *handle_v2_get_create_timestamp(int *result);
113
114   void send_v2_get_data_pool();
115   Context *handle_v2_get_data_pool(int *result);
116
117   void send_v2_apply_metadata();
118   Context *handle_v2_apply_metadata(int *result);
119
120   void send_register_watch();
121   Context *handle_register_watch(int *result);
122
123   void send_refresh();
124   Context *handle_refresh(int *result);
125
126   Context *send_set_snap(int *result);
127   Context *handle_set_snap(int *result);
128
129   void send_close_image(int error_result);
130   Context *handle_close_image(int *result);
131
132 };
133
134 } // namespace image
135 } // namespace librbd
136
137 extern template class librbd::image::OpenRequest<librbd::ImageCtx>;
138
139 #endif // CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H