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