From 76f840c0498726e2e80fadbd57414fc9476b16f3 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Wed, 25 Aug 2021 12:50:55 +0200 Subject: [PATCH] autotest: Check if nvme devices are in use before the wipe Signed-off-by: Michal Berger Change-Id: I4f838df0bfb91398eb5d179a982165adb8af3476 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9291 Reviewed-by: Konrad Sztyber Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins --- autotest.sh | 20 +++++++++++--------- scripts/common.sh | 29 +++++++++++++++++++++++++++++ test/setup/devices.sh | 10 +--------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/autotest.sh b/autotest.sh index 54bc986b6..f4dbffdf7 100755 --- a/autotest.sh +++ b/autotest.sh @@ -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 diff --git a/scripts/common.sh b/scripts/common.sh index edd5fa5f5..7d867996a 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -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 diff --git a/test/setup/devices.sh b/test/setup/devices.sh index df196f5d0..861437835 100755 --- a/test/setup/devices.sh +++ b/test/setup/devices.sh @@ -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