Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 typedef shared_ptr<librados::Rados> RadosRef;
20 typedef shared_ptr<librados::IoCtx> IoCtxRef;
21 typedef shared_ptr<librbd::Image> ImageRef;
22
23 struct ImageId {
24   std::string global_id;
25   std::string id;
26
27   explicit ImageId(const std::string &global_id) : global_id(global_id) {
28   }
29   ImageId(const std::string &global_id, const std::string &id)
30     : global_id(global_id), id(id) {
31   }
32
33   inline bool operator==(const ImageId &rhs) const {
34     return (global_id == rhs.global_id && id == rhs.id);
35   }
36   inline bool operator<(const ImageId &rhs) const {
37     return global_id < rhs.global_id;
38   }
39 };
40
41 std::ostream &operator<<(std::ostream &, const ImageId &image_id);
42
43 typedef std::set<ImageId> ImageIds;
44
45 struct Peer {
46   std::string peer_uuid;
47   librados::IoCtx io_ctx;
48
49   Peer() {
50   }
51   Peer(const std::string &peer_uuid) : peer_uuid(peer_uuid) {
52   }
53   Peer(const std::string &peer_uuid, librados::IoCtx& io_ctx)
54     : peer_uuid(peer_uuid), io_ctx(io_ctx) {
55   }
56
57   inline bool operator<(const Peer &rhs) const {
58     return peer_uuid < rhs.peer_uuid;
59   }
60 };
61
62 typedef std::set<Peer> Peers;
63
64 struct peer_t {
65   peer_t() = default;
66   peer_t(const std::string &uuid, const std::string &cluster_name,
67          const std::string &client_name)
68     : uuid(uuid), cluster_name(cluster_name), client_name(client_name)
69   {
70   }
71   peer_t(const librbd::mirror_peer_t &peer) :
72     uuid(peer.uuid),
73     cluster_name(peer.cluster_name),
74     client_name(peer.client_name)
75   {
76   }
77   std::string uuid;
78   std::string cluster_name;
79   std::string client_name;
80   bool operator<(const peer_t &rhs) const {
81     return this->uuid < rhs.uuid;
82   }
83   bool operator()(const peer_t &lhs, const peer_t &rhs) const {
84     return lhs.uuid < rhs.uuid;
85   }
86   bool operator==(const peer_t &rhs) const {
87     return uuid == rhs.uuid;
88   }
89 };
90
91 std::ostream& operator<<(std::ostream& lhs, const peer_t &peer);
92
93 } // namespace mirror
94 } // namespace rbd
95
96
97 #endif // CEPH_RBD_MIRROR_TYPES_H