ftl: ftl_rq helpers for compaction

Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Signed-off-by: Kozlowski Mateusz <mateusz.kozlowski@intel.com>
Change-Id: I614b29e7bc7f6db20b10395bc780ff633c497b59
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13336
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Artur Paszkiewicz 2022-06-14 10:19:37 +02:00 committed by Ben Walker
parent 31cf633679
commit 1dadcd8786
3 changed files with 115 additions and 1 deletions

View File

@ -22,7 +22,7 @@ CFLAGS += -I.
FTL_SUBDIRS := mngt utils FTL_SUBDIRS := mngt utils
C_SRCS = ftl_core.c ftl_init.c ftl_layout.c ftl_debug.c ftl_io.c ftl_sb.c ftl_l2p.c ftl_l2p_flat.c C_SRCS = ftl_core.c ftl_init.c ftl_layout.c ftl_debug.c ftl_io.c ftl_sb.c ftl_l2p.c ftl_l2p_flat.c
C_SRCS += ftl_nv_cache.c ftl_band.c ftl_band_ops.c ftl_writer.c C_SRCS += ftl_nv_cache.c ftl_band.c ftl_band_ops.c ftl_writer.c ftl_rq.c
C_SRCS += mngt/ftl_mngt.c mngt/ftl_mngt_bdev.c mngt/ftl_mngt_shutdown.c mngt/ftl_mngt_startup.c C_SRCS += mngt/ftl_mngt.c mngt/ftl_mngt_bdev.c mngt/ftl_mngt_shutdown.c mngt/ftl_mngt_startup.c
C_SRCS += mngt/ftl_mngt_md.c mngt/ftl_mngt_misc.c mngt/ftl_mngt_ioch.c mngt/ftl_mngt_l2p.c C_SRCS += mngt/ftl_mngt_md.c mngt/ftl_mngt_misc.c mngt/ftl_mngt_ioch.c mngt/ftl_mngt_l2p.c
C_SRCS += mngt/ftl_mngt_band.c C_SRCS += mngt/ftl_mngt_band.c

View File

@ -299,6 +299,9 @@ int ftl_io_init(struct spdk_io_channel *ioch, struct ftl_io *io, uint64_t lba,
size_t num_blocks, struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn, size_t num_blocks, struct iovec *iov, size_t iov_cnt, spdk_ftl_fn cb_fn,
void *cb_arg, int type); void *cb_arg, int type);
void ftl_io_complete(struct ftl_io *io); void ftl_io_complete(struct ftl_io *io);
void ftl_rq_del(struct ftl_rq *rq);
struct ftl_rq *ftl_rq_new(struct spdk_ftl_dev *dev, uint32_t io_md_size);
void ftl_rq_unpin(struct ftl_rq *rq);
static inline void static inline void
ftl_basic_rq_init(struct spdk_ftl_dev *dev, struct ftl_basic_rq *brq, ftl_basic_rq_init(struct spdk_ftl_dev *dev, struct ftl_basic_rq *brq,

111
lib/ftl/ftl_rq.c Normal file
View File

@ -0,0 +1,111 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk/ftl.h"
#include "spdk/env.h"
#include "ftl_io.h"
#include "ftl_core.h"
struct ftl_rq *
ftl_rq_new(struct spdk_ftl_dev *dev, uint32_t io_md_size)
{
struct ftl_rq *rq;
struct ftl_rq_entry *entry;
struct iovec *io_vec;
void *io_payload, *io_md = NULL;
uint64_t i;
size_t size;
uint32_t num_blocks = dev->xfer_size;
size = sizeof(*rq) + (sizeof(rq->entries[0]) * num_blocks);
rq = calloc(1, size);
if (!rq) {
return NULL;
}
rq->dev = dev;
rq->num_blocks = num_blocks;
/* Allocate payload for IO and IO vector */
io_payload = rq->io_payload = spdk_zmalloc(FTL_BLOCK_SIZE * num_blocks,
FTL_BLOCK_SIZE, NULL, SPDK_ENV_LCORE_ID_ANY,
SPDK_MALLOC_DMA);
if (!io_payload) {
goto error;
}
rq->io_vec = calloc(num_blocks, sizeof(rq->io_vec[0]));
if (!rq->io_vec) {
goto error;
}
rq->io_vec_size = num_blocks;
/* Allocate extended metadata for IO */
if (io_md_size) {
rq->io_md_size = io_md_size;
io_md = rq->io_md = spdk_zmalloc(io_md_size * num_blocks,
FTL_BLOCK_SIZE, NULL,
SPDK_ENV_LCORE_ID_ANY,
SPDK_MALLOC_DMA);
if (!io_md) {
goto error;
}
}
entry = rq->entries;
io_vec = rq->io_vec;
for (i = 0; i < num_blocks; ++i) {
uint64_t *index = (uint64_t *)&entry->index;
*index = i;
entry->addr = FTL_ADDR_INVALID;
entry->lba = FTL_LBA_INVALID;
entry->io_payload = io_payload;
if (io_md_size) {
entry->io_md = io_md;
}
io_vec->iov_base = io_payload;
io_vec->iov_len = FTL_BLOCK_SIZE;
entry++;
io_vec++;
io_payload += FTL_BLOCK_SIZE;
io_md += io_md_size;
}
return rq;
error:
ftl_rq_del(rq);
return NULL;
}
void
ftl_rq_del(struct ftl_rq *rq)
{
if (!rq) {
return;
}
spdk_free(rq->io_payload);
spdk_free(rq->io_md);
free(rq->io_vec);
free(rq);
}
void
ftl_rq_unpin(struct ftl_rq *rq)
{
struct ftl_l2p_pin_ctx *pin_ctx;
uint64_t i;
for (i = 0; i < rq->iter.count; i++) {
pin_ctx = &rq->entries[i].l2p_pin_ctx;
if (pin_ctx->lba != FTL_LBA_INVALID) {
ftl_l2p_unpin(rq->dev, pin_ctx->lba, pin_ctx->count);
}
}
}