Add scripts to simplify hard disk management for IBM trays

This commit is contained in:
Jeremy Gardais 2018-04-04 16:17:47 +02:00
parent 20222ea1d0
commit 8c97848104
7 changed files with 280 additions and 0 deletions

View File

@ -5,6 +5,7 @@
1. [Overview](#overview)
2. [Scripts](#scripts)
* [Proxmox](#proxmox)
* [Fiber Channel](#fiber_channel)
* [Grav](#grav)
* [Sesame2mail](#sesame2mail)
* [WordPress](#wordpress)
@ -57,6 +58,9 @@ This script must be used as a vzdump's hook (the backup utility for CT and VMs f
Same as above but set jessie in **$TEMPLATE_FILE_LINK**.
### Fiber Channel
Some scripts to manage hard disk with IBM trays.
### Grav
#### grav_cron

20
fiber_channel/delete_fc_luns Executable file
View File

@ -0,0 +1,20 @@
#!/bin/ksh
PGM_LS_LUNS=/usr/local/sbin/ls_fc_luns
set -A tuples $($PGM_LS_LUNS | awk '$3 ~ /[0-9]:[0-9]:[0-9]:[0-9]/ {print $3}')
for tuple in "${tuples[@]}"
do
set -A parts $( echo $tuple | awk -F ':' '{print($1,$2,$3,$4)}' )
h=${parts[0]}
b=${parts[1]}
t=${parts[2]}
l=${parts[3]}
#echo $host $bus $tgt $lun
set -x
fn=/sys/class/scsi_host/host$h/device/subsystem/devices/$h\:$b\:$t\:$l/delete
[[ -f $fn ]] && echo "1" > $fn
set +x
done

22
fiber_channel/get-vdev-wwn-sn Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
touch /tmp/vdev-wwn-sn.list;
echo "" > /tmp/vdev-wwn-sn.list;
# eg: /dev/disk/by-id/dm-uuid-mpath-32208000a338f2d50
for device in $(find /dev/disk/by-id -name 'dm-uuid-mpath-32208000a338*')
do
#wwn=$(echo "${device}" | cut -d"/" -f5 | cut -d"-"cut -f4);
wwn=$(/lib/udev/scsi_id -g -u -d "${device}");
# eg : 32208000a338f2d50a338f2d50
slot=$(multipath -l "${device}" | egrep "^ \`- [0-9]*\:[0-9]*\:[0-9]*\:[0-9]* " | cut -d":" -f3);
# eg : 18
sn=$(smartctl -dm scsi -i "${device}" | /bin/egrep "^Serial number:" | /bin/sed 's/^Serial number\: *//');
echo "alias disk${slot} dm-uuid-mpath-${wwn}" >> /tmp/vdev-wwn-sn.list;
done
sort -g /tmp/vdev-wwn-sn.list > /tmp/vdev-wwn-sn-sorted.list;
cat "/tmp/vdev-wwn-sn-sorted.list";

28
fiber_channel/lip_fc_hosts Executable file
View File

@ -0,0 +1,28 @@
#!/bin/ksh
PGM_LS_LUNS=/usr/local/sbin/ls_fc_luns
set -A hosts $($PGM_LS_LUNS | awk '$1 ~ /^HBA/ {print $3}')
for host in "${hosts[@]}"; do
# set -A parts $( echo $tuple | awk -F ':' '{print($1,$2,$3,$4)}' )
# h=${parts[0]}
# b=${parts[1]}
# t=${parts[2]}
# l=${parts[3]}
# #echo $host $bus $tgt $lun
fn_mulx=/sys/class/fc_host/$host/issue_lip
fn_qla=/sys/class/fc_host/$host/issue_lip
set -x
if [[ -f $fn_mulx ]]
then
echo "1" > $fn_mulx
#echo "1 $fn_mulx"
elif [[ -f $fn_qla ]]
then
echo "1" > $fn_qla
#echo "1 $fn_qla"
fi
set +x
done

188
fiber_channel/ls_fc_luns Executable file
View File

@ -0,0 +1,188 @@
#!/bin/ksh
function get_hba_vendor_code
{
host=$1
pci_loc=$(ls -l /sys/class/scsi_host/host${host} \
| awk -F '/' '{i=NF-3; print $i}' )
hba_vendor_code=$(lspci -nvms $pci_loc | awk '/^Vendor/ {print $2}')
print $hba_vendor_code
}
function get_hba_wwpn
{
host=$1
hba_vendor_code=$(get_hba_vendor_code $host)
case $hba_vendor_code in
1077)
wwpn=$(get_qla_wwpn $host);;
10df)
wwpn=$(cat /sys/class/fc_host/host${host}/port_name);;
1000)
wwpn=$(cat /sys/class/fc_host/host${host}/port_name);;
esac
print $wwpn
}
function get_qla_wwpn
{
host=$1
wwpn=''
file=/sys/class/fc_host/host${host}/port_name
if [ -r $file ]
then
wwpn=$(cat $file)
else
file=/sys/class/scsi_host/host${host}/proc_name
if [ -r $file ]
then
proc_name=$(cat $file)
file=/proc/scsi/$proc_name/$host
if [ -r $file ]
then
wwpn=$(grep 'adapter-port' /proc/scsi/$proc_name/$host \
| awk -F '=' '{print $2}' \
| tr -d ';')
else
return 2
fi
else
return 1
fi
fi
print $wwpn
}
function get_host_targets
{
host=$1
ls /sys/class/scsi_host/host${host}/device | sed -ne 's/^target//p'
set -A rports $(ls /sys/class/scsi_host/host${host}/device | sed -ne '/^rport/p')
for r in ${rports[@]}
do
ls /sys/class/scsi_host/host${host}/device/$r
done | sed -ne 's/^target//p'
}
function get_target_wwpn
{
host=$1
target=$2
target_id=$(echo $target | awk -F ':' '{print $NF}')
#echo get_target_wwpn $host $target target_id=$target_id
wwpn='tgt-wwpn???'
vendor_code=$(get_hba_vendor_code $host)
case $vendor_code in
1077)
wwpn=$(get_qla_tgt_wwpn $host $target);;
10df | 1000)
wwpn=$(cat /sys/class/fc_transport/target${target}/port_name);;
esac
print $wwpn
}
function get_qla_tgt_wwpn
{
host=$1
tgt=$2
wwpn=''
file=/sys/class/fc_transport/target${tgt}/port_name
if [ -r $file ]
then
wwpn=$(cat $file)
else
file=/sys/class/scsi_host/host${host}/proc_name
if [ -r $file ]
then
proc_name=$(cat /sys/class/scsi_host/host${host}/proc_name)
file=/proc/scsi/$proc_name/$host
if [ -r $file ]
then
wwpn=$(grep "scsi-qla.-target-$target_id" $file \
| awk -F '=' '{print $2}' \
| tr -d ';' )
else
return 2
fi
else
return 1
fi
fi
print $wwpn
}
function array_merge_numeric
{
for i in $@; do echo $i; done | sort -nu
}
function array_merge
{
for i in $@; do echo $i; done | sort -u
}
#set -x
# Check for host hba's
set -A list1
[[ -d /sys/class/fc_host ]] && \
set -A list1 $(ls /sys/class/fc_host | sed -e 's/host//')
# Check for host hba's another way
set -A list2
[[ -d /sys/class/scsi_host ]] && \
for i in /sys/class/scsi_host/host*
do
proc=$(cat $i/proc_name)
case $proc in
qla2* | lpfc | mptfc)
host=$(basename $i | sed -e 's/host//')
list2[${#list2[@]}]=$host
esac
done
set -A hbas $(array_merge_numeric ${list1[@]} ${list2[@]})
# FOREACH HBA
for hba in "${hbas[@]}"
do
# hba wwpn
hba_wwpn=$(get_hba_wwpn $hba)
print "HBA $hba_wwpn host$hba"
# get list of targets for this hba
set -A targets $(get_host_targets $hba)
# FOREACH TARGET
for target in "${targets[@]}"
do
# get target wwpn
target_wwpn=$(get_target_wwpn $hba $target)
# get list of luns for this hba:target
set -A luns $(
ls /sys/class/fc_transport/target${target}/device \
| sed -ne "s/${target}://p")
# FOREACH LUN
for lun in "${luns[@]}"
do
unset lun_scsi_dev lun_uniq_id
# get local scsi dev this lun is mapped to
file=$(ls /sys/class/fc_transport/target${target}/device/${target}:${lun} | sed -ne '/^block/p')
if [ -n "${file}" ]
then
#lun_scsi_dev=$(basename $(ls -l /sys/class/fc_transport/target${target}/device/${target}:${lun}/block* | awk '{print $NF}') )
lun_scsi_dev=$(ls /sys/class/fc_transport/target${target}/device/${target}:${lun}/block* )
# get unique lun id
lun_uniq_id=$(/lib/udev/scsi_id --page=0x83 --whitelisted --device=/dev/${lun_scsi_dev})
fi
lun_timeout=`cat /sys/class/scsi_device/${target}:${lun}/device/timeout`
# PRINT
print $hba_wwpn $target_wwpn "$target:$lun" $lun_scsi_dev $lun_uniq_id $lun_timeout
done
done
done

15
fiber_channel/scan_fc_luns Executable file
View File

@ -0,0 +1,15 @@
#!/bin/ksh
PGM_LS_LUNS=/usr/local/sbin/ls_fc_luns
set -A hosts $($PGM_LS_LUNS | awk '$1 ~ /^HBA/ {print $3}')
for host in "${hosts[@]}"; do
fn=/sys/class/scsi_host/$host/scan
if [[ -f $fn ]]
then
echo "- - -" > $fn
else
echo "ERR file not found : '$fn'"
fi
done

3
fiber_channel/wwn2sdx Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
/bin/ls -l /dev/disk/by-path | /bin/sed 's/ -> \.\.\/\.\.\// /' | /bin/grep "0x220a000a33" | /bin/egrep -v "\-part[0-9]" | /usr/bin/cut -c "60-78,85-";