]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/AsyncObjectThrottle.h
update sources to 12.2.7
[ceph.git] / ceph / src / librbd / AsyncObjectThrottle.h
CommitLineData
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
11namespace librbd
12{
13template <typename ImageCtxT> class AsyncRequest;
14class ProgressContext;
15struct ImageCtx;
16
17class AsyncObjectThrottleFinisher {
18public:
19 virtual ~AsyncObjectThrottleFinisher() {};
20 virtual void finish_op(int r) = 0;
21};
22
23template <typename ImageCtxT = ImageCtx>
24class C_AsyncObjectThrottle : public Context {
25public:
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
33protected:
34 ImageCtxT &m_image_ctx;
35
36 void finish(int r) override {
37 m_finisher.finish_op(r);
38 }
39
40private:
41 AsyncObjectThrottleFinisher &m_finisher;
42};
43
44template <typename ImageCtxT = ImageCtx>
45class AsyncObjectThrottle : public AsyncObjectThrottleFinisher {
46public:
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
60private:
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
77extern template class librbd::AsyncObjectThrottle<librbd::ImageCtx>;
78
79#endif // CEPH_LIBRBD_ASYNC_OBJECT_THROTTLE_H