From 69d4ec07086e06f86145bdc42a0507dd0844c1eb Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 20 Jan 2023 00:39:17 +0000 Subject: [PATCH] ublk: break ublk_start_disk into two parts For now, we will still execute the two parts consecutively and synchronously. Follow-up patches will do the second part asynchronously, after the ublk cmds associated with the first part have completed. Signed-off-by: Jim Harris Change-Id: I814d885a8a113c3367207d11ae09dd536eb63460 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16403 Reviewed-by: Konrad Sztyber Reviewed-by: Xiaodong Liu Reviewed-by: Paul Luse Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- lib/ublk/ublk.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ublk/ublk.c b/lib/ublk/ublk.c index a73a9f4b1..d10f1126c 100644 --- a/lib/ublk/ublk.c +++ b/lib/ublk/ublk.c @@ -43,6 +43,7 @@ struct ublk_thread_ctx; static void ublk_submit_bdev_io(struct ublk_queue *q, uint16_t tag); static void ublk_dev_queue_fini(struct ublk_queue *q); static int ublk_poll(void *arg); +static int finish_start(struct spdk_ublk_dev *ublk); struct ublk_io { void *payload; @@ -1321,11 +1322,8 @@ ublk_start_disk(const char *bdev_name, uint32_t ublk_id, uint32_t num_queues, uint32_t queue_depth) { int rc; - uint32_t q_id, i; 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"); @@ -1388,6 +1386,21 @@ ublk_start_disk(const char *bdev_name, uint32_t ublk_id, goto err; } + return finish_start(ublk); + +err: + _ublk_try_close_dev(ublk); + return rc; +} + +static int +finish_start(struct spdk_ublk_dev *ublk) +{ + int rc; + uint32_t q_id, i; + struct spdk_thread *ublk_thread; + char buf[64]; + snprintf(buf, 64, "%s%d", UBLK_BLK_CDEV, ublk->ublk_id); ublk->cdev_fd = open(buf, O_RDWR); if (ublk->cdev_fd < 0) {