xref: /spdk/test/ftl/common.sh (revision c680e3a05b1a903c18bf3f75b732765607126f45)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2019 Intel Corporation
3#  All rights reserved.
4#
5
6# Common utility functions to be sourced by the libftl test scripts
7
8function clear_lvols() {
9	stores=$("$rootdir/scripts/rpc.py" bdev_lvol_get_lvstores | jq -r ".[] | .uuid")
10	for lvs in $stores; do
11		"$rootdir/scripts/rpc.py" bdev_lvol_delete_lvstore -u $lvs
12	done
13}
14
15function create_nv_cache_bdev() {
16	local name=$1
17	local cache_bdf=$2
18	local base_bdev=$3
19
20	# use 5% space of base bdev
21	local size=$(($(get_bdev_size $base_bdev) * 5 / 100))
22
23	# Create NVMe bdev on specified device and split it so that it has the desired size
24	local nvc_bdev
25	nvc_bdev=$($rootdir/scripts/rpc.py bdev_nvme_attach_controller -b $name -t PCIe -a $cache_bdf)
26
27	local nvc_size
28	nvc_size=$(get_bdev_size $nvc_bdev)
29	if [[ $size -gt $nvc_size ]]; then
30		size=nvc_size
31	fi
32	$rootdir/scripts/rpc.py bdev_split_create $nvc_bdev -s $size 1
33}
34
35function create_base_bdev() {
36	local name=$1
37	local base_bdf=$2
38	local size=$3
39
40	# Create NVMe bdev on specified device and split it so that it has the desired size
41	local base_bdev
42	base_bdev=$($rootdir/scripts/rpc.py bdev_nvme_attach_controller -b $name -t PCIe -a $base_bdf)
43
44	local base_size
45	base_size=$(get_bdev_size $base_bdev)
46	if [[ $size -le $base_size ]]; then
47		$rootdir/scripts/rpc.py bdev_split_create $base_bdev -s $size 1
48	else
49		clear_lvols
50		lvs=$($rootdir/scripts/rpc.py bdev_lvol_create_lvstore $base_bdev lvs)
51		$rootdir/scripts/rpc.py bdev_lvol_create ${base_bdev}p0 $size -t -u $lvs
52	fi
53}
54
55# Remove not needed files from shared memory
56function remove_shm() {
57	echo Remove shared memory files
58	rm -f rm -f /dev/shm/ftl*
59	rm -f rm -f /dev/hugepages/ftl*
60	rm -f rm -f /dev/shm/spdk*
61	rm -f rm -f /dev/shm/iscsi
62	rm -f rm -f /dev/hugepages/spdk*
63}
64