From 8b6f5d54db094f6466bef29c8c2ae8cf78a24f0b Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Mon, 17 Jul 2017 15:45:46 +0800 Subject: [PATCH] bdev,test: move common gpt partition code to autotest_common.sh Change-Id: I261e6ed578335ab091973f7546035e63a00dbbf4 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/369735 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- scripts/autotest_common.sh | 34 ++++++++++++++++++++++++++++++++++ test/lib/bdev/bdev.conf.in | 3 +++ test/lib/bdev/blockdev.sh | 35 ++--------------------------------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index ec9b7ce36..b5fd63702 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -310,5 +310,39 @@ function print_backtrace() { return 0 } +function part_dev_by_gpt () { + if [ $(uname -s) = Linux ] && hash sgdisk; then + conf=$1 + devname=$2 + rootdir=$3 + + if [ ! -e $conf ]; then + return 1 + fi + + cp $conf ${conf}.gpt + echo "[Gpt]" >> ${conf}.gpt + echo " Disable Yes" >> ${conf}.gpt + + modprobe nbd + $rootdir/test/lib/bdev/nbd/nbd -c ${conf}.gpt -b $devname -n /dev/nbd0 & + nbd_pid=$! + echo "Process nbd pid: $nbd_pid" + waitforlisten $nbd_pid 5260 + waitforbdev $devname "python $rootdir/scripts/rpc.py" + + if [ -e /dev/nbd0 ]; then + parted -s /dev/nbd0 mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%' + # change the GUID to SPDK GUID value + sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0 + sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0 + fi + killprocess $nbd_pid + rm -f ${conf}.gpt + fi + + return 0 +} + set -o errtrace trap "trap - ERR; print_backtrace >&2" ERR diff --git a/test/lib/bdev/bdev.conf.in b/test/lib/bdev/bdev.conf.in index bd63771dc..255e7e966 100644 --- a/test/lib/bdev/bdev.conf.in +++ b/test/lib/bdev/bdev.conf.in @@ -15,3 +15,6 @@ [AIO] AIO /dev/ram0 AIO0 + +[Rpc] + Enable Yes diff --git a/test/lib/bdev/blockdev.sh b/test/lib/bdev/blockdev.sh index 9197c433d..074abf1f4 100755 --- a/test/lib/bdev/blockdev.sh +++ b/test/lib/bdev/blockdev.sh @@ -17,39 +17,8 @@ timing_enter bounds $testdir/bdevio/bdevio $testdir/bdev.conf timing_exit bounds -if [ $(uname -s) = Linux ] && hash sgdisk; then - echo "[Rpc]" >> $testdir/bdev.conf - echo " Enable Yes" >> $testdir/bdev.conf - echo "[Gpt]" >> $testdir/bdev.conf - echo " Disable Yes" >> $testdir/bdev.conf - - if grep -q Nvme0 $testdir/bdev.conf; then - modprobe nbd - $testdir/nbd/nbd -c $testdir/bdev.conf -b Nvme0n1 -n /dev/nbd0 & - nbd_pid=$! - echo "Process nbd pid: $nbd_pid" - waitforlisten $nbd_pid 5260 - #if return 1, it will trap, so do not need to consider this case - waitforbdev Nvme0n1 $rootdir/scripts/rpc.py - - if [ -e /dev/nbd0 ]; then - parted -s /dev/nbd0 mklabel gpt mkpart first '0%' '50%' mkpart second '50%' '100%' - # change the partition type GUID to SPDK GUID value - sgdisk -t 1:$SPDK_GPT_GUID /dev/nbd0 - sgdisk -t 2:$SPDK_GPT_GUID /dev/nbd0 - fi - killprocess $nbd_pid - - # enable the gpt module and run nbd again to test get_bdevs and - # bind nbd to the new gpt partition bdev - sed -i'' '/Disable/d' $testdir/bdev.conf - $testdir/nbd/nbd -c $testdir/bdev.conf -b Nvme0n1p1 -n /dev/nbd0 & - nbd_pid=$! - waitforlisten $nbd_pid 5260 - waitforbdev Nvme0n1p1 $rootdir/scripts/rpc.py - $rpc_py get_bdevs - killprocess $nbd_pid - fi +if grep -q Nvme0 $testdir/bdev.conf; then + part_dev_by_gpt $testdir/bdev.conf Nvme0n1 $rootdir fi timing_enter verify