]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commit
libext2fs: check open(O_EXCL) first in ismounted.c
authorLukas Czerner <lczerner@redhat.com>
Tue, 3 Mar 2020 13:53:48 +0000 (14:53 +0100)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 7 Mar 2020 17:50:02 +0000 (12:50 -0500)
commitca84539d5fa32061fa1ea09296990b30866f1f84
tree81bee253ed5ee337439c0bbdc1406f53df1a0551
parentf106b01c98d7abc12af39aad4024f17ffa14dc06
libext2fs: check open(O_EXCL) first in ismounted.c

Currently the ext2fs_check_mount_point() will use the open(O_EXCL) check
on linux after all the other checks are done. However it is not
necessary to check mntent if open(O_EXCL) succeeds because it means that
the device is not mounted.

Moreover the commit ea4d53b7 introduced a regression where a following
set of commands fails:

vgcreate mygroup /dev/sda
lvcreate -L 1G -n lvol0 mygroup
mkfs.ext4 /dev/mygroup/lvol0
mount /dev/mygroup/lvol0 /mnt
lvrename /dev/mygroup/lvol0 /dev/mygroup/lvol1
lvcreate -L 1G -n lvol0 mygroup
mkfs.ext4 /dev/mygroup/lvol0   <<<--- This fails

It fails because it thinks that /dev/mygroup/lvol0 is mounted because
the device name in /proc/mounts is not updated following the lvrename.

Move the open(O_EXCL) check before the mntent check and return
immediatelly if the device is not busy.

Fixes: ea4d53b7 ("libext2fs/ismounted.c: check device id in advance to skip false device names")
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
Reported-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ismounted.c