From afc4f9134126fa94cd5c37128a4d18d76ad1277b Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Tue, 19 Feb 2019 05:06:12 -0500 Subject: [PATCH] bdev/ftl: Add json config generation Change-Id: I0baa6cfb4e4cb2a5ae68de730edb75011bd8e49d Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/445254 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- scripts/gen_ftl.sh | 38 ++++++++++++++++++++++++++++++++++---- test/ftl/ftl.sh | 4 ++++ test/ftl/json.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100755 test/ftl/json.sh diff --git a/scripts/gen_ftl.sh b/scripts/gen_ftl.sh index d1af330d3..ba34f42d8 100755 --- a/scripts/gen_ftl.sh +++ b/scripts/gen_ftl.sh @@ -5,9 +5,10 @@ set -e rootdir=$(readlink -f $(dirname $0))/.. function usage { - echo "Usage: $0 -a TRANSPORT_ADDR -n BDEV_NAME -l PUNITS [-u UUID] [-c CACHE]" + echo "Usage: [-j] $0 -a TRANSPORT_ADDR -n BDEV_NAME -l PUNITS [-u UUID] [-c CACHE]" echo "UUID is required when restoring device state" echo + echo "-j json format" echo "TRANSPORT_ADDR - SSD's PCIe address" echo "BDEV_NAME - name of the bdev" echo "PUNITS - bdev's parallel unit range (e.g. 0-3)" @@ -15,15 +16,40 @@ function usage { echo "CACHE - name of the bdev to be used as write buffer cache" } -function generate_config { +function create_classic_config { echo "[Ftl]" echo " TransportID \"trtype:PCIe traddr:$1\" $2 $3 $4 $5" } +function create_json_config() +{ + echo "{" + echo '"subsystem": "bdev",' + echo '"config": [' + echo '{' + echo '"method": "construct_ftl_bdev",' + echo '"params": {' + echo "\"name\": \"$2\"," + echo '"trtype": "PCIe",' + echo "\"traddr\": \"$1\"," + echo "\"punits\": \"$3\"," + if [ -n "$5" ]; then + echo "\"uuid\": \"$4\"," + echo "\"cache\": \"$5\"" + else + echo "\"uuid\": \"$4\"" + fi + echo '}' + echo '}' + echo ']' + echo '}' +} + uuid=00000000-0000-0000-0000-000000000000 -while getopts ":a:n:l:m:u:c:" arg; do +while getopts "ja:n:l:m:u:c:" arg; do case "$arg" in + j) json=1 ;; a) addr=$OPTARG ;; n) name=$OPTARG ;; l) punits=$OPTARG ;; @@ -41,4 +67,8 @@ if [[ -z "$addr" || -z "$name" || -z "$punits" ]]; then exit 1 fi -generate_config $addr $name $punits $uuid $cache +if [ -n "$json" ]; then + create_json_config $addr $name $punits $uuid $cache +else + create_classic_config $addr $name $punits $uuid $cache +fi diff --git a/test/ftl/ftl.sh b/test/ftl/ftl.sh index fdd80e0c1..5b04c747e 100755 --- a/test/ftl/ftl.sh +++ b/test/ftl/ftl.sh @@ -41,6 +41,10 @@ timing_enter restore run_test suite $testdir/restore.sh $device timing_exit restore +timing_enter json +run_test suite $testdir/json.sh $device +timing_exit json + if [ $SPDK_TEST_FTL_EXTENDED -eq 1 ]; then timing_enter fio_basic run_test suite $testdir/fio.sh $device basic diff --git a/test/ftl/json.sh b/test/ftl/json.sh new file mode 100755 index 000000000..d32731f64 --- /dev/null +++ b/test/ftl/json.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -e + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../..) +rpc_py=$rootdir/scripts/rpc.py + +source $rootdir/test/common/autotest_common.sh + +device=$1 +FTL_BDEV_CONF=$testdir/config/ftl.json + +json_kill() { + killprocess $svcpid +} + +trap "json_kill; exit 1" SIGINT SIGTERM EXIT + +$rootdir/test/app/bdev_svc/bdev_svc & svcpid=$! +waitforlisten $svcpid + +# Create new bdev from json configuration +$rootdir/scripts/gen_ftl.sh -j -a $device -n nvme0 -l 0-3 | $rpc_py load_subsystem_config + +uuid=$($rpc_py get_bdevs | jq -r '.[0].uuid') + +$rpc_py delete_ftl_bdev -b nvme0 + +# Restore bdev from json configuration +$rootdir/scripts/gen_ftl.sh -j -a $device -n nvme0 -l 0-3 -u $uuid | $rpc_py load_subsystem_config +# Create new bdev from json configuration +$rootdir/scripts/gen_ftl.sh -j -a $device -n nvme1 -l 4-5 | $rpc_py load_subsystem_config +# Create new bdev from RPC +$rpc_py construct_ftl_bdev -b nvme2 -a $device -l 7-7 + +$rpc_py delete_ftl_bdev -b nvme2 +$rpc_py delete_ftl_bdev -b nvme0 +$rpc_py delete_ftl_bdev -b nvme1 + +# TODO: add negative test cases + +trap - SIGINT SIGTERM EXIT +json_kill