1#!/usr/bin/env bash 2 3testdir=$(readlink -f $(dirname $0)) 4rootdir=$(readlink -f $testdir/../..) 5source $rootdir/test/common/autotest_common.sh 6source $testdir/common.sh 7 8rpc_py=$rootdir/scripts/rpc.py 9 10mount_dir=$(mktemp -d) 11pu_start=0 12pu_end=3 13 14while getopts ':u:c:' opt; do 15 case $opt in 16 u) uuid=$OPTARG ;; 17 c) nv_cache=$OPTARG ;; 18 ?) echo "Usage: $0 [-u UUID] [-c NV_CACHE_PCI_BDF] OCSSD_PCI_BDF" && exit 1 ;; 19 esac 20done 21shift $((OPTIND -1)) 22device=$1 23 24restore_kill() { 25 if mount | grep $mount_dir; then 26 umount $mount_dir 27 fi 28 rm -rf $mount_dir 29 rm -f $testdir/testfile.md5 30 rm -f $testdir/testfile2.md5 31 rm -f $testdir/config/ftl.json 32 33 $rpc_py delete_ftl_bdev -b nvme0 34 killprocess $svcpid 35 rmmod nbd || true 36} 37 38trap "restore_kill; exit 1" SIGINT SIGTERM EXIT 39 40$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$! 41# Wait until spdk_tgt starts 42waitforlisten $svcpid 43 44if [ -n "$nv_cache" ]; then 45 nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $(($pu_end - $pu_start + 1))) 46fi 47 48ftl_construct_args="construct_ftl_bdev -b nvme0 -a $device -l ${pu_start}-${pu_end}" 49 50[ -n "$uuid" ] && ftl_construct_args+=" -u $uuid" 51[ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev" 52 53$rpc_py $ftl_construct_args 54 55# Load the nbd driver 56modprobe nbd 57$rpc_py start_nbd_disk nvme0 /dev/nbd0 58waitfornbd nbd0 59 60$rpc_py save_config > $testdir/config/ftl.json 61 62# Prepare the disk by creating ext4 fs and putting a file on it 63mkfs.ext4 -F /dev/nbd0 64mount /dev/nbd0 $mount_dir 65dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K 66sync 67mount -o remount /dev/nbd0 $mount_dir 68md5sum $mount_dir/testfile > $testdir/testfile.md5 69 70# Kill bdev service and start it again 71umount $mount_dir 72killprocess $svcpid 73 74$rootdir/app/spdk_tgt/spdk_tgt -L ftl_init & svcpid=$! 75# Wait until spdk_tgt starts 76waitforlisten $svcpid 77 78$rpc_py load_config < $testdir/config/ftl.json 79waitfornbd nbd0 80 81mount /dev/nbd0 $mount_dir 82 83# Write second file, to make sure writer thread has restored properly 84dd if=/dev/urandom of=$mount_dir/testfile2 bs=4K count=256K 85md5sum $mount_dir/testfile2 > $testdir/testfile2.md5 86 87# Make sure second file will be read from disk 88echo 3 > /proc/sys/vm/drop_caches 89 90# Check both files have proper data 91md5sum -c $testdir/testfile.md5 92md5sum -c $testdir/testfile2.md5 93 94report_test_completion occsd_restore 95 96trap - SIGINT SIGTERM EXIT 97restore_kill 98