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
6 #include "include/int_types.h"
7 #include "include/Context.h"
9 #include <boost/function.hpp>
13 template <typename ImageCtxT
> class AsyncRequest
;
14 class ProgressContext
;
17 class AsyncObjectThrottleFinisher
{
19 virtual ~AsyncObjectThrottleFinisher() {};
20 virtual void finish_op(int r
) = 0;
23 template <typename ImageCtxT
= ImageCtx
>
24 class C_AsyncObjectThrottle
: public Context
{
26 C_AsyncObjectThrottle(AsyncObjectThrottleFinisher
&finisher
,
28 : m_image_ctx(image_ctx
), m_finisher(finisher
) {
31 virtual int send() = 0;
34 ImageCtxT
&m_image_ctx
;
36 void finish(int r
) override
{
37 m_finisher
.finish_op(r
);
41 AsyncObjectThrottleFinisher
&m_finisher
;
44 template <typename ImageCtxT
= ImageCtx
>
45 class AsyncObjectThrottle
: public AsyncObjectThrottleFinisher
{
47 typedef boost::function
<
48 C_AsyncObjectThrottle
<ImageCtxT
>* (AsyncObjectThrottle
&,
49 uint64_t)> ContextFactory
;
51 AsyncObjectThrottle(const AsyncRequest
<ImageCtxT
> *async_request
,
53 const ContextFactory
& context_factory
, Context
*ctx
,
54 ProgressContext
*prog_ctx
, uint64_t object_no
,
55 uint64_t end_object_no
);
57 void start_ops(uint64_t max_concurrent
);
58 void finish_op(int r
) override
;
62 const AsyncRequest
<ImageCtxT
> *m_async_request
;
63 ImageCtxT
&m_image_ctx
;
64 ContextFactory m_context_factory
;
66 ProgressContext
*m_prog_ctx
;
68 uint64_t m_end_object_no
;
69 uint64_t m_current_ops
;
77 extern template class librbd::AsyncObjectThrottle
<librbd::ImageCtx
>;
79 #endif // CEPH_LIBRBD_ASYNC_OBJECT_THROTTLE_H