Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2017 Intel Corporation.
3 : : * All rights reserved.
4 : : * Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : : */
6 : :
7 : : #include "spdk/stdinc.h"
8 : :
9 : : #include "blobstore.h"
10 : : #include "request.h"
11 : :
12 : : #include "spdk/thread.h"
13 : : #include "spdk/queue.h"
14 : : #include "spdk/trace.h"
15 : :
16 : : #include "spdk_internal/trace_defs.h"
17 : : #include "spdk/log.h"
18 : :
19 : : void
20 : 56917 : bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno)
21 : : {
22 [ - + + + : 56917 : switch (cpl->type) {
+ + - + ]
23 : : case SPDK_BS_CPL_TYPE_BS_BASIC:
24 : 1402 : cpl->u.bs_basic.cb_fn(cpl->u.bs_basic.cb_arg,
25 : 701 : bserrno);
26 : 701 : break;
27 : : case SPDK_BS_CPL_TYPE_BS_HANDLE:
28 : 2030 : cpl->u.bs_handle.cb_fn(cpl->u.bs_handle.cb_arg,
29 [ + + ]: 1015 : bserrno == 0 ? cpl->u.bs_handle.bs : NULL,
30 : 1015 : bserrno);
31 : 1015 : break;
32 : : case SPDK_BS_CPL_TYPE_BLOB_BASIC:
33 : 97586 : cpl->u.blob_basic.cb_fn(cpl->u.blob_basic.cb_arg,
34 : 48793 : bserrno);
35 : 48793 : break;
36 : : case SPDK_BS_CPL_TYPE_BLOBID:
37 : 3766 : cpl->u.blobid.cb_fn(cpl->u.blobid.cb_arg,
38 [ + + ]: 1883 : bserrno == 0 ? cpl->u.blobid.blobid : SPDK_BLOBID_INVALID,
39 : 1883 : bserrno);
40 : 1883 : break;
41 : : case SPDK_BS_CPL_TYPE_BLOB_HANDLE:
42 : 7012 : cpl->u.blob_handle.cb_fn(cpl->u.blob_handle.cb_arg,
43 [ + + ]: 3506 : bserrno == 0 ? cpl->u.blob_handle.blob : NULL,
44 : 3506 : bserrno);
45 : 3506 : break;
46 : : case SPDK_BS_CPL_TYPE_NESTED_SEQUENCE:
47 : 0 : cpl->u.nested_seq.cb_fn(cpl->u.nested_seq.cb_arg,
48 : 0 : cpl->u.nested_seq.parent,
49 : 0 : bserrno);
50 : 0 : break;
51 : : case SPDK_BS_CPL_TYPE_NONE:
52 : : /* this completion's callback is handled elsewhere */
53 : 1019 : break;
54 : : }
55 : 56917 : }
56 : :
57 : : static void
58 : 55898 : bs_request_set_complete(struct spdk_bs_request_set *set)
59 : : {
60 : 55898 : struct spdk_bs_cpl cpl = set->cpl;
61 : 55898 : int bserrno = set->bserrno;
62 : :
63 [ + + + - ]: 55898 : spdk_trace_record(TRACE_BLOB_REQ_SET_COMPLETE, 0, 0, (uintptr_t)&set->cb_args,
64 : : (uintptr_t)set->cpl.u.blob_basic.cb_arg);
65 : :
66 : 55898 : TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
67 : :
68 : 55898 : bs_call_cpl(&cpl, bserrno);
69 : 55898 : }
70 : :
71 : : static void
72 : 24748 : bs_sequence_completion(struct spdk_io_channel *channel, void *cb_arg, int bserrno)
73 : : {
74 : 24748 : struct spdk_bs_request_set *set = cb_arg;
75 : :
76 : 24748 : set->bserrno = bserrno;
77 : 24748 : set->u.sequence.cb_fn((spdk_bs_sequence_t *)set, set->u.sequence.cb_arg, bserrno);
78 : 24748 : }
79 : :
80 : : static inline spdk_bs_sequence_t *
81 : 18390 : bs_sequence_start(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl,
82 : : struct spdk_io_channel *back_channel)
83 : : {
84 : : struct spdk_bs_channel *channel;
85 : : struct spdk_bs_request_set *set;
86 : :
87 : 18390 : channel = spdk_io_channel_get_ctx(_channel);
88 [ + - ]: 18390 : assert(channel != NULL);
89 : 18390 : set = TAILQ_FIRST(&channel->reqs);
90 [ + - ]: 18390 : if (!set) {
91 : 0 : return NULL;
92 : : }
93 [ + - ]: 18390 : TAILQ_REMOVE(&channel->reqs, set, link);
94 : :
95 [ + + - + ]: 18390 : spdk_trace_record(TRACE_BLOB_REQ_SET_START, 0, 0, (uintptr_t)&set->cb_args,
96 : : (uintptr_t)cpl->u.blob_basic.cb_arg);
97 : :
98 : 18390 : set->cpl = *cpl;
99 : 18390 : set->bserrno = 0;
100 : 18390 : set->channel = channel;
101 : 18390 : set->back_channel = back_channel;
102 : :
103 : 18390 : set->cb_args.cb_fn = bs_sequence_completion;
104 : 18390 : set->cb_args.cb_arg = set;
105 : 18390 : set->cb_args.channel = channel->dev_channel;
106 : 18390 : set->ext_io_opts = NULL;
107 : :
108 : 18390 : return (spdk_bs_sequence_t *)set;
109 : 18390 : }
110 : :
111 : : /* Use when performing IO directly on the blobstore (e.g. metadata - not a blob). */
112 : : spdk_bs_sequence_t *
113 : 14999 : bs_sequence_start_bs(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl)
114 : : {
115 : 14999 : return bs_sequence_start(_channel, cpl, _channel);
116 : : }
117 : :
118 : : /* Use when performing IO on a blob. */
119 : : spdk_bs_sequence_t *
120 : 3391 : bs_sequence_start_blob(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl,
121 : : struct spdk_blob *blob)
122 : : {
123 : 3391 : struct spdk_io_channel *esnap_ch = _channel;
124 : :
125 [ + + ]: 3391 : if (spdk_blob_is_esnap_clone(blob)) {
126 : 1500 : esnap_ch = blob_esnap_get_io_channel(_channel, blob);
127 [ - + ]: 1500 : if (esnap_ch == NULL) {
128 : : /*
129 : : * The most likely reason we are here is because of some logic error
130 : : * elsewhere that caused channel allocations to fail. We could get here due
131 : : * to being out of memory as well. If we are out of memory, the process is
132 : : * this will be just one of many problems that this process will be having.
133 : : * Killing it off debug builds now due to logic errors is the right thing to
134 : : * do and killing it off due to ENOMEM is no big loss.
135 : : */
136 : 0 : assert(false);
137 : : return NULL;
138 : : }
139 : 1500 : }
140 : 3391 : return bs_sequence_start(_channel, cpl, esnap_ch);
141 : : }
142 : :
143 : : void
144 : 282 : bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
145 : : void *payload, uint64_t lba, uint32_t lba_count,
146 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
147 : : {
148 : 282 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
149 : 282 : struct spdk_io_channel *back_channel = set->back_channel;
150 : :
151 [ + - ]: 282 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
152 : : lba);
153 : :
154 : 282 : set->u.sequence.cb_fn = cb_fn;
155 : 282 : set->u.sequence.cb_arg = cb_arg;
156 : :
157 : 282 : bs_dev->read(bs_dev, back_channel, payload, lba, lba_count, &set->cb_args);
158 : 282 : }
159 : :
160 : : void
161 : 13351 : bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload,
162 : : uint64_t lba, uint32_t lba_count,
163 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
164 : : {
165 : 13351 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
166 : 13351 : struct spdk_bs_channel *channel = set->channel;
167 : :
168 [ + - ]: 13351 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
169 : : lba);
170 : :
171 : 13351 : set->u.sequence.cb_fn = cb_fn;
172 : 13351 : set->u.sequence.cb_arg = cb_arg;
173 : :
174 : 13351 : channel->dev->read(channel->dev, channel->dev_channel, payload, lba, lba_count, &set->cb_args);
175 : 13351 : }
176 : :
177 : : void
178 : 8587 : bs_sequence_write_dev(spdk_bs_sequence_t *seq, void *payload,
179 : : uint64_t lba, uint32_t lba_count,
180 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
181 : : {
182 : 8587 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
183 : 8587 : struct spdk_bs_channel *channel = set->channel;
184 : :
185 [ + - ]: 8587 : SPDK_DEBUGLOG(blob_rw, "Writing %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
186 : : lba);
187 : :
188 : 8587 : set->u.sequence.cb_fn = cb_fn;
189 : 8587 : set->u.sequence.cb_arg = cb_arg;
190 : :
191 : 17174 : channel->dev->write(channel->dev, channel->dev_channel, payload, lba, lba_count,
192 : 8587 : &set->cb_args);
193 : 8587 : }
194 : :
195 : : void
196 : 1559 : bs_sequence_readv_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
197 : : struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
198 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
199 : : {
200 : 1559 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
201 : 1559 : struct spdk_io_channel *back_channel = set->back_channel;
202 : :
203 [ + - ]: 1559 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
204 : : lba);
205 : :
206 : 1559 : set->u.sequence.cb_fn = cb_fn;
207 : 1559 : set->u.sequence.cb_arg = cb_arg;
208 : :
209 [ + + ]: 1559 : if (set->ext_io_opts) {
210 [ - + ]: 87 : assert(bs_dev->readv_ext);
211 : 174 : bs_dev->readv_ext(bs_dev, back_channel, iov, iovcnt, lba, lba_count,
212 : 87 : &set->cb_args, set->ext_io_opts);
213 : 87 : } else {
214 : 1472 : bs_dev->readv(bs_dev, back_channel, iov, iovcnt, lba, lba_count, &set->cb_args);
215 : : }
216 : 1559 : }
217 : :
218 : : void
219 : 558 : bs_sequence_readv_dev(spdk_bs_sequence_t *seq, struct iovec *iov, int iovcnt,
220 : : uint64_t lba, uint32_t lba_count, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
221 : : {
222 : 558 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
223 : 558 : struct spdk_bs_channel *channel = set->channel;
224 : :
225 [ + - ]: 558 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
226 : : lba);
227 : :
228 : 558 : set->u.sequence.cb_fn = cb_fn;
229 : 558 : set->u.sequence.cb_arg = cb_arg;
230 [ + + ]: 558 : if (set->ext_io_opts) {
231 [ - + ]: 234 : assert(channel->dev->readv_ext);
232 : 468 : channel->dev->readv_ext(channel->dev, channel->dev_channel, iov, iovcnt, lba, lba_count,
233 : 234 : &set->cb_args, set->ext_io_opts);
234 : 234 : } else {
235 : 324 : channel->dev->readv(channel->dev, channel->dev_channel, iov, iovcnt, lba, lba_count, &set->cb_args);
236 : : }
237 : 558 : }
238 : :
239 : : void
240 : 276 : bs_sequence_writev_dev(spdk_bs_sequence_t *seq, struct iovec *iov, int iovcnt,
241 : : uint64_t lba, uint32_t lba_count,
242 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
243 : : {
244 : 276 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
245 : 276 : struct spdk_bs_channel *channel = set->channel;
246 : :
247 [ + - ]: 276 : SPDK_DEBUGLOG(blob_rw, "Writing %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
248 : : lba);
249 : :
250 : 276 : set->u.sequence.cb_fn = cb_fn;
251 : 276 : set->u.sequence.cb_arg = cb_arg;
252 : :
253 [ + + ]: 276 : if (set->ext_io_opts) {
254 [ - + ]: 72 : assert(channel->dev->writev_ext);
255 : 144 : channel->dev->writev_ext(channel->dev, channel->dev_channel, iov, iovcnt, lba, lba_count,
256 : 72 : &set->cb_args, set->ext_io_opts);
257 : 72 : } else {
258 : 408 : channel->dev->writev(channel->dev, channel->dev_channel, iov, iovcnt, lba, lba_count,
259 : 204 : &set->cb_args);
260 : : }
261 : 276 : }
262 : :
263 : : void
264 : 5 : bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq,
265 : : uint64_t lba, uint64_t lba_count,
266 : : spdk_bs_sequence_cpl cb_fn, void *cb_arg)
267 : : {
268 : 5 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
269 : 5 : struct spdk_bs_channel *channel = set->channel;
270 : :
271 [ + - ]: 5 : SPDK_DEBUGLOG(blob_rw, "writing zeroes to %" PRIu64 " blocks at LBA %" PRIu64 "\n",
272 : : lba_count, lba);
273 : :
274 : 5 : set->u.sequence.cb_fn = cb_fn;
275 : 5 : set->u.sequence.cb_arg = cb_arg;
276 : :
277 : 10 : channel->dev->write_zeroes(channel->dev, channel->dev_channel, lba, lba_count,
278 : 5 : &set->cb_args);
279 : 5 : }
280 : :
281 : : void
282 : 130 : bs_sequence_copy_dev(spdk_bs_sequence_t *seq, uint64_t dst_lba, uint64_t src_lba,
283 : : uint64_t lba_count, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
284 : : {
285 : 130 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
286 : 130 : struct spdk_bs_channel *channel = set->channel;
287 : :
288 [ + - ]: 130 : SPDK_DEBUGLOG(blob_rw, "Copying %" PRIu64 " blocks from LBA %" PRIu64 " to LBA %" PRIu64 "\n",
289 : : lba_count, src_lba, dst_lba);
290 : :
291 : 130 : set->u.sequence.cb_fn = cb_fn;
292 : 130 : set->u.sequence.cb_arg = cb_arg;
293 : :
294 : 130 : channel->dev->copy(channel->dev, channel->dev_channel, dst_lba, src_lba, lba_count, &set->cb_args);
295 : 130 : }
296 : :
297 : : void
298 : 18390 : bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno)
299 : : {
300 [ + + ]: 18390 : if (bserrno != 0) {
301 : 405 : seq->bserrno = bserrno;
302 : 405 : }
303 : 18390 : bs_request_set_complete((struct spdk_bs_request_set *)seq);
304 : 18390 : }
305 : :
306 : : void
307 : 0 : bs_user_op_sequence_finish(void *cb_arg, int bserrno)
308 : : {
309 : 0 : spdk_bs_sequence_t *seq = cb_arg;
310 : :
311 : 0 : bs_sequence_finish(seq, bserrno);
312 : 0 : }
313 : :
314 : : static void
315 : 42039 : bs_batch_completion(struct spdk_io_channel *_channel,
316 : : void *cb_arg, int bserrno)
317 : : {
318 : 42039 : struct spdk_bs_request_set *set = cb_arg;
319 : :
320 : 42039 : set->u.batch.outstanding_ops--;
321 [ + + ]: 42039 : if (bserrno != 0) {
322 : 4 : set->bserrno = bserrno;
323 : 4 : }
324 : :
325 [ + + + + ]: 42039 : if (set->u.batch.outstanding_ops == 0 && set->u.batch.batch_closed) {
326 [ + + ]: 40520 : if (set->u.batch.cb_fn) {
327 : 3948 : set->cb_args.cb_fn = bs_sequence_completion;
328 : 3948 : set->u.batch.cb_fn((spdk_bs_sequence_t *)set, set->u.batch.cb_arg, bserrno);
329 : 3948 : } else {
330 : 36572 : bs_request_set_complete(set);
331 : : }
332 : 40520 : }
333 : 42039 : }
334 : :
335 : : spdk_bs_batch_t *
336 : 37508 : bs_batch_open(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl, struct spdk_blob *blob)
337 : : {
338 : : struct spdk_bs_channel *channel;
339 : : struct spdk_bs_request_set *set;
340 : 37508 : struct spdk_io_channel *back_channel = _channel;
341 : :
342 [ + + ]: 37508 : if (spdk_blob_is_esnap_clone(blob)) {
343 : 7340 : back_channel = blob_esnap_get_io_channel(_channel, blob);
344 [ + - ]: 7340 : if (back_channel == NULL) {
345 : 0 : return NULL;
346 : : }
347 : 7340 : }
348 : :
349 : 37508 : channel = spdk_io_channel_get_ctx(_channel);
350 [ + - ]: 37508 : assert(channel != NULL);
351 : 37508 : set = TAILQ_FIRST(&channel->reqs);
352 [ + - ]: 37508 : if (!set) {
353 : 0 : return NULL;
354 : : }
355 [ + - ]: 37508 : TAILQ_REMOVE(&channel->reqs, set, link);
356 : :
357 [ + - - + ]: 37508 : spdk_trace_record(TRACE_BLOB_REQ_SET_START, 0, 0, (uintptr_t)&set->cb_args,
358 : : (uintptr_t)cpl->u.blob_basic.cb_arg);
359 : :
360 : 37508 : set->cpl = *cpl;
361 : 37508 : set->bserrno = 0;
362 : 37508 : set->channel = channel;
363 : 37508 : set->back_channel = back_channel;
364 : :
365 : 37508 : set->u.batch.cb_fn = NULL;
366 : 37508 : set->u.batch.cb_arg = NULL;
367 : 37508 : set->u.batch.outstanding_ops = 0;
368 : 37508 : set->u.batch.batch_closed = 0;
369 : :
370 : 37508 : set->cb_args.cb_fn = bs_batch_completion;
371 : 37508 : set->cb_args.cb_arg = set;
372 : 37508 : set->cb_args.channel = channel->dev_channel;
373 : :
374 : 37508 : return (spdk_bs_batch_t *)set;
375 : 37508 : }
376 : :
377 : : void
378 : 1088 : bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
379 : : void *payload, uint64_t lba, uint32_t lba_count)
380 : : {
381 : 1088 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
382 : 1088 : struct spdk_io_channel *back_channel = set->back_channel;
383 : :
384 [ + - ]: 1088 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
385 : : lba);
386 : :
387 : 1088 : set->u.batch.outstanding_ops++;
388 : 1088 : bs_dev->read(bs_dev, back_channel, payload, lba, lba_count, &set->cb_args);
389 : 1088 : }
390 : :
391 : : void
392 : 15857 : bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload,
393 : : uint64_t lba, uint32_t lba_count)
394 : : {
395 : 15857 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
396 : 15857 : struct spdk_bs_channel *channel = set->channel;
397 : :
398 [ + - ]: 15857 : SPDK_DEBUGLOG(blob_rw, "Reading %" PRIu32 " blocks from LBA %" PRIu64 "\n", lba_count,
399 : : lba);
400 : :
401 : 15857 : set->u.batch.outstanding_ops++;
402 : 15857 : channel->dev->read(channel->dev, channel->dev_channel, payload, lba, lba_count, &set->cb_args);
403 : 15857 : }
404 : :
405 : : void
406 : 20571 : bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload,
407 : : uint64_t lba, uint32_t lba_count)
408 : : {
409 : 20571 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
410 : 20571 : struct spdk_bs_channel *channel = set->channel;
411 : :
412 [ + - ]: 20571 : SPDK_DEBUGLOG(blob_rw, "Writing %" PRIu32 " blocks to LBA %" PRIu64 "\n", lba_count, lba);
413 : :
414 : 20571 : set->u.batch.outstanding_ops++;
415 : 41142 : channel->dev->write(channel->dev, channel->dev_channel, payload, lba, lba_count,
416 : 20571 : &set->cb_args);
417 : 20571 : }
418 : :
419 : : void
420 : 1824 : bs_batch_unmap_dev(spdk_bs_batch_t *batch,
421 : : uint64_t lba, uint64_t lba_count)
422 : : {
423 : 1824 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
424 : 1824 : struct spdk_bs_channel *channel = set->channel;
425 : :
426 [ + - ]: 1824 : SPDK_DEBUGLOG(blob_rw, "Unmapping %" PRIu64 " blocks at LBA %" PRIu64 "\n", lba_count,
427 : : lba);
428 : :
429 : 1824 : set->u.batch.outstanding_ops++;
430 : 3648 : channel->dev->unmap(channel->dev, channel->dev_channel, lba, lba_count,
431 : 1824 : &set->cb_args);
432 : 1824 : }
433 : :
434 : : void
435 : 2699 : bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch,
436 : : uint64_t lba, uint64_t lba_count)
437 : : {
438 : 2699 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
439 : 2699 : struct spdk_bs_channel *channel = set->channel;
440 : :
441 [ + - ]: 2699 : SPDK_DEBUGLOG(blob_rw, "Zeroing %" PRIu64 " blocks at LBA %" PRIu64 "\n", lba_count, lba);
442 : :
443 : 2699 : set->u.batch.outstanding_ops++;
444 : 5398 : channel->dev->write_zeroes(channel->dev, channel->dev_channel, lba, lba_count,
445 : 2699 : &set->cb_args);
446 : 2699 : }
447 : :
448 : : void
449 : 56920 : bs_batch_close(spdk_bs_batch_t *batch)
450 : : {
451 : 56920 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
452 : :
453 : 56920 : set->u.batch.batch_closed = 1;
454 : :
455 [ + + ]: 56920 : if (set->u.batch.outstanding_ops == 0) {
456 [ + + ]: 16400 : if (set->u.batch.cb_fn) {
457 : 15464 : set->cb_args.cb_fn = bs_sequence_completion;
458 : 15464 : set->u.batch.cb_fn((spdk_bs_sequence_t *)set, set->u.batch.cb_arg, set->bserrno);
459 : 15464 : } else {
460 : 936 : bs_request_set_complete(set);
461 : : }
462 : 16400 : }
463 : 56920 : }
464 : :
465 : : spdk_bs_batch_t *
466 : 19412 : bs_sequence_to_batch(spdk_bs_sequence_t *seq, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
467 : : {
468 : 19412 : struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
469 : :
470 : 19412 : set->u.batch.cb_fn = cb_fn;
471 : 19412 : set->u.batch.cb_arg = cb_arg;
472 : 19412 : set->u.batch.outstanding_ops = 0;
473 : 19412 : set->u.batch.batch_closed = 0;
474 : :
475 : 19412 : set->cb_args.cb_fn = bs_batch_completion;
476 : :
477 : 19412 : return set;
478 : : }
479 : :
480 : : spdk_bs_user_op_t *
481 : 824 : bs_user_op_alloc(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl,
482 : : enum spdk_blob_op_type op_type, struct spdk_blob *blob,
483 : : void *payload, int iovcnt, uint64_t offset, uint64_t length)
484 : : {
485 : : struct spdk_bs_channel *channel;
486 : : struct spdk_bs_request_set *set;
487 : : struct spdk_bs_user_op_args *args;
488 : :
489 : 824 : channel = spdk_io_channel_get_ctx(_channel);
490 [ + - ]: 824 : assert(channel != NULL);
491 : 824 : set = TAILQ_FIRST(&channel->reqs);
492 [ + - ]: 824 : if (!set) {
493 : 0 : return NULL;
494 : : }
495 [ + - ]: 824 : TAILQ_REMOVE(&channel->reqs, set, link);
496 : :
497 [ + - - + ]: 824 : spdk_trace_record(TRACE_BLOB_REQ_SET_START, 0, 0, (uintptr_t)&set->cb_args,
498 : : (uintptr_t)cpl->u.blob_basic.cb_arg);
499 : :
500 : 824 : set->cpl = *cpl;
501 : 824 : set->channel = channel;
502 : 824 : set->back_channel = NULL;
503 : 824 : set->ext_io_opts = NULL;
504 : :
505 : 824 : args = &set->u.user_op;
506 : :
507 : 824 : args->type = op_type;
508 : 824 : args->iovcnt = iovcnt;
509 : 824 : args->blob = blob;
510 : 824 : args->offset = offset;
511 : 824 : args->length = length;
512 : 824 : args->payload = payload;
513 : :
514 : 824 : return (spdk_bs_user_op_t *)set;
515 : 824 : }
516 : :
517 : : void
518 : 824 : bs_user_op_execute(spdk_bs_user_op_t *op)
519 : : {
520 : : struct spdk_bs_request_set *set;
521 : : struct spdk_bs_user_op_args *args;
522 : : struct spdk_io_channel *ch;
523 : :
524 : 824 : set = (struct spdk_bs_request_set *)op;
525 : 824 : args = &set->u.user_op;
526 : 824 : ch = spdk_io_channel_from_ctx(set->channel);
527 : :
528 [ + + - - : 824 : switch (args->type) {
- + - ]
529 : : case SPDK_BLOB_READ:
530 : 904 : spdk_blob_io_read(args->blob, ch, args->payload, args->offset, args->length,
531 : 452 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
532 : 452 : break;
533 : : case SPDK_BLOB_WRITE:
534 : 712 : spdk_blob_io_write(args->blob, ch, args->payload, args->offset, args->length,
535 : 356 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
536 : 356 : break;
537 : : case SPDK_BLOB_UNMAP:
538 : 0 : spdk_blob_io_unmap(args->blob, ch, args->offset, args->length,
539 : 0 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
540 : 0 : break;
541 : : case SPDK_BLOB_WRITE_ZEROES:
542 : 0 : spdk_blob_io_write_zeroes(args->blob, ch, args->offset, args->length,
543 : 0 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
544 : 0 : break;
545 : : case SPDK_BLOB_READV:
546 : 0 : spdk_blob_io_readv_ext(args->blob, ch, args->payload, args->iovcnt,
547 : 0 : args->offset, args->length,
548 : 0 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg,
549 : 0 : set->ext_io_opts);
550 : 0 : break;
551 : : case SPDK_BLOB_WRITEV:
552 : 32 : spdk_blob_io_writev_ext(args->blob, ch, args->payload, args->iovcnt,
553 : 16 : args->offset, args->length,
554 : 16 : set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg,
555 : 16 : set->ext_io_opts);
556 : 16 : break;
557 : : }
558 : 824 : TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
559 : 824 : }
560 : :
561 : : void
562 : 0 : bs_user_op_abort(spdk_bs_user_op_t *op, int bserrno)
563 : : {
564 : : struct spdk_bs_request_set *set;
565 : :
566 : 0 : set = (struct spdk_bs_request_set *)op;
567 : :
568 : 0 : set->cpl.u.blob_basic.cb_fn(set->cpl.u.blob_basic.cb_arg, bserrno);
569 : 0 : TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
570 : 0 : }
571 : :
572 : 45 : SPDK_LOG_REGISTER_COMPONENT(blob_rw)
|