Patchwork [Open-FCoE,03/14] fipvlan: Extract create_missing_vlan function from loop

login
register
mail settings
Submitter Hannes Reinecke
Date Nov. 19, 2013, 12:26 p.m.
Message ID <1384863974-27096-4-git-send-email-hare@suse.de>
Download mbox | patch
Permalink /patch/117/
State Accepted
Headers show

Comments

Hannes Reinecke - Nov. 19, 2013, 12:26 p.m.
No functional change.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 fipvlan.c | 74 +++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 41 insertions(+), 33 deletions(-)

Patch

diff --git a/fipvlan.c b/fipvlan.c
index 148d823..d91cc1c 100644
--- a/fipvlan.c
+++ b/fipvlan.c
@@ -544,48 +544,56 @@  static int rtnl_listener_handler(struct nlmsghdr *nh, UNUSED void *arg)
 	return -1;
 }
 
-static void
-create_missing_vlans_list(struct fcf_list_head *list, const char *label)
+static int
+create_missing_vlan(struct fcf *fcf, const char *label)
 {
-	struct fcf *fcf;
 	struct iff *real_dev, *vlan;
 	char vlan_name[IFNAMSIZ];
 	int rc;
 
+	real_dev = lookup_iff(fcf->ifindex, NULL);
+	if (!real_dev) {
+		FIP_LOG_ERR(ENODEV,
+			    "lost device %d with discovered %s?\n",
+			    fcf->ifindex, label);
+		return -ENXIO;
+	}
+	if (!fcf->vlan) {
+		/*
+		 * If the vlan notification has VLAN id 0,
+		 * skip creating vlan interface, and FCoE is
+		 * started on the physical interface itself.
+		 */
+		FIP_LOG_DBG("VLAN id is 0 for %s\n", real_dev->ifname);
+		return -EPERM;
+	}
+	vlan = lookup_vlan(fcf->ifindex, fcf->vlan);
+	if (vlan) {
+		FIP_LOG_DBG("VLAN %s.%d already exists as %s\n",
+			    real_dev->ifname, fcf->vlan, vlan->ifname);
+		return -EEXIST;
+	}
+	snprintf(vlan_name, IFNAMSIZ, "%s.%d%s",
+		 real_dev->ifname, fcf->vlan, config.suffix);
+	rc = vlan_create(fcf->ifindex, fcf->vlan, vlan_name);
+	if (rc < 0)
+		printf("Failed to create VLAN device %s\n\t%s\n",
+		       vlan_name, strerror(-rc));
+	else
+		printf("Created VLAN device %s\n", vlan_name);
+	return rc;
+}
+
+static void
+create_missing_vlans_list(struct fcf_list_head *list, const char *label)
+{
+	struct fcf *fcf;
+
 	if (!config.create)
 		return;
 
 	TAILQ_FOREACH(fcf, list, list_node) {
-		real_dev = lookup_iff(fcf->ifindex, NULL);
-		if (!real_dev) {
-			FIP_LOG_ERR(ENODEV,
-				    "lost device %d with discovered %s?\n",
-				    fcf->ifindex, label);
-			continue;
-		}
-		if (!fcf->vlan) {
-			/*
-			 * If the vlan notification has VLAN id 0,
-			 * skip creating vlan interface, and FCoE is
-			 * started on the physical interface itself.
-			 */
-			FIP_LOG_DBG("VLAN id is 0 for %s\n", real_dev->ifname);
-			continue;
-		}
-		vlan = lookup_vlan(fcf->ifindex, fcf->vlan);
-		if (vlan) {
-			FIP_LOG_DBG("VLAN %s.%d already exists as %s\n",
-				    real_dev->ifname, fcf->vlan, vlan->ifname);
-			continue;
-		}
-		snprintf(vlan_name, IFNAMSIZ, "%s.%d%s",
-			 real_dev->ifname, fcf->vlan, config.suffix);
-		rc = vlan_create(fcf->ifindex, fcf->vlan, vlan_name);
-		if (rc < 0)
-			printf("Failed to create VLAN device %s\n\t%s\n",
-			       vlan_name, strerror(-rc));
-		else
-			printf("Created VLAN device %s\n", vlan_name);
+		create_missing_vlan(fcf, label);
 	}
 	printf("\n");
 }