summaryrefslogtreecommitdiffstats
path: root/addIscsiDisk
blob: 1aee906e7ac4b5645b54d27b3cab66bc72517ca4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

if [ -z "$1" ]; then
	echo "Usage: $0 <lvname>"
	exit 1
fi

lvname=$(basename $1)
if [ ! -b "/dev/scsiRaid/${lvname}" ]; then
	echo "Device '/dev/scsiRaid/${lvname}' not found."
	exit 1
fi

# check if disk exists in config
if grep -qs "Path=/dev/scsiRaid/${lvname},Type=diskio" /etc/iet/ietd.conf ; then
	echo "Disk is already in config file. Not adding it again." >&2
else
	echo -n "Adding disk to 'ietd.conf' config file... " >&2
	cat <<EOF >> /etc/iet/ietd.conf

Target iqn.2011-04.de.spline:${lvname}
	Lun 0 Path=/dev/scsiRaid/${lvname},Type=diskio,ScsiId=1,ScsiSN=2
EOF
	echo "Done." >&2
fi

if [ -r /proc/net/iet/volume ]; then
	if grep -qs "path:/dev/scsiRaid/${lvname}$" /proc/net/iet/volume ; then
		echo "Disk is already configured in ietd. Skipping live update." >&2
	else
		# get the next avilable tid
		tid=$(awk '$1 ~ /tid:/ {         \
		          gsub(/tid:/,"",$1);    \
	        	  if ( max < int($1) ) { \
		              max=int($1)        \
		          }                      \
		      }                          \
		                                 \
		      END { print max+1 }' /proc/net/iet/volume)

		echo -n "Adding disk to running ietd... " >&2
		ietadm --op new --tid=${tid} --params "Name=iqn.2011-04.de.spline:${lvname}"
		ietadm --op new --tid=${tid} --lun=0 --params "Path=/dev/scsiRaid/${lvname},Type=diskio,ScsiId=1,ScsiSN=2"
		echo "Done." >&2
	fi
else
	echo "ietd not running. Skipping live update." >&2
fi