blob/bdev: Add an API spdk_bdev_create_bs_dev_ext()

spdk_bdev_open_ext() requires the caller to use bdev_event_cb_t
and bdev_event_cb_t is more extensible than bdev_remove_cb_t.
Hence use bdev_event_t as an argument.

spdk_bdev_open_ext() calls spdk_bdev_get_by_name() inside and
spdk_bdev_create_bs_dev_ext() calls spdk_bdev_open_ext() inside.
The caller needs to know if the spdk_bdev_get_by_name() succeeded.
Hence spdk_bdev_create_bs_dev_ext() returns return code by return
value and returns the created bs_dev by double pointer.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I1c225bfb66db036439c69c459f39c86684d8a540
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4692
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2020-10-14 23:55:06 +09:00 committed by Tomasz Zawadzki
parent 778e21aabd
commit 6a72c19ee2
5 changed files with 51 additions and 4 deletions

View File

@ -16,6 +16,11 @@ A new `spdk_bdev_part_base_construct_ext` function has been added and the
of bdev structure to avoid a race condition that can happen when the bdev is being
removed between a call to get its structure based on a name and actually openning it.
### blobstore
A new `spdk_bdev_create_bs_dev_ext` function has been added and `spdk_bdev_create_bs_dev_from_desc`
function has been deprecated.
### dpdk
Updated DPDK submodule to DPDK 20.08.

View File

@ -50,8 +50,7 @@ struct spdk_bdev;
struct spdk_bdev_module;
/**
* Create a blobstore block device from a bdev. (deprecated, please use spdk_bdev_create_bs_dev_from_desc,
* together with spdk_bdev_open_ext).
* Create a blobstore block device from a bdev (deprecated, please use spdk_bdev_create_bs_dev_ext).
*
* \param bdev Bdev to use.
* \param remove_cb Called when the block device is removed.
@ -63,7 +62,7 @@ struct spdk_bs_dev *spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_re
void *remove_ctx);
/**
* Create a blobstore block device from the descriptor of a bdev.
* Create a blobstore block device from the descriptor of a bdev (deprecated, please use spdk_bdev_create_bs_dev_ext).
*
* \param desc Descriptor of a bdev. spdk_bdev_open_ext() is recommended to get the desc.
*
@ -71,6 +70,19 @@ struct spdk_bs_dev *spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_re
*/
struct spdk_bs_dev *spdk_bdev_create_bs_dev_from_desc(struct spdk_bdev_desc *desc);
/**
* Create a blobstore block device from a bdev.
*
* \param bdev_name Name of the bdev to use.
* \param event_cb Called when the bdev triggers asynchronous event.
* \param event_ctx Argument passed to function event_cb.
* \param bs_dev Output parameter for a pointer to the blobstore block device.
*
* \return 0 if operation is successful, or suitable errno value otherwise.
*/
int spdk_bdev_create_bs_dev_ext(const char *bdev_name, spdk_bdev_event_cb_t event_cb,
void *event_ctx, struct spdk_bs_dev **bs_dev);
/**
* Claim the bdev module for the given blobstore.
*

View File

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

View File

@ -383,3 +383,32 @@ spdk_bdev_create_bs_dev_from_desc(struct spdk_bdev_desc *desc)
return &b->bs_dev;
}
int
spdk_bdev_create_bs_dev_ext(const char *bdev_name, spdk_bdev_event_cb_t event_cb,
void *event_ctx, struct spdk_bs_dev **_bs_dev)
{
struct blob_bdev *b;
struct spdk_bdev_desc *desc;
int rc;
b = calloc(1, sizeof(*b));
if (b == NULL) {
SPDK_ERRLOG("could not allocate blob_bdev\n");
return -ENOMEM;
}
rc = spdk_bdev_open_ext(bdev_name, true, event_cb, event_ctx, &desc);
if (rc != 0) {
free(b);
return rc;
}
blob_bdev_init(b, desc);
*_bs_dev = &b->bs_dev;
return 0;
}

View File

@ -4,6 +4,7 @@
# public functions
spdk_bdev_create_bs_dev;
spdk_bdev_create_bs_dev_from_desc;
spdk_bdev_create_bs_dev_ext;
spdk_bs_bdev_claim;
local: *;