From f2d98673d7d27dbe28947980066e2c05b3ce1d14 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Mon, 24 Jan 2022 16:36:34 +0100 Subject: [PATCH] scripts/common: set special name to test partitions SPDK test script can fail during any point of the execution. To keep using the same devices between test runs in CI, those devices have to be cleaned between runs. To select device for tests or to clean before tests, the partition table and lack of mount points is used. SPDK GPT partitions were always considered not in use. Meanwhile Linux GPT were not, even if lacking a mount point. Some of the SPDK tests create Linux GPT partitions, which might remain after a test run. Linux GPT partitions created during tests now contain "SPDK_TEST" as part of their partition name. This allows marking such block devices as 'not in use', to be cleaned and used in further SPDK test. fixes #2345 Signed-off-by: Tomasz Zawadzki Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11220 (master) (cherry picked from commit c733cd682facc7b2906f8cc10089c9c0d6684e42) Change-Id: I0098776239da9b0c5dcc748625485284e4863525 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11301 Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- scripts/common.sh | 7 +++++++ test/bdev/blockdev.sh | 2 +- test/nvme/nvme.sh | 2 +- test/vhost/integrity/integrity_vm.sh | 2 +- test/vhost/readonly/disabled_readonly_vm.sh | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index 3bfad54b1..5174487d1 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -342,6 +342,13 @@ block_in_use() { return 1 fi + # Devices used in SPDK tests always create GPT partitions + # with label containing SPDK_TEST string. Such devices were + # part of the tests before, so are not considered in use. + if [[ $pt == gpt ]] && parted "/dev/${block##*/}" -ms print | grep -q "SPDK_TEST"; then + return 1 + fi + return 0 } diff --git a/test/bdev/blockdev.sh b/test/bdev/blockdev.sh index cfdd03db6..8d6cdc9b7 100755 --- a/test/bdev/blockdev.sh +++ b/test/bdev/blockdev.sh @@ -79,7 +79,7 @@ function setup_gpt_conf() { done if [[ -n $gpt_nvme ]]; then # Create gpt partition table - parted -s "$gpt_nvme" mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%' + parted -s "$gpt_nvme" mklabel gpt mkpart SPDK_TEST_first '0%' '50%' mkpart SPDK_TEST_second '50%' '100%' # change the GUID to SPDK GUID value SPDK_GPT_GUID=$(get_spdk_gpt) sgdisk -t "1:$SPDK_GPT_GUID" "$gpt_nvme" diff --git a/test/nvme/nvme.sh b/test/nvme/nvme.sh index 7ba4a7703..7f705e833 100755 --- a/test/nvme/nvme.sh +++ b/test/nvme/nvme.sh @@ -91,7 +91,7 @@ if [ $(uname) = Linux ]; then # just create a 100MB partition - this tests our ability to detect mountpoints # on partitions of the device, not just the device itself; it also is faster # since we don't trim and initialize the whole namespace - parted -s /dev/$blkname mkpart primary 1 100 + parted -s /dev/$blkname mkpart SPDK_TEST 1 100 sleep 1 mkfs.ext4 -F /dev/${blkname}p1 mkdir -p /tmp/nvmetest diff --git a/test/vhost/integrity/integrity_vm.sh b/test/vhost/integrity/integrity_vm.sh index 3fff7eb27..c201f278c 100755 --- a/test/vhost/integrity/integrity_vm.sh +++ b/test/vhost/integrity/integrity_vm.sh @@ -43,7 +43,7 @@ for fs in $fs; do i=$((i + 1)) sleep 0.1 done - $parted_cmd mkpart primary 2048s 100% + $parted_cmd mkpart SPDK_TEST 2048s 100% mkfs_cmd="mkfs.$fs" if [[ $fs == "ntfs" ]] || [[ $fs == "btrfs" ]]; then diff --git a/test/vhost/readonly/disabled_readonly_vm.sh b/test/vhost/readonly/disabled_readonly_vm.sh index 2aec5b80a..92c2c1a39 100755 --- a/test/vhost/readonly/disabled_readonly_vm.sh +++ b/test/vhost/readonly/disabled_readonly_vm.sh @@ -30,7 +30,7 @@ if (($(lsblk -r -n -o RO -d "/dev/$disk_name") == 1)); then fi parted -s /dev/$disk_name mklabel gpt -parted -s /dev/$disk_name mkpart primary 2048s 100% +parted -s /dev/$disk_name mkpart SPDK_TEST 2048s 100% partprobe sleep 0.1