diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index 36ccae6bf1..818e6472bf 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -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; @@ -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) @@ -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) @@ -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) @@ -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; diff --git a/nvme.c b/nvme.c index f078d0adcc..32bfffd344 100644 --- a/nvme.c +++ b/nvme.c @@ -7350,6 +7350,28 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi 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"); + 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");