]>
Commit | Line | Data |
---|---|---|
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_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 | ||
d2e6a577 | 13 | #include "include/rados/librados.hpp" |
7c673cae | 14 | #include "include/rbd/librbd.hpp" |
7c673cae FG |
15 | |
16 | namespace rbd { | |
17 | namespace mirror { | |
18 | ||
9f95a23c TL |
19 | template <typename> struct MirrorStatusUpdater; |
20 | ||
11fdf7f2 TL |
21 | // Performance counters |
22 | enum { | |
23 | l_rbd_mirror_first = 27000, | |
24 | l_rbd_mirror_replay, | |
25 | l_rbd_mirror_replay_bytes, | |
26 | l_rbd_mirror_replay_latency, | |
27 | l_rbd_mirror_last, | |
28 | }; | |
29 | ||
30 | typedef std::shared_ptr<librados::Rados> RadosRef; | |
31 | typedef std::shared_ptr<librados::IoCtx> IoCtxRef; | |
32 | typedef std::shared_ptr<librbd::Image> ImageRef; | |
7c673cae | 33 | |
7c673cae FG |
34 | struct ImageId { |
35 | std::string global_id; | |
36 | std::string id; | |
37 | ||
38 | explicit ImageId(const std::string &global_id) : global_id(global_id) { | |
39 | } | |
40 | ImageId(const std::string &global_id, const std::string &id) | |
41 | : global_id(global_id), id(id) { | |
42 | } | |
43 | ||
44 | inline bool operator==(const ImageId &rhs) const { | |
45 | return (global_id == rhs.global_id && id == rhs.id); | |
46 | } | |
47 | inline bool operator<(const ImageId &rhs) const { | |
48 | return global_id < rhs.global_id; | |
49 | } | |
50 | }; | |
51 | ||
52 | std::ostream &operator<<(std::ostream &, const ImageId &image_id); | |
53 | ||
54 | typedef std::set<ImageId> ImageIds; | |
55 | ||
9f95a23c TL |
56 | struct LocalPoolMeta { |
57 | LocalPoolMeta() {} | |
58 | LocalPoolMeta(const std::string& mirror_uuid) | |
59 | : mirror_uuid(mirror_uuid) { | |
60 | } | |
61 | ||
62 | std::string mirror_uuid; | |
63 | }; | |
64 | ||
65 | std::ostream& operator<<(std::ostream& lhs, | |
66 | const LocalPoolMeta& local_pool_meta); | |
67 | ||
68 | struct RemotePoolMeta { | |
69 | RemotePoolMeta() {} | |
70 | RemotePoolMeta(const std::string& mirror_uuid, | |
71 | const std::string& mirror_peer_uuid) | |
72 | : mirror_uuid(mirror_uuid), | |
73 | mirror_peer_uuid(mirror_peer_uuid) { | |
74 | } | |
75 | ||
76 | std::string mirror_uuid; | |
77 | std::string mirror_peer_uuid; | |
78 | }; | |
79 | ||
80 | std::ostream& operator<<(std::ostream& lhs, | |
81 | const RemotePoolMeta& remote_pool_meta); | |
82 | ||
83 | template <typename I> | |
d2e6a577 | 84 | struct Peer { |
9f95a23c TL |
85 | std::string uuid; |
86 | mutable librados::IoCtx io_ctx; | |
87 | RemotePoolMeta remote_pool_meta; | |
88 | MirrorStatusUpdater<I>* mirror_status_updater = nullptr; | |
d2e6a577 FG |
89 | |
90 | Peer() { | |
91 | } | |
9f95a23c TL |
92 | Peer(const std::string& uuid, |
93 | librados::IoCtx& io_ctx, | |
94 | const RemotePoolMeta& remote_pool_meta, | |
95 | MirrorStatusUpdater<I>* mirror_status_updater) | |
96 | : io_ctx(io_ctx), | |
97 | remote_pool_meta(remote_pool_meta), | |
98 | mirror_status_updater(mirror_status_updater) { | |
d2e6a577 FG |
99 | } |
100 | ||
101 | inline bool operator<(const Peer &rhs) const { | |
9f95a23c | 102 | return uuid < rhs.uuid; |
d2e6a577 FG |
103 | } |
104 | }; | |
105 | ||
9f95a23c TL |
106 | template <typename I> |
107 | std::ostream& operator<<(std::ostream& lhs, const Peer<I>& peer) { | |
108 | return lhs << peer.remote_pool_meta; | |
109 | } | |
d2e6a577 | 110 | |
11fdf7f2 TL |
111 | struct PeerSpec { |
112 | PeerSpec() = default; | |
113 | PeerSpec(const std::string &uuid, const std::string &cluster_name, | |
114 | const std::string &client_name) | |
7c673cae FG |
115 | : uuid(uuid), cluster_name(cluster_name), client_name(client_name) |
116 | { | |
117 | } | |
9f95a23c | 118 | PeerSpec(const librbd::mirror_peer_site_t &peer) : |
7c673cae | 119 | uuid(peer.uuid), |
9f95a23c | 120 | cluster_name(peer.site_name), |
7c673cae FG |
121 | client_name(peer.client_name) |
122 | { | |
123 | } | |
11fdf7f2 | 124 | |
7c673cae FG |
125 | std::string uuid; |
126 | std::string cluster_name; | |
127 | std::string client_name; | |
11fdf7f2 TL |
128 | |
129 | /// optional config properties | |
130 | std::string mon_host; | |
131 | std::string key; | |
132 | ||
133 | bool operator==(const PeerSpec& rhs) const { | |
134 | return (uuid == rhs.uuid && | |
135 | cluster_name == rhs.cluster_name && | |
136 | client_name == rhs.client_name && | |
137 | mon_host == rhs.mon_host && | |
138 | key == rhs.key); | |
7c673cae | 139 | } |
11fdf7f2 TL |
140 | bool operator<(const PeerSpec& rhs) const { |
141 | if (uuid != rhs.uuid) { | |
142 | return uuid < rhs.uuid; | |
143 | } else if (cluster_name != rhs.cluster_name) { | |
144 | return cluster_name < rhs.cluster_name; | |
145 | } else if (client_name != rhs.client_name) { | |
146 | return client_name < rhs.client_name; | |
147 | } else if (mon_host < rhs.mon_host) { | |
148 | return mon_host < rhs.mon_host; | |
149 | } else { | |
150 | return key < rhs.key; | |
151 | } | |
7c673cae FG |
152 | } |
153 | }; | |
154 | ||
11fdf7f2 | 155 | std::ostream& operator<<(std::ostream& lhs, const PeerSpec &peer); |
7c673cae FG |
156 | |
157 | } // namespace mirror | |
158 | } // namespace rbd | |
159 | ||
160 | ||
161 | #endif // CEPH_RBD_MIRROR_TYPES_H |