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