}
function ts_fdisk_clean {
+ local DEVNAME=$(basename "$1")
+
# remove non comparable parts of fdisk output
- [ x"${DEVNAME}" != x"" ] && sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT
+ if [ x"${DEVNAME}" != x"" ]; then
+ sed -i -e "s/\/dev\/${DEVNAME}/\/dev\/.../g" $TS_OUTPUT
+ fi
+
sed -i -e 's/Disk identifier:.*//g' \
-e 's/Building a new.*//g' \
-e 's/Welcome to fdisk.*//g' \
$TS_OUTPUT
}
+
+function ts_scsi_debug_init {
+
+ modprobe --dry-run --quiet scsi_debug
+ [ "$?" == 0 ] || ts_skip "missing scsi_debug module"
+
+ rmmod scsi_debug &> /dev/null
+ modprobe scsi_debug $*
+ [ "$?" == 0 ] || ts_die "Cannot init device"
+
+ DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
+ [ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
+
+ DEVICE="/dev/${DEVNAME}"
+
+ sleep 1
+ udevadm settle
+
+ echo $DEVICE
+}
ts_device_deinit $DEVICE2
ts_fdisk_clean
+
# remove generated UUIDs
sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-[ -x /sbin/mdadm ] || ts_skip "missing mdadm"
-
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=51 sector_size=512
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=51 sector_size=512)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
udevadm settle
rmmod scsi_debug
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
# substitue UUIDs and major/minor number before comparison
sed -i \
-e 's/^\(ID_FS_UUID\)=.*/\1=__ts_uuid__/' \
# not removable device.
#
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-rmmod scsi_debug &> /dev/null
-
function init_device {
- modprobe scsi_debug dev_size_mb=100
- [ "$?" == 0 ] || ts_die "Cannot init device"
-
- sleep 3
-
- DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
- [ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
- echo "/dev/${DEVNAME}"
-
+ ts_scsi_debug_init dev_size_mb=100
}
function init_partitions {
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
rmmod scsi_debug
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
ts_finalize
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3 lowest_aligned=7)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
rmmod scsi_debug
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
ts_finalize
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-[ -x /sbin/mdadm ] || ts_skip "missing mdadm"
-
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50 sector_size=512 physblk_exp=3
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512 physblk_exp=3)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
udevadm settle
rmmod scsi_debug
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
ts_finalize
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50 sector_size=512
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
rmmod scsi_debug
-ts_fdisk_clean
+ts_fdisk_clean $DEVICE
ts_finalize
TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex"
[ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST
-#set -x
-
[ -x $TESTPROG ] || ts_skip "test not compiled"
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
ts_log "Init device"
umount $MOUNTPOINT &> /dev/null
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=100
-[ "$?" == 0 ] || ts_die "Cannot init device"
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
-udevadm settle
+DEVICE=$(ts_scsi_debug_init dev_size_mb=100)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
-$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 <<EOF
+$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF
n
p
1
q
EOF
-DEVICE="/dev/${DEVNAME}1"
+DEVICE="${DEVICE}1"
+
+sleep 1
udevadm settle
+grep -q $DEVNAME /proc/partitions
+if [ $? -ne 0 ]; then
+ rmmod scsi_debug
+ ts_skip "no partition!"
+fi
+
ts_log "Create filesystem"
mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
> $LIBMOUNT_MTAB
udevadm settle
+ts_device_has "TYPE" "ext4" $DEVICE || ts_die "Cannot find ext3 on $DEVICE" $DEVICE
ts_init_subtest "mount-by-devname"
mkdir -p $MOUNTPOINT &> /dev/null
[ -x $TESTPROG ] || ts_skip "test not compiled"
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-ts_log "Init device"
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=260
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
-udevadm settle
+DEVICE=$(ts_scsi_debug_init dev_size_mb=100)
+DEVNAME=$(basename $DEVICE)
ts_log "Create partitions"
-$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 <<EOF
+$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF
n
p
1
q
EOF
-DEVICE="/dev/${DEVNAME}1"
+DEVICE="${DEVICE}1"
+sleep 1
udevadm settle
+grep -q $DEVNAME /proc/partitions
+if [ $? -ne 0 ]; then
+ rmmod scsi_debug
+ ts_skip "no partition!"
+fi
+
ts_log "Create filesystem"
mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
[ -x $TESTPROG ] || ts_skip "test not compiled"
-#
-# Init device
-#
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50 sector_size=512
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50 sector_size=512)
LABEL="testLibmount"
UUID="de1bc6e9-34ab-4151-a1d7-900042eee8d9"
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
-ts_log "Init device"
-$TS_CMD_UMOUNT --recursive $MOUNTPOINT &> /dev/null
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF
ts_init "$*"
ts_skip_nonroot
-modprobe --dry-run --quiet scsi_debug
-[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
-
ts_log "Init device"
-$TS_CMD_UMOUNT --recursive $MOUNTPOINT &> /dev/null
-rmmod scsi_debug &> /dev/null
-modprobe scsi_debug dev_size_mb=50
-[ "$?" == 0 ] || ts_die "Cannot init device"
-
-sleep 3
-
-DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
-[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"
-
-DEVICE="/dev/${DEVNAME}"
+DEVICE=$(ts_scsi_debug_init dev_size_mb=50)
ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} &> /dev/null <<EOF