test/nbd: use dd to confirm I/O path is ready

We see a delay, especially in VMs, between when the
block layer reports the nbd device as ready (with
non-zero size) and when I/O will complete successfully
without an -ENOSPC error.

So to compensate, dd the first block of the nbd
device to a temporary file, then check the size of that
file to confirm the nbd device is ready for I/O.
Note that dd with a zero-sized input file will always
complete successfully just with 0 blocks transferred.
So we cannot rely on the return value of dd - we check
the size of the written file instead.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I84ea3b663668a27021619cbee502769af4922937

Reviewed-on: https://review.gerrithub.io/385936
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-11-06 11:33:48 -07:00
parent 2f2288485a
commit fa952fcd5a

View File

@ -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