From 7a85820db3b2fc4fca39bf2abc95c8d0835af24a Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 13 Oct 2020 23:35:32 +0900 Subject: [PATCH] bdev/zone: Use spdk_bdev_open_ext() instead of spdk_bdev_open() This is just a drop-in replacement. Signed-off-by: Shuhei Matsumoto Change-Id: I018ef60648122aa672430bb62dc7b1a2e1cd5d7c Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4648 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Paul Luse Reviewed-by: Jim Harris --- module/bdev/zone_block/vbdev_zone_block.c | 21 +++++++++++++++---- test/unit/lib/bdev/bdev_zone.c/bdev_zone_ut.c | 6 +++--- .../vbdev_zone_block.c/vbdev_zone_block_ut.c | 16 ++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/module/bdev/zone_block/vbdev_zone_block.c b/module/bdev/zone_block/vbdev_zone_block.c index 51b38e3772..fdaa1ed259 100644 --- a/module/bdev/zone_block/vbdev_zone_block.c +++ b/module/bdev/zone_block/vbdev_zone_block.c @@ -591,10 +591,9 @@ static const struct spdk_bdev_fn_table zone_block_fn_table = { }; static void -zone_block_base_bdev_hotremove_cb(void *ctx) +zone_block_base_bdev_hotremove_cb(struct spdk_bdev *bdev_find) { struct bdev_zone_block *bdev_node, *tmp; - struct spdk_bdev *bdev_find = ctx; TAILQ_FOREACH_SAFE(bdev_node, &g_bdev_nodes, link, tmp) { if (bdev_find == spdk_bdev_desc_get_bdev(bdev_node->base_desc)) { @@ -603,6 +602,20 @@ zone_block_base_bdev_hotremove_cb(void *ctx) } } +static void +zone_block_base_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev, + void *event_ctx) +{ + switch (type) { + case SPDK_BDEV_EVENT_REMOVE: + zone_block_base_bdev_hotremove_cb(bdev); + break; + default: + SPDK_NOTICELOG("Unsupported bdev event: type %d\n", type); + break; + } +} + static int _zone_block_ch_create_cb(void *io_device, void *ctx_buf) { @@ -803,8 +816,8 @@ zone_block_register(struct spdk_bdev *base_bdev) sizeof(struct zone_block_io_channel), name->vbdev_name); - rc = spdk_bdev_open(base_bdev, true, zone_block_base_bdev_hotremove_cb, - base_bdev, &bdev_node->base_desc); + rc = spdk_bdev_open_ext(spdk_bdev_get_name(base_bdev), true, zone_block_base_bdev_event_cb, + NULL, &bdev_node->base_desc); if (rc) { SPDK_ERRLOG("could not open bdev %s\n", spdk_bdev_get_name(base_bdev)); goto open_failed; diff --git a/test/unit/lib/bdev/bdev_zone.c/bdev_zone_ut.c b/test/unit/lib/bdev/bdev_zone.c/bdev_zone_ut.c index 589e105b9d..2ee1af3015 100644 --- a/test/unit/lib/bdev/bdev_zone.c/bdev_zone_ut.c +++ b/test/unit/lib/bdev/bdev_zone.c/bdev_zone_ut.c @@ -206,8 +206,8 @@ bdev_channel_get_io(struct spdk_bdev_channel *channel) } int -spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_cb, - void *remove_ctx, struct spdk_bdev_desc **_desc) +spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb, + void *event_ctx, struct spdk_bdev_desc **_desc) { *_desc = (void *)0x1; return 0; @@ -305,7 +305,7 @@ test_zone_get_operation(void) int rc; \ memset(&bdev, 0, sizeof(bdev)); \ bdev.name = "bdev_zone_ut"; \ - rc = spdk_bdev_open(&bdev, true, NULL, NULL, &desc); \ + rc = spdk_bdev_open_ext(bdev.name, true, NULL, NULL, &desc); \ CU_ASSERT(rc == 0); \ SPDK_CU_ASSERT_FATAL(desc != NULL); \ ch = spdk_bdev_get_io_channel(desc); \ diff --git a/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c b/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c index d0ee553e34..28ceca2e49 100644 --- a/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c +++ b/test/unit/lib/bdev/vbdev_zone_block.c/vbdev_zone_block_ut.c @@ -116,11 +116,19 @@ spdk_bdev_free_io(struct spdk_bdev_io *bdev_io) } int -spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_cb, - void *remove_ctx, struct spdk_bdev_desc **_desc) +spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb, + void *event_ctx, struct spdk_bdev_desc **_desc) { - *_desc = (void *)bdev; - return 0; + struct spdk_bdev *bdev; + + TAILQ_FOREACH(bdev, &g_bdev_list, internal.link) { + if (strcmp(bdev_name, bdev->name) == 0) { + *_desc = (void *)bdev; + return 0; + } + } + + return -ENODEV; } struct spdk_bdev *