[PATCH 4/6] nvme-ioctl: common user timeout setting
Keith Busch
kbusch at meta.com
Mon Feb 24 10:21:26 PST 2025
From: Keith Busch <kbusch at kernel.org>
Most of the passthrough paths repeat the same request timeout setup, so
make it common with the request allocation.
Signed-off-by: Keith Busch <kbusch at kernel.org>
---
drivers/nvme/host/ioctl.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 3da014ccbe550..1f28fc4b341dd 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -101,7 +101,7 @@ static void __user *nvme_to_user_ptr(uintptr_t ptrval)
static struct request *nvme_alloc_user_request(struct request_queue *q,
struct nvme_command *cmd, blk_opf_t rq_flags,
- blk_mq_req_flags_t blk_flags)
+ blk_mq_req_flags_t blk_flags, unsigned timeout_ms)
{
struct request *req;
@@ -110,6 +110,7 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
return req;
nvme_init_request(req, cmd);
nvme_req(req)->flags |= NVME_REQ_USERCMD;
+ req->timeout = timeout_ms ? msecs_to_jiffies(timeout_ms) : 0;
return req;
}
@@ -180,7 +181,7 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
static int nvme_submit_user_cmd(struct request_queue *q,
struct nvme_command *cmd, u64 ubuffer, unsigned bufflen,
u64 meta_buffer, unsigned meta_len, u64 *result,
- unsigned timeout, unsigned int flags)
+ unsigned timeout_ms, unsigned int flags)
{
struct nvme_ns *ns = q->queuedata;
struct nvme_ctrl *ctrl;
@@ -189,11 +190,10 @@ static int nvme_submit_user_cmd(struct request_queue *q,
u32 effects;
int ret;
- req = nvme_alloc_user_request(q, cmd, 0, 0);
+ req = nvme_alloc_user_request(q, cmd, 0, 0, timeout_ms);
if (IS_ERR(req))
return PTR_ERR(req);
- req->timeout = timeout;
if (ubuffer && bufflen) {
ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer,
meta_len, NULL, flags);
@@ -297,7 +297,6 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
{
struct nvme_passthru_cmd cmd;
struct nvme_command c;
- unsigned timeout = 0;
u64 result;
int status;
@@ -324,12 +323,9 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
if (!nvme_cmd_allowed(ns, &c, flags))
return -EACCES;
- if (cmd.timeout_ms)
- timeout = msecs_to_jiffies(cmd.timeout_ms);
-
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
cmd.addr, cmd.data_len, cmd.metadata, cmd.metadata_len,
- &result, timeout, flags);
+ &result, cmd.timeout_ms, flags);
if (status >= 0) {
if (put_user(result, &ucmd->result))
@@ -344,7 +340,6 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
{
struct nvme_passthru_cmd64 cmd;
struct nvme_command c;
- unsigned timeout = 0;
int status;
if (copy_from_user(&cmd, ucmd, sizeof(cmd)))
@@ -370,12 +365,9 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
if (!nvme_cmd_allowed(ns, &c, flags))
return -EACCES;
- if (cmd.timeout_ms)
- timeout = msecs_to_jiffies(cmd.timeout_ms);
-
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
cmd.addr, cmd.data_len, cmd.metadata, cmd.metadata_len,
- &cmd.result, timeout, flags);
+ &cmd.result, cmd.timeout_ms, flags);
if (status >= 0) {
if (put_user(cmd.result, &ucmd->result))
@@ -507,10 +499,9 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
if (issue_flags & IO_URING_F_IOPOLL)
rq_flags |= REQ_POLLED;
- req = nvme_alloc_user_request(q, &c, rq_flags, blk_flags);
+ req = nvme_alloc_user_request(q, &c, rq_flags, blk_flags, d.timeout_ms);
if (IS_ERR(req))
return PTR_ERR(req);
- req->timeout = d.timeout_ms ? msecs_to_jiffies(d.timeout_ms) : 0;
if (d.addr && d.data_len) {
ret = nvme_map_user_request(req, d.addr, d.data_len, d.metadata,
--
2.43.5
More information about the Linux-nvme
mailing list