xref: /spdk/test/ftl/restore.sh (revision 34edd9f1bf5fda4c987f4500ddc3c9f50be32e7d)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2018 Intel Corporation
4#  All rights reserved.
5#
6testdir=$(readlink -f $(dirname $0))
7rootdir=$(readlink -f $testdir/../..)
8source $rootdir/test/common/autotest_common.sh
9source $testdir/common.sh
10
11rpc_py=$rootdir/scripts/rpc.py
12
13mount_dir=$(mktemp -d)
14
15while getopts ':u:c:f' opt; do
16	case $opt in
17		u) uuid=$OPTARG ;;
18		c) nv_cache=$OPTARG ;;
19		f) fast_shutdown=1 ;;
20		?) echo "Usage: $0 [-f] [-u UUID] [-c NV_CACHE_PCI_BDF] BASE_PCI_BDF" && exit 1 ;;
21	esac
22done
23shift $((OPTIND - 1))
24device=$1
25timeout=240
26
27restore_kill() {
28	rm -f $testdir/testfile
29	rm -f $testdir/testfile.md5
30	rm -f $testdir/config/ftl.json
31
32	killprocess $svcpid
33	remove_shm
34}
35
36trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
37
38"$SPDK_BIN_DIR/spdk_tgt" &
39svcpid=$!
40# Wait until spdk_tgt starts
41waitforlisten $svcpid
42
43split_bdev=$(create_base_bdev nvme0 $device $((1024 * 101)))
44if [ -n "$nv_cache" ]; then
45	nvc_bdev=$(create_nv_cache_bdev nvc0 $nv_cache $split_bdev)
46fi
47
48l2p_dram_size_mb=$(($(get_bdev_size $split_bdev) * 10 / 100 / 1024))
49ftl_construct_args="bdev_ftl_create -b ftl0 -d $split_bdev --l2p_dram_limit $l2p_dram_size_mb"
50
51[ -n "$uuid" ] && ftl_construct_args+=" -u $uuid"
52[ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev"
53
54if [ "$fast_shutdown" -eq "1" ]; then
55	ftl_construct_args+=" --fast-shutdown"
56fi
57
58$rpc_py -t $timeout $ftl_construct_args
59
60(
61	echo '{"subsystems": ['
62	$rpc_py save_subsystem_config -n bdev
63	echo ']}'
64) > $testdir/config/ftl.json
65$rpc_py bdev_ftl_unload -b ftl0
66killprocess $svcpid
67
68# Generate random data and calculate checksum
69dd if=/dev/urandom of=$testdir/testfile bs=4K count=256K
70md5sum $testdir/testfile > $testdir/testfile.md5
71
72# Write and read back the data, verifying checksum
73"$SPDK_BIN_DIR/spdk_dd" --if=$testdir/testfile --ob=ftl0 --json=$testdir/config/ftl.json
74"$SPDK_BIN_DIR/spdk_dd" --ib=ftl0 --of=$testdir/testfile --json=$testdir/config/ftl.json --count=262144
75
76md5sum -c $testdir/testfile.md5
77
78# Write second time at overlapped sectors, read back and verify checksum
79"$SPDK_BIN_DIR/spdk_dd" --if=$testdir/testfile --ob=ftl0 --json=$testdir/config/ftl.json --seek=131072
80"$SPDK_BIN_DIR/spdk_dd" --ib=ftl0 --of=$testdir/testfile --json=$testdir/config/ftl.json --skip=131072 --count=262144
81
82md5sum -c $testdir/testfile.md5
83
84trap - SIGINT SIGTERM EXIT
85restore_kill
86