Commit 4c21ef36 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

test/cuse: revert NVMe namespaces to default state



If for any reason the cuse tests do not revert state
of NVMe namespaces to the original state, the test
machines would be stuck in until manual intervention.

Assumed default state is single namespace,
encompassing available space formatted as 4k block size.

This patch adds nvme_namespace_revert(), which
searches for NVMe devices that support Namespace Managment
and have some space unallocated.
When such device is found, all existing namespaces are removed
and single one created.

Fix #1435

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: Ifc3b04b3f166bf450b884674fa6a482e2fbc4c29
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2829


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent d5eb5835
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ if [ $(uname -s) = Linux ]; then
	fi
fi

# Revert NVMe namespaces to default state
nvme_namespace_revert

# Delete all leftover lvols and gpt partitions
# Matches both /dev/nvmeXnY on Linux and /dev/nvmeXnsY on BSD
# Filter out nvme with partitions - the "p*" suffix
+42 −0
Original line number Diff line number Diff line
@@ -1212,6 +1212,48 @@ function get_first_nvme_bdf() {
	head -1 <<< "$(get_nvme_bdfs)"
}

function nvme_namespace_revert() {
	$rootdir/scripts/setup.sh
	sleep 1
	bdfs=$(get_nvme_bdfs)

	$rootdir/scripts/setup.sh reset
	sleep 1

	for bdf in $bdfs; do
		nvme_ctrlr=/dev/$(get_nvme_ctrlr_from_bdf ${bdf})
		if [[ -z "$nvme_ctrlr" ]]; then
			continue
		fi

		# Check Optional Admin Command Support for Namespace Management
		oacs=$(nvme id-ctrl ${nvme_ctrlr} | grep oacs | cut -d: -f2)
		oacs_ns_manage=$((oacs & 0x8))

		if [[ "$oacs_ns_manage" -ne 0 ]]; then
			# This assumes every NVMe controller contains single namespace,
			# encompassing Total NVM Capacity and formatted as 4k block size.

			unvmcap=$(nvme id-ctrl ${nvme_ctrlr} | grep unvmcap | cut -d: -f2)
			if [[ "$unvmcap" -eq 0 ]]; then
				# All available space already used
				continue
			fi
			tnvmcap=$(nvme id-ctrl ${nvme_ctrlr} | grep tnvmcap | cut -d: -f2)
			blksize=4096

			size=$((tnvmcap / blksize))

			nvme detach-ns ${nvme_ctrlr} -n 0xffffffff -c 0 || true
			nvme delete-ns ${nvme_ctrlr} -n 0xffffffff || true
			nvme create-ns ${nvme_ctrlr} -s ${size} -c ${size} -b ${blksize}
			nvme attach-ns ${nvme_ctrlr} -n 1 -c 0
			nvme reset ${nvme_ctrlr}
			waitforblk "${nvme_ctrlr}n1"
		fi
	done
}

# Define temp storage for all the tests. Look for 2GB at minimum
set_test_storage "${TEST_MIN_STORAGE_SIZE:-$((1 << 31))}"