From 62a00973bfdfeb375335d25cac15200762ca0a40 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Wed, 27 Jan 2021 12:46:38 -0500 Subject: [PATCH] nbd: put nbd_disk_register ahead Also remove duplicated checking on nbd path Change-Id: I3b2aec6de5134ef2404529690f7692689c198a56 Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6121 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Ziye Yang Reviewed-by: Changpeng Liu Reviewed-by: --- lib/nbd/nbd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/nbd/nbd.c b/lib/nbd/nbd.c index bb9bef32b..5420eab13 100644 --- a/lib/nbd/nbd.c +++ b/lib/nbd/nbd.c @@ -187,6 +187,7 @@ spdk_nbd_fini(spdk_nbd_fini_cb cb_fn, void *cb_arg) static int nbd_disk_register(struct spdk_nbd_disk *nbd) { + /* Make sure nbd_path is not used in this SPDK app */ if (nbd_disk_find_by_nbd_path(nbd->nbd_path)) { SPDK_NOTICELOG("%s is already exported\n", nbd->nbd_path); return -EBUSY; @@ -917,14 +918,6 @@ nbd_start_complete(struct spdk_nbd_start_ctx *ctx) pthread_t tid; int flag; - /* Add nbd_disk to the end of disk list */ - rc = nbd_disk_register(ctx->nbd); - if (rc != 0) { - SPDK_ERRLOG("Failed to register %s, it should not happen.\n", ctx->nbd->nbd_path); - assert(false); - goto err; - } - rc = ioctl(ctx->nbd->dev_fd, NBD_SET_BLKSIZE, spdk_bdev_get_block_size(ctx->nbd->bdev)); if (rc == -1) { SPDK_ERRLOG("ioctl(NBD_SET_BLKSIZE) failed: %s\n", spdk_strerror(errno)); @@ -1117,10 +1110,9 @@ spdk_nbd_start(const char *bdev_name, const char *nbd_path, TAILQ_INIT(&nbd->received_io_list); TAILQ_INIT(&nbd->executed_io_list); - /* Make sure nbd_path is not used in this SPDK app */ - if (nbd_disk_find_by_nbd_path(nbd->nbd_path)) { - SPDK_NOTICELOG("%s is already exported\n", nbd->nbd_path); - rc = -EBUSY; + /* Add nbd_disk to the end of disk list */ + nbd_disk_register(ctx->nbd); + if (rc != 0) { goto err; }