1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2022 Intel Corporation 4# All rights reserved. 5# 6 7testdir=$(readlink -f $(dirname $0)) 8rootdir=$(readlink -f $testdir/../..) 9source $rootdir/test/common/autotest_common.sh 10source $testdir/common.sh 11 12rpc_py=$rootdir/scripts/rpc.py 13 14fio_kill() { 15 rm -f $testdir/testfile.md5 16 rm -f $testdir/config/ftl.json 17 18 killprocess $svcpid 19 rmmod nbd || true 20} 21 22device=$1 23cache_device=$2 24timeout=240 25data_size=$((262144 * 5)) 26 27if [[ $CONFIG_FIO_PLUGIN != y ]]; then 28 echo "FIO not available" 29 exit 1 30fi 31 32export FTL_BDEV_NAME=ftl0 33export FTL_JSON_CONF=$testdir/config/ftl.json 34 35trap "fio_kill; exit 1" SIGINT SIGTERM EXIT 36 37"$SPDK_BIN_DIR/spdk_tgt" & 38svcpid=$! 39waitforlisten $svcpid 40 41split_bdev=$(create_base_bdev nvme0 $device $((1024 * 101))) 42nv_cache=$(create_nv_cache_bdev nvc0 $cache_device $split_bdev) 43 44l2p_percentage=60 45l2p_dram_size_mb=$(($(get_bdev_size $split_bdev) * l2p_percentage / 100 / 1024)) 46 47$rpc_py -t $timeout bdev_ftl_create -b ftl0 -d $split_bdev -c $nv_cache --l2p_dram_limit $l2p_dram_size_mb 48 49waitforbdev ftl0 50 51( 52 echo '{"subsystems": [' 53 $rpc_py save_subsystem_config -n bdev 54 echo ']}' 55) > $FTL_JSON_CONF 56 57killprocess $svcpid 58 59fio_bdev $testdir/config/fio/write_after_write.fio 60 61"$SPDK_BIN_DIR/spdk_tgt" -L ftl_init & 62svcpid=$! 63waitforlisten $svcpid 64 65$rpc_py load_config < $FTL_JSON_CONF 66# Load the nbd driver 67modprobe nbd 68$rpc_py nbd_start_disk ftl0 /dev/nbd0 69waitfornbd nbd0 70 71$rpc_py save_config > $testdir/config/ftl.json 72 73# Calculate checksum of the data written 74dd if=/dev/nbd0 bs=4K count=$data_size | md5sum > $testdir/testfile.md5 75$rpc_py nbd_stop_disk /dev/nbd0 76 77# Force kill bdev service (dirty shutdown) and start it again 78kill -9 $svcpid 79rm -f /dev/shm/spdk_tgt_trace.pid$svcpid 80 81"$SPDK_BIN_DIR/spdk_tgt" -L ftl_init & 82svcpid=$! 83waitforlisten $svcpid 84 85$rpc_py load_config < $testdir/config/ftl.json 86waitfornbd nbd0 87 88# Verify that the checksum matches and the data is consistent 89dd if=/dev/nbd0 bs=4K count=$data_size | md5sum -c $testdir/testfile.md5 90 91trap - SIGINT SIGTERM EXIT 92fio_kill 93