]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
mi: restore default ep timeout during admin_passthru
authorJinliang Wang <jinliangw@google.com>
Thu, 5 Jan 2023 18:10:44 +0000 (10:10 -0800)
committerDaniel Wagner <wagi@monom.org>
Wed, 8 May 2024 07:08:42 +0000 (09:08 +0200)
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 <jinliangw@google.com>
src/nvme/mi.c

index 6ccd668e2d79d905649f3ae78a71beaf297645d3..3793ad46bebfe786c44be272c0e6878effe99350 100644 (file)
@@ -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;