bdev/nvme: Clean up bdev_nvme_reset() to clarify the failover case

Swap the resetting case and the non-resetting case. Unlock mutex
before calling spdk_bdev_io_complete(). Use curr_trid instead of
tmp_trid to clarify the meaning of the stored value.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: If3b520a16459aba498ac80ed887b9223ac5ca3d8
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4523
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Mellanox Build Bot
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-10-04 04:55:22 +09:00 committed by Tomasz Zawadzki
parent 5908576131
commit 0004476aac

View File

@ -434,8 +434,6 @@ _bdev_nvme_reset(struct spdk_io_channel_iter *i, int status)
_bdev_nvme_reset_create_qpair,
bio,
_bdev_nvme_reset_create_qpairs_done);
}
static void
@ -458,36 +456,31 @@ bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bi
{
struct spdk_io_channel *ch;
struct nvme_io_channel *nvme_ch;
struct nvme_bdev_ctrlr_trid *next_trid = NULL, *tmp_trid = NULL;
struct nvme_bdev_ctrlr_trid *curr_trid = NULL, *next_trid = NULL;
int rc = 0;
pthread_mutex_lock(&g_bdev_nvme_mutex);
if (nvme_bdev_ctrlr->destruct) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
/* Don't bother resetting if the controller is in the process of being destructed. */
if (bio) {
spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bio), SPDK_BDEV_IO_STATUS_FAILED);
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
return 0;
}
if (failover) {
tmp_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
assert(tmp_trid);
assert(&tmp_trid->trid == nvme_bdev_ctrlr->connected_trid);
next_trid = TAILQ_NEXT(tmp_trid, link);
curr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
assert(curr_trid);
assert(&curr_trid->trid == nvme_bdev_ctrlr->connected_trid);
next_trid = TAILQ_NEXT(curr_trid, link);
if (!next_trid) {
failover = false;
}
}
if (!nvme_bdev_ctrlr->resetting) {
nvme_bdev_ctrlr->resetting = true;
if (failover) {
nvme_bdev_ctrlr->failover_in_progress = true;
}
} else {
if (next_trid && !nvme_bdev_ctrlr->failover_in_progress) {
if (nvme_bdev_ctrlr->resetting) {
if (failover && !nvme_bdev_ctrlr->failover_in_progress) {
rc = -EAGAIN;
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
@ -507,7 +500,10 @@ bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bi
return rc;
}
nvme_bdev_ctrlr->resetting = true;
if (failover) {
nvme_bdev_ctrlr->failover_in_progress = true;
spdk_nvme_ctrlr_fail(nvme_bdev_ctrlr->ctrlr);
nvme_bdev_ctrlr->connected_trid = &next_trid->trid;
rc = spdk_nvme_ctrlr_set_trid(nvme_bdev_ctrlr->ctrlr, &next_trid->trid);
@ -515,8 +511,8 @@ bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bi
/** Shuffle the old trid to the end of the list and use the new one.
* Allows for round robin through multiple connections.
*/
TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, tmp_trid, link);
TAILQ_INSERT_TAIL(&nvme_bdev_ctrlr->trids, tmp_trid, link);
TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, curr_trid, link);
TAILQ_INSERT_TAIL(&nvme_bdev_ctrlr->trids, curr_trid, link);
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);