]> xenbits.xensource.com Git - people/vhanquez/xen.git/commitdiff
tools/examples/block better use of losetup -r
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 24 Jan 2008 14:58:25 +0000 (14:58 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 24 Jan 2008 14:58:25 +0000 (14:58 +0000)
Use losetup -r when the vbd is specified to be readonly, but only if
-r is supported (rather than always creating a writeable losetup
mapping if possible).

This was inspired by (but not derived from) a diff from the Fedora 8
patchset which uses -r iff the vbd is specified as readonly.  We need
to be cleverer upstream because not all systems have losetup -r.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
xen-unstable changeset:   16642:643ab64d12d5ce57e5f1e08f85ab4bb7fbc136ae
xen-unstable date:        Wed Dec 19 15:05:15 2007 +0000

tools/examples/block

index a058f5c3081c4c58531fbf8b3b647548e9eb5a7e..566a8acba376cfef58b6cf27d91bb1441c847e79 100644 (file)
@@ -367,10 +367,13 @@ mount it read-write in a guest domain."
           fatal 'Failed to find an unused loop device'
         fi
 
-        status=$(losetup "$loopdev" "$file" || echo "failed")
-        if [ -n "$status" ]; then
-          do_or_die losetup -r "$loopdev" "$file"
+        if LANG=C losetup -h 2>&1 | grep read-only >/dev/null
+        then
+          roflag="-$mode"; roflag="${roflag#-w}"
+        else
+          roflag=''
         fi
+        do_or_die losetup $roflag "$loopdev" "$file"
         xenstore_write "$XENBUS_PATH/node" "$loopdev"
         write_dev "$loopdev"
         release_lock "block"