1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2023 Intel Corporation 4# All rights reserved. 5# 6 7testdir=$(readlink -f $(dirname $0)) 8rootdir=$(readlink -f $testdir/../..) 9 10# Use TCP as the default nvmf transport 11TEST_TRANSPORT=${TEST_TRANSPORT:=tcp} 12 13source "$rootdir/test/common/autotest_common.sh" 14source "$rootdir/test/nvmf/common.sh" 15 16nqn=nqn.2016-06.io.spdk:cnode0 17key0=(00112233445566778899001122334455 11223344556677889900112233445500) 18key1=(22334455667788990011223344550011 33445566778899001122334455001122) 19declare -A stats 20 21spdk_dd() { 22 local config 23 24 # Disable auto-examine to avoid seeing the examine callbacks' reads in accel stats 25 config=$("$rootdir/scripts/gen_nvme.sh" --mode=remote --json-with-subsystems \ 26 --trid="$TEST_TRANSPORT:$NVMF_FIRST_TARGET_IP:$NVMF_PORT:$nqn" \ 27 | jq '.subsystems[0].config[.subsystems[0].config | length] |= 28 {"method": "bdev_set_options", "params": {"bdev_auto_examine": false}}') 29 30 "$rootdir/build/bin/spdk_dd" -c <(echo "$config") "$@" 31} 32 33get_stat() { 34 local event opcode 35 36 event="$1" opcode="$2" 37 if [[ -z "$opcode" ]]; then 38 rpc_cmd accel_get_stats | jq -r ".$event" 39 else 40 rpc_cmd accel_get_stats \ 41 | jq -r ".operations[] | select(.opcode == \"$opcode\").$event" 42 fi 43} 44 45update_stats() { 46 stats[sequence_executed]=$(get_stat sequence_executed) 47 stats[encrypt_executed]=$(get_stat executed encrypt) 48 stats[decrypt_executed]=$(get_stat executed decrypt) 49 stats[copy_executed]=$(get_stat executed copy) 50} 51 52cleanup() { 53 [[ -v input ]] && rm -f "$input" || : 54 [[ -v output ]] && rm -f "$output" || : 55 nvmftestfini 56} 57 58nvmftestinit 59nvmfappstart -m 0x2 60 61input=$(mktemp) output=$(mktemp) 62trap 'cleanup; exit 1' SIGINT SIGTERM EXIT 63 64rpc_cmd <<- CONFIG 65 bdev_malloc_create 32 4096 -b malloc0 66 accel_crypto_key_create -c AES_XTS -k "${key0[0]}" -e "${key0[1]}" -n key0 67 accel_crypto_key_create -c AES_XTS -k "${key1[0]}" -e "${key1[1]}" -n key1 68 bdev_crypto_create malloc0 crypto0 -n key0 69 bdev_crypto_create crypto0 crypto1 -n key1 70 nvmf_create_transport $NVMF_TRANSPORT_OPTS 71 nvmf_create_subsystem $nqn -a 72 nvmf_subsystem_add_listener $nqn -t $TEST_TRANSPORT -a $NVMF_FIRST_TARGET_IP -s $NVMF_PORT 73 nvmf_subsystem_add_ns $nqn crypto1 74CONFIG 75 76# Remember initial stats 77update_stats 78 79# Write a single 64K request and check the stats 80dd if=/dev/urandom of="$input" bs=1K count=64 81spdk_dd --if "$input" --ob Nvme0n1 --bs $((64 * 1024)) --count 1 82(($(get_stat sequence_executed) == stats[sequence_executed] + 1)) 83(($(get_stat executed encrypt) == stats[encrypt_executed] + 2)) 84(($(get_stat executed decrypt) == stats[decrypt_executed])) 85# No copies should be done - the copy from the malloc should translate to changing encrypt's 86# destination buffer 87(($(get_stat executed copy) == stats[copy_executed])) 88update_stats 89 90# Now read that 64K, verify the stats and check that it matches what was written 91spdk_dd --of "$output" --ib Nvme0n1 --bs $((64 * 1024)) --count 1 92(($(get_stat sequence_executed) == stats[sequence_executed] + 1)) 93(($(get_stat executed encrypt) == stats[encrypt_executed])) 94(($(get_stat executed decrypt) == stats[decrypt_executed] + 2)) 95(($(get_stat executed copy) == stats[copy_executed])) 96cmp "$input" "$output" 97spdk_dd --if /dev/zero --ob Nvme0n1 --bs $((64 * 1024)) --count 1 98update_stats 99 100# Now do the same using 4K requests 101spdk_dd --if "$input" --ob Nvme0n1 --bs 4096 --count 16 102(($(get_stat sequence_executed) == stats[sequence_executed] + 16)) 103(($(get_stat executed encrypt) == stats[encrypt_executed] + 32)) 104(($(get_stat executed decrypt) == stats[decrypt_executed])) 105(($(get_stat executed copy) == stats[copy_executed])) 106update_stats 107 108# Check the reads 109: > "$output" 110spdk_dd --of "$output" --ib Nvme0n1 --bs 4096 --count 16 111(($(get_stat sequence_executed) == stats[sequence_executed] + 16)) 112(($(get_stat executed encrypt) == stats[encrypt_executed])) 113(($(get_stat executed decrypt) == stats[decrypt_executed] + 32)) 114(($(get_stat executed copy) == stats[copy_executed])) 115cmp "$input" "$output" 116 117trap - SIGINT SIGTERM EXIT 118cleanup 119