1*44704f69SBart Van Assche#!/bin/bash 2*44704f69SBart Van Assche# scsi_mandat 3*44704f69SBart Van Assche# 4*44704f69SBart Van Assche# Script to test compliance with SCSI mandatory commands. 5*44704f69SBart Van Assche# The vintage is SPC-3 and SPC-4 (see www.t10.org). 6*44704f69SBart Van Assche# 7*44704f69SBart Van Assche# Coverage: 8*44704f69SBart Van Assche# Command Standard/Draft (is mandatory in) 9*44704f69SBart Van Assche# ------------------------------------------------------- 10*44704f69SBart Van Assche# INQUIRY (standard) SCSI-2, SPC, SPC-2, SPC-3, SPC-4 11*44704f69SBart Van Assche# INQUIRY (VPD pages 0, 0x83) SPC-2, SPC-3, SPC-4 12*44704f69SBart Van Assche# REPORT LUNS SPC-3, SPC-4 13*44704f69SBart Van Assche# TEST UNIT READY SCSI-2, SPC, SPC-2, SPC-3, SPC-4 14*44704f69SBart Van Assche# REQUEST SENSE SCSI-2, SBC, SBC-2,3, MMC-4,5, SSC-2,3 15*44704f69SBart Van Assche# SEND DIAGNOSTIC SBC, SBC-2,3, SSC-2,3 16*44704f69SBart Van Assche# 17*44704f69SBart Van Assche# This script uses utilities frim sg3_utils package (version 18*44704f69SBart Van Assche# 1.21 or later) 19*44704f69SBart Van Assche# 20*44704f69SBart Van Assche# Douglas Gilbert 20131016 21*44704f69SBart Van Assche 22*44704f69SBart Van Assche 23*44704f69SBart Van Asschelog=0 24*44704f69SBart Van Asschequiet=0 25*44704f69SBart Van Asscheverbose="" 26*44704f69SBart Van Assche 27*44704f69SBart Van Asschefile_err=0 28*44704f69SBart Van Asscheinv_opcode=0 29*44704f69SBart Van Asscheilleg_req=0 30*44704f69SBart Van Asschenot_ready=0 31*44704f69SBart Van Asschemedium=0 32*44704f69SBart Van Asscheother_err=0 33*44704f69SBart Van Asscherecovered=0 34*44704f69SBart Van Asschesanity=0 35*44704f69SBart Van Asschesyntax=0 36*44704f69SBart Van Asschetimeout=0 37*44704f69SBart Van Asscheunit_attention=0 38*44704f69SBart Van Asscheaborted_command=0 39*44704f69SBart Van Assche 40*44704f69SBart Van Assche## total_err=0 41*44704f69SBart Van Assche 42*44704f69SBart Van Asscheusage() 43*44704f69SBart Van Assche{ 44*44704f69SBart Van Assche echo "Usage: scsi_mandat [-h] [-L] [-q] [-v] <device>" 45*44704f69SBart Van Assche echo " where: -h, --help print usage message" 46*44704f69SBart Van Assche echo " -L, --log append stderr to 'scsi_mandat.err'" 47*44704f69SBart Van Assche echo " -q, --quiet suppress some output" 48*44704f69SBart Van Assche echo " -v, --verbose increase verbosity of output" 49*44704f69SBart Van Assche echo "" 50*44704f69SBart Van Assche echo "Check <device> for mandatory SCSI command support" 51*44704f69SBart Van Assche} 52*44704f69SBart Van Assche 53*44704f69SBart Van Assche 54*44704f69SBart Van Asscheopt="$1" 55*44704f69SBart Van Asschewhile test ! -z "$opt" -a -z "${opt##-*}"; do 56*44704f69SBart Van Assche opt=${opt#-} 57*44704f69SBart Van Assche case "$opt" in 58*44704f69SBart Van Assche h|-help) usage ; exit 0 ;; 59*44704f69SBart Van Assche L|-log) let log=$log+1 ;; 60*44704f69SBart Van Assche q|-quiet) let quiet=$quiet+1 ;; 61*44704f69SBart Van Assche v|-verbose) verbose="-v" ;; 62*44704f69SBart Van Assche vv) verbose="-vv" ;; 63*44704f69SBart Van Assche vvv) verbose="-vvv" ;; 64*44704f69SBart Van Assche *) echo "Unknown option: -$opt " ; exit 1 ;; 65*44704f69SBart Van Assche esac 66*44704f69SBart Van Assche shift 67*44704f69SBart Van Assche opt="$1" 68*44704f69SBart Van Asschedone 69*44704f69SBart Van Assche 70*44704f69SBart Van Asscheif [ $# -lt 1 ] 71*44704f69SBart Van Assche then 72*44704f69SBart Van Assche usage 73*44704f69SBart Van Assche exit 1 74*44704f69SBart Van Asschefi 75*44704f69SBart Van Assche 76*44704f69SBart Van Asschefor command in "sg_inq" "sg_luns" "sg_turs" "sg_requests" "sg_vpd" \ 77*44704f69SBart Van Assche "sg_vpd -i" "sg_senddiag -t" 78*44704f69SBart Van Asschedo 79*44704f69SBart Van Assche if [ $quiet -eq 0 ] 80*44704f69SBart Van Assche then echo "$command" $verbose "$1" 81*44704f69SBart Van Assche fi 82*44704f69SBart Van Assche 83*44704f69SBart Van Assche if [ $verbose ] 84*44704f69SBart Van Assche then 85*44704f69SBart Van Assche if [ $log -eq 0 ] 86*44704f69SBart Van Assche then 87*44704f69SBart Van Assche $command $verbose "$1" 88*44704f69SBart Van Assche else 89*44704f69SBart Van Assche $command $verbose "$1" >> scsi_mandat.err 2>> scsi_mandat.err 90*44704f69SBart Van Assche fi 91*44704f69SBart Van Assche else 92*44704f69SBart Van Assche if [ $log -eq 0 ] 93*44704f69SBart Van Assche then 94*44704f69SBart Van Assche $command "$1" > /dev/null 2>> /dev/null 95*44704f69SBart Van Assche else 96*44704f69SBart Van Assche $command "$1" > /dev/null 2>> scsi_mandat.err 97*44704f69SBart Van Assche fi 98*44704f69SBart Van Assche fi 99*44704f69SBart Van Assche res=$? 100*44704f69SBart Van Assche case "$res" in 101*44704f69SBart Van Assche 0) ;; 102*44704f69SBart Van Assche 1) echo " syntax error" ; let syntax=$syntax+1 ;; 103*44704f69SBart Van Assche 2) echo " not ready" ; let not_ready=$not_ready+1 ;; 104*44704f69SBart Van Assche 3) echo " medium error" ; let medium=$medium+1 ;; 105*44704f69SBart Van Assche 5) echo " illegal request, general" ; let illeg_req=$illeg_req+1 ;; 106*44704f69SBart Van Assche 6) echo " unit attention" ; let unit_attention=$unit_attention+1 ;; 107*44704f69SBart Van Assche 9) echo " illegal request, invalid opcode" ; let inv_opcode=$inv_opcode+1 ;; 108*44704f69SBart Van Assche 11) echo " aborted command" ; let aborted_command=$aborted_command+1 ;; 109*44704f69SBart Van Assche 15) echo " file error with $1 " ; let file_err=$file_err+1 ;; 110*44704f69SBart Van Assche 20) echo " no sense" ; let other_err=$other_err+1 ;; 111*44704f69SBart Van Assche 21) echo " recovered error" ; let recovered=$recovered+1 ;; 112*44704f69SBart Van Assche 33) echo " timeout" ; let timeout=$timeout+1 ;; 113*44704f69SBart Van Assche 97) echo " response fails sanity" ; let sanity=$sanity+1 ;; 114*44704f69SBart Van Assche 98) echo " other SCSI error" ; let other_err=$other_err+1 ;; 115*44704f69SBart Van Assche 99) echo " other error" ; let other_err=$other_err+1 ;; 116*44704f69SBart Van Assche *) echo " unknown exit status for sg_inq: $res" ; let other_err=$other_err+1 ;; 117*44704f69SBart Van Assche esac 118*44704f69SBart Van Asschedone 119*44704f69SBart Van Assche 120*44704f69SBart Van Asscheecho "" 121*44704f69SBart Van Asschelet total_bad_err=$file_err+$inv_opcode+$illeg_req+$medium+$aborted_command 122*44704f69SBart Van Asschelet total_bad_err+=$other_err+$recovered+$sanity+$syntax+$timeout 123*44704f69SBart Van Assche 124*44704f69SBart Van Asschelet total_allow_err=$not_ready+$unit_attention 125*44704f69SBart Van Assche 126*44704f69SBart Van Assche echo "total number of bad errors: $total_bad_err " 127*44704f69SBart Van Assche 128*44704f69SBart Van Asscheif [ $total_allow_err -gt 0 ] 129*44704f69SBart Van Assche then 130*44704f69SBart Van Assche echo "total number of allowable errors: $total_allow_err " 131*44704f69SBart Van Asschefi 132*44704f69SBart Van Assche 133*44704f69SBart Van Asscheexit $total_bad_err 134