]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: use flock to modify fstab
authorKarel Zak <kzak@redhat.com>
Wed, 6 Dec 2017 13:38:44 +0000 (14:38 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Dec 2017 14:55:09 +0000 (15:55 +0100)
Note that for btrfs test we need to use low-level ts_fstab_addline,
because we add multiple lines there.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/functions.sh
tests/ts/mount/fstab-broken
tests/ts/mount/fstab-btrfs
tests/ts/mount/fstab-devname
tests/ts/mount/fstab-loop

index 0409b62835ae607e9b228b9e1bd42e716f4a3a0f..181fe7972b38c8224ac2465bea5ff552ac15ce12 100644 (file)
@@ -628,6 +628,7 @@ function ts_fstab_open {
 
 function ts_fstab_close {
        echo "# -->" >> /etc/fstab
+       sync /etc/fstab
 }
 
 function ts_fstab_addline {
@@ -639,7 +640,12 @@ function ts_fstab_addline {
        echo "$SPEC   $MNT   $FS   $OPT   0   0" >> /etc/fstab
 }
 
+function ts_fstab_lock {
+       ts_lock "fstab"
+}
+
 function ts_fstab_add {
+       ts_fstab_lock
        ts_fstab_open
        ts_fstab_addline $*
        ts_fstab_close
@@ -655,6 +661,9 @@ function ts_fstab_clean {
 }
 s/# <!-- util-linux.*-->//;
 /^$/d" /etc/fstab
+
+       sync /etc/fstab
+       ts_unlock "fstab"
 }
 
 function ts_fdisk_clean {
@@ -694,7 +703,7 @@ function ts_lock {
 
 # Note that flock(2) lock is released on FD close.
 function ts_unlock {
-       200<&-
+       200<&- || :
 }
 
 function ts_scsi_debug_init {
index 67dfa6e8125ed76b5750a5caac3f42a6ef91782d..947e3af7aeb28fe35e1c4567b71dee602ac9db49 100755 (executable)
@@ -31,6 +31,7 @@ ts_skip_nonroot
 MNT=$TS_MOUNTPOINT
 mkdir -p $MNT
 
+ts_fstab_lock
 ts_fstab_open
 echo "tmpd $MNT tmpfs" >> /etc/fstab
 ts_fstab_close
@@ -72,7 +73,7 @@ else
 fi
 ts_finalize_subtest
 
-ts_fstab_clean
+ts_fstab_clean # this unlocks too
 
 ts_log "Success"
 ts_finalize
index 6abbd0be1de3142209cc7c20b1d9a76ca84531f8..090f52304e079cf4e771f60618e0823b9cd29965 100755 (executable)
@@ -78,15 +78,18 @@ $TS_CMD_UMOUNT "$TS_MOUNTPOINT_CREATE"
 
 
 ts_init_subtest "btrfs"
+ts_fstab_lock
+ts_fstab_open
 # Tests with fs == btrfs
 # mounting default subvolume, deep in the structure, without entry in fstab
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "btrfs" ""
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "btrfs" ""
 # mounting default subvolume, deep in the structure
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "btrfs" "subvol=$NON_DEFAULT_SUBVOL"
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "btrfs" "subvol=$NON_DEFAULT_SUBVOL"
 # mounting non-default subvolume
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "btrfs" "subvolid=$NON_DEFAULT_SUBVOLID"
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "btrfs" "subvolid=$NON_DEFAULT_SUBVOLID"
 # test bind mount pointing to subvolume root
-ts_fstab_add "$TS_MOUNTPOINT_SUBVOLID" "$TS_MOUNTPOINT_BIND" "auto" "bind"
+ts_fstab_addline "$TS_MOUNTPOINT_SUBVOLID" "$TS_MOUNTPOINT_BIND" "auto" "bind"
+ts_fstab_close
 
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
@@ -99,20 +102,24 @@ $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>&1
 # check that everything was unmounted
 $TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>&1
 
-ts_fstab_clean
+ts_fstab_clean         # this unlock too
 ts_log "Success"
 ts_finalize_subtest
 
+
 ts_init_subtest "auto"
+ts_fstab_lock
+ts_fstab_open
 # Tests with fs == auto
 # mounting default subvolume, deep in the structure, without entry in fstab
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "auto" ""
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "auto" ""
 # mounting default subvolume, deep in the structure
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "auto" "subvol=$NON_DEFAULT_SUBVOL"
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "auto" "subvol=$NON_DEFAULT_SUBVOL"
 # mounting non-default subvolume
-ts_fstab_add "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "auto" "subvolid=$NON_DEFAULT_SUBVOLID"
+ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "auto" "subvolid=$NON_DEFAULT_SUBVOLID"
 # test bind mount pointing to subvolume sub-directory
-ts_fstab_add "$TS_MOUNTPOINT_SUBVOL/bind-mnt" "$TS_MOUNTPOINT_BIND" "auto" "bind"
+ts_fstab_addline "$TS_MOUNTPOINT_SUBVOL/bind-mnt" "$TS_MOUNTPOINT_BIND" "auto" "bind"
+ts_fstab_close
 
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
@@ -125,7 +132,7 @@ $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>&1
 # check that everything was unmounted
 $TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>&1
 
-ts_fstab_clean
+ts_fstab_clean         # this unlock too
 ts_log "Success"
 ts_finalize_subtest
 
index 8e391c806a4f6d2e77747b0a7b085bca046daf09..6648784d3f5372cd5a9ad28f57661a8863cea851 100755 (executable)
@@ -50,7 +50,5 @@ ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts"
 $TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE"
 
 ts_fstab_clean
-
 ts_log "Success"
 ts_finalize
-
index 9e17943b1033bab8c21cf9dd30a6aea66d573965..4104a62a0be6827c10666328781732ed589bf0c0 100755 (executable)
@@ -35,12 +35,17 @@ mkfs.ext3 -F $IMG &> /dev/null || ts_die "Cannot make ext3 on $IMG"
 [ -d "$TS_MOUNTPOINT-1" ] || mkdir -p $TS_MOUNTPOINT-1
 [ -d "$TS_MOUNTPOINT-2" ] || mkdir -p $TS_MOUNTPOINT-2
 
-ts_fstab_add "$IMG" "$TS_MOUNTPOINT-1" "ext3" "loop"
+ts_fstab_lock
+ts_fstab_open
+
+ts_fstab_addline "$IMG" "$TS_MOUNTPOINT-1" "ext3" "loop"
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
 
-ts_fstab_add "$IMG" "$TS_MOUNTPOINT-2" "ext3" "loop"
+ts_fstab_addline "$IMG" "$TS_MOUNTPOINT-2" "ext3" "loop"
 $TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
 
+ts_fstab_close
+
 $TS_CMD_UMOUNT "$TS_MOUNTPOINT-1" >> $TS_OUTPUT 2>&1
 $TS_CMD_UMOUNT "$TS_MOUNTPOINT-2" >> $TS_OUTPUT 2>&1