Skip to content

Instantly share code, notes, and snippets.

@chrishiestand
Last active September 27, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishiestand/139a4bd459fb9c152941 to your computer and use it in GitHub Desktop.
Save chrishiestand/139a4bd459fb9c152941 to your computer and use it in GitHub Desktop.
A workaround for Overland 2000 tape devices (via FC), /dev/sgx, /dev/nstx not being added automatically in RHEL4. This was my first python script, so feel free to LoL
#!/usr/bin/env python
#This is a workaround for Overland 2000 tape devices (via FC), /dev/sgx, /dev/nstx not being added automatically in RHEL4.
#For more information see notes at end of file
#
# chkconfig: 235 71 25
# description: Workaround for Overland 2000 tape devices (via FC) \
# being added as device nodes.
DEBUG = 9
import os, re, time
qla_search_path = '/proc/scsi/qla2xxx'
scsi_file = '/proc/scsi/scsi'
qla_hba_file = ''
IDLunArray = {}
for qlafile in os.listdir(qla_search_path):
try:
f = open(qla_search_path + '/' + qlafile, 'r+')
for line in f.readlines():
HBAMatch = re.match('QLogic PCI to Fibre Channel Host Adapter(.*) ' , line)
IDLUNMatch = re.match('^\(\s(\d):\s(\d)\)', line)
if HBAMatch:
qla_hba_file = f.name.split('/').pop();
if DEBUG:
print 'found QLA controller id: ' + qla_hba_file
try:
f.write("scsi-qlascan\n")
time.sleep(3)
except:
print "Could not write to file: " + qlafile
elif IDLUNMatch:
try:
if IDLunArray[IDLUNMatch.group(1)] :
if DEBUG:
print "Matched Regular expression for ID:" + IDLUNMatch.group(1) + " LUN:" + IDLUNMatch.group(2)
IDLunArray[IDLUNMatch.group(1)].append( IDLUNMatch.group(2) )
except KeyError:
if DEBUG:
print IDLUNMatch.group(1) + " not found in IDLunArray, adding it."
IDLunArray[IDLUNMatch.group(1)] = []
IDLunArray[IDLUNMatch.group(1)].append( IDLUNMatch.group(2) )
except IOError:
print "Could not open/read file:" + qlafile
for ID in (IDLunArray):
for LUN in IDLunArray[ID]:
#You must open/close the file handle for each line you write (flushing may be sufficient?)
try:
f = open(scsi_file, 'w')
except:
print "Could not open file: " + scsi_file
if DEBUG:
print "Adding scsi device: " + qla_hba_file +" with ID: " + ID + ". And LUN: " + LUN + ' to ' + f.name
f.write('scsi add-single-device ' + qla_hba_file + ' 0 ' + ID + ' ' + LUN + "\n" )
f.close()
if DEBUG:
print 'done.\n';
#NOTES:
#http://publib.boulder.ibm.com/infocenter/tssfsv21/index.jsp?topic=/com.ibm.sanfs.doc/foe0_t_adding_luns_to_sanfs.html
#The following text was taken from the overland support site, before Overland expired the article:
#[6169] How to rescan devices in Linux OS without reloading the linux driver?
#Procedure:
#There is a procedure which forces the driver to rescan the targets to allow a new device to be added. This triggers the driver to initiate a LUN discovery process.
#To force a rescan from the command line, type the following command:
# echo "scsi-qlascan" > /proc/scsi//
#Where:
#- = qla2100, qla2200, qla2300 (2.4 kernel drivers) or qla2xxx (2.6 kernel drivers)
#- = the instance number of the HBA
#After executing this command, force the SCSI mid layer to do its own scan and build the device table entry for the new device by typing the following command:
# echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
#Where:
# "0 1 2 3" = your "Host Channel ID LUN"
#The scanning must be done in the above mentioned order: first the driver (qla2300/qla2200 driver, etc.), and then the Linux SCSI mid layer (i.e. OS scan).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment