]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/Types.h
update ceph source to reef 18.1.2
[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 template <typename> struct MirrorStatusUpdater;
20
21 // Performance counters
22 enum {
23 l_rbd_mirror_journal_first = 27000,
24 l_rbd_mirror_journal_entries,
25 l_rbd_mirror_journal_replay_bytes,
26 l_rbd_mirror_journal_replay_latency,
27 l_rbd_mirror_journal_last,
28 l_rbd_mirror_snapshot_first,
29 l_rbd_mirror_snapshot_snapshots,
30 l_rbd_mirror_snapshot_sync_time,
31 l_rbd_mirror_snapshot_sync_bytes,
32 // per-image only counters below
33 l_rbd_mirror_snapshot_remote_timestamp,
34 l_rbd_mirror_snapshot_local_timestamp,
35 l_rbd_mirror_snapshot_last_sync_time,
36 l_rbd_mirror_snapshot_last_sync_bytes,
37 l_rbd_mirror_snapshot_last,
38 };
39
40 typedef std::shared_ptr<librados::Rados> RadosRef;
41 typedef std::shared_ptr<librados::IoCtx> IoCtxRef;
42 typedef std::shared_ptr<librbd::Image> ImageRef;
43
44 struct ImageId {
45 std::string global_id;
46 std::string id;
47
48 explicit ImageId(const std::string &global_id) : global_id(global_id) {
49 }
50 ImageId(const std::string &global_id, const std::string &id)
51 : global_id(global_id), id(id) {
52 }
53
54 inline bool operator==(const ImageId &rhs) const {
55 return (global_id == rhs.global_id && id == rhs.id);
56 }
57 inline bool operator<(const ImageId &rhs) const {
58 return global_id < rhs.global_id;
59 }
60 };
61
62 std::ostream &operator<<(std::ostream &, const ImageId &image_id);
63
64 typedef std::set<ImageId> ImageIds;
65
66 struct LocalPoolMeta {
67 LocalPoolMeta() {}
68 LocalPoolMeta(const std::string& mirror_uuid)
69 : mirror_uuid(mirror_uuid) {
70 }
71
72 std::string mirror_uuid;
73 };
74
75 std::ostream& operator<<(std::ostream& lhs,
76 const LocalPoolMeta& local_pool_meta);
77
78 struct RemotePoolMeta {
79 RemotePoolMeta() {}
80 RemotePoolMeta(const std::string& mirror_uuid,
81 const std::string& mirror_peer_uuid)
82 : mirror_uuid(mirror_uuid),
83 mirror_peer_uuid(mirror_peer_uuid) {
84 }
85
86 std::string mirror_uuid;
87 std::string mirror_peer_uuid;
88 };
89
90 std::ostream& operator<<(std::ostream& lhs,
91 const RemotePoolMeta& remote_pool_meta);
92
93 template <typename I>
94 struct Peer {
95 std::string uuid;
96 mutable librados::IoCtx io_ctx;
97 RemotePoolMeta remote_pool_meta;
98 MirrorStatusUpdater<I>* mirror_status_updater = nullptr;
99
100 Peer() {
101 }
102 Peer(const std::string& uuid,
103 librados::IoCtx& io_ctx,
104 const RemotePoolMeta& remote_pool_meta,
105 MirrorStatusUpdater<I>* mirror_status_updater)
106 : io_ctx(io_ctx),
107 remote_pool_meta(remote_pool_meta),
108 mirror_status_updater(mirror_status_updater) {
109 }
110
111 inline bool operator<(const Peer &rhs) const {
112 return uuid < rhs.uuid;
113 }
114 };
115
116 template <typename I>
117 std::ostream& operator<<(std::ostream& lhs, const Peer<I>& peer) {
118 return lhs << peer.remote_pool_meta;
119 }
120
121 struct PeerSpec {
122 PeerSpec() = default;
123 PeerSpec(const std::string &uuid, const std::string &cluster_name,
124 const std::string &client_name)
125 : uuid(uuid), cluster_name(cluster_name), client_name(client_name)
126 {
127 }
128 PeerSpec(const librbd::mirror_peer_site_t &peer) :
129 uuid(peer.uuid),
130 cluster_name(peer.site_name),
131 client_name(peer.client_name)
132 {
133 }
134
135 std::string uuid;
136 std::string cluster_name;
137 std::string client_name;
138
139 /// optional config properties
140 std::string mon_host;
141 std::string key;
142
143 bool operator==(const PeerSpec& rhs) const {
144 return (uuid == rhs.uuid &&
145 cluster_name == rhs.cluster_name &&
146 client_name == rhs.client_name &&
147 mon_host == rhs.mon_host &&
148 key == rhs.key);
149 }
150 bool operator<(const PeerSpec& rhs) const {
151 if (uuid != rhs.uuid) {
152 return uuid < rhs.uuid;
153 } else if (cluster_name != rhs.cluster_name) {
154 return cluster_name < rhs.cluster_name;
155 } else if (client_name != rhs.client_name) {
156 return client_name < rhs.client_name;
157 } else if (mon_host < rhs.mon_host) {
158 return mon_host < rhs.mon_host;
159 } else {
160 return key < rhs.key;
161 }
162 }
163 };
164
165 std::ostream& operator<<(std::ostream& lhs, const PeerSpec &peer);
166
167 } // namespace mirror
168 } // namespace rbd
169
170
171 #endif // CEPH_RBD_MIRROR_TYPES_H