Re: [PATCH] support NIC configuration in iBFT

2010-01-15 Thread Hannes Reinecke
Mike Christie wrote:
 On 01/07/2010 08:16 AM, Alex Zeffertt wrote:
 Mike Christie wrote:

 Thanks for doing this. Sorry for the late reply.


 Just one comment on the patch. Could you move the code in the 'n' case

 + case 'n':
 + /*
 + * Bring up NICs required by targets in iBFT
 + * using IP addresses and routing info from iBFT.
 + */

 ..


 to some helper function, so it is not so crowed and a little easier to
 read?


 No problem. Please find a new patch attached.

 
 Merged in commit 39f4761231e2aa20b468cd5258785d6f56472772. It should
 show up in the git tree in a little bit and in the next major release.
 Thanks!
 
Finally found some time to comment on this one.
In principle this is a good idea; it certainly saves quite some trouble
for eg initrd as we don't have to worry about interface naming etc.

However:
Having iscsiadm setting up the network interfaces we do have the problem
that we're doing it alongside the 'normal' system network configuration.
IE the system hasn't any idea that we've already configured the interface
nor how it should handle it.
This is especially a problem during shutdown, where the networking scripts
are prone to shutdown any unknown interface.
And having the networking scripts calling out to iscsiadm is not earning
us much favours I would assume.

A possible route here would be to modify the networking scripts to check
the ibft variables; however, this requires quite some bit of sysfs tree
walking. And given the somewhat fluctuating nature of sysfs it will earn
us even less favours.

It would be cool if we had an 'ibft' link in the network interface, though ...
Hmm. Maybe I can trick Kay Sievers into doing one ...

But apart from that is a pretty cool thing.
It especially fixes the problem we have right now that changes in the
iBFT BIOS are not picked up once the machines are installed.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)
-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.




Re: [PATCH] support NIC configuration in iBFT

2010-01-15 Thread Alex Zeffertt

Hannes Reinecke wrote:

Mike Christie wrote:

On 01/07/2010 08:16 AM, Alex Zeffertt wrote:

Mike Christie wrote:

Thanks for doing this. Sorry for the late reply.


Just one comment on the patch. Could you move the code in the 'n' case

+ case 'n':
+ /*
+ * Bring up NICs required by targets in iBFT
+ * using IP addresses and routing info from iBFT.
+ */

..


to some helper function, so it is not so crowed and a little easier to
read?


No problem. Please find a new patch attached.


Merged in commit 39f4761231e2aa20b468cd5258785d6f56472772. It should
show up in the git tree in a little bit and in the next major release.
Thanks!


Finally found some time to comment on this one.
In principle this is a good idea; it certainly saves quite some trouble
for eg initrd as we don't have to worry about interface naming etc.

However:
Having iscsiadm setting up the network interfaces we do have the problem
that we're doing it alongside the 'normal' system network configuration.
IE the system hasn't any idea that we've already configured the interface
nor how it should handle it.
This is especially a problem during shutdown, where the networking scripts
are prone to shutdown any unknown interface.
And having the networking scripts calling out to iscsiadm is not earning
us much favours I would assume.

A possible route here would be to modify the networking scripts to check
the ibft variables; however, this requires quite some bit of sysfs tree
walking. And given the somewhat fluctuating nature of sysfs it will earn
us even less favours.



Remember that the context is that this has to be done in the initrd!  (You have 
to bring up the LUNs present in the iBFT to access the root disk, and to do that 
you need to apply the network configuration in the iBFT.)


You may not be able to do much scripting in the initrd.  In particular Redhat 
initrds use an interpreter called nash which is hopeless for scripting - you 
can't even assign an environment variable in nash!  Adding one line which says 
iscsistart -n is much simpler.


Most distro's shutdown scripts will only shutdown interfaces if they have been 
explicitly configured.  So to avoid the interface being shutdown (and thereby 
breaking the root disk) it should just be sufficient to just not write 
ifcfg-ethN (or equivalent for your distro).




It would be cool if we had an 'ibft' link in the network interface, though ...
Hmm. Maybe I can trick Kay Sievers into doing one ...

But apart from that is a pretty cool thing.
It especially fixes the problem we have right now that changes in the
iBFT BIOS are not picked up once the machines are installed.



Thanks!

 -- Alex



Cheers,

Hannes



-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.




Re: [PATCH] support NIC configuration in iBFT

2010-01-12 Thread Mike Christie

On 01/07/2010 08:16 AM, Alex Zeffertt wrote:

Mike Christie wrote:


Thanks for doing this. Sorry for the late reply.


Just one comment on the patch. Could you move the code in the 'n' case

+ case 'n':
+ /*
+ * Bring up NICs required by targets in iBFT
+ * using IP addresses and routing info from iBFT.
+ */

..


to some helper function, so it is not so crowed and a little easier to
read?



No problem. Please find a new patch attached.



Merged in commit 39f4761231e2aa20b468cd5258785d6f56472772. It should 
show up in the git tree in a little bit and in the next major release. 
Thanks!
-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.




Re: [PATCH] support NIC configuration in iBFT

2010-01-07 Thread Alex Zeffertt

Mike Christie wrote:


Thanks for doing this. Sorry for the late reply.


Just one comment on the patch. Could you move the code in the 'n' case

+   case 'n':
+   /*
+* Bring up NICs required by targets in iBFT
+* using IP addresses and routing info from iBFT.
+*/

..


to some helper function, so it is not so crowed and a little easier to read?



No problem.  Please find a new patch attached.

Regards,

Alex
-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.


iscsistart option to bring up NICs using configuration in iBFT.

For each target listed, iSCSI Boot Firmware Tables specify which NIC to use and
how it should be configured.  Until now this information has been ignored by
open-iscsi.  This patch enables iscsistart to apply the NIC configuration.

The new command iscsiadm -n applies the NIC configuration specified in the
iBFT for each valid target.

The primary benefit of this is that it allows the initrd to extract networking
information from the iBFT rather than hard code it.  If the initrd uses the iBFT
for networking info then when this info is modified via the BIOS it is not
necessary to rebuild the initrd.

Signed-off-byalex.zeffe...@eu.citrix.com

diff --git a/usr/iscsistart.c b/usr/iscsistart.c
index 8482ad5..2ee2674 100644
--- a/usr/iscsistart.c
+++ b/usr/iscsistart.c
@@ -24,6 +24,7 @@
 #include getopt.h
 #include stdlib.h
 #include stdio.h
+#include stddef.h
 #include unistd.h
 #include string.h
 #include signal.h
@@ -32,6 +33,11 @@
 #include sys/signal.h
 #include sys/types.h
 #include sys/wait.h
+#include sys/socket.h
+#include sys/ioctl.h
+#include netinet/in.h
+#include arpa/inet.h
+#include net/route.h
 
 #include initiator.h
 #include iscsi_ipc.h
@@ -73,6 +79,7 @@ static struct option const long_options[] = {
 	{password_in, required_argument, NULL, 'W'},
 	{debug, required_argument, NULL, 'd'},
 	{fwparam_connect, no_argument, NULL, 'b'},
+	{fwparam_network, no_argument, NULL, 'n'},
 	{fwparam_print, no_argument, NULL, 'f'},
 	{help, no_argument, NULL, 'h'},
 	{version, no_argument, NULL, 'v'},
@@ -99,6 +106,7 @@ Open-iSCSI initiator.\n\
   -W, --password_in=N  set incoming password to N (optional\n\
   -d, --debug debuglevel   print debugging information \n\
   -b, --fwparam_connectcreate a session to the target\n\
+  -n, --fwparam_networkbring up the network as specified by iBFT\n\
   -f, --fwparam_print  print the iBFT to STDOUT \n\
   -h, --help   display this help and exit\n\
   -v, --versiondisplay version and exit\n\
@@ -199,6 +207,140 @@ static int setup_session(void)
 	return rc;
 }
 
+static int setup_nics(void)
+{
+	struct boot_context *context;
+	char *iface_prev = NULL;
+	int sock;
+	int ret;
+
+	/* Create socket for making networking changes */
+	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
+		perror(socket(AF_INET, SOCK_DGRAM, 0));
+		exit(1);
+	}
+			
+	/* 
+	 * For each target in iBFT bring up required NIC and use routing
+	 * to force iSCSI traffic through correct NIC
+	 */
+	list_for_each_entry(context, targets, list) {
+	
+		/* Bring up NIC with correct address  - unless it
+		 * has already been handled (2 targets in IBFT may share one NIC)
+		 */
+		struct sockaddr_in ipaddr = { .sin_family = AF_INET };
+		struct sockaddr_in netmask = { .sin_family = AF_INET };
+		struct sockaddr_in hostmask = { .sin_family = AF_INET };
+		struct sockaddr_in gateway = { .sin_family = AF_INET };
+		struct sockaddr_in tgt_ipaddr = { .sin_family = AF_INET };
+		struct rtentry rt;
+		struct ifreq ifr;
+
+		if (!strlen(context-iface)) {
+			printf(No iface in fw entry\n);
+			ret = -1;
+			continue;
+		}
+		if (!inet_aton(context-ipaddr, ipaddr.sin_addr)) {
+			printf(Invalid or no ipaddr in fw entry\n);
+			ret = -1;
+			continue;
+		}
+
+		if (!inet_aton(context-mask, netmask.sin_addr)) {
+			printf(Invalid or no netmask in fw entry\n);
+			ret = -1;
+			continue;
+		}
+		inet_aton(255.255.255.255, hostmask.sin_addr);
+
+		if (!inet_aton(context-target_ipaddr, tgt_ipaddr.sin_addr)) {
+			printf(Invalid or no target ipaddr in fw entry\n);
+			ret = -1;
+			continue;
+		}
+
+		/* Only set IP/NM if this is a new interface */
+		if (iface_prev == NULL || strcmp(context-iface, iface_prev)) {
+	
+			/* Note: test above works because there is a maximum of two targets in the iBFT */
+			iface_prev = context-iface;
+
+			/* TODO: create vlan if strlen(context-vlan) */
+
+			/* Bring up interface */
+			memset(ifr, 0, sizeof(ifr));
+			strncpy(ifr.ifr_name, context-iface, IFNAMSIZ);
+			ifr.ifr_flags = IFF_UP | IFF_RUNNING;
+			if (ioctl(sock, 

Re: [PATCH] support NIC configuration in iBFT

2010-01-07 Thread Ulrich Windl
On getopt:

I always prefer to list options in an ordered way (alphabetically).

-   while ((ch = getopt_long(argc, argv, i:t:g:a:p:d:u:w:U:W:bfvh,
+   while ((ch = getopt_long(argc, argv, i:t:g:a:p:d:u:w:U:W:bnfvh,

On 7 Jan 2010 at 14:16, Alex Zeffertt wrote:

 Mike Christie wrote:
  
  Thanks for doing this. Sorry for the late reply.
  
  
  Just one comment on the patch. Could you move the code in the 'n' case
  
  +   case 'n':
  +   /*
  +* Bring up NICs required by targets in iBFT
  +* using IP addresses and routing info from iBFT.
  +*/
  
  ..
  
  
  to some helper function, so it is not so crowed and a little easier to read?
  
 
 No problem.  Please find a new patch attached.
 
 Regards,
 
 Alex
 


-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.




Re: [PATCH] support NIC configuration in iBFT

2009-12-18 Thread Alex Zeffertt
All,

Please ignore the patch in my previous email and use the one attached instead.

I fixed a bug in the previous patch where iscsistart -n was assuming that the 
interface being configured was already up.

Regards,

Alex

Alex Zeffertt wrote:
 Please could the attached patch be considered for inclusion in the 
 open-iscsi
 source.  Note: this patch depends on support-multidisk-ibft.patch sent 
 earlier.
 
 Regards,
 
 Alex Zeffertt
 
 Changelog:
 -
 
 For each target listed, iSCSI Boot Firmware Tables specify which NIC to 
 use and how it should be configured.  Until now this information has 
 been ignored by open-iscsi.
 
 This patch enables this information to be listed by iscsiadm/iscsistart, 
 and it also enables iscsistart to apply the configuration.
 
 The existing commands iscsiadm -m fw and iscsistart -f now list the 
 NIC configuration from the iBFT in addition to the other information.
 
 The new command iscsiadm -n applies the NIC configuration specified in 
 the iBFT for each valid target.
 
 The primary benefit of this is that it allows the initrd to extract 
 networking information from the iBFT rather than hard code it.  If the 
 initrd uses the iBFT for networking info then when the setup is modified 
 via the BIOS it is not necessary to rebuild the initrd.
 
 

--

You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.


diff -r 64c9bc1babc0 include/fw_context.h
--- a/include/fw_context.h	Thu Dec 17 12:49:46 2009 +
+++ b/include/fw_context.h	Fri Dec 18 14:49:36 2009 +
@@ -35,6 +35,7 @@
 	char mac[18];
 	char ipaddr[18];
 	char mask[18];
+	char gateway[18];
 	char lun[17];
 	char vlan[15];
 	char isid[10];
diff -r 64c9bc1babc0 usr/iscsi_sysfs.c
--- a/usr/iscsi_sysfs.c	Thu Dec 17 12:49:46 2009 +
+++ b/usr/iscsi_sysfs.c	Fri Dec 18 14:49:36 2009 +
@@ -40,6 +40,7 @@
 #define ISCSI_TRANSPORT_DIR	/sys/class/iscsi_transport
 #define ISCSI_SESSION_DIR	/sys/class/iscsi_session
 #define ISCSI_HOST_DIR		/sys/class/iscsi_host
+#define NETDEV_DIR			/sys/class/net
 
 #define ISCSI_SYSFS_INVALID_VALUE	NULL
 #define ISCSI_SESSION_SUBSYS		iscsi_session
@@ -49,6 +50,7 @@
 #define SCSI_HOST_SUBSYS		scsi_host
 #define SCSI_DEVICE_SUBSYS		scsi_device
 #define SCSI_SUBSYS			scsi
+#define NET_SUBSYS			net
 
 #define ISCSI_MAX_SYSFS_BUFFER NI_MAXHOST
 
@@ -121,6 +123,7 @@
 
 iscsi_sysfs_get_param_by_str(transport, ISCSI_TRANSPORT_SUBSYS);
 iscsi_sysfs_get_param_by_str(scsi_dev, SCSI_SUBSYS);
+iscsi_sysfs_get_param_by_str(netdev, NET_SUBSYS);
 
 static int iscsi_sysfs_set_param(char *id, char *subsys, char *attr_name,
  char *write_buf, ssize_t buf_size)
@@ -657,6 +660,46 @@
 	return ret;
 }
 
+static int get_netdev_mac(char *netdev, char mac[18])
+{
+	return iscsi_sysfs_get_netdev_param(netdev, address, mac, %s);
+}
+
+int iscsi_sysfs_get_netdev_by_mac(char mac[18], char netdev[], int len)
+{
+	struct dirent **namelist;
+	int n, i;
+	int retval = -1;
+
+	n = scandir(NETDEV_DIR, namelist, NULL, direntcmp);
+	if (n = 0)
+		return n;
+
+	for (i = 0; i  n; i++) {
+		char *name = namelist[i]-d_name;
+		char buf[18];
+if (!strcmp(name, .) || !strcmp(name, ..))
+			continue;
+		
+		if (get_netdev_mac(name, buf)) {
+			log_error(could not find mac address for %s, name);
+			continue;
+		}
+		
+		if (strncasecmp(buf, mac, 17) == 0) {
+			strlcpy(netdev, name, len);
+			retval = 0;
+			break;
+		}
+	}
+
+	for (i = 0; i  n; i++)
+		free(namelist[i]);
+	free(namelist);
+
+	return retval;	
+}
+
 int iscsi_sysfs_for_each_host(void *data, int *nr_found,
 			  iscsi_sysfs_host_op_fn *fn)
 {
diff -r 64c9bc1babc0 usr/iscsi_sysfs.h
--- a/usr/iscsi_sysfs.h	Thu Dec 17 12:49:46 2009 +
+++ b/usr/iscsi_sysfs.h	Fri Dec 18 14:49:36 2009 +
@@ -97,6 +97,7 @@
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_session(char *sys_session);
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_sid(uint32_t sid);
 extern struct iscsi_transport *iscsi_sysfs_get_transport_by_name(char *transport_name);
+extern int iscsi_sysfs_get_netdev_by_mac(char mac[18], char netdev[], int len);
 
 extern struct list_head transports;
 
diff -r 64c9bc1babc0 usr/iscsistart.c
--- a/usr/iscsistart.c	Thu Dec 17 12:49:46 2009 +
+++ b/usr/iscsistart.c	Fri Dec 18 14:49:36 2009 +
@@ -24,6 +24,7 @@
 #include getopt.h
 #include stdlib.h
 #include stdio.h
+#include stddef.h
 #include unistd.h
 #include string.h
 #include signal.h
@@ -32,6 +33,11 @@
 #include sys/signal.h
 #include sys/types.h
 #include sys/wait.h
+#include sys/socket.h
+#include sys/ioctl.h
+#include netinet/in.h
+#include arpa/inet.h
+#include net/route.h
 
 #include initiator.h
 #include iscsi_ipc.h
@@ -93,7 +99,8 @@
   -U, --username_in=N  set 

Re: [PATCH] support NIC configuration in iBFT

2009-12-18 Thread Mike Christie
Alex Zeffertt wrote:
 Please could the attached patch be considered for inclusion in the open-iscsi
 source.  Note: this patch depends on support-multidisk-ibft.patch sent 
 earlier.
 
 Regards,
 
 Alex Zeffertt
 
 Changelog:
 -
 
 For each target listed, iSCSI Boot Firmware Tables specify which NIC to use 
 and 
 how it should be configured.  Until now this information has been ignored by 
 open-iscsi.
 
 This patch enables this information to be listed by iscsiadm/iscsistart, and 
 it 
 also enables iscsistart to apply the configuration.
 
 The existing commands iscsiadm -m fw and iscsistart -f now list the NIC 
 configuration from the iBFT in addition to the other information.
 
 The new command iscsiadm -n applies the NIC configuration specified in the 
 iBFT for each valid target.
 
 The primary benefit of this is that it allows the initrd to extract 
 networking 
 information from the iBFT rather than hard code it.  If the initrd uses the 
 iBFT 
 for networking info then when the setup is modified via the BIOS it is not 
 necessary to rebuild the initrd.
 

For offload with bnx2i and cxgb3i, this is going to be needed. Instead 
of the net ioctls, we have to pass this info down to the iscsi offload 
drivers using the iscsi interface.


For software iscsi with ibft, I think it will be useful too. I am just 
not sure if it might mess up other distro stuff. Have you evaluated 
them? Let's see if Hannes from SUSE or Hans from Red Hat have an opinion.

--

You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-is...@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.