2018-10-29 14:40:34 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
testdir=$(readlink -f $(dirname $0))
|
|
|
|
rootdir=$(readlink -f $testdir/../..)
|
|
|
|
source $rootdir/test/common/autotest_common.sh
|
2019-06-18 13:19:06 +00:00
|
|
|
source $testdir/common.sh
|
2018-10-29 14:40:34 +00:00
|
|
|
|
2019-06-10 07:16:46 +00:00
|
|
|
rpc_py=$rootdir/scripts/rpc.py
|
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
mount_dir=$(mktemp -d)
|
2019-06-18 13:19:06 +00:00
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
device=$1
|
2021-06-10 14:06:53 +00:00
|
|
|
config=$SPDK_TEST_STORAGE/ftl.json
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
restore_kill() {
|
|
|
|
if mount | grep $mount_dir; then
|
|
|
|
umount $mount_dir
|
|
|
|
fi
|
|
|
|
rm -rf $mount_dir
|
2021-06-10 14:06:53 +00:00
|
|
|
rm -f "$SPDK_TEST_STORAGE/testfile.md5"
|
|
|
|
rm -f "$SPDK_TEST_STORAGE/testfile2.md5"
|
|
|
|
rm -f "$config"
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
killprocess $svcpid
|
|
|
|
rmmod nbd || true
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
|
|
|
|
|
2020-05-11 21:15:03 +00:00
|
|
|
"$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) &
|
2020-05-07 11:27:06 +00:00
|
|
|
svcpid=$!
|
2019-07-10 09:38:49 +00:00
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 14:40:34 +00:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2019-10-25 07:31:14 +00:00
|
|
|
$rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie
|
|
|
|
$rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1
|
|
|
|
ftl_construct_args="bdev_ftl_create -b ftl0 -d nvme0n1"
|
2019-06-18 13:19:06 +00:00
|
|
|
|
|
|
|
$rpc_py $ftl_construct_args
|
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
# Load the nbd driver
|
|
|
|
modprobe nbd
|
2019-10-25 07:31:14 +00:00
|
|
|
$rpc_py nbd_start_disk ftl0 /dev/nbd0
|
2018-10-29 14:40:34 +00:00
|
|
|
waitfornbd nbd0
|
|
|
|
|
2021-06-10 14:06:53 +00:00
|
|
|
$rpc_py save_config > "$config"
|
2019-01-28 13:12:21 +00:00
|
|
|
|
2018-10-29 14:40:34 +00:00
|
|
|
# Prepare the disk by creating ext4 fs and putting a file on it
|
2020-03-06 11:47:48 +00:00
|
|
|
make_filesystem ext4 /dev/nbd0
|
2018-10-29 14:40:34 +00:00
|
|
|
mount /dev/nbd0 $mount_dir
|
|
|
|
dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K
|
|
|
|
sync
|
|
|
|
mount -o remount /dev/nbd0 $mount_dir
|
2021-06-10 14:06:53 +00:00
|
|
|
md5sum $mount_dir/testfile > "$SPDK_TEST_STORAGE/testfile.md5"
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
# Kill bdev service and start it again
|
|
|
|
umount $mount_dir
|
|
|
|
killprocess $svcpid
|
|
|
|
|
2020-05-11 21:15:03 +00:00
|
|
|
"$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) -L ftl_init &
|
2020-05-07 11:27:06 +00:00
|
|
|
svcpid=$!
|
2019-07-10 09:38:49 +00:00
|
|
|
# Wait until spdk_tgt starts
|
2018-10-29 14:40:34 +00:00
|
|
|
waitforlisten $svcpid
|
|
|
|
|
2021-06-10 14:06:53 +00:00
|
|
|
$rpc_py load_config < "$config"
|
2019-06-26 09:39:12 +00:00
|
|
|
waitfornbd nbd0
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
mount /dev/nbd0 $mount_dir
|
2019-06-11 13:35:22 +00:00
|
|
|
|
|
|
|
# Write second file, to make sure writer thread has restored properly
|
|
|
|
dd if=/dev/urandom of=$mount_dir/testfile2 bs=4K count=256K
|
2021-06-10 14:06:53 +00:00
|
|
|
md5sum $mount_dir/testfile2 > "$SPDK_TEST_STORAGE/testfile2.md5"
|
2019-06-11 13:35:22 +00:00
|
|
|
|
|
|
|
# Make sure second file will be read from disk
|
|
|
|
echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
|
|
|
|
# Check both files have proper data
|
2021-06-10 14:06:53 +00:00
|
|
|
md5sum -c "$SPDK_TEST_STORAGE/testfile.md5"
|
|
|
|
md5sum -c "$SPDK_TEST_STORAGE/testfile2.md5"
|
2018-10-29 14:40:34 +00:00
|
|
|
|
|
|
|
trap - SIGINT SIGTERM EXIT
|
|
|
|
restore_kill
|