From 63966d6c0255708180fffc57f69a5f7011f53198 Mon Sep 17 00:00:00 2001 From: Jinliang Wang Date: Thu, 5 Jan 2023 10:10:44 -0800 Subject: [PATCH] mi: restore default ep timeout during admin_passthru Before the fix, the timeout can only increase and also it will change the default timeout setting permanently. After the fix, the timeout can be any value provided by the timeout_ms parameter and also we will restore the default timeout settings. Signed-off-by: Jinliang Wang --- src/nvme/mi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/nvme/mi.c b/src/nvme/mi.c index 6ccd668e..3793ad46 100644 --- a/src/nvme/mi.c +++ b/src/nvme/mi.c @@ -639,6 +639,7 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, struct nvme_mi_admin_req_hdr req_hdr; struct nvme_mi_resp resp; struct nvme_mi_req req; + unsigned int timeout_save; int rc; int direction = opcode & 0x3; bool has_write_data = false; @@ -665,11 +666,6 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, has_read_data = true; } - if (timeout_ms > nvme_mi_ep_get_timeout(ctrl->ep)) { - /* Set timeout if user needs a bigger timeout */ - nvme_mi_ep_set_timeout(ctrl->ep, timeout_ms); - } - nvme_mi_admin_init_req(&req, &req_hdr, ctrl->id, opcode); req_hdr.cdw1 = cpu_to_le32(nsid); req_hdr.cdw2 = cpu_to_le32(cdw2); @@ -701,7 +697,17 @@ int nvme_mi_admin_admin_passthru(nvme_mi_ctrl_t ctrl, __u8 opcode, __u8 flags, resp.data_len = data_len; } + /* if the user has specified a custom timeout, save the current + * timeout and override + */ + if (timeout_ms != 0) { + timeout_save = nvme_mi_ep_get_timeout(ctrl->ep); + nvme_mi_ep_set_timeout(ctrl->ep, timeout_ms); + } rc = nvme_mi_submit(ctrl->ep, &req, &resp); + if (timeout_ms != 0) + nvme_mi_ep_set_timeout(ctrl->ep, timeout_save); + if (rc) return rc;