Index: xen-unstable/tools/examples/block =================================================================== --- xen-unstable.orig/tools/examples/block +++ xen-unstable/tools/examples/block @@ -274,9 +274,12 @@ case "$command" in mount it read-write in a guest domain." fi - loopdev='' - for dev in /dev/loop* + losetup_failure=1 + for do_losetup in 1 2 3 do + loopdev='' + for dev in /dev/loop* + do if [ ! -b "$dev" ] then continue @@ -360,14 +363,20 @@ mount it read-write in a guest domain." loopdev="$dev" fi fi - done + done + + if [ "$loopdev" = '' ] + then + fatal 'Failed to find an unused loop device' + fi - if [ "$loopdev" = '' ] + losetup "$loopdev" "$file" && losetup_failure="" && break + done + if [ "$losetup_failure" ] then - fatal 'Failed to find an unused loop device' + fatal 'losetup $loopdev $file' fi - do_or_die losetup "$loopdev" "$file" xenstore_write "$XENBUS_PATH/node" "$loopdev" write_dev "$loopdev" release_lock "block" @@ -390,8 +399,18 @@ mount it read-write in a guest domain." file) node=$(xenstore_read "$XENBUS_PATH/node") - losetup -d "$node" - exit 0 + + #In case the loopback is temporarily blocked, retry the losetup -d. + for i in 1 2 3 4 5 + do + if losetup -d "$node" + then + exit 0 + fi + sleep 1 + done + log err "losetup -d $node failed." + exit 1 ;; "")