xref: /spdk/test/lvol/common.sh (revision c680e3a05b1a903c18bf3f75b732765607126f45)
1#  SPDX-License-Identifier: BSD-3-Clause
2#  Copyright (C) 2019 Intel Corporation
3#  All rights reserved.
4#
5
6MALLOC_SIZE_MB=128
7MALLOC_BS=512
8AIO_SIZE_MB=400
9AIO_BS=4096
10LVS_DEFAULT_CLUSTER_SIZE_MB=4
11LVS_DEFAULT_CLUSTER_SIZE=$((LVS_DEFAULT_CLUSTER_SIZE_MB * 1024 * 1024))
12# reserve some MBs for lvolstore metadata
13LVS_DEFAULT_CAPACITY_MB=$((MALLOC_SIZE_MB - LVS_DEFAULT_CLUSTER_SIZE_MB))
14LVS_DEFAULT_CAPACITY=$((LVS_DEFAULT_CAPACITY_MB * 1024 * 1024))
15
16function get_bdev_jq() {
17	rpc_cmd_simple_data_json bdev "$@"
18}
19
20function get_lvs_jq() {
21	rpc_cmd_simple_data_json lvs "$@"
22}
23
24function check_leftover_devices() {
25	leftover_bdevs=$(rpc_cmd bdev_get_bdevs)
26	[ "$(jq length <<< "$leftover_bdevs")" == "0" ]
27	leftover_lvs=$(rpc_cmd bdev_lvol_get_lvstores)
28	[ "$(jq length <<< "$leftover_lvs")" == "0" ]
29}
30
31function round_down() {
32	local CLUSTER_SIZE_MB=$LVS_DEFAULT_CLUSTER_SIZE_MB
33	if [ -n "$2" ]; then
34		CLUSTER_SIZE_MB=$2
35	fi
36	echo $(($1 / CLUSTER_SIZE_MB * CLUSTER_SIZE_MB))
37}
38
39function run_fio_test() {
40	local file=$1
41	local offset=$2
42	local size=$3
43	local rw=$4
44	local pattern=$5
45	local extra_params=$6
46
47	local pattern_template="" fio_template=""
48	if [[ -n "$pattern" ]]; then
49		pattern_template="--do_verify=1 --verify=pattern --verify_pattern=$pattern --verify_state_save=0"
50	fi
51
52	fio_template="fio --name=fio_test --filename=$file --offset=$offset --size=$size --rw=$rw --direct=1 $extra_params $pattern_template"
53	$fio_template
54}
55
56function calc() {
57	bc -l <<< "define ceil(x) { scale=0; return(x + (x % 1 > 0))/1 } $1"
58}
59