Skip to content
Merged
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
35 changes: 13 additions & 22 deletions libnvme/src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void nvme_uring_cmd_exit(struct io_uring *ring)
}

static int nvme_uring_cmd_admin_passthru_async(struct nvme_transport_handle *hdl,
struct io_uring *ring, struct nvme_passthru_cmd *cmd, __u32 *result)
struct io_uring *ring, struct nvme_passthru_cmd *cmd)
{
struct io_uring_sqe *sqe;
int ret;
Expand All @@ -274,7 +274,6 @@ static int nvme_uring_cmd_admin_passthru_async(struct nvme_transport_handle *hdl
sqe->fd = hdl->fd;
sqe->opcode = IORING_OP_URING_CMD;
sqe->cmd_op = NVME_URING_CMD_ADMIN;
sqe->user_data = (__u64)(uintptr_t)result;

ret = io_uring_submit(ring);
if (ret < 0)
Expand All @@ -286,26 +285,16 @@ static int nvme_uring_cmd_admin_passthru_async(struct nvme_transport_handle *hdl
static int nvme_uring_cmd_wait_complete(struct io_uring *ring, int n)
{
struct io_uring_cqe *cqe;
int i, ret = 0;
__u32 *result;
int ret, i;

for (i = 0; i < n; i++) {
ret = io_uring_wait_cqe(ring, &cqe);
if (ret)
return -1;

if (cqe->res) {
result = (__u32 *)cqe->user_data;
if (result)
*result = cqe->res;
ret = cqe->res;
break;
}

if (ret < 0)
return -errno;
io_uring_cqe_seen(ring, cqe);
}

return ret;
return 0;
}

static bool nvme_uring_is_usable(struct nvme_transport_handle *hdl)
Expand Down Expand Up @@ -388,15 +377,16 @@ int nvme_get_log(struct nvme_transport_handle *hdl,
#ifdef CONFIG_LIBURING
if (use_uring) {
if (n >= NVME_URING_ENTRIES) {
nvme_uring_cmd_wait_complete(&ring, n);
ret = nvme_uring_cmd_wait_complete(&ring, n);
if (ret)
goto uring_exit;
n = 0;
}
n += 1;
ret = nvme_uring_cmd_admin_passthru_async(hdl, &ring,
cmd, result);

ret = nvme_uring_cmd_admin_passthru_async(hdl,
&ring, cmd);
if (ret)
nvme_uring_cmd_exit(&ring);
goto uring_exit;
} else {
ret = nvme_submit_admin_passthru(hdl, cmd);
if (ret)
Expand All @@ -414,7 +404,8 @@ int nvme_get_log(struct nvme_transport_handle *hdl,

#ifdef CONFIG_LIBURING
if (use_uring) {
nvme_uring_cmd_wait_complete(&ring, n);
ret = nvme_uring_cmd_wait_complete(&ring, n);
uring_exit:
nvme_uring_cmd_exit(&ring);
if (ret)
return ret;
Expand Down
22 changes: 22 additions & 0 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -7350,6 +7350,28 @@
if (err)
return err;

if (nvme_transport_handle_is_chardev(hdl)) {
_cleanup_free_ char *cdev = NULL;

if (!cfg.namespace_id) {
nvme_show_error("char device not supported without --namespace-id");

Check failure on line 7357 in nvme.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 92 exceeds 80 columns
return -EINVAL;
}

if (asprintf(&cdev, "/dev/%sn%d",
nvme_transport_handle_get_name(hdl),
cfg.namespace_id) < 0)
return -ENOMEM;

nvme_close(hdl);

err = nvme_open(ctx, cdev, &hdl);
if (err) {
nvme_show_error("could not open %s", cdev);
return err;
}
}

err = validate_output_format(nvme_cfg.output_format, &flags);
if (err < 0) {
nvme_show_error("Invalid output format");
Expand Down
Loading