[Open-FCoE] [PATCH 4/4] libfc fcoe: stop doing things by ifname, remove ifname from fc_lport

Yi Zou yi.zou at intel.com
Wed Oct 1 21:59:34 UTC 2008


From: Chris Leech <christopher.leech at intel.com>

Signed-off-by: Chris Leech <christopher.leech at intel.com>
Signed-off-by: Yi Zou <yi.zou at intel.com>
---

 drivers/scsi/fcoe/fc_transport_fcoe.c |   31 +++++++++++++++++----------
 drivers/scsi/fcoe/fcoe_def.h          |    4 ++-
 drivers/scsi/fcoe/fcoe_sw.c           |   38 ++++++++++-----------------------
 include/scsi/libfc/libfc.h            |    1 -
 4 files changed, 33 insertions(+), 41 deletions(-)

diff --git a/drivers/scsi/fcoe/fc_transport_fcoe.c b/drivers/scsi/fcoe/fc_transport_fcoe.c
index 76888cf..e11d36b 100644
--- a/drivers/scsi/fcoe/fc_transport_fcoe.c
+++ b/drivers/scsi/fcoe/fc_transport_fcoe.c
@@ -230,20 +230,32 @@ static void trimstr(char *str, int len)
 static ssize_t fcoe_destroy(struct kobject *kobj, struct kobj_attribute *attr,
 			    const char *buffer, size_t size)
 {
-	char ifname[40];
-	strcpy(ifname, buffer);
+	struct net_device *netdev;
+	char ifname[IFNAMSIZ + 2];
+
+	strlcpy(ifname, buffer, IFNAMSIZ);
 	trimstr(ifname, strlen(ifname));
-	fcoe_destroy_interface(ifname);
+	netdev = dev_get_by_name(&init_net, ifname);
+	if (netdev) {
+		fcoe_destroy_interface(netdev);
+		dev_put(netdev);
+	}
 	return size;
 }
 
 static ssize_t fcoe_create(struct kobject *kobj, struct kobj_attribute *attr,
 			   const char *buffer, size_t size)
 {
-	char ifname[40];
-	strcpy(ifname, buffer);
+	struct net_device *netdev;
+	char ifname[IFNAMSIZ + 2];
+
+	strlcpy(ifname, buffer, IFNAMSIZ);
 	trimstr(ifname, strlen(ifname));
-	fcoe_create_interface(ifname);
+	netdev = dev_get_by_name(&init_net, ifname);
+	if (netdev) {
+		fcoe_create_interface(netdev);
+		dev_put(netdev);
+	}
 	return size;
 }
 
@@ -341,7 +353,6 @@ static void __exit fcoe_exit(void)
 {
 	u32 idx;
 	struct fcoe_softc *fc, *tmp;
-	struct fc_lport *lp;
 	struct fcoe_percpu_s *p;
 	struct sk_buff *skb;
 
@@ -363,10 +374,8 @@ static void __exit fcoe_exit(void)
 	 * ioctl in prograss, therefore we do not need to lock the
 	 * list.
 	 */
-	list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list) {
-		lp = fc->lp;
-		fcoe_destroy_interface(lp->ifname);
-	}
+	list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
+		fcoe_destroy_interface(fc->real_dev);
 
 	for (idx = 0; idx < NR_CPUS; idx++) {
 		if (fcoe_percpu[idx]) {
diff --git a/drivers/scsi/fcoe/fcoe_def.h b/drivers/scsi/fcoe/fcoe_def.h
index 3d7e9e1..762af58 100644
--- a/drivers/scsi/fcoe/fcoe_def.h
+++ b/drivers/scsi/fcoe/fcoe_def.h
@@ -81,8 +81,8 @@ int fcoe_percpu_receive_thread(void *arg);
  */
 void fcoe_clean_pending_queue(struct fc_lport *fd);
 void fcoe_watchdog(ulong vp);
-int fcoe_destroy_interface(const char *ifname);
-int fcoe_create_interface(const char *ifname);
+int fcoe_destroy_interface(struct net_device *);
+int fcoe_create_interface(struct net_device *);
 int fcoe_xmit(struct fc_lport *, struct fc_frame *);
 int fcoe_rcv(struct sk_buff *, struct net_device *,
 	     struct packet_type *, struct net_device *);
diff --git a/drivers/scsi/fcoe/fcoe_sw.c b/drivers/scsi/fcoe/fcoe_sw.c
index fcef466..9127047 100644
--- a/drivers/scsi/fcoe/fcoe_sw.c
+++ b/drivers/scsi/fcoe/fcoe_sw.c
@@ -61,15 +61,13 @@ struct fcoe_percpu_s *fcoe_percpu[NR_CPUS];
 
 static struct scsi_transport_template *fcoe_transport_template;
 
-static struct fcoe_softc *fcoe_find_fc_lport(const char *name)
+static struct fcoe_softc *fcoe_find_fc_lport(const struct net_device *netdev)
 {
 	struct fcoe_softc *fc;
-	struct fc_lport *lp;
 
 	read_lock(&fcoe_hostlist_lock);
 	list_for_each_entry(fc, &fcoe_hostlist, list) {
-		lp = fc->lp;
-		if (!strncmp(name, lp->ifname, IFNAMSIZ)) {
+		if (fc->real_dev == netdev) {
 			read_unlock(&fcoe_hostlist_lock);
 			return fc;
 		}
@@ -132,7 +130,7 @@ static struct scsi_host_template fcoe_driver_template = {
 	.max_sectors = 0xffff,
 };
 
-int fcoe_destroy_interface(const char *ifname)
+int fcoe_destroy_interface(struct net_device *netdev)
 {
 	int cpu, idx;
 	struct fcoe_dev_stats *p;
@@ -145,7 +143,7 @@ int fcoe_destroy_interface(const char *ifname)
 	struct fc_lport *lp;
 	u8 flogi_maddr[ETH_ALEN];
 
-	fc = fcoe_find_fc_lport(ifname);
+	fc = fcoe_find_fc_lport(netdev);
 	if (!fc)
 		return -ENODEV;
 
@@ -336,8 +334,6 @@ static int net_config(struct fc_lport *lp)
 
 	skb_queue_head_init(&fc->fcoe_pending_queue);
 
-	memcpy(lp->ifname, fc->real_dev->name, IFNAMSIZ);
-
 	/* setup Source Mac Address */
 	memcpy(fc->ctl_src_addr, fc->real_dev->dev_addr,
 	       fc->real_dev->addr_len);
@@ -399,25 +395,15 @@ static int libfc_config(struct fc_lport *lp)
  * create struct fcdev which is a shared structure between opefc
  * and transport level protocol.
  */
-int fcoe_create_interface(const char *ifname)
+int fcoe_create_interface(struct net_device *netdev)
 {
 	struct fc_lport *lp = NULL;
 	struct fcoe_softc *fc;
-	struct net_device *net_dev;
 	struct Scsi_Host *shost;
 	int rc = 0;
 
-	net_dev = dev_get_by_name(&init_net, ifname);
-	if (net_dev == NULL) {
-		FC_DBG("could not get network device for %s",
-		       ifname);
-		return -ENODEV;
-	}
-
-	if (fcoe_find_fc_lport(net_dev->name) != NULL) {
-		rc = -EEXIST;
-		goto out_put_dev;
-	}
+	if (fcoe_find_fc_lport(netdev) != NULL)
+		return -EEXIST;
 
 	shost = scsi_host_alloc(&fcoe_driver_template,
 				sizeof(struct fc_lport) +
@@ -425,8 +411,7 @@ int fcoe_create_interface(const char *ifname)
 
 	if (!shost) {
 		FC_DBG("Could not allocate host structure\n");
-		rc = -ENOMEM;
-		goto out_put_dev;
+		return -ENOMEM;
 	}
 
 	lp = shost_priv(shost);
@@ -437,7 +422,7 @@ int fcoe_create_interface(const char *ifname)
 	/* Configure the fcoe_softc */
 	fc = (struct fcoe_softc *)lp->drv_priv;
 	fc->lp = lp;
-	fc->real_dev = net_dev;
+	fc->real_dev = netdev;
 	shost_config(lp);
 
 
@@ -450,7 +435,7 @@ int fcoe_create_interface(const char *ifname)
 
 	sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
 		FCOE_DRIVER_NAME, FCOE_VERSION,
-		ifname);
+		netdev->name);
 
 	/* Configure netdev and networking properties of the lp */
 	rc = net_config(lp);
@@ -470,14 +455,13 @@ int fcoe_create_interface(const char *ifname)
 
 	fc_fabric_login(lp);
 
+	dev_hold(netdev);
 	return rc;
 
 out_lp_destroy:
 	fc_exch_mgr_free(lp->emp); /* Free the EM */
 out_host_put:
 	scsi_host_put(lp->host);
-out_put_dev:
-	dev_put(net_dev);
 	return rc;
 }
 
diff --git a/include/scsi/libfc/libfc.h b/include/scsi/libfc/libfc.h
index 08f5c0a..9e39147 100644
--- a/include/scsi/libfc/libfc.h
+++ b/include/scsi/libfc/libfc.h
@@ -420,7 +420,6 @@ struct fc_lport {
 	unsigned char		ns_disc_buf_len;
 
 	/* Capabilities */
-	char			ifname[IFNAMSIZ];
 	u32			capabilities;
 	u32			mfs;	/* max FC payload size */
 	unsigned int		service_params;




More information about the devel mailing list