]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/AsyncObjectThrottle.cc
e0fcefff18a03f81be5000b421906bc130ac1838
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #include "librbd/AsyncObjectThrottle.h"
4 #include "librbd/AsyncRequest.h"
5 #include "librbd/ImageCtx.h"
6 #include "librbd/Utils.h"
7 #include "librbd/asio/ContextWQ.h"
13 AsyncObjectThrottle
<T
>::AsyncObjectThrottle(
14 const AsyncRequest
<T
>* async_request
, T
&image_ctx
,
15 const ContextFactory
& context_factory
, Context
*ctx
,
16 ProgressContext
*prog_ctx
, uint64_t object_no
, uint64_t end_object_no
)
17 : m_lock(ceph::make_mutex(
18 util::unique_lock_name("librbd::AsyncThrottle::m_lock", this))),
19 m_async_request(async_request
), m_image_ctx(image_ctx
),
20 m_context_factory(context_factory
), m_ctx(ctx
), m_prog_ctx(prog_ctx
),
21 m_object_no(object_no
), m_end_object_no(end_object_no
), m_current_ops(0),
27 void AsyncObjectThrottle
<T
>::start_ops(uint64_t max_concurrent
) {
28 ceph_assert(ceph_mutex_is_locked(m_image_ctx
.owner_lock
));
31 std::lock_guard l
{m_lock
};
32 for (uint64_t i
= 0; i
< max_concurrent
; ++i
) {
34 if (m_ret
< 0 && m_current_ops
== 0) {
38 complete
= (m_current_ops
== 0);
41 // avoid re-entrant callback
42 m_image_ctx
.op_work_queue
->queue(m_ctx
, m_ret
);
48 void AsyncObjectThrottle
<T
>::finish_op(int r
) {
51 std::shared_lock owner_locker
{m_image_ctx
.owner_lock
};
52 std::lock_guard locker
{m_lock
};
54 if (r
< 0 && r
!= -ENOENT
&& m_ret
== 0) {
59 complete
= (m_current_ops
== 0);
62 m_ctx
->complete(m_ret
);
68 void AsyncObjectThrottle
<T
>::start_next_op() {
71 if (m_async_request
!= NULL
&& m_async_request
->is_canceled() &&
73 // allow in-flight ops to complete, but don't start new ops
76 } else if (m_ret
!= 0 || m_object_no
>= m_end_object_no
) {
80 uint64_t ono
= m_object_no
++;
81 C_AsyncObjectThrottle
<T
> *ctx
= m_context_factory(*this, ono
);
89 // op completed immediately
95 if (m_prog_ctx
!= NULL
) {
96 r
= m_prog_ctx
->update_progress(ono
, m_end_object_no
);
104 } // namespace librbd
107 template class librbd::AsyncObjectThrottle
<librbd::ImageCtx
>;