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 #ifndef SPDK_BS_REQUEST_H 35 #define SPDK_BS_REQUEST_H 36 37 #include "spdk/stdinc.h" 38 39 #include "spdk/blob.h" 40 41 enum spdk_bs_cpl_type { 42 SPDK_BS_CPL_TYPE_BS_BASIC, 43 SPDK_BS_CPL_TYPE_BS_HANDLE, 44 SPDK_BS_CPL_TYPE_BLOB_BASIC, 45 SPDK_BS_CPL_TYPE_BLOBID, 46 SPDK_BS_CPL_TYPE_BLOB_HANDLE, 47 SPDK_BS_CPL_TYPE_NESTED_SEQUENCE, 48 }; 49 50 struct spdk_bs_request_set; 51 52 /* Use a sequence to submit a set of requests serially */ 53 typedef struct spdk_bs_request_set spdk_bs_sequence_t; 54 55 /* Use a batch to submit a set of requests in parallel */ 56 typedef struct spdk_bs_request_set spdk_bs_batch_t; 57 58 typedef void (*spdk_bs_nested_seq_complete)(void *cb_arg, spdk_bs_sequence_t *parent, int bserrno); 59 60 struct spdk_bs_cpl { 61 enum spdk_bs_cpl_type type; 62 union { 63 struct { 64 spdk_bs_op_complete cb_fn; 65 void *cb_arg; 66 } bs_basic; 67 68 struct { 69 spdk_bs_op_with_handle_complete cb_fn; 70 void *cb_arg; 71 struct spdk_blob_store *bs; 72 } bs_handle; 73 74 struct { 75 spdk_blob_op_complete cb_fn; 76 void *cb_arg; 77 } blob_basic; 78 79 struct { 80 spdk_blob_op_with_id_complete cb_fn; 81 void *cb_arg; 82 spdk_blob_id blobid; 83 } blobid; 84 85 struct { 86 spdk_blob_op_with_handle_complete cb_fn; 87 void *cb_arg; 88 struct spdk_blob *blob; 89 } blob_handle; 90 91 struct { 92 spdk_bs_nested_seq_complete cb_fn; 93 void *cb_arg; 94 spdk_bs_sequence_t *parent; 95 } nested_seq; 96 } u; 97 }; 98 99 typedef void (*spdk_bs_sequence_cpl)(spdk_bs_sequence_t *sequence, 100 void *cb_arg, int bserrno); 101 102 /* A generic request set. Can be a sequence or a batch. */ 103 struct spdk_bs_request_set { 104 struct spdk_bs_cpl cpl; 105 106 int bserrno; 107 108 struct spdk_bs_channel *channel; 109 110 struct spdk_bs_dev_cb_args cb_args; 111 112 union { 113 struct { 114 spdk_bs_sequence_cpl cb_fn; 115 void *cb_arg; 116 } sequence; 117 118 struct { 119 uint32_t outstanding_ops; 120 uint32_t batch_closed; 121 spdk_bs_sequence_cpl cb_fn; 122 void *cb_arg; 123 } batch; 124 } u; 125 126 TAILQ_ENTRY(spdk_bs_request_set) link; 127 }; 128 129 void spdk_bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno); 130 131 spdk_bs_sequence_t *spdk_bs_sequence_start(struct spdk_io_channel *channel, 132 struct spdk_bs_cpl *cpl); 133 134 void spdk_bs_sequence_read(spdk_bs_sequence_t *seq, void *payload, 135 uint64_t lba, uint32_t lba_count, 136 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 137 138 void spdk_bs_sequence_write(spdk_bs_sequence_t *seq, void *payload, 139 uint64_t lba, uint32_t lba_count, 140 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 141 142 void spdk_bs_sequence_readv(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt, 143 uint64_t lba, uint32_t lba_count, 144 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 145 146 void spdk_bs_sequence_writev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt, 147 uint64_t lba, uint32_t lba_count, 148 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 149 150 void spdk_bs_sequence_flush(spdk_bs_sequence_t *seq, 151 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 152 153 void spdk_bs_sequence_unmap(spdk_bs_sequence_t *seq, 154 uint64_t lba, uint32_t lba_count, 155 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 156 157 void spdk_bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno); 158 159 spdk_bs_batch_t *spdk_bs_batch_open(struct spdk_io_channel *channel, 160 struct spdk_bs_cpl *cpl); 161 162 void spdk_bs_batch_read(spdk_bs_batch_t *batch, void *payload, 163 uint64_t lba, uint32_t lba_count); 164 165 void spdk_bs_batch_write(spdk_bs_batch_t *batch, void *payload, 166 uint64_t lba, uint32_t lba_count); 167 168 void spdk_bs_batch_flush(spdk_bs_batch_t *batch); 169 170 void spdk_bs_batch_unmap(spdk_bs_batch_t *batch, 171 uint64_t lba, uint32_t lba_count); 172 173 void spdk_bs_batch_close(spdk_bs_batch_t *batch); 174 175 spdk_bs_batch_t *spdk_bs_sequence_to_batch(spdk_bs_sequence_t *seq, 176 spdk_bs_sequence_cpl cb_fn, 177 void *cb_arg); 178 179 #endif 180