I met this problem several years before, the sympton is that when a host reboot, all tapes in drivers are rewinded, It's pretty dangers in a SAN cluster environment. A host doing tape writing, while another host had reboot.

This is for the case that use Linux native st driver.

I did not figure it out by myself, I found the idea by googling, but I can't remember the origional blog/website. Anyway, I had changes anyway in past years.

Here is it.


The idea is that remove st module from kernel, so it won't even reconganize tape deivices, then load st module after boot.

# cat /etc/init.d/st_module
#!/bin/sh
#
# chkconfig: 2345 90 80
#
# description: This is a workaround to prevent tape rewinds\
# by moving tape discovery later in the boot process.
#
BADST="/lib/modules/`uname -r`/kernel/drivers/scsi/st.ko"
ST="/lib/modules/`uname -r`/kernel/drivers/scsi/ST.KO"
INSMOD="/sbin/insmod"
RMMOD="/sbin/rmmod"
UDEVSTART="/sbin/start_udev"
STINIT="/sbin/stinit"
LOG="/var/log/st_module.log"
start()
{
if [ -f $BADST ]
then
    echo "Ouch ! The kernel module ST is
    potentially loadable at boot time !"
    echo "I decide to move it from $BADST "
    echo "to $ST . Now future reboots are safe "
    mv $BADST $ST
fi
if [ -f $INSMOD ]
then
    if [ -f $ST ]
    then
        if [ "`lsmod |grep "^st "| wc -l`" -gt 0 ]; then
            echo "Module already loaded"
        else
            echo "Inserting st module "
            $INSMOD $ST
                        sleep 15
                        echo "st_module start at"`date` >>$LOG
                        echo "devices: " >>$LOG
                        ls -l /dev/fcnst* >>$LOG
            $UDEVSTART
                        sleep 10
                        echo "stinit... " >>$LOG
            $STINIT >>$LOG
        fi
    else
        echo "UNABLE TO FIND $ST"
    fi
else
    echo "UNABLE TO FIND $INSMOD"
fi
}
stop()
{
if [ -f $BADST ]
then
    echo "Ouch ! The kernel module ST is
    potentially loadable at boot time !"
    echo "I decide to move it from $BADST "
    echo "to $ST . Now next reboot is safe "
    mv $BADST $ST
fi

    echo "Removing st module at "`date` >>$LOG
if [ -f $RMMOD ]
then
    echo "Removing st module "
    $RMMOD st
else
    echo "UNABLE TO FIND $RMMOD"
fi
}

status()
{
if [ "`lsmod |grep "^st "| wc -l`" -gt 0 ];
then
    echo "Module st is currently loaded";
else
    echo "Module st is NOT currently loaded";
fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac