Skip to contentSkip to conversation

Fix for loop mounting of readonly images

PATCH Applied Daniel P. Berrange 2 participants 2 messages Feb 2, 2007 – Feb 6, 2007

lore
Share & tools
lore
#0 lore raw

We hit an wierd edge case when booting a fullyvirt guest VM off an ISO image stored on NFS, where the hotplug scripts would fail to map the ISO to the backend. This only happened if the ISO image was marked readonly, but on a read-write NFS mount. It worked fine on a readonly NFS mount!

After a little debugging appears that losetup was failing with:

# mount -orw nfs1:/some/path /mnt
# strace -e trace=open losetup /dev/loop0  /mnt/rhel4-i386-AS/images/boot.iso 2>&1 | grep boot.iso
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDWR) = -1 EACCES (Permission denied)
/mnt/rhel4-i386-AS/images/boot.iso: Permission denied

When the NFS mount is mounted read-only it works, because it falls back to setting up a readonly loop device:

# mount -oro nfs1:/some/path /mnt
# strace -e trace=open losetup /dev/loop0  /mnt/rhel4-i386-AS/images/boot.iso 2>&1 | grep boot.iso
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDWR) = -1 EROFS (Read-only file system)
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDONLY) = 3

Which made me wonder - why don't we request a readonly loopdevice in the first place, given that the ISO is being exported read-only to the guest.

So I'm ataching a patch to teh block hotplug scripts which will automatically pass the '-r' option to losetup if the device sharing mode is 'r'

Regards,
Dan.

Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
tools/examples/block +7 -1
diff -r 2e80cd715047 tools/examples/block
@@ -367,7 +367,13 @@ mount it read-write in a guest domain."
           fatal 'Failed to find an unused loop device'
         fi
 
-        do_or_die losetup "$loopdev" "$file"
+        cmode=`canonicalise_mode $mode`
+        if [ "$cmode" == 'r' ]
+        then
+          do_or_die losetup -r "$loopdev" "$file"
+        else
+          do_or_die losetup "$loopdev" "$file"
+        fi
         xenstore_write "$XENBUS_PATH/node" "$loopdev"
         write_dev "$loopdev"
         release_lock "block"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Applied
#1 lore raw
Quoted 20 lines · Daniel P. Berrange

We hit an wierd edge case when booting a fullyvirt guest VM off an ISO image stored on NFS, where the hotplug scripts would fail to map the ISO to the backend. This only happened if the ISO image was marked readonly, but on a read-write NFS mount. It worked fine on a readonly NFS mount!

After a little debugging appears that losetup was failing with:

# mount -orw nfs1:/some/path /mnt
# strace -e trace=open losetup /dev/loop0  /mnt/rhel4-i386-AS/images/boot.iso 2>&1 | grep boot.iso
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDWR) = -1 EACCES (Permission denied)
/mnt/rhel4-i386-AS/images/boot.iso: Permission denied

When the NFS mount is mounted read-only it works, because it falls back to setting up a readonly loop device:

# mount -oro nfs1:/some/path /mnt
# strace -e trace=open losetup /dev/loop0  /mnt/rhel4-i386-AS/images/boot.iso 2>&1 | grep boot.iso
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDWR) = -1 EROFS (Read-only file system)
open("/mnt/rhel4-i386-AS/images/boot.iso", O_RDONLY) = 3
Quoted 7 lines

Which made me wonder - why don't we request a readonly loopdevice in the first place, given that the ISO is being exported read-only to the guest.

So I'm ataching a patch to teh block hotplug scripts which will automatically pass the '-r' option to losetup if the device sharing mode is 'r'

Applied, thank you.

Ewan.