xref: /spdk/test/bdev/chaining.sh (revision 6ecf0442ef0837776cebebdd988431f2420be303)
16060669eSKonrad Sztyber#!/usr/bin/env bash
26060669eSKonrad Sztyber# SPDX-License-Identifier: BSD-3-Clause
36060669eSKonrad Sztyber# Copyright (C) 2023 Intel Corporation
46060669eSKonrad Sztyber# All rights reserved.
56060669eSKonrad Sztyber#
66060669eSKonrad Sztyber
76060669eSKonrad Sztybertestdir=$(readlink -f $(dirname $0))
86060669eSKonrad Sztyberrootdir=$(readlink -f $testdir/../..)
96060669eSKonrad Sztyber
106060669eSKonrad Sztyber# Use TCP as the default nvmf transport
116060669eSKonrad SztyberTEST_TRANSPORT=${TEST_TRANSPORT:=tcp}
126060669eSKonrad Sztyber
136060669eSKonrad Sztybersource "$rootdir/test/common/autotest_common.sh"
146060669eSKonrad Sztybersource "$rootdir/test/nvmf/common.sh"
156060669eSKonrad Sztyber
166060669eSKonrad Sztybernqn=nqn.2016-06.io.spdk:cnode0
176060669eSKonrad Sztyberkey0=(00112233445566778899001122334455 11223344556677889900112233445500)
186060669eSKonrad Sztyberkey1=(22334455667788990011223344550011 33445566778899001122334455001122)
192ed026b1SKonrad Sztyberbperfsock=/var/tmp/bperf.sock
206060669eSKonrad Sztyberdeclare -A stats
216060669eSKonrad Sztyber
222ed026b1SKonrad Sztyberrpc_bperf() { "$rootdir/scripts/rpc.py" -s "$bperfsock" "$@"; }
232ed026b1SKonrad Sztyber
246060669eSKonrad Sztyberspdk_dd() {
256060669eSKonrad Sztyber	local config
266060669eSKonrad Sztyber
276060669eSKonrad Sztyber	# Disable auto-examine to avoid seeing the examine callbacks' reads in accel stats
286060669eSKonrad Sztyber	config=$("$rootdir/scripts/gen_nvme.sh" --mode=remote --json-with-subsystems \
296060669eSKonrad Sztyber		--trid="$TEST_TRANSPORT:$NVMF_FIRST_TARGET_IP:$NVMF_PORT:$nqn" \
306060669eSKonrad Sztyber		| jq '.subsystems[0].config[.subsystems[0].config | length] |=
316060669eSKonrad Sztyber			{"method": "bdev_set_options", "params": {"bdev_auto_examine": false}}')
326060669eSKonrad Sztyber
336060669eSKonrad Sztyber	"$rootdir/build/bin/spdk_dd" -c <(echo "$config") "$@"
346060669eSKonrad Sztyber}
356060669eSKonrad Sztyber
366060669eSKonrad Sztyberget_stat() {
372ed026b1SKonrad Sztyber	local event opcode rpc
386060669eSKonrad Sztyber
392ed026b1SKonrad Sztyber	event="$1" opcode="$2" rpc=${3:-rpc_cmd}
406060669eSKonrad Sztyber	if [[ -z "$opcode" ]]; then
412ed026b1SKonrad Sztyber		"$rpc" accel_get_stats | jq -r ".$event"
426060669eSKonrad Sztyber	else
432ed026b1SKonrad Sztyber		"$rpc" accel_get_stats \
446060669eSKonrad Sztyber			| jq -r ".operations[] | select(.opcode == \"$opcode\").$event"
456060669eSKonrad Sztyber	fi
466060669eSKonrad Sztyber}
476060669eSKonrad Sztyber
482ed026b1SKonrad Sztyberget_stat_bperf() { get_stat "$1" "$2" rpc_bperf; }
492ed026b1SKonrad Sztyber
506060669eSKonrad Sztyberupdate_stats() {
51a52a8a01SKonrad Sztyber	stats["sequence_executed"]=$(get_stat sequence_executed)
52a52a8a01SKonrad Sztyber	stats["encrypt_executed"]=$(get_stat executed encrypt)
53a52a8a01SKonrad Sztyber	stats["decrypt_executed"]=$(get_stat executed decrypt)
54a52a8a01SKonrad Sztyber	stats["copy_executed"]=$(get_stat executed copy)
556060669eSKonrad Sztyber}
566060669eSKonrad Sztyber
573824f6e3SKonrad Sztybertgtcleanup() {
58a52a8a01SKonrad Sztyber	rm -f "$input" "$output"
596060669eSKonrad Sztyber	nvmftestfini
606060669eSKonrad Sztyber}
616060669eSKonrad Sztyber
623824f6e3SKonrad Sztyberbperfcleanup() {
63a52a8a01SKonrad Sztyber	[[ -n "$bperfpid" ]] && killprocess $bperfpid
643824f6e3SKonrad Sztyber}
653824f6e3SKonrad Sztyber
666060669eSKonrad Sztybernvmftestinit
676060669eSKonrad Sztybernvmfappstart -m 0x2
686060669eSKonrad Sztyber
696060669eSKonrad Sztyberinput=$(mktemp) output=$(mktemp)
703824f6e3SKonrad Sztybertrap 'tgtcleanup; exit 1' SIGINT SIGTERM EXIT
716060669eSKonrad Sztyber
726060669eSKonrad Sztyberrpc_cmd <<- CONFIG
736060669eSKonrad Sztyber	bdev_malloc_create 32 4096 -b malloc0
746060669eSKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0
756060669eSKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key1[0]}" -e "${key1[1]}" -n key1
766060669eSKonrad Sztyber	bdev_crypto_create malloc0 crypto0 -n key0
776060669eSKonrad Sztyber	bdev_crypto_create crypto0 crypto1 -n key1
786060669eSKonrad Sztyber	nvmf_create_transport $NVMF_TRANSPORT_OPTS
796060669eSKonrad Sztyber	nvmf_create_subsystem $nqn -a
806060669eSKonrad Sztyber	nvmf_subsystem_add_listener $nqn -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
816060669eSKonrad Sztyber	nvmf_subsystem_add_ns $nqn crypto1
826060669eSKonrad SztyberCONFIG
836060669eSKonrad Sztyber
846060669eSKonrad Sztyber# Remember initial stats
856060669eSKonrad Sztyberupdate_stats
866060669eSKonrad Sztyber
876060669eSKonrad Sztyber# Write a single 64K request and check the stats
886060669eSKonrad Sztyberdd if=/dev/urandom of="$input" bs=1K count=64
896060669eSKonrad Sztyberspdk_dd --if "$input" --ob Nvme0n1 --bs $((64 * 1024)) --count 1
90a52a8a01SKonrad Sztyber(($(get_stat sequence_executed) == stats["sequence_executed"] + 1))
91a52a8a01SKonrad Sztyber(($(get_stat executed encrypt) == stats["encrypt_executed"] + 2))
92a52a8a01SKonrad Sztyber(($(get_stat executed decrypt) == stats["decrypt_executed"]))
9397ce07c2SKonrad Sztyber# No copies should be done - the copy from the malloc should translate to changing encrypt's
9497ce07c2SKonrad Sztyber# destination buffer
95a52a8a01SKonrad Sztyber(($(get_stat executed copy) == stats["copy_executed"]))
966060669eSKonrad Sztyberupdate_stats
976060669eSKonrad Sztyber
986060669eSKonrad Sztyber# Now read that 64K, verify the stats and check that it matches what was written
996060669eSKonrad Sztyberspdk_dd --of "$output" --ib Nvme0n1 --bs $((64 * 1024)) --count 1
100a52a8a01SKonrad Sztyber(($(get_stat sequence_executed) == stats["sequence_executed"] + 1))
101a52a8a01SKonrad Sztyber(($(get_stat executed encrypt) == stats["encrypt_executed"]))
102a52a8a01SKonrad Sztyber(($(get_stat executed decrypt) == stats["decrypt_executed"] + 2))
103a52a8a01SKonrad Sztyber(($(get_stat executed copy) == stats["copy_executed"]))
1046060669eSKonrad Sztybercmp "$input" "$output"
1056060669eSKonrad Sztyberspdk_dd --if /dev/zero --ob Nvme0n1 --bs $((64 * 1024)) --count 1
1066060669eSKonrad Sztyberupdate_stats
1076060669eSKonrad Sztyber
1086060669eSKonrad Sztyber# Now do the same using 4K requests
1096060669eSKonrad Sztyberspdk_dd --if "$input" --ob Nvme0n1 --bs 4096 --count 16
110a52a8a01SKonrad Sztyber(($(get_stat sequence_executed) == stats["sequence_executed"] + 16))
111a52a8a01SKonrad Sztyber(($(get_stat executed encrypt) == stats["encrypt_executed"] + 32))
112a52a8a01SKonrad Sztyber(($(get_stat executed decrypt) == stats["decrypt_executed"]))
113a52a8a01SKonrad Sztyber(($(get_stat executed copy) == stats["copy_executed"]))
1146060669eSKonrad Sztyberupdate_stats
1156060669eSKonrad Sztyber
1166060669eSKonrad Sztyber# Check the reads
1176060669eSKonrad Sztyber: > "$output"
1186060669eSKonrad Sztyberspdk_dd --of "$output" --ib Nvme0n1 --bs 4096 --count 16
119a52a8a01SKonrad Sztyber(($(get_stat sequence_executed) == stats["sequence_executed"] + 16))
120a52a8a01SKonrad Sztyber(($(get_stat executed encrypt) == stats["encrypt_executed"]))
121a52a8a01SKonrad Sztyber(($(get_stat executed decrypt) == stats["decrypt_executed"] + 32))
122a52a8a01SKonrad Sztyber(($(get_stat executed copy) == stats["copy_executed"]))
1236060669eSKonrad Sztybercmp "$input" "$output"
1246060669eSKonrad Sztyber
1256060669eSKonrad Sztybertrap - SIGINT SIGTERM EXIT
1263824f6e3SKonrad Sztybertgtcleanup
1273824f6e3SKonrad Sztyber
1283824f6e3SKonrad Sztyber# Verify bdev crypto ENOMEM handling by setting low accel task count and sending IO with high qd
1293824f6e3SKonrad Sztybertrap 'bperfcleanup; exit 1' SIGINT SIGTERM EXIT
1303824f6e3SKonrad Sztyber
1313824f6e3SKonrad Sztyber"$rootdir/build/examples/bdevperf" -t 5 -w verify -o 4096 -q 256 --wait-for-rpc -z &
1323824f6e3SKonrad Sztyberbperfpid=$!
1333824f6e3SKonrad Sztyber
1343824f6e3SKonrad Sztyberwaitforlisten $bperfpid
1353824f6e3SKonrad Sztyberrpc_cmd <<- CONFIG
1363824f6e3SKonrad Sztyber	accel_set_options --task-count 16
1373824f6e3SKonrad Sztyber	framework_start_init
1383824f6e3SKonrad Sztyber	bdev_malloc_create 32 4096 -b malloc0
1393824f6e3SKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0
1403824f6e3SKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key1[0]}" -e "${key1[1]}" -n key1
1413824f6e3SKonrad Sztyber	bdev_crypto_create malloc0 crypto0 -n key0
1423824f6e3SKonrad Sztyber	bdev_crypto_create crypto0 crypto1 -n key1
1433824f6e3SKonrad SztyberCONFIG
1443824f6e3SKonrad Sztyber
1453824f6e3SKonrad Sztyber"$rootdir/examples/bdev/bdevperf/bdevperf.py" perform_tests
1464a4c905bSKonrad Sztyberkillprocess $bperfpid
1474a4c905bSKonrad Sztyber
1484a4c905bSKonrad Sztyber# Verify ENOMEM handling in the bdev layer by using the same accel configuration, but adding a
1494a4c905bSKonrad Sztyber# passthru bdev, which doesn't support memory domains/accel, to force bdev layer to append copies
1504a4c905bSKonrad Sztyber# and execute accel sequences
1514a4c905bSKonrad Sztyber"$rootdir/build/examples/bdevperf" -t 5 -w verify -o 4096 -q 256 --wait-for-rpc -z &
1524a4c905bSKonrad Sztyberbperfpid=$!
1534a4c905bSKonrad Sztyber
1544a4c905bSKonrad Sztyberwaitforlisten $bperfpid
1554a4c905bSKonrad Sztyberrpc_cmd <<- CONFIG
1564a4c905bSKonrad Sztyber	accel_set_options --task-count 16
1574a4c905bSKonrad Sztyber	framework_start_init
1584a4c905bSKonrad Sztyber	bdev_malloc_create 32 4096 -b malloc0
1594a4c905bSKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0
1604a4c905bSKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key1[0]}" -e "${key1[1]}" -n key1
1614a4c905bSKonrad Sztyber	bdev_passthru_create -p pt0 -b malloc0
1624a4c905bSKonrad Sztyber	bdev_crypto_create pt0 crypto0 -n key0
1634a4c905bSKonrad Sztyber	bdev_crypto_create crypto0 crypto1 -n key1
1644a4c905bSKonrad SztyberCONFIG
1654a4c905bSKonrad Sztyber
1664a4c905bSKonrad Sztyber"$rootdir/examples/bdev/bdevperf/bdevperf.py" perform_tests
1674a4c905bSKonrad Sztyberkillprocess $bperfpid
1683824f6e3SKonrad Sztyber
1693824f6e3SKonrad Sztybertrap - SIGINT SIGTERM EXIT
1703824f6e3SKonrad Sztyberkillprocess $bperfpid
1713824f6e3SKonrad Sztyberwait $bperfpid
1722ed026b1SKonrad Sztyber
1732ed026b1SKonrad Sztyber# Check integration with the TCP transport in the NVMe driver by running I/O with data
1742ed026b1SKonrad Sztyber# digest enabled
1752ed026b1SKonrad Sztybernvmftestinit
1762ed026b1SKonrad Sztybernvmfappstart -m 0x2
1772ed026b1SKonrad Sztyber
1782ed026b1SKonrad Sztyberrpc_cmd <<- CONFIG
1792ed026b1SKonrad Sztyber	bdev_malloc_create 32 4096 -b malloc0
1802ed026b1SKonrad Sztyber	nvmf_create_transport -t tcp
1812ed026b1SKonrad Sztyber	nvmf_create_subsystem $nqn -a
1822ed026b1SKonrad Sztyber	nvmf_subsystem_add_listener $nqn -t tcp -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT
1832ed026b1SKonrad Sztyber	nvmf_subsystem_add_ns $nqn malloc0
1842ed026b1SKonrad SztyberCONFIG
1852ed026b1SKonrad Sztyber
1862ed026b1SKonrad Sztybertrap 'bperfcleanup || :; nvmftestfini || :; exit 1' SIGINT SIGTERM EXIT
1872ed026b1SKonrad Sztyber"$rootdir/build/examples/bdevperf" -r "$bperfsock" -t 5 -w verify -o 4096 -q 256 \
1882ed026b1SKonrad Sztyber	--wait-for-rpc -z &
1892ed026b1SKonrad Sztyberbperfpid=$!
1902ed026b1SKonrad Sztyber
1912ed026b1SKonrad Sztyberwaitforlisten $bperfpid "$bperfsock"
1922ed026b1SKonrad Sztyberrpc_bperf <<- CONFIG
1932ed026b1SKonrad Sztyber	bdev_set_options --disable-auto-examine
194*6ecf0442SKonrad Sztyber	bdev_nvme_set_options --allow-accel-sequence
1952ed026b1SKonrad Sztyber	framework_start_init
1962ed026b1SKonrad Sztyber	bdev_nvme_attach_controller -t tcp -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n $nqn -b nvme0 --ddgst
1972ed026b1SKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0
1982ed026b1SKonrad Sztyber	bdev_crypto_create nvme0n1 crypto0 -n key0
1992ed026b1SKonrad SztyberCONFIG
2002ed026b1SKonrad Sztyber
2012ed026b1SKonrad Sztyber"$rootdir/examples/bdev/bdevperf/bdevperf.py" -s "$bperfsock" perform_tests
2022ed026b1SKonrad Sztyber
203ed87975aSKonrad Sztyber# Check the stats and verify that sequence is executed once for all operations (either encrypt+crc32
204ed87975aSKonrad Sztyber# or decrypt+crc32)
2052ed026b1SKonrad Sztybersequence=$(get_stat_bperf sequence_executed)
2062ed026b1SKonrad Sztyberencrypt=$(get_stat_bperf executed encrypt)
2072ed026b1SKonrad Sztyberdecrypt=$(get_stat_bperf executed decrypt)
2082ed026b1SKonrad Sztybercrc32c=$(get_stat_bperf executed crc32c)
2092ed026b1SKonrad Sztyber
2102ed026b1SKonrad Sztyber((sequence > 0))
211ed87975aSKonrad Sztyber((encrypt + decrypt == sequence))
2122ed026b1SKonrad Sztyber((encrypt + decrypt == crc32c))
2132ed026b1SKonrad Sztyber
2142ed026b1SKonrad Sztyberkillprocess $bperfpid
2152ed026b1SKonrad Sztyber
2162ed026b1SKonrad Sztyber# Check the same with a larger block size to verify the digest calculation without in-capsule data
2172ed026b1SKonrad Sztyber"$rootdir/build/examples/bdevperf" -r "$bperfsock" -t 5 -w verify -o $((64 * 1024)) -q 32 \
2182ed026b1SKonrad Sztyber	--wait-for-rpc -z &
2192ed026b1SKonrad Sztyberbperfpid=$!
2202ed026b1SKonrad Sztyber
2212ed026b1SKonrad Sztyberwaitforlisten $bperfpid "$bperfsock"
2222ed026b1SKonrad Sztyberrpc_bperf <<- CONFIG
2232ed026b1SKonrad Sztyber	bdev_set_options --disable-auto-examine
224*6ecf0442SKonrad Sztyber	bdev_nvme_set_options --allow-accel-sequence
2252ed026b1SKonrad Sztyber	framework_start_init
2262ed026b1SKonrad Sztyber	bdev_nvme_attach_controller -t tcp -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT -f ipv4 -n $nqn -b nvme0 --ddgst
2272ed026b1SKonrad Sztyber	accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0
2282ed026b1SKonrad Sztyber	bdev_crypto_create nvme0n1 crypto0 -n key0
2292ed026b1SKonrad SztyberCONFIG
2302ed026b1SKonrad Sztyber
2312ed026b1SKonrad Sztyber"$rootdir/examples/bdev/bdevperf/bdevperf.py" -s "$bperfsock" perform_tests
2322ed026b1SKonrad Sztyber
2332ed026b1SKonrad Sztybersequence=$(get_stat_bperf sequence_executed)
2342ed026b1SKonrad Sztyberencrypt=$(get_stat_bperf executed encrypt)
2352ed026b1SKonrad Sztyberdecrypt=$(get_stat_bperf executed decrypt)
2362ed026b1SKonrad Sztybercrc32c=$(get_stat_bperf executed crc32c)
2372ed026b1SKonrad Sztyber
2382ed026b1SKonrad Sztyber((sequence > 0))
239ed87975aSKonrad Sztyber((encrypt + decrypt == sequence))
2402ed026b1SKonrad Sztyber((encrypt + decrypt == crc32c))
2412ed026b1SKonrad Sztyber
2422ed026b1SKonrad Sztyberkillprocess $bperfpid
2432ed026b1SKonrad Sztybernvmftestfini
2442ed026b1SKonrad Sztyber
2452ed026b1SKonrad Sztybertrap - SIGINT SIGTERM EXIT
246