#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2019 Logan Gunthorpe
# Copyright (C) 2019 Eideticom Communications Inc.

. tests/nvme/rc

DESCRIPTION="test NVMe reset command on an NVMeOF target with a passthru controller"
QUICK=1

requires() {
	_nvme_requires
	_have_kernel_option NVME_TARGET_PASSTHRU
}

device_requires() {
	_require_test_dev_is_not_nvme_multipath
}

set_conditions() {
	_set_nvme_trtype "$@"
}

test_device() {
	echo "Running ${TEST_NAME}"

	_setup_nvmet

	local ctrldev
	local nsdev

	_nvmet_passthru_target_setup
	nsdev=$(_nvmet_passthru_target_connect)

	if [[ -z "$nsdev" ]]; then
		echo "FAIL: Failed to find passthru target namespace"
	else
		ctrldev=$(_find_nvme_dev "${def_subsysnqn}")

		if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
			echo "ERROR: reset failed"
		fi
	fi

	_nvme_disconnect_subsys
	_nvmet_passthru_target_cleanup

	echo "Test complete"
}
