xref: /spdk/lib/blob/request.c (revision c7852cf98d4df6ce3e2b1f7660db634876c42e0e)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "spdk/stdinc.h"
35 
36 #include "blobstore.h"
37 #include "request.h"
38 
39 #include "spdk/io_channel.h"
40 #include "spdk/queue.h"
41 
42 #include "spdk_internal/log.h"
43 
44 void
45 spdk_bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno)
46 {
47 	switch (cpl->type) {
48 	case SPDK_BS_CPL_TYPE_BS_BASIC:
49 		cpl->u.bs_basic.cb_fn(cpl->u.bs_basic.cb_arg,
50 				      bserrno);
51 		break;
52 	case SPDK_BS_CPL_TYPE_BS_HANDLE:
53 		cpl->u.bs_handle.cb_fn(cpl->u.bs_handle.cb_arg,
54 				       cpl->u.bs_handle.bs,
55 				       bserrno);
56 		break;
57 	case SPDK_BS_CPL_TYPE_BLOB_BASIC:
58 		cpl->u.blob_basic.cb_fn(cpl->u.blob_basic.cb_arg,
59 					bserrno);
60 		break;
61 	case SPDK_BS_CPL_TYPE_BLOBID:
62 		cpl->u.blobid.cb_fn(cpl->u.blobid.cb_arg,
63 				    cpl->u.blobid.blobid,
64 				    bserrno);
65 		break;
66 	case SPDK_BS_CPL_TYPE_BLOB_HANDLE:
67 		cpl->u.blob_handle.cb_fn(cpl->u.blob_handle.cb_arg,
68 					 cpl->u.blob_handle.blob,
69 					 bserrno);
70 		break;
71 	case SPDK_BS_CPL_TYPE_NESTED_SEQUENCE:
72 		cpl->u.nested_seq.cb_fn(cpl->u.nested_seq.cb_arg,
73 					cpl->u.nested_seq.parent,
74 					bserrno);
75 		break;
76 	case SPDK_BS_CPL_TYPE_NONE:
77 		/* this completion's callback is handled elsewhere */
78 		break;
79 	}
80 }
81 
82 static void
83 spdk_bs_request_set_complete(struct spdk_bs_request_set *set)
84 {
85 	struct spdk_bs_cpl cpl = set->cpl;
86 	int bserrno = set->bserrno;
87 
88 	TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
89 
90 	spdk_bs_call_cpl(&cpl, bserrno);
91 }
92 
93 static void
94 spdk_bs_sequence_completion(struct spdk_io_channel *channel, void *cb_arg, int bserrno)
95 {
96 	struct spdk_bs_request_set *set = cb_arg;
97 
98 	set->bserrno = bserrno;
99 	set->u.sequence.cb_fn((spdk_bs_sequence_t *)set, set->u.sequence.cb_arg, bserrno);
100 }
101 
102 spdk_bs_sequence_t *
103 spdk_bs_sequence_start(struct spdk_io_channel *_channel,
104 		       struct spdk_bs_cpl *cpl)
105 {
106 	struct spdk_bs_channel		*channel;
107 	struct spdk_bs_request_set	*set;
108 
109 	channel = spdk_io_channel_get_ctx(_channel);
110 
111 	set = TAILQ_FIRST(&channel->reqs);
112 	if (!set) {
113 		return NULL;
114 	}
115 	TAILQ_REMOVE(&channel->reqs, set, link);
116 
117 	set->cpl = *cpl;
118 	set->bserrno = 0;
119 	set->channel = channel;
120 
121 	set->cb_args.cb_fn = spdk_bs_sequence_completion;
122 	set->cb_args.cb_arg = set;
123 	set->cb_args.channel = channel->dev_channel;
124 
125 	return (spdk_bs_sequence_t *)set;
126 }
127 
128 void
129 spdk_bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
130 			     void *payload, uint64_t lba, uint32_t lba_count,
131 			     spdk_bs_sequence_cpl cb_fn, void *cb_arg)
132 {
133 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
134 	struct spdk_bs_channel       *channel = set->channel;
135 
136 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Reading %u blocks from LBA %lu\n", lba_count, lba);
137 
138 	set->u.sequence.cb_fn = cb_fn;
139 	set->u.sequence.cb_arg = cb_arg;
140 
141 	bs_dev->read(bs_dev, channel->dev_channel, payload, lba, lba_count, &set->cb_args);
142 }
143 
144 void
145 spdk_bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload,
146 			  uint64_t lba, uint32_t lba_count,
147 			  spdk_bs_sequence_cpl cb_fn, void *cb_arg)
148 {
149 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
150 	struct spdk_bs_channel       *channel = set->channel;
151 
152 	spdk_bs_sequence_read_bs_dev(seq, channel->dev, payload, lba, lba_count, cb_fn, cb_arg);
153 }
154 
155 void
156 spdk_bs_sequence_write_dev(spdk_bs_sequence_t *seq, void *payload,
157 			   uint64_t lba, uint32_t lba_count,
158 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg)
159 {
160 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
161 	struct spdk_bs_channel       *channel = set->channel;
162 
163 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Writing %u blocks to LBA %lu\n", lba_count, lba);
164 
165 	set->u.sequence.cb_fn = cb_fn;
166 	set->u.sequence.cb_arg = cb_arg;
167 
168 	channel->dev->write(channel->dev, channel->dev_channel, payload, lba, lba_count,
169 			    &set->cb_args);
170 }
171 
172 void
173 spdk_bs_sequence_readv_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
174 			      struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
175 			      spdk_bs_sequence_cpl cb_fn, void *cb_arg)
176 {
177 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
178 	struct spdk_bs_channel       *channel = set->channel;
179 
180 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Reading %u blocks from LBA %lu\n", lba_count, lba);
181 
182 	set->u.sequence.cb_fn = cb_fn;
183 	set->u.sequence.cb_arg = cb_arg;
184 
185 	bs_dev->readv(bs_dev, channel->dev_channel, iov, iovcnt, lba, lba_count,
186 		      &set->cb_args);
187 }
188 
189 void
190 spdk_bs_sequence_readv_dev(spdk_bs_sequence_t *seq, struct iovec *iov, int iovcnt,
191 			   uint64_t lba, uint32_t lba_count, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
192 {
193 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
194 	struct spdk_bs_channel       *channel = set->channel;
195 
196 	spdk_bs_sequence_readv_bs_dev(seq, channel->dev, iov, iovcnt, lba, lba_count, cb_fn, cb_arg);
197 }
198 
199 void
200 spdk_bs_sequence_writev_dev(spdk_bs_sequence_t *seq, struct iovec *iov, int iovcnt,
201 			    uint64_t lba, uint32_t lba_count,
202 			    spdk_bs_sequence_cpl cb_fn, void *cb_arg)
203 {
204 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
205 	struct spdk_bs_channel       *channel = set->channel;
206 
207 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Writing %u blocks to LBA %lu\n", lba_count, lba);
208 
209 	set->u.sequence.cb_fn = cb_fn;
210 	set->u.sequence.cb_arg = cb_arg;
211 
212 	channel->dev->writev(channel->dev, channel->dev_channel, iov, iovcnt, lba, lba_count,
213 			     &set->cb_args);
214 }
215 
216 void
217 spdk_bs_sequence_unmap_dev(spdk_bs_sequence_t *seq,
218 			   uint64_t lba, uint32_t lba_count,
219 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg)
220 {
221 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
222 	struct spdk_bs_channel       *channel = set->channel;
223 
224 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Unmapping %u blocks at LBA %lu\n", lba_count, lba);
225 
226 	set->u.sequence.cb_fn = cb_fn;
227 	set->u.sequence.cb_arg = cb_arg;
228 
229 	channel->dev->unmap(channel->dev, channel->dev_channel, lba, lba_count,
230 			    &set->cb_args);
231 }
232 
233 void
234 spdk_bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq,
235 				  uint64_t lba, uint32_t lba_count,
236 				  spdk_bs_sequence_cpl cb_fn, void *cb_arg)
237 {
238 	struct spdk_bs_request_set      *set = (struct spdk_bs_request_set *)seq;
239 	struct spdk_bs_channel       *channel = set->channel;
240 
241 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "writing zeroes to %u blocks at LBA %lu\n", lba_count, lba);
242 
243 	set->u.sequence.cb_fn = cb_fn;
244 	set->u.sequence.cb_arg = cb_arg;
245 
246 	channel->dev->write_zeroes(channel->dev, channel->dev_channel, lba, lba_count,
247 				   &set->cb_args);
248 }
249 
250 void
251 spdk_bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno)
252 {
253 	if (bserrno != 0) {
254 		seq->bserrno = bserrno;
255 	}
256 	spdk_bs_request_set_complete((struct spdk_bs_request_set *)seq);
257 }
258 
259 void
260 spdk_bs_user_op_sequence_finish(void *cb_arg, int bserrno)
261 {
262 	spdk_bs_sequence_t *seq = cb_arg;
263 
264 	spdk_bs_sequence_finish(seq, bserrno);
265 }
266 
267 static void
268 spdk_bs_batch_completion(struct spdk_io_channel *_channel,
269 			 void *cb_arg, int bserrno)
270 {
271 	struct spdk_bs_request_set	*set = cb_arg;
272 
273 	set->u.batch.outstanding_ops--;
274 	if (bserrno != 0) {
275 		set->bserrno = bserrno;
276 	}
277 
278 	if (set->u.batch.outstanding_ops == 0 && set->u.batch.batch_closed) {
279 		if (set->u.batch.cb_fn) {
280 			set->cb_args.cb_fn = spdk_bs_sequence_completion;
281 			set->u.batch.cb_fn((spdk_bs_sequence_t *)set, set->u.batch.cb_arg, bserrno);
282 		} else {
283 			spdk_bs_request_set_complete(set);
284 		}
285 	}
286 }
287 
288 spdk_bs_batch_t *
289 spdk_bs_batch_open(struct spdk_io_channel *_channel,
290 		   struct spdk_bs_cpl *cpl)
291 {
292 	struct spdk_bs_channel		*channel;
293 	struct spdk_bs_request_set	*set;
294 
295 	channel = spdk_io_channel_get_ctx(_channel);
296 
297 	set = TAILQ_FIRST(&channel->reqs);
298 	if (!set) {
299 		return NULL;
300 	}
301 	TAILQ_REMOVE(&channel->reqs, set, link);
302 
303 	set->cpl = *cpl;
304 	set->bserrno = 0;
305 	set->channel = channel;
306 
307 	set->u.batch.cb_fn = NULL;
308 	set->u.batch.cb_arg = NULL;
309 	set->u.batch.outstanding_ops = 0;
310 	set->u.batch.batch_closed = 0;
311 
312 	set->cb_args.cb_fn = spdk_bs_batch_completion;
313 	set->cb_args.cb_arg = set;
314 	set->cb_args.channel = channel->dev_channel;
315 
316 	return (spdk_bs_batch_t *)set;
317 }
318 
319 void
320 spdk_bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
321 			  void *payload, uint64_t lba, uint32_t lba_count)
322 {
323 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
324 	struct spdk_bs_channel		*channel = set->channel;
325 
326 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Reading %u blocks from LBA %lu\n", lba_count, lba);
327 
328 	set->u.batch.outstanding_ops++;
329 	bs_dev->read(bs_dev, channel->dev_channel, payload, lba, lba_count, &set->cb_args);
330 }
331 
332 void
333 spdk_bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload,
334 		       uint64_t lba, uint32_t lba_count)
335 {
336 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
337 	struct spdk_bs_channel		*channel = set->channel;
338 
339 	spdk_bs_batch_read_bs_dev(batch, channel->dev, payload, lba, lba_count);
340 }
341 
342 void
343 spdk_bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload,
344 			uint64_t lba, uint32_t lba_count)
345 {
346 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
347 	struct spdk_bs_channel		*channel = set->channel;
348 
349 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Writing %u blocks to LBA %lu\n", lba_count, lba);
350 
351 	set->u.batch.outstanding_ops++;
352 	channel->dev->write(channel->dev, channel->dev_channel, payload, lba, lba_count,
353 			    &set->cb_args);
354 }
355 
356 void
357 spdk_bs_batch_unmap_dev(spdk_bs_batch_t *batch,
358 			uint64_t lba, uint32_t lba_count)
359 {
360 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
361 	struct spdk_bs_channel		*channel = set->channel;
362 
363 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Unmapping %u blocks at LBA %lu\n", lba_count, lba);
364 
365 	set->u.batch.outstanding_ops++;
366 	channel->dev->unmap(channel->dev, channel->dev_channel, lba, lba_count,
367 			    &set->cb_args);
368 }
369 
370 void
371 spdk_bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch,
372 			       uint64_t lba, uint32_t lba_count)
373 {
374 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
375 	struct spdk_bs_channel		*channel = set->channel;
376 
377 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Zeroing %u blocks at LBA %lu\n", lba_count, lba);
378 
379 	set->u.batch.outstanding_ops++;
380 	channel->dev->write_zeroes(channel->dev, channel->dev_channel, lba, lba_count,
381 				   &set->cb_args);
382 }
383 
384 static void
385 spdk_bs_batch_blob_op_complete(void *arg, int bserrno)
386 {
387 	/* TODO: spdk_bs_batch_completion does not actually use the channel parameter -
388 	 *  just pass NULL here instead of getting the channel from the set cb_arg.
389 	 */
390 	spdk_bs_batch_completion(NULL, arg, bserrno);
391 }
392 
393 void
394 spdk_bs_batch_read_blob(spdk_bs_batch_t *batch, struct spdk_blob *blob,
395 			void *payload, uint64_t offset, uint64_t length)
396 {
397 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
398 	struct spdk_bs_channel		*channel = set->channel;
399 
400 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Reading %lu pages from offset %lu\n", length, offset);
401 
402 	set->u.batch.outstanding_ops++;
403 	spdk_bs_io_read_blob(blob, spdk_io_channel_from_ctx(channel), payload, offset,
404 			     length, spdk_bs_batch_blob_op_complete, set);
405 }
406 
407 void
408 spdk_bs_batch_write_blob(spdk_bs_batch_t *batch, struct spdk_blob *blob,
409 			 void *payload, uint64_t offset, uint64_t length)
410 {
411 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
412 	struct spdk_bs_channel		*channel = set->channel;
413 
414 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Writing %lu pages from offset %lu\n", length, offset);
415 
416 	set->u.batch.outstanding_ops++;
417 	spdk_bs_io_write_blob(blob, spdk_io_channel_from_ctx(channel), payload, offset,
418 			      length, spdk_bs_batch_blob_op_complete, set);
419 }
420 
421 void
422 spdk_bs_batch_unmap_blob(spdk_bs_batch_t *batch, struct spdk_blob *blob,
423 			 uint64_t offset, uint64_t length)
424 {
425 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
426 	struct spdk_bs_channel		*channel = set->channel;
427 
428 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Unmapping %lu pages from offset %lu\n", length, offset);
429 
430 	set->u.batch.outstanding_ops++;
431 	spdk_bs_io_unmap_blob(blob, spdk_io_channel_from_ctx(channel), offset, length,
432 			      spdk_bs_batch_blob_op_complete, set);
433 }
434 
435 void
436 spdk_bs_batch_write_zeroes_blob(spdk_bs_batch_t *batch, struct spdk_blob *blob,
437 				uint64_t offset, uint64_t length)
438 {
439 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
440 	struct spdk_bs_channel		*channel = set->channel;
441 
442 	SPDK_DEBUGLOG(SPDK_LOG_BLOB_RW, "Zeroing %lu pages from offset %lu\n", length, offset);
443 
444 	set->u.batch.outstanding_ops++;
445 	spdk_bs_io_write_zeroes_blob(blob, spdk_io_channel_from_ctx(channel), offset, length,
446 				     spdk_bs_batch_blob_op_complete, set);
447 }
448 
449 void
450 spdk_bs_batch_set_errno(spdk_bs_batch_t *batch, int bserrno)
451 {
452 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
453 
454 	set->bserrno = bserrno;
455 }
456 
457 void
458 spdk_bs_batch_close(spdk_bs_batch_t *batch)
459 {
460 	struct spdk_bs_request_set	*set = (struct spdk_bs_request_set *)batch;
461 
462 	set->u.batch.batch_closed = 1;
463 
464 	if (set->u.batch.outstanding_ops == 0) {
465 		if (set->u.batch.cb_fn) {
466 			set->cb_args.cb_fn = spdk_bs_sequence_completion;
467 			set->u.batch.cb_fn((spdk_bs_sequence_t *)set, set->u.batch.cb_arg, set->bserrno);
468 		} else {
469 			spdk_bs_request_set_complete(set);
470 		}
471 	}
472 }
473 
474 spdk_bs_batch_t *
475 spdk_bs_sequence_to_batch(spdk_bs_sequence_t *seq, spdk_bs_sequence_cpl cb_fn, void *cb_arg)
476 {
477 	struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)seq;
478 
479 	set->u.batch.cb_fn = cb_fn;
480 	set->u.batch.cb_arg = cb_arg;
481 	set->u.batch.outstanding_ops = 0;
482 	set->u.batch.batch_closed = 0;
483 
484 	set->cb_args.cb_fn = spdk_bs_batch_completion;
485 
486 	return set;
487 }
488 
489 spdk_bs_sequence_t *
490 spdk_bs_batch_to_sequence(spdk_bs_batch_t *batch)
491 {
492 	struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)batch;
493 
494 	set->u.batch.outstanding_ops++;
495 
496 	set->cpl.type = SPDK_BS_CPL_TYPE_BLOB_BASIC;
497 	set->cpl.u.blob_basic.cb_fn = spdk_bs_sequence_to_batch_completion;
498 	set->cpl.u.blob_basic.cb_arg = set;
499 	set->bserrno = 0;
500 
501 	set->cb_args.cb_fn = spdk_bs_sequence_completion;
502 	set->cb_args.cb_arg = set;
503 	set->cb_args.channel = set->channel->dev_channel;
504 
505 	return (spdk_bs_sequence_t *)set;
506 }
507 
508 spdk_bs_user_op_t *
509 spdk_bs_user_op_alloc(struct spdk_io_channel *_channel, struct spdk_bs_cpl *cpl,
510 		      enum spdk_blob_op_type op_type, struct spdk_blob *blob,
511 		      void *payload, int iovcnt, uint64_t offset, uint64_t length)
512 {
513 	struct spdk_bs_channel		*channel;
514 	struct spdk_bs_request_set	*set;
515 	struct spdk_bs_user_op_args	*args;
516 
517 	channel = spdk_io_channel_get_ctx(_channel);
518 
519 	set = TAILQ_FIRST(&channel->reqs);
520 	if (!set) {
521 		return NULL;
522 	}
523 	TAILQ_REMOVE(&channel->reqs, set, link);
524 
525 	set->cpl = *cpl;
526 	set->channel = channel;
527 
528 	args = &set->u.user_op;
529 
530 	args->type = op_type;
531 	args->iovcnt = iovcnt;
532 	args->blob = blob;
533 	args->offset = offset;
534 	args->length = length;
535 	args->payload = payload;
536 
537 	return (spdk_bs_user_op_t *)set;
538 }
539 
540 void
541 spdk_bs_user_op_execute(spdk_bs_user_op_t *op)
542 {
543 	struct spdk_bs_request_set	*set;
544 	struct spdk_bs_user_op_args	*args;
545 	struct spdk_io_channel		*ch;
546 
547 	set = (struct spdk_bs_request_set *)op;
548 	args = &set->u.user_op;
549 	ch = spdk_io_channel_from_ctx(set->channel);
550 
551 	switch (args->type) {
552 	case SPDK_BLOB_READ:
553 		spdk_bs_io_read_blob(args->blob, ch, args->payload, args->offset, args->length,
554 				     set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
555 		break;
556 	case SPDK_BLOB_WRITE:
557 		spdk_bs_io_write_blob(args->blob, ch, args->payload, args->offset, args->length,
558 				      set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
559 		break;
560 	case SPDK_BLOB_UNMAP:
561 		spdk_bs_io_unmap_blob(args->blob, ch, args->offset, args->length,
562 				      set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
563 		break;
564 	case SPDK_BLOB_WRITE_ZEROES:
565 		spdk_bs_io_write_zeroes_blob(args->blob, ch, args->offset, args->length,
566 					     set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
567 		break;
568 	case SPDK_BLOB_READV:
569 		spdk_bs_io_readv_blob(args->blob, ch, args->payload, args->iovcnt,
570 				      args->offset, args->length,
571 				      set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
572 		break;
573 	case SPDK_BLOB_WRITEV:
574 		spdk_bs_io_writev_blob(args->blob, ch, args->payload, args->iovcnt,
575 				       args->offset, args->length,
576 				       set->cpl.u.blob_basic.cb_fn, set->cpl.u.blob_basic.cb_arg);
577 		break;
578 	}
579 	TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
580 }
581 
582 void
583 spdk_bs_user_op_abort(spdk_bs_user_op_t *op)
584 {
585 	struct spdk_bs_request_set	*set;
586 
587 	set = (struct spdk_bs_request_set *)op;
588 
589 	set->cpl.u.blob_basic.cb_fn(set->cpl.u.blob_basic.cb_arg, -EIO);
590 	TAILQ_INSERT_TAIL(&set->channel->reqs, set, link);
591 }
592 
593 void
594 spdk_bs_sequence_to_batch_completion(void *cb_arg, int bserrno)
595 {
596 	struct spdk_bs_request_set *set = (struct spdk_bs_request_set *)cb_arg;
597 
598 	set->u.batch.outstanding_ops--;
599 
600 	if (set->u.batch.outstanding_ops == 0 && set->u.batch.batch_closed) {
601 		if (set->cb_args.cb_fn) {
602 			set->cb_args.cb_fn(set->cb_args.channel, set->cb_args.cb_arg, bserrno);
603 		}
604 	}
605 }
606 
607 SPDK_LOG_REGISTER_COMPONENT("blob_rw", SPDK_LOG_BLOB_RW)
608