nvme: Update spdk_nvme_wait_for_completion_robust_lock error handling

Update error handling of spdk_nvme_wait_for_completion_robust_lock to
differentiate cases when request is completed (possibly with error)
or polling was aborted by transport/device error
The function returns 0 on success, -ECANCELED if transport/device
error occurred and -EIO if the request is completed with error

Change-Id: Ibf7f3c330317af0d8f27ba9cd10d8b773f6a796b
Signed-off-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/481529
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Alexey Marchuk 2020-01-10 16:51:11 +03:00 committed by Tomasz Zawadzki
parent 9ad2046ae1
commit 52f1e4b029
2 changed files with 27 additions and 6 deletions

View File

@ -103,7 +103,9 @@ nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl)
* \param status completion status * \param status completion status
* \param robust_mutex optional robust mutex to lock while polling qpair * \param robust_mutex optional robust mutex to lock while polling qpair
* *
* \return 0 if command completed without error, negative errno on failure * \return 0 if command completed without error,
* -EIO if command completed with error,
* -ECANCELED if command is not completed due to transport/device error
* *
* The command to wait upon must be submitted with nvme_completion_poll_cb as the callback * The command to wait upon must be submitted with nvme_completion_poll_cb as the callback
* and status as the callback argument. * and status as the callback argument.
@ -116,21 +118,24 @@ spdk_nvme_wait_for_completion_robust_lock(
{ {
memset(&status->cpl, 0, sizeof(status->cpl)); memset(&status->cpl, 0, sizeof(status->cpl));
status->done = false; status->done = false;
int rc;
while (status->done == false) { while (status->done == false) {
if (robust_mutex) { if (robust_mutex) {
nvme_robust_mutex_lock(robust_mutex); nvme_robust_mutex_lock(robust_mutex);
} }
if (spdk_nvme_qpair_process_completions(qpair, 0) < 0) { rc = spdk_nvme_qpair_process_completions(qpair, 0);
status->done = true;
status->cpl.status.sct = SPDK_NVME_SCT_GENERIC;
status->cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
}
if (robust_mutex) { if (robust_mutex) {
nvme_robust_mutex_unlock(robust_mutex); nvme_robust_mutex_unlock(robust_mutex);
} }
if (rc < 0) {
status->cpl.status.sct = SPDK_NVME_SCT_GENERIC;
status->cpl.status.sc = SPDK_NVME_SC_ABORTED_SQ_DELETION;
return -ECANCELED;
}
} }
return spdk_nvme_cpl_is_error(&status->cpl) ? -EIO : 0; return spdk_nvme_cpl_is_error(&status->cpl) ? -EIO : 0;

View File

@ -1257,6 +1257,22 @@ test_nvme_wait_for_completion(void)
rc = spdk_nvme_wait_for_completion_timeout(&qpair, &g_status, timeout_in_secs); rc = spdk_nvme_wait_for_completion_timeout(&qpair, &g_status, timeout_in_secs);
CU_ASSERT(g_status.done == true); CU_ASSERT(g_status.done == true);
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
/* spdk_nvme_wait_for_completion */
/* spdk_nvme_qpair_process_completions returns error */
g_process_comp_result = -1;
rc = spdk_nvme_wait_for_completion(&qpair, &g_status);
CU_ASSERT(rc == -ECANCELED);
CU_ASSERT(g_status.done == false);
CU_ASSERT(g_status.cpl.status.sct == SPDK_NVME_SCT_GENERIC);
CU_ASSERT(g_status.cpl.status.sc == SPDK_NVME_SC_ABORTED_SQ_DELETION);
g_process_comp_result = 0;
/* successful completion */
rc = spdk_nvme_wait_for_completion(&qpair, &g_status);
CU_ASSERT(rc == 0);
CU_ASSERT(g_status.done == true);
} }
static void static void