]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/ImageSyncThrottler.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / tools / rbd_mirror / ImageSyncThrottler.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 RBD_MIRROR_IMAGE_SYNC_THROTTLER_H
5 #define RBD_MIRROR_IMAGE_SYNC_THROTTLER_H
6
7 #include <list>
8 #include <set>
9 #include <sstream>
10 #include <string>
11 #include <utility>
12
13 #include "common/Mutex.h"
14 #include "common/config_obs.h"
15
16 class CephContext;
17 class Context;
18
19 namespace ceph { class Formatter; }
20 namespace librbd { class ImageCtx; }
21
22 namespace rbd {
23 namespace mirror {
24
25 template <typename ImageCtxT = librbd::ImageCtx>
26 class ImageSyncThrottler : public md_config_obs_t {
27 public:
28 static ImageSyncThrottler *create(CephContext *cct) {
29 return new ImageSyncThrottler(cct);
30 }
31 void destroy() {
32 delete this;
33 }
34
35 ImageSyncThrottler(CephContext *cct);
36 ~ImageSyncThrottler() override;
37
38 void set_max_concurrent_syncs(uint32_t max);
39 void start_op(const std::string &id, Context *on_start);
40 bool cancel_op(const std::string &id);
41 void finish_op(const std::string &id);
42 void drain(int r);
43
44 void print_status(Formatter *f, std::stringstream *ss);
45
46 private:
47 CephContext *m_cct;
48 Mutex m_lock;
49 uint32_t m_max_concurrent_syncs;
50 std::list<std::pair<std::string, Context *>> m_queue;
51 std::set<std::string> m_inflight_ops;
52
53 const char **get_tracked_conf_keys() const override;
54 void handle_conf_change(const ConfigProxy& conf,
55 const std::set<std::string> &changed) override;
56 };
57
58 } // namespace mirror
59 } // namespace rbd
60
61 extern template class rbd::mirror::ImageSyncThrottler<librbd::ImageCtx>;
62
63 #endif // RBD_MIRROR_IMAGE_SYNC_THROTTLER_H