[Open-FCoE] [PATCH 2/4] fcoe: remove fcoe_info structure, just make the members global individually

Yi Zou yi.zou at intel.com
Wed Oct 1 21:59:17 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 |   64 ++++++++++++++-------------------
 drivers/scsi/fcoe/fcoe_def.h          |   19 +++-------
 drivers/scsi/fcoe/fcoe_sw.c           |   34 ++++++++----------
 drivers/scsi/fcoe/libfcoe.c           |   21 +++++------
 4 files changed, 58 insertions(+), 80 deletions(-)

diff --git a/drivers/scsi/fcoe/fc_transport_fcoe.c b/drivers/scsi/fcoe/fc_transport_fcoe.c
index 4baa9f5..fbec7f9 100644
--- a/drivers/scsi/fcoe/fc_transport_fcoe.c
+++ b/drivers/scsi/fcoe/fc_transport_fcoe.c
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
+ * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -91,8 +91,6 @@ struct fc_function_template fcoe_transport_function = {
 	.terminate_rport_io = fc_rport_terminate_io,
 };
 
-struct fcoe_percpu_s *fcoe_percpu[NR_CPUS];
-
 #ifdef CONFIG_HOTPLUG_CPU
 static struct notifier_block fcoe_cpu_notifier = {
 	.notifier_call = fcoe_cpu_callback,
@@ -116,10 +114,9 @@ static void fcoe_create_percpu_data(int cpu)
 	struct fc_lport *lp;
 	struct fcoe_softc *fc;
 	struct fcoe_dev_stats *p;
-	struct fcoe_info *fci = &fcoei;
 
-	write_lock_bh(&fci->fcoe_hostlist_lock);
-	list_for_each_entry(fc, &fci->fcoe_hostlist, list) {
+	write_lock_bh(&fcoe_hostlist_lock);
+	list_for_each_entry(fc, &fcoe_hostlist, list) {
 		lp = fc->lp;
 		if (lp->dev_stats[cpu] == NULL) {
 			p = kzalloc(sizeof(struct fcoe_dev_stats), GFP_KERNEL);
@@ -127,7 +124,7 @@ static void fcoe_create_percpu_data(int cpu)
 				lp->dev_stats[cpu] = p;
 		}
 	}
-	write_unlock_bh(&fci->fcoe_hostlist_lock);
+	write_unlock_bh(&fcoe_hostlist_lock);
 }
 
 /*
@@ -139,10 +136,9 @@ static void fcoe_destroy_percpu_data(int cpu)
 	struct fcoe_dev_stats *p;
 	struct fc_lport *lp;
 	struct fcoe_softc *fc;
-	struct fcoe_info *fci = &fcoei;
 
-	write_lock_bh(&fci->fcoe_hostlist_lock);
-	list_for_each_entry(fc, &fci->fcoe_hostlist, list) {
+	write_lock_bh(&fcoe_hostlist_lock);
+	list_for_each_entry(fc, &fcoe_hostlist, list) {
 		lp = fc->lp;
 		p = lp->dev_stats[cpu];
 		if (p != NULL) {
@@ -150,7 +146,7 @@ static void fcoe_destroy_percpu_data(int cpu)
 			kfree(p);
 		}
 	}
-	write_unlock_bh(&fci->fcoe_hostlist_lock);
+	write_unlock_bh(&fcoe_hostlist_lock);
 }
 
 /*
@@ -206,19 +202,18 @@ static int fcoe_device_notification(struct notifier_block *notifier,
 	struct net_device *real_dev = ptr;
 	struct fcoe_softc *fc;
 	struct fcoe_dev_stats *stats;
-	struct fcoe_info *fci = &fcoei;
 	u16 new_status;
 	u32 mfs;
 	int rc = NOTIFY_OK;
 
-	read_lock(&fci->fcoe_hostlist_lock);
-	list_for_each_entry(fc, &fci->fcoe_hostlist, list) {
+	read_lock(&fcoe_hostlist_lock);
+	list_for_each_entry(fc, &fcoe_hostlist, list) {
 		if (fc->real_dev == real_dev) {
 			lp = fc->lp;
 			break;
 		}
 	}
-	read_unlock(&fci->fcoe_hostlist_lock);
+	read_unlock(&fcoe_hostlist_lock);
 	if (lp == NULL) {
 		rc = NOTIFY_DONE;
 		goto out;
@@ -304,12 +299,11 @@ static const struct kobj_attribute fcoe_createattr = \
  * 1. Will create fc transport software structure
  * 2. initialize the link list of port information structure
  */
-static int __init fcoeinit(void)
+static int __init fcoe_init(void)
 {
 	int rc = 0;
 	int cpu;
 	struct fcoe_percpu_s *p;
-	struct fcoe_info *fci = &fcoei;
 
 	rc = sysfs_create_file(&THIS_MODULE->mkobj.kobj,
 			       &fcoe_destroyattr.attr);
@@ -320,7 +314,7 @@ static int __init fcoeinit(void)
 	if (rc)
 		return rc;
 
-	rwlock_init(&fci->fcoe_hostlist_lock);
+	rwlock_init(&fcoe_hostlist_lock);
 
 #ifdef CONFIG_HOTPLUG_CPU
 	register_cpu_notifier(&fcoe_cpu_notifier);
@@ -342,12 +336,12 @@ static int __init fcoeinit(void)
 			 */
 			if (likely(!IS_ERR(p->thread))) {
 				p->cpu = cpu;
-				fci->fcoe_percpu[cpu] = p;
+				fcoe_percpu[cpu] = p;
 				skb_queue_head_init(&p->fcoe_rx_list);
 				kthread_bind(p->thread, cpu);
 				wake_up_process(p->thread);
 			} else {
-				fci->fcoe_percpu[cpu] = NULL;
+				fcoe_percpu[cpu] = NULL;
 				kfree(p);
 
 			}
@@ -364,11 +358,11 @@ static int __init fcoeinit(void)
 	 */
 	fcoe_dev_setup();
 
-	init_timer(&fci->timer);
-	fci->timer.data = (ulong) fci;
-	fci->timer.function = fcoe_watchdog;
-	fci->timer.expires = (jiffies + (10 * HZ));
-	add_timer(&fci->timer);
+	init_timer(&fcoe_timer);
+	fcoe_timer.data = 0;
+	fcoe_timer.function = fcoe_watchdog;
+	fcoe_timer.expires = (jiffies + (10 * HZ));
+	add_timer(&fcoe_timer);
 
 	fcoe_transport_template =
 		fc_attach_transport(&fcoe_transport_function);
@@ -386,13 +380,13 @@ out_chrdev:
 #endif /* CONFIG_HOTPLUG_CPU */
 	return rc;
 }
+module_init(fcoe_init);
 
 static void __exit fcoe_exit(void)
 {
 	u32 idx;
 	struct fcoe_softc *fc, *tmp;
 	struct fc_lport *lp;
-	struct fcoe_info *fci = &fcoei;
 	struct fcoe_percpu_s *p;
 	struct sk_buff *skb;
 
@@ -407,34 +401,32 @@ static void __exit fcoe_exit(void)
 	/*
 	 * stop timer
 	 */
-	del_timer_sync(&fci->timer);
+	del_timer_sync(&fcoe_timer);
 
 	/*
 	 * assuming that at this time there will be no
 	 * ioctl in prograss, therefore we do not need to lock the
 	 * list.
 	 */
-	list_for_each_entry_safe(fc, tmp, &fci->fcoe_hostlist, list) {
+	list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list) {
 		lp = fc->lp;
 		fcoe_destroy_interface(lp->ifname);
 	}
 
 	for (idx = 0; idx < NR_CPUS; idx++) {
-		if (fci->fcoe_percpu[idx]) {
-			kthread_stop(fci->fcoe_percpu[idx]->thread);
-			p = fci->fcoe_percpu[idx];
+		if (fcoe_percpu[idx]) {
+			kthread_stop(fcoe_percpu[idx]->thread);
+			p = fcoe_percpu[idx];
 			spin_lock_bh(&p->fcoe_rx_list.lock);
 			while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
 				kfree_skb(skb);
 			spin_unlock_bh(&p->fcoe_rx_list.lock);
-			if (fci->fcoe_percpu[idx]->crc_eof_page)
-				put_page(fci->fcoe_percpu[idx]->crc_eof_page);
-			kfree(fci->fcoe_percpu[idx]);
+			if (fcoe_percpu[idx]->crc_eof_page)
+				put_page(fcoe_percpu[idx]->crc_eof_page);
+			kfree(fcoe_percpu[idx]);
 		}
 	}
 
 	fc_release_transport(fcoe_transport_template);
 }
-
-module_init(fcoeinit);
 module_exit(fcoe_exit);
diff --git a/drivers/scsi/fcoe/fcoe_def.h b/drivers/scsi/fcoe/fcoe_def.h
index 12bf69c..1fe4db6 100644
--- a/drivers/scsi/fcoe/fcoe_def.h
+++ b/drivers/scsi/fcoe/fcoe_def.h
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
+ * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -48,16 +48,10 @@ struct fcoe_percpu_s {
 	int crc_eof_offset;
 };
 
-struct fcoe_info {
-	struct timer_list timer;
-	/*
-	 * fcoe host list is protected by the following read/write lock
-	 */
-	rwlock_t fcoe_hostlist_lock;
-	struct list_head fcoe_hostlist;
-
-	struct fcoe_percpu_s *fcoe_percpu[NR_CPUS];
-};
+extern struct timer_list fcoe_timer;
+extern rwlock_t fcoe_hostlist_lock;
+extern struct list_head fcoe_hostlist;
+extern struct fcoe_percpu_s *fcoe_percpu[];
 
 struct fcoe_softc {
 	struct list_head list;
@@ -80,15 +74,12 @@ struct fcoe_softc {
 };
 
 extern int debug_fcoe;
-extern struct fcoe_percpu_s *fcoe_percpu[];
 extern struct scsi_transport_template *fcoe_transport_template;
 int fcoe_percpu_receive_thread(void *arg);
 
 /*
  * HBA transport ops prototypes
  */
-extern struct fcoe_info fcoei;
-
 void fcoe_clean_pending_queue(struct fc_lport *fd);
 void fcoe_watchdog(ulong vp);
 int fcoe_destroy_interface(const char *ifname);
diff --git a/drivers/scsi/fcoe/fcoe_sw.c b/drivers/scsi/fcoe/fcoe_sw.c
index d5f1df0..1b77192 100644
--- a/drivers/scsi/fcoe/fcoe_sw.c
+++ b/drivers/scsi/fcoe/fcoe_sw.c
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
+ * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -54,25 +54,25 @@
 
 int debug_fcoe;
 
-struct fcoe_info fcoei = {
-	.fcoe_hostlist = LIST_HEAD_INIT(fcoei.fcoe_hostlist),
-};
+LIST_HEAD(fcoe_hostlist);
+DEFINE_RWLOCK(fcoe_hostlist_lock);
+DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
+struct fcoe_percpu_s *fcoe_percpu[NR_CPUS];
 
 static struct fcoe_softc *fcoe_find_fc_lport(const char *name)
 {
 	struct fcoe_softc *fc;
 	struct fc_lport *lp;
-	struct fcoe_info *fci = &fcoei;
 
-	read_lock(&fci->fcoe_hostlist_lock);
-	list_for_each_entry(fc, &fci->fcoe_hostlist, list) {
+	read_lock(&fcoe_hostlist_lock);
+	list_for_each_entry(fc, &fcoe_hostlist, list) {
 		lp = fc->lp;
 		if (!strncmp(name, lp->ifname, IFNAMSIZ)) {
-			read_unlock(&fci->fcoe_hostlist_lock);
+			read_unlock(&fcoe_hostlist_lock);
 			return fc;
 		}
 	}
-	read_unlock(&fci->fcoe_hostlist_lock);
+	read_unlock(&fcoe_hostlist_lock);
 	return NULL;
 }
 
@@ -137,7 +137,6 @@ int fcoe_destroy_interface(const char *ifname)
 	struct fcoe_percpu_s *pp;
 	struct fcoe_softc *fc;
 	struct fcoe_rcv_info *fr;
-	struct fcoe_info *fci = &fcoei;
 	struct sk_buff_head *list;
 	struct sk_buff *skb, *next;
 	struct sk_buff *head;
@@ -151,9 +150,9 @@ int fcoe_destroy_interface(const char *ifname)
 	lp = fc->lp;
 
 	/* Remove the instance from fcoe's list */
-	write_lock_bh(&fci->fcoe_hostlist_lock);
+	write_lock_bh(&fcoe_hostlist_lock);
 	list_del(&fc->list);
-	write_unlock_bh(&fci->fcoe_hostlist_lock);
+	write_unlock_bh(&fcoe_hostlist_lock);
 
 	/* Don't listen for Ethernet packets anymore */
 	dev_remove_pack(&fc->fcoe_packet_type);
@@ -178,8 +177,8 @@ int fcoe_destroy_interface(const char *ifname)
 
 	/* Free the per-CPU revieve threads */
 	for (idx = 0; idx < NR_CPUS; idx++) {
-		if (fci->fcoe_percpu[idx]) {
-			pp = fci->fcoe_percpu[idx];
+		if (fcoe_percpu[idx]) {
+			pp = fcoe_percpu[idx];
 			spin_lock_bh(&pp->fcoe_rx_list.lock);
 			list = &pp->fcoe_rx_list;
 			head = list->next;
@@ -404,7 +403,6 @@ int fcoe_create_interface(const char *ifname)
 	struct fcoe_softc *fc;
 	struct net_device *net_dev;
 	struct Scsi_Host *shost;
-	struct fcoe_info *fci = &fcoei;
 	int rc = 0;
 
 	net_dev = dev_get_by_name(&init_net, ifname);
@@ -462,9 +460,9 @@ int fcoe_create_interface(const char *ifname)
 	if (rc)
 		goto out_lp_destroy;
 
-	write_lock_bh(&fci->fcoe_hostlist_lock);
-	list_add_tail(&fc->list, &fci->fcoe_hostlist);
-	write_unlock_bh(&fci->fcoe_hostlist_lock);
+	write_lock_bh(&fcoe_hostlist_lock);
+	list_add_tail(&fc->list, &fcoe_hostlist);
+	write_unlock_bh(&fcoe_hostlist_lock);
 
 	lp->boot_time = jiffies;
 
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
index d5a354f..93fc7ae 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/libfcoe.c
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2007 Intel Corporation. All rights reserved.
+ * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -75,7 +75,6 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
 	unsigned short oxid;
 	int cpu_idx;
 	struct fcoe_percpu_s *fps;
-	struct fcoe_info *fci = &fcoei;
 
 	fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
 	lp = fc->lp;
@@ -115,10 +114,10 @@ int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
 	 * for a given idx then use first online cpu.
 	 */
 	cpu_idx = oxid & (num_online_cpus() >> 1);
-	if (fci->fcoe_percpu[cpu_idx] == NULL)
+	if (fcoe_percpu[cpu_idx] == NULL)
 		cpu_idx = first_cpu(cpu_online_map);
 #endif
-	fps = fci->fcoe_percpu[cpu_idx];
+	fps = fcoe_percpu[cpu_idx];
 
 	spin_lock_bh(&fps->fcoe_rx_list.lock);
 	__skb_queue_tail(&fps->fcoe_rx_list, skb);
@@ -155,13 +154,12 @@ static inline int fcoe_start_io(struct sk_buff *skb)
 
 static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
 {
-	struct fcoe_info *fci = &fcoei;
 	struct fcoe_percpu_s *fps;
 	struct page *page;
 	int cpu_idx;
 
 	cpu_idx = get_cpu();
-	fps = fci->fcoe_percpu[cpu_idx];
+	fps = fcoe_percpu[cpu_idx];
 	page = fps->crc_eof_page;
 	if (!page) {
 		page = alloc_page(GFP_ATOMIC);
@@ -534,11 +532,10 @@ void fcoe_watchdog(ulong vp)
 {
 	struct fc_lport *lp;
 	struct fcoe_softc *fc;
-	struct fcoe_info *fci = &fcoei;
 	int paused = 0;
 
-	read_lock(&fci->fcoe_hostlist_lock);
-	list_for_each_entry(fc, &fci->fcoe_hostlist, list) {
+	read_lock(&fcoe_hostlist_lock);
+	list_for_each_entry(fc, &fcoe_hostlist, list) {
 		lp = fc->lp;
 		if (lp) {
 			if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
@@ -549,10 +546,10 @@ void fcoe_watchdog(ulong vp)
 			}
 		}
 	}
-	read_unlock(&fci->fcoe_hostlist_lock);
+	read_unlock(&fcoe_hostlist_lock);
 
-	fci->timer.expires = jiffies + (1 * HZ);
-	add_timer(&fci->timer);
+	fcoe_timer.expires = jiffies + (1 * HZ);
+	add_timer(&fcoe_timer);
 }
 
 /*




More information about the devel mailing list