]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/mirror/EnableRequest.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / mirror / EnableRequest.h
CommitLineData
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
16class Context;
17class ContextWQ;
18
7c673cae 19namespace librbd {
7c673cae
FG
20namespace mirror {
21
22template <typename ImageCtxT = ImageCtx>
23class EnableRequest {
24public:
9f95a23c
TL
25 static EnableRequest *create(ImageCtxT *image_ctx,
26 cls::rbd::MirrorImageMode mode,
27 Context *on_finish) {
28 return new EnableRequest(image_ctx->md_ctx, image_ctx->id, image_ctx, mode,
29 "", image_ctx->op_work_queue, on_finish);
7c673cae
FG
30 }
31 static EnableRequest *create(librados::IoCtx &io_ctx,
32 const std::string &image_id,
9f95a23c 33 cls::rbd::MirrorImageMode mode,
7c673cae
FG
34 const std::string &non_primary_global_image_id,
35 ContextWQ *op_work_queue, Context *on_finish) {
9f95a23c
TL
36 return new EnableRequest(io_ctx, image_id, nullptr, mode,
37 non_primary_global_image_id, op_work_queue,
38 on_finish);
7c673cae
FG
39 }
40
41 void send();
42
43private:
44 /**
45 * @verbatim
46 *
47 * <start>
48 * |
49 * v
11fdf7f2
TL
50 * GET_MIRROR_IMAGE * * * * * * *
51 * | * (on error)
9f95a23c 52 * v (skip if not needed) *
7c673cae
FG
53 * GET_TAG_OWNER * * * * * * * *
54 * | *
9f95a23c
TL
55 * v (skip if not needed) *
56 * CREATE_PRIMARY_SNAPSHOT * * *
57 * | *
58 * v (skip if not needed) *
59 * ENABLE_NON_PRIMARY_FEATURE *
7c673cae
FG
60 * | *
61 * v *
9f95a23c 62 * IMAGE_STATE_UPDATE * * * * * *
7c673cae
FG
63 * | *
64 * v *
65 * <finish> < * * * * * * * * *
66 *
67 * @endverbatim
68 */
69
70 EnableRequest(librados::IoCtx &io_ctx, const std::string &image_id,
9f95a23c 71 ImageCtxT* image_ctx, cls::rbd::MirrorImageMode mode,
7c673cae
FG
72 const std::string &non_primary_global_image_id,
73 ContextWQ *op_work_queue, Context *on_finish);
74
75 librados::IoCtx &m_io_ctx;
76 std::string m_image_id;
9f95a23c
TL
77 ImageCtxT* m_image_ctx;
78 cls::rbd::MirrorImageMode m_mode;
7c673cae
FG
79 std::string m_non_primary_global_image_id;
80 ContextWQ *m_op_work_queue;
81 Context *m_on_finish;
82
83 CephContext *m_cct = nullptr;
7c673cae
FG
84 bufferlist m_out_bl;
85 cls::rbd::MirrorImage m_mirror_image;
86
9f95a23c
TL
87 bool m_is_primary = false;
88 uint64_t m_snap_id = CEPH_NOSNAP;
89
90 void get_mirror_image();
91 void handle_get_mirror_image(int r);
92
93 void get_tag_owner();
94 void handle_get_tag_owner(int r);
95
96 void create_primary_snapshot();
97 void handle_create_primary_snapshot(int r);
7c673cae 98
9f95a23c
TL
99 void enable_non_primary_feature();
100 void handle_enable_non_primary_feature(int r);
11fdf7f2 101
9f95a23c
TL
102 void image_state_update();
103 void handle_image_state_update(int r);
7c673cae 104
9f95a23c 105 void finish(int r);
7c673cae
FG
106};
107
108} // namespace mirror
109} // namespace librbd
110
111extern template class librbd::mirror::EnableRequest<librbd::ImageCtx>;
112
113#endif // CEPH_LIBRBD_MIRROR_ENABLE_REQUEST_H