Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions drivers/block/ublk_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2953,8 +2953,10 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
if (wait_for_completion_interruptible(&ub->completion) != 0)
return -EINTR;

if (ub->ublksrv_tgid != ublksrv_pid)
return -EINVAL;
if (ub->ublksrv_tgid != ublksrv_pid) {
ret = -EINVAL;
goto out;
}

mutex_lock(&ub->mutex);
if (ub->dev_info.state == UBLK_S_DEV_LIVE ||
Expand Down Expand Up @@ -3017,6 +3019,9 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
put_disk(disk);
out_unlock:
mutex_unlock(&ub->mutex);
out:
if (ret)
ublk_cancel_dev(ub);
return ret;
}

Expand Down
14 changes: 7 additions & 7 deletions tools/testing/selftests/ublk/kublk.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,10 @@ static int ublk_ctrl_add_dev(struct ublk_dev *dev)
return __ublk_ctrl_cmd(dev, &data);
}

static int ublk_ctrl_del_dev(struct ublk_dev *dev)
static int ublk_ctrl_del_dev(struct ublk_dev *dev, bool async)
{
struct ublk_ctrl_cmd_data data = {
.cmd_op = UBLK_U_CMD_DEL_DEV,
.flags = 0,
.cmd_op = async ? UBLK_U_CMD_DEL_DEV_ASYNC: UBLK_U_CMD_DEL_DEV,
};

return __ublk_ctrl_cmd(dev, &data);
Expand Down Expand Up @@ -1063,11 +1062,11 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)
else
ublk_send_dev_event(ctx, dev, dev->dev_info.dev_id);

fail:
/* wait until we are terminated */
for (i = 0; i < dev->nthreads; i++)
pthread_join(tinfo[i].thread, &thread_ret);
free(tinfo);
fail:
for (i = 0; i < dinfo->nr_hw_queues; i++)
ublk_queue_deinit(&dev->q[i]);
ublk_dev_unprep(dev);
Expand Down Expand Up @@ -1272,9 +1271,9 @@ static int __cmd_dev_add(const struct dev_ctx *ctx)
}

ret = ublk_start_daemon(ctx, dev);
ublk_dbg(UBLK_DBG_DEV, "%s: daemon exit %d\b", ret);
ublk_dbg(UBLK_DBG_DEV, "%s: daemon exit %d\n", __func__, ret);
if (ret < 0)
ublk_ctrl_del_dev(dev);
ublk_ctrl_del_dev(dev, true);

fail:
if (ret < 0)
Expand Down Expand Up @@ -1371,7 +1370,7 @@ static int __cmd_dev_del(struct dev_ctx *ctx)
if (ret < 0)
ublk_err("%s: stop daemon id %d dev %d, ret %d\n",
__func__, dev->dev_info.ublksrv_pid, number, ret);
ublk_ctrl_del_dev(dev);
ublk_ctrl_del_dev(dev, false);
fail:
ublk_ctrl_deinit(dev);

Expand Down Expand Up @@ -1622,6 +1621,7 @@ int main(int argc, char *argv[])
.nr_hw_queues = 2,
.dev_id = -1,
.tgt_type = "unknown",
._evtfd = -1,
};
int ret = -EINVAL, i;
int tgt_argc = 1;
Expand Down