Skip to contentSkip to conversation

about test mount/rlimit

DISCUSSION Ruediger Meier 3 participants 5 messages Apr 1, 2015 – Apr 2, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hi,

Some questions regarding test mount/rlimit which runs only if /etc/mtab is a file.

This is the umount subtest:

.......
ts_init_subtest "umount"
[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null OLD_SUM=$(mtab_checksum)
(
ulimit -f 1
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
) &> /dev/null
NEW_SUM=$(mtab_checksum)
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
ts_finalize_subtest
...........

I do not fully understand what is expected. Obviously the first "umount" should NOT modify /etc/mtab. But should it umount or not, or doesn't matter? Why we call a second umount then?

The problem is that in case that the first umount works we are leaving the test with a broken mtab file. This is not nice and also problematic because later tests may find a mounted /dev/loop0 in /etc/mtab.

Should we restore the original mtab? I guess it's a bit unsafe to copy back a backed up one. Or is there a way to "repair/sync" from /proc/mounts.?

cu,
Rudi

maintainer
#1 lore raw
Quoted 15 lines · Ruediger Meier

ts_init_subtest "umount"
[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null OLD_SUM=$(mtab_checksum)
(
ulimit -f 1
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
) &> /dev/null
NEW_SUM=$(mtab_checksum)
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
ts_finalize_subtest
...........

Quoted 3 lines

I do not fully understand what is expected. Obviously the first "umount" should NOT modify /etc/mtab. But should it umount or not, or doesn't matter? Why we call a second umount then?

I guess the second umount is just copy & past (from mount test) and it's there to be sure that the device has been really unmounted (and this is unnecessary because ts_device_deinit() calls umount too).

Quoted 3 lines

The problem is that in case that the first umount works we are leaving the test with a broken mtab file. This is not nice and also problematic because later tests may find a mounted /dev/loop0 in /etc/mtab.

It would be probably better to replace the second umount with "umount --fake" to only remove entry from mtab.

Quoted 3 lines

Should we restore the original mtab? I guess it's a bit unsafe to copy back a backed up one. Or is there a way to "repair/sync" from /proc/mounts.?

Don't use /proc/mounts. It's bad idea as the files maybe very different.

use the --fake or you can try to redirect libmount to use non-standard mtab by env. variable LIBMOUNT_MTAB=, but it will increase complexity of the test.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 16 lines · Karel Zak
Quoted 15 lines · Ruediger Meier

ts_init_subtest "umount"
[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null OLD_SUM=$(mtab_checksum)
(
ulimit -f 1
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
) &> /dev/null
NEW_SUM=$(mtab_checksum)
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
ts_finalize_subtest
...........

Quoted 5 lines
Quoted 3 lines

I do not fully understand what is expected. Obviously the first "umount" should NOT modify /etc/mtab. But should it umount or not, or doesn't matter? Why we call a second umount then?

I guess the second umount is just copy & past (from mount test) and

Ah, now it makes sense. So the first umount should work and we could check "ismounted" too.
BTW could it be that in past "umount" always removed the mtab entry like "--fake" still does for umounted devices?

Quoted 11 lines

it's there to be sure that the device has been really unmounted (and this is unnecessary because ts_device_deinit() calls umount too).

Quoted 4 lines

The problem is that in case that the first umount works we are leaving the test with a broken mtab file. This is not nice and also problematic because later tests may find a mounted /dev/loop0 in /etc/mtab.

It would be probably better to replace the second umount with "umount --fake" to only remove entry from mtab.

Ah that's good. I'll send a patch with some other fixes later. The umount part would look like this:

$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
) &> /dev/null
NEW_SUM=$(mtab_checksum)
-$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
+ts_is_mounted $DEVICE && echo "FAIL: $DEVICE is still mounted" >> $TS_OUTPUT +# repair /etc/mtab
+$TS_CMD_UMOUNT --fake $TS_MOUNTPOINT &> /dev/null
+ts_is_mounted $DEVICE && ts_die "$DEVICE is still mounted"
ts_finalize_subtest

Quoted 12 lines
Quoted 3 lines

Should we restore the original mtab? I guess it's a bit unsafe to copy back a backed up one. Or is there a way to "repair/sync" from /proc/mounts.?

Don't use /proc/mounts. It's bad idea as the files maybe very different.

use the --fake or you can try to redirect libmount to use non-standard mtab by env. variable LIBMOUNT_MTAB=, but it will increase complexity of the test.

Karel

maintainer
#4 lore raw
In reply to Ruediger Meier
Quoted 17 lines · Ruediger Meier
Quoted 16 lines · Karel Zak
Quoted 15 lines · Ruediger Meier

ts_init_subtest "umount"
[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT $TS_CMD_MOUNT $DEVICE $TS_MOUNTPOINT &> /dev/null OLD_SUM=$(mtab_checksum)
(
ulimit -f 1
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
) &> /dev/null
NEW_SUM=$(mtab_checksum)
$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
[ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
ts_finalize_subtest
...........

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I do not fully understand what is expected. Obviously the first "umount" should NOT modify /etc/mtab. But should it umount or not, or doesn't matter? Why we call a second umount then?

I guess the second umount is just copy & past (from mount test) and

Ah, now it makes sense. So the first umount should work and we could check "ismounted" too.

yes

Quoted 2 lines

BTW could it be that in past "umount" always removed the mtab entry like "--fake" still does for umounted devices?

git show v2.13:mount/umount.c

       if (!nomtab &&
             (umnt_err == 0 || umnt_err == EINVAL || umnt_err == ENOENT)) {
                 update_mtab (node, NULL);
       }

so yes, but for me it's little bit fragile (for example EINVAL means wrong mount options in same situations, unreachable mountpoint maybe in situation when it's hidden by another mount and with namespaces it does not make sense at all).

Thanks God that mtab is dead.

Review

Quoted 13 lines

Ah that's good. I'll send a patch with some other fixes later. The umount part would look like this:

(quoted diff) +4 -1
 	$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
 ) &> /dev/null
 NEW_SUM=$(mtab_checksum)
-$TS_CMD_UMOUNT $TS_MOUNTPOINT &> /dev/null
 [ $NEW_SUM = $OLD_SUM ] && echo "OK: mtab unmodified by umount" >> $TS_OUTPUT
+ts_is_mounted $DEVICE && echo "FAIL: $DEVICE is still mounted" >> $TS_OUTPUT
+# repair /etc/mtab
+$TS_CMD_UMOUNT --fake $TS_MOUNTPOINT &> /dev/null
+ts_is_mounted $DEVICE && ts_die "$DEVICE is still mounted"
 ts_finalize_subtest

Seems good.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com