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