Skip to content

Commit 23e62cf

Browse files
Ming Leiaxboe
authored andcommitted
selftests/ublk: fix error handling for starting device
Fix error handling in ublk_start_daemon() when start_dev fails: 1. Call ublk_ctrl_stop_dev() to cancel inflight uring_cmd before cleanup. Without this, the device deletion may hang waiting for I/O completion that will never happen. 2. Add fail_start label so that pthread_join() is called on the error path. This ensures proper thread cleanup when startup fails. Fixes: 6aecda0 ("selftests: ublk: add kernel selftests for ublk") Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Caleb Sander Mateos <csander@purestorage.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 75aad5f commit 23e62cf

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • tools/testing/selftests/ublk

tools/testing/selftests/ublk/kublk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +1054,17 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)
10541054
}
10551055
if (ret < 0) {
10561056
ublk_err("%s: ublk_ctrl_start_dev failed: %d\n", __func__, ret);
1057-
goto fail;
1057+
/* stop device so that inflight uring_cmd can be cancelled */
1058+
ublk_ctrl_stop_dev(dev);
1059+
goto fail_start;
10581060
}
10591061

10601062
ublk_ctrl_get_info(dev);
10611063
if (ctx->fg)
10621064
ublk_ctrl_dump(dev);
10631065
else
10641066
ublk_send_dev_event(ctx, dev, dev->dev_info.dev_id);
1065-
1067+
fail_start:
10661068
/* wait until we are terminated */
10671069
for (i = 0; i < dev->nthreads; i++)
10681070
pthread_join(tinfo[i].thread, &thread_ret);

0 commit comments

Comments
 (0)