public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: linux-scsi@vger.kernel.org
Cc: Hannes Reinecke <hare@suse.de>,
	Chad Dupuis <chad.dupuis@qlogic.com>,
	Andrew Vasquez <andrew.vasquez@qlogic.com>,
	James Smart <james.smart@emulex.com>,
	James Bottomley <jbottomley@parallels.com>,
	Mike Christie <michaelc@cs.wisc.edu>
Subject: [PATCH] scsi_transport_fc: Make 'port_state' writeable
Date: Tue, 15 Jan 2013 16:02:18 +0100	[thread overview]
Message-ID: <1358262138-13378-1-git-send-email-hare@suse.de> (raw)

Multipath might detect a path down even though the LLDD
hasn't registered a link down event.
This patch makes the 'port_state' FC attribute writeable
to enforce a link down scenario in these cases, allowing
for a fast failover to the remaining ports.

Cc: Chad Dupuis <chad.dupuis@qlogic.com>
Cc: Andrew Vasquez <andrew.vasquez@qlogic.com>
Cc: James Smart <james.smart@emulex.com>
Cc: James Bottomley <jbottomley@parallels.com>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: Hannes Reinecke <hare@suse.de>

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 5e1c6dd..4d28ee5 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -42,6 +42,8 @@
 #include "scsi_priv.h"
 #include "scsi_transport_fc_internal.h"
 
+static void fc_flush_devloss(struct Scsi_Host *shost);
+static void fc_flush_work(struct Scsi_Host *shost);
 static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
 static void fc_vport_sched_delete(struct work_struct *work);
 static int fc_vport_setup(struct Scsi_Host *shost, int channel,
@@ -949,7 +951,76 @@ show_fc_rport_roles (struct device *dev, struct device_attribute *attr,
 static FC_DEVICE_ATTR(rport, roles, S_IRUGO,
 		show_fc_rport_roles, NULL);
 
-fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
+static ssize_t
+store_fc_rport_port_state(struct device *dev,
+			  struct device_attribute *attr,
+			  const char *buf, size_t count)
+{
+	unsigned long flags;
+	struct fc_rport *rport = transport_class_to_rport(dev);
+	struct Scsi_Host *shost = rport_to_shost(rport);
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	if (!strncmp(buf, "Blocked", 7)) {
+		if (rport->port_state != FC_PORTSTATE_ONLINE) {
+			spin_unlock_irqrestore(shost->host_lock, flags);
+			return -EBUSY;
+		}
+		spin_unlock_irqrestore(shost->host_lock, flags);
+		fc_remote_port_delete(rport);
+	} else if (!strncmp(buf, "Online", 6)) {
+		if (rport->port_state != FC_PORTSTATE_BLOCKED) {
+			spin_unlock_irqrestore(shost->host_lock, flags);
+			return -EBUSY;
+		}
+		/* Reset back to online for rescan */
+		rport->port_state = FC_PORTSTATE_ONLINE;
+		spin_unlock_irqrestore(shost->host_lock, flags);
+
+		if (!cancel_delayed_work(&rport->fail_io_work))
+			fc_flush_devloss(shost);
+		if (!cancel_delayed_work(&rport->dev_loss_work))
+			fc_flush_devloss(shost);
+
+		spin_lock_irqsave(shost->host_lock, flags);
+		rport->flags &= ~(FC_RPORT_FAST_FAIL_TIMEDOUT |
+				  FC_RPORT_DEVLOSS_PENDING |
+				  FC_RPORT_DEVLOSS_CALLBK_DONE);
+		spin_unlock_irqrestore(shost->host_lock, flags);
+
+		/* ensure any stgt delete functions are done */
+		fc_flush_work(shost);
+
+		if (rport->roles & FC_PORT_ROLE_FCP_TARGET) {
+			scsi_target_unblock(&rport->dev, SDEV_RUNNING);
+			/* initiate a scan of the target */
+			spin_lock_irqsave(shost->host_lock, flags);
+			rport->flags |= FC_RPORT_SCAN_PENDING;
+			scsi_queue_work(shost, &rport->scan_work);
+			spin_unlock_irqrestore(shost->host_lock, flags);
+		}
+	} else
+		return -EINVAL;
+
+	return count;
+}
+
+static ssize_t
+show_fc_rport_port_state (struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct fc_rport *rport = transport_class_to_rport(dev);
+	const char *name;
+
+	name = get_fc_port_state_name(rport->port_state);
+	if (!name)
+		return -EINVAL;
+	return snprintf(buf, FC_PORTSTATE_MAX_NAMELEN, "%s\n", name);
+}
+
+static FC_DEVICE_ATTR(rport, port_state, S_IRUGO | S_IWUSR,
+		show_fc_rport_port_state, store_fc_rport_port_state);
+
 fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20);
 
 /*
@@ -2289,7 +2360,7 @@ fc_attach_transport(struct fc_function_template *ft)
 	SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name);
 	SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id);
 	SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles);
-	SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state);
+	SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(port_state);
 	SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id);
 	SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo);
 

             reply	other threads:[~2013-01-15 15:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 15:02 Hannes Reinecke [this message]
2013-03-14 18:09 ` [PATCH] scsi_transport_fc: Make 'port_state' writeable Steffen Maier
2013-03-15 11:55   ` Hannes Reinecke
2013-03-15 12:01     ` Bryn M. Reeves
2013-03-15 12:24     ` Bart Van Assche
2013-03-15 12:37       ` Bryn M. Reeves
2013-03-15 12:46         ` Bart Van Assche
2013-03-15 13:28           ` Bryn M. Reeves
2013-03-15 13:41             ` Bart Van Assche
2013-03-15 18:51               ` Mike Christie
2013-03-15 19:13                 ` Bart Van Assche
2013-03-15 21:12                   ` Mike Christie
2013-03-18  7:09                   ` Hannes Reinecke
2013-04-01 21:06                     ` James Smart
2013-04-04  6:26                       ` Hannes Reinecke
2013-04-05 15:14                         ` James Smart
2013-04-12 14:24                           ` Chad Dupuis
2013-03-18 21:54             ` Jeremy Linton
2013-04-01 20:51     ` James Smart

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=1358262138-13378-1-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=andrew.vasquez@qlogic.com \
    --cc=chad.dupuis@qlogic.com \
    --cc=james.smart@emulex.com \
    --cc=jbottomley@parallels.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=michaelc@cs.wisc.edu \
    /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