2022-05-31 12:16:40 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2018 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2022-05-31 12:16:40 +00:00
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
|
|
|
source $testdir/common.sh
|
|
|
|
|
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
|
|
|
mount_dir=$(mktemp -d)
|
|
|
|
|
|
|
|
while getopts ':u:c:f' opt; do
|
|
|
|
case $opt in
|
|
|
|
u) uuid=$OPTARG ;;
|
|
|
|
c) nv_cache=$OPTARG ;;
|
|
|
|
f) fast_shutdown=1 ;;
|
|
|
|
?) echo "Usage: $0 [-f] [-u UUID] [-c NV_CACHE_PCI_BDF] BASE_PCI_BDF" && exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
device=$1
|
|
|
|
timeout=240
|
|
|
|
|
|
|
|
restore_kill() {
|
2022-09-07 16:22:15 +00:00
|
|
|
rm -f $testdir/testfile
|
2022-05-31 12:16:40 +00:00
|
|
|
rm -f $testdir/testfile.md5
|
|
|
|
rm -f $testdir/config/ftl.json
|
|
|
|
|
|
|
|
killprocess $svcpid
|
|
|
|
remove_shm
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
|
|
|
|
"$SPDK_BIN_DIR/spdk_tgt" &
|
|
|
|
svcpid=$!
|
|
|
|
# Wait until spdk_tgt starts
|
|
|
|
waitforlisten $svcpid
|
|
|
|
|
|
|
|
split_bdev=$(create_base_bdev nvme0 $device $((1024 * 101)))
|
|
|
|
if [ -n "$nv_cache" ]; then
|
|
|
|
nvc_bdev=$(create_nv_cache_bdev nvc0 $nv_cache $split_bdev)
|
|
|
|
fi
|
|
|
|
|
|
|
|
l2p_dram_size_mb=$(($(get_bdev_size $split_bdev) * 10 / 100 / 1024))
|
|
|
|
ftl_construct_args="bdev_ftl_create -b ftl0 -d $split_bdev --l2p_dram_limit $l2p_dram_size_mb"
|
|
|
|
|
|
|
|
[ -n "$uuid" ] && ftl_construct_args+=" -u $uuid"
|
|
|
|
[ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev"
|
|
|
|
|
|
|
|
if [ "$fast_shutdown" -eq "1" ]; then
|
2022-09-07 16:22:15 +00:00
|
|
|
ftl_construct_args+=" --fast-shutdown"
|
2022-05-31 12:16:40 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
$rpc_py -t $timeout $ftl_construct_args
|
2022-05-31 12:16:40 +00:00
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
(
|
|
|
|
echo '{"subsystems": ['
|
|
|
|
$rpc_py save_subsystem_config -n bdev
|
|
|
|
echo ']}'
|
|
|
|
) > $testdir/config/ftl.json
|
|
|
|
killprocess $svcpid
|
2022-05-31 12:16:40 +00:00
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
# Generate random data and calculate checksum
|
|
|
|
dd if=/dev/urandom of=$testdir/testfile bs=4K count=256K
|
|
|
|
md5sum $testdir/testfile > $testdir/testfile.md5
|
2022-05-31 12:16:40 +00:00
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
# Write and read back the data, verifying checksum
|
|
|
|
"$SPDK_BIN_DIR/spdk_dd" --if=$testdir/testfile --ob=ftl0 --json=$testdir/config/ftl.json
|
|
|
|
"$SPDK_BIN_DIR/spdk_dd" --ib=ftl0 --of=$testdir/testfile --json=$testdir/config/ftl.json --count=262144
|
2022-05-31 12:16:40 +00:00
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
md5sum -c $testdir/testfile.md5
|
2022-05-31 12:16:40 +00:00
|
|
|
|
2022-09-07 16:22:15 +00:00
|
|
|
# Write second time at overlapped sectors, read back and verify checkum
|
|
|
|
"$SPDK_BIN_DIR/spdk_dd" --if=$testdir/testfile --ob=ftl0 --json=$testdir/config/ftl.json --seek=131072
|
|
|
|
"$SPDK_BIN_DIR/spdk_dd" --ib=ftl0 --of=$testdir/testfile --json=$testdir/config/ftl.json --skip=131072 --count=262144
|
2022-05-31 12:16:40 +00:00
|
|
|
|
|
|
|
md5sum -c $testdir/testfile.md5
|
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
restore_kill
|