From dcf927aba2f96b45471c188d5eee921857c18f76 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 3 Oct 2023 14:46:37 -0700 Subject: [PATCH] scsi/008: Test SCSI disk data lifetime support SCSI disk data lifetime support is available since kernel v6.9-rc1. See also https://lore.kernel.org/linux-scsi/3b789eacddd6265921be9da6e15257908f29b186.camel@HansenPartnership.com/. Signed-off-by: Bart Van Assche --- common/scsi_debug | 14 ++++++++ tests/scsi/008 | 82 ++++++++++++++++++++++++++++++++++++++++++++++ tests/scsi/008.out | 26 +++++++++++++++ 3 files changed, 122 insertions(+) create mode 100755 tests/scsi/008 create mode 100644 tests/scsi/008.out diff --git a/common/scsi_debug b/common/scsi_debug index 4e64b931..1027b468 100644 --- a/common/scsi_debug +++ b/common/scsi_debug @@ -25,6 +25,20 @@ _scsi_debug_key_path() { echo "$path" } +_have_scsi_debug_group_number_stats() { + local ret=0 + + modprobe -qr scsi_debug >&/dev/null + if ! modprobe -q scsi_debug delay=0 >&/dev/null || + ! [[ -e ${SD_PSEUDO_PATH}/group_number_stats ]] + then + SKIP_REASONS+=("scsi_debug does not support group number statistics") + ret=1 + fi + modprobe -qr scsi_debug >&/dev/null + return ${ret} +} + declare -a SCSI_DEBUG_HOSTS declare -a SCSI_DEBUG_TARGETS declare -a SCSI_DEBUG_DEVICES diff --git a/tests/scsi/008 b/tests/scsi/008 new file mode 100755 index 00000000..3c4a2766 --- /dev/null +++ b/tests/scsi/008 @@ -0,0 +1,82 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2024 Google LLC + +. tests/scsi/rc +. common/null_blk +. common/scsi_debug + +DESCRIPTION="test block data lifetime support" +QUICK=1 + +requires() { + _have_fio + _have_scsi_debug_group_number_stats +} + +submit_io() { + local stats_attr=/sys/bus/pseudo/drivers/scsi_debug/group_number_stats + echo "$1 ($3)" + echo "$*" >>"${FULL}" + local direct_io=$2 + echo 0 > "${stats_attr}" && + local fio_args wh && + for wh in none short medium long extreme; do + if [ "${direct_io}" = 0 ]; then + sync + echo 1 > /proc/sys/vm/drop_caches + fi + fio_args=( + --bs=4K + --buffer_pattern='"'"$wh"'"' + --direct="${direct_io}" + --disable_clat=1 + --disable_slat=1 + --end_fsync=$((1 - direct_io)) + --filename="${dev}" + --group_reporting=1 + --gtod_reduce=1 + --ioengine="$3" + --ioscheduler=none + --name=whint_"$wh" + --norandommap + --rw=randwrite + --size=4M + --thread=1 + --write_hint="$wh" + ) + echo "fio ${fio_args[*]}" >>"${FULL}" 2>&1 + fio "${fio_args[@]}" >>"${FULL}" 2>&1 || return $? + done && + grep -v ' 0$' "${stats_attr}" >> "${FULL}" + while read -r group count; do + if [ "$count" -gt 0 ]; then echo "$group"; fi + done < "${stats_attr}" +} + +test() { + echo "Running ${TEST_NAME}" + + local scsi_debug_params=( + delay=0 + dev_size_mb=1024 + sector_size=4096 + ) + _configure_scsi_debug "${scsi_debug_params[@]}" && + local dev="/dev/${SCSI_DEBUG_DEVICES[0]}" fail && + ls -ldi "${dev}" >>"${FULL}" && + submit_io "Direct I/O" 1 pvsync && + submit_io "Direct I/O" 1 libaio && + submit_io "Direct I/O" 1 io_uring && + submit_io "Buffered I/O" 0 pvsync || + fail=true + + _exit_scsi_debug + + if [ -z "$fail" ]; then + echo "Test complete" + else + echo "Test failed" + return 1 + fi +} diff --git a/tests/scsi/008.out b/tests/scsi/008.out new file mode 100644 index 00000000..25788fd1 --- /dev/null +++ b/tests/scsi/008.out @@ -0,0 +1,26 @@ +Running scsi/008 +Direct I/O (pvsync) +1 +2 +3 +4 +5 +Direct I/O (libaio) +1 +2 +3 +4 +5 +Direct I/O (io_uring) +1 +2 +3 +4 +5 +Buffered I/O (pvsync) +1 +2 +3 +4 +5 +Test complete