]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/lib/ftl/ftl_io.h
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
37 #include "spdk/stdinc.h"
38 #include "spdk/nvme.h"
42 #include "ftl_trace.h"
49 typedef int (*ftl_md_pack_fn
)(struct ftl_band
*);
50 typedef void (*ftl_io_fn
)(struct ftl_io
*, void *, int);
54 /* Indicates whether IO is already initialized */
55 FTL_IO_INITIALIZED
= (1 << 0),
56 /* Internal based IO (defrag, metadata etc.) */
57 FTL_IO_INTERNAL
= (1 << 1),
58 /* Indicates that the IO should not go through if there's */
59 /* already another one scheduled to the same LBA */
60 FTL_IO_WEAK
= (1 << 2),
61 /* Indicates that the IO is used for padding */
62 FTL_IO_PAD
= (1 << 3),
63 /* The IO operates on metadata */
65 /* Using PPA instead of LBA */
66 FTL_IO_PPA_MODE
= (1 << 5),
67 /* Indicates that IO contains noncontiguous LBAs */
68 FTL_IO_VECTOR_LBA
= (1 << 6),
69 /* Indicates that IO is being retried */
70 FTL_IO_RETRY
= (1 << 7),
71 /* The IO is directed to non-volatile cache */
72 FTL_IO_CACHE
= (1 << 8),
73 /* Indicates that PPA should be taken from IO struct, */
74 /* not assigned by wptr, only works if wptr is also in direct mode */
75 FTL_IO_DIRECT_ACCESS
= (1 << 9),
84 struct ftl_io_init_opts
{
85 struct spdk_ftl_dev
*dev
;
91 struct ftl_io
*parent
;
93 /* Size of IO descriptor */
100 enum ftl_io_type type
;
103 struct ftl_rwb_batch
*rwb_batch
;
105 /* Band to which the IO is directed */
106 struct ftl_band
*band
;
108 /* Number of logical blocks */
117 /* Callback's function */
120 /* Callback's context */
124 struct ftl_io_channel
{
126 struct spdk_ftl_dev
*dev
;
127 /* IO pool element size */
130 struct spdk_mempool
*io_pool
;
131 /* Persistent cache IO channel */
132 struct spdk_io_channel
*cache_ioch
;
135 /* General IO descriptor */
138 struct spdk_ftl_dev
*dev
;
141 struct spdk_io_channel
*ioch
;
154 /* Number of processed lbks */
160 #define FTL_IO_MAX_IOVEC 64
161 struct iovec iov
[FTL_IO_MAX_IOVEC
];
166 /* Number of IO vectors */
169 /* Position within the iovec */
172 /* Offset within the iovec (in lbks) */
175 /* RWB entry (valid only for RWB-based IO) */
176 struct ftl_rwb_batch
*rwb_batch
;
178 /* Band this IO is being written to */
179 struct ftl_band
*band
;
184 /* Number of split requests */
187 /* Callback's function */
190 /* Callback's context */
193 /* User callback function */
200 enum ftl_io_type type
;
206 struct ftl_io
*parent
;
207 /* Child requests list */
208 LIST_HEAD(, ftl_io
) children
;
209 /* Child list link */
210 LIST_ENTRY(ftl_io
) child_entry
;
212 pthread_spinlock_t lock
;
217 TAILQ_ENTRY(ftl_io
) retry_entry
;
222 /* Parent IO structure */
225 /* Serialization/deserialization callback */
226 ftl_md_pack_fn pack_fn
;
228 /* Callback's function */
231 /* Callback's context */
236 ftl_io_mode_ppa(const struct ftl_io
*io
)
238 return io
->flags
& FTL_IO_PPA_MODE
;
242 ftl_io_mode_lba(const struct ftl_io
*io
)
244 return !ftl_io_mode_ppa(io
);
248 ftl_io_done(const struct ftl_io
*io
)
250 return io
->req_cnt
== 0 &&
251 io
->pos
== io
->lbk_cnt
&&
252 !(io
->flags
& FTL_IO_RETRY
);
255 struct ftl_io
*ftl_io_alloc(struct spdk_io_channel
*ch
);
256 struct ftl_io
*ftl_io_alloc_child(struct ftl_io
*parent
);
257 void ftl_io_fail(struct ftl_io
*io
, int status
);
258 void ftl_io_free(struct ftl_io
*io
);
259 struct ftl_io
*ftl_io_init_internal(const struct ftl_io_init_opts
*opts
);
260 void ftl_io_reinit(struct ftl_io
*io
, ftl_io_fn cb
,
261 void *ctx
, int flags
, int type
);
262 void ftl_io_clear(struct ftl_io
*io
);
263 void ftl_io_inc_req(struct ftl_io
*io
);
264 void ftl_io_dec_req(struct ftl_io
*io
);
265 struct iovec
*ftl_io_iovec(struct ftl_io
*io
);
266 uint64_t ftl_io_current_lba(const struct ftl_io
*io
);
267 uint64_t ftl_io_get_lba(const struct ftl_io
*io
, size_t offset
);
268 void ftl_io_advance(struct ftl_io
*io
, size_t lbk_cnt
);
269 size_t ftl_iovec_num_lbks(struct iovec
*iov
, size_t iov_cnt
);
270 void *ftl_io_iovec_addr(struct ftl_io
*io
);
271 size_t ftl_io_iovec_len_left(struct ftl_io
*io
);
272 struct ftl_io
*ftl_io_rwb_init(struct spdk_ftl_dev
*dev
, struct ftl_band
*band
,
273 struct ftl_rwb_batch
*entry
, ftl_io_fn cb
);
274 struct ftl_io
*ftl_io_erase_init(struct ftl_band
*band
, size_t lbk_cnt
, ftl_io_fn cb
);
275 struct ftl_io
*ftl_io_user_init(struct spdk_io_channel
*ioch
, uint64_t lba
, size_t lbk_cnt
,
276 struct iovec
*iov
, size_t iov_cnt
, spdk_ftl_fn cb_fn
,
277 void *cb_arg
, int type
);
278 void *ftl_io_get_md(const struct ftl_io
*io
);
279 void ftl_io_complete(struct ftl_io
*io
);
280 void ftl_io_shrink_iovec(struct ftl_io
*io
, size_t lbk_cnt
);
281 void ftl_io_process_error(struct ftl_io
*io
, const struct spdk_nvme_cpl
*status
);
282 void ftl_io_reset(struct ftl_io
*io
);
283 void ftl_io_call_foreach_child(struct ftl_io
*io
, int (*callback
)(struct ftl_io
*));
285 #endif /* FTL_IO_H */