summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_mirror/ServiceDaemon.h
blob: 8b1e0f584546f25aedc279c6c4802bec2fd40b5b (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_RBD_MIRROR_SERVICE_DAEMON_H
#define CEPH_RBD_MIRROR_SERVICE_DAEMON_H

#include "common/ceph_mutex.h"
#include "include/common_fwd.h"
#include "tools/rbd_mirror/Types.h"
#include "tools/rbd_mirror/service_daemon/Types.h"
#include <map>
#include <string>

struct Context;
namespace librbd { struct ImageCtx; }

namespace rbd {
namespace mirror {

template <typename> struct Threads;

template <typename ImageCtxT = librbd::ImageCtx>
class ServiceDaemon {
public:
  ServiceDaemon(CephContext *cct, RadosRef rados, Threads<ImageCtxT>* threads);
  ~ServiceDaemon();

  int init();

  void add_pool(int64_t pool_id, const std::string& pool_name);
  void remove_pool(int64_t pool_id);

  void add_namespace(int64_t pool_id, const std::string& namespace_name);
  void remove_namespace(int64_t pool_id, const std::string& namespace_name);

  uint64_t add_or_update_callout(int64_t pool_id, uint64_t callout_id,
                                 service_daemon::CalloutLevel callout_level,
                                 const std::string& text);
  void remove_callout(int64_t pool_id, uint64_t callout_id);

  void add_or_update_attribute(int64_t pool_id, const std::string& key,
                               const service_daemon::AttributeValue& value);
  void add_or_update_namespace_attribute(
      int64_t pool_id, const std::string& namespace_name,
      const std::string& key, const service_daemon::AttributeValue& value);
  void remove_attribute(int64_t pool_id, const std::string& key);

private:
  struct Callout {
    service_daemon::CalloutLevel level;
    std::string text;

    Callout() : level(service_daemon::CALLOUT_LEVEL_INFO) {
    }
    Callout(service_daemon::CalloutLevel level, const std::string& text)
      : level(level), text(text) {
    }
  };
  typedef std::map<uint64_t, Callout> Callouts;
  typedef std::map<std::string, service_daemon::AttributeValue> Attributes;
  typedef std::map<std::string, Attributes> NamespaceAttributes;

  struct Pool {
    std::string name;
    Callouts callouts;
    Attributes attributes;
    NamespaceAttributes ns_attributes;

    Pool(const std::string& name) : name(name) {
    }
  };

  typedef std::map<int64_t, Pool> Pools;

  CephContext *m_cct;
  RadosRef m_rados;
  Threads<ImageCtxT>* m_threads;

  ceph::mutex m_lock = ceph::make_mutex("rbd::mirror::ServiceDaemon");
  Pools m_pools;
  uint64_t m_callout_id = service_daemon::CALLOUT_ID_NONE;

  Context* m_timer_ctx = nullptr;

  void schedule_update_status();
  void update_status();
};

} // namespace mirror
} // namespace rbd

extern template class rbd::mirror::ServiceDaemon<librbd::ImageCtx>;

#endif // CEPH_RBD_MIRROR_SERVICE_DAEMON_H