]>
Commit | Line | Data |
---|---|---|
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_MIRROR_ENABLE_REQUEST_H | |
5 | #define CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H | |
6 | ||
11fdf7f2 TL |
7 | #include "include/buffer_fwd.h" |
8 | #include "include/rados/librados_fwd.hpp" | |
9f95a23c | 9 | #include "include/rbd/librbd.hpp" |
7c673cae | 10 | #include "cls/rbd/cls_rbd_types.h" |
9f95a23c TL |
11 | #include "librbd/ImageCtx.h" |
12 | #include "librbd/mirror/Types.h" | |
7c673cae FG |
13 | #include <map> |
14 | #include <string> | |
15 | ||
16 | class Context; | |
7c673cae | 17 | |
7c673cae | 18 | namespace librbd { |
f67539c2 TL |
19 | |
20 | namespace asio { struct ContextWQ; } | |
21 | ||
7c673cae FG |
22 | namespace mirror { |
23 | ||
24 | template <typename ImageCtxT = ImageCtx> | |
25 | class EnableRequest { | |
26 | public: | |
9f95a23c TL |
27 | static EnableRequest *create(ImageCtxT *image_ctx, |
28 | cls::rbd::MirrorImageMode mode, | |
1911f103 TL |
29 | const std::string &non_primary_global_image_id, |
30 | bool image_clean, Context *on_finish) { | |
9f95a23c | 31 | return new EnableRequest(image_ctx->md_ctx, image_ctx->id, image_ctx, mode, |
1911f103 TL |
32 | non_primary_global_image_id, image_clean, |
33 | image_ctx->op_work_queue, on_finish); | |
7c673cae FG |
34 | } |
35 | static EnableRequest *create(librados::IoCtx &io_ctx, | |
36 | const std::string &image_id, | |
9f95a23c | 37 | cls::rbd::MirrorImageMode mode, |
7c673cae | 38 | const std::string &non_primary_global_image_id, |
f67539c2 | 39 | bool image_clean, asio::ContextWQ *op_work_queue, |
1911f103 | 40 | Context *on_finish) { |
9f95a23c | 41 | return new EnableRequest(io_ctx, image_id, nullptr, mode, |
1911f103 TL |
42 | non_primary_global_image_id, image_clean, |
43 | op_work_queue, on_finish); | |
7c673cae FG |
44 | } |
45 | ||
46 | void send(); | |
47 | ||
48 | private: | |
49 | /** | |
50 | * @verbatim | |
51 | * | |
52 | * <start> | |
53 | * | | |
54 | * v | |
11fdf7f2 TL |
55 | * GET_MIRROR_IMAGE * * * * * * * |
56 | * | * (on error) | |
9f95a23c | 57 | * v (skip if not needed) * |
7c673cae FG |
58 | * GET_TAG_OWNER * * * * * * * * |
59 | * | * | |
9f95a23c | 60 | * v (skip if not needed) * |
1911f103 TL |
61 | * OPEN_IMAGE * |
62 | * | * | |
63 | * v (skip if not needed) * | |
9f95a23c TL |
64 | * CREATE_PRIMARY_SNAPSHOT * * * |
65 | * | * | |
1911f103 TL |
66 | * v (skip of not opened) * |
67 | * CLOSE_IMAGE * | |
68 | * | * | |
9f95a23c TL |
69 | * v (skip if not needed) * |
70 | * ENABLE_NON_PRIMARY_FEATURE * | |
7c673cae | 71 | * | * |
f67539c2 | 72 | * v (skip if not needed) * |
9f95a23c | 73 | * IMAGE_STATE_UPDATE * * * * * * |
7c673cae FG |
74 | * | * |
75 | * v * | |
76 | * <finish> < * * * * * * * * * | |
77 | * | |
78 | * @endverbatim | |
79 | */ | |
80 | ||
81 | EnableRequest(librados::IoCtx &io_ctx, const std::string &image_id, | |
9f95a23c | 82 | ImageCtxT* image_ctx, cls::rbd::MirrorImageMode mode, |
7c673cae | 83 | const std::string &non_primary_global_image_id, |
f67539c2 TL |
84 | bool image_clean, asio::ContextWQ *op_work_queue, |
85 | Context *on_finish); | |
7c673cae FG |
86 | |
87 | librados::IoCtx &m_io_ctx; | |
88 | std::string m_image_id; | |
9f95a23c TL |
89 | ImageCtxT* m_image_ctx; |
90 | cls::rbd::MirrorImageMode m_mode; | |
7c673cae | 91 | std::string m_non_primary_global_image_id; |
1911f103 | 92 | bool m_image_clean; |
f67539c2 | 93 | asio::ContextWQ *m_op_work_queue; |
7c673cae FG |
94 | Context *m_on_finish; |
95 | ||
96 | CephContext *m_cct = nullptr; | |
7c673cae FG |
97 | bufferlist m_out_bl; |
98 | cls::rbd::MirrorImage m_mirror_image; | |
99 | ||
1911f103 TL |
100 | int m_ret_val = 0; |
101 | bool m_close_image = false; | |
102 | ||
9f95a23c TL |
103 | bool m_is_primary = false; |
104 | uint64_t m_snap_id = CEPH_NOSNAP; | |
105 | ||
106 | void get_mirror_image(); | |
107 | void handle_get_mirror_image(int r); | |
108 | ||
109 | void get_tag_owner(); | |
110 | void handle_get_tag_owner(int r); | |
111 | ||
1911f103 TL |
112 | void open_image(); |
113 | void handle_open_image(int r); | |
114 | ||
9f95a23c TL |
115 | void create_primary_snapshot(); |
116 | void handle_create_primary_snapshot(int r); | |
7c673cae | 117 | |
1911f103 TL |
118 | void close_image(); |
119 | void handle_close_image(int r); | |
120 | ||
9f95a23c TL |
121 | void enable_non_primary_feature(); |
122 | void handle_enable_non_primary_feature(int r); | |
11fdf7f2 | 123 | |
9f95a23c TL |
124 | void image_state_update(); |
125 | void handle_image_state_update(int r); | |
7c673cae | 126 | |
9f95a23c | 127 | void finish(int r); |
7c673cae FG |
128 | }; |
129 | ||
130 | } // namespace mirror | |
131 | } // namespace librbd | |
132 | ||
133 | extern template class librbd::mirror::EnableRequest<librbd::ImageCtx>; | |
134 | ||
135 | #endif // CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H |