]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/Types.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / tools / rbd_mirror / Types.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_RBD_MIRROR_TYPES_H
5 #define CEPH_RBD_MIRROR_TYPES_H
6
7 #include <iostream>
8 #include <memory>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "include/rados/librados.hpp"
14 #include "include/rbd/librbd.hpp"
15
16 namespace rbd {
17 namespace mirror {
18
19 // Performance counters
20 enum {
21 l_rbd_mirror_first = 27000,
22 l_rbd_mirror_replay,
23 l_rbd_mirror_replay_bytes,
24 l_rbd_mirror_replay_latency,
25 l_rbd_mirror_last,
26 };
27
28 typedef std::shared_ptr<librados::Rados> RadosRef;
29 typedef std::shared_ptr<librados::IoCtx> IoCtxRef;
30 typedef std::shared_ptr<librbd::Image> ImageRef;
31
32 struct ImageId {
33 std::string global_id;
34 std::string id;
35
36 explicit ImageId(const std::string &global_id) : global_id(global_id) {
37 }
38 ImageId(const std::string &global_id, const std::string &id)
39 : global_id(global_id), id(id) {
40 }
41
42 inline bool operator==(const ImageId &rhs) const {
43 return (global_id == rhs.global_id && id == rhs.id);
44 }
45 inline bool operator<(const ImageId &rhs) const {
46 return global_id < rhs.global_id;
47 }
48 };
49
50 std::ostream &operator<<(std::ostream &, const ImageId &image_id);
51
52 typedef std::set<ImageId> ImageIds;
53
54 struct Peer {
55 std::string peer_uuid;
56 librados::IoCtx io_ctx;
57
58 Peer() {
59 }
60 Peer(const std::string &peer_uuid) : peer_uuid(peer_uuid) {
61 }
62 Peer(const std::string &peer_uuid, librados::IoCtx& io_ctx)
63 : peer_uuid(peer_uuid), io_ctx(io_ctx) {
64 }
65
66 inline bool operator<(const Peer &rhs) const {
67 return peer_uuid < rhs.peer_uuid;
68 }
69 };
70
71 typedef std::set<Peer> Peers;
72
73 struct PeerSpec {
74 PeerSpec() = default;
75 PeerSpec(const std::string &uuid, const std::string &cluster_name,
76 const std::string &client_name)
77 : uuid(uuid), cluster_name(cluster_name), client_name(client_name)
78 {
79 }
80 PeerSpec(const librbd::mirror_peer_t &peer) :
81 uuid(peer.uuid),
82 cluster_name(peer.cluster_name),
83 client_name(peer.client_name)
84 {
85 }
86
87 std::string uuid;
88 std::string cluster_name;
89 std::string client_name;
90
91 /// optional config properties
92 std::string mon_host;
93 std::string key;
94
95 bool operator==(const PeerSpec& rhs) const {
96 return (uuid == rhs.uuid &&
97 cluster_name == rhs.cluster_name &&
98 client_name == rhs.client_name &&
99 mon_host == rhs.mon_host &&
100 key == rhs.key);
101 }
102 bool operator<(const PeerSpec& rhs) const {
103 if (uuid != rhs.uuid) {
104 return uuid < rhs.uuid;
105 } else if (cluster_name != rhs.cluster_name) {
106 return cluster_name < rhs.cluster_name;
107 } else if (client_name != rhs.client_name) {
108 return client_name < rhs.client_name;
109 } else if (mon_host < rhs.mon_host) {
110 return mon_host < rhs.mon_host;
111 } else {
112 return key < rhs.key;
113 }
114 }
115 };
116
117 std::ostream& operator<<(std::ostream& lhs, const PeerSpec &peer);
118
119 } // namespace mirror
120 } // namespace rbd
121
122
123 #endif // CEPH_RBD_MIRROR_TYPES_H