| From 2b330a663d6688096a00d3259a2e3ace2e851021 Mon Sep 17 00:00:00 2001 |
| From: Hao Jiang <jianghao@google.com> |
| Date: Tue, 10 Jan 2023 01:24:00 +0000 |
| Subject: [PATCH 21/44] nvmesensor: add timeout for xfer |
| |
| The xfer which is used by plugins or others may share a different timeout |
| setting, since the VU command could take time for processing. So added |
| the timeout as parameter so the client can modify according to the use |
| case. |
| |
| Signed-off-by: Hao Jiang <jianghao@google.com> |
| Change-Id: I02d8c8527d56914ef15faf502cb2db98ea705228 |
| --- |
| src/NVMeIntf.hpp | 3 ++- |
| src/NVMeMi.cpp | 10 ++++++++-- |
| src/NVMeMi.hpp | 2 +- |
| src/NVMePlugin.hpp | 5 +++-- |
| 4 files changed, 14 insertions(+), 6 deletions(-) |
| |
| diff --git a/src/NVMeIntf.hpp b/src/NVMeIntf.hpp |
| index 7c639c6..e52a700 100644 |
| --- a/src/NVMeIntf.hpp |
| +++ b/src/NVMeIntf.hpp |
| @@ -188,6 +188,7 @@ class NVMeMiIntf |
| * @ctrl: controller to send the admin command to |
| * @admin_req: request header |
| * @data: request data payload |
| + * @timeout_ms: timeout in ms |
| * @resp_data_offset: offset into request data to retrieve from controller |
| * @cb: callback function after the response received. |
| * @ec: error code |
| @@ -213,7 +214,7 @@ class NVMeMiIntf |
| */ |
| virtual void |
| adminXfer(nvme_mi_ctrl_t ctrl, const nvme_mi_admin_req_hdr& admin_req, |
| - std::span<uint8_t> data, |
| + std::span<uint8_t> data, unsigned int timeout_ms, |
| std::function<void(const std::error_code& ec, |
| const nvme_mi_admin_resp_hdr& admin_resp, |
| std::span<uint8_t> resp_data)>&& cb) = 0; |
| diff --git a/src/NVMeMi.cpp b/src/NVMeMi.cpp |
| index 0cd9ebc..c8579a7 100644 |
| --- a/src/NVMeMi.cpp |
| +++ b/src/NVMeMi.cpp |
| @@ -615,7 +615,7 @@ void NVMeMi::adminGetLogPage( |
| |
| void NVMeMi::adminXfer( |
| nvme_mi_ctrl_t ctrl, const nvme_mi_admin_req_hdr& admin_req, |
| - std::span<uint8_t> data, |
| + std::span<uint8_t> data, unsigned int timeout_ms, |
| std::function<void(const std::error_code&, const nvme_mi_admin_resp_hdr&, |
| std::span<uint8_t>)>&& cb) |
| { |
| @@ -633,7 +633,7 @@ void NVMeMi::adminXfer( |
| memcpy(req.data(), &admin_req, sizeof(nvme_mi_admin_req_hdr)); |
| memcpy(req.data() + sizeof(nvme_mi_admin_req_hdr), data.data(), |
| data.size()); |
| - post([ctrl, req{std::move(req)}, self{shared_from_this()}, |
| + post([ctrl, req{std::move(req)}, self{shared_from_this()}, timeout_ms, |
| cb{std::move(cb)}]() mutable { |
| int rc = 0; |
| |
| @@ -649,9 +649,15 @@ void NVMeMi::adminXfer( |
| nvme_mi_admin_resp_hdr* respHeader = |
| reinterpret_cast<nvme_mi_admin_resp_hdr*>(buf.data()); |
| |
| + // set timeout |
| + unsigned timeout = nvme_mi_ep_get_timeout(self->nvmeEP); |
| + nvme_mi_ep_set_timeout(self->nvmeEP, timeout_ms); |
| + |
| rc = nvme_mi_admin_xfer(ctrl, reqHeader, |
| req.size() - sizeof(nvme_mi_admin_req_hdr), |
| respHeader, respDataOffset, &respDataSize); |
| + // revert to previous timeout |
| + nvme_mi_ep_set_timeout(self->nvmeEP, timeout); |
| |
| if (rc < 0) |
| { |
| diff --git a/src/NVMeMi.hpp b/src/NVMeMi.hpp |
| index 64f2fc6..0d9fe2c 100644 |
| --- a/src/NVMeMi.hpp |
| +++ b/src/NVMeMi.hpp |
| @@ -41,7 +41,7 @@ class NVMeMi : public NVMeMiIntf, public std::enable_shared_from_this<NVMeMi> |
| override; |
| |
| void adminXfer(nvme_mi_ctrl_t ctrl, const nvme_mi_admin_req_hdr& admin_req, |
| - std::span<uint8_t> data, |
| + std::span<uint8_t> data, unsigned int timeout_ms, |
| std::function<void(const std::error_code&, |
| const nvme_mi_admin_resp_hdr&, |
| std::span<uint8_t>)>&& cb) override; |
| diff --git a/src/NVMePlugin.hpp b/src/NVMePlugin.hpp |
| index 122bc5a..0283e9b 100644 |
| --- a/src/NVMePlugin.hpp |
| +++ b/src/NVMePlugin.hpp |
| @@ -48,6 +48,7 @@ class NVMeControllerPlugin |
| * adminXfer() - transfer Raw admin cmd to the binded conntroller |
| * @admin_req: request header |
| * @data: request data payload |
| + * @timeout_ms: timeout in ms |
| * @resp_data_offset: offset into request data to retrieve from controller |
| * @cb: callback function after the response received. |
| * @ec: error code |
| @@ -73,13 +74,13 @@ class NVMeControllerPlugin |
| * @ec will be returned on failure. |
| */ |
| void adminXfer(const nvme_mi_admin_req_hdr& admin_req, |
| - std::span<uint8_t> data, |
| + std::span<uint8_t> data, unsigned int timeout_ms, |
| std::function<void(const std::error_code& ec, |
| const nvme_mi_admin_resp_hdr& admin_resp, |
| std::span<uint8_t> resp_data)>&& cb) |
| { |
| nvmeController->nvmeIntf->adminXfer(nvmeController->nvmeCtrl, admin_req, |
| - data, std::move(cb)); |
| + data, timeout_ms, std::move(cb)); |
| } |
| /** |
| * @brief Get cntrl_id for the binded NVMe controller |
| -- |
| 2.34.1 |
| |