Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Robert Love <robert.w.love@intel.com>
To: James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org
Cc: Vasu Dev <vasu.dev@intel.com>, Robert Love <robert.w.love@intel.com>
Subject: [PATCH 17/22] fcoe: modifies fcoe_hostlist_lock uses as prep work to add shared offload EM
Date: Wed, 29 Jul 2009 17:05:15 -0700	[thread overview]
Message-ID: <20090730000515.24658.72918.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090730000345.24658.24830.stgit@localhost.localdomain>

From: Vasu Dev <vasu.dev@intel.com>

Modifies fcoe_hostlist_lock uses such that a new EM allocation in
fcoe_em_config and adding new fcoe_softc using fcoe_hostlist_add
are atomic, this is to ensure that a shared offload EM gets allocated
only once per eth device for its all lports.

Signed-off-by: Vasu Dev <vasu.dev@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
---

 drivers/scsi/fcoe/fcoe.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index ebf2e20..86410b9 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -419,6 +419,8 @@ static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
  * fcoe_em_config() - allocates em for this lport
  * @lp: the port that em is to allocated for
  *
+ * Called with write fcoe_hostlist_lock held.
+ *
  * Returns : 0 on success
  */
 static inline int fcoe_em_config(struct fc_lport *lp)
@@ -607,6 +609,13 @@ static int fcoe_if_create(struct net_device *netdev)
 		goto out_lp_destroy;
 	}
 
+	/*
+	 * fcoe_em_alloc() and fcoe_hostlist_add() both
+	 * need to be atomic under fcoe_hostlist_lock
+	 * since fcoe_em_alloc() looks for an existing EM
+	 * instance on host list updated by fcoe_hostlist_add().
+	 */
+	write_lock(&fcoe_hostlist_lock);
 	/* lport exch manager allocation */
 	rc = fcoe_em_config(lp);
 	if (rc) {
@@ -617,6 +626,7 @@ static int fcoe_if_create(struct net_device *netdev)
 
 	/* add to lports list */
 	fcoe_hostlist_add(lp);
+	write_unlock(&fcoe_hostlist_lock);
 
 	lp->boot_time = jiffies;
 
@@ -1720,6 +1730,8 @@ int fcoe_reset(struct Scsi_Host *shost)
  * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
  * @dev: this is currently ptr to net_device
  *
+ * Called with fcoe_hostlist_lock held.
+ *
  * Returns: NULL or the located fcoe_softc
  */
 static struct fcoe_softc *
@@ -1727,14 +1739,10 @@ fcoe_hostlist_lookup_softc(const struct net_device *dev)
 {
 	struct fcoe_softc *fc;
 
-	read_lock(&fcoe_hostlist_lock);
 	list_for_each_entry(fc, &fcoe_hostlist, list) {
-		if (fc->real_dev == dev) {
-			read_unlock(&fcoe_hostlist_lock);
+		if (fc->real_dev == dev)
 			return fc;
-		}
 	}
-	read_unlock(&fcoe_hostlist_lock);
 	return NULL;
 }
 
@@ -1748,7 +1756,9 @@ struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
 {
 	struct fcoe_softc *fc;
 
+	read_lock(&fcoe_hostlist_lock);
 	fc = fcoe_hostlist_lookup_softc(netdev);
+	read_unlock(&fcoe_hostlist_lock);
 
 	return (fc) ? fc->ctlr.lp : NULL;
 }
@@ -1757,6 +1767,8 @@ struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
  * fcoe_hostlist_add() - Add a lport to lports list
  * @lp: ptr to the fc_lport to be added
  *
+ * Called with write fcoe_hostlist_lock held.
+ *
  * Returns: 0 for success
  */
 int fcoe_hostlist_add(const struct fc_lport *lp)
@@ -1766,9 +1778,7 @@ int fcoe_hostlist_add(const struct fc_lport *lp)
 	fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
 	if (!fc) {
 		fc = lport_priv(lp);
-		write_lock_bh(&fcoe_hostlist_lock);
 		list_add_tail(&fc->list, &fcoe_hostlist);
-		write_unlock_bh(&fcoe_hostlist_lock);
 	}
 	return 0;
 }
@@ -1783,9 +1793,9 @@ int fcoe_hostlist_remove(const struct fc_lport *lp)
 {
 	struct fcoe_softc *fc;
 
+	write_lock_bh(&fcoe_hostlist_lock);
 	fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
 	BUG_ON(!fc);
-	write_lock_bh(&fcoe_hostlist_lock);
 	list_del(&fc->list);
 	write_unlock_bh(&fcoe_hostlist_lock);
 


  parent reply	other threads:[~2009-07-30  0:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-30  0:03 [PATCH 00/22] Open-FCoE Features for 2.6.32 Robert Love
2009-07-30  0:03 ` [PATCH 01/22] fcoe: Fix validation of mac address when checking for spma support Robert Love
2009-07-30  0:03 ` [PATCH 02/22] libfcoe: Set fip_flags according to fcf and lport's capability of SPMA support Robert Love
2009-07-30  0:04 ` [PATCH 03/22] fcoe: Call dev_ethtool_get_settings() in fcoe_link_ok Robert Love
2009-07-30  0:04 ` [PATCH 04/22] libfc: remove extra semicolons from debug macros Robert Love
2009-07-30  0:04 ` [PATCH 05/22] libfc: change debug messages to give host number Robert Love
2009-07-30  0:04 ` [PATCH 06/22] fcoe: stop delivery of received frames before doing lport_destroy() Robert Love
2009-07-30  0:04 ` [PATCH 07/22] libfc: rename lport NONE state to DISABLED Robert Love
2009-07-30  0:04 ` [PATCH 08/22] libfc: stop login after fabric logoff Robert Love
2009-07-30  0:04 ` [PATCH 09/22] libfc: in fc_lport_destroy, flush rports after turning off link Robert Love
2009-07-30  0:04 ` [PATCH 10/22] libfc: fix WARNING from fc_seq_start_next on closed exchanges Robert Love
2009-07-30  0:04 ` [PATCH 11/22] libfc: rename rport state "NONE" to "DELETE" Robert Love
2009-07-30  0:04 ` [PATCH 12/22] libfc: fc_rport_logoff should not drop the lock Robert Love
2009-07-30  0:04 ` [PATCH 13/22] libfc: fix: cancel rport retry timer Robert Love
2009-07-30  0:05 ` [PATCH 14/22] fcoe, libfc: adds exchange manager(EM) anchor list per lport and related APIs Robert Love
2009-07-30  0:05 ` [PATCH 15/22] libfc: Remove the FC_EM_DBG macro Robert Love
2009-07-30  0:05 ` [PATCH 16/22] fcoe, fnic, libfc: modifies current code paths to use EM anchor list Robert Love
2009-07-30  0:05 ` Robert Love [this message]
2009-07-30  0:05 ` [PATCH 18/22] fcoe, libfc: adds offload EM per eth device with only single xid range per EM Robert Love
2009-07-30  0:05 ` [PATCH 19/22] fcoe: Remove ifdef for NETIF_F_FCOE_CRC and NETIF_F_FSO Robert Love
2009-07-30  0:05 ` [PATCH 20/22] libfc: Remove FC_FRAME_SG_LEN in fc_fcp_send_data Robert Love
2009-07-30  0:05 ` [PATCH 21/22] libfc: Remove page flags check for sglist Robert Love
2009-07-30  0:05 ` [PATCH 22/22] fcoe: removes phys_dev and renames real_dev to netdev Robert Love

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090730000515.24658.72918.stgit@localhost.localdomain \
    --to=robert.w.love@intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vasu.dev@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox