1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "common/dout.h"
#include "include/neorados/RADOS.hpp"
#include "librbd/cache/pwl/AbstractWriteLog.h"
#include "librbd/cache/pwl/ShutdownRequest.h"
#include "librbd/cache/WriteLogImageDispatch.h"
#include "librbd/ImageCtx.h"
#include "librbd/io/AioCompletion.h"
#include "librbd/io/Utils.h"
#define dout_subsys ceph_subsys_rbd_pwl
#undef dout_prefix
#define dout_prefix *_dout << "librbd::cache::WriteLogImageDispatch: " << this << " " \
<< __func__ << ": "
namespace librbd {
namespace cache {
template <typename I>
void WriteLogImageDispatch<I>::shut_down(Context* on_finish) {
ceph_assert(m_image_cache != nullptr);
Context* ctx = new LambdaContext(
[this, on_finish](int r) {
m_image_cache = nullptr;
on_finish->complete(r);
});
cache::pwl::ShutdownRequest<I> *req = cache::pwl::ShutdownRequest<I>::create(
*m_image_ctx, m_image_cache, m_plugin_api, ctx);
req->send();
}
template <typename I>
bool WriteLogImageDispatch<I>::read(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
io::ReadResult &&read_result, IOContext io_context,
int op_flags, int read_flags,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
if (*image_dispatch_flags & io::IMAGE_DISPATCH_FLAG_CRYPTO_HEADER) {
return false;
}
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "image_extents=" << image_extents << dendl;
if (io_context->read_snap().value_or(CEPH_NOSNAP) != CEPH_NOSNAP) {
return false;
}
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
if (preprocess_length(aio_comp, image_extents)) {
return true;
}
m_plugin_api.update_aio_comp(aio_comp, 1, read_result, image_extents);
auto *req_comp = m_plugin_api.create_image_read_request(aio_comp, 0, image_extents);
m_image_cache->read(std::move(image_extents),
&req_comp->bl, op_flags,
req_comp);
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::write(
io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
if (*image_dispatch_flags & io::IMAGE_DISPATCH_FLAG_CRYPTO_HEADER) {
return false;
}
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "image_extents=" << image_extents << dendl;
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
if (preprocess_length(aio_comp, image_extents)) {
return true;
}
m_plugin_api.update_aio_comp(aio_comp, 1);
io::C_AioRequest *req_comp = m_plugin_api.create_aio_request(aio_comp);
m_image_cache->write(std::move(image_extents),
std::move(bl), op_flags, req_comp);
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::discard(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
if (*image_dispatch_flags & io::IMAGE_DISPATCH_FLAG_CRYPTO_HEADER) {
return false;
}
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "image_extents=" << image_extents << dendl;
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
if (preprocess_length(aio_comp, image_extents)) {
return true;
}
m_plugin_api.update_aio_comp(aio_comp, image_extents.size());
for (auto &extent : image_extents) {
io::C_AioRequest *req_comp = m_plugin_api.create_aio_request(aio_comp);
m_image_cache->discard(extent.first, extent.second,
discard_granularity_bytes,
req_comp);
}
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::write_same(
io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
if (*image_dispatch_flags & io::IMAGE_DISPATCH_FLAG_CRYPTO_HEADER) {
return false;
}
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "image_extents=" << image_extents << dendl;
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
if (preprocess_length(aio_comp, image_extents)) {
return true;
}
m_plugin_api.update_aio_comp(aio_comp, image_extents.size());
for (auto &extent : image_extents) {
io::C_AioRequest *req_comp = m_plugin_api.create_aio_request(aio_comp);
m_image_cache->writesame(extent.first, extent.second,
std::move(bl), op_flags,
req_comp);
}
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::compare_and_write(
io::AioCompletion* aio_comp, io::Extents &&image_extents,
bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
int op_flags, const ZTracer::Trace &parent_trace,
uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
if (*image_dispatch_flags & io::IMAGE_DISPATCH_FLAG_CRYPTO_HEADER) {
return false;
}
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "image_extents=" << image_extents << dendl;
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
if (preprocess_length(aio_comp, image_extents)) {
return true;
}
m_plugin_api.update_aio_comp(aio_comp, 1);
io::C_AioRequest *req_comp = m_plugin_api.create_aio_request(aio_comp);
m_image_cache->compare_and_write(
std::move(image_extents), std::move(cmp_bl), std::move(bl),
mismatch_offset, op_flags, req_comp);
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::flush(
io::AioCompletion* aio_comp, io::FlushSource flush_source,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result,
Context** on_finish, Context* on_dispatched) {
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "tid=" << tid << dendl;
*dispatch_result = io::DISPATCH_RESULT_COMPLETE;
m_plugin_api.update_aio_comp(aio_comp, 1);
io::C_AioRequest *req_comp = m_plugin_api.create_aio_request(aio_comp);
m_image_cache->flush(flush_source, req_comp);
return true;
}
template <typename I>
bool WriteLogImageDispatch<I>::list_snaps(
io::AioCompletion* aio_comp, io::Extents&& image_extents,
io::SnapIds&& snap_ids,
int list_snaps_flags, io::SnapshotDelta* snapshot_delta,
const ZTracer::Trace &parent_trace, uint64_t tid,
std::atomic<uint32_t>* image_dispatch_flags,
io::DispatchResult* dispatch_result, Context** on_finish,
Context* on_dispatched) {
return false;
}
template <typename I>
bool WriteLogImageDispatch<I>::preprocess_length(
io::AioCompletion* aio_comp, io::Extents &image_extents) const {
auto total_bytes = io::util::get_extents_length(image_extents);
if (total_bytes == 0) {
m_plugin_api.update_aio_comp(aio_comp, 0);
return true;
}
return false;
}
template <typename I>
bool WriteLogImageDispatch<I>::invalidate_cache(Context* on_finish) {
m_image_cache->invalidate(on_finish);
return true;
}
} // namespace io
} // namespace librbd
template class librbd::cache::WriteLogImageDispatch<librbd::ImageCtx>;
|