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