Bacula-users

Re: [Bacula-users] [Bacula-devel] bacula (un)mount request

2011-02-10 12:55:16
Subject: Re: [Bacula-users] [Bacula-devel] bacula (un)mount request
From: Alan Brown <ajb2 AT mssl.ucl.ac DOT uk>
To: bacula-devel AT lists.sourceforge DOT net, "bacula-users AT lists.sourceforge DOT net" <bacula-users AT lists.sourceforge DOT net>
Date: Thu, 10 Feb 2011 17:52:35 +0000
Alan Brown wrote:

> Now that I've got a better understanding of the problem, I see two 
> options for fabric connected tape drives (usually inside a library)
> 
> 1: Send unlock commands to all instances of the tape drive - this 
> requires that all instances are known to bacula or the scripts it calls.
> 

Here's my "scripted in an hour" solution.

It's non-portable (RHEL 5.6) AND assumes:

  1: tape drive entries in bacula-sd.conf are symlinks to 
/dev/tape/by-id/ entries.

  2: There are only 2 connections from the SD host to the fabric.

  3: /etc/udev/50-udev-rules has been modified as below (submitted to 
redhat. It fixes some typos in RH's supplied file and adds -sg devices)

I'm sure others on these lists can do much better (hint!)...

===================
Firstly: mtx-changer

# diff -C10 -F3 -r mtx-changer mtx-changer-MSSL
*** mtx-changer.ORIG    2010-09-15 13:27:23.000000000 +0100
--- mtx-changer-MSSL    2011-02-10 17:32:16.000000000 +0000
***************   while [ $i -le 300 ]; do  # Wait max 3
*** 147,166 ****
--- 147,170 ----
   slot=$3
   device=$4
   drive=$5

   debug "Parms: $ctl $cmd $slot $device $drive"

   case $cmd in
      unload)
         debug "Doing mtx -f $ctl unload $slot $drive"

+ # AJB2 20110210 - unlock BOTH /dev/nst instances
+       /usr/local/bin/unlocktapedrive.sh $device
+ # End of addition.
+
         if test ${offline} -eq 1 ; then
         mt -f $device offline
         fi
         if test ${offline_sleep} -ne 0 ; then
         sleep ${offline_sleep}
         fi
         ${MTX} -f $ctl unload $slot $drive
         ;;

      load)

==========================

Secondly: /usr/local/bin/unlocktapedrive.sh

#!/bin/bash

# on a Fibrechannel host with 2 connections to the fabric,
# a tape drive will show up twice.
#
# It's possible for udev to swap /dev/tape/by-id around,
# which is fine for standard operations, BUT:
#
# Therefore a drive might be locked by one initiator
# and unlocked from the other.
#
# That doesn't work.
#
# Tape drive door locks are set per-initiator and ORed.
#
# locks set by one initiator have to be released by the same
# initiator AND multiple locks can be set (one per initiator)
#
# This script gets BOTH /dev/nst devices for each
# /etc/bacula/DEVICES/{drive} (symlinks to /dev/tape/by-id/)
# and sends unlocks to them, to be on the safe side.
#
# input is assumed to be /etc/bacula/DEVICES/{drive}

if ! test -h $1
         then
         echo Argument: /dev/bacula/DEVICES/{drive}
         exit 1
fi

# GET THE /dev/tape/by-id for this device
export INDIRECT=`/bin/ls -l $1 | /bin/cut -f2 -d\>`

# udev sometimes loses drives, or other weirdness might hav happened.
if ! test -h $INDIRECT
         then
         echo I've lost that drive!
         exit 1
fi

# get the /dev/nst being used.
export DEVICE=`/bin/ls -l $INDIRECT | /bin/cut -f2 -d\>  | /bin/cut -f3 -d/`

# get the device's /dev/tape/by-path entry
export PATH=`/bin/ls -l /dev/tape/by-path | /bin/grep $DEVICE$  | 
/bin/cut -f4 -d-`

# get the OTHER device
export DEVICEGHOST=`/bin/ls -l /dev/tape/by-path/*$PATH-nst | /bin/grep 
-v $DEVICE$ | /bin/cut -f2 -d\> | /bin/cut -f3 -d/`

#echo $1 $INDIRECT $DEVICE $PATH $DEVICEGHOST

#echo $DEVICE $DEVICEGHOST

/bin/mt -f /dev/$DEVICE unlock
/bin/mt -f /dev/$DEVICEGHOST unlock

exit 0
# Spaghetti scripts rule OK
===========================

Thirdly: My modifications to /etc/udev/rules.d/50.udev-rules

# diff -F5 -u /etc/udev/OLDRULES/50-udev.rules.EL-5.6-ORIG-20110126 
/etc/udev/rules.d/50-udev.rules
--- /etc/udev/OLDRULES/50-udev.rules.EL-5.6-ORIG-20110126 
2011-01-26 15:57:48.000000000 +0000
+++ /etc/udev/rules.d/50-udev.rules     2011-02-10 17:06:33.000000000 +0000
@@ -255,26 +255,30 @@ KERNEL=="usb/rio500",             MODE="0660"

  KERNEL=="dm-[0-9]*", GOTO="persistent_end"

+SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"
+
  KERNEL=="st*[0-9]|nst[0-9]*", IMPORT{parent}=="ID_*"
-KERNEL=="st*[0-9]|nst[0-9]*", SUBSYSTEM=="scsi_tape", ENV{ID_SERIAL}=="", \
-       IMPORT{program}="scsi_id -u -g -x -s %p -d $tempnode"
-KERNEL=="st*[0-9]|nst[0-9]*", SUBSYSTEM=="scsi_tape", ENV{ID_SERIAL}=="", \
-       IMPORT{program}="scsi_id -u -g -x -a -s %p -d $tempnode"
-KERNEL=="nst[0-9]*", SUBSYSTEM=="scsi_tape", ENV{ID_SERIAL}=="?*", \
-       SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
+KERNEL=="st*[0-9]|nst[0-9]*", SUBSYSTEM=="scsi_tape", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -u -g -x -s %p -d $tempnode"
+KERNEL=="st*[0-9]|nst[0-9]*", SUBSYSTEM=="scsi_tape", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -u -g -x -a -s %p -d $tempnode"
+KERNEL=="nst*[0-9]", SUBSYSTEM=="scsi_tape", ENV{ID_SERIAL}=="?*", 
SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-nst"
+KERNEL=="st*[0-9]", SUBSYSTEM=="scsi_tape", ENV{ID_SERIAL}=="?*", 
SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-st"

-SUBSYSTEM!="scsi_tape", GOTO="persistent_storage_tape_end"
  # by-path (parent device path)
  KERNEL=="st*[0-9]|nst*[0-9]", IMPORT{program}="path_id %p"
  KERNEL=="st*[0-9]", ENV{ID_PATH}=="?*", 
SYMLINK+="tape/by-path/$env{ID_PATH}"
-KERNEL=="nst*[0-9]", ENV{ID_PATH}=="?*", 
SYMLINK+="tape/by-path/$env{ID_PATH}-nst"
+KERNEL=="nst*[0-9]", ENV{ID_PATH}=="?*", 
SYMLINK+="tape/by-path/$env{ID_PATH}"
  LABEL="persistent_storage_tape_end"

  # type 8 devices are "Medium Changers"
  KERNEL=="sg*", IMPORT{parent}=="ID_*"
  KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="8", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -g -u -x -s %p -d $tempnode"
  KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="8", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -g -u -x -a -s %p -d $tempnode"
-KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="8", 
ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
+KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="8", 
ENV{ID_SERIAL}=="?*", 
SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-changer"
+
+# type 1 devices are "Scsi Tape"
+KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="1", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -g -u -x -s %p -d $tempnode"
+KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="1", 
ENV{ID_SERIAL}=="", IMPORT{program}="scsi_id -g -u -x -a -s %p -d $tempnode"
+KERNEL=="sg*", SUBSYSTEM=="scsi_generic", SYSFS{type}=="1", 
ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}-sg"

  SUBSYSTEM!="block", GOTO="persistent_end"
=======================




------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users

<Prev in Thread] Current Thread [Next in Thread>