[PATCH] iscsid: Add support for net_prio cgroups

2012-02-24 Thread Mark Rustad
When net_prio cgroups are in use, let the priority be controlled by that
mechanism, since it can handle changes dynamically, as opposed to the
current method used with DCB. Continue to use the current DCB method
when net_prio cgroups are not present.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |   36 +++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
index c31e2b8..0c509cc 100644
--- a/usr/dcb_app.c
+++ b/usr/dcb_app.c
@@ -1,7 +1,7 @@
 
/***
 
   DCB application support
-  Copyright(c) 2007-2011 Intel Corporation.
+  Copyright(c) 2007-2012 Intel Corporation.
 
   This program is free software; you can redistribute it and/or modify it
   under the terms and conditions of the GNU General Public License,
@@ -25,6 +25,8 @@
 
***/
 
 #include unistd.h
+#include stdbool.h
+#include stdio.h
 #include stdlib.h
 #include string.h
 #include errno.h
@@ -57,6 +59,9 @@
 /* Maximum size of response requested or message sent */
 #define MAX_MSG_SIZE1024
 
+#define CGROUPS_PATH   /proc/cgroups
+#define NET_PRIO_CGnet_prio
+
 static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
 {
struct nlmsghdr *nlh;
@@ -337,6 +342,32 @@ static int get_link_ifname(const char *ifname, char 
*link_ifname)
return 0;
 }
 
+static bool net_prio_cgroup(void)
+{
+   FILE*cgs;
+   charline[80];
+   static bool inited;
+   static bool result;
+
+   if (inited)
+   return result;
+   cgs = fopen(CGROUPS_PATH, r);
+   if (!cgs)
+   return false;
+
+   result = false;
+   while (fgets(line, sizeof(line), cgs)) {
+   if (strncmp(NET_PRIO_CG \t, line, sizeof(NET_PRIO_CG)))
+   continue;
+   result = true;
+   break;
+   }
+
+   inited = true;
+   fclose(cgs);
+   return result;
+}
+
 static int get_app_pri(const char *iface, __u8 req_idtype, __u16 req_id,
   __u8 ieee_mask)
 {
@@ -345,6 +376,9 @@ static int get_app_pri(const char *iface, __u8 req_idtype, 
__u16 req_id,
int nl_sd;
char ifname[IFNAMSIZ];
 
+   if (net_prio_cgroup())
+   return 0;
+
if (get_link_ifname(iface, ifname))
return 0;
 

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH] iscsid: Add IEEE DCB support

2011-06-21 Thread Mark Rustad
Add IEEE DCB support. This still has the same limitations as the existing
DCB support, in that it cannot dynamically track priority changes if the
configuration, or even the routing, changes over time, but it provides
equivalent support for systems running with 802.1Qaz as the current DCB
support in iscsid. This should still support CEE when run on kernels that
do not support IEEE.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |  201 +++--
 usr/dcb_app.h |   17 +++--
 usr/dcbnl.h   |  110 ++-
 usr/io.c  |2 -
 4 files changed, 287 insertions(+), 43 deletions(-)

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
index 0131b09..78a5cd1 100644
--- a/usr/dcb_app.c
+++ b/usr/dcb_app.c
@@ -1,7 +1,7 @@
 
/***
 
   DCB application support
-  Copyright(c) 2007-2010 Intel Corporation.
+  Copyright(c) 2007-2011 Intel Corporation.
 
   This program is free software; you can redistribute it and/or modify it
   under the terms and conditions of the GNU General Public License,
@@ -20,8 +20,7 @@
   the file called COPYING.
 
   Contact Information:
-  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
-  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+  open-lldp Mailing List lldp-de...@open-lldp.org
 
 
***/
 
@@ -39,7 +38,13 @@
 #include dcb_app.h
 #include sysfs.h
 
-#define NLA_DATA(nla)((void *)((char*)(nla) + NLA_HDRLEN))
+#define IEEE_SMASK_ETHTYPE (1  IEEE_8021QAZ_APP_SEL_ETHERTYPE)
+#define IEEE_SMASK_STREAM  (1  IEEE_8021QAZ_APP_SEL_STREAM)
+#define IEEE_SMASK_DGRAM   (1  IEEE_8021QAZ_APP_SEL_DGRAM)
+#define IEEE_SMASK_ANY (1  IEEE_8021QAZ_APP_SEL_ANY)
+
+#define NLA_DATA(nla)((void *)((char *)(nla) + NLA_HDRLEN))
+#define NLA_NEXT(nla) (struct rtattr *)((char *)nla + 
NLMSG_ALIGN(nla-rta_len))
 
 /* Maximum size of response requested or message sent */
 #define MAX_MSG_SIZE1024
@@ -72,7 +77,7 @@ static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
 }
 
 static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
-  void *attr, __u16 rta_len)
+ void *attr, __u16 rta_len)
 {
struct rtattr *rta;
 
@@ -127,14 +132,49 @@ static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
return nlh;
 }
 
-static int get_app_cfg(const char *ifname, __u8 req_idtype, __u16 req_id)
+static int get_dcbx_cap(int nl_sd, const char *ifname)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+   struct rtattr *rta;
+   int rval;
+
+   nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GDCBX);
+   if (!nlh)
+   return -EIO;
+
+   add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+   rval = dcbnl_send_msg(nl_sd, nlh);
+   free(nlh);
+   if (rval)
+   return -EIO;
+
+   /* Receive DCBX capabilities */
+   nlh = dcbnl_get_msg(nl_sd);
+   if (!nlh)
+   return -EIO;
+
+   d = (struct dcbmsg *)NLMSG_DATA(nlh);
+   rta = (struct rtattr *)(((char *)d) +
+   NLMSG_ALIGN(sizeof(struct dcbmsg)));
+
+   if (d-cmd != DCB_CMD_GDCBX || rta-rta_type != DCB_ATTR_DCBX) {
+   free(nlh);
+   return -EIO;
+   }
+
+   rval = *(__u8 *)NLA_DATA(rta);
+   free(nlh);
+   return rval;
+}
+
+static int get_cee_app_pri(int nl_sd, const char *ifname,
+  __u8 req_idtype, __u16 req_id)
 {
struct nlmsghdr *nlh;
struct dcbmsg *d;
struct rtattr *rta_parent, *rta_child;
int rval = 0;
-   int nl_sd;
-   unsigned int seq;
__u8 idtype;
__u16 id;
 
@@ -142,7 +182,6 @@ static int get_app_cfg(const char *ifname, __u8 req_idtype, 
__u16 req_id)
if (!nlh)
return -EIO;
 
-   seq = nlh-nlmsg_seq;
add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
 
@@ -154,19 +193,12 @@ static int get_app_cfg(const char *ifname, __u8 
req_idtype, __u16 req_id)
(void *)req_id, sizeof(__u16));
rta_parent-rta_len += NLA_ALIGN(rta_child-rta_len);
 
-   nl_sd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-   if (nl_sd  0)
-   return nl_sd;
-
rval = dcbnl_send_msg(nl_sd, nlh);
free(nlh);
-   if (rval) {
-   close(nl_sd);
+   if (rval)
return -EIO;
-   }
 
nlh = dcbnl_get_msg(nl_sd);
-   close(nl_sd);
if (!nlh)
return -EIO;
 
@@ -184,28 +216,100 @@ static int get_app_cfg(const char *ifname, __u8 
req_idtype, __u16 req_id)
}
 
rta_child = NLA_DATA(rta_parent);
-   rta_parent = (struct rtattr

[PATCH V2] iscsid: Add IEEE DCB support

2011-06-21 Thread Mark Rustad
Add IEEE DCB support. This still has the same limitations as the existing
DCB support, in that it cannot dynamically track priority changes if the
configuration, or even the routing, changes over time, but it provides
equivalent support for systems running with 802.1Qaz as the current DCB
support in iscsid. This should still support CEE when run on kernels that
do not support IEEE.

v2: Add omitted Tested-by credit.

Tested-by: Ross Brattain ross.b.bratt...@intel.com
Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |  201 +++--
 usr/dcb_app.h |   17 +++--
 usr/dcbnl.h   |  110 ++-
 usr/io.c  |2 -
 4 files changed, 287 insertions(+), 43 deletions(-)

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
index 0131b09..78a5cd1 100644
--- a/usr/dcb_app.c
+++ b/usr/dcb_app.c
@@ -1,7 +1,7 @@
 
/***
 
   DCB application support
-  Copyright(c) 2007-2010 Intel Corporation.
+  Copyright(c) 2007-2011 Intel Corporation.
 
   This program is free software; you can redistribute it and/or modify it
   under the terms and conditions of the GNU General Public License,
@@ -20,8 +20,7 @@
   the file called COPYING.
 
   Contact Information:
-  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
-  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+  open-lldp Mailing List lldp-de...@open-lldp.org
 
 
***/
 
@@ -39,7 +38,13 @@
 #include dcb_app.h
 #include sysfs.h
 
-#define NLA_DATA(nla)((void *)((char*)(nla) + NLA_HDRLEN))
+#define IEEE_SMASK_ETHTYPE (1  IEEE_8021QAZ_APP_SEL_ETHERTYPE)
+#define IEEE_SMASK_STREAM  (1  IEEE_8021QAZ_APP_SEL_STREAM)
+#define IEEE_SMASK_DGRAM   (1  IEEE_8021QAZ_APP_SEL_DGRAM)
+#define IEEE_SMASK_ANY (1  IEEE_8021QAZ_APP_SEL_ANY)
+
+#define NLA_DATA(nla)((void *)((char *)(nla) + NLA_HDRLEN))
+#define NLA_NEXT(nla) (struct rtattr *)((char *)nla + 
NLMSG_ALIGN(nla-rta_len))
 
 /* Maximum size of response requested or message sent */
 #define MAX_MSG_SIZE1024
@@ -72,7 +77,7 @@ static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
 }
 
 static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
-  void *attr, __u16 rta_len)
+ void *attr, __u16 rta_len)
 {
struct rtattr *rta;
 
@@ -127,14 +132,49 @@ static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
return nlh;
 }
 
-static int get_app_cfg(const char *ifname, __u8 req_idtype, __u16 req_id)
+static int get_dcbx_cap(int nl_sd, const char *ifname)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+   struct rtattr *rta;
+   int rval;
+
+   nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GDCBX);
+   if (!nlh)
+   return -EIO;
+
+   add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+   rval = dcbnl_send_msg(nl_sd, nlh);
+   free(nlh);
+   if (rval)
+   return -EIO;
+
+   /* Receive DCBX capabilities */
+   nlh = dcbnl_get_msg(nl_sd);
+   if (!nlh)
+   return -EIO;
+
+   d = (struct dcbmsg *)NLMSG_DATA(nlh);
+   rta = (struct rtattr *)(((char *)d) +
+   NLMSG_ALIGN(sizeof(struct dcbmsg)));
+
+   if (d-cmd != DCB_CMD_GDCBX || rta-rta_type != DCB_ATTR_DCBX) {
+   free(nlh);
+   return -EIO;
+   }
+
+   rval = *(__u8 *)NLA_DATA(rta);
+   free(nlh);
+   return rval;
+}
+
+static int get_cee_app_pri(int nl_sd, const char *ifname,
+  __u8 req_idtype, __u16 req_id)
 {
struct nlmsghdr *nlh;
struct dcbmsg *d;
struct rtattr *rta_parent, *rta_child;
int rval = 0;
-   int nl_sd;
-   unsigned int seq;
__u8 idtype;
__u16 id;
 
@@ -142,7 +182,6 @@ static int get_app_cfg(const char *ifname, __u8 req_idtype, 
__u16 req_id)
if (!nlh)
return -EIO;
 
-   seq = nlh-nlmsg_seq;
add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
 
@@ -154,19 +193,12 @@ static int get_app_cfg(const char *ifname, __u8 
req_idtype, __u16 req_id)
(void *)req_id, sizeof(__u16));
rta_parent-rta_len += NLA_ALIGN(rta_child-rta_len);
 
-   nl_sd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-   if (nl_sd  0)
-   return nl_sd;
-
rval = dcbnl_send_msg(nl_sd, nlh);
free(nlh);
-   if (rval) {
-   close(nl_sd);
+   if (rval)
return -EIO;
-   }
 
nlh = dcbnl_get_msg(nl_sd);
-   close(nl_sd);
if (!nlh)
return -EIO;
 
@@ -184,28 +216,100 @@ static int get_app_cfg(const char *ifname, __u8 
req_idtype, __u16 req_id

[PATCH] Remove redundant initialization

2011-04-07 Thread Mark Rustad
The variable len in iscsi_io_tcp_poll is initialized in its declaration, but
also initialized before use. Remove the initialization in the declaration.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
Tested-by: Ross Brattain ross.b.bratt...@intel.com
---
 usr/io.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/usr/io.c b/usr/io.c
index 0c52a39..aa81941 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -436,7 +436,7 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, int timeout_ms)
struct pollfd pdesc;
char serv[NI_MAXSERV], lserv[NI_MAXSERV];
struct sockaddr_storage ss;
-   socklen_t len = sizeof(ss);
+   socklen_t len;
 
pdesc.fd = conn-socket_fd;
pdesc.events = POLLOUT;

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH] iscsi: Simplify serial number comparisons

2011-04-07 Thread Mark Rustad
Unsigned serial number comparison is very simple if you simply put the
difference into a signed integer of the same size and then compare that
value with zero. All the complexity and confusion fall away.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 include/scsi/iscsi_proto.h |   21 -
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
index 0c6c1d6..98ebc3d 100644
--- a/include/scsi/iscsi_proto.h
+++ b/include/scsi/iscsi_proto.h
@@ -35,30 +35,33 @@
 /*
  * Serial Number Arithmetic, 32 bits, RFC1982
  */
-#define SNA32_CHECK 2147483648UL
 
 static inline int iscsi_sna_lt(u32 n1, u32 n2)
 {
-   return n1 != n2  ((n1  n2  (n2 - n1  SNA32_CHECK)) ||
-   (n1  n2  (n2 - n1  SNA32_CHECK)));
+   s32 diff = n1 - n2;
+
+   return diff  0;
 }
 
 static inline int iscsi_sna_lte(u32 n1, u32 n2)
 {
-   return n1 == n2 || ((n1  n2  (n2 - n1  SNA32_CHECK)) ||
-   (n1  n2  (n2 - n1  SNA32_CHECK)));
+   s32 diff = n1 - n2;
+
+   return diff = 0;
 }
 
 static inline int iscsi_sna_gt(u32 n1, u32 n2)
 {
-   return n1 != n2  (((n1  n2)  ((n2 - n1)  SNA32_CHECK)) ||
-   ((n1  n2)  ((n1 - n2)  SNA32_CHECK)));
+   s32 diff = n1 - n2;
+
+   return diff  0;
 }
 
 static inline int iscsi_sna_gte(u32 n1, u32 n2)
 {
-   return n1 == n2 || (((n1  n2)  ((n2 - n1)  SNA32_CHECK)) ||
-   ((n1  n2)  ((n1 - n2)  SNA32_CHECK)));
+   s32 diff = n1 - n2;
+
+   return diff = 0;
 }
 
 /*

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[Fcoe-patches,open-iscsi] Remove redundant initialization

2011-04-06 Thread Mark Rustad
The variable len in iscsi_io_tcp_poll is initialized in its declaration, but
also initialized before use. Remove the initialization in the declaration.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
Tested-by: Ross Brattain ross.b.bratt...@intel.com

---
usr/io.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/usr/io.c b/usr/io.c
index 28d9168..e638dbd 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -433,7 +433,7 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, int timeout_ms)
struct pollfd pdesc;
char serv[NI_MAXSERV], lserv[NI_MAXSERV];
struct sockaddr_storage ss;
-   socklen_t len = sizeof(ss);
+   socklen_t len;
 
pdesc.fd = conn-socket_fd;
pdesc.events = POLLOUT;

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH] iscsid: Fix netdev check

2011-03-31 Thread Mark Rustad
A check for a bound session omitted the subscript for the first byte of
the array, forcing the check to always be true. This means that in the
case of a session not bound to an interface, the ss structure will not
be filled-in if the logging level is set to 0. This will prevent the
DCB priority from being set.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
Tested-by: Ross Brattain ross.b.bratt...@intel.com
---
 usr/io.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/usr/io.c b/usr/io.c
index 7d366c7..28d9168 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -470,7 +470,7 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, int timeout_ms)
}
 
len = sizeof(ss);
-   if (log_level  0 || !conn-session-netdev)
+   if (log_level  0 || !conn-session-netdev[0])
rc = getsockname(conn-socket_fd, (struct sockaddr *)ss, len);
if (log_level  0  rc = 0) {
getnameinfo((struct sockaddr *) conn-saddr,

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH] iscsid: Fix netdev check

2011-03-31 Thread Mark Rustad
A check for a bound session omitted the subscript for the first byte of
the array, forcing the check to always be true. This means that in the
case of a session not bound to an interface, the ss structure will not
be filled-in if the logging level is set to 0. This will prevent the
DCB priority from being set.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
Tested-by: Ross Brattain ross.b.bratt...@intel.com
---
 usr/io.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/usr/io.c b/usr/io.c
index 7d366c7..28d9168 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -470,7 +470,7 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, int timeout_ms)
}
 
len = sizeof(ss);
-   if (log_level  0 || !conn-session-netdev)
+   if (log_level  0 || !conn-session-netdev[0])
rc = getsockname(conn-socket_fd, (struct sockaddr *)ss, len);
if (log_level  0  rc = 0) {
getnameinfo((struct sockaddr *) conn-saddr,

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[v3 PATCH 0/4] Add initial DCB support

2011-02-02 Thread Mark Rustad
This patch series adds initial DCB support to open-iscsi. In this
implementation, the application priority mask is fetched from the
kernel at session connect time and the highest priority in the mask
is chosen and set as a socket priority. Established session will
not have their priorities changed dynamically if the DCB application
mask changes over time unless the connection is reestablished. This
patch series also does nothing to add DCB support for iSNS.

Changes in v3:
Merged to latest git tree
Added some consts to quiet warnings
Added a union to quiet warnings
Removed a log_debug left over from testing
Check the return on setsockopt and warn if it fails
Added socket number to debug message
Consistently return negative error code from get_link_ifname

---

Mark Rustad (4):
  Add some consts to char * parameters that are not changed
  Add dcb_app.h for DCB support
  Add dcb_app.c for DCB support
  Add initial DCB support


 usr/Makefile  |4 +
 usr/dcb_app.c |  246 +
 usr/dcb_app.h |   34 
 usr/io.c  |  120 +++-
 usr/sysfs.c   |4 -
 usr/sysfs.h   |4 -
 6 files changed, 405 insertions(+), 7 deletions(-)
 create mode 100644 usr/dcb_app.c
 create mode 100644 usr/dcb_app.h

-- 
Signature

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[v3 PATCH 1/4] Add some consts to char * parameters that are not changed

2011-02-02 Thread Mark Rustad
Add const to some char * parameters that are not changed by the called
routine.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/sysfs.c |4 ++--
 usr/sysfs.h |4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/usr/sysfs.c b/usr/sysfs.c
index 8c176f0..cb9cf08 100644
--- a/usr/sysfs.c
+++ b/usr/sysfs.c
@@ -547,7 +547,7 @@ found:
 }
 
 
-char *sysfs_get_value(char *id, char *subsys, char *param)
+char *sysfs_get_value(const char *id, char *subsys, char *param)
 {
char devpath[PATH_SIZE];
char *sysfs_value;
@@ -590,7 +590,7 @@ int sysfs_get_uint(char *id, char *subsys, char *param,
return 0;
 }
 
-int sysfs_get_int(char *id, char *subsys, char *param, int *value)
+int sysfs_get_int(const char *id, char *subsys, char *param, int *value)
 {
char *sysfs_value;
 
diff --git a/usr/sysfs.h b/usr/sysfs.h
index 4c70dbd..f5e13b3 100644
--- a/usr/sysfs.h
+++ b/usr/sysfs.h
@@ -51,10 +51,10 @@ extern char *sysfs_attr_get_value(const char *devpath, 
const char *attr_name);
 extern int sysfs_resolve_link(char *path, size_t size);
 extern int sysfs_lookup_devpath_by_subsys_id(char *devpath, size_t len, const 
char *subsystem, const char *id);
 
-extern char *sysfs_get_value(char *id, char *subsys, char *param);
+extern char *sysfs_get_value(const char *id, char *subsys, char *param);
 extern int sysfs_get_uint(char *id, char *subsys, char *param,
  unsigned int *value);
-extern int sysfs_get_int(char *id, char *subsys, char *param, int *value);
+extern int sysfs_get_int(const char *id, char *subsys, char *param, int 
*value);
 extern int sysfs_get_str(char *id, char *subsys, char *param, char *value,
 int value_size);
 extern int sysfs_get_uint64(char *id, char *subsys, char *param,

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[v3 PATCH 3/4] Add dcb_app.c for DCB support

2011-02-02 Thread Mark Rustad
Add functions to obtain application priority mask from DCB in the kernel.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |  246 +
 1 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 usr/dcb_app.c

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
new file mode 100644
index 000..f5c9709
--- /dev/null
+++ b/usr/dcb_app.c
@@ -0,0 +1,246 @@
+/***
+
+  DCB application support
+  Copyright(c) 2007-2010 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called COPYING.
+
+  Contact Information:
+  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
+  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+
+***/
+
+#include unistd.h
+#include stdlib.h
+#include string.h
+#include errno.h
+#include asm/errno.h
+#include fcntl.h
+#include sys/socket.h
+#include net/if.h
+#include linux/netlink.h
+#include linux/rtnetlink.h
+#include linux/dcbnl.h
+#include dcb_app.h
+#include sysfs.h
+
+#define NLA_DATA(nla)((void *)((char*)(nla) + NLA_HDRLEN))
+
+/* Maximum size of response requested or message sent */
+#define MAX_MSG_SIZE1024
+
+static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+   nlh-nlmsg_type = msg_type;
+   nlh-nlmsg_flags = NLM_F_REQUEST;
+   nlh-nlmsg_seq = 0;
+   nlh-nlmsg_pid = getpid();
+   if (msg_type != RTM_GETDCB) {
+   free(nlh);
+   return NULL;
+   }
+
+   nlh-nlmsg_len = NLMSG_LENGTH(sizeof(struct dcbmsg));
+   d = NLMSG_DATA(nlh);
+   d-cmd = arg;
+   d-dcb_family = AF_UNSPEC;
+   d-dcb_pad = 0;
+
+   return nlh;
+}
+
+static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
+  void *attr, __u16 rta_len)
+{
+   struct rtattr *rta;
+
+   rta = (struct rtattr *)((char *)nlh + nlh-nlmsg_len);
+   rta-rta_type = rta_type;
+   rta-rta_len = rta_len + NLA_HDRLEN;
+   if (attr)
+   memcpy(NLA_DATA(rta), attr, rta_len);
+   nlh-nlmsg_len += NLMSG_ALIGN(rta-rta_len);
+
+   return rta;
+}
+
+static int dcbnl_send_msg(int nl_sd, struct nlmsghdr *nlh)
+{
+   struct sockaddr_nl nladdr;
+   void *buf = nlh;
+   int r, len = nlh-nlmsg_len;
+
+   memset(nladdr, 0, sizeof(nladdr));
+   nladdr.nl_family = AF_NETLINK;
+   
+   do {
+   r = sendto(nl_sd, buf, len, 0, (struct sockaddr *)nladdr,
+   sizeof(nladdr));
+   } while (r  0  errno == EINTR);
+
+   if (r  0)
+   return 1;
+
+   return 0;
+}
+
+static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
+{
+   struct nlmsghdr *nlh;
+   int len;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+
+   len = recv(nl_sd, (void *)nlh, MAX_MSG_SIZE, 0);
+
+   if (len  0 || nlh-nlmsg_type == NLMSG_ERROR ||
+   !NLMSG_OK(nlh, (unsigned int)len)) {
+   free(nlh);
+   return NULL;
+   }
+
+   return nlh;
+}
+
+static int get_app_cfg(const char *ifname, __u8 req_idtype, __u16 req_id)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+   struct rtattr *rta_parent, *rta_child;
+   int rval = 0;
+   int nl_sd;
+   unsigned int seq;
+   __u8 idtype;
+   __u16 id;
+
+   nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GAPP);
+   if (!nlh)
+   return -EIO;
+
+   seq = nlh-nlmsg_seq;
+   add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+   rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_IDTYPE, 
+   (void *)req_idtype, sizeof(__u8));
+   rta_parent-rta_len += NLA_ALIGN(rta_child-rta_len);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_ID, 
+   (void *)req_id, sizeof(__u16));
+   rta_parent-rta_len

[v3 PATCH 4/4] Add initial DCB support

2011-02-02 Thread Mark Rustad
Add support for setting priorities provided by DCB in the kernel. This
implementation does not track any priority changes which could occur
over time.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/Makefile |4 +-
 usr/io.c |  120 +-
 2 files changed, 121 insertions(+), 3 deletions(-)

diff --git a/usr/Makefile b/usr/Makefile
index e2e517b..3ee0cb4 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -21,10 +21,12 @@ ifeq ($(OSNAME),Linux)
endif
endif
 IPC_OBJ=netlink.o
+DCB_OBJ=dcb_app.o
 else
 ifeq ($(OSNAME),FreeBSD)
 IPC_CFLAGS=
 IPC_OBJ=ioctl.o
+DCB_OBJ=
 endif
 endif
 
@@ -40,7 +42,7 @@ SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
 ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
iscsi_net_util.o iscsid_req.o transport.o cxgbi.o be2iscsi.o \
-   initiator_common.o iscsi_err.o $(IPC_OBJ)  $(SYSDEPS_SRCS)
+   initiator_common.o iscsi_err.o $(IPC_OBJ)  $(SYSDEPS_SRCS) $(DCB_OBJ)
 # core initiator files
 INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o
 
diff --git a/usr/io.c b/usr/io.c
index cf21088..317c502 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -26,11 +26,14 @@
 #include fcntl.h
 #include sys/poll.h
 #include sys/ioctl.h
+#include sys/types.h
+#include ifaddrs.h
 #include netinet/tcp.h
 #include arpa/inet.h
 
 #include types.h
 #include iscsi_proto.h
+#include iscsi_settings.h
 #include initiator.h
 #include iscsi_ipc.h
 #include log.h
@@ -38,6 +41,7 @@
 #include idbm.h
 #include iface.h
 #include sysdeps.h
+#include dcb_app.h
 
 #define LOG_CONN_CLOSED(conn) \
 do { \
@@ -53,6 +57,13 @@ do { \
log_error(Connection to Discovery Address %s failed, conn-host); \
 } while (0)
 
+union sockaddr_u {
+   struct sockaddr_storage ss;
+   struct sockaddr sa;
+   struct sockaddr_in si;
+   struct sockaddr_in6 si6;
+};
+
 static int timedout;
 
 static void
@@ -76,6 +87,90 @@ set_non_blocking(int fd)
 
 }
 
+static int select_priority(struct iscsi_conn *conn, int pri_mask)
+{
+   int msk;
+
+   if (!pri_mask)
+   return 0;
+
+   /*
+* TODO: Configure priority selection from the mask
+* For now, just always take the highest
+*/
+
+   /* Find highest bit set */
+   while ((msk = pri_mask  (pri_mask - 1)))
+   pri_mask = msk;
+
+   return ffs(pri_mask) - 1;
+}
+
+static int
+inet_cmp_addr(const union sockaddr_u *s1, const union sockaddr_u *s2)
+{
+   const struct sockaddr_in *si1 = s1-si;
+   const struct sockaddr_in *si2 = s2-si;
+
+   return si1-sin_addr.s_addr != si2-sin_addr.s_addr;
+}
+
+static int
+inet6_cmp_addr(const union sockaddr_u *s1, const union sockaddr_u *s2)
+{
+   const struct sockaddr_in6 *si1 = s1-si6;
+   const struct sockaddr_in6 *si2 = s2-si6;
+
+   return memcmp(si1-sin6_addr, si2-sin6_addr, sizeof(si1-sin6_addr));
+}
+
+static char *
+find_ifname(const struct ifaddrs *ifa, const union sockaddr_u *ss)
+{
+   for (; ifa; ifa = ifa-ifa_next) {
+   if (ss-ss.ss_family != ifa-ifa_addr-sa_family)
+   continue;
+   switch (ss-ss.ss_family) {
+   case AF_INET:
+   if (inet_cmp_addr(ss, (union sockaddr_u 
*)ifa-ifa_addr) == 0)
+   return ifa-ifa_name;
+   break;
+   case AF_INET6:
+   if (inet6_cmp_addr(ss, (union sockaddr_u 
*)ifa-ifa_addr) == 0)
+   return ifa-ifa_name;
+   break;
+   }
+   }
+
+   return NULL;
+}
+
+static void set_dcb_priority(struct iscsi_conn *conn, const char *devname)
+{
+   int pri_mask = 0;
+
+   pri_mask = get_dcb_app_pri_by_port(devname, ISCSI_DEFAULT_PORT);
+   if (pri_mask  0)
+   log_debug(2, Getting priority for %s returned %d,
+   devname, pri_mask);
+   else if (pri_mask == 0)
+   log_debug(2, No priority for %s, devname);
+   else {
+   int pri = select_priority(conn, pri_mask);
+   int rc;
+
+   log_debug(1, Setting socket %d priority to %d,
+   conn-socket_fd, pri);
+   rc = setsockopt(conn-socket_fd, SOL_SOCKET,
+   SO_PRIORITY, pri, sizeof(pri));
+   if (rc  0) {
+   log_warning(Setting socket %d priority to %d failed 
+   with errno %d, conn-socket_fd,
+   pri, errno);
+   }
+   }
+}
+
 #if 0
 /* not used by anyone */
 static int get_hwaddress_from_netdev(char *netdev, char *hwaddress)
@@ -320,6 +415,10 @@ iscsi_io_tcp_connect(iscsi_conn_t *conn, int non_blocking)
log_debug(1, connecting

[v2 PATCH 0/3] Add DCB support

2011-02-01 Thread Mark Rustad
This patch series adds initial DCB support to open-iscsi. In this
implementation, the application priority mask is fetched from the
kernel at session connect time and the highest priority in the mask
is chosen and set as a socket priority. Established session will
not have their priorities changed dynamically if the DCB application
mask changes over time unless the connection is reestablished. This
patch series also does nothing to add DCB support for iSNS.

Changes in v2:
Removed #ifdef Linux
Use struct iscsi_conn instead of iscsi_conn_t
Added support for connections not bound to a specific netdev

---

Mark Rustad (3):
  Add dcb_app.h for DCB support
  Add dcb_app.c for DCB support
  Add initial DCB support


 usr/Makefile  |4 +
 usr/dcb_app.c |  246 +
 usr/dcb_app.h |   34 
 usr/io.c  |  104 
 4 files changed, 385 insertions(+), 3 deletions(-)
 create mode 100644 usr/dcb_app.c
 create mode 100644 usr/dcb_app.h

-- 
Signature

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH 2/3] Add dcb_app.c for DCB support

2011-02-01 Thread Mark Rustad
Add functions to obtain application priority mask from DCB in the kernel.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |  246 +
 1 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 usr/dcb_app.c

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
new file mode 100644
index 000..f8b9f9f
--- /dev/null
+++ b/usr/dcb_app.c
@@ -0,0 +1,246 @@
+/***
+
+  DCB application support
+  Copyright(c) 2007-2010 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called COPYING.
+
+  Contact Information:
+  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
+  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+
+***/
+
+#include unistd.h
+#include stdlib.h
+#include string.h
+#include errno.h
+#include asm/errno.h
+#include fcntl.h
+#include sys/socket.h
+#include net/if.h
+#include linux/netlink.h
+#include linux/rtnetlink.h
+#include linux/dcbnl.h
+#include dcb_app.h
+#include sysfs.h
+
+#define NLA_DATA(nla)((void *)((char*)(nla) + NLA_HDRLEN))
+
+/* Maximum size of response requested or message sent */
+#define MAX_MSG_SIZE1024
+
+static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+   nlh-nlmsg_type = msg_type;
+   nlh-nlmsg_flags = NLM_F_REQUEST;
+   nlh-nlmsg_seq = 0;
+   nlh-nlmsg_pid = getpid();
+   if (msg_type != RTM_GETDCB) {
+   free(nlh);
+   return NULL;
+   }
+
+   nlh-nlmsg_len = NLMSG_LENGTH(sizeof(struct dcbmsg));
+   d = NLMSG_DATA(nlh);
+   d-cmd = arg;
+   d-dcb_family = AF_UNSPEC;
+   d-dcb_pad = 0;
+
+   return nlh;
+}
+
+static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
+  void *attr, __u16 rta_len)
+{
+   struct rtattr *rta;
+
+   rta = (struct rtattr *)((char *)nlh + nlh-nlmsg_len);
+   rta-rta_type = rta_type;
+   rta-rta_len = rta_len + NLA_HDRLEN;
+   if (attr)
+   memcpy(NLA_DATA(rta), attr, rta_len);
+   nlh-nlmsg_len += NLMSG_ALIGN(rta-rta_len);
+
+   return rta;
+}
+
+static int dcbnl_send_msg(int nl_sd, struct nlmsghdr *nlh)
+{
+   struct sockaddr_nl nladdr;
+   void *buf = nlh;
+   int r, len = nlh-nlmsg_len;
+
+   memset(nladdr, 0, sizeof(nladdr));
+   nladdr.nl_family = AF_NETLINK;
+   
+   do {
+   r = sendto(nl_sd, buf, len, 0, (struct sockaddr *)nladdr,
+   sizeof(nladdr));
+   } while (r  0  errno == EINTR);
+
+   if (r  0)
+   return 1;
+
+   return 0;
+}
+
+static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
+{
+   struct nlmsghdr *nlh;
+   int len;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+
+   len = recv(nl_sd, (void *)nlh, MAX_MSG_SIZE, 0);
+
+   if (len  0 || nlh-nlmsg_type == NLMSG_ERROR ||
+   !NLMSG_OK(nlh, (unsigned int)len)) {
+   free(nlh);
+   return NULL;
+   }
+
+   return nlh;
+}
+
+static int get_app_cfg(const char *ifname, __u8 req_idtype, __u16 req_id)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+   struct rtattr *rta_parent, *rta_child;
+   int rval = 0;
+   int nl_sd;
+   unsigned int seq;
+   __u8 idtype;
+   __u16 id;
+
+   nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GAPP);
+   if (!nlh)
+   return -EIO;
+
+   seq = nlh-nlmsg_seq;
+   add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+   rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_IDTYPE, 
+   (void *)req_idtype, sizeof(__u8));
+   rta_parent-rta_len += NLA_ALIGN(rta_child-rta_len);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_ID, 
+   (void *)req_id, sizeof(__u16));
+   rta_parent-rta_len

[PATCH 3/3] Add initial DCB support

2011-02-01 Thread Mark Rustad
Add support for setting priorities provided by DCB in the kernel. This
implementation does not track any priority changes which could occur
over time.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/Makefile |4 ++
 usr/io.c |  104 +-
 2 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/usr/Makefile b/usr/Makefile
index b02a706..991efd9 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -21,10 +21,12 @@ ifeq ($(OSNAME),Linux)
endif
endif
 IPC_OBJ=netlink.o
+DCB_OBJ=dcb_app.o
 else
 ifeq ($(OSNAME),FreeBSD)
 IPC_CFLAGS=
 IPC_OBJ=ioctl.o
+DCB_OBJ=
 endif
 endif
 
@@ -39,7 +41,7 @@ SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
 # sources shared between iscsid, iscsiadm and iscsistart
 ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o login.o log.o md5.o sha1.o iface.o \
idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o iscsi_net_util.o \
-   iscsid_req.o $(SYSDEPS_SRCS)
+   iscsid_req.o $(SYSDEPS_SRCS) $(DCB_OBJ)
 # core initiator files
 INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o \
transport.o cxgbi.o be2iscsi.o
diff --git a/usr/io.c b/usr/io.c
index 8fb806d..e9017a1 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -26,11 +26,14 @@
 #include fcntl.h
 #include sys/poll.h
 #include sys/ioctl.h
+#include sys/types.h
+#include ifaddrs.h
 #include netinet/tcp.h
 #include arpa/inet.h
 
 #include types.h
 #include iscsi_proto.h
+#include iscsi_settings.h
 #include initiator.h
 #include iscsi_ipc.h
 #include log.h
@@ -38,6 +41,7 @@
 #include idbm.h
 #include iface.h
 #include sysdeps.h
+#include dcb_app.h
 
 #define LOG_CONN_CLOSED(conn) \
 do { \
@@ -76,6 +80,80 @@ set_non_blocking(int fd)
 
 }
 
+static int select_priority(struct iscsi_conn *conn, int pri_mask)
+{
+   int msk;
+
+   if (!pri_mask)
+   return 0;
+
+   /*
+* TODO: Configure priority selection from the mask
+* For now, just always take the highest
+*/
+
+   /* Find highest bit set */
+   while ((msk = pri_mask  (pri_mask - 1)))
+   pri_mask = msk;
+
+   return ffs(pri_mask) - 1;
+}
+
+static int inet_cmp_addr(struct sockaddr *s1, struct sockaddr *s2)
+{
+   struct sockaddr_in *si1 = (struct sockaddr_in *)s1;
+   struct sockaddr_in *si2 = (struct sockaddr_in *)s2;
+
+   return si1-sin_addr.s_addr != si2-sin_addr.s_addr;
+}
+
+static int inet6_cmp_addr(struct sockaddr *s1, struct sockaddr *s2)
+{
+   struct sockaddr_in6 *si1 = (struct sockaddr_in6 *)s1;
+   struct sockaddr_in6 *si2 = (struct sockaddr_in6 *)s2;
+
+   return memcmp(si1-sin6_addr, si2-sin6_addr, sizeof(si1-sin6_addr));
+}
+
+static char *find_ifname(struct ifaddrs *ifa, struct sockaddr *sa)
+{
+   for (; ifa; ifa = ifa-ifa_next) {
+   if (sa-sa_family != ifa-ifa_addr-sa_family)
+   continue;
+   switch (sa-sa_family) {
+   case AF_INET:
+   if (inet_cmp_addr(sa, ifa-ifa_addr) == 0)
+   return ifa-ifa_name;
+   break;
+   case AF_INET6:
+   if (inet6_cmp_addr(sa, ifa-ifa_addr) == 0)
+   return ifa-ifa_name;
+   break;
+   }
+   }
+
+   return NULL;
+}
+
+static void set_dcb_priority(struct iscsi_conn *conn, const char *devname)
+{
+   int pri_mask = 0;
+
+   pri_mask = get_dcb_app_pri_by_port(devname, ISCSI_DEFAULT_PORT);
+   if (pri_mask  0)
+   log_debug(2, Getting priority for %s returned %d,
+   devname, pri_mask);
+   else if (pri_mask == 0)
+   log_debug(2, No priority for %s, devname);
+   else {
+   int pri = select_priority(conn, pri_mask);
+
+   log_debug(1, Setting socket priority to %d, pri);
+   setsockopt(conn-socket_fd, SOL_SOCKET,
+   SO_PRIORITY, pri, sizeof(pri));
+   }
+}
+
 #if 0
 /* not used by anyone */
 static int get_hwaddress_from_netdev(char *netdev, char *hwaddress)
@@ -320,6 +398,10 @@ iscsi_io_tcp_connect(iscsi_conn_t *conn, int non_blocking)
log_debug(1, connecting to %s:%s, conn-host, serv);
if (non_blocking)
set_non_blocking(conn-socket_fd);
+
+   if (conn-session-netdev[0])
+   set_dcb_priority(conn, conn-session-netdev);
+
rc = connect(conn-socket_fd, (struct sockaddr *) ss, sizeof (*ss));
return rc;
 }
@@ -368,8 +450,9 @@ iscsi_io_tcp_poll(iscsi_conn_t *conn, int timeout_ms)
}
 
len = sizeof(ss);
-   if (log_level  0 
-   getsockname(conn-socket_fd, (struct sockaddr *) ss, len) = 0) {
+   if (log_level  0 || !conn-session-netdev)
+   rc = getsockname(conn-socket_fd, (struct sockaddr *)ss, len);
+   if (log_level  0  rc = 0

[PATCH 1/3] Add dcb_app.h for DCB support

2011-02-01 Thread Mark Rustad
Add header file with prototypes for functions in dcb_app.c.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.h |   34 ++
 1 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 usr/dcb_app.h

diff --git a/usr/dcb_app.h b/usr/dcb_app.h
new file mode 100644
index 000..2e756f1
--- /dev/null
+++ b/usr/dcb_app.h
@@ -0,0 +1,34 @@
+/***
+
+  DCB application support
+  Copyright(c) 2007-2010 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called COPYING.
+
+  Contact Information:
+  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
+  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+
+***/
+
+#ifndef _DCB_APP_H_
+#define _DCB_APP_H_
+
+int get_dcb_app_pri_by_port(const char *iface, int port);
+int get_dcb_app_pri_by_ethtype(const char *iface, int ethtype);
+
+#endif  /* _DCB_APP_H_ */

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH 1/3] Add dcb_app.h for DCB support

2011-01-31 Thread Mark Rustad
Add header file with prototypes for functions in dcb_app.c.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.h |   34 ++
 1 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 usr/dcb_app.h

diff --git a/usr/dcb_app.h b/usr/dcb_app.h
new file mode 100644
index 000..2e756f1
--- /dev/null
+++ b/usr/dcb_app.h
@@ -0,0 +1,34 @@
+/***
+
+  DCB application support
+  Copyright(c) 2007-2010 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called COPYING.
+
+  Contact Information:
+  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
+  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+
+***/
+
+#ifndef _DCB_APP_H_
+#define _DCB_APP_H_
+
+int get_dcb_app_pri_by_port(const char *iface, int port);
+int get_dcb_app_pri_by_ethtype(const char *iface, int ethtype);
+
+#endif  /* _DCB_APP_H_ */

-- 
You received this message because you are subscribed to the Google Groups 
open-iscsi group.
To post to this group, send email to open-iscsi@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.



[PATCH 2/3] Add dcb_app.c for DCB support

2011-01-31 Thread Mark Rustad
Add functions to obtain application priority mask from DCB in the kernel.

Signed-off-by: Mark Rustad mark.d.rus...@intel.com
---
 usr/dcb_app.c |  246 +
 1 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 usr/dcb_app.c

diff --git a/usr/dcb_app.c b/usr/dcb_app.c
new file mode 100644
index 000..f8b9f9f
--- /dev/null
+++ b/usr/dcb_app.c
@@ -0,0 +1,246 @@
+/***
+
+  DCB application support
+  Copyright(c) 2007-2010 Intel Corporation.
+
+  This program is free software; you can redistribute it and/or modify it
+  under the terms and conditions of the GNU General Public License,
+  version 2, as published by the Free Software Foundation.
+
+  This program is distributed in the hope it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  this program; if not, write to the Free Software Foundation, Inc.,
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+  The full GNU General Public License is included in this distribution in
+  the file called COPYING.
+
+  Contact Information:
+  e1000-eedc Mailing List e1000-e...@lists.sourceforge.net
+  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+
+***/
+
+#include unistd.h
+#include stdlib.h
+#include string.h
+#include errno.h
+#include asm/errno.h
+#include fcntl.h
+#include sys/socket.h
+#include net/if.h
+#include linux/netlink.h
+#include linux/rtnetlink.h
+#include linux/dcbnl.h
+#include dcb_app.h
+#include sysfs.h
+
+#define NLA_DATA(nla)((void *)((char*)(nla) + NLA_HDRLEN))
+
+/* Maximum size of response requested or message sent */
+#define MAX_MSG_SIZE1024
+
+static struct nlmsghdr *start_dcbmsg(__u16 msg_type, __u8 arg)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+   nlh-nlmsg_type = msg_type;
+   nlh-nlmsg_flags = NLM_F_REQUEST;
+   nlh-nlmsg_seq = 0;
+   nlh-nlmsg_pid = getpid();
+   if (msg_type != RTM_GETDCB) {
+   free(nlh);
+   return NULL;
+   }
+
+   nlh-nlmsg_len = NLMSG_LENGTH(sizeof(struct dcbmsg));
+   d = NLMSG_DATA(nlh);
+   d-cmd = arg;
+   d-dcb_family = AF_UNSPEC;
+   d-dcb_pad = 0;
+
+   return nlh;
+}
+
+static struct rtattr *add_rta(struct nlmsghdr *nlh, __u16 rta_type,
+  void *attr, __u16 rta_len)
+{
+   struct rtattr *rta;
+
+   rta = (struct rtattr *)((char *)nlh + nlh-nlmsg_len);
+   rta-rta_type = rta_type;
+   rta-rta_len = rta_len + NLA_HDRLEN;
+   if (attr)
+   memcpy(NLA_DATA(rta), attr, rta_len);
+   nlh-nlmsg_len += NLMSG_ALIGN(rta-rta_len);
+
+   return rta;
+}
+
+static int dcbnl_send_msg(int nl_sd, struct nlmsghdr *nlh)
+{
+   struct sockaddr_nl nladdr;
+   void *buf = nlh;
+   int r, len = nlh-nlmsg_len;
+
+   memset(nladdr, 0, sizeof(nladdr));
+   nladdr.nl_family = AF_NETLINK;
+   
+   do {
+   r = sendto(nl_sd, buf, len, 0, (struct sockaddr *)nladdr,
+   sizeof(nladdr));
+   } while (r  0  errno == EINTR);
+
+   if (r  0)
+   return 1;
+
+   return 0;
+}
+
+static struct nlmsghdr *dcbnl_get_msg(int nl_sd)
+{
+   struct nlmsghdr *nlh;
+   int len;
+
+   nlh = malloc(MAX_MSG_SIZE);
+   if (!nlh)
+   return NULL;
+   memset(nlh, 0, MAX_MSG_SIZE);
+
+   len = recv(nl_sd, (void *)nlh, MAX_MSG_SIZE, 0);
+
+   if (len  0 || nlh-nlmsg_type == NLMSG_ERROR ||
+   !NLMSG_OK(nlh, (unsigned int)len)) {
+   free(nlh);
+   return NULL;
+   }
+
+   return nlh;
+}
+
+static int get_app_cfg(const char *ifname, __u8 req_idtype, __u16 req_id)
+{
+   struct nlmsghdr *nlh;
+   struct dcbmsg *d;
+   struct rtattr *rta_parent, *rta_child;
+   int rval = 0;
+   int nl_sd;
+   unsigned int seq;
+   __u8 idtype;
+   __u16 id;
+
+   nlh = start_dcbmsg(RTM_GETDCB, DCB_CMD_GAPP);
+   if (!nlh)
+   return -EIO;
+
+   seq = nlh-nlmsg_seq;
+   add_rta(nlh, DCB_ATTR_IFNAME, (void *)ifname, strlen(ifname) + 1);
+   rta_parent = add_rta(nlh, DCB_ATTR_APP, NULL, 0);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_IDTYPE, 
+   (void *)req_idtype, sizeof(__u8));
+   rta_parent-rta_len += NLA_ALIGN(rta_child-rta_len);
+
+   rta_child = add_rta(nlh, DCB_APP_ATTR_ID, 
+   (void *)req_id, sizeof(__u16));
+   rta_parent-rta_len