From 5f1b5f18aed2f5672b016946cfd5053f86c284e7 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 20 Jan 2023 00:32:56 +0000 Subject: [PATCH] ublk: change where new dev's ublk file gets opened Upcoming patches will submit ctrl cmds and wait for them to complete asynchronously. So we will want to first send the ADD_DEV and SET_PARAMS commands, wait for them to complete, and only then open the ublk device file. So to prepare for that sequencing, move the open() from _ublk_start_disk to ublk_start_disk. Signed-off-by: Jim Harris Change-Id: I9fdf19ce9b51bd552faa917e1e842f9ddfb111a1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16402 Tested-by: SPDK CI Jenkins Reviewed-by: Xiaodong Liu Reviewed-by: Konrad Sztyber Reviewed-by: Paul Luse Reviewed-by: Ben Walker --- lib/ublk/ublk.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/ublk/ublk.c b/lib/ublk/ublk.c index b434a31b8..a73a9f4b1 100644 --- a/lib/ublk/ublk.c +++ b/lib/ublk/ublk.c @@ -1179,7 +1179,6 @@ static int _ublk_start_disk(struct spdk_ublk_dev *ublk) { int rc; - char buf[64]; rc = ublk_ctrl_cmd(ublk, UBLK_CMD_ADD_DEV, &ublk->dev_info); if (rc < 0) { @@ -1193,13 +1192,6 @@ _ublk_start_disk(struct spdk_ublk_dev *ublk) SPDK_ERRLOG("UBLK can't set params for dev %d, rc %s\n", ublk->ublk_id, spdk_strerror(-rc)); goto err; } - snprintf(buf, 64, "%s%d", UBLK_BLK_CDEV, ublk->ublk_id); - ublk->cdev_fd = open(buf, O_RDWR); - if (ublk->cdev_fd < 0) { - rc = ublk->cdev_fd; - SPDK_ERRLOG("can't open %s, rc %d\n", buf, rc); - goto err; - } return 0; @@ -1333,6 +1325,7 @@ ublk_start_disk(const char *bdev_name, uint32_t ublk_id, struct spdk_bdev *bdev; struct spdk_ublk_dev *ublk = NULL; struct spdk_thread *ublk_thread; + char buf[64]; if (g_ublk_tgt.active == false) { SPDK_ERRLOG("NO ublk target exist\n"); @@ -1395,6 +1388,14 @@ ublk_start_disk(const char *bdev_name, uint32_t ublk_id, goto err; } + snprintf(buf, 64, "%s%d", UBLK_BLK_CDEV, ublk->ublk_id); + ublk->cdev_fd = open(buf, O_RDWR); + if (ublk->cdev_fd < 0) { + rc = ublk->cdev_fd; + SPDK_ERRLOG("can't open %s, rc %d\n", buf, rc); + goto err; + } + for (q_id = 0; q_id < ublk->num_queues; q_id++) { rc = ublk_dev_queue_init(&ublk->queues[q_id]); if (rc) {