]>
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 | #include "librbd/AsyncRequest.h" | |
4 | #include "librbd/ImageCtx.h" | |
5 | #include "librbd/Utils.h" | |
f67539c2 | 6 | #include "librbd/asio/ContextWQ.h" |
7c673cae FG |
7 | |
8 | namespace librbd | |
9 | { | |
10 | ||
11 | template <typename T> | |
12 | AsyncRequest<T>::AsyncRequest(T &image_ctx, Context *on_finish) | |
13 | : m_image_ctx(image_ctx), m_on_finish(on_finish), m_canceled(false), | |
14 | m_xlist_item(this) { | |
11fdf7f2 | 15 | ceph_assert(m_on_finish != NULL); |
7c673cae FG |
16 | start_request(); |
17 | } | |
18 | ||
19 | template <typename T> | |
20 | AsyncRequest<T>::~AsyncRequest() { | |
21 | } | |
22 | ||
23 | template <typename T> | |
24 | void AsyncRequest<T>::async_complete(int r) { | |
25 | m_image_ctx.op_work_queue->queue(create_callback_context(), r); | |
26 | } | |
27 | ||
28 | template <typename T> | |
29 | librados::AioCompletion *AsyncRequest<T>::create_callback_completion() { | |
30 | return util::create_rados_callback(this); | |
31 | } | |
32 | ||
33 | template <typename T> | |
34 | Context *AsyncRequest<T>::create_callback_context() { | |
35 | return util::create_context_callback(this); | |
36 | } | |
37 | ||
38 | template <typename T> | |
39 | Context *AsyncRequest<T>::create_async_callback_context() { | |
40 | return util::create_context_callback<AsyncRequest<T>, | |
41 | &AsyncRequest<T>::async_complete>(this); | |
42 | } | |
43 | ||
44 | template <typename T> | |
45 | void AsyncRequest<T>::start_request() { | |
9f95a23c | 46 | std::lock_guard async_ops_locker{m_image_ctx.async_ops_lock}; |
7c673cae FG |
47 | m_image_ctx.async_requests.push_back(&m_xlist_item); |
48 | } | |
49 | ||
50 | template <typename T> | |
51 | void AsyncRequest<T>::finish_request() { | |
52 | decltype(m_image_ctx.async_requests_waiters) waiters; | |
53 | { | |
9f95a23c | 54 | std::lock_guard async_ops_locker{m_image_ctx.async_ops_lock}; |
11fdf7f2 | 55 | ceph_assert(m_xlist_item.remove_myself()); |
7c673cae FG |
56 | |
57 | if (m_image_ctx.async_requests.empty()) { | |
58 | waiters = std::move(m_image_ctx.async_requests_waiters); | |
59 | } | |
60 | } | |
61 | ||
62 | for (auto ctx : waiters) { | |
63 | ctx->complete(0); | |
64 | } | |
65 | } | |
66 | ||
67 | } // namespace librbd | |
68 | ||
69 | #ifndef TEST_F | |
70 | template class librbd::AsyncRequest<librbd::ImageCtx>; | |
71 | #endif |