c2d5d21
From d86ca42685620ad3263da098923308a3a00ac55a Mon Sep 17 00:00:00 2001
c2d5d21
From: Eddie Wai <eddie.wai@broadcom.com>
c2d5d21
Date: Fri, 12 Apr 2013 10:41:16 -0700
c2d5d21
Subject: ISCSID: Added the extraction of the session boot info
c2d5d21
c2d5d21
This patch does the work to extract the corresponding
c2d5d21
<boot_root>->ethernetN net params as specified from the kernel
c2d5d21
session boot_nic sysfs entry based on the transport param
c2d5d21
use_boot_info.
c2d5d21
c2d5d21
This is only populated for iscsi_tcp and bnx2i.
c2d5d21
c2d5d21
Signed-off-by: Eddie Wai <eddie.wai@broadcom.com>
c2d5d21
---
c2d5d21
 usr/iscsi_sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
c2d5d21
 usr/transport.c   |  2 ++
c2d5d21
 usr/transport.h   |  1 +
c2d5d21
 3 files changed, 43 insertions(+)
c2d5d21
c2d5d21
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
c2d5d21
index aed10a3..79ec79d 100644
c2d5d21
--- a/usr/iscsi_sysfs.c
c2d5d21
+++ b/usr/iscsi_sysfs.c
c2d5d21
@@ -674,6 +674,43 @@ free_fnode:
c2d5d21
 	return rc;
c2d5d21
 }
c2d5d21
 
c2d5d21
+static int iscsi_sysfs_read_boot(struct iface_rec *iface, char *session)
c2d5d21
+{
c2d5d21
+	char boot_root[BOOT_NAME_MAXLEN], boot_nic[BOOT_NAME_MAXLEN];
c2d5d21
+	char boot_name[BOOT_NAME_MAXLEN], boot_content[BOOT_NAME_MAXLEN];
c2d5d21
+
c2d5d21
+	/* Extract boot info */
c2d5d21
+	strlcpy(boot_name, "boot_target", sizeof(boot_name));
c2d5d21
+	if (sysfs_get_str(session, ISCSI_SESSION_SUBSYS, boot_name,
c2d5d21
+			  boot_content, BOOT_NAME_MAXLEN))
c2d5d21
+		return -1;
c2d5d21
+	strlcpy(boot_name, "boot_nic", sizeof(boot_name));
c2d5d21
+	if (sysfs_get_str(session, ISCSI_SESSION_SUBSYS, boot_name, boot_nic,
c2d5d21
+			  BOOT_NAME_MAXLEN))
c2d5d21
+		return -1;
c2d5d21
+	strlcpy(boot_name, "boot_root", sizeof(boot_name));
c2d5d21
+	if (sysfs_get_str(session, ISCSI_SESSION_SUBSYS, boot_name, boot_root,
c2d5d21
+			  BOOT_NAME_MAXLEN))
c2d5d21
+		return -1;
c2d5d21
+
c2d5d21
+	/* If all boot_root/boot_target/boot_nic exist, then extract the
c2d5d21
+	   info from the boot nic */
c2d5d21
+	if (sysfs_get_str(boot_nic, boot_root, "vlan", boot_content,
c2d5d21
+			  BOOT_NAME_MAXLEN))
c2d5d21
+		log_debug(5, "could not read %s/%s/vlan", boot_root, boot_nic);
c2d5d21
+	else
c2d5d21
+		iface->vlan_id = atoi(boot_content);
c2d5d21
+
c2d5d21
+	if (sysfs_get_str(boot_nic, boot_root, "subnet-mask",
c2d5d21
+			  iface->subnet_mask, NI_MAXHOST))
c2d5d21
+		log_debug(5, "could not read %s/%s/subnet", boot_root,
c2d5d21
+			  boot_nic);
c2d5d21
+
c2d5d21
+	log_debug(5, "sysfs read boot returns %s/%s/ vlan = %d subnet = %s",
c2d5d21
+		  boot_root, boot_nic, iface->vlan_id, iface->subnet_mask);
c2d5d21
+	return 0;
c2d5d21
+}
c2d5d21
+
c2d5d21
 /*
c2d5d21
  * Read in iface settings based on host and session values. If
c2d5d21
  * session is not passed in, then the ifacename will not be set. And
c2d5d21
@@ -802,6 +839,9 @@ static int iscsi_sysfs_read_iface(struct iface_rec *iface, int host_no,
c2d5d21
 		}
c2d5d21
 	}
c2d5d21
 
f9b971f
+	if (t->template->use_boot_info && session)
c2d5d21
+		iscsi_sysfs_read_boot(iface, session);
c2d5d21
+
c2d5d21
 	if (!iface_kern_id)
c2d5d21
 		goto done;
c2d5d21
 
c2d5d21
diff --git a/usr/transport.c b/usr/transport.c
c2d5d21
index 52b7674..4d030a8 100644
c2d5d21
--- a/usr/transport.c
c2d5d21
+++ b/usr/transport.c
c2d5d21
@@ -42,6 +42,7 @@
c2d5d21
 
c2d5d21
 struct iscsi_transport_template iscsi_tcp = {
c2d5d21
 	.name		= "tcp",
c2d5d21
+	.use_boot_info	= 1,
c2d5d21
 	.ep_connect	= iscsi_io_tcp_connect,
c2d5d21
 	.ep_poll	= iscsi_io_tcp_poll,
c2d5d21
 	.ep_disconnect	= iscsi_io_tcp_disconnect,
c2d5d21
@@ -77,6 +78,7 @@ struct iscsi_transport_template cxgb4i = {
c2d5d21
 struct iscsi_transport_template bnx2i = {
c2d5d21
 	.name		= "bnx2i",
c2d5d21
 	.set_host_ip	= 1,
c2d5d21
+	.use_boot_info	= 1,
c2d5d21
 	.ep_connect	= ktransport_ep_connect,
c2d5d21
 	.ep_poll	= ktransport_ep_poll,
c2d5d21
 	.ep_disconnect	= ktransport_ep_disconnect,
c2d5d21
diff --git a/usr/transport.h b/usr/transport.h
c2d5d21
index 5dcf872..388e4b1 100644
c2d5d21
--- a/usr/transport.h
c2d5d21
+++ b/usr/transport.h
c2d5d21
@@ -31,6 +31,7 @@ struct iscsi_transport_template {
c2d5d21
 	 * the host's ip address.
c2d5d21
 	 */
c2d5d21
 	uint8_t set_host_ip;
c2d5d21
+	uint8_t use_boot_info;
c2d5d21
 	int (*ep_connect) (struct iscsi_conn *conn, int non_blocking);
c2d5d21
 	int (*ep_poll) (struct iscsi_conn *conn, int timeout_ms);
c2d5d21
 	void (*ep_disconnect) (struct iscsi_conn *conn);
c2d5d21
-- 
c2d5d21
1.8.1.4
c2d5d21