function ts_skip {
ts_skip_subtest "$1"
- if [ -n "$2" -a -b "$2" ]; then
- ts_device_deinit "$2"
- fi
+
ts_cleanup_on_exit
exit 0
}
declare -a TS_SUID_PROGS
declare -a TS_SUID_USER
declare -a TS_SUID_GROUP
+ declare -a TS_LOOP_DEVS
if [ -f $TS_TOPDIR/commands.sh ]; then
. $TS_TOPDIR/commands.sh
function ts_die {
ts_log "$1"
- if [ -n "$2" ] && [ -b "$2" ]; then
- ts_device_deinit "$2"
- ts_fstab_clean # for sure...
- fi
ts_finalize
}
chmod a-s $PROG &> /dev/null
chown ${TS_SUID_USER[$idx]}.${TS_SUID_GROUP[$idx]} $PROG &> /dev/null
done
+
+ for dev in "${TS_LOOP_DEVS[@]}"; do
+ ts_device_deinit "$dev"
+ done
+ unset TS_LOOP_DEVS
}
function ts_image_md5sum {
return 0
}
+function ts_register_loop_device {
+ local ct=${#TS_LOOP_DEVS[*]}
+ TS_LOOP_DEVS[$ct]=$1
+}
+
function ts_device_init {
local img
local dev
img=$(ts_image_init $1 $2)
dev=$($TS_CMD_LOSETUP --show -f "$img")
+ if [ "$?" != "0" -o "$dev" = "" ]; then
+ ts_die "Cannot init device"
+ fi
- echo $dev
+ ts_register_loop_device "$dev"
+ TS_LODEV=$dev
}
+# call from ts_cleanup_on_exit() only because of TS_LOOP_DEVS maintenance
function ts_device_deinit {
local DEV="$1"
ts_log "create loop device from image"
DEVICE=$($TS_CMD_LOSETUP --show -f $IMAGE_PATH)
+ts_register_loop_device "$DEVICE"
CMD_SED_DEVICE="sed s#$DEVICE:\s##"
ts_log "testing offsets with full block size"
$TS_CMD_BLKDISCARD -v -p 511 -o 511 -l 10240 $DEVICE 2>&1 | $CMD_SED_DEVICE >> $TS_OUTPUT
ts_log "detach loop device from image"
-$TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT
ts_cd "$ORIGPWD"
ts_log "Initialize devices"
IMGNAME="${TS_OUTDIR}/${TS_TESTNAME}"
-DEVICE1=$(ts_device_init 50 ${IMGNAME}1.img)
-[ "$?" == 0 ] || ts_die "Cannot init device1"
+ts_device_init 50 ${IMGNAME}1.img
+DEVICE1=$TS_LODEV
-DEVICE2=$(ts_device_init 50 ${IMGNAME}2.img)
-[ "$?" == 0 ] || ts_die "Cannot init device2" $DEVICE1
+ts_device_init 50 ${IMGNAME}2.img
+DEVICE2=$TS_LODEV
MD_DEVNAME=md8
MD_DEVICE=/dev/${MD_DEVNAME}
udevadm settle
ts_log "Deinitialize devices"
-ts_device_deinit $DEVICE1
-ts_device_deinit $DEVICE2
ts_fdisk_clean $MD_DEVICE
ts_log "Initialize devices"
IMGNAME="${TS_OUTDIR}/${TS_TESTNAME}"
-DEVICE1=$(ts_device_init 50 ${IMGNAME}1.img)
-[ "$?" == 0 ] || ts_die "Cannot init device1"
+ts_device_init 50 ${IMGNAME}1.img
+DEVICE1=$TS_LODEV
-DEVICE2=$(ts_device_init 50 ${IMGNAME}2.img)
-[ "$?" == 0 ] || ts_die "Cannot init device2" $DEVICE1
+ts_device_init 50 ${IMGNAME}2.img
+DEVICE2=$TS_LODEV
MD_DEVNAME=md8
MD_DEVICE=/dev/${MD_DEVNAME}
udevadm settle
ts_log "Deinitialize devices"
-ts_device_deinit $DEVICE1
-ts_device_deinit $DEVICE2
ts_fdisk_clean
# remove generated UUIDs
ts_log "create loop device from image"
DEVICE=$($TS_CMD_LOSETUP --show -f $IMAGE_PATH)
+ts_register_loop_device "$DEVICE"
ts_log "check the image"
ts_device_has "TYPE" "cramfs" $DEVICE
ts_cd "$ORIGPWD"
ts_log "umount the image"
-$TS_CMD_UMOUNT $DEVICE
-$TS_CMD_LOSETUP -d $DEVICE 2>&1 >> $TS_OUTPUT
ts_finalize
ts_skip_nonroot
ts_check_losetup
-DEVICE=$(ts_device_init 50)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init 50
+DEVICE=$TS_LODEV
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
q
EOF
-ts_device_deinit $DEVICE
ts_fdisk_clean $DEVICE
ts_finalize
> $TS_OUTPUT
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_finalize
set -o pipefail
IMAGE="$TS_OUTDIR/${TS_TESTNAME}-loop.img"
-DEVICE=$(ts_device_init)
+ts_device_init
+DEVICE=$TS_LODEV
ts_log "create minix fs"
$TS_CMD_MKMINIX $DEVICE 2>&1 >> $TS_OUTPUT
ts_log "fsck minix fs"
$TS_CMD_FSCKMINIX $DEVICE 2>&1 >> $TS_OUTPUT
-ts_device_deinit $DEVICE
ts_finalize
set -o pipefail
IMAGE="$TS_OUTDIR/${TS_TESTNAME}-loop.img"
-DEVICE=$(ts_device_init)
+ts_device_init
+DEVICE=$TS_LODEV
ts_log "create minix fs"
$TS_CMD_MKMINIX $DEVICE 2>&1 >> $TS_OUTPUT
ts_log "umount the image"
$TS_CMD_UMOUNT $DEVICE
-ts_device_deinit $DEVICE
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
grep -q $DEVICE /etc/mtab &&
echo "umount failed: found $DEVICE in mtab" >> $TS_OUTPUT 2>&1
-ts_device_deinit $DEVICE
-
ts_log "Success"
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_log "Success"
ts_finalize_subtest
-
-ts_device_deinit $DEVICE
-
ts_log "Success"
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "C) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "C) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
LINKNAME="$TS_OUTDIR/${TS_TESTNAME}_lnk"
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
#su $TS_TESTUSER -c "$TS_CMD_UMOUNT $LINKNAME" 2>&1 >> $TS_OUTPUT \
# || ts_die "B) Cannot umount $LINKNAME" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
rm -f $LINKNAME
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "C) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "C) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
ts_fstab_clean
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
-
ts_log "Success"
ts_finalize
# mountpoint
[ -d $TS_MOUNTPOINT ] || mkdir -p $TS_MOUNTPOINT
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE" $DEVICE
$TS_CMD_FINDMNT --kernel --target "$TS_MOUNTPOINT" --options "ro" &> /dev/null
[ "$?" == "0" ] || ts_die "Cannot find read-only in $TS_MOUNTPOINT in /proc/self/mountinfo"
-ts_device_deinit $DEVICE
-
ts_log "Success"
ts_finalize
md5sum /etc/mtab | awk '{printf $1}'
}
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
fi
ts_finalize_subtest
-
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize
#
# block dev based mounts
#
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_device_has "TYPE" "ext3" $DEVICE || ts_die "Cannot find ext3 on $DEVICE" $DEVICE
$TS_CMD_UMOUNT $MOUNTPOINT
ts_finalize_subtest
-ts_device_deinit $DEVICE
rmdir $MOUNTPOINT
ts_log "Success"
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE" $DEVICE
ts_is_mounted $DEVICE || ts_die "B) Cannot find $DEVICE in /proc/mounts" $DEVICE
$TS_CMD_UMOUNT $DEVICE || ts_die "B) Cannot umount $DEVICE" $DEVICE
-ts_device_deinit $DEVICE
-
ts_log "Success"
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
$TS_CMD_MKSWAP $DEVICE > /dev/null 2>> $TS_OUTPUT \
|| ts_die "Cannot make swap $DEVICE" $DEVICE
grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $DEVICE
$TS_CMD_SWAPOFF $DEVICE
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize
BADSIZE=4096
fi
-DEVICE=$(ts_device_init)
+ts_device_init
+DEVICE=$TS_LODEV
$TS_CMD_MKSWAP -L MyFooBarLabel --pagesize $BADSIZE $DEVICE > /dev/null &> /dev/null \
|| ts_die "Cannot make swap $DEVICE" $DEVICE
grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $DEVICE
$TS_CMD_SWAPOFF $DEVICE
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize
#
# Create a swap-area
#
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
$TS_CMD_MKSWAP $DEVICE > /dev/null 2>> $TS_OUTPUT \
|| ts_die "Cannot make swap $DEVICE" $DEVICE
grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $DEVICE
$TS_CMD_SWAPOFF $DEVICE
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
$TS_CMD_MKSWAP -L $LABEL $DEVICE > /dev/null 2>> $TS_OUTPUT \
|| ts_die "Cannot make swap on $DEVICE" $DEVICE
grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $DEVICE
$TS_CMD_SWAPOFF $DEVICE
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize
set -o pipefail
-DEVICE=$(ts_device_init)
-[ "$?" == 0 ] || ts_die "Cannot init device"
+ts_device_init
+DEVICE=$TS_LODEV
$TS_CMD_MKSWAP $DEVICE > /dev/null 2>> $TS_OUTPUT \
|| ts_die "Cannot make swap $DEVICE" $DEVICE
grep -q $DEVICE /proc/swaps || ts_die "Cannot find $DEVICE in /proc/swaps" $DEVICE
$TS_CMD_SWAPOFF $DEVICE
-ts_device_deinit $DEVICE
ts_log "Success"
ts_finalize