lib/nvmf: Update spdk_nvmf_qpair_disconnect return value

If the qpair is already in the process of disconnect,
the spdk_nvmf_qpair_disconnect API now return -EINPROGRESS
and doesn't call the callback passed by the user.

Signed-off-by: Alexey Marchuk <alexeymar@nvidia.com>
Change-Id: If996b0496bf15729654d18771756b736e41812ae
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17164
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Michael Haeuptle <michaelhaeuptle@gmail.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Alexey Marchuk 2023-03-13 09:28:25 +01:00 committed by David Ko
parent 49415f8ece
commit b0ef9637e5
3 changed files with 13 additions and 11 deletions

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2016 Intel Corporation. All rights reserved. * Copyright (C) 2016 Intel Corporation. All rights reserved.
* Copyright (c) 2018-2021 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 2018-2021 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/ */
/** \file /** \file
@ -296,6 +296,7 @@ typedef void (*nvmf_qpair_disconnect_cb)(void *ctx);
* *
* \return 0 upon success. * \return 0 upon success.
* \return -ENOMEM if the function specific context could not be allocated. * \return -ENOMEM if the function specific context could not be allocated.
* \return -EINPROGRESS if the qpair is already in the process of disconnect.
*/ */
int spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_cb cb_fn, int spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_cb cb_fn,
void *ctx); void *ctx);

View File

@ -1,7 +1,7 @@
/* SPDX-License-Identifier: BSD-3-Clause /* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2017 Intel Corporation. All rights reserved. * Copyright (C) 2017 Intel Corporation. All rights reserved.
* Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved. * Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/ */
#include "spdk/stdinc.h" #include "spdk/stdinc.h"
@ -131,11 +131,15 @@ _nvmf_ctrlr_disconnect_qpairs_on_pg(struct spdk_io_channel_iter *i, bool include
if (qpair->ctrlr == ctrlr && (include_admin || !nvmf_qpair_is_admin_queue(qpair))) { if (qpair->ctrlr == ctrlr && (include_admin || !nvmf_qpair_is_admin_queue(qpair))) {
rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL); rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL);
if (rc) { if (rc) {
if (rc == -EINPROGRESS) {
rc = 0;
} else {
SPDK_ERRLOG("Qpair disconnect failed\n"); SPDK_ERRLOG("Qpair disconnect failed\n");
return rc; return rc;
} }
} }
} }
}
return rc; return rc;
} }
@ -1001,7 +1005,7 @@ nvmf_ctrlr_association_remove(void *ctx)
if (ctrlr->admin_qpair) { if (ctrlr->admin_qpair) {
rc = spdk_nvmf_qpair_disconnect(ctrlr->admin_qpair, NULL, NULL); rc = spdk_nvmf_qpair_disconnect(ctrlr->admin_qpair, NULL, NULL);
if (rc < 0) { if (rc < 0 && rc != -EINPROGRESS) {
SPDK_ERRLOG("Fail to disconnect admin ctrlr qpair\n"); SPDK_ERRLOG("Fail to disconnect admin ctrlr qpair\n");
assert(false); assert(false);
} }

View File

@ -231,7 +231,7 @@ _nvmf_tgt_disconnect_qpairs(void *ctx)
TAILQ_FOREACH_SAFE(qpair, &group->qpairs, link, qpair_tmp) { TAILQ_FOREACH_SAFE(qpair, &group->qpairs, link, qpair_tmp) {
rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL); rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL);
if (rc) { if (rc && rc != -EINPROGRESS) {
break; break;
} }
} }
@ -1249,10 +1249,7 @@ spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_
struct nvmf_qpair_disconnect_ctx *qpair_ctx; struct nvmf_qpair_disconnect_ctx *qpair_ctx;
if (__atomic_test_and_set(&qpair->disconnect_started, __ATOMIC_RELAXED)) { if (__atomic_test_and_set(&qpair->disconnect_started, __ATOMIC_RELAXED)) {
if (cb_fn) { return -EINPROGRESS;
cb_fn(ctx);
}
return 0;
} }
/* If we get a qpair in the uninitialized state, we can just destroy it immediately */ /* If we get a qpair in the uninitialized state, we can just destroy it immediately */
@ -1595,7 +1592,7 @@ nvmf_poll_group_remove_subsystem_msg(void *ctx)
if ((qpair->ctrlr != NULL) && (qpair->ctrlr->subsys == subsystem)) { if ((qpair->ctrlr != NULL) && (qpair->ctrlr->subsys == subsystem)) {
qpairs_found = true; qpairs_found = true;
rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL); rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL);
if (rc) { if (rc && rc != -EINPROGRESS) {
break; break;
} }
} }