+for d in $scsidevs $rawdevs; do
+ str=(`split_hostname $d`)
+ hosts[$ndevs]=${str[0]}
+ devs[$ndevs]=${str[1]}
+ ndevs=$((ndevs+1))
+done
+unique_hosts=(`unique ${hosts[@]}`)
+
+# map given device names into SG device names
+if [ "$scsidevs" ]; then
+ # 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
+ fi
+ done
+elif [ "$rawdevs" ]; then
+ for ((i=0; i < $ndevs; i++)); do
+ RES=$(remote_shell ${hosts[$i]} raw -q ${devs[$i]})
+ if [ $? -ne 0 ];then
+ echo "Raw device ${hosts[$i]}:${devs[$i]} not set up"
+ exit 1
+ fi
+ done
+fi
+
+# determine block size of each device. This should also work for raw devices
+# If it fails, set to 512
+for ((i=0; i < $ndevs; i++)); do
+ # retrieve device size (in kbytes) and block size (in bytes)
+ tmp=( `remote_shell ${hosts[$i]} sg_readcap -lb ${devs[$i]}` )
+ bs[$i]=$((tmp[1]))
+ if [ ${bs[$i]} == 0 ]; then
+ echo "sg_readcap on device ${hosts[$i]}:${devs[$i]} failed, " \
+ "setting block size to 512"
+ bs[$i]=512
+ fi
+ devsize=$((tmp[0]*bs[$i]/1024))
+
+ # check record size is a multiple of block size
+ if [ $((rszlo*1024%bs[$i])) -ne 0 ]; then
+ echo "Record size is not a multiple of block size (${bs[$i]} bytes) " \
+ "for device ${hosts[$i]}:${devs[$i]}"
+ exit 1
+ fi
+
+ # check device size
+ if [ $devsize -lt $((size*1024)) ]; then
+ echo -e "device ${hosts[$i]}:${devs[$i]} not big enough: " \
+ "$devsize < $((size*1024)).\nConsider reducing \$size"