Commit 76f840c0 authored by Michal Berger's avatar Michal Berger Committed by Jim Harris
Browse files

autotest: Check if nvme devices are in use before the wipe



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


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@gmail.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 8419c294
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -87,6 +87,17 @@ rm -f /var/tmp/spdk*.sock
# Load the kernel driver
./scripts/setup.sh reset

# 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
for dev in $(ls /dev/nvme*n* | grep -v p || true); do
	if ! block_in_use "$dev"; then
		dd if=/dev/zero of="$dev" bs=1M count=1
	fi
done

sync

if [ $(uname -s) = Linux ]; then
	# OCSSD devices drivers don't support IO issues by kernel so
	# detect OCSSD devices and block them (unbind from any driver).
@@ -130,15 +141,6 @@ if [[ $(uname -s) == Linux ]]; then
	nvme_namespace_revert
fi

# 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
for dev in $(ls /dev/nvme*n* | grep -v p || true); do
	dd if=/dev/zero of="$dev" bs=1M count=1
done

sync

timing_exit cleanup

# set up huge pages
+29 −0
Original line number Diff line number Diff line
@@ -316,6 +316,35 @@ ge() { cmp_versions "$1" ">=" "$2"; }
eq() { cmp_versions "$1" "==" "$2"; }
neq() { ! eq "$1" "$2"; }

block_in_use() {
	local block=$1 data pt
	# Skip devices that are in use - simple blkid it to see if
	# there's any metadata (pt, fs, etc.) present on the drive.
	# FIXME: Special case to ignore atari as a potential false
	# positive:
	# https://github.com/spdk/spdk/issues/2079
	# Devices with SPDK's GPT part type are not considered to
	# be in use.

	if "$rootdir/scripts/spdk-gpt.py" "$block"; then
		return 1
	fi

	data=$(blkid "/dev/${block##*/}") || data=none

	if [[ $data == none ]]; then
		return 1
	fi

	pt=$(blkid -s PTTYPE -o value "/dev/${block##*/}") || pt=none

	if [[ $pt == none || $pt == atari ]]; then
		return 1
	fi

	return 0
}

if [[ -e "$CONFIG_WPDK_DIR/bin/wpdk_common.sh" ]]; then
	# Adjust uname to report the operating system as WSL, Msys or Cygwin
	# and the kernel name as Windows. Define kill() to invoke the SIGTERM
+1 −9
Original line number Diff line number Diff line
@@ -175,15 +175,7 @@ min_disk_size=$((1024 ** 3 * 2)) # 2GB
for block in "/sys/block/nvme"*; do
	pci=$(readlink -f "$block/device/device")
	pci=${pci##*/}
	# Skip devices that are in use - simple blkid it to see if
	# there's any metadata (pt, fs, etc.) present on the drive.
	# If the drive's size is less than 2G, skip it as we need
	# something bigger for the tests.
	# FIXME: Special case to ignore atari as a potential false
	# positive:
	# https://github.com/spdk/spdk/issues/2079
	pt=$(blkid -s PTTYPE -o value "/dev/${block##*/}") || pt=none
	if [[ $pt == none || $pt == atari ]] && (($(sec_size_to_bytes "${block##*/}") >= min_disk_size)); then
	if ! block_in_use "${block##*/}" && (($(sec_size_to_bytes "${block##*/}") >= min_disk_size)); then
		blocks+=("${block##*/}")
		blocks_to_pci["${block##*/}"]=$pci
	fi