]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/io/RefreshImageDispatch.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / io / RefreshImageDispatch.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/RefreshImageDispatch.h"
5#include "common/dout.h"
6#include "librbd/ImageCtx.h"
7#include "librbd/ImageState.h"
8#include <map>
9
10#define dout_subsys ceph_subsys_rbd
11#undef dout_prefix
12#define dout_prefix *_dout << "librbd::io::RefreshImageDispatch: " << this \
13 << " " << __func__ << ": "
14
15namespace librbd {
16namespace io {
17
18template <typename I>
19RefreshImageDispatch<I>::RefreshImageDispatch(I* image_ctx)
20 : m_image_ctx(image_ctx) {
21 auto cct = m_image_ctx->cct;
22 ldout(cct, 5) << "ictx=" << image_ctx << dendl;
23}
24
25template <typename I>
26void RefreshImageDispatch<I>::shut_down(Context* on_finish) {
27 on_finish->complete(0);
28}
29
30template <typename I>
31bool RefreshImageDispatch<I>::read(
32 AioCompletion* aio_comp, Extents &&image_extents, ReadResult &&read_result,
33 IOContext io_context, int op_flags, int read_flags,
34 const ZTracer::Trace &parent_trace, uint64_t tid,
35 std::atomic<uint32_t>* image_dispatch_flags,
36 DispatchResult* dispatch_result, Context** on_finish,
37 Context* on_dispatched) {
38 auto cct = m_image_ctx->cct;
39 ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
40 << dendl;
41
42 if (needs_refresh(dispatch_result, on_dispatched)) {
43 return true;
44 }
45
46 return false;
47}
48
49template <typename I>
50bool RefreshImageDispatch<I>::write(
51 AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
1e59de90 52 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
53 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
54 DispatchResult* dispatch_result, Context** on_finish,
55 Context* on_dispatched) {
56 auto cct = m_image_ctx->cct;
57 ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
58 << dendl;
59
60 if (needs_refresh(dispatch_result, on_dispatched)) {
61 return true;
62 }
63
64 return false;
65}
66
67template <typename I>
68bool RefreshImageDispatch<I>::discard(
69 AioCompletion* aio_comp, Extents &&image_extents,
1e59de90
TL
70 uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
71 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
f67539c2
TL
72 DispatchResult* dispatch_result, Context** on_finish,
73 Context* on_dispatched) {
74 auto cct = m_image_ctx->cct;
75 ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
76 << dendl;
77
78 if (needs_refresh(dispatch_result, on_dispatched)) {
79 return true;
80 }
81
82 return false;
83}
84
85template <typename I>
86bool RefreshImageDispatch<I>::write_same(
87 AioCompletion* aio_comp, Extents &&image_extents, bufferlist &&bl,
1e59de90 88 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
89 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
90 DispatchResult* dispatch_result, Context** on_finish,
91 Context* on_dispatched) {
92 auto cct = m_image_ctx->cct;
93 ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
94 << dendl;
95
96 if (needs_refresh(dispatch_result, on_dispatched)) {
97 return true;
98 }
99
100 return false;
101}
102
103template <typename I>
104bool RefreshImageDispatch<I>::compare_and_write(
1e59de90
TL
105 AioCompletion* aio_comp, Extents &&image_extents,
106 bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
107 int op_flags, const ZTracer::Trace &parent_trace,
108 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
f67539c2
TL
109 DispatchResult* dispatch_result, Context** on_finish,
110 Context* on_dispatched) {
111 auto cct = m_image_ctx->cct;
112 ldout(cct, 20) << "tid=" << tid << ", image_extents=" << image_extents
113 << dendl;
114
115 if (needs_refresh(dispatch_result, on_dispatched)) {
116 return true;
117 }
118
119 return false;
120}
121
122template <typename I>
123bool RefreshImageDispatch<I>::flush(
124 AioCompletion* aio_comp, FlushSource flush_source,
125 const ZTracer::Trace &parent_trace, uint64_t tid,
126 std::atomic<uint32_t>* image_dispatch_flags,
127 DispatchResult* dispatch_result, Context** on_finish,
128 Context* on_dispatched) {
129 auto cct = m_image_ctx->cct;
130 ldout(cct, 20) << "tid=" << tid << dendl;
131
132 // The refresh state machine can initiate a flush and it can
133 // enable the exclusive-lock which will also attmept to flush.
134 if (flush_source == FLUSH_SOURCE_REFRESH ||
135 flush_source == FLUSH_SOURCE_EXCLUSIVE_LOCK_SKIP_REFRESH ||
136 flush_source == FLUSH_SOURCE_SHUTDOWN) {
137 return false;
138 }
139
140 if (needs_refresh(dispatch_result, on_dispatched)) {
141 return true;
142 }
143
144 return false;
145}
146
147template <typename I>
148bool RefreshImageDispatch<I>::needs_refresh(
149 DispatchResult* dispatch_result, Context* on_dispatched) {
150 auto cct = m_image_ctx->cct;
151
152 if (m_image_ctx->state->is_refresh_required()) {
153 ldout(cct, 15) << "on_dispatched=" << on_dispatched << dendl;
154
155 *dispatch_result = DISPATCH_RESULT_CONTINUE;
156 m_image_ctx->state->refresh(on_dispatched);
157 return true;
158 }
159
160 return false;
161}
162
163} // namespace io
164} // namespace librbd
165
166template class librbd::io::RefreshImageDispatch<librbd::ImageCtx>;