diff --git a/CHANGELOG.md b/CHANGELOG.md index 83f9dc14e..3568c4e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/include/spdk/blob_bdev.h b/include/spdk/blob_bdev.h index dcaa5b18c..1867c464c 100644 --- a/include/spdk/blob_bdev.h +++ b/include/spdk/blob_bdev.h @@ -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. * diff --git a/module/blob/bdev/blob_bdev.c b/module/blob/bdev/blob_bdev.c index 42293142d..67949fcfe 100644 --- a/module/blob/bdev/blob_bdev.c +++ b/module/blob/bdev/blob_bdev.c @@ -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; +}