xref: /spdk/lib/blob/request.h (revision 2948183f2b9cf0d51ef85c32456444c76b6d7788)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  *   Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5  */
6 
7 #ifndef SPDK_BS_REQUEST_H
8 #define SPDK_BS_REQUEST_H
9 
10 #include "spdk/stdinc.h"
11 
12 #include "spdk/blob.h"
13 
14 enum spdk_bs_cpl_type {
15 	SPDK_BS_CPL_TYPE_NONE,
16 	SPDK_BS_CPL_TYPE_BS_BASIC,
17 	SPDK_BS_CPL_TYPE_BS_HANDLE,
18 	SPDK_BS_CPL_TYPE_BLOB_BASIC,
19 	SPDK_BS_CPL_TYPE_BLOBID,
20 	SPDK_BS_CPL_TYPE_BLOB_HANDLE,
21 	SPDK_BS_CPL_TYPE_NESTED_SEQUENCE,
22 };
23 
24 enum spdk_blob_op_type;
25 
26 struct spdk_bs_request_set;
27 
28 /* Use a sequence to submit a set of requests serially */
29 typedef struct spdk_bs_request_set spdk_bs_sequence_t;
30 
31 /* Use a batch to submit a set of requests in parallel */
32 typedef struct spdk_bs_request_set spdk_bs_batch_t;
33 
34 /* Use a user_op to queue a user operation for later execution */
35 typedef struct spdk_bs_request_set spdk_bs_user_op_t;
36 
37 typedef void (*spdk_bs_nested_seq_complete)(void *cb_arg, spdk_bs_sequence_t *parent, int bserrno);
38 
39 struct spdk_bs_cpl {
40 	enum spdk_bs_cpl_type type;
41 	union {
42 		struct {
43 			spdk_bs_op_complete     cb_fn;
44 			void                    *cb_arg;
45 		} bs_basic;
46 
47 		struct {
48 			spdk_bs_op_with_handle_complete cb_fn;
49 			void                            *cb_arg;
50 			struct spdk_blob_store          *bs;
51 		} bs_handle;
52 
53 		struct {
54 			spdk_blob_op_complete   cb_fn;
55 			void                    *cb_arg;
56 		} blob_basic;
57 
58 		struct {
59 			spdk_blob_op_with_id_complete   cb_fn;
60 			void                            *cb_arg;
61 			spdk_blob_id                     blobid;
62 		} blobid;
63 
64 		struct {
65 			spdk_blob_op_with_handle_complete       cb_fn;
66 			void                                    *cb_arg;
67 			struct spdk_blob                        *blob;
68 			void					*esnap_ctx;
69 		} blob_handle;
70 
71 		struct {
72 			spdk_bs_nested_seq_complete	cb_fn;
73 			void				*cb_arg;
74 			spdk_bs_sequence_t		*parent;
75 		} nested_seq;
76 	} u;
77 };
78 
79 typedef void (*spdk_bs_sequence_cpl)(spdk_bs_sequence_t *sequence,
80 				     void *cb_arg, int bserrno);
81 
82 /* A generic request set. Can be a sequence, batch or a user_op. */
83 struct spdk_bs_request_set {
84 	struct spdk_bs_cpl      cpl;
85 
86 	int                     bserrno;
87 
88 	/*
89 	 * The blobstore's channel, obtained by blobstore consumers via
90 	 * spdk_bs_alloc_io_channel(). Used for IO to the blobstore.
91 	 */
92 	struct spdk_bs_channel		*channel;
93 	/*
94 	 * The channel used by the blobstore to perform IO on back_bs_dev.
95 	 * For now, back_channel == spdk_io_channel_get_ctx(set->channel).
96 	 */
97 	struct spdk_io_channel		*back_channel;
98 
99 	struct spdk_bs_dev_cb_args	cb_args;
100 
101 	union {
102 		struct {
103 			spdk_bs_sequence_cpl    cb_fn;
104 			void                    *cb_arg;
105 		} sequence;
106 
107 		struct {
108 			uint32_t		outstanding_ops;
109 			uint32_t		batch_closed;
110 			spdk_bs_sequence_cpl	cb_fn;
111 			void			*cb_arg;
112 		} batch;
113 
114 		struct spdk_bs_user_op_args {
115 			int			type;
116 			int			iovcnt;
117 			struct spdk_blob	*blob;
118 			uint64_t		offset;
119 			uint64_t		length;
120 			spdk_blob_op_complete	cb_fn;
121 			void			*cb_arg;
122 			void			*payload; /* cast to iov for readv/writev */
123 		} user_op;
124 	} u;
125 	/* Pointer to ext_io_opts passed by the user */
126 	struct spdk_blob_ext_io_opts *ext_io_opts;
127 	TAILQ_ENTRY(spdk_bs_request_set) link;
128 };
129 
130 void bs_call_cpl(struct spdk_bs_cpl *cpl, int bserrno);
131 
132 spdk_bs_sequence_t *bs_sequence_start_bs(struct spdk_io_channel *channel,
133 		struct spdk_bs_cpl *cpl);
134 
135 spdk_bs_sequence_t *bs_sequence_start_blob(struct spdk_io_channel *channel,
136 		struct spdk_bs_cpl *cpl, struct spdk_blob *blob);
137 
138 void bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
139 			     void *payload, uint64_t lba, uint32_t lba_count,
140 			     spdk_bs_sequence_cpl cb_fn, void *cb_arg);
141 
142 void bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload,
143 			  uint64_t lba, uint32_t lba_count,
144 			  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
145 
146 void bs_sequence_write_dev(spdk_bs_sequence_t *seq, void *payload,
147 			   uint64_t lba, uint32_t lba_count,
148 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
149 
150 void bs_sequence_readv_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
151 			      struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
152 			      spdk_bs_sequence_cpl cb_fn, void *cb_arg);
153 
154 void bs_sequence_readv_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
155 			   uint64_t lba, uint32_t lba_count,
156 			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
157 
158 void bs_sequence_writev_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
159 			    uint64_t lba, uint32_t lba_count,
160 			    spdk_bs_sequence_cpl cb_fn, void *cb_arg);
161 
162 void bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq,
163 				  uint64_t lba, uint64_t lba_count,
164 				  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
165 
166 void bs_sequence_copy_dev(spdk_bs_sequence_t *seq,
167 			  uint64_t dst_lba, uint64_t src_lba, uint64_t lba_count,
168 			  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
169 
170 void bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno);
171 
172 void bs_user_op_sequence_finish(void *cb_arg, int bserrno);
173 
174 spdk_bs_batch_t *bs_batch_open(struct spdk_io_channel *channel,
175 			       struct spdk_bs_cpl *cpl);
176 
177 void bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
178 			  void *payload, uint64_t lba, uint32_t lba_count);
179 
180 void bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload,
181 		       uint64_t lba, uint32_t lba_count);
182 
183 void bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload,
184 			uint64_t lba, uint32_t lba_count);
185 
186 void bs_batch_unmap_dev(spdk_bs_batch_t *batch,
187 			uint64_t lba, uint64_t lba_count);
188 
189 void bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch,
190 			       uint64_t lba, uint64_t lba_count);
191 
192 void bs_batch_close(spdk_bs_batch_t *batch);
193 
194 spdk_bs_batch_t *bs_sequence_to_batch(spdk_bs_sequence_t *seq,
195 				      spdk_bs_sequence_cpl cb_fn,
196 				      void *cb_arg);
197 
198 spdk_bs_user_op_t *bs_user_op_alloc(struct spdk_io_channel *channel, struct spdk_bs_cpl *cpl,
199 				    enum spdk_blob_op_type op_type, struct spdk_blob *blob,
200 				    void *payload, int iovcnt, uint64_t offset, uint64_t length);
201 
202 void bs_user_op_execute(spdk_bs_user_op_t *op);
203 
204 void bs_user_op_abort(spdk_bs_user_op_t *op, int bserrno);
205 
206 #endif
207