2018-10-29 10:40:34 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
2019-06-18 15:19:06 +02:00
|
|
|
source $testdir/common.sh
|
2018-10-29 10:40:34 -04:00
|
|
|
|
2019-06-10 09:16:46 +02:00
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
2018-10-29 10:40:34 -04:00
|
|
|
mount_dir=$(mktemp -d)
|
2019-06-18 15:19:06 +02:00
|
|
|
|
|
|
|
while getopts ':u:c:' opt; do
|
|
|
|
case $opt in
|
|
|
|
u) uuid=$OPTARG ;;
|
|
|
|
c) nv_cache=$OPTARG ;;
|
|
|
|
?) echo "Usage: $0 [-u UUID] [-c NV_CACHE_PCI_BDF] OCSSD_PCI_BDF" && exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND -1))
|
2018-10-29 10:40:34 -04:00
|
|
|
device=$1
|
2019-09-10 09:01:27 -04:00
|
|
|
num_group=$(get_num_group $device)
|
|
|
|
num_pu=$(get_num_pu $device)
|
|
|
|
pu_count=$((num_group * num_pu))
|
2018-10-29 10:40:34 -04:00
|
|
|
|
2019-10-25 03:31:14 -04:00
|
|
|
ftl_bdev_conf=$testdir/config/ftl.conf
|
|
|
|
gen_ftl_nvme_conf > $ftl_bdev_conf
|
|
|
|
|
2018-10-29 10:40:34 -04:00
|
|
|
restore_kill() {
|
|
|
|
if mount | grep $mount_dir; then
|
|
|
|
umount $mount_dir
|
|
|
|
fi
|
|
|
|
rm -rf $mount_dir
|
|
|
|
rm -f $testdir/testfile.md5
|
2019-06-11 15:35:22 +02:00
|
|
|
rm -f $testdir/testfile2.md5
|
2019-01-28 08:12:21 -05:00
|
|
|
rm -f $testdir/config/ftl.json
|
2019-10-25 03:31:14 -04:00
|
|
|
rm -f $ftl_bdev_conf
|
2018-10-29 10:40:34 -04:00
|
|
|
|
|
|
|
killprocess $svcpid
|
|
|
|
rmmod nbd || true
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
|
2019-10-25 03:31:14 -04:00
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf & svcpid=$!
|
2019-07-10 11:38:49 +02:00
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 10:40:34 -04:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
if [ -n "$nv_cache" ]; then
|
2019-09-10 09:01:27 -04:00
|
|
|
nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $pu_count)
|
2018-10-29 10:40:34 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-25 03:31:14 -04:00
|
|
|
$rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie
|
|
|
|
$rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1
|
|
|
|
ftl_construct_args="bdev_ftl_create -b ftl0 -d nvme0n1"
|
2019-06-18 15:19:06 +02:00
|
|
|
|
|
|
|
[ -n "$uuid" ] && ftl_construct_args+=" -u $uuid"
|
|
|
|
[ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev"
|
|
|
|
|
|
|
|
$rpc_py $ftl_construct_args
|
|
|
|
|
2018-10-29 10:40:34 -04:00
|
|
|
# Load the nbd driver
|
|
|
|
modprobe nbd
|
2019-10-25 03:31:14 -04:00
|
|
|
$rpc_py nbd_start_disk ftl0 /dev/nbd0
|
2018-10-29 10:40:34 -04:00
|
|
|
waitfornbd nbd0
|
|
|
|
|
2019-01-28 08:12:21 -05:00
|
|
|
$rpc_py save_config > $testdir/config/ftl.json
|
|
|
|
|
2018-10-29 10:40:34 -04: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-10-25 03:31:14 -04:00
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf -L ftl_init & svcpid=$!
|
2019-07-10 11:38:49 +02:00
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 10:40:34 -04:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2019-01-28 08:12:21 -05:00
|
|
|
$rpc_py load_config < $testdir/config/ftl.json
|
2019-06-26 11:39:12 +02:00
|
|
|
waitfornbd nbd0
|
2018-10-29 10:40:34 -04:00
|
|
|
|
|
|
|
mount /dev/nbd0 $mount_dir
|
2019-06-11 15:35:22 +02: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 10:40:34 -04:00
|
|
|
md5sum -c $testdir/testfile.md5
|
2019-06-11 15:35:22 +02:00
|
|
|
md5sum -c $testdir/testfile2.md5
|
2018-10-29 10:40:34 -04:00
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
restore_kill
|