From c4fe4798124f47e930df06d9eefccbaf201962a1 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Thu, 5 Oct 2017 17:17:38 +0200 Subject: [PATCH] blob: add support for base bdev claim MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maciej Szwed Change-Id: Ia6b6e5352ce4da04784fb0a3ea1efd0552650067 Reviewed-on: https://review.gerrithub.io/381548 Reviewed-by: Piotr Pelpliński Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- include/spdk/blob_bdev.h | 3 +++ lib/blob/bdev/blob_bdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/spdk/blob_bdev.h b/include/spdk/blob_bdev.h index 883791fa14..2fb69c094d 100644 --- a/include/spdk/blob_bdev.h +++ b/include/spdk/blob_bdev.h @@ -47,10 +47,13 @@ extern "C" { struct spdk_bs_dev; struct spdk_bdev; +struct spdk_bdev_module_if; struct spdk_bs_dev *spdk_bdev_create_bs_dev(struct spdk_bdev *bdev, spdk_bdev_remove_cb_t remove_cb, void *remove_ctx); +int spdk_bs_bdev_claim(struct spdk_bs_dev *bs_dev, struct spdk_bdev_module_if *module); + #ifdef __cplusplus } #endif diff --git a/lib/blob/bdev/blob_bdev.c b/lib/blob/bdev/blob_bdev.c index d09232f2b9..d9c3187fb6 100644 --- a/lib/blob/bdev/blob_bdev.c +++ b/lib/blob/bdev/blob_bdev.c @@ -38,11 +38,13 @@ #include "spdk/io_channel.h" #include "spdk/log.h" #include "spdk/endian.h" +#include "spdk_internal/bdev.h" struct blob_bdev { struct spdk_bs_dev bs_dev; struct spdk_bdev *bdev; struct spdk_bdev_desc *desc; + bool claimed; }; static inline struct spdk_bdev_desc * @@ -134,6 +136,23 @@ bdev_blob_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, uint64 } } +int +spdk_bs_bdev_claim(struct spdk_bs_dev *bs_dev, struct spdk_bdev_module_if *module) +{ + struct blob_bdev *blob_bdev = (struct blob_bdev *)bs_dev; + int rc; + + rc = spdk_bdev_module_claim_bdev(blob_bdev->bdev, NULL, module); + if (rc != 0) { + SPDK_ERRLOG("could not claim bs dev\n"); + return rc; + } + + blob_bdev->claimed = true; + + return rc; +} + static struct spdk_io_channel * bdev_blob_create_channel(struct spdk_bs_dev *dev) { @@ -152,6 +171,11 @@ static void bdev_blob_destroy(struct spdk_bs_dev *bs_dev) { struct spdk_bdev_desc *desc = __get_desc(bs_dev); + struct blob_bdev *blob_bdev = (struct blob_bdev *)bs_dev; + + if (blob_bdev->claimed) { + spdk_bdev_module_release_bdev(blob_bdev->bdev); + } spdk_bdev_close(desc); free(bs_dev);