Skip to contentSkip to conversation

remount ro on loopback mount leaves unmountable filesystem behind

BUG David Chinner 4 participants 6 messages May 13, 2008 VFS

lore
Share & tools
lore
#0 lore raw

The following steps will leave an unmountable filesystem behind. This test "works" using ext3 or XFS. XFS version is as follows replacing steps with ext3 specific commands results in the same unmountable filesystem problem:

$ mount -t xfs /dev/sdb6 /mnt/scratch
$ mkdir /mnt/scratch/mnt
$ touch /mnt/scratch/img
$ mkfs.xfs -f -d file,name=/mnt/scratch/img,size=1g
$ mount -t xfs -o loop /mnt/scratch/img /mnt/scratch/mnt

All normal up to here. I can unmount everything just fine.

$ umount /mnt/scratch/mnt
$ umount /mnt/scratch
$

Same thing, but remounting the loop filesystem readonly before unmounting:

$ mount -t xfs /dev/sdb6 /mnt/scratch
$ mkdir /mnt/scratch/mnt
$ touch /mnt/scratch/img
$ mkfs.xfs -f -d file,name=/mnt/scratch/img,size=1g
$ mount -t xfs -o loop /mnt/scratch/img /mnt/scratch/mnt
$ mount -t xfs -o remount,ro /mnt/scratch/img /mnt/scratch/mnt
$ umount /mnt/scratch/mnt
$ umount /mnt/scratch
umount: /mnt/scratch: device is busy
umount: /mnt/scratch: device is busy
$

At this point /mnt/scratch is unmountable. lsof shows no open references to the filesytem, so it would seem to be a reference count leak somewhere....

Reproduced on 2.6.25-rc3 on ia64 and x86_64, and UML on 2.6.26-pre-rc1. Found when changing XFSQA test 073 to host loopback images and mounts mounts on something other than /tmp.

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#1 lore raw
Quoted 13 lines · David Chinner

Same thing, but remounting the loop filesystem readonly before unmounting:

$ mount -t xfs /dev/sdb6 /mnt/scratch
$ mkdir /mnt/scratch/mnt
$ touch /mnt/scratch/img
$ mkfs.xfs -f -d file,name=/mnt/scratch/img,size=1g
$ mount -t xfs -o loop /mnt/scratch/img /mnt/scratch/mnt
$ mount -t xfs -o remount,ro /mnt/scratch/img /mnt/scratch/mnt
$ umount /mnt/scratch/mnt
$ umount /mnt/scratch
umount: /mnt/scratch: device is busy
umount: /mnt/scratch: device is busy

This is a problem in mount, no the kernel. Before the remount the /etc mtab looks something like this:

/qemu/test.img /mnt xfs rw,loop=/dev/loop0 0 0

and after it looks something like this:

/qemu/test.img /mnt xfs ro 0 0

As a workaround do a losetup -d /dev/loop0 after unmounting the filesystem.

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 18 lines · Christoph Hellwig
Quoted 13 lines · David Chinner

Same thing, but remounting the loop filesystem readonly before unmounting:

$ mount -t xfs /dev/sdb6 /mnt/scratch
$ mkdir /mnt/scratch/mnt
$ touch /mnt/scratch/img
$ mkfs.xfs -f -d file,name=/mnt/scratch/img,size=1g
$ mount -t xfs -o loop /mnt/scratch/img /mnt/scratch/mnt
$ mount -t xfs -o remount,ro /mnt/scratch/img /mnt/scratch/mnt
$ umount /mnt/scratch/mnt
$ umount /mnt/scratch
umount: /mnt/scratch: device is busy
umount: /mnt/scratch: device is busy

This is a problem in mount, no the kernel. Before the remount the /etc mtab looks something like this:

Quoted 8 lines

/qemu/test.img /mnt xfs rw,loop=/dev/loop0 0 0

and after it looks something like this:

/qemu/test.img /mnt xfs ro 0 0

As a workaround do a losetup -d /dev/loop0 after unmounting the filesystem.

Hmmm - I even considered that and tried a '-o remount,ro,loop' but that obviously doesn't work with dynamic loop device instantiation, either.

/me didn't read all the way to the bottom of the extremely verbose mount man page so didn't find the bit about losetup -d....

Anyway, I'll hard code loop device numbers into the script so I can just forget about this problem. Thanks, Christoph.

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#3 lore raw
Quoted 2 lines · David Chinner

Anyway, I'll hard code loop device numbers into the script so I can just forget about this problem. Thanks, Christoph.

hardcoding them is a little dangerous because a system might aswell have them in use already, e.g. for CD images. Just use losetup -f to find the first free one and keep it in a shell variable.
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · David Chinner

Anyway, I'll hard code loop device numbers into the script so I can just forget about this problem. Thanks, Christoph.

hardcoding them is a little dangerous because a system might aswell have them in use already, e.g. for CD images. Just use losetup -f to find the first free one and keep it in a shell variable.

losetup -f is racy, too. losetup -sf is safe, however.

-hpa
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Christoph Hellwig
Quoted 15 lines · Christoph Hellwig
Quoted 13 lines · David Chinner

Same thing, but remounting the loop filesystem readonly before unmounting:

$ mount -t xfs /dev/sdb6 /mnt/scratch
$ mkdir /mnt/scratch/mnt
$ touch /mnt/scratch/img
$ mkfs.xfs -f -d file,name=/mnt/scratch/img,size=1g
$ mount -t xfs -o loop /mnt/scratch/img /mnt/scratch/mnt
$ mount -t xfs -o remount,ro /mnt/scratch/img /mnt/scratch/mnt
$ umount /mnt/scratch/mnt
$ umount /mnt/scratch
umount: /mnt/scratch: device is busy
umount: /mnt/scratch: device is busy
Quoted 8 lines

This is a problem in mount, no the kernel. Before the remount the /etc mtab looks something like this:

/qemu/test.img /mnt xfs rw,loop=/dev/loop0 0 0

and after it looks something like this:

/qemu/test.img /mnt xfs ro 0 0

Yes, that's mount(8) bug. It doesn't read old options from /etc/mtab when you remount by "mount -o remount <src> <dest>".

Quoted 2 lines

As a workaround do a losetup -d /dev/loop0 after unmounting the filesystem.

... or use "mount -o remount <dest>", for example:

mount -t xfs -o remount,ro /mnt/scratch/mnt

Karel

Signature · 1 line
 Karel Zak  <[email protected]>