> > I put some time into this and I thought I would share.
>
> Thanks, I compiled chg-scsi on my Solaris 8 box with a L280, but had
> some kind of timing problem. I could issue a command, it would fail
> because the changer wouldn't return any info, then turn around and
> issue the same command and have it work. I'll try your patches to
> chg-mtx-zd.
> -----
> Bradley S. Huffman (405) 744-2918
> Online Coordinator
> 208 Life Sciences East
> College of Arts and Sciences
> Oklahoma State University
> Stillwater, Oklahoma 74078-1053
----------
Before anyone uses the patch I'll do this the way it should have been done
the first time. I have applied my changes to chg-zd-mtx.sh.in, next I have
built in semaphores into the code around dd's and load/unloads. Next I've
changed grep to grep -s to prevent error messages from generating false "no
tape on line" messages. I have also added some comments and a bit in the
"next" "prev"... slot selector area where two runs can confiuse eachother
and non existant slots are loaded(0 or 7). I also added a second rewind
after the DD command because it appears that without it you can sometimes
miss labels. Here's the patch to chg-zd-mtx.sh.in, I'd love comments and
It looks like I may look into fixing up the amtape and amcheck routines in
order to allow for a more robust behavior(if no one minds that is). Also,
My next order of bussiness is to get amanda working with a bigger changer(
an L1000). I hope the current script will work but I'll try to get it as
versitile as possible.
*** chg-zd-mtx.sh.in.ORIG Wed Jan 10 09:25:54 2001
--- chg-zd-mtx.sh.in Fri Jan 12 19:13:29 2001
***************
*** 7,12 ****
--- 7,15 ----
#
# Contributed by Eric DOUTRELEAU <[EMAIL PROTECTED]>
# This is supposed to work with Zubkoff/Dandelion version of mtx
+ #
+ # Modified by Robert Weber <[EMAIL PROTECTED]> to include the
+ # correct blocksize and added 3 lock files to prevent conflicts
# try to hit all the possibilities here
prefix=@prefix@
***************
*** 19,26 ****
if [ -d "@AMANDA_DBGDIR@" ]; then
DBGFILE=@AMANDA_DBGDIR@/changer.debug
else
! DBGFILE=/dev/null
fi
USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
--- 22,37 ----
if [ -d "@AMANDA_DBGDIR@" ]; then
DBGFILE=@AMANDA_DBGDIR@/changer.debug
+ DDLOCK=@AMANDA_DBGDIR@/dd.lock
+ LOADLOCK=@AMANDA_DBGDIR@/changer.load
+ UNLOADLOCK=@AMANDA_DBGDIR@/changer.unload
else
! mkdir @AMANDA_DBGDIR@
! chmod 700 @AMANDA_DBGDIR@
! DBGFILE=@AMANDA_DBGDIR@/changer.debug
! DDLOCK=@AMANDA_DBGDIR@/dd.lock
! LOADLOCK=@AMANDA_DBGDIR@/changer.load
! UNLOADLOCK=@AMANDA_DBGDIR@/changer.unload
fi
USE_VERSION_SUFFIXES="@USE_VERSION_SUFFIXES@"
***************
*** 40,47 ****
fake=0
MT=@MT@
MTF=@MT_FILE_FLAG@
! MTX=@MTX@
! DD=@DD@
firstslot=1
lastslot=6
# counted from 1 !!!
--- 51,58 ----
fake=0
MT=@MT@
MTF=@MT_FILE_FLAG@
! MTX=@MTX@" -f $TAPE"
! DD=@DD@" bs=32k"
firstslot=1
lastslot=6
# counted from 1 !!!
***************
*** 61,67 ****
readstatus() {
used=`$MTX status |
! sed -n 's/Data Transfer Element:.Empty/-1/p;s/Data Transfer Element:.Full
(Storage Element \(.\) Loaded)/\1/p'`
if [ "$used" -eq -1 ]; then
used=`cat $slotfile`
--- 72,81 ----
readstatus() {
used=`$MTX status |
! echo $MTX" status" >>$DBGFILE
! used=`$MTX status | grep -s "Data Transfer Element" | awk '{print $7}'
! sleep 1
! # sed -n 's/Data Transfer Element:.Empty/-1/p;s/Data Transfer Element:.Full
(Storage Element \(.\) Loaded)/\1/p'`
if [ "$used" -eq -1 ]; then
used=`cat $slotfile`
***************
*** 73,79 ****
--- 87,102 ----
eject() {
readstatus
if [ $used -gt 0 ];then
+ while [ -f $UNLOADLOCK ] ; do
+ echo "$UNLOADLOCK exists, sleeping for an other (un)load to finish" >> $DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $UNLOADLOCK # don't unload twice
+ echo $MTX" unload "$used >> $DBGFILE
$MTX unload $used 2>/dev/null
+ sleep 45
+ rm -f $LOADLOCK # now you may load a tape
echo 0 $tape
exit 0
else
***************
*** 85,93 ****
--- 108,135 ----
reset() {
readstatus
if [ $used -gt 0 ];then
+ while [ -f $UNLOADLOCK ] ; do
+ echo "$UNLOADLOCK exists, sleeping for an other (un)load to finish" >> $DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $UNLOADLOCK # don't unload twice
+ echo $MTX" unload "$used >>$DBGFILE
$MTX unload $used 2>/dev/null
+ sleep 45
+ rm -f $LOADLOCK # now you may load a tape
fi
+ echo $MTX" load 1 ">> $DBGFILE
+ while [ -f $LOADLOCK ] ; do
+ echo "$LOADLOCK exists, sleeping for an other (un)load to finish" >> $DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $LOADLOCK # don't load twice
+ echo "$MTX load 1" >>$DBGFILE
res=`$MTX load 1 2>&1`
+ sleep 45
+ rm -f $UNLOADLOCK # now you may unload a tape
if [ $? -eq 0 ];then
echo "1 $tape"
exit 0
***************
*** 105,112 ****
--- 147,163 ----
case $whichslot in
current)
if [ $used -lt 0 ];then
+ while [ -f $LOADLOCK ] ; do
+ echo "$LOADLOCK exists, sleeping for an other (un)load to finish"
+>> $DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $LOADLOCK # don't load twice
+ echo $MTX" load 1">> $DBGFILE
$MTX load 1 2>/dev/null
echo "1 $tape"
+ sleep 45
+ rm -f $UNLOADLOCK # you may unload
exit 0
else
echo "$used $tape"
***************
*** 116,137 ****
--- 167,200 ----
next|advance)
load=`expr $used + 1`
[ $load -gt $lastslot ] && load=$firstslot
+ echo "next|advance) load -> $load" >>$DBGFILE
+ echo "$load" > $slotfile
;;
prev)
load=`expr $used - 1`
[ $load -lt $firstslot ] && load=$lastslot
+ echo "prev) load -> $load" >> $DBGFILE
+ echo "$load" > $slotfile
;;
first)
load=$firstslot
+ echo "first) load -> $load" >> $DBGFILE
+ echo "$load" > $slotfile
;;
last)
load=$lastslot
+ echo "last) load -> $load" >> $DBGFILE
+ echo "$load" > $slotfile
;;
[$firstslot-$lastslot])
load=$1
+ echo "$firstslot-$lastslot) load -> $load" >> $DBGFILE
+ echo "$load" > $slotfile
;;
clean)
load=$cleanslot
+ echo "clean) load -> $load" >> $DBGFILE
+ echo "$load" > $slotfile
;;
*)
echo "0 illegal request"
***************
*** 163,169 ****
--- 226,241 ----
if [ $fake -eq 0 ];then
echo " -> unload $used" >> $DBGFILE
+ while [ -f $UNLOADLOCK ] ; do
+ echo "$UNLOADLOCK exists, sleeping for an other (un)load to finish" >>
+$DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $UNLOADLOCK # don't unload twice
+ echo $MTX" unload "$used >> $DBGFILE
res=`$MTX unload $used 2>&1`
+ sleep 45
+ rm -f $LOADLOCK # now you can load a new one
status=$?
echo " -> status $status" >> $DBGFILE
echo " -> res $res" >> $DBGFILE
***************
*** 177,195 ****
exit 0
fi
echo " -> load $load" >> $DBGFILE
res=`$MTX load $load 2>&1`
status=$?
echo " -> status $status" >> $DBGFILE
echo " -> res $res" >> $DBGFILE
if [ $status -eq 0 ];then
echo " -> rew $load" >> $DBGFILE
$MT $MTF $tape rewind
$DD if=$tape count=1 >> $DBGFILE 2>&1
echo "$load $tape"
echo "$load" > $slotfile
exit 0
else
! res2=`echo $res | grep "Storage Element . is Empty"`
if [ -z $res2 ]; then
echo "$load $res"
exit 2
--- 249,289 ----
exit 0
fi
echo " -> load $load" >> $DBGFILE
+ while [ -f $LOADLOCK ] ; do
+ echo "$LOADLOCK exists, sleeping for an other (un)load to finish" >> $DBGFILE
+ sleep 10
+ readstatus
+ done
+ touch $LOADLOCK # don't load twice
+ echo $MTX" load "$load >>$DBGFILE
res=`$MTX load $load 2>&1`
+ sleep 46
+ rm -f $UNLOADLOCK # you can unload now
status=$?
echo " -> status $status" >> $DBGFILE
echo " -> res $res" >> $DBGFILE
if [ $status -eq 0 ];then
echo " -> rew $load" >> $DBGFILE
+ echo $MT" "$MTF" "$tape" rewind" >> $DBGFILE
$MT $MTF $tape rewind
+ sleep 5
+ while [ -f $DDLOCK ] ; do
+ echo "$DDLOCK exists, sleeping while another $DD is running" >> $DBGFILE
+ sleep 10
+ done
+ echo $DD" if="$tape" count=1 ">> $DBGFILE
+ touch $DDLOCK
$DD if=$tape count=1 >> $DBGFILE 2>&1
+ rm -f $DDLOCK
+ sleep 10
+ echo $MT" "$MTF" "$tape" rewind" >> $DBGFILE
+ $MT $MTF $tape rewind
+ sleep 5
echo "$load $tape"
echo "$load" > $slotfile
exit 0
else
! res2=`echo $res | grep -s "Storage Element . is Empty"`
if [ -z $res2 ]; then
echo "$load $res"
exit 2