#!/bin/sh scsi_debug=/mnt/mainline/drivers/scsi/scsi_debug.ko function clear_error() { error=$1 tmpfile=$$_clear cat $error | grep -v Type | awk '{print $1,$3}' > $tmpfile while read -r line; do echo "- $line" > $error; done < $tmpfile rm -rf $tmpfile echo 0 > /sys/kernel/debug/scsi_debug/target$target_id/fail_reset } function lun_test_sense1() { echo "LUN reset success, TUR success" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function lun_test_sense2() { echo "LUN reset success, TUR failed" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject timeout command for TUR command echo "0 -1 0x0 " > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function lun_test_sense3() { echo "LUN reset failed, fallback to target reset success" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject lunreset failed echo "4 -1 0xff" > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function target_test_sense1() { echo "LUN reset success, TUR success" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function target_test_sense2() { echo "LUN reset success, TUR failed, target reset success, TUR success" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject timeout command for TUR command echo "0 -1 0x0 " > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function target_test_sense3() { echo "LUN reset failed, target reset success, TUR success" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject lunreset failed echo "4 -1 0xff" > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function target_test_sense4() { echo "LUN reset failed, target reset success TUR failed" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject lunreset failed echo "4 -1 0xff" > ${error} # inject timeout command for TUR command echo "0 -1 0x0 " > ${error} dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } function target_test_sense5() { echo "LUN reset failed, target reset failed, fallback to host recovery" # inject timeout command for write command echo "0 -10 0x2a " > ${error} # inject abort command for write command echo "3 -1 0x2a " > ${error} # inject lunreset failed echo "4 -1 0xff" > ${error} # inject target reset failed echo 1 > /sys/kernel/debug/scsi_debug/target$target_id/fail_reset dd if=/dev/zero of=/dev/$disk bs=1K count=10 oflag=direct echo $(cat /sys/block/$disk/device/state) clear_error $error echo running > /sys/block/$disk/device/state } scsi_logging_level -s --error 4 > /dev/null 2>&1 insmod $scsi_debug lun_eh=Y target_eh=N str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $1}') scsi_id=${str#*\[} scsi_id=${scsi_id%\]*} error=/sys/kernel/debug/scsi_debug/$scsi_id/error str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $6}') disk=$(basename $str) target_id=${scsi_id%\:*} echo none > /sys/block/$disk/queue/scheduler echo 1 > /sys/block/$disk/device/timeout echo 1 > /sys/block/$disk/device/eh_timeout for((loop=1;loop<=3;loop++)) do time=$(date "+%Y-%m-%d-%H-%M-%S") since=$(date "+%Y-%m-%d %H:%M:%S") lun_test_sense$loop sleep 3 until=$(date "+%Y-%m-%d %H:%M:%S") mkdir logs/lun_sense$loop journalctl --since="$since" --until="$until" > logs/lun_sense$loop/$time.log done rmmod scsi_debug insmod $scsi_debug lun_eh=N target_eh=Y str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $1}') scsi_id=${str#*\[} scsi_id=${scsi_id%\]*} error=/sys/kernel/debug/scsi_debug/$scsi_id/error str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $6}') disk=$(basename $str) echo none > /sys/block/$disk/queue/scheduler echo 1 > /sys/block/$disk/device/timeout echo 1 > /sys/block/$disk/device/eh_timeout for((loop=1;loop<=5;loop++)) do time=$(date "+%Y-%m-%d-%H-%M-%S") since=$(date "+%Y-%m-%d %H:%M:%S") target_test_sense$loop sleep 3 until=$(date "+%Y-%m-%d %H:%M:%S") mkdir logs/target_sense$loop journalctl --since="$since" --until="$until" > logs/target_sense$loop/$time.log done rmmod scsi_debug insmod $scsi_debug lun_eh=Y target_eh=Y str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $1}') scsi_id=${str#*\[} scsi_id=${scsi_id%\]*} error=/sys/kernel/debug/scsi_debug/$scsi_id/error str=$(lsscsi | grep scsi_debug | head -n 1 | awk '{print $6}') disk=$(basename $str) echo none > /sys/block/$disk/queue/scheduler echo 1 > /sys/block/$disk/device/timeout echo 1 > /sys/block/$disk/device/eh_timeout for((loop=1;loop<=5;loop++)) do time=$(date "+%Y-%m-%d-%H-%M-%S") since=$(date "+%Y-%m-%d %H:%M:%S") target_test_sense$loop sleep 3 until=$(date "+%Y-%m-%d %H:%M:%S") mkdir logs/lun_target_sense$loop journalctl --since="$since" --until="$until" > logs/lun_target_sense$loop/$time.log done rmmod scsi_debug