Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / watcher / 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_LIBRBD_WATCHER_TYPES_H
5 #define CEPH_LIBRBD_WATCHER_TYPES_H
6
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
10
11 namespace ceph { class Formatter; }
12
13 namespace librbd {
14
15 class Watcher;
16
17 namespace watcher {
18
19 struct ClientId {
20   uint64_t gid;
21   uint64_t handle;
22
23   ClientId() : gid(0), handle(0) {}
24   ClientId(uint64_t gid, uint64_t handle) : gid(gid), handle(handle) {}
25
26   void encode(bufferlist& bl) const;
27   void decode(bufferlist::iterator& it);
28   void dump(Formatter *f) const;
29
30   inline bool is_valid() const {
31     return (*this != ClientId());
32   }
33
34   inline bool operator==(const ClientId &rhs) const {
35     return (gid == rhs.gid && handle == rhs.handle);
36   }
37   inline bool operator!=(const ClientId &rhs) const {
38     return !(*this == rhs);
39   }
40   inline bool operator<(const ClientId &rhs) const {
41     if (gid != rhs.gid) {
42       return gid < rhs.gid;
43     } else {
44       return handle < rhs.handle;
45     }
46   }
47 };
48
49 struct NotifyResponse {
50   std::map<ClientId, bufferlist> acks;
51   std::vector<ClientId> timeouts;
52
53   void encode(bufferlist& bl) const;
54   void decode(bufferlist::iterator& it);
55 };
56
57 template <typename ImageCtxT>
58 struct Traits {
59   typedef librbd::Watcher Watcher;
60 };
61
62 } // namespace watcher
63 } // namespace librbd
64
65 std::ostream &operator<<(std::ostream &out,
66                          const librbd::watcher::ClientId &client);
67
68 WRITE_CLASS_ENCODER(librbd::watcher::ClientId);
69 WRITE_CLASS_ENCODER(librbd::watcher::NotifyResponse);
70
71 #endif // CEPH_LIBRBD_WATCHER_TYPES_H