bdev/malloc: malloc IO channel
It'll allow the malloc bdev to store per-thread data. For now, it's only used to keep the pointer to the accel library's IO channel, more fields will be added in subsequent patches. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: I604a38877ae8d6075b911f5a484d1793d4bc2ddb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10802 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
45ded6b8de
commit
fcd5f60144
@ -142,7 +142,6 @@ DEPDIRS-bdev_gpt := bdev json log thread util
|
||||
|
||||
DEPDIRS-bdev_error := $(BDEV_DEPS)
|
||||
DEPDIRS-bdev_lvol := $(BDEV_DEPS) lvol blob blob_bdev
|
||||
DEPDIRS-bdev_malloc := $(BDEV_DEPS) accel
|
||||
DEPDIRS-bdev_rpc := $(BDEV_DEPS)
|
||||
DEPDIRS-bdev_split := $(BDEV_DEPS)
|
||||
|
||||
@ -151,6 +150,7 @@ DEPDIRS-bdev_compress := $(BDEV_DEPS_THREAD) reduce
|
||||
DEPDIRS-bdev_crypto := $(BDEV_DEPS_THREAD)
|
||||
DEPDIRS-bdev_delay := $(BDEV_DEPS_THREAD)
|
||||
DEPDIRS-bdev_iscsi := $(BDEV_DEPS_THREAD)
|
||||
DEPDIRS-bdev_malloc := $(BDEV_DEPS_THREAD) accel
|
||||
DEPDIRS-bdev_null := $(BDEV_DEPS_THREAD)
|
||||
DEPDIRS-bdev_nvme = $(BDEV_DEPS_THREAD) accel nvme
|
||||
DEPDIRS-bdev_ocf := $(BDEV_DEPS_THREAD)
|
||||
|
@ -58,6 +58,10 @@ struct malloc_task {
|
||||
enum spdk_bdev_io_status status;
|
||||
};
|
||||
|
||||
struct malloc_channel {
|
||||
struct spdk_io_channel *accel_channel;
|
||||
};
|
||||
|
||||
static void
|
||||
malloc_done(void *ref, int status)
|
||||
{
|
||||
@ -81,6 +85,7 @@ static TAILQ_HEAD(, malloc_disk) g_malloc_disks = TAILQ_HEAD_INITIALIZER(g_mallo
|
||||
int malloc_disk_count = 0;
|
||||
|
||||
static int bdev_malloc_initialize(void);
|
||||
static void bdev_malloc_deinitialize(void);
|
||||
|
||||
static int
|
||||
bdev_malloc_get_ctx_size(void)
|
||||
@ -91,6 +96,7 @@ bdev_malloc_get_ctx_size(void)
|
||||
static struct spdk_bdev_module malloc_if = {
|
||||
.name = "malloc",
|
||||
.module_init = bdev_malloc_initialize,
|
||||
.module_fini = bdev_malloc_deinitialize,
|
||||
.get_ctx_size = bdev_malloc_get_ctx_size,
|
||||
|
||||
};
|
||||
@ -235,6 +241,7 @@ bdev_malloc_reset(struct malloc_disk *mdisk, struct malloc_task *task)
|
||||
|
||||
static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
struct malloc_channel *mch = spdk_io_channel_get_ctx(ch);
|
||||
uint32_t block_size = bdev_io->bdev->blocklen;
|
||||
|
||||
switch (bdev_io->type) {
|
||||
@ -250,7 +257,7 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
}
|
||||
|
||||
bdev_malloc_readv((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
mch->accel_channel,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.bdev.iovs,
|
||||
bdev_io->u.bdev.iovcnt,
|
||||
@ -260,7 +267,7 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||
bdev_malloc_writev((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
mch->accel_channel,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.bdev.iovs,
|
||||
bdev_io->u.bdev.iovcnt,
|
||||
@ -280,7 +287,7 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
|
||||
case SPDK_BDEV_IO_TYPE_UNMAP:
|
||||
return bdev_malloc_unmap((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
mch->accel_channel,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.bdev.offset_blocks * block_size,
|
||||
bdev_io->u.bdev.num_blocks * block_size);
|
||||
@ -288,7 +295,7 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b
|
||||
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
||||
/* bdev_malloc_unmap is implemented with a call to mem_cpy_fill which zeroes out all of the requested bytes. */
|
||||
return bdev_malloc_unmap((struct malloc_disk *)bdev_io->bdev->ctxt,
|
||||
ch,
|
||||
mch->accel_channel,
|
||||
(struct malloc_task *)bdev_io->driver_ctx,
|
||||
bdev_io->u.bdev.offset_blocks * block_size,
|
||||
bdev_io->u.bdev.num_blocks * block_size);
|
||||
@ -344,7 +351,7 @@ bdev_malloc_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
|
||||
static struct spdk_io_channel *
|
||||
bdev_malloc_get_io_channel(void *ctx)
|
||||
{
|
||||
return spdk_accel_engine_get_io_channel();
|
||||
return spdk_get_io_channel(&g_malloc_disks);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -468,13 +475,46 @@ delete_malloc_disk(struct spdk_bdev *bdev, spdk_delete_malloc_complete cb_fn, vo
|
||||
spdk_bdev_unregister(bdev, cb_fn, cb_arg);
|
||||
}
|
||||
|
||||
static int
|
||||
malloc_create_channel_cb(void *io_device, void *ctx)
|
||||
{
|
||||
struct malloc_channel *ch = ctx;
|
||||
|
||||
ch->accel_channel = spdk_accel_engine_get_io_channel();
|
||||
if (!ch->accel_channel) {
|
||||
SPDK_ERRLOG("Failed to get accel engine's IO channel\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
malloc_destroy_channel_cb(void *io_device, void *ctx)
|
||||
{
|
||||
struct malloc_channel *ch = ctx;
|
||||
|
||||
spdk_put_io_channel(ch->accel_channel);
|
||||
}
|
||||
|
||||
static int bdev_malloc_initialize(void)
|
||||
{
|
||||
/* This needs to be reset for each reinitialization of submodules.
|
||||
* Otherwise after enough devices or reinitializations the value gets too high.
|
||||
* TODO: Make malloc bdev name mandatory and remove this counter. */
|
||||
malloc_disk_count = 0;
|
||||
|
||||
spdk_io_device_register(&g_malloc_disks, malloc_create_channel_cb,
|
||||
malloc_destroy_channel_cb, sizeof(struct malloc_channel),
|
||||
"bdev_malloc");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_malloc_deinitialize(void)
|
||||
{
|
||||
spdk_io_device_unregister(&g_malloc_disks, NULL);
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT(bdev_malloc)
|
||||
|
Loading…
Reference in New Issue
Block a user