[Open-FCoE] [PATCH V2 11/13] fcoe: add mutex to protect create and destroy

Chris Leech christopher.leech at intel.com
Wed Jul 8 17:40:28 UTC 2009


Rather than rely on the hostlist_lock to be held while creating exchange
managers, serialize fcoe instance creation and destruction with a mutex.
This will allow the hostlist addition to be moved out of fcoe_if_create(),
which will simplify NPIV support.

Signed-off-by: Chris Leech <christopher.leech at intel.com>
---

 drivers/scsi/fcoe/fcoe.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 49a9d5b..73ae360 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -49,6 +49,8 @@ MODULE_AUTHOR("Open-FCoE.org");
 MODULE_DESCRIPTION("FCoE");
 MODULE_LICENSE("GPL v2");
 
+DEFINE_MUTEX(fcoe_create_mutex);
+
 /* fcoe host list */
 LIST_HEAD(fcoe_hostlist);
 DEFINE_RWLOCK(fcoe_hostlist_lock);
@@ -795,6 +797,7 @@ static int __init fcoe_if_init(void)
 int __exit fcoe_if_exit(void)
 {
 	fc_release_transport(scsi_transport_fcoe_sw);
+	scsi_transport_fcoe_sw = NULL;
 	return 0;
 }
 
@@ -1674,6 +1677,12 @@ static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
 	struct fc_lport *lport;
 	int rc;
 
+	mutex_lock(&fcoe_create_mutex);
+	if (!scsi_transport_fcoe_sw) {
+		rc = -ENODEV;
+		goto out_nodev;
+	}
+
 	netdev = fcoe_if_to_netdev(buffer);
 	if (!netdev) {
 		rc = -ENODEV;
@@ -1693,6 +1702,7 @@ static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
 out_putdev:
 	dev_put(netdev);
 out_nodev:
+	mutex_unlock(&fcoe_create_mutex);
 	return rc;
 }
 
@@ -1710,6 +1720,12 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
 	struct fc_lport *lport;
 	struct net_device *netdev;
 
+	mutex_lock(&fcoe_create_mutex);
+	if (!scsi_transport_fcoe_sw) {
+		rc = -ENODEV;
+		goto out_nodev;
+	}
+
 	netdev = fcoe_if_to_netdev(buffer);
 	if (!netdev) {
 		rc = -ENODEV;
@@ -1747,6 +1763,7 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
 		fcoe_ctlr_link_up(&fcoe->ctlr);
 
 	dev_put(netdev);
+	mutex_unlock(&fcoe_create_mutex);
 	return 0;
 
 out_free:
@@ -1754,6 +1771,7 @@ out_free:
 out_putdev:
 	dev_put(netdev);
 out_nodev:
+	mutex_unlock(&fcoe_create_mutex);
 	return rc;
 }
 
@@ -1999,6 +2017,8 @@ static void __exit fcoe_exit(void)
 	unsigned int cpu;
 	struct fcoe_interface *fcoe, *tmp;
 
+	mutex_lock(&fcoe_create_mutex);
+
 	fcoe_dev_cleanup();
 
 	/* releases the associated fcoe hosts */
@@ -2012,5 +2032,7 @@ static void __exit fcoe_exit(void)
 
 	/* detach from scsi transport */
 	fcoe_if_exit();
+
+	mutex_unlock(&fcoe_create_mutex);
 }
 module_exit(fcoe_exit);




More information about the devel mailing list