summaryrefslogtreecommitdiffstats
path: root/src/librbd/watcher/Types.h
blob: d1517fb0f5d887c72b551ee5d8d90c0819b51009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_WATCHER_TYPES_H
#define CEPH_LIBRBD_WATCHER_TYPES_H

#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/encoding.h"

namespace ceph { class Formatter; }

namespace librbd {

class Watcher;

namespace watcher {

struct ClientId {
  uint64_t gid;
  uint64_t handle;

  ClientId() : gid(0), handle(0) {}
  ClientId(uint64_t gid, uint64_t handle) : gid(gid), handle(handle) {}

  void encode(bufferlist& bl) const;
  void decode(bufferlist::const_iterator& it);
  void dump(Formatter *f) const;

  inline bool is_valid() const {
    return (*this != ClientId());
  }

  inline bool operator==(const ClientId &rhs) const {
    return (gid == rhs.gid && handle == rhs.handle);
  }
  inline bool operator!=(const ClientId &rhs) const {
    return !(*this == rhs);
  }
  inline bool operator<(const ClientId &rhs) const {
    if (gid != rhs.gid) {
      return gid < rhs.gid;
    } else {
      return handle < rhs.handle;
    }
  }
};

struct NotifyResponse {
  std::map<ClientId, bufferlist> acks;
  std::vector<ClientId> timeouts;

  void encode(bufferlist& bl) const;
  void decode(bufferlist::const_iterator& it);
};

template <typename ImageCtxT>
struct Traits {
  typedef librbd::Watcher Watcher;
};

std::ostream &operator<<(std::ostream &out,
                         const ClientId &client);

WRITE_CLASS_ENCODER(ClientId);
WRITE_CLASS_ENCODER(NotifyResponse);

} // namespace watcher
} // namespace librbd

#endif // CEPH_LIBRBD_WATCHER_TYPES_H