#!/bin/bash
#
#
# Program Usage
# main
if test @$1 = @-help -o @$1 = @-h -o @$1 = @-?; then
#echo "Usage: remove-LUN.sh [A] [C] [S] [L]"
echo "Usage: $0 [host] [channel] [id] [lun]"
echo "Explain:"
echo " host is the host bus adapter(HBA) number"
echo " channel is the channel ID on the HBA"
echo " id is the SCSI ID of the removed device"
echo " lun is the LUN of the removed device"
echo " e.g $0 1 0 2 2"
exit 0
fi

# Check options
if [ $# -ne 4 ]; then
echo "!! Wrong arguments,program terminated"
exit 1
fi

# Main
HOST=$1
CHANNEL=$2
ID=$3
LUN=$4

if test -e /sys/class/scsi_device/$HOST:$CHANNEL:$ID:$LUN/device/delete; then
echo 1 > /sys/class/scsi_device/$HOST:$CHANNEL:$ID:$LUN/device/delete
# Try reading, should fail if device is gone
echo "$CHANNEL $ID $LUN" > /sys/class/scsi_host/host$HOST/scan
else
echo "scsi remove-single-device $HOST $CHANNEL $ID $LUN" > /proc/scsi/scsi
fi
cat /proc/scsi/scsi
