Commit 685dfa0a authored by Michal Berger's avatar Michal Berger Committed by Konrad Sztyber
Browse files

test/nvme/cuse: Create common wrapper around OACS



Use it in the nvme_cli_cuse to make sure proper drive was selected
for the test (i.e. supporting ns management) - some of the nvmes
installed in the CI pool don't support ns management, hence all
related commands fail as part of these tests.

Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Change-Id: Ib93933d7ee9b0d2eb283313d3f2bbb6f4af727a4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17079


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent a18050e8
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -118,3 +118,46 @@ get_active_lbaf() {
	done
	return 1
}

get_oacs() {
	local ctrl=${1:-nvme0} bit=${2:-nsmgt}
	local -A bits

	# Figure 275: Identify – Identify Controller Data Structure, I/O Command Set Independent
	bits["ss/sr"]=$((1 << 0))
	bits["fnvme"]=$((1 << 1))
	bits["fc/fi"]=$((1 << 2))
	bits["nsmgt"]=$((1 << 3))
	bits["self-test"]=$((1 << 4))
	bits["directives"]=$((1 << 5))
	bits["nvme-mi-s/r"]=$((1 << 6))
	bits["virtmgt"]=$((1 << 7))
	bits["doorbellbuf"]=$((1 << 8))
	bits["getlba"]=$((1 << 9))
	bits["commfeatlock"]=$((1 << 10))

	bit=${bit,,}
	[[ -n ${bits["$bit"]} ]] || return 1

	(($(get_nvme_ctrl_feature "$ctrl" oacs) & bits["$bit"]))
}

get_nvmes_with_ns_management() {
	((${#ctrls[@]} == 0)) && scan_nvme_ctrls

	local ctrl
	for ctrl in "${!ctrls[@]}"; do
		get_oacs "$ctrl" nsmgt && echo "$ctrl"
	done
}

get_nvme_with_ns_management() {
	local _ctrls

	_ctrls=($(get_nvmes_with_ns_management))
	if ((${#_ctrls[@]} > 0)); then
		echo "${_ctrls[0]}"
		return 0
	fi
	return 1
}
+1 −6
Original line number Diff line number Diff line
@@ -11,12 +11,7 @@ $rootdir/scripts/setup.sh reset
scan_nvme_ctrls

# Find bdf that supports Namespace Management
for ctrl in "${!ctrls[@]}"; do
	# Check Optional Admin Command Support for Namespace Management
	(($(get_nvme_ctrl_feature "$ctrl" oacs) & 0x8)) && nvme_name=$ctrl && break
done

if [[ -z $nvme_name ]]; then
if ! nvme_name=$(get_nvme_with_ns_management); then
	echo "No NVMe device supporting Namespace management found"
	$rootdir/scripts/setup.sh
	exit 1
+6 −7
Original line number Diff line number Diff line
@@ -5,8 +5,7 @@
#
testdir=$(readlink -f $(dirname $0))
rootdir=$(readlink -f $testdir/../../..)
source $rootdir/scripts/common.sh
source $rootdir/test/common/autotest_common.sh
source "$testdir/common.sh"

rm -Rf $testdir/match_files
mkdir $testdir/match_files
@@ -17,17 +16,17 @@ CUSE_OUT=$testdir/match_files/cuse.out
NVME_CMD=/usr/local/src/nvme-cli/nvme
rpc_py=$rootdir/scripts/rpc.py

bdf=$(get_first_nvme_bdf)
"$rootdir/scripts/setup.sh" reset
scan_nvme_ctrls

PCI_ALLOWED="${bdf}" $rootdir/scripts/setup.sh reset
nvme_name=$(get_nvme_ctrlr_from_bdf ${bdf})
if [[ -z "$nvme_name" ]]; then
	echo "setup.sh failed bind kernel driver to ${bdf}"
if ! nvme_name=$(get_nvme_with_ns_management); then
	echo "Failed to find suitable nvme for the test" >&2
	return 1
fi

ctrlr="/dev/${nvme_name}"
ns="/dev/${nvme_name}n1"
bdf=${bdfs["$nvme_name"]}

waitforblk "${nvme_name}n1"