]>
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 | |
3 | #ifndef CEPH_LIBRBD_ASYNC_OBJECT_THROTTLE_H | |
4 | #define CEPH_LIBRBD_ASYNC_OBJECT_THROTTLE_H | |
5 | ||
6 | #include "include/int_types.h" | |
7 | #include "include/Context.h" | |
8 | ||
9 | #include <boost/function.hpp> | |
10 | ||
11 | namespace librbd | |
12 | { | |
13 | template <typename ImageCtxT> class AsyncRequest; | |
14 | class ProgressContext; | |
15 | struct ImageCtx; | |
16 | ||
17 | class AsyncObjectThrottleFinisher { | |
18 | public: | |
19 | virtual ~AsyncObjectThrottleFinisher() {}; | |
20 | virtual void finish_op(int r) = 0; | |
21 | }; | |
22 | ||
23 | template <typename ImageCtxT = ImageCtx> | |
24 | class C_AsyncObjectThrottle : public Context { | |
25 | public: | |
26 | C_AsyncObjectThrottle(AsyncObjectThrottleFinisher &finisher, | |
27 | ImageCtxT &image_ctx) | |
28 | : m_image_ctx(image_ctx), m_finisher(finisher) { | |
29 | } | |
30 | ||
31 | virtual int send() = 0; | |
32 | ||
33 | protected: | |
34 | ImageCtxT &m_image_ctx; | |
35 | ||
36 | void finish(int r) override { | |
37 | m_finisher.finish_op(r); | |
38 | } | |
39 | ||
40 | private: | |
41 | AsyncObjectThrottleFinisher &m_finisher; | |
42 | }; | |
43 | ||
44 | template <typename ImageCtxT = ImageCtx> | |
45 | class AsyncObjectThrottle : public AsyncObjectThrottleFinisher { | |
46 | public: | |
47 | typedef boost::function< | |
48 | C_AsyncObjectThrottle<ImageCtxT>* (AsyncObjectThrottle&, | |
49 | uint64_t)> ContextFactory; | |
50 | ||
51 | AsyncObjectThrottle(const AsyncRequest<ImageCtxT> *async_request, | |
52 | ImageCtxT &image_ctx, | |
53 | const ContextFactory& context_factory, Context *ctx, | |
54 | ProgressContext *prog_ctx, uint64_t object_no, | |
55 | uint64_t end_object_no); | |
56 | ||
57 | void start_ops(uint64_t max_concurrent); | |
58 | void finish_op(int r) override; | |
59 | ||
60 | private: | |
61 | Mutex m_lock; | |
62 | const AsyncRequest<ImageCtxT> *m_async_request; | |
63 | ImageCtxT &m_image_ctx; | |
64 | ContextFactory m_context_factory; | |
65 | Context *m_ctx; | |
66 | ProgressContext *m_prog_ctx; | |
67 | uint64_t m_object_no; | |
68 | uint64_t m_end_object_no; | |
69 | uint64_t m_current_ops; | |
70 | int m_ret; | |
71 | ||
72 | void start_next_op(); | |
73 | }; | |
74 | ||
75 | } // namespace librbd | |
76 | ||
77 | extern template class librbd::AsyncObjectThrottle<librbd::ImageCtx>; | |
78 | ||
79 | #endif // CEPH_LIBRBD_ASYNC_OBJECT_THROTTLE_H |