]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/AsyncObjectThrottle.cc
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 "common/RWLock.h"
5 #include "common/WorkQueue.h"
6 #include "librbd/AsyncRequest.h"
7 #include "librbd/ImageCtx.h"
8 #include "librbd/Utils.h"
14 AsyncObjectThrottle
<T
>::AsyncObjectThrottle(
15 const AsyncRequest
<T
>* async_request
, T
&image_ctx
,
16 const ContextFactory
& context_factory
, Context
*ctx
,
17 ProgressContext
*prog_ctx
, uint64_t object_no
, uint64_t end_object_no
)
18 : m_lock(ceph::make_mutex(
19 util::unique_lock_name("librbd::AsyncThrottle::m_lock", this))),
20 m_async_request(async_request
), m_image_ctx(image_ctx
),
21 m_context_factory(context_factory
), m_ctx(ctx
), m_prog_ctx(prog_ctx
),
22 m_object_no(object_no
), m_end_object_no(end_object_no
), m_current_ops(0),
28 void AsyncObjectThrottle
<T
>::start_ops(uint64_t max_concurrent
) {
29 ceph_assert(ceph_mutex_is_locked(m_image_ctx
.owner_lock
));
32 std::lock_guard l
{m_lock
};
33 for (uint64_t i
= 0; i
< max_concurrent
; ++i
) {
35 if (m_ret
< 0 && m_current_ops
== 0) {
39 complete
= (m_current_ops
== 0);
42 // avoid re-entrant callback
43 m_image_ctx
.op_work_queue
->queue(m_ctx
, m_ret
);
49 void AsyncObjectThrottle
<T
>::finish_op(int r
) {
52 std::shared_lock owner_locker
{m_image_ctx
.owner_lock
};
53 std::lock_guard locker
{m_lock
};
55 if (r
< 0 && r
!= -ENOENT
&& m_ret
== 0) {
60 complete
= (m_current_ops
== 0);
63 m_ctx
->complete(m_ret
);
69 void AsyncObjectThrottle
<T
>::start_next_op() {
72 if (m_async_request
!= NULL
&& m_async_request
->is_canceled() &&
74 // allow in-flight ops to complete, but don't start new ops
77 } else if (m_ret
!= 0 || m_object_no
>= m_end_object_no
) {
81 uint64_t ono
= m_object_no
++;
82 C_AsyncObjectThrottle
<T
> *ctx
= m_context_factory(*this, ono
);
90 // op completed immediately
96 if (m_prog_ctx
!= NULL
) {
97 r
= m_prog_ctx
->update_progress(ono
, m_end_object_no
);
105 } // namespace librbd
108 template class librbd::AsyncObjectThrottle
<librbd::ImageCtx
>;