diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index 1976d6a4a..d81bd44df 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -207,6 +207,22 @@ function waitfornbd() { for ((i=1; i<=20; i++)); do if grep -q -w $nbd_name /proc/partitions; then + break + else + sleep 0.1 + fi + done + + # The nbd device is now recognized as a block device, but there can be + # a small delay before we can start I/O to that block device. So loop + # here trying to read the first block of the nbd block device to a temp + # file. Note that dd returns success when reading an empty file, so we + # need to check the size of the output file instead. + for ((i=1; i<=20; i++)); do + dd if=/dev/$nbd_name of=/tmp/nbdtest bs=4096 count=1 iflag=direct + size=`stat -c %s /tmp/nbdtest` + rm -f /tmp/nbdtest + if [ "$size" != "0" ]; then return 0 else sleep 0.1