test/mkfs: provide common function to create filesystem

There are tests which create a filesystem on a device.
Each one could use a timeout and retries for each mkfs.
Otherwise following error could appear due to not test
related system activities:
'mkfs.xfs: cannot open /dev/sdb1: Device or resource busy'

References #1141

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I7307b085ada42200995d8bd2fcfd0469ee60a732
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1178
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
Tomasz Zawadzki 2020-03-06 06:47:48 -05:00
parent c7325e3fad
commit 0c7aeea925
5 changed files with 30 additions and 22 deletions

View File

@ -540,6 +540,29 @@ function waitforbdev() {
return 1 return 1
} }
function make_filesystem() {
local fstype=$1
local dev_name=$2
local i=0
local force
if [ $fstype = ext4 ]; then
force=-F
else
force=-f
fi
while ! mkfs.${fstype} $force ${dev_name}; do
if [ $i -ge 15 ]; then
return 1
fi
i=$((i+1))
sleep 1
done
return 0
}
function killprocess() { function killprocess() {
# $1 = process pid # $1 = process pid
if [ -z "$1" ]; then if [ -z "$1" ]; then

View File

@ -66,7 +66,7 @@ waitfornbd nbd0
$rpc_py save_config > $testdir/config/ftl.json $rpc_py save_config > $testdir/config/ftl.json
# Prepare the disk by creating ext4 fs and putting a file on it # Prepare the disk by creating ext4 fs and putting a file on it
mkfs.ext4 -F /dev/nbd0 make_filesystem ext4 /dev/nbd0
mount /dev/nbd0 $mount_dir mount /dev/nbd0 $mount_dir
dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K
sync sync

View File

@ -51,8 +51,8 @@ $rpc_py bdev_error_inject_error EE_Malloc0 'all' 'failure' -n 1000
dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') dev=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
set +e set +e
waitforfile /dev/$dev waitforfile /dev/${dev}
if mkfs.ext4 -F /dev/$dev; then if make_filesystem ext4 /dev/${dev}; then
echo "mkfs successful - expected failure" echo "mkfs successful - expected failure"
iscsicleanup iscsicleanup
killprocess $pid killprocess $pid
@ -84,9 +84,9 @@ waitforiscsidevices 1
devs=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}') devs=$(iscsiadm -m session -P 3 | grep "Attached scsi disk" | awk '{print $4}')
for dev in $devs; do for dev in $devs; do
mkfs.ext4 -F /dev/$dev make_filesystem ext4 /dev/${dev}
mkdir -p /mnt/${dev}dir mkdir -p /mnt/${dev}dir
mount -o sync /dev/$dev /mnt/${dev}dir mount -o sync /dev/${dev} /mnt/${dev}dir
rsync -qav --exclude=".git" --exclude="*.o" $rootdir/ /mnt/${dev}dir/spdk rsync -qav --exclude=".git" --exclude="*.o" $rootdir/ /mnt/${dev}dir/spdk

View File

@ -78,11 +78,7 @@ sleep 1
function filesystem_test { function filesystem_test {
fstype=$1 fstype=$1
if [ "$fstype" == "ext4" ]; then make_filesystem ${fstype} /dev/${dev}1
mkfs.${fstype} -F /dev/${dev}1
else
mkfs.${fstype} -f /dev/${dev}1
fi
mount /dev/${dev}1 /mnt/device mount /dev/${dev}1 /mnt/device
if [ $RUN_NIGHTLY -eq 1 ]; then if [ $RUN_NIGHTLY -eq 1 ]; then
fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randwrite -ioengine=libaio -bs=4k \ fio -filename=/mnt/device/test -direct=1 -iodepth 64 -thread=1 -invalidate=1 -rw=randwrite -ioengine=libaio -bs=4k \

View File

@ -16,18 +16,7 @@ function nvmf_filesystem_create {
fstype=$1 fstype=$1
nvme_name=$2 nvme_name=$2
if [ $fstype = ext4 ]; then make_filesystem ${fstype} /dev/${nvme_name}p1
force=-F
else
force=-f
fi
local i=0
while ! mkfs.${fstype} $force /dev/${nvme_name}p1; do
[ $i -lt 15 ] || break
i=$((i+1))
sleep 1
done
mount /dev/${nvme_name}p1 /mnt/device mount /dev/${nvme_name}p1 /mnt/device
touch /mnt/device/aaa touch /mnt/device/aaa