bdev: extend interface with get module ctx

Currently only nvme bdev module implements this interface. Bdev module
context (in this case spdk_nvme_ctrlr opaque handle) allows for nvme
interface usage for additional management.

Signed-off-by: Jacek Kalwas <jacek.kalwas@intel.com>
Change-Id: I6302c9229d5f7f294a3c1472d9e8dc1519637ffb
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4924
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Jacek Kalwas 2020-10-27 12:13:54 -04:00 committed by Tomasz Zawadzki
parent b10e305010
commit 296a6d9838
7 changed files with 54 additions and 3 deletions

View File

@ -249,6 +249,14 @@ void spdk_bdev_finish(spdk_bdev_fini_cb cb_fn, void *cb_arg);
*/
void spdk_bdev_subsystem_config_json(struct spdk_json_write_ctx *w);
/**
* Get block device module name.
*
* \param bdev Block device to query.
* \return Name of bdev module as a null-terminated string.
*/
const char *spdk_bdev_get_module_name(const struct spdk_bdev *bdev);
/**
* Get block device by the block device name.
*
@ -686,6 +694,16 @@ uint64_t spdk_bdev_get_weighted_io_time(const struct spdk_bdev *bdev);
*/
struct spdk_io_channel *spdk_bdev_get_io_channel(struct spdk_bdev_desc *desc);
/**
* Obtain a bdev module context for the block device opened by the specified
* descriptor.
*
* \param desc Block device descriptor.
*
* \return A bdev module context or NULL on failure.
*/
void *spdk_bdev_get_module_ctx(struct spdk_bdev_desc *desc);
/**
* \defgroup bdev_io_submit_functions bdev I/O Submit Functions
*

View File

@ -219,6 +219,9 @@ struct spdk_bdev_fn_table {
* Optional - may be NULL.
*/
uint64_t (*get_spin_time)(struct spdk_io_channel *ch);
/** Get bdev module context. */
void *(*get_module_ctx)(void *ctx);
};
/** bdev I/O completion status */

View File

@ -2966,6 +2966,25 @@ spdk_bdev_get_io_channel(struct spdk_bdev_desc *desc)
return spdk_get_io_channel(__bdev_to_io_dev(spdk_bdev_desc_get_bdev(desc)));
}
void *
spdk_bdev_get_module_ctx(struct spdk_bdev_desc *desc)
{
struct spdk_bdev *bdev = spdk_bdev_desc_get_bdev(desc);
void *ctx = NULL;
if (bdev->fn_table->get_module_ctx) {
ctx = bdev->fn_table->get_module_ctx(bdev->ctxt);
}
return ctx;
}
const char *
spdk_bdev_get_module_name(const struct spdk_bdev *bdev)
{
return bdev->module->name;
}
const char *
spdk_bdev_get_name(const struct spdk_bdev *bdev)
{

View File

@ -9,6 +9,7 @@
spdk_bdev_finish;
spdk_bdev_subsystem_config_json;
spdk_bdev_get_by_name;
spdk_bdev_get_module_name;
spdk_bdev_first;
spdk_bdev_next;
spdk_bdev_first_leaf;
@ -47,6 +48,7 @@
spdk_bdev_get_io_time;
spdk_bdev_get_weighted_io_time;
spdk_bdev_get_io_channel;
spdk_bdev_get_module_ctx;
spdk_bdev_read;
spdk_bdev_read_blocks;
spdk_bdev_read_blocks_with_md;

View File

@ -34,7 +34,7 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 2
SO_VER := 3
SO_MINOR := 0
C_SRCS = lvol.c

View File

@ -920,6 +920,14 @@ bdev_nvme_get_io_channel(void *ctx)
return spdk_get_io_channel(nvme_bdev->nvme_ns->ctrlr);
}
static void *
bdev_nvme_get_module_ctx(void *ctx)
{
struct nvme_bdev *nvme_bdev = ctx;
return bdev_nvme_get_ctrlr(&nvme_bdev->disk);
}
static int
bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
{
@ -1066,6 +1074,7 @@ static const struct spdk_bdev_fn_table nvmelib_fn_table = {
.dump_info_json = bdev_nvme_dump_info_json,
.write_config_json = bdev_nvme_write_config_json,
.get_spin_time = bdev_nvme_get_spin_time,
.get_module_ctx = bdev_nvme_get_module_ctx,
};
static struct nvme_bdev *

View File

@ -34,8 +34,8 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 3
SO_MINOR := 1
SO_VER := 4
SO_MINOR := 0
C_SRCS = blob_bdev.c
LIBNAME = blob_bdev