1#!/usr/bin/env bash 2 3curdir=$(dirname $(readlink -f "${BASH_SOURCE[0]}")) 4rootdir=$(readlink -f $curdir/../../..) 5 6source $rootdir/test/ocf/common.sh 7 8function fio_verify() { 9 fio_bdev $curdir/test.fio --aux-path=/tmp/ --ioengine=spdk_bdev "$@" 10} 11 12function cleanup() { 13 rm -f $curdir/modes.conf 14} 15 16# Clear nvme device which we will use in test 17clear_nvme 18 19trap "cleanup; exit 1" SIGINT SIGTERM EXIT 20 21# Building config is not backtrace worthy ... 22xtrace_disable 23 24config=() ocf_names=() ocf_modes=() 25 26ocf_names[1]=PT_Nvme ocf_modes[1]=pt 27ocf_names[2]=WT_Nvme ocf_modes[2]=wt 28ocf_names[3]=WB_Nvme0 ocf_modes[3]=wb 29ocf_names[4]=WB_Nvme1 ocf_modes[4]=wb 30 31mapfile -t config < <("$rootdir/scripts/gen_nvme.sh") 32 33# Drop anything from last closing ] so we can inject our own config pieces ... 34config=("${config[@]::${#config[@]}-2}") 35# ... and now convert entire array to a single string item 36config=("${config[*]}") 37 38config+=( 39 "$( 40 cat <<- JSON 41 { 42 "method": "bdev_split_create", 43 "params": { 44 "base_bdev": "Nvme0n1", 45 "split_count": 8, 46 "split_size_mb": 101 47 } 48 } 49 JSON 50 )" 51) 52 53for ((d = 0, c = 1; d <= ${#ocf_names[@]} + 2; d += 2, c++)); do 54 config+=( 55 "$( 56 cat <<- JSON 57 { 58 "method": "bdev_ocf_create", 59 "params": { 60 "name": "${ocf_names[c]}", 61 "mode": "${ocf_modes[c]}", 62 "cache_bdev_name": "Nvme0n1p$d", 63 "core_bdev_name": "Nvme0n1p$((d + 1))" 64 } 65 } 66 JSON 67 )" 68 ) 69done 70 71# First ']}' closes our config and bdev subsystem blocks 72cat <<- CONFIG > "$curdir/modes.conf" 73 {"subsystems":[ 74 $( 75 IFS="," 76 printf '%s\n' "${config[*]}" 77 ) 78 ]}]} 79CONFIG 80 81# Format the config nicely and dump it to stdout for everyone to marvel at it ... 82jq . "$curdir/modes.conf" 83 84# ... and now back to our regularly scheduled program 85xtrace_restore 86 87fio_verify --filename=PT_Nvme:WT_Nvme:WB_Nvme0:WB_Nvme1 --spdk_json_conf="$curdir/modes.conf" --thread=1 88 89trap - SIGINT SIGTERM EXIT 90cleanup 91