[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

iSCSI boot patch



Hello

this is a patch somewhat based on the Pravin's post on Etherboot wiki.

There is a long standing issue (since 2006 by some email post) with
open-iscsi that prevents it from starting in live-initramfs.

Attached patch should resolve the issue and allow running iscsid.

The remaining issue is that network is brought down during shutdown
and the system locks up because it loses the / filesystem backing.

To use a Debian Live CD with iCSCSI put a line like the following in
your ietd.conf:

           Lun 0 Path=/srv/ftp/binary.iso,Type=fileio,IOMode=ro

I tested the iSCSI patch on a small image and did not see any
performance improvement over httpfs. However. iSCSI would hopefully
prevent slowdowns when disk IO is stopped for a while and then
restarted. httpfs needs to find out that its connections timed out and
re-establish them.

Thanks

Michal
diff -ur open-iscsi-2.0.870~rc3/debian/changelog open-iscsi-2.0.870~rc3.default_user/debian/changelog
--- open-iscsi-2.0.870~rc3/debian/changelog	2009-09-09 15:39:57.000000000 +0200
+++ open-iscsi-2.0.870~rc3.default_user/debian/changelog	2009-09-09 15:44:14.000000000 +0200
@@ -1,3 +1,9 @@
+open-iscsi (2.0.870~rc3-0.4.defuser) unstable; urgency=low
+
+  * add default user entry in case getpwuid fails
+
+ -- Michal Suchanek <hramrach@centrum.cz>  Wed, 09 Sep 2009 15:42:26 +0200
+
 open-iscsi (2.0.870~rc3-0.4) unstable; urgency=medium
 
   * Clean up diff.gz, it downgraded the package to 2.0.869.2.
diff -ur open-iscsi-2.0.870~rc3/usr/mgmt_ipc.c open-iscsi-2.0.870~rc3.default_user/usr/mgmt_ipc.c
--- open-iscsi-2.0.870~rc3/usr/mgmt_ipc.c	2008-09-26 01:53:08.000000000 +0200
+++ open-iscsi-2.0.870~rc3.default_user/usr/mgmt_ipc.c	2009-09-10 15:35:29.000000000 +0200
@@ -359,9 +359,14 @@
 
 	pass = getpwuid(peercred.uid);
 	if (pass == NULL) {
-		log_error("peeruser_unix: unknown local user with uid %d",
-				(int) peercred.uid);
-		return 0;
+		if(peercred.uid) {
+			log_error("peeruser_unix: unknown local user with uid %d",
+					(int) peercred.uid);
+			return 0;
+		} else {
+			log_error("peeruser_unix: getpwuid failed for uid 0, returning root");
+			strncpy(user, "root", PEERUSER_MAX);
+		}
 	}
 
 	strncpy(user, pass->pw_name, PEERUSER_MAX);
--- usr/share/initramfs-tools/hooks/live.0	2009-09-09 17:33:41.000000000 +0200
+++ usr/share/initramfs-tools/hooks/live	2009-09-09 17:36:47.000000000 +0200
@@ -176,3 +176,13 @@
 then
 	copy_exec /usr/bin/curlftpfs /bin
 fi
+
+# iSCSI
+if [ -x /usr/bin/iscsiadm ] && [ -x /usr/sbin/iscsid ]
+then
+    copy_exec /usr/bin/iscsiadm /bin
+    copy_exec /usr/sbin/iscsid /bin
+    #manual_add_modules ib_iser
+    manual_add_modules iscsi_tcp
+    manual_add_modules crc32c
+fi
--- usr/share/initramfs-tools/scripts/live.0	2009-09-09 17:33:25.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 17:37:58.000000000 +0200
@@ -87,6 +87,15 @@
 				export HTTPFS
 				;;
 
+			iscsi=*)
+				ISCSI="${ARGUMENT#iscsi=}"
+				#ip:port - separated by ,
+				ISCSI_PORTAL="${ISCSI%,*}"
+				#target name
+				ISCSI_TARGET="${ISCSI#*,}"
+				export ISCSI ISCSI_PORTAL ISCSI_TARGET
+				;;
+
 			hostname=*)
 				HOSTNAME="${ARGUMENT#hostname=}"
 				LIVECONF="changed"
@@ -688,7 +697,7 @@
 	return 0
 }
 
-do_netmount ()
+do_netsetup ()
 {
 	rc=1
 
@@ -713,6 +722,11 @@
 	[ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
 	export HOSTNAME
 
+	if [ -n "${DEVICE}" ]
+	then
+		HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
+	fi
+
 	# Check if we have a network device at all
 	if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
 	   ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
@@ -721,6 +735,11 @@
 	then
 		panic "No supported network device found, maybe a non-mainline driver is required."
 	fi
+}
+
+do_netmount()
+{
+	do_netsetup
 
 	if [ "${NFSROOT}" = "auto" ]
 	then
@@ -754,6 +773,24 @@
 	return ${rc}
 }
 
+do_iscsi()
+{
+	do_netsetup
+	#modprobe ib_iser
+	modprobe iscsi_tcp
+	mkdir -p /etc/iscsi
+	#FIXME this name is supposed to be unique - some date + ifconfig hash?
+	echo "InitiatorName=iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" > /etc/iscsi/initiatorname.iscsi
+	iscsid -f &
+	iscsiadm --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
+	iscsiadm --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
+	if [ $? != 0 ]
+	then
+		panic "Failed to log into iscsi target"
+	fi
+	#FIXME set the iscsi device name into ROOT
+}
+
 do_httpmount ()
 {
 	rc=1
@@ -1580,6 +1617,10 @@
 			panic "Unable to find a live file system on the network"
 		fi
 	else
+		if [ -n "${ISCSI_PORTAL}" ]
+		then
+			do_iscsi
+		fi
 		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 18:04:25.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 18:09:24.000000000 +0200
@@ -779,11 +779,13 @@
 	#modprobe ib_iser
 	modprobe iscsi_tcp
 	mkdir -p /etc/iscsi
+	local debugopt=""
+	[ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
 	#FIXME this name is supposed to be unique - some date + ifconfig hash?
 	echo "InitiatorName=iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" > /etc/iscsi/initiatorname.iscsi
-	iscsid -f &
-	iscsiadm --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
-	iscsiadm --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
+	iscsid $debugopt -f &
+	iscsiadm $debugopt --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
+	iscsiadm $debugopt --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
 	if [ $? != 0 ]
 	then
 		panic "Failed to log into iscsi target"
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 19:05:55.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 20:08:49.000000000 +0200
@@ -790,7 +790,21 @@
 	then
 		panic "Failed to log into iscsi target"
 	fi
-	#FIXME set the iscsi device name into ROOT
+	local host="$(ls -d /sys/class/scsi_host/host?/device/iscsi_host:host? | sed -e 's:/device.*::' -e 's:.*host::')"
+	if [ -n "${host}" ]
+	then
+		local devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+		for dev in $devices
+		do
+			if check_dev "null" "/dev/$dev"
+			then
+				return 0;
+			fi
+		done
+		panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
+	else
+		panic "Failed to locate iSCSI host in /sys"
+	fi
 }
 
 do_httpmount ()
@@ -1623,6 +1637,7 @@
 		if [ -n "${ISCSI_PORTAL}" ]
 		then
 			do_iscsi
+			livefs_root="${mountpoint}"
 		fi
 		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 20:08:49.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 20:17:45.000000000 +0200
@@ -793,7 +793,15 @@
 	local host="$(ls -d /sys/class/scsi_host/host?/device/iscsi_host:host? | sed -e 's:/device.*::' -e 's:.*host::')"
 	if [ -n "${host}" ]
 	then
-		local devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+		local devices=""
+		local i=0
+		while [ -z "${devices}" -a $i -lt 60 ]
+		do
+			sleep 1
+			devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+			i=$(expr $i + 1)
+			echo -ne $i\\r
+		done
 		for dev in $devices
 		do
 			if check_dev "null" "/dev/$dev"
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 21:11:21.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 23:03:16.000000000 +0200
@@ -1642,10 +1642,8 @@
 	else
 		if [ -n "${ISCSI_PORTAL}" ]
 		then
-			do_iscsi
-			livefs_root="${mountpoint}"
-		fi
-		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
+		    livefs_root="$(do_iscsi)"
+		elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd
 			livefs_root=${ROOT}
--- usr/share/initramfs-tools/scripts/live~	2009-09-10 13:08:01.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-10 14:13:17.000000000 +0200
@@ -1641,9 +1641,9 @@
 			panic "Unable to find a live file system on the network"
 		fi
 	else
-		if [ -n "${ISCSI_PORTAL}" ]
+		if [ -n "${ISCSI_PORTAL}" ]
 		then
-		    livefs_root="$(do_iscsi)"
+			do_iscsi && livefs_root="${mountpoint}"
 		elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd

Reply to: