]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/io/QueueImageDispatch.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / io / QueueImageDispatch.cc
CommitLineData
f67539c2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "librbd/io/QueueImageDispatch.h"
5#include "common/dout.h"
6#include "common/Cond.h"
7#include "librbd/AsioEngine.h"
8#include "librbd/ImageCtx.h"
9#include "librbd/Utils.h"
10#include "librbd/io/AioCompletion.h"
11#include "librbd/io/FlushTracker.h"
12#include "librbd/io/ImageDispatchSpec.h"
13
14#define dout_subsys ceph_subsys_rbd
15#undef dout_prefix
16#define dout_prefix *_dout << "librbd::io::QueueImageDispatch: " << this \
17 << " " << __func__ << ": "
18
19namespace librbd {
20namespace io {
21
22template <typename I>
23QueueImageDispatch<I>::QueueImageDispatch(I* image_ctx)
24 : m_image_ctx(image_ctx), m_flush_tracker(new FlushTracker<I>(image_ctx)) {
25 auto cct = m_image_ctx->cct;
26 ldout(cct, 5) << "ictx=" << image_ctx << dendl;
27}
28
29template <typename I>
30QueueImageDispatch<I>::~QueueImageDispatch() {
31 delete m_flush_tracker;
32}
33
34template <typename I>
35void QueueImageDispatch<I>::shut_down(Context* on_finish) {
36 m_flush_tracker->shut_down();
37 on_finish->complete(0);
38}
39
40template <typename I>
41bool QueueImageDispatch<I>::read(
42 AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
43 IOContext io_context, int op_flags, int read_flags,
44 const ZTracer::Trace &parent_trace, uint64_t tid,
45 std::atomic<uint32_t>* image_dispatch_flags,
46 DispatchResult* dispatch_result, Context** on_finish,
47 Context* on_dispatched) {
48 auto cct = m_image_ctx->cct;
49 ldout(cct, 20) << "tid=" << tid << dendl;
50
51 return enqueue(true, tid, dispatch_result, on_finish, on_dispatched);
52}
53
54template <typename I>
55bool QueueImageDispatch<I>::write(
56 AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
1e59de90 57 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
58 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
59 DispatchResult* dispatch_result, Context** on_finish,
60 Context* on_dispatched) {
61 auto cct = m_image_ctx->cct;
62 ldout(cct, 20) << "tid=" << tid << dendl;
63
64 return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
65}
66
67template <typename I>
68bool QueueImageDispatch<I>::discard(
69 AioCompletion* aio_comp, Extents &&image_extents,
1e59de90 70 uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
f67539c2
TL
71 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
72 DispatchResult* dispatch_result, Context** on_finish,
73 Context* on_dispatched) {
74 auto cct = m_image_ctx->cct;
75 ldout(cct, 20) << "tid=" << tid << dendl;
76
77 return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
78}
79
80template <typename I>
81bool QueueImageDispatch<I>::write_same(
82 AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
1e59de90 83 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
84 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
85 DispatchResult* dispatch_result, Context** on_finish,
86 Context* on_dispatched) {
87 auto cct = m_image_ctx->cct;
88 ldout(cct, 20) << "tid=" << tid << dendl;
89
90 return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
91}
92
93template <typename I>
94bool QueueImageDispatch<I>::compare_and_write(
1e59de90
TL
95 AioCompletion* aio_comp, Extents &&image_extents,
96 bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
97 int op_flags, const ZTracer::Trace &parent_trace,
98 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
f67539c2
TL
99 DispatchResult* dispatch_result, Context** on_finish,
100 Context* on_dispatched) {
101 auto cct = m_image_ctx->cct;
102 ldout(cct, 20) << "tid=" << tid << dendl;
103
104 return enqueue(false, tid, dispatch_result, on_finish, on_dispatched);
105}
106
107template <typename I>
108bool QueueImageDispatch<I>::flush(
109 AioCompletion* aio_comp, FlushSource flush_source,
110 const ZTracer::Trace &parent_trace, uint64_t tid,
111 std::atomic<uint32_t>* image_dispatch_flags,
112 DispatchResult* dispatch_result, Context** on_finish,
113 Context* on_dispatched) {
114 auto cct = m_image_ctx->cct;
115 ldout(cct, 20) << "tid=" << tid << dendl;
116
117 *dispatch_result = DISPATCH_RESULT_CONTINUE;
118 m_flush_tracker->flush(on_dispatched);
119 return true;
120}
121
122template <typename I>
123void QueueImageDispatch<I>::handle_finished(int r, uint64_t tid) {
124 auto cct = m_image_ctx->cct;
125 ldout(cct, 20) << "tid=" << tid << dendl;
126
127 m_flush_tracker->finish_io(tid);
128}
129
130template <typename I>
131bool QueueImageDispatch<I>::enqueue(
132 bool read_op, uint64_t tid, DispatchResult* dispatch_result,
133 Context** on_finish, Context* on_dispatched) {
134 if (!m_image_ctx->non_blocking_aio) {
135 return false;
136 }
137
138 if (!read_op) {
139 m_flush_tracker->start_io(tid);
140 *on_finish = new LambdaContext([this, tid, on_finish=*on_finish](int r) {
141 handle_finished(r, tid);
142 on_finish->complete(r);
143 });
144 }
145
146 *dispatch_result = DISPATCH_RESULT_CONTINUE;
147 m_image_ctx->asio_engine->post(on_dispatched, 0);
148 return true;
149}
150
151} // namespace io
152} // namespace librbd
153
154template class librbd::io::QueueImageDispatch<librbd::ImageCtx>;