View | Details | Raw Unified | Return to bug 630434
Collapse All | Expand All

(-)setup-iscsi.sh.orig (-58 / +114 lines)
Lines 2-78 Link Here
2
#
2
#
3
#%stage: device
3
#%stage: device
4
#
4
#
5
check_iscsi_root() {
5
function verify_path()
6
    local devname=$1
6
{
7
    local sysfs_path
7
    local devname="$1" path="$2"
8
8
9
    sysfs_path=$(/sbin/udevadm info -q path -n $devname 2> /dev/null)
9
    if [[ ! -d "${path}" ]]
10
    if [ -z "$sysfs_path" ] ; then
10
    then
11
	sysfs_path="/block${devname##/dev}"
11
	if [[ "${path}" =~ .+\ .+ ]]
12
    fi
12
	then
13
    if [ ! -d /sys$sysfs_path ] ; then
13
	    error 2 "iSCSI device ${devname} is connected to more than one iSCSI target!"
14
	return;
14
	    # NEVER REACHED!!
15
	else
16
	    # Does not seem to be an iSCSI attached device
17
	    return 1
18
	fi
15
    fi
19
    fi
20
    return 0
21
}
16
22
17
    pushd /sys$sysfs_path > /dev/null
18
    if [ ! -d device ] ; then
19
	cd ..
20
    fi
21
23
22
    if [ ! -d device ] ; then
24
function check_iscsi()
23
	# no device link; return
25
{
24
	popd > /dev/null
26
    local devname="$1" retval=1
25
	return;
27
    local sysfs_path=$(/sbin/udevadm info -q path -n "${devname}" 2>/dev/null) ip target startup
28
29
    # Do we have a valid device?
30
    [[ -z "${sysfs_path}" ]] && sysfs_path="/block${devname##/dev}"
31
    sysfs_path="/sys${sysfs_path}"
32
    [[ ! -d "${sysfs_path}" ]] && return 1		# Nope, return false
33
34
    # Do we have a valid device link?
35
    [[ ! -d "${sysfs_path}/device" ]] && sysfs_path="${sysfs_path%/*}"
36
    [[ ! -d "${sysfs_path}/device" ]] && return 1	# Nope, return false
37
38
    # Is device an iSCSI device?
39
    sysfs_path="${sysfs_path}/device/../.."
40
41
    ip="$(echo ${sysfs_path}/connection*)"
42
    verify_path "${devname}" "${ip}" || return 1	# Nope, return false
43
44
    ip="${ip}/iscsi_connection/${ip##*/}/persistent_"
45
    [[ ! -r "${ip}address" || ! -r "${ip}port" ]] &&
46
	error 2 "iSCSI device ${devname} connected to iSCSI target without any persistent_{address,port}!"
47
    ip="$(cat "${ip}address"):$(cat "${ip}port")"
48
49
    target=$(echo ${sysfs_path}/iscsi_session/*)
50
    verify_path "${devname}" "${target}" || return 1	# Nope, return false
51
52
    target="${target}/targetname"
53
    [[ ! -r "${target}" ]] &&
54
	error 2 "iSCSI device ${devname} connected to iSCSI target without any targetname!"
55
    target="$(cat ${target})"
56
57
    # Yes, figure out whether it has been correctly configured!
58
    [[ ! -x "${_iadm_}" ]] &&
59
	error 2 "iSCSI device ${devname} connected to iSCSI target, but no ${_iadm_} command available!"
60
61
    startup="$(
62
	${_iadm_} -m node -p "${ip}" -T "${target}" 2>/dev/null | grep 'node.conn\[0\].startup'
63
    )"
64
    startup="${startup##* }"
65
    startup="${startup%% *}"
66
    if [[ "${startup}" != "onboot" ]]
67
    then
68
	[[ -z "${startup}" ]] && return 1	# Oops, no parameter - not an iSCSI, return false
69
70
	## Either:
71
	#echo >&2 "WARNING: iSCSI device ${devname} is using 'node.conn[0].startup = ${startup}',"
72
	#echo >&2 "WARNING: setting it to 'onboot' instead."
73
	#${_iadm_} -m node -p "${ip}" -T "${target}" -o update -n 'node.conn[0].startup' -v onboot
74
75
	## or:
76
	echo >&2 "WARNING: iSCSI device ${devname} is using 'node.conn[0].startup = ${startup}'!"
77
	echo >&2 "WARNING: System not bootable with this setting, need to be set to 'onboot' instead, using:"
78
	echo >&2 "
79
	${_iadm_} -m node -p '${ip}' -T '${target}' -o update -n 'node.conn[0].startup' -v onboot"
26
    fi
80
    fi
27
81
28
    cd -P device
82
    # Yes, is attached to an iSCSI device
29
    cd ../..
83
    return 0
30
31
    if [ -d connection* ]; then
32
	cd -P connection*
33
	cid=${PWD#*connection}
34
	sid=${cid%%:*}
35
	if [ -d /sys/class/iscsi_session/session$sid ]; then
36
	    cd -P /sys/class/iscsi_session/session$sid
37
	    echo $(basename $PWD)
38
	fi
39
    fi
40
    popd > /dev/null
41
}
84
}
42
85
43
for bd in $blockdev; do
86
_iadm_="/sbin/iscsiadm"
87
88
# Are system device(s) attached to iSCSI devices?
89
# In case they are, ensure
90
#	(1) that the iSCSI gets included in the "initrd"
91
# and
92
#	(2) that the iSCSI sessions have been configured with "node.conn[0].startup = onboot".
93
for bd in $blockdev
94
do
44
    update_blockdev $bd
95
    update_blockdev $bd
45
    sid=$(check_iscsi_root $bd)
96
    check_iscsi $bd && root_iscsi=1
46
    if [ "$sid" ]; then
47
    	root_iscsi=1
48
    	iscsi_sessions="$iscsi_sessions ${sid#session}"
49
    fi
50
done
97
done
51
98
99
# Are any of the defined file partitions to be mounted at system boot attached to iSCSI devices?
100
# In case they are, ensure
101
#	(1) that the iSCSI gets included in the "initrd"
102
# and
103
#	(2) that the iSCSI sessions have been configured with "node.conn[0].startup = onboot".
104
for bd in $(awk '/^[[:space:]]*(\/dev\/|(LABEL|UUID)=)/ { print $1 }' /etc/fstab)
105
do
106
    bd="${bd/LABEL=//dev/disk/by-label/}"
107
    bd="${bd/UUID=//dev/disk/by-uuid/}"
108
    update_blockdev $bd
109
    check_iscsi $bd && root_iscsi=1
110
done
111
112
# Include the iSCSI stack, when at least one active iSCSI session has been configured with
113
# "node.conn[0].startup = onboot", even if it was not used for a system device or mounted
114
# partition.
115
if [[ -x "${_iadm_}" ]] ; then
116
    for node in $(${_iadm_} -m node 2>/dev/null | sed -e 's/ /,/g') ; do
117
	[[ "$(
118
		${_iadm_} -m node -T "${node##*,}" -p "${node%%,*}" 2>/dev/null |
119
		grep "node.conn\[0\].startup"
120
	    )" =~ [[:space:]]*=[[:space:]]*onboot ]] && root_iscsi=1
121
    done
122
fi
123
124
unset _iadm_
125
52
save_var root_iscsi
126
save_var root_iscsi
53
save_var iscsi_sessions
54
127
55
if [ "${root_iscsi}" ]; then
128
if [ "${root_iscsi}" ]; then
56
    for session in $iscsi_sessions; do
129
    # Copy the iscsi configuration
57
	read TargetName${session} </sys/class/iscsi_session/session${session}/targetname
58
	read TargetAddress${session} </sys/class/iscsi_connection/connection${session}:0/address
59
        TargetAddress=$(< /sys/class/iscsi_connection/connection${session}:0/address)
60
	read TargetPort${session} </sys/class/iscsi_connection/connection${session}:0/port
61
62
	save_var TargetName${session}
63
	save_var TargetAddress${session}
64
	save_var TargetPort${session}
65
66
        cmd=ip
67
        case "$TargetAddress" in
68
        *:*)
69
            cmd="ip -6"
70
        esac
71
        interface="$interface $($cmd route get "$TargetAddress" | sed -rn 's/.*\<dev ([^ ]*)\>.*/\1/p; T; q')"
72
        unset TargetAddress cmd
73
    done
74
    # copy the iscsi configuration
75
    cp -rp /etc/iscsi etc/
130
    cp -rp /etc/iscsi etc/
76
131
77
    save_var TargetPort 3260 # in case the port was not defined via command line we assign a default port
132
    # In case target port was not defined via command line, assign default port
133
    save_var TargetPort 3260
78
fi
134
fi

Return to bug 630434