1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef SPDK_BS_REQUEST_H 36 #define SPDK_BS_REQUEST_H 37 38 #include "spdk/stdinc.h" 39 40 #include "spdk/blob.h" 41 42 enum spdk_bs_cpl_type { 43 SPDK_BS_CPL_TYPE_NONE, 44 SPDK_BS_CPL_TYPE_BS_BASIC, 45 SPDK_BS_CPL_TYPE_BS_HANDLE, 46 SPDK_BS_CPL_TYPE_BLOB_BASIC, 47 SPDK_BS_CPL_TYPE_BLOBID, 48 SPDK_BS_CPL_TYPE_BLOB_HANDLE, 49 SPDK_BS_CPL_TYPE_NESTED_SEQUENCE, 50 }; 51 52 enum spdk_blob_op_type; 53 54 struct spdk_bs_request_set; 55 56 /* Use a sequence to submit a set of requests serially */ 57 typedef struct spdk_bs_request_set spdk_bs_sequence_t; 58 59 /* Use a batch to submit a set of requests in parallel */ 60 typedef struct spdk_bs_request_set spdk_bs_batch_t; 61 62 /* Use a user_op to queue a user operation for later execution */ 63 typedef struct spdk_bs_request_set spdk_bs_user_op_t; 64 65 typedef void (*spdk_bs_nested_seq_complete)(void *cb_arg, spdk_bs_sequence_t *parent, int bserrno); 66 67 struct spdk_bs_cpl { 68 enum spdk_bs_cpl_type type; 69 union { 70 struct { 71 spdk_bs_op_complete cb_fn; 72 void *cb_arg; 73 } bs_basic; 74 75 struct { 76 spdk_bs_op_with_handle_complete cb_fn; 77 void *cb_arg; 78 struct spdk_blob_store *bs; 79 } bs_handle; 80 81 struct { 82 spdk_blob_op_complete cb_fn; 83 void *cb_arg; 84 } blob_basic; 85 86 struct { 87 spdk_blob_op_with_id_complete cb_fn; 88 void *cb_arg; 89 spdk_blob_id blobid; 90 } blobid; 91 92 struct { 93 spdk_blob_op_with_handle_complete cb_fn; 94 void *cb_arg; 95 struct spdk_blob *blob; 96 } blob_handle; 97 98 struct { 99 spdk_bs_nested_seq_complete cb_fn; 100 void *cb_arg; 101 spdk_bs_sequence_t *parent; 102 } nested_seq; 103 } u; 104 }; 105 106 typedef void (*spdk_bs_sequence_cpl)(spdk_bs_sequence_t *sequence, 107 void *cb_arg, int bserrno); 108 109 /* A generic request set. Can be a sequence, batch or a user_op. */ 110 struct spdk_bs_request_set { 111 struct spdk_bs_cpl cpl; 112 113 int bserrno; 114 115 struct spdk_bs_channel *channel; 116 117 struct spdk_bs_dev_cb_args cb_args; 118 119 union { 120 struct { 121 spdk_bs_sequence_cpl cb_fn; 122 void *cb_arg; 123 } sequence; 124 125 struct { 126 uint32_t outstanding_ops; 127 uint32_t batch_closed; 128 spdk_bs_sequence_cpl cb_fn; 129 void *cb_arg; 130 } batch; 131 132 struct spdk_bs_user_op_args { 133 int type; 134 int iovcnt; 135 struct spdk_blob *blob; 136 uint64_t offset; 137 uint64_t length; 138 spdk_blob_op_complete cb_fn; 139 void *cb_arg; 140 void *payload; /* cast to iov for readv/writev */ 141 } user_op; 142 } u; 143 /* Pointer to ext_io_opts passed by the user */ 144 struct spdk_blob_ext_io_opts *ext_io_opts; 145 TAILQ_ENTRY(spdk_bs_request_set) link; 146 }; 147 148 void bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno); 149 150 spdk_bs_sequence_t *bs_sequence_start(struct spdk_io_channel *channel, 151 struct spdk_bs_cpl *cpl); 152 153 void bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev, 154 void *payload, uint64_t lba, uint32_t lba_count, 155 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 156 157 void bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload, 158 uint64_t lba, uint32_t lba_count, 159 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 160 161 void bs_sequence_write_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 void bs_sequence_readv_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev, 166 struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count, 167 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 168 169 void bs_sequence_readv_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt, 170 uint64_t lba, uint32_t lba_count, 171 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 172 173 void bs_sequence_writev_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt, 174 uint64_t lba, uint32_t lba_count, 175 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 176 177 void bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq, 178 uint64_t lba, uint64_t lba_count, 179 spdk_bs_sequence_cpl cb_fn, void *cb_arg); 180 181 void bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno); 182 183 void bs_user_op_sequence_finish(void *cb_arg, int bserrno); 184 185 spdk_bs_batch_t *bs_batch_open(struct spdk_io_channel *channel, 186 struct spdk_bs_cpl *cpl); 187 188 void bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev, 189 void *payload, uint64_t lba, uint32_t lba_count); 190 191 void bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload, 192 uint64_t lba, uint32_t lba_count); 193 194 void bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload, 195 uint64_t lba, uint32_t lba_count); 196 197 void bs_batch_unmap_dev(spdk_bs_batch_t *batch, 198 uint64_t lba, uint64_t lba_count); 199 200 void bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch, 201 uint64_t lba, uint64_t lba_count); 202 203 void bs_batch_close(spdk_bs_batch_t *batch); 204 205 spdk_bs_batch_t *bs_sequence_to_batch(spdk_bs_sequence_t *seq, 206 spdk_bs_sequence_cpl cb_fn, 207 void *cb_arg); 208 209 spdk_bs_user_op_t *bs_user_op_alloc(struct spdk_io_channel *channel, struct spdk_bs_cpl *cpl, 210 enum spdk_blob_op_type op_type, struct spdk_blob *blob, 211 void *payload, int iovcnt, uint64_t offset, uint64_t length); 212 213 void bs_user_op_execute(spdk_bs_user_op_t *op); 214 215 void bs_user_op_abort(spdk_bs_user_op_t *op, int bserrno); 216 217 #endif 218