Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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 Context;
17
18 namespace ceph { class Formatter; }
19 namespace librbd { class ImageCtx; }
20
21 namespace rbd {
22 namespace mirror {
23
24 template <typename ImageCtxT = librbd::ImageCtx>
25 class ImageSyncThrottler : public md_config_obs_t {
26 public:
27   static ImageSyncThrottler *create() {
28     return new ImageSyncThrottler();
29   }
30   void destroy() {
31     delete this;
32   }
33
34   ImageSyncThrottler();
35   ~ImageSyncThrottler() override;
36
37   void set_max_concurrent_syncs(uint32_t max);
38   void start_op(const std::string &id, Context *on_start);
39   bool cancel_op(const std::string &id);
40   void finish_op(const std::string &id);
41   void drain(int r);
42
43   void print_status(Formatter *f, std::stringstream *ss);
44
45 private:
46   Mutex m_lock;
47   uint32_t m_max_concurrent_syncs;
48   std::list<std::pair<std::string, Context *>> m_queue;
49   std::set<std::string> m_inflight_ops;
50
51   const char **get_tracked_conf_keys() const override;
52   void handle_conf_change(const struct md_config_t *conf,
53                           const std::set<std::string> &changed) override;
54 };
55
56 } // namespace mirror
57 } // namespace rbd
58
59 extern template class rbd::mirror::ImageSyncThrottler<librbd::ImageCtx>;
60
61 #endif // RBD_MIRROR_IMAGE_SYNC_THROTTLER_H