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