Blame SOURCES/0046-iscsi-tools-Use-single-function-to-enable-disable-ne.patch

786c6d
From 2220ee4334637946e93dca5c68889b5e3e807515 Mon Sep 17 00:00:00 2001
786c6d
From: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
786c6d
Date: Fri, 18 Oct 2013 09:29:21 -0400
786c6d
Subject: [PATCH] iscsi tools: Use single function to enable/disable network
786c6d
 parameters
786c6d
786c6d
Signed-off-by: Harish Zunjarrao <harish.zunjarrao@qlogic.com>
786c6d
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
786c6d
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
786c6d
---
786c6d
 usr/iface.c | 148 ++++++++++++++++++++++++++++++------------------------------
786c6d
 1 file changed, 74 insertions(+), 74 deletions(-)
786c6d
786c6d
diff --git a/usr/iface.c b/usr/iface.c
786c6d
index 19ad5ab..292c804 100644
786c6d
--- a/usr/iface.c
786c6d
+++ b/usr/iface.c
786c6d
@@ -1311,60 +1311,45 @@ static int iface_fill_vlan_id(struct iovec *iov, struct iface_rec *iface,
786c6d
 	return 0;
786c6d
 }
786c6d
 
786c6d
-/* IPv4/IPv6 VLAN state: disable/enable */
786c6d
-static int iface_fill_vlan_state(struct iovec *iov, struct iface_rec *iface,
786c6d
-				 uint32_t iface_type)
786c6d
+/* disable/enable parameters */
786c6d
+static int iface_fill_param_state(struct iovec *iov, uint32_t iface_num,
786c6d
+				  uint8_t iface_type, uint16_t param,
786c6d
+				  uint8_t param_type, char *param_val)
786c6d
 {
786c6d
 	int len;
786c6d
 	struct iscsi_iface_param_info *net_param;
786c6d
 	struct nlattr *attr;
786c6d
 
786c6d
+	if (!param_val[0])
786c6d
+		return 1;
786c6d
+
786c6d
 	len = sizeof(struct iscsi_iface_param_info) + 1;
786c6d
-	iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_VLAN_ENABLED, len);
786c6d
+	iov->iov_base = iscsi_nla_alloc(param, len);
786c6d
 	if (!(iov->iov_base))
786c6d
 		return 1;
786c6d
 
786c6d
 	attr = iov->iov_base;
786c6d
 	iov->iov_len = NLA_ALIGN(attr->nla_len);
786c6d
 	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
786c6d
-	net_param->param = ISCSI_NET_PARAM_VLAN_ENABLED;
786c6d
-	net_param->iface_type = iface_type;
786c6d
-	net_param->iface_num = iface->iface_num;
786c6d
-	net_param->param_type = ISCSI_NET_PARAM;
786c6d
+	net_param->iface_num = iface_num;
786c6d
 	net_param->len = 1;
786c6d
-	if (strcmp(iface->vlan_state, "disable") && iface->vlan_id)
786c6d
-		net_param->value[0] = ISCSI_VLAN_ENABLE;
786c6d
+	net_param->param = param;
786c6d
+	net_param->iface_type = iface_type;
786c6d
+	net_param->param_type = param_type;
786c6d
+	if (strcmp(param_val, "disable"))
786c6d
+		net_param->value[0] = ISCSI_NET_PARAM_ENABLE;
786c6d
 	else /* Assume disabled */
786c6d
-		net_param->value[0] = ISCSI_VLAN_DISABLE;
786c6d
+		net_param->value[0] = ISCSI_NET_PARAM_DISABLE;
786c6d
 	return 0;
786c6d
 }
786c6d
 
786c6d
-/* IPv4/IPv6 Network state: disable/enable */
786c6d
-static int iface_fill_net_state(struct iovec *iov, struct iface_rec *iface,
786c6d
-				uint32_t iface_type)
786c6d
-{
786c6d
-	int len;
786c6d
-	struct iscsi_iface_param_info *net_param;
786c6d
-	struct nlattr *attr;
786c6d
-
786c6d
-	len = sizeof(struct iscsi_iface_param_info) + 1;
786c6d
-	iov->iov_base = iscsi_nla_alloc(ISCSI_NET_PARAM_IFACE_ENABLE, len);
786c6d
-	if (!(iov->iov_base))
786c6d
-		return 1;
786c6d
-
786c6d
-	attr = iov->iov_base;
786c6d
-	iov->iov_len = NLA_ALIGN(attr->nla_len);
786c6d
-	net_param = (struct iscsi_iface_param_info *)ISCSI_NLA_DATA(attr);
786c6d
-	net_param->param = ISCSI_NET_PARAM_IFACE_ENABLE;
786c6d
-	net_param->iface_type = iface_type;
786c6d
-	net_param->iface_num = iface->iface_num;
786c6d
-	net_param->param_type = ISCSI_NET_PARAM;
786c6d
-	net_param->len = 1;
786c6d
-	if (!strcmp(iface->state, "disable"))
786c6d
-		net_param->value[0] = ISCSI_IFACE_DISABLE;
786c6d
-	else /* Assume enabled */
786c6d
-		net_param->value[0] = ISCSI_IFACE_ENABLE;
786c6d
-	return 0;
786c6d
+#define IFACE_SET_PARAM_STATE(iov, inum, itype, param, ptype, ival,	\
786c6d
+			      gcnt, lcnt) {				\
786c6d
+	if (!iface_fill_param_state(iov, inum, itype, param, ptype,	\
786c6d
+				    ival)) {				\
786c6d
+		(*gcnt)++;						\
786c6d
+		(*lcnt)++;						\
786c6d
+	}								\
786c6d
 }
786c6d
 
786c6d
 /* IPv4 Bootproto: DHCP/static */
786c6d
@@ -1598,13 +1583,14 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 	iptype = iface_get_iptype(iface);
786c6d
 	if (iptype == ISCSI_IFACE_TYPE_IPV4) {
786c6d
 		if (!strcmp(iface->state, "disable")) {
786c6d
-			if (!iface_fill_net_state(&iov[net_config->count],
786c6d
-						  iface,
786c6d
-						  ISCSI_IFACE_TYPE_IPV4)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
-
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV4,
786c6d
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
 			return 0;
786c6d
 		}
786c6d
 
786c6d
@@ -1648,18 +1634,24 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 		 * fill state and other parameters (if any)
786c6d
 		 */
786c6d
 		if (count) {
786c6d
-			if (!iface_fill_net_state(&iov[net_config->count],
786c6d
-						  iface,
786c6d
-						  ISCSI_IFACE_TYPE_IPV4)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
-			if (!iface_fill_vlan_state(&iov[net_config->count],
786c6d
-						iface,
786c6d
-						ISCSI_IFACE_TYPE_IPV4)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV4,
786c6d
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
+
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV4,
786c6d
+					      ISCSI_NET_PARAM_VLAN_ENABLED,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->vlan_state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
+
786c6d
 			if (strcmp(iface->vlan_state, "disable") &&
786c6d
 			    iface->vlan_id) {
786c6d
 				if (!iface_fill_vlan_id(&iov[net_config->count],
786c6d
@@ -1687,12 +1679,14 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 		}
786c6d
 	} else if (iptype == ISCSI_IFACE_TYPE_IPV6) {
786c6d
 		if (!strcmp(iface->state, "disable")) {
786c6d
-			if (!iface_fill_net_state(&iov[net_config->count],
786c6d
-						  iface,
786c6d
-						  ISCSI_IFACE_TYPE_IPV6)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV6,
786c6d
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
 			return 0;
786c6d
 		}
786c6d
 
786c6d
@@ -1770,18 +1764,24 @@ static int __iface_build_net_config(void *data, struct iface_rec *iface)
786c6d
 		 * fill state and other parameters
786c6d
 		 */
786c6d
 		if (count) {
786c6d
-			if (!iface_fill_net_state(&iov[net_config->count],
786c6d
-						  iface,
786c6d
-						  ISCSI_IFACE_TYPE_IPV6)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
-			if (!iface_fill_vlan_state(&iov[net_config->count],
786c6d
-						   iface,
786c6d
-						   ISCSI_IFACE_TYPE_IPV6)) {
786c6d
-				net_config->count++;
786c6d
-				count++;
786c6d
-			}
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV6,
786c6d
+					      ISCSI_NET_PARAM_IFACE_ENABLE,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
+
786c6d
+			IFACE_SET_PARAM_STATE(&iov[net_config->count],
786c6d
+					      iface->iface_num,
786c6d
+					      ISCSI_IFACE_TYPE_IPV6,
786c6d
+					      ISCSI_NET_PARAM_VLAN_ENABLED,
786c6d
+					      ISCSI_NET_PARAM,
786c6d
+					      iface->vlan_state,
786c6d
+					      &net_config->count,
786c6d
+					      &count);
786c6d
+
786c6d
 			if (strcmp(iface->vlan_state, "disable") &&
786c6d
 			    iface->vlan_id) {
786c6d
 				if (!iface_fill_vlan_id(&iov[net_config->count],
786c6d
-- 
786c6d
1.8.3.1
786c6d