blob_bdev: add spdk_bdev_create_bs_dev_from_desc

New interface for create spdk_bs_dev from bdev desc.
This change, together with spdk_bdev_open_ext, can
remove the race condition where user gets the bdev
structure, but bdev is removed after getting that
structure and before spdk_bdev_create_bs_dev function
is called.

Change-Id: Ia80c3527ff91b45f97f44d295a5cb6d83f5ee0e4
Signed-off-by: Xiaodong Liu <xiaodong.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468412
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
Xiaodong Liu 2019-09-16 16:28:29 +08:00 committed by Changpeng Liu
parent 032a8b1c9b
commit 3cba062b86
3 changed files with 51 additions and 1 deletions

View File

@ -24,6 +24,13 @@ asynchronous event such as bdev removal. spdk_bdev_open_ext function takes bdev
an argument instead 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_from_desc function has been added and spdk_bdev_create_bs_dev
function has been deprecated.
The new create function can cowork with spdk_bdev_open_ext function, which provides callback
function that will be called by asynchronous event such as bdev removal.
### nvme
Added `no_shn_notification` to NVMe controller initialization options, users can enable

View File

@ -50,7 +50,8 @@ struct spdk_bdev;
struct spdk_bdev_module;
/**
* Create a blobstore block device from a bdev.
* Create a blobstore block device from a bdev. (deprecated, please use spdk_bdev_create_bs_dev_from_desc,
* together with spdk_bdev_open_ext).
*
* \param bdev Bdev to use.
* \param remove_cb Called when the block device is removed.
@ -61,6 +62,15 @@ struct spdk_bdev_module;
struct spdk_bs_dev *spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_remove_cb_t remove_cb,
void *remove_ctx);
/**
* Create a blobstore block device from the descriptor of a bdev.
*
* \param desc Descriptor of a bdev. spdk_bdev_open_ext() is recommended to get the desc.
*
* \return a pointer to the blobstore block device on success or NULL otherwise.
*/
struct spdk_bs_dev *spdk_bdev_create_bs_dev_from_desc(struct spdk_bdev_desc *desc);
/**
* Claim the bdev module for the given blobstore.
*

View File

@ -355,3 +355,36 @@ spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_remove_cb_t remove_cb,
return &b->bs_dev;
}
struct spdk_bs_dev *
spdk_bdev_create_bs_dev_from_desc(struct spdk_bdev_desc *desc)
{
struct blob_bdev *b;
struct spdk_bdev *bdev;
b = calloc(1, sizeof(*b));
if (b == NULL) {
SPDK_ERRLOG("could not allocate blob_bdev\n");
return NULL;
}
bdev = spdk_bdev_desc_get_bdev(desc);
assert(bdev != NULL);
b->bdev = bdev;
b->desc = desc;
b->bs_dev.blockcnt = spdk_bdev_get_num_blocks(bdev);
b->bs_dev.blocklen = spdk_bdev_get_block_size(bdev);
b->bs_dev.create_channel = bdev_blob_create_channel;
b->bs_dev.destroy_channel = bdev_blob_destroy_channel;
b->bs_dev.destroy = bdev_blob_destroy;
b->bs_dev.read = bdev_blob_read;
b->bs_dev.write = bdev_blob_write;
b->bs_dev.readv = bdev_blob_readv;
b->bs_dev.writev = bdev_blob_writev;
b->bs_dev.write_zeroes = bdev_blob_write_zeroes;
b->bs_dev.unmap = bdev_blob_unmap;
return &b->bs_dev;
}