diff --git a/lib/nvmf/direct.c b/lib/nvmf/direct.c index 7f51f6065..dc3be590c 100644 --- a/lib/nvmf/direct.c +++ b/lib/nvmf/direct.c @@ -159,6 +159,8 @@ nvmf_direct_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req) return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; case SPDK_NVME_FEAT_HOST_IDENTIFIER: return spdk_nvmf_session_get_features_host_identifier(req); + case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER: + return spdk_nvmf_session_get_features_keep_alive_timer(req); default: goto passthrough; } @@ -181,6 +183,8 @@ nvmf_direct_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req) return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; case SPDK_NVME_FEAT_HOST_IDENTIFIER: return spdk_nvmf_session_set_features_host_identifier(req); + case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER: + return spdk_nvmf_session_set_features_keep_alive_timer(req); default: goto passthrough; } diff --git a/lib/nvmf/session.c b/lib/nvmf/session.c index d37c3d729..568b9e477 100644 --- a/lib/nvmf/session.c +++ b/lib/nvmf/session.c @@ -45,6 +45,8 @@ #include "spdk_internal/log.h" +#define MIN_KEEP_ALIVE_TIMEOUT 10000 + static void nvmf_init_discovery_session_properties(struct spdk_nvmf_session *session) { @@ -617,3 +619,36 @@ spdk_nvmf_session_get_features_host_identifier(struct spdk_nvmf_request *req) memcpy(req->data, session->hostid, sizeof(session->hostid)); return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } + +int +spdk_nvmf_session_set_features_keep_alive_timer(struct spdk_nvmf_request *req) +{ + struct spdk_nvmf_session *session = req->conn->sess; + struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd; + struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; + + SPDK_TRACELOG(SPDK_TRACE_NVMF, "Set Features - Keep Alive Timer (%u ms)\n", cmd->cdw11); + + if (cmd->cdw11 == 0) { + rsp->status.sc = SPDK_NVME_SC_KEEP_ALIVE_INVALID; + } else if (cmd->cdw11 < MIN_KEEP_ALIVE_TIMEOUT) { + session->kato = MIN_KEEP_ALIVE_TIMEOUT; + } else { + session->kato = cmd->cdw11; + } + + SPDK_TRACELOG(SPDK_TRACE_NVMF, "Set Features - Keep Alive Timer set to %u ms\n", session->kato); + + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; +} + +int +spdk_nvmf_session_get_features_keep_alive_timer(struct spdk_nvmf_request *req) +{ + struct spdk_nvmf_session *session = req->conn->sess; + struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl; + + SPDK_TRACELOG(SPDK_TRACE_NVMF, "Get Features - Keep Alive Timer\n"); + rsp->cdw0 = session->kato; + return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; +} diff --git a/lib/nvmf/session.h b/lib/nvmf/session.h index 14e892c63..240a04835 100644 --- a/lib/nvmf/session.h +++ b/lib/nvmf/session.h @@ -119,4 +119,7 @@ void spdk_nvmf_session_destruct(struct spdk_nvmf_session *session); int spdk_nvmf_session_set_features_host_identifier(struct spdk_nvmf_request *req); int spdk_nvmf_session_get_features_host_identifier(struct spdk_nvmf_request *req); +int spdk_nvmf_session_set_features_keep_alive_timer(struct spdk_nvmf_request *req); +int spdk_nvmf_session_get_features_keep_alive_timer(struct spdk_nvmf_request *req); + #endif diff --git a/lib/nvmf/virtual.c b/lib/nvmf/virtual.c index f8a0da53e..52bd6dd83 100644 --- a/lib/nvmf/virtual.c +++ b/lib/nvmf/virtual.c @@ -48,7 +48,6 @@ #include "spdk_internal/log.h" -#define MIN_KEEP_ALIVE_TIMEOUT 10000 #define MODEL_NUMBER "SPDK Virtual Controller" #define FW_VERSION "FFFFFFFF" @@ -290,8 +289,7 @@ nvmf_virtual_ctrlr_get_features(struct spdk_nvmf_request *req) response->cdw0 = 1; return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER: - response->cdw0 = session->kato; - return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; + return spdk_nvmf_session_get_features_keep_alive_timer(req); case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION: SPDK_TRACELOG(SPDK_TRACE_NVMF, "Get Features - Async Event Configuration\n"); response->cdw0 = session->async_event_config.raw; @@ -330,14 +328,7 @@ nvmf_virtual_ctrlr_set_features(struct spdk_nvmf_request *req) } return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER: - if (cmd->cdw11 == 0) { - response->status.sc = SPDK_NVME_SC_KEEP_ALIVE_INVALID; - } else if (cmd->cdw11 < MIN_KEEP_ALIVE_TIMEOUT) { - session->kato = MIN_KEEP_ALIVE_TIMEOUT; - } else { - session->kato = cmd->cdw11; - } - return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; + return spdk_nvmf_session_set_features_keep_alive_timer(req); case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION: SPDK_TRACELOG(SPDK_TRACE_NVMF, "Set Features - Async Event Configuration, cdw11 0x%08x\n", cmd->cdw11);