Commit a90f7d98 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Konrad Sztyber
Browse files

bdev/nvme: Relocate bdev_nvme_reset_ctrlr_complete()



The next patch will merge bdev_nvme_reset_ctrlr_complete() and
_bdev_nvme_reset_ctrlr_complete(). This relocation will be helpful to
reduce the size of the next patch.

bdev_nvme_disable_ctrlr_complete() will have the same change in the next
patch. Relocate bdev_nvme_disable_ctrlr_complete() in this patch too.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I7a337c228041a1c84085c100f485a6d32a727925
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25320


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
parent 6eb2657a
Loading
Loading
Loading
Loading
+55 −51
Original line number Diff line number Diff line
@@ -2231,6 +2231,49 @@ bdev_nvme_start_reconnect_delay_timer(struct nvme_ctrlr *nvme_ctrlr)

static void remove_discovery_entry(struct nvme_ctrlr *nvme_ctrlr);

static void _bdev_nvme_reset_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status);

static void
bdev_nvme_reset_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, bool success)
{
	pthread_mutex_lock(&nvme_ctrlr->mutex);
	if (!success) {
		/* Connecting the active trid failed. Set the next alternate trid to the
		 * active trid if it exists.
		 */
		if (bdev_nvme_failover_trid(nvme_ctrlr, false, false)) {
			/* The next alternate trid exists and is ready to try. Try it now. */
			pthread_mutex_unlock(&nvme_ctrlr->mutex);

			NVME_CTRLR_INFOLOG(nvme_ctrlr, "Try the next alternate trid %s:%s now.\n",
					   nvme_ctrlr->active_path_id->trid.traddr,
					   nvme_ctrlr->active_path_id->trid.trsvcid);

			nvme_ctrlr_disconnect(nvme_ctrlr, bdev_nvme_reconnect_ctrlr);
			return;
		}

		/* We came here if there is no alternate trid or if the next trid exists but
		 * is not ready to try. We will try the active trid after reconnect_delay_sec
		 * seconds if it is non-zero or at the next reset call otherwise.
		 */
	} else {
		/* Connecting the active trid succeeded. Clear the last failed time because it
		 * means the trid is failed if its last failed time is non-zero.
		 */
		nvme_ctrlr->active_path_id->last_failed_tsc = 0;
	}
	pthread_mutex_unlock(&nvme_ctrlr->mutex);

	NVME_CTRLR_INFOLOG(nvme_ctrlr, "Clear pending resets.\n");

	/* Make sure we clear any pending resets before returning. */
	nvme_ctrlr_for_each_channel(nvme_ctrlr,
				    bdev_nvme_complete_pending_resets,
				    success ? NULL : (void *)0x1,
				    _bdev_nvme_reset_ctrlr_complete);
}

static void
_bdev_nvme_reset_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status)
{
@@ -2284,47 +2327,6 @@ _bdev_nvme_reset_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int st
	}
}

static void
bdev_nvme_reset_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, bool success)
{
	pthread_mutex_lock(&nvme_ctrlr->mutex);
	if (!success) {
		/* Connecting the active trid failed. Set the next alternate trid to the
		 * active trid if it exists.
		 */
		if (bdev_nvme_failover_trid(nvme_ctrlr, false, false)) {
			/* The next alternate trid exists and is ready to try. Try it now. */
			pthread_mutex_unlock(&nvme_ctrlr->mutex);

			NVME_CTRLR_INFOLOG(nvme_ctrlr, "Try the next alternate trid %s:%s now.\n",
					   nvme_ctrlr->active_path_id->trid.traddr,
					   nvme_ctrlr->active_path_id->trid.trsvcid);

			nvme_ctrlr_disconnect(nvme_ctrlr, bdev_nvme_reconnect_ctrlr);
			return;
		}

		/* We came here if there is no alternate trid or if the next trid exists but
		 * is not ready to try. We will try the active trid after reconnect_delay_sec
		 * seconds if it is non-zero or at the next reset call otherwise.
		 */
	} else {
		/* Connecting the active trid succeeded. Clear the last failed time because it
		 * means the trid is failed if its last failed time is non-zero.
		 */
		nvme_ctrlr->active_path_id->last_failed_tsc = 0;
	}
	pthread_mutex_unlock(&nvme_ctrlr->mutex);

	NVME_CTRLR_INFOLOG(nvme_ctrlr, "Clear pending resets.\n");

	/* Make sure we clear any pending resets before returning. */
	nvme_ctrlr_for_each_channel(nvme_ctrlr,
				    bdev_nvme_complete_pending_resets,
				    success ? NULL : (void *)0x1,
				    _bdev_nvme_reset_ctrlr_complete);
}

static void
bdev_nvme_reset_create_qpairs_failed(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status)
{
@@ -2666,6 +2668,18 @@ bdev_nvme_enable_ctrlr(struct nvme_ctrlr *nvme_ctrlr)
	return 0;
}

static void _bdev_nvme_disable_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status);

static void
bdev_nvme_disable_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr)
{
	/* Make sure we clear any pending resets before returning. */
	nvme_ctrlr_for_each_channel(nvme_ctrlr,
				    bdev_nvme_complete_pending_resets,
				    NULL,
				    _bdev_nvme_disable_ctrlr_complete);
}

static void
_bdev_nvme_disable_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status)
{
@@ -2704,16 +2718,6 @@ _bdev_nvme_disable_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int

}

static void
bdev_nvme_disable_ctrlr_complete(struct nvme_ctrlr *nvme_ctrlr)
{
	/* Make sure we clear any pending resets before returning. */
	nvme_ctrlr_for_each_channel(nvme_ctrlr,
				    bdev_nvme_complete_pending_resets,
				    NULL,
				    _bdev_nvme_disable_ctrlr_complete);
}

static void
bdev_nvme_disable_destroy_qpairs_done(struct nvme_ctrlr *nvme_ctrlr, void *ctx, int status)
{