xref: /spdk/lib/blob/request.h (revision b30d57cdad6d2bc75cc1e4e2ebbcebcb0d98dcfa)
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 enum spdk_blob_op_type;
52 
53 struct spdk_bs_request_set;
54 
55 /* Use a sequence to submit a set of requests serially */
56 typedef struct spdk_bs_request_set spdk_bs_sequence_t;
57 
58 /* Use a batch to submit a set of requests in parallel */
59 typedef struct spdk_bs_request_set spdk_bs_batch_t;
60 
61 /* Use a user_op to queue a user operation for later execution */
62 typedef struct spdk_bs_request_set spdk_bs_user_op_t;
63 
64 typedef void (*spdk_bs_nested_seq_complete)(void *cb_arg, spdk_bs_sequence_t *parent, int bserrno);
65 
66 struct spdk_bs_cpl {
67 	enum spdk_bs_cpl_type type;
68 	union {
69 		struct {
70 			spdk_bs_op_complete     cb_fn;
71 			void                    *cb_arg;
72 		} bs_basic;
73 
74 		struct {
75 			spdk_bs_op_with_handle_complete cb_fn;
76 			void                            *cb_arg;
77 			struct spdk_blob_store          *bs;
78 		} bs_handle;
79 
80 		struct {
81 			spdk_blob_op_complete   cb_fn;
82 			void                    *cb_arg;
83 		} blob_basic;
84 
85 		struct {
86 			spdk_blob_op_with_id_complete   cb_fn;
87 			void                            *cb_arg;
88 			spdk_blob_id                     blobid;
89 		} blobid;
90 
91 		struct {
92 			spdk_blob_op_with_handle_complete       cb_fn;
93 			void                                    *cb_arg;
94 			struct spdk_blob                        *blob;
95 		} blob_handle;
96 
97 		struct {
98 			spdk_bs_nested_seq_complete	cb_fn;
99 			void				*cb_arg;
100 			spdk_bs_sequence_t		*parent;
101 		} nested_seq;
102 	} u;
103 };
104 
105 typedef void (*spdk_bs_sequence_cpl)(spdk_bs_sequence_t *sequence,
106 				     void *cb_arg, int bserrno);
107 
108 /* A generic request set. Can be a sequence, batch or a user_op. */
109 struct spdk_bs_request_set {
110 	struct spdk_bs_cpl      cpl;
111 
112 	int                     bserrno;
113 
114 	struct spdk_bs_channel		*channel;
115 
116 	struct spdk_bs_dev_cb_args	cb_args;
117 
118 	union {
119 		struct {
120 			spdk_bs_sequence_cpl    cb_fn;
121 			void                    *cb_arg;
122 		} sequence;
123 
124 		struct {
125 			uint32_t		outstanding_ops;
126 			uint32_t		batch_closed;
127 			spdk_bs_sequence_cpl	cb_fn;
128 			void			*cb_arg;
129 		} batch;
130 
131 		struct spdk_bs_user_op_args {
132 			int			type;
133 			int			iovcnt;
134 			struct spdk_blob	*blob;
135 			uint64_t		offset;
136 			uint64_t		length;
137 			spdk_blob_op_complete	cb_fn;
138 			void			*cb_arg;
139 			void			*payload; /* cast to iov for readv/writev */
140 		} user_op;
141 	} u;
142 
143 	TAILQ_ENTRY(spdk_bs_request_set) link;
144 };
145 
146 void bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno);
147 
148 spdk_bs_sequence_t *bs_sequence_start(struct spdk_io_channel *channel,
149 				      struct spdk_bs_cpl *cpl);
150 
151 void bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
152 			     void *payload, uint64_t lba, uint32_t lba_count,
153 			     spdk_bs_sequence_cpl cb_fn, void *cb_arg);
154 
155 void bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload,
156 			  uint64_t lba, uint32_t lba_count,
157 			  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
158 
159 void bs_sequence_write_dev(spdk_bs_sequence_t *seq, void *payload,
160 			   uint64_t lba, uint32_t lba_count,
161 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
162 
163 void bs_sequence_readv_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
164 			      struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
165 			      spdk_bs_sequence_cpl cb_fn, void *cb_arg);
166 
167 void bs_sequence_readv_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
168 			   uint64_t lba, uint32_t lba_count,
169 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
170 
171 void bs_sequence_writev_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
172 			    uint64_t lba, uint32_t lba_count,
173 			    spdk_bs_sequence_cpl cb_fn, void *cb_arg);
174 
175 void bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq,
176 				  uint64_t lba, uint32_t lba_count,
177 				  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
178 
179 void bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno);
180 
181 void bs_user_op_sequence_finish(void *cb_arg, int bserrno);
182 
183 spdk_bs_batch_t *bs_batch_open(struct spdk_io_channel *channel,
184 			       struct spdk_bs_cpl *cpl);
185 
186 void bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
187 			  void *payload, uint64_t lba, uint32_t lba_count);
188 
189 void bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload,
190 		       uint64_t lba, uint32_t lba_count);
191 
192 void bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload,
193 			uint64_t lba, uint32_t lba_count);
194 
195 void bs_batch_unmap_dev(spdk_bs_batch_t *batch,
196 			uint64_t lba, uint32_t lba_count);
197 
198 void bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch,
199 			       uint64_t lba, uint32_t lba_count);
200 
201 void bs_batch_close(spdk_bs_batch_t *batch);
202 
203 spdk_bs_batch_t *bs_sequence_to_batch(spdk_bs_sequence_t *seq,
204 				      spdk_bs_sequence_cpl cb_fn,
205 				      void *cb_arg);
206 
207 spdk_bs_user_op_t *bs_user_op_alloc(struct spdk_io_channel *channel, struct spdk_bs_cpl *cpl,
208 				    enum spdk_blob_op_type op_type, struct spdk_blob *blob,
209 				    void *payload, int iovcnt, uint64_t offset, uint64_t length);
210 
211 void bs_user_op_execute(spdk_bs_user_op_t *op);
212 
213 void bs_user_op_abort(spdk_bs_user_op_t *op);
214 
215 void bs_sequence_to_batch_completion(void *cb_arg, int bserrno);
216 
217 #endif
218