]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H | |
5 | #define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H | |
6 | ||
7 | #include "include/buffer.h" | |
8 | #include "cls/rbd/cls_rbd_types.h" | |
9 | #include "librbd/Types.h" | |
f67539c2 | 10 | #include "librbd/internal.h" |
9f95a23c TL |
11 | #include "librbd/mirror/snapshot/Types.h" |
12 | ||
13 | #include <string> | |
14 | #include <set> | |
15 | ||
16 | struct Context; | |
17 | ||
18 | namespace librbd { | |
19 | ||
20 | struct ImageCtx; | |
21 | ||
22 | namespace mirror { | |
23 | namespace snapshot { | |
24 | ||
25 | template <typename ImageCtxT = librbd::ImageCtx> | |
26 | class CreateNonPrimaryRequest { | |
27 | public: | |
28 | static CreateNonPrimaryRequest *create(ImageCtxT *image_ctx, | |
29 | bool demoted, | |
30 | const std::string &primary_mirror_uuid, | |
31 | uint64_t primary_snap_id, | |
32 | const SnapSeqs& snap_seqs, | |
33 | const ImageState &image_state, | |
34 | uint64_t *snap_id, | |
35 | Context *on_finish) { | |
36 | return new CreateNonPrimaryRequest(image_ctx, demoted, primary_mirror_uuid, | |
37 | primary_snap_id, snap_seqs, image_state, | |
38 | snap_id, on_finish); | |
39 | } | |
40 | ||
41 | CreateNonPrimaryRequest(ImageCtxT *image_ctx, | |
42 | bool demoted, | |
43 | const std::string &primary_mirror_uuid, | |
44 | uint64_t primary_snap_id, | |
45 | const SnapSeqs& snap_seqs, | |
46 | const ImageState &image_state, uint64_t *snap_id, | |
1911f103 | 47 | Context *on_finish); |
9f95a23c TL |
48 | |
49 | void send(); | |
50 | ||
51 | private: | |
52 | /** | |
53 | * @verbatim | |
54 | * | |
55 | * <start> | |
56 | * | | |
57 | * v | |
58 | * REFRESH_IMAGE | |
59 | * | | |
60 | * v | |
61 | * GET_MIRROR_IMAGE | |
62 | * | | |
1911f103 TL |
63 | * v (skip if not needed) |
64 | * GET_MIRROR_PEERS | |
65 | * | | |
9f95a23c TL |
66 | * v |
67 | * CREATE_SNAPSHOT | |
68 | * | | |
69 | * v | |
70 | * WRITE_IMAGE_STATE | |
71 | * | | |
72 | * v | |
73 | * <finish> | |
74 | * | |
75 | * @endverbatim | |
76 | */ | |
77 | ||
78 | ImageCtxT *m_image_ctx; | |
79 | bool m_demoted; | |
80 | std::string m_primary_mirror_uuid; | |
81 | uint64_t m_primary_snap_id; | |
82 | SnapSeqs m_snap_seqs; | |
83 | ImageState m_image_state; | |
84 | uint64_t *m_snap_id; | |
85 | Context *m_on_finish; | |
86 | ||
1911f103 TL |
87 | librados::IoCtx m_default_ns_ctx; |
88 | std::set<std::string> m_mirror_peer_uuids; | |
89 | ||
9f95a23c TL |
90 | std::string m_snap_name; |
91 | ||
92 | bufferlist m_out_bl; | |
f67539c2 | 93 | NoOpProgressContext m_prog_ctx; |
9f95a23c TL |
94 | |
95 | bool is_orphan() const { | |
96 | return m_primary_mirror_uuid.empty(); | |
97 | } | |
98 | ||
99 | void refresh_image(); | |
100 | void handle_refresh_image(int r); | |
101 | ||
102 | void get_mirror_image(); | |
103 | void handle_get_mirror_image(int r); | |
104 | ||
105 | void get_mirror_peers(); | |
106 | void handle_get_mirror_peers(int r); | |
107 | ||
108 | void create_snapshot(); | |
109 | void handle_create_snapshot(int r); | |
110 | ||
111 | void write_image_state(); | |
112 | void handle_write_image_state(int r); | |
113 | ||
114 | void finish(int r); | |
115 | }; | |
116 | ||
117 | } // namespace snapshot | |
118 | } // namespace mirror | |
119 | } // namespace librbd | |
120 | ||
121 | extern template class librbd::mirror::snapshot::CreateNonPrimaryRequest<librbd::ImageCtx>; | |
122 | ||
123 | #endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_NON_PRIMARY_REQUEST_H |