2018-10-29 14:40:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
|
2019-06-10 07:16:46 +00:00
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
mount_dir=$(mktemp -d)
|
|
|
|
device=$1
|
|
|
|
uuid=$2
|
|
|
|
|
|
|
|
restore_kill() {
|
|
|
|
if mount | grep $mount_dir; then
|
|
|
|
umount $mount_dir
|
|
|
|
fi
|
|
|
|
rm -rf $mount_dir
|
|
|
|
rm -f $testdir/testfile.md5
|
2019-06-11 13:35:22 +00:00
|
|
|
rm -f $testdir/testfile2.md5
|
2019-01-28 13:12:21 +00:00
|
|
|
rm -f $testdir/config/ftl.json
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
$rpc_py delete_ftl_bdev -b nvme0
|
|
|
|
killprocess $svcpid
|
|
|
|
rmmod nbd || true
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
|
2019-07-10 09:38:49 +00:00
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$!
|
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 14:40:34 +00:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
|
|
|
if [ -n "$uuid" ]; then
|
|
|
|
$rpc_py construct_ftl_bdev -b nvme0 -a $device -l 0-3 -u $uuid
|
|
|
|
else
|
2019-01-28 13:12:21 +00:00
|
|
|
$rpc_py construct_ftl_bdev -b nvme0 -a $device -l 0-3
|
2018-10-29 14:40:34 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Load the nbd driver
|
|
|
|
modprobe nbd
|
|
|
|
$rpc_py start_nbd_disk nvme0 /dev/nbd0
|
|
|
|
waitfornbd nbd0
|
|
|
|
|
2019-01-28 13:12:21 +00:00
|
|
|
$rpc_py save_config > $testdir/config/ftl.json
|
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
# Prepare the disk by creating ext4 fs and putting a file on it
|
|
|
|
mkfs.ext4 -F /dev/nbd0
|
|
|
|
mount /dev/nbd0 $mount_dir
|
|
|
|
dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K
|
|
|
|
sync
|
|
|
|
mount -o remount /dev/nbd0 $mount_dir
|
|
|
|
md5sum $mount_dir/testfile > $testdir/testfile.md5
|
|
|
|
|
|
|
|
# Kill bdev service and start it again
|
|
|
|
umount $mount_dir
|
|
|
|
killprocess $svcpid
|
|
|
|
|
2019-07-10 09:38:49 +00:00
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$!
|
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 14:40:34 +00:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2019-01-28 13:12:21 +00:00
|
|
|
$rpc_py load_config < $testdir/config/ftl.json
|
2019-06-26 09:39:12 +00:00
|
|
|
waitfornbd nbd0
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
mount /dev/nbd0 $mount_dir
|
2019-06-11 13:35:22 +00:00
|
|
|
|
|
|
|
# Write second file, to make sure writer thread has restored properly
|
|
|
|
dd if=/dev/urandom of=$mount_dir/testfile2 bs=4K count=256K
|
|
|
|
md5sum $mount_dir/testfile2 > $testdir/testfile2.md5
|
|
|
|
|
|
|
|
# Make sure second file will be read from disk
|
|
|
|
echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
|
|
|
|
# Check both files have proper data
|
2018-10-29 14:40:34 +00:00
|
|
|
md5sum -c $testdir/testfile.md5
|
2019-06-11 13:35:22 +00:00
|
|
|
md5sum -c $testdir/testfile2.md5
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
report_test_completion occsd_restore
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
restore_kill
|