]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
7c673cae | 3 | |
31f18b77 FG |
4 | #ifndef RBD_MIRROR_IMAGE_SYNC_THROTTLER_H |
5 | #define RBD_MIRROR_IMAGE_SYNC_THROTTLER_H | |
7c673cae FG |
6 | |
7 | #include <list> | |
494da23a | 8 | #include <map> |
31f18b77 FG |
9 | #include <set> |
10 | #include <sstream> | |
11 | #include <string> | |
7c673cae | 12 | #include <utility> |
31f18b77 | 13 | |
7c673cae | 14 | #include "common/Mutex.h" |
31f18b77 | 15 | #include "common/config_obs.h" |
7c673cae | 16 | |
11fdf7f2 | 17 | class CephContext; |
7c673cae | 18 | class Context; |
31f18b77 FG |
19 | |
20 | namespace ceph { class Formatter; } | |
21 | namespace librbd { class ImageCtx; } | |
7c673cae FG |
22 | |
23 | namespace rbd { | |
24 | namespace mirror { | |
25 | ||
7c673cae FG |
26 | template <typename ImageCtxT = librbd::ImageCtx> |
27 | class ImageSyncThrottler : public md_config_obs_t { | |
28 | public: | |
11fdf7f2 TL |
29 | static ImageSyncThrottler *create(CephContext *cct) { |
30 | return new ImageSyncThrottler(cct); | |
31f18b77 FG |
31 | } |
32 | void destroy() { | |
33 | delete this; | |
34 | } | |
7c673cae | 35 | |
11fdf7f2 | 36 | ImageSyncThrottler(CephContext *cct); |
7c673cae | 37 | ~ImageSyncThrottler() override; |
7c673cae FG |
38 | |
39 | void set_max_concurrent_syncs(uint32_t max); | |
31f18b77 FG |
40 | void start_op(const std::string &id, Context *on_start); |
41 | bool cancel_op(const std::string &id); | |
42 | void finish_op(const std::string &id); | |
43 | void drain(int r); | |
7c673cae FG |
44 | |
45 | void print_status(Formatter *f, std::stringstream *ss); | |
46 | ||
47 | private: | |
11fdf7f2 | 48 | CephContext *m_cct; |
31f18b77 FG |
49 | Mutex m_lock; |
50 | uint32_t m_max_concurrent_syncs; | |
494da23a TL |
51 | std::list<std::string> m_queue; |
52 | std::map<std::string, Context *> m_queued_ops; | |
31f18b77 | 53 | std::set<std::string> m_inflight_ops; |
7c673cae FG |
54 | |
55 | const char **get_tracked_conf_keys() const override; | |
11fdf7f2 | 56 | void handle_conf_change(const ConfigProxy& conf, |
7c673cae | 57 | const std::set<std::string> &changed) override; |
7c673cae FG |
58 | }; |
59 | ||
60 | } // namespace mirror | |
61 | } // namespace rbd | |
62 | ||
31f18b77 FG |
63 | extern template class rbd::mirror::ImageSyncThrottler<librbd::ImageCtx>; |
64 | ||
65 | #endif // RBD_MIRROR_IMAGE_SYNC_THROTTLER_H |