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