Commit fe9a8fab authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: Factor out set callback and call ctrlr_disconnect() into a helper function



The following patches will swap the ordering of destroying I/O qpairs
and disconnecting a controller for PCIe transport to fix a github issue.

Setting callback and calling spdk_nvme_ctrlr_disconnect() have been
executed in two cases now.

After the following patches, these will be executed in three cases.

Factoring out these into a helper function will be rewarded.

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


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarMichael Haeuptle <michaelhaeuptle@gmail.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 91165150
Loading
Loading
Loading
Loading
+21 −20
Original line number Diff line number Diff line
@@ -1516,6 +1516,25 @@ bdev_nvme_check_fast_io_fail_timeout(struct nvme_ctrlr *nvme_ctrlr)
	}
}

static void
nvme_ctrlr_disconnect(struct nvme_ctrlr *nvme_ctrlr, nvme_ctrlr_disconnected_cb cb_fn)
{
	int rc __attribute__((unused));

	/* spdk_nvme_ctrlr_disconnect() may complete asynchronously later by polling adminq.
	 * Set callback here to execute the specified operation after ctrlr is really disconnected.
	 */
	assert(nvme_ctrlr->disconnected_cb == NULL);
	nvme_ctrlr->disconnected_cb = cb_fn;

	/* Disconnect fails if ctrlr is already resetting or removed. Both cases are
	 * not possible. Reset is controlled and the callback to hot remove is called
	 * when ctrlr is hot removed.
	 */
	rc = spdk_nvme_ctrlr_disconnect(nvme_ctrlr->ctrlr);
	assert(rc == 0);
}

enum bdev_nvme_op_after_reset {
	OP_NONE,
	OP_COMPLETE_PENDING_DESTRUCT,
@@ -1636,13 +1655,7 @@ _bdev_nvme_reset_complete(struct spdk_io_channel_iter *i, int status)
		_bdev_nvme_delete(nvme_ctrlr, false);
		break;
	case OP_DELAYED_RECONNECT:
		/* spdk_nvme_ctrlr_disconnect() may complete asynchronously later by polling adminq.
		 * Set callback here to start reconnect delay timer after ctrlr is really disconnected.
		 */
		assert(nvme_ctrlr->disconnected_cb == NULL);
		nvme_ctrlr->disconnected_cb = bdev_nvme_start_reconnect_delay_timer;

		spdk_nvme_ctrlr_disconnect(nvme_ctrlr->ctrlr);
		nvme_ctrlr_disconnect(nvme_ctrlr, bdev_nvme_start_reconnect_delay_timer);
		break;
	default:
		break;
@@ -1760,22 +1773,10 @@ static void
bdev_nvme_reset_ctrlr(struct spdk_io_channel_iter *i, int status)
{
	struct nvme_ctrlr *nvme_ctrlr = spdk_io_channel_iter_get_io_device(i);
	int rc __attribute__((unused));

	assert(status == 0);

	/* spdk_nvme_ctrlr_disconnect() may complete asynchronously later by polling adminq.
	 * Set callback here to reconnect after ctrlr is really disconnected.
	 */
	assert(nvme_ctrlr->disconnected_cb == NULL);
	nvme_ctrlr->disconnected_cb = bdev_nvme_reconnect_ctrlr;

	/* Disconnect fails if ctrlr is already resetting or removed. Both cases are
	 * not possible. Reset is controlled and the callback to hot remove is called
	 * when ctrlr is hot removed.
	 */
	rc = spdk_nvme_ctrlr_disconnect(nvme_ctrlr->ctrlr);
	assert(rc == 0);
	nvme_ctrlr_disconnect(nvme_ctrlr, bdev_nvme_reconnect_ctrlr);
}

static void