From f2c8083ef37ff10d227a6a3538bd983570be20ad Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Fri, 25 Oct 2019 03:31:14 -0400 Subject: [PATCH] lib/ftl: Functional tests This patch adjust functional tests to new FTL stack. Change-Id: I0b8ff08c61793d7f1685942031aecf9cc88d1f24 Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468738 Community-CI: Broadcom SPDK FC-NVMe CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber --- autotest.sh | 6 +++--- scripts/gen_ftl.sh | 38 +++++++++++++------------------------- scripts/rpc.py | 12 ++++-------- scripts/rpc/bdev.py | 8 +++----- test/ftl/bdevperf.sh | 23 ++++++++++++++++++++--- test/ftl/common.sh | 5 +++++ test/ftl/dirty_shutdown.sh | 14 +++++++++----- test/ftl/ftl.sh | 17 +++++++++++------ test/ftl/json.sh | 20 +++++++++----------- test/ftl/restore.sh | 15 ++++++++++----- 10 files changed, 87 insertions(+), 71 deletions(-) diff --git a/autotest.sh b/autotest.sh index 9b8adc0fa..a3b161f57 100755 --- a/autotest.sh +++ b/autotest.sh @@ -263,9 +263,9 @@ if [ $SPDK_RUN_FUNCTIONAL_TEST -eq 1 ]; then run_test "ocf" ./test/ocf/ocf.sh fi - # if [ $SPDK_TEST_FTL -eq 1 ]; then - # run_test "ftl" ./test/ftl/ftl.sh - # fi + if [ $SPDK_TEST_FTL -eq 1 ]; then + run_test "ftl" ./test/ftl/ftl.sh + fi if [ $SPDK_TEST_VMD -eq 1 ]; then run_test "vmd" ./test/vmd/vmd.sh diff --git a/scripts/gen_ftl.sh b/scripts/gen_ftl.sh index e9d1311aa..5d7e4158a 100755 --- a/scripts/gen_ftl.sh +++ b/scripts/gen_ftl.sh @@ -5,21 +5,15 @@ set -e rootdir=$(readlink -f $(dirname $0))/.. function usage { - echo "Usage: [-j] $0 -a TRANSPORT_ADDR -n BDEV_NAME [-u UUID] [-c CACHE]" + echo "Usage: [-j] $0 -n BDEV_NAME -d BASE_BDEV [-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 "BASE_BDEV - name of the bdev to be used as underlying device" echo "UUID - bdev's uuid (used when in restore mode)" echo "CACHE - name of the bdev to be used as write buffer cache" } -function create_classic_config { - echo "[Ftl]" - echo " TransportID \"trtype:PCIe traddr:$1\" $2 $3 $4" -} - function create_json_config() { echo "{" @@ -28,9 +22,8 @@ function create_json_config() echo '{' echo '"method": "bdev_ftl_create",' echo '"params": {' - echo "\"name\": \"$2\"," - echo '"trtype": "PCIe",' - echo "\"traddr\": \"$1\"," + echo "\"name\": \"$1\"," + echo "\"base_bdev\": \"$2\"," if [ -n "$4" ]; then echo "\"uuid\": \"$3\"," echo "\"cache\": \"$4\"" @@ -45,27 +38,22 @@ function create_json_config() uuid=00000000-0000-0000-0000-000000000000 -while getopts "ja:n:l:m:u:c:h" arg; do +while getopts ":c:d:hn:u:" arg; do case "$arg" in - j) json=1 ;; - a) addr=$OPTARG ;; - n) name=$OPTARG ;; - u) uuid=$OPTARG ;; - c) cache=$OPTARG ;; + n) name=$OPTARG ;; + d) base_bdev=$OPTARG ;; + u) uuid=$OPTARG ;; + c) cache=$OPTARG ;; h) usage - exit 0 ;; + exit 0 ;; *) usage - exit 1 ;; + exit 1 ;; esac done -if [[ -z "$addr" || -z "$name" ]]; then +if [[ -z "$name" || -z "$base_bdev" ]]; then usage exit 1 fi -if [ -n "$json" ]; then - create_json_config $addr $name $uuid $cache -else - create_classic_config $addr $name $uuid $cache -fi +create_json_config $name $base_bdev $uuid $cache diff --git a/scripts/rpc.py b/scripts/rpc.py index cb1bb3340..4421c4c92 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -1540,21 +1540,17 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse print_dict(rpc.bdev.bdev_ftl_create(args.client, name=args.name, - trtype=args.trtype, - traddr=args.traddr, + base_bdev=args.base_bdev, uuid=args.uuid, cache=args.cache, allow_open_bands=args.allow_open_bands, overprovisioning=args.overprovisioning, **arg_limits)) - p = subparsers.add_parser('bdev_ftl_create', aliases=['construct_ftl_bdev'], - help='Add FTL bdev') + p = subparsers.add_parser('bdev_ftl_create', aliases=['construct_ftl_bdev'], help='Add FTL bdev') p.add_argument('-b', '--name', help="Name of the bdev", required=True) - p.add_argument('-t', '--trtype', - help='NVMe target trtype: e.g., pcie', default='pcie') - p.add_argument('-a', '--traddr', - help='NVMe target address: e.g., an ip address or BDF', required=True) + p.add_argument('-d', '--base_bdev', help='Name of zoned bdev used as underlying device', + required=True) p.add_argument('-u', '--uuid', help='UUID of restored bdev (not applicable when creating new ' 'instance): e.g. b286d19a-0059-4709-abcd-9f7732b1567d (optional)') p.add_argument('-c', '--cache', help='Name of the bdev to be used as a write buffer cache (optional)') diff --git a/scripts/rpc/bdev.py b/scripts/rpc/bdev.py index 2929947e9..301805ead 100644 --- a/scripts/rpc/bdev.py +++ b/scripts/rpc/bdev.py @@ -884,18 +884,16 @@ def bdev_split_delete(client, base_bdev): @deprecated_alias('construct_ftl_bdev') -def bdev_ftl_create(client, name, trtype, traddr, **kwargs): +def bdev_ftl_create(client, name, base_bdev, **kwargs): """Construct FTL bdev Args: name: name of the bdev - trtype: transport type - traddr: transport address + base_bdev: name of the base bdev kwargs: optional parameters """ params = {'name': name, - 'trtype': trtype, - 'traddr': traddr} + 'base_bdev': base_bdev} for key, value in kwargs.items(): if value is not None: params[key] = value diff --git a/test/ftl/bdevperf.sh b/test/ftl/bdevperf.sh index 64aad6349..109bc27b5 100755 --- a/test/ftl/bdevperf.sh +++ b/test/ftl/bdevperf.sh @@ -3,15 +3,32 @@ testdir=$(readlink -f $(dirname $0)) rootdir=$(readlink -f $testdir/../..) source $rootdir/test/common/autotest_common.sh +source $testdir/common.sh tests=('-q 1 -w randwrite -t 4 -o 69632' '-q 128 -w randwrite -t 4 -o 4096' '-q 128 -w verify -t 4 -o 4096') device=$1 -ftl_bdev_conf=$testdir/config/ftl.conf +rpc_py=$rootdir/scripts/rpc.py -$rootdir/scripts/gen_ftl.sh -a $device -n nvme0 > $ftl_bdev_conf +ftl_bdev_conf=$testdir/config/ftl.conf +gen_ftl_nvme_conf > $ftl_bdev_conf for (( i=0; i<${#tests[@]}; i++ )) do timing_enter "${tests[$i]}" - $rootdir/test/bdev/bdevperf/bdevperf -c $ftl_bdev_conf ${tests[$i]} + $rootdir/test/bdev/bdevperf/bdevperf -z -T ftl0 ${tests[$i]} -c $ftl_bdev_conf & + bdevperf_pid=$! + + trap 'killprocess $bdevperf_pid; exit 1' SIGINT SIGTERM EXIT + waitforlisten $bdevperf_pid + $rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie + $rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 + $rpc_py bdev_ftl_create -b ftl0 -d nvme0n1 + $rootdir/test/bdev/bdevperf/bdevperf.py perform_tests + $rpc_py delete_ftl_bdev -b ftl0 + $rpc_py bdev_ocssd_delete nvme0n1 + $rpc_py delete_nvme_controller nvme0 + killprocess $bdevperf_pid + trap - SIGINT SIGTERM EXIT timing_exit "${tests[$i]}" done + +rm -f $ftl_bdev_conf diff --git a/test/ftl/common.sh b/test/ftl/common.sh index 0e0fb5864..492233251 100644 --- a/test/ftl/common.sh +++ b/test/ftl/common.sh @@ -46,3 +46,8 @@ function create_nv_cache_bdev() { nvc_bdev=$($rootdir/scripts/rpc.py bdev_nvme_attach_controller -b $name -t PCIe -a $cache_bdf) $rootdir/scripts/rpc.py bdev_split_create $nvc_bdev -s $size 1 } + +function gen_ftl_nvme_conf() { + echo "[Nvme]" + echo " AdminPollRate 100" +} diff --git a/test/ftl/dirty_shutdown.sh b/test/ftl/dirty_shutdown.sh index 274937633..cb1942778 100755 --- a/test/ftl/dirty_shutdown.sh +++ b/test/ftl/dirty_shutdown.sh @@ -17,13 +17,15 @@ done shift $((OPTIND -1)) device=$1 +ftl_bdev_conf=$testdir/config/ftl.conf +gen_ftl_nvme_conf > $ftl_bdev_conf restore_kill() { rm -f $testdir/config/ftl.json rm -f $testdir/testfile.md5 rm -f $testdir/testfile2.md5 + rm -f $ftl_bdev_conf - $rpc_py bdev_ftl_delete -b nvme0 || true killprocess $svcpid || true rmmod nbd || true } @@ -38,14 +40,16 @@ pu_count=$((num_group * num_pu)) # Write one band worth of data + one extra chunk data_size=$((chunk_size * (pu_count + 1))) -$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$! +$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf & svcpid=$! waitforlisten $svcpid if [ -n "$nv_cache" ]; then nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $pu_count) fi -ftl_construct_args="bdev_ftl_create -b nvme0 -a $device -o" +$rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie +$rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1 +ftl_construct_args="bdev_ftl_create -b ftl0 -d nvme0n1 -o" [ -n "$nvc_bdev" ] && ftl_construct_args+=" -c $nvc_bdev" [ -n "$uuid" ] && ftl_construct_args+=" -u $uuid" @@ -54,7 +58,7 @@ $rpc_py $ftl_construct_args # Load the nbd driver modprobe nbd -$rpc_py nbd_start_disk nvme0 /dev/nbd0 +$rpc_py nbd_start_disk ftl0 /dev/nbd0 waitfornbd nbd0 $rpc_py save_config > $testdir/config/ftl.json @@ -68,7 +72,7 @@ $rpc_py nbd_stop_disk /dev/nbd0 kill -9 $svcpid rm -f /dev/shm/spdk_tgt_trace.pid$svcpid -$rootdir/app/spdk_tgt/spdk_tgt -L ftl_init & svcpid=$! +$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf -L ftl_init & svcpid=$! waitforlisten $svcpid $rpc_py load_config < $testdir/config/ftl.json diff --git a/test/ftl/ftl.sh b/test/ftl/ftl.sh index fb7eaef9a..adea2cf94 100755 --- a/test/ftl/ftl.sh +++ b/test/ftl/ftl.sh @@ -61,14 +61,19 @@ run_test "ftl_json" $testdir/json.sh $device if [ $SPDK_TEST_FTL_EXTENDED -eq 1 ]; then run_test "ftl_fio_basic" $testdir/fio.sh $device basic - $rootdir/app/spdk_tgt/spdk_tgt & - svc_pid=$! + ftl_bdev_conf=$testdir/config/ftl.conf + gen_ftl_nvme_conf > $ftl_bdev_conf + $rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf & svcpid=$! - trap 'killprocess $svc_pid; exit 1' SIGINT SIGTERM EXIT + trap 'killprocess $svcpid; exit 1' SIGINT SIGTERM EXIT - waitforlisten $svc_pid - uuid=$($rpc_py bdev_ftl_create -b nvme0 -a $device | jq -r '.uuid') - killprocess $svc_pid + waitforlisten $svcpid + + $rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie + $rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1 + uuid=$($rpc_py bdev_ftl_create -b ftl0 -d nvme0n1 | jq -r '.uuid') + killprocess $svcpid + rm -f $ftl_bdev_conf trap - SIGINT SIGTERM EXIT diff --git a/test/ftl/json.sh b/test/ftl/json.sh index 11f902f5a..457e8f4b4 100755 --- a/test/ftl/json.sh +++ b/test/ftl/json.sh @@ -3,20 +3,22 @@ testdir=$(readlink -f $(dirname $0)) rootdir=$(readlink -f $testdir/../..) source $rootdir/test/common/autotest_common.sh +source $testdir/common.sh rpc_py=$rootdir/scripts/rpc.py - device=$1 -FTL_BDEV_CONF=$testdir/config/ftl.json +ftl_bdev_conf=$testdir/config/ftl.conf +gen_ftl_nvme_conf > $ftl_bdev_conf json_kill() { killprocess $svcpid + rm -f $ftl_bdev_conf } trap "json_kill; exit 1" SIGINT SIGTERM EXIT -$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$! +$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf & svcpid=$! waitforlisten $svcpid # Create new bdev from json configuration @@ -27,16 +29,12 @@ $rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1 waitforbdev ftl0 uuid=$($rpc_py bdev_get_bdevs | jq -r ".[] | select(.name==\"ftl0\").uuid") -$rpc_py bdev_ftl_delete -b nvme0 +$rpc_py bdev_ftl_delete -b ftl0 # Restore bdev from json configuration -$rootdir/scripts/gen_ftl.sh -j -a $device -n nvme0 -u $uuid | $rpc_py load_subsystem_config -$rpc_py bdev_ftl_delete -b nvme0 -# Create new bdev from RPC -$rpc_py bdev_ftl_create -b nvme1 -a $device -$rpc_py bdev_ftl_delete -b nvme1 - -# TODO: add negative test cases +$rootdir/scripts/gen_ftl.sh -n ftl0 -d nvme0n1 -u $uuid | $rpc_py load_subsystem_config +$rpc_py bdev_ftl_delete -b ftl0 +$rpc_py bdev_nvme_detach_controller nvme0 trap - SIGINT SIGTERM EXIT json_kill diff --git a/test/ftl/restore.sh b/test/ftl/restore.sh index 867575fae..b1a97b3fd 100755 --- a/test/ftl/restore.sh +++ b/test/ftl/restore.sh @@ -22,6 +22,9 @@ num_group=$(get_num_group $device) num_pu=$(get_num_pu $device) pu_count=$((num_group * num_pu)) +ftl_bdev_conf=$testdir/config/ftl.conf +gen_ftl_nvme_conf > $ftl_bdev_conf + restore_kill() { if mount | grep $mount_dir; then umount $mount_dir @@ -30,15 +33,15 @@ restore_kill() { rm -f $testdir/testfile.md5 rm -f $testdir/testfile2.md5 rm -f $testdir/config/ftl.json + rm -f $ftl_bdev_conf - $rpc_py bdev_ftl_delete -b nvme0 killprocess $svcpid rmmod nbd || true } trap "restore_kill; exit 1" SIGINT SIGTERM EXIT -$rootdir/app/spdk_tgt/spdk_tgt & svcpid=$! +$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf & svcpid=$! # Wait until spdk_tgt starts waitforlisten $svcpid @@ -46,7 +49,9 @@ if [ -n "$nv_cache" ]; then nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $pu_count) fi -ftl_construct_args="bdev_ftl_create -b nvme0 -a $device" +$rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie +$rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1 +ftl_construct_args="bdev_ftl_create -b ftl0 -d nvme0n1" [ -n "$uuid" ] && ftl_construct_args+=" -u $uuid" [ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev" @@ -55,7 +60,7 @@ $rpc_py $ftl_construct_args # Load the nbd driver modprobe nbd -$rpc_py nbd_start_disk nvme0 /dev/nbd0 +$rpc_py nbd_start_disk ftl0 /dev/nbd0 waitfornbd nbd0 $rpc_py save_config > $testdir/config/ftl.json @@ -72,7 +77,7 @@ md5sum $mount_dir/testfile > $testdir/testfile.md5 umount $mount_dir killprocess $svcpid -$rootdir/app/spdk_tgt/spdk_tgt -L ftl_init & svcpid=$! +$rootdir/app/spdk_tgt/spdk_tgt -c $ftl_bdev_conf -L ftl_init & svcpid=$! # Wait until spdk_tgt starts waitforlisten $svcpid