#!/bin/sh
#    cfgdisk-lsi.sh
#
# Configure the ESRT2 RAID disks for disk write cache on/off
# Note that the megaraid_sas kernel module must first be loaded
#
megadir=.
logfile=/cfgdiskl.log
wce=0
# ADDLOG=addLogRecord
ADDLOG=echo

date >$logfile
lsmod |grep megasr >>$logfile
if [ $? -ne 0 ]
then
   echo "Error, first do: modprobe megaraid_sas"
   exit 1
fi
 
# save the disk parameters
echo "$megadir/CmdTool2 -LDGetProp -DskCache -LALL -aALL"  >>$logfile
$megadir/CmdTool2 -LDGetProp -DskCache -LALL -aALL  >>$logfile

# turn off/on disk write cache
if [ $wce -eq 0 ]
then
     echo "$megadir/CmdTool2 -LDSetProp WT -Lall -aALL" >>$logfile
     $megadir/CmdTool2 -LDSetProp WT -Lall -aALL  >>$logfile
     ret=$?
else
     echo "$megadir/CmdTool2 -LDSetProp WB -Lall -aALL" >>$logfile
     $megadir/CmdTool2 -LDSetProp WB -Lall -aALL  >>$logfile
     ret=$?
fi

if [ $ret -eq 0 ]
then
     $ADDLOG CFGDISK INFO "Success: CmdTool2 WCE=${wce} "
else
     $ADDLOG CFGDISK ERROR "Error $ret: CmdTool2 WCE=${wce} "
fi

exit $ret
