]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/snapshot/CreatePrimaryRequest.h
69c0ed4470198423a80bad74b558599d657f4a14
[ceph.git] / ceph / src / librbd / mirror / snapshot / CreatePrimaryRequest.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_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
5 #define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
6
7 #include "include/buffer.h"
8 #include "include/rados/librados.hpp"
9 #include "cls/rbd/cls_rbd_types.h"
10 #include "librbd/mirror/snapshot/Types.h"
11
12 #include <string>
13 #include <set>
14
15 struct Context;
16
17 namespace librbd {
18
19 struct ImageCtx;
20
21 namespace mirror {
22 namespace snapshot {
23
24 template <typename ImageCtxT = librbd::ImageCtx>
25 class CreatePrimaryRequest {
26 public:
27 static CreatePrimaryRequest *create(ImageCtxT *image_ctx,
28 const std::string& global_image_id,
29 uint32_t flags, uint64_t *snap_id,
30 Context *on_finish) {
31 return new CreatePrimaryRequest(image_ctx, global_image_id, flags, snap_id,
32 on_finish);
33 }
34
35 CreatePrimaryRequest(ImageCtxT *image_ctx,
36 const std::string& global_image_id,
37 uint32_t flags, uint64_t *snap_id, Context *on_finish);
38
39 void send();
40
41 private:
42 /**
43 * @verbatim
44 *
45 * <start>
46 * |
47 * v
48 * GET_MIRROR_PEERS
49 * |
50 * v
51 * CREATE_SNAPSHOT
52 * |
53 * v
54 * REFRESH_IMAGE
55 * |
56 * v
57 * UNLINK_PEER (skip if not needed,
58 * | repeat if needed)
59 * v
60 * <finish>
61 *
62 * @endverbatim
63 */
64
65 ImageCtxT *m_image_ctx;
66 std::string m_global_image_id;
67 const uint32_t m_flags;
68 uint64_t *m_snap_id;
69 Context *m_on_finish;
70
71 librados::IoCtx m_default_ns_ctx;
72 std::set<std::string> m_mirror_peer_uuids;
73 std::string m_snap_name;
74
75 bufferlist m_out_bl;
76
77 void get_mirror_peers();
78 void handle_get_mirror_peers(int r);
79
80 void create_snapshot();
81 void handle_create_snapshot(int r);
82
83 void refresh_image();
84 void handle_refresh_image(int r);
85
86 void unlink_peer();
87 void handle_unlink_peer(int r);
88
89 void finish(int r);
90 };
91
92 } // namespace snapshot
93 } // namespace mirror
94 } // namespace librbd
95
96 extern template class librbd::mirror::snapshot::CreatePrimaryRequest<librbd::ImageCtx>;
97
98 #endif // CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H