manage-vdi: Wait until devices have been created before mounting

kpartx creates partition devices asynchronously - it may exit before
the devices have been created.  This may cause a subsequent mount call
to fail, because the device it is trying to mount does not yet exist.
kpartx now has a -s option which makes it wait for the devices to be
created before returning, but the version XenServer's dom0 doesn't have
this option.   Work around this by retrying the mount.

When dom0's kpartx is updated, we will be able to use the -s option.

Change-Id: I823a8eac4f3a2ef313d06e21da0f38ed46d7386a
diff --git a/tools/xen/scripts/manage-vdi b/tools/xen/scripts/manage-vdi
index 05c4b07..6dcb211 100755
--- a/tools/xen/scripts/manage-vdi
+++ b/tools/xen/scripts/manage-vdi
@@ -41,7 +41,17 @@
        echo "Failed to find mapping"
        exit -1
     fi
-    echo "/dev/mapper/${mapping}"
+
+    local device="/dev/mapper/${mapping}"
+    for (( i = 0; i < 5; i++ )) ; do
+        if [ -b $device ] ; then
+            echo $device
+            return
+        fi
+        sleep 1
+    done
+    echo "ERROR: timed out waiting for dev-mapper"
+    exit 1
   else
     echo "/dev/$dev$part"
   fi