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

(-)open-iscsi-2.0.871-0.29.1/etc/init.d/boot.open-iscsi (-77 lines)
Lines 1-77 Link Here
1
#!/bin/bash
2
#
3
# /etc/init.d/iscsi
4
#
5
### BEGIN INIT INFO
6
# Provides:          iscsiboot
7
# Required-Start:
8
# Should-Start:      boot.multipath
9
# Required-Stop:
10
# Should-Stop:       boot.multipath
11
# Default-Start:     B
12
# Default-Stop:      
13
# Short-Description: iSCSI initiator daemon root-fs support
14
# Description:       Starts the iSCSI initiator daemon if the
15
#                    root-filesystem is on an iSCSI device
16
#               
17
### END INIT INFO
18
19
ISCSIADM=/sbin/iscsiadm
20
CONFIG_FILE=/etc/iscsid.conf
21
DAEMON=/sbin/iscsid
22
ARGS="-c $CONFIG_FILE"
23
24
# Source LSB init functions
25
. /etc/rc.status
26
27
#
28
# This service is run right after booting. So all targets activated
29
# during mkinitrd run should not be removed when the open-iscsi
30
# service is stopped.
31
#
32
iscsi_mark_root_nodes()
33
{
34
    $ISCSIADM -m session 2> /dev/null | while read t num i target ; do
35
	ip=${i%%:*}
36
	STARTUP=`$ISCSIADM -m node -p $ip -T $target 2> /dev/null | grep "node.conn\[0\].startup" | cut -d' ' -f3`
37
	if [ "$STARTUP" -a "$STARTUP" != "onboot" ] ; then
38
	    $ISCSIADM -m node -p $ip -T $target -o update -n node.conn[0].startup -v onboot
39
	fi
40
    done
41
}
42
43
# Reset status of this service
44
rc_reset
45
46
# We only need to start this for root on iSCSI
47
if ! grep -q iscsi_tcp /proc/modules ; then
48
    rc_failed 6
49
    rc_exit
50
fi
51
52
case "$1" in
53
    start)
54
	echo -n "Starting iSCSI initiator for the root device: "
55
	startproc $DAEMON $ARGS
56
	rc_status -v
57
	iscsi_mark_root_nodes
58
	;;
59
    stop|restart|reload)
60
	rc_failed 0
61
	;;
62
    status)
63
	echo -n "Checking for iSCSI initiator service: "
64
	if checkproc $DAEMON ; then
65
	    rc_status -v
66
	else
67
	    rc_failed 3
68
	    rc_status -v
69
	fi
70
	;;
71
    *)
72
	echo "Usage: $0 {start|stop|status|restart|reload}"
73
	exit 1
74
	;;
75
esac
76
rc_exit
77
(-)open-iscsi-2.0.871-0.29.1/etc/init.d/open-iscsi (-7 / +11 lines)
Lines 5-10 Link Here
5
### BEGIN INIT INFO
5
### BEGIN INIT INFO
6
# Provides:          iscsi
6
# Provides:          iscsi
7
# Required-Start:    $network
7
# Required-Start:    $network
8
# X-Start-Before:    $remote_fs
8
# Should-Start:      iscsitarget multipathd
9
# Should-Start:      iscsitarget multipathd
9
# Required-Stop:     $network
10
# Required-Stop:     $network
10
# Should-Stop:       multipathd
11
# Should-Stop:       multipathd
Lines 386-399 Link Here
386
iscsi_list_all_nodes()
387
iscsi_list_all_nodes()
387
{
388
{
388
    # Check for active sessions
389
    # Check for active sessions
389
    if $ISCSIADM -m session > /dev/null; then
390
    if [[ -n "$($ISCSIADM -m session 2>&1 >/dev/null)" ]]
390
	return 0
391
    then
392
	echo "No active connections."
393
    else
394
	echo "Active connections:"
395
	$ISCSIADM -m session |
396
	    while read proto num PORTAL TARGET
397
	    do
398
		echo -e "\t$TARGET at ${PORTAL%,*}"
399
	    done
391
    fi
400
    fi
392
    echo "Active connections:"
393
    $ISCSIADM -m session | while read proto num PORTAL TARGET ; do
394
	PORTAL=${PORTAL%,*}
395
	echo -e "\t$TARGET at $PORTAL"
396
    done
397
}
401
}
398
402
399
case "$1" in
403
case "$1" in
(-)open-iscsi-2.0.871-0.29.1/lib/mkinitrd/scripts/setup-iscsi.sh (-50 / +118 lines)
Lines 2-71 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
23
function check_iscsi()
18
    if [ ! -d device ] ; then
24
{
19
	cd ..
25
    local devname="$1" retval=1
26
    local sysfs_path=$(/sbin/udevadm info -q path -n "${devname}" 2>/dev/null) ip target startup
27
28
    # Do we have a valid device?
29
    [[ -z "${sysfs_path}" ]] && sysfs_path="/block${devname##/dev}"
30
    sysfs_path="/sys${sysfs_path}"
31
    [[ ! -d "${sysfs_path}" ]] && return 1		# Nope, return false
32
33
    # Do we have a valid device link?
34
    [[ ! -d "${sysfs_path}/device" ]] && sysfs_path="${sysfs_path%/*}"
35
    [[ ! -d "${sysfs_path}/device" ]] && return 1	# Nope, return false
36
37
    # Is device an iSCSI device?
38
    sysfs_path="${sysfs_path}/device/../.."
39
40
    ip="$(echo ${sysfs_path}/connection*)"
41
    verify_path "${devname}" "${ip}" || return 1	# Nope, return false
42
43
    ip="${ip}/iscsi_connection/${ip##*/}/persistent_"
44
    [[ ! -r "${ip}address" || ! -r "${ip}port" ]] &&
45
	error 2 "iSCSI device ${devname} connected to iSCSI target without any persistent_{address,port}!"
46
    ip="$(cat "${ip}address"):$(cat "${ip}port")"
47
48
    target=$(echo ${sysfs_path}/iscsi_session/*)
49
    verify_path "${devname}" "${target}" || return 1	# Nope, return false
50
51
    target="${target}/targetname"
52
    [[ ! -r "${target}" ]] &&
53
	error 2 "iSCSI device ${devname} connected to iSCSI target without any targetname!"
54
    target="$(cat ${target})"
55
56
    # Yes, figure out whether it has been correctly configured!
57
    [[ ! -x "${_iadm_}" ]] &&
58
	error 2 "iSCSI device ${devname} connected to iSCSI target, but no ${_iadm_} command available!"
59
60
    startup="$(
61
	${_iadm_} -m node -p "${ip}" -T "${target}" 2>/dev/null | grep 'node.conn\[0\].startup'
62
    )"
63
    startup="${startup##* }"
64
    startup="${startup%% *}"
65
    if [[ "${startup}" != "onboot" ]]
66
    then
67
	[[ -z "${startup}" ]] && return 1	# Oops, no parameter - not an iSCSI, return false
68
69
	## Either:
70
	#echo >&2 "WARNING: iSCSI device ${devname} is using 'node.conn[0].startup = ${startup}',"
71
	#echo >&2 "WARNING: setting it to 'onboot' instead."
72
	#${_iadm_} -m node -p "${ip}" -T "${target}" -o update -n 'node.conn[0].startup' -v onboot
73
74
	## or:
75
	echo >&2 "WARNING: iSCSI device ${devname} is using 'node.conn[0].startup = ${startup}'!"
76
	echo >&2 "WARNING: System not bootable with this setting, need to be set to 'onboot' instead, using:"
77
	echo >&2 "
78
	${_iadm_} -m node -p '${ip}' -T '${target}' -o update -n 'node.conn[0].startup' -v onboot"
20
    fi
79
    fi
21
80
22
    if [ ! -d device ] ; then
81
    # Yes, is attached to an iSCSI device
23
	# no device link; return
82
    return 0
24
	popd > /dev/null
83
}
25
	return;
26
    fi
27
84
28
    cd -P device
85
_iadm_="/sbin/iscsiadm"
29
    cd ../..
30
86
31
    if [ -d connection* ]; then
87
# Are system device(s) attached to iSCSI devices?
32
	cd -P connection*
88
# In case they are, ensure
33
	cid=${PWD#*connection}
89
#	(1) that the iSCSI gets included in the "initrd"
34
	sid=${cid%%:*}
90
# and
35
	if [ -d /sys/class/iscsi_session/session$sid ]; then
91
#	(2) that the iSCSI sessions have been configured with "node.conn[0].startup = onboot".
36
	    cd -P /sys/class/iscsi_session/session$sid
92
for bd in $blockdev
37
	    echo $(basename $PWD)
93
do
38
	fi
94
    update_blockdev $bd
39
    fi
95
    check_iscsi $bd && root_iscsi=1
40
    popd > /dev/null
96
done
41
}
42
97
43
for bd in $blockdev; do
98
# Are any of the defined file partitions to be mounted at system boot attached to iSCSI devices?
99
# In case they are, ensure
100
#	(1) that the iSCSI gets included in the "initrd"
101
# and
102
#	(2) that the iSCSI sessions have been configured with "node.conn[0].startup = onboot".
103
for bd in $(awk '/^[[:space:]]*(\/dev\/|(LABEL|UUID)=)/ { print $1 }' /etc/fstab)
104
do
105
    bd="${bd/LABEL=//dev/disk/by-label/}"
106
    bd="${bd/UUID=//dev/disk/by-uuid/}"
44
    update_blockdev $bd
107
    update_blockdev $bd
45
    sid=$(check_iscsi_root $bd)
108
    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
109
done
51
110
111
# Include the iSCSI stack, when at least one active iSCSI session has been configured with
112
# "node.conn[0].startup = onboot", even if it was not used for a system device or mounted
113
# partition.
114
if [[ -x "${_iadm_}" ]]
115
then
116
    for node in $(${_iadm_} -m node 2>/dev/null | sed -e 's/ /,/g')
117
    do
118
	[[ "$(
119
		${_iadm_} -m node -T "${node##*,}" -p "${node%%,*}" 2>/dev/null |
120
		grep "node.conn\[0\].startup"
121
	    )" =~ [[:space:]]*=[[:space:]]*onboot ]] && root_iscsi=1
122
    done
123
fi
124
125
unset _iadm_
126
52
save_var root_iscsi
127
save_var root_iscsi
53
save_var iscsi_sessions
54
128
55
if [ "${root_iscsi}" ]; then
129
if [[ -z "${root_iscsi}" ]]
56
    for session in $iscsi_sessions; do
130
then
57
	eval TargetName${session}=$(cat /sys/class/iscsi_session/session${session}/targetname)
131
    # Copy the iscsi configuration
58
	eval TargetAddress${session}=$(cat /sys/class/iscsi_connection/connection${session}:0/address)
59
	eval TargetPort${session}=$(cat /sys/class/iscsi_connection/connection${session}:0/port)
60
61
	save_var TargetName${session}
62
	save_var TargetAddress${session}
63
	save_var TargetPort${session}
64
    done
65
    # copy the iscsi configuration
66
    cp -rp /etc/iscsi etc/
132
    cp -rp /etc/iscsi etc/
133
67
    # Use default interface
134
    # Use default interface
68
    interface="default"
135
    interface="default"
69
136
70
    save_var TargetPort 3260 # in case the port was not defined via command line we assign a default port
137
    # In case target port was not defined via command line, assign default port
138
    save_var TargetPort 3260
71
fi
139
fi

Return to bug 630434