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 8mount_dir=$(mktemp -d) 9 10device=$1 11config=$SPDK_TEST_STORAGE/ftl.json 12 13restore_kill() { 14 if mount | grep $mount_dir; then 15 umount $mount_dir 16 fi 17 rm -rf $mount_dir 18 rm -f "$SPDK_TEST_STORAGE/testfile.md5" 19 rm -f "$SPDK_TEST_STORAGE/testfile2.md5" 20 rm -f "$config" 21 22 killprocess $svcpid 23 rmmod nbd || true 24} 25 26trap "restore_kill; exit 1" SIGINT SIGTERM EXIT 27 28"$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) & 29svcpid=$! 30# Wait until spdk_tgt starts 31waitforlisten $svcpid 32 33$rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie 34bdev_create_zone nvme0n1 35ftl_construct_args="bdev_ftl_create -b ftl0 -d $ZONE_DEV" 36 37$rpc_py $ftl_construct_args 38 39# Load the nbd driver 40modprobe nbd 41$rpc_py nbd_start_disk ftl0 /dev/nbd0 42waitfornbd nbd0 43 44$rpc_py save_config > "$config" 45 46# Prepare the disk by creating ext4 fs and putting a file on it 47make_filesystem ext4 /dev/nbd0 48mount /dev/nbd0 $mount_dir 49dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=4k 50sync 51mount -o remount /dev/nbd0 $mount_dir 52md5sum $mount_dir/testfile > "$SPDK_TEST_STORAGE/testfile.md5" 53 54# Kill bdev service and start it again 55umount $mount_dir 56killprocess $svcpid 57 58"$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) -L ftl_init & 59svcpid=$! 60# Wait until spdk_tgt starts 61waitforlisten $svcpid 62 63$rpc_py load_config < "$config" 64waitfornbd nbd0 65 66mount /dev/nbd0 $mount_dir 67 68# Write second file, to make sure writer thread has restored properly 69dd if=/dev/urandom of=$mount_dir/testfile2 bs=4K count=4k 70md5sum $mount_dir/testfile2 > "$SPDK_TEST_STORAGE/testfile2.md5" 71 72# Make sure second file will be read from disk 73echo 3 > /proc/sys/vm/drop_caches 74 75# Check both files have proper data 76md5sum -c "$SPDK_TEST_STORAGE/testfile.md5" 77md5sum -c "$SPDK_TEST_STORAGE/testfile2.md5" 78 79trap - SIGINT SIGTERM EXIT 80restore_kill 81