- # we will test for a LUN, the test for a partition
- # if the partition number is > 9 this will fail
- for d in $scsidevs; do
- devs[$i]=`sg_map | awk "{if (\\\$2 == \"$d\") print \\\$1}"`
- if [ -z "${devs[i]}" ]; then
- echo "Can't find SG device for $d, testing for partition"
- pt=`echo $d | sed 's/[0-9]$//'`
- # Try again
- devs[$i]=`sg_map | awk "{if (\\\$2 == \"$pt\") print \\\$1}"`
- if [ -z "${devs[i]}" ]; then
- echo "Can't find SG device $pt"
- exit 1
- fi
+ # make sure sg kernel module is loaded
+ for host in ${unique_hosts[@]}; do
+ sg_is_loaded=$(remote_shell $host grep -q "^sg " /proc/modules \
+ && echo true || echo false)
+ if ! $sg_is_loaded; then
+ echo "loading the sg kernel module on $host"
+ remote_shell $host modprobe sg
+ sg_was_loaded_on="$sg_was_loaded_on $host"
+ fi
+ done
+
+ for ((i=0; i < $ndevs; i++)); do
+ # resolv symbolic link if any
+ devs[$i]=$(remote_shell ${hosts[$i]} readlink -f ${devs[$i]})
+
+ # retrieve associated sg device
+ # we will test for a LUN, the test for a partition
+ # if the partition number is > 9 this will fail
+ devs[$i]=$(remote_shell ${hosts[$i]} sg_map | \
+ awk -v dev=${devs[$i]} '{if ($2 == dev) print $1}')
+ if [ -z "${devs[i]}" ]; then
+ echo "Can't find SG device for ${hosts[$i]}:${devs[$i]}, " \
+ "testing for partition"
+ pt=`echo ${devs[$i]} | sed 's/[0-9]*$//'`
+ # Try again
+ devs[$i]=$(remote_shell ${hosts[$i]} sg_map | \
+ awk -v dev=$pt '{if ($2 == dev) print $1}')
+ if [ -z "${devs[i]}" ]; then
+ echo -e "Can't find SG device ${hosts[$i]}:$pt.\n" \
+ "Do you have the sg module configured for your kernel?"
+ exit 1
+ fi