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