xref: /spdk/lib/blob/request.h (revision b47cee6c96303f16c01318884c2969cf855c49e9)
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. Unless the blob
95  	 * is an esnap clone, 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  spdk_bs_sequence_t *bs_sequence_start_esnap(struct spdk_io_channel *channel,
139  		struct spdk_bs_cpl *cpl, struct spdk_blob *blob);
140  
141  void bs_sequence_read_bs_dev(spdk_bs_sequence_t *seq, struct spdk_bs_dev *bs_dev,
142  			     void *payload, uint64_t lba, uint32_t lba_count,
143  			     spdk_bs_sequence_cpl cb_fn, void *cb_arg);
144  
145  void bs_sequence_read_dev(spdk_bs_sequence_t *seq, void *payload,
146  			  uint64_t lba, uint32_t lba_count,
147  			  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
148  
149  void bs_sequence_write_dev(spdk_bs_sequence_t *seq, void *payload,
150  			   uint64_t lba, uint32_t lba_count,
151  			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
152  
153  void bs_sequence_readv_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
154  			      struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
155  			      spdk_bs_sequence_cpl cb_fn, void *cb_arg);
156  
157  void bs_sequence_readv_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
158  			   uint64_t lba, uint32_t lba_count,
159  			   spdk_bs_sequence_cpl cb_fn, void *cb_arg);
160  
161  void bs_sequence_writev_dev(spdk_bs_batch_t *batch, struct iovec *iov, int iovcnt,
162  			    uint64_t lba, uint32_t lba_count,
163  			    spdk_bs_sequence_cpl cb_fn, void *cb_arg);
164  
165  void bs_sequence_write_zeroes_dev(spdk_bs_sequence_t *seq,
166  				  uint64_t lba, uint64_t lba_count,
167  				  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
168  
169  void bs_sequence_copy_dev(spdk_bs_sequence_t *seq,
170  			  uint64_t dst_lba, uint64_t src_lba, uint64_t lba_count,
171  			  spdk_bs_sequence_cpl cb_fn, void *cb_arg);
172  
173  void bs_sequence_finish(spdk_bs_sequence_t *seq, int bserrno);
174  
175  void bs_user_op_sequence_finish(void *cb_arg, int bserrno);
176  
177  spdk_bs_batch_t *bs_batch_open(struct spdk_io_channel *channel,
178  			       struct spdk_bs_cpl *cpl, struct spdk_blob *blob);
179  
180  void bs_batch_read_bs_dev(spdk_bs_batch_t *batch, struct spdk_bs_dev *bs_dev,
181  			  void *payload, uint64_t lba, uint32_t lba_count);
182  
183  void bs_batch_read_dev(spdk_bs_batch_t *batch, void *payload,
184  		       uint64_t lba, uint32_t lba_count);
185  
186  void bs_batch_write_dev(spdk_bs_batch_t *batch, void *payload,
187  			uint64_t lba, uint32_t lba_count);
188  
189  void bs_batch_unmap_dev(spdk_bs_batch_t *batch,
190  			uint64_t lba, uint64_t lba_count);
191  
192  void bs_batch_write_zeroes_dev(spdk_bs_batch_t *batch,
193  			       uint64_t lba, uint64_t lba_count);
194  
195  void bs_batch_close(spdk_bs_batch_t *batch);
196  
197  spdk_bs_batch_t *bs_sequence_to_batch(spdk_bs_sequence_t *seq,
198  				      spdk_bs_sequence_cpl cb_fn,
199  				      void *cb_arg);
200  
201  spdk_bs_user_op_t *bs_user_op_alloc(struct spdk_io_channel *channel, struct spdk_bs_cpl *cpl,
202  				    enum spdk_blob_op_type op_type, struct spdk_blob *blob,
203  				    void *payload, int iovcnt, uint64_t offset, uint64_t length);
204  
205  void bs_user_op_execute(spdk_bs_user_op_t *op);
206  
207  void bs_user_op_abort(spdk_bs_user_op_t *op, int bserrno);
208  
209  #endif
210