summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKarel Zak2017-12-06 14:38:44 +0100
committerKarel Zak2017-12-06 15:55:09 +0100
commite140506af35821857a47c1013bad03b12f31062d (patch)
tree967ef56e98223c8546b56b9348ae23a657755533 /tests
parenttests: add lock on shared resources (e.g. scsi_debug) (diff)
downloadkernel-qcow2-util-linux-e140506af35821857a47c1013bad03b12f31062d.tar.gz
kernel-qcow2-util-linux-e140506af35821857a47c1013bad03b12f31062d.tar.xz
kernel-qcow2-util-linux-e140506af35821857a47c1013bad03b12f31062d.zip
tests: use flock to modify fstab
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/functions.sh11
-rwxr-xr-xtests/ts/mount/fstab-broken3
-rwxr-xr-xtests/ts/mount/fstab-btrfs27
-rwxr-xr-xtests/ts/mount/fstab-devname2
-rwxr-xr-xtests/ts/mount/fstab-loop9
5 files changed, 36 insertions, 16 deletions
diff --git a/tests/functions.sh b/tests/functions.sh
index 0409b6283..181fe7972 100644
--- a/tests/functions.sh
+++ b/tests/functions.sh
@@ -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 {
diff --git a/tests/ts/mount/fstab-broken b/tests/ts/mount/fstab-broken
index 67dfa6e81..947e3af7a 100755
--- a/tests/ts/mount/fstab-broken
+++ b/tests/ts/mount/fstab-broken
@@ -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
diff --git a/tests/ts/mount/fstab-btrfs b/tests/ts/mount/fstab-btrfs
index 6abbd0be1..090f52304 100755
--- a/tests/ts/mount/fstab-btrfs
+++ b/tests/ts/mount/fstab-btrfs
@@ -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
diff --git a/tests/ts/mount/fstab-devname b/tests/ts/mount/fstab-devname
index 8e391c806..6648784d3 100755
--- a/tests/ts/mount/fstab-devname
+++ b/tests/ts/mount/fstab-devname
@@ -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
-
diff --git a/tests/ts/mount/fstab-loop b/tests/ts/mount/fstab-loop
index 9e17943b1..4104a62a0 100755
--- a/tests/ts/mount/fstab-loop
+++ b/tests/ts/mount/fstab-loop
@@ -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