2019-05-31 13:35:12 +02: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
|
2019-05-31 13:35:12 +02:00
|
|
|
|
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
pu_start=0
|
|
|
|
pu_end=3
|
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))
|
2019-05-31 13:35:12 +02:00
|
|
|
|
|
|
|
device=$1
|
|
|
|
|
|
|
|
restore_kill() {
|
|
|
|
rm -f $testdir/config/ftl.json
|
|
|
|
rm -f $testdir/testfile.md5
|
2019-06-11 15:35:22 +02:00
|
|
|
rm -f $testdir/testfile2.md5
|
2019-05-31 13:35:12 +02:00
|
|
|
|
2019-08-21 05:03:04 -04:00
|
|
|
$rpc_py bdev_ftl_delete -b nvme0 || true
|
2019-05-31 13:35:12 +02:00
|
|
|
killprocess $svcpid || true
|
|
|
|
rmmod nbd || true
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
chunk_size=$(get_chunk_size $device)
|
2019-11-05 10:28:35 +01:00
|
|
|
pu_count=$((pu_end - pu_start + 1))
|
2019-05-31 13:35:12 +02:00
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
# Write one band worth of data + one extra chunk
|
2019-11-05 10:28:35 +01:00
|
|
|
data_size=$((chunk_size * (pu_count + 1)))
|
2019-05-31 13:35:12 +02:00
|
|
|
|
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$!
|
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
if [ -n "$nv_cache" ]; then
|
|
|
|
nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $pu_count)
|
2019-05-31 13:35:12 +02:00
|
|
|
fi
|
|
|
|
|
2019-08-21 05:03:04 -04:00
|
|
|
ftl_construct_args="bdev_ftl_create -b nvme0 -a $device -l $pu_start-$pu_end -o"
|
2019-06-18 15:19:06 +02:00
|
|
|
|
|
|
|
[ -n "$nvc_bdev" ] && ftl_construct_args+=" -c $nvc_bdev"
|
|
|
|
[ -n "$uuid" ] && ftl_construct_args+=" -u $uuid"
|
|
|
|
|
|
|
|
$rpc_py $ftl_construct_args
|
|
|
|
|
2019-05-31 13:35:12 +02:00
|
|
|
# Load the nbd driver
|
|
|
|
modprobe nbd
|
2019-09-17 06:36:40 -04:00
|
|
|
$rpc_py nbd_start_disk nvme0 /dev/nbd0
|
2019-05-31 13:35:12 +02:00
|
|
|
waitfornbd nbd0
|
|
|
|
|
|
|
|
$rpc_py save_config > $testdir/config/ftl.json
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
dd if=/dev/urandom of=/dev/nbd0 bs=4K count=$data_size oflag=dsync
|
|
|
|
# Calculate checksum of the data written
|
|
|
|
dd if=/dev/nbd0 bs=4K count=$data_size | md5sum > $testdir/testfile.md5
|
2019-09-17 06:47:41 -04:00
|
|
|
$rpc_py nbd_stop_disk /dev/nbd0
|
2019-05-31 13:35:12 +02:00
|
|
|
|
|
|
|
# Force kill bdev service (dirty shutdown) and start it again
|
|
|
|
kill -9 $svcpid
|
|
|
|
rm -f /dev/shm/spdk_tgt_trace.pid$svcpid
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
$rootdir/app/spdk_tgt/spdk_tgt -L ftl_init & svcpid=$!
|
2019-05-31 13:35:12 +02:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
|
|
|
$rpc_py load_config < $testdir/config/ftl.json
|
2019-06-26 11:39:12 +02:00
|
|
|
waitfornbd nbd0
|
2019-05-31 13:35:12 +02:00
|
|
|
|
2019-06-11 15:35:22 +02:00
|
|
|
# Write extra data after restore
|
2019-06-18 15:19:06 +02:00
|
|
|
dd if=/dev/urandom of=/dev/nbd0 bs=4K count=$chunk_size seek=$data_size oflag=dsync
|
2019-06-11 15:35:22 +02:00
|
|
|
# Save md5 data
|
2019-06-18 15:19:06 +02:00
|
|
|
dd if=/dev/nbd0 bs=4K count=$chunk_size skip=$data_size | md5sum > $testdir/testfile2.md5
|
2019-06-11 15:35:22 +02:00
|
|
|
|
|
|
|
# Make sure all data will be read from disk
|
|
|
|
echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
|
2019-06-18 15:19:06 +02:00
|
|
|
# Verify that the checksum matches and the data is consistent
|
|
|
|
dd if=/dev/nbd0 bs=4K count=$data_size | md5sum -c $testdir/testfile.md5
|
|
|
|
dd if=/dev/nbd0 bs=4K count=$chunk_size skip=$data_size | md5sum -c $testdir/testfile2.md5
|
2019-05-31 13:35:12 +02:00
|
|
|
|
|
|
|
report_test_completion ftl_dirty_shutdown
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
restore_kill
|