mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] scsi: export busy state for request stacking drivers
@ 2008-10-04 18:03 Kiyoshi Ueda
  2008-10-04 18:11 ` [PATCH 1/2] scsi: refactor sdev/starget/shost busy checking Kiyoshi Ueda
  2008-10-04 18:11 ` [PATCH 2/2] scsi: export busy state via q->lld_busy_fn() Kiyoshi Ueda
  0 siblings, 2 replies; 3+ messages in thread
From: Kiyoshi Ueda @ 2008-10-04 18:03 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-kernel, linux-scsi, dm-devel, j-nomura, k-ueda

Hi James,

The following patches export busy-status of SCSI LLD to request-based
dm-multipath for proper I/O scheduling.
The patches are created on the following commit of scsi-post-merge-2.6.
---------------------------------------------------------------
commit 454f40af9f0d4cda1c89e1fc0028d5235b150bc7
Author: Mike Christie <michaelc@cs.wisc.edu>
Date:   Wed Sep 24 11:46:15 2008 -0500

    libiscsi: fix locking in iscsi_eh_device_reset
---------------------------------------------------------------

The changes from the previous version (*) is to check the busy state
everytime instead of using a cached flag inside scsi.

Summary of the patches:
  1/2: scsi: refactor sdev/starget/shost busy checking
  2/2: scsi: export busy state via q->lld_busy_fn()

Please review and apply.

Thanks,
Kiyoshi Ueda

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] scsi: refactor sdev/starget/shost busy checking
  2008-10-04 18:03 [PATCH 0/2] scsi: export busy state for request stacking drivers Kiyoshi Ueda
@ 2008-10-04 18:11 ` Kiyoshi Ueda
  2008-10-04 18:11 ` [PATCH 2/2] scsi: export busy state via q->lld_busy_fn() Kiyoshi Ueda
  1 sibling, 0 replies; 3+ messages in thread
From: Kiyoshi Ueda @ 2008-10-04 18:11 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-kernel, linux-scsi, dm-devel, j-nomura, k-ueda

This patch refactors the busy checking codes of scsi_device,
Scsi_Host and scsi_target.  There should be no functional change.

This is a preparation for another patch which exports scsi's busy
state to the block layer for request stacking drivers.


Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 drivers/scsi/scsi_lib.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

Index: scsi-post-merge-2.6/drivers/scsi/scsi_lib.c
===================================================================
--- scsi-post-merge-2.6.orig/drivers/scsi/scsi_lib.c
+++ scsi-post-merge-2.6/drivers/scsi/scsi_lib.c
@@ -529,6 +529,14 @@ static void scsi_single_lun_run(struct s
 	spin_unlock_irqrestore(shost->host_lock, flags);
 }
 
+static inline int scsi_device_is_busy(struct scsi_device *sdev)
+{
+	if (sdev->device_busy >= sdev->queue_depth || sdev->device_blocked)
+		return 1;
+
+	return 0;
+}
+
 static inline int scsi_target_is_busy(struct scsi_target *starget)
 {
 	return ((starget->can_queue > 0 &&
@@ -536,6 +544,15 @@ static inline int scsi_target_is_busy(st
 		 starget->target_blocked);
 }
 
+static inline int scsi_host_is_busy(struct Scsi_Host *shost)
+{
+	if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
+	    shost->host_blocked || shost->host_self_blocked)
+		return 1;
+
+	return 0;
+}
+
 /*
  * Function:	scsi_run_queue()
  *
@@ -558,11 +575,7 @@ static void scsi_run_queue(struct reques
 		scsi_single_lun_run(sdev);
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	while (!list_empty(&shost->starved_list) &&
-	       !shost->host_blocked && !shost->host_self_blocked &&
-		!((shost->can_queue > 0) &&
-		  (shost->host_busy >= shost->can_queue))) {
-
+	while (!list_empty(&shost->starved_list) && !scsi_host_is_busy(shost)) {
 		int flagset;
 
 		/*
@@ -1348,8 +1361,6 @@ int scsi_prep_fn(struct request_queue *q
 static inline int scsi_dev_queue_ready(struct request_queue *q,
 				  struct scsi_device *sdev)
 {
-	if (sdev->device_busy >= sdev->queue_depth)
-		return 0;
 	if (sdev->device_busy == 0 && sdev->device_blocked) {
 		/*
 		 * unblock after device_blocked iterates to zero
@@ -1363,7 +1374,7 @@ static inline int scsi_dev_queue_ready(s
 			return 0;
 		}
 	}
-	if (sdev->device_blocked)
+	if (scsi_device_is_busy(sdev))
 		return 0;
 
 	return 1;
@@ -1440,8 +1451,7 @@ static inline int scsi_host_queue_ready(
 			return 0;
 		}
 	}
-	if ((shost->can_queue > 0 && shost->host_busy >= shost->can_queue) ||
-	    shost->host_blocked || shost->host_self_blocked) {
+	if (scsi_host_is_busy(shost)) {
 		if (list_empty(&sdev->starved_entry))
 			list_add_tail(&sdev->starved_entry, &shost->starved_list);
 		return 0;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] scsi: export busy state via q->lld_busy_fn()
  2008-10-04 18:03 [PATCH 0/2] scsi: export busy state for request stacking drivers Kiyoshi Ueda
  2008-10-04 18:11 ` [PATCH 1/2] scsi: refactor sdev/starget/shost busy checking Kiyoshi Ueda
@ 2008-10-04 18:11 ` Kiyoshi Ueda
  1 sibling, 0 replies; 3+ messages in thread
From: Kiyoshi Ueda @ 2008-10-04 18:11 UTC (permalink / raw)
  To: James.Bottomley; +Cc: linux-kernel, linux-scsi, dm-devel, j-nomura, k-ueda

This patch implements q->lld_busy_fn() for scsi mid layer to export
its busy state for request stacking drivers.

For efficiency, no lock is taken to check the busy state of
shost/starget/sdev, since the returned value is not guaranteed and
may be changed after request stacking drivers call the function,
regardless of taking lock or not.

When scsi can't dispatch I/Os anymore and needs to kill I/Os
(e.g. !sdev), scsi needs to return 'not busy'.
Otherwise, request stacking drivers may hold requests forever.


Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 drivers/scsi/scsi_lib.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+)

Index: scsi-post-merge-2.6/drivers/scsi/scsi_lib.c
===================================================================
--- scsi-post-merge-2.6.orig/drivers/scsi/scsi_lib.c
+++ scsi-post-merge-2.6/drivers/scsi/scsi_lib.c
@@ -1465,6 +1465,37 @@ static inline int scsi_host_queue_ready(
 }
 
 /*
+ * Busy state exporting function for request stacking drivers.
+ *
+ * For efficiency, no lock is taken to check the busy state of
+ * shost/starget/sdev, since the returned value is not guaranteed and
+ * may be changed after request stacking drivers call the function,
+ * regardless of taking lock or not.
+ *
+ * When scsi can't dispatch I/Os anymore and needs to kill I/Os
+ * (e.g. !sdev), scsi needs to return 'not busy'.
+ * Otherwise, request stacking drivers may hold requests forever.
+ */
+static int scsi_lld_busy(struct request_queue *q)
+{
+	struct scsi_device *sdev = q->queuedata;
+	struct Scsi_Host *shost;
+	struct scsi_target *starget;
+
+	if (!sdev)
+		return 0;
+
+	shost = sdev->host;
+	starget = scsi_target(sdev);
+
+	if (scsi_host_in_recovery(shost) || scsi_host_is_busy(shost) ||
+	    scsi_target_is_busy(starget) || scsi_device_is_busy(sdev))
+		return 1;
+
+	return 0;
+}
+
+/*
  * Kill a request for a dead device
  */
 static void scsi_kill_request(struct request *req, struct request_queue *q)
@@ -1767,6 +1798,7 @@ struct request_queue *scsi_alloc_queue(s
 	blk_queue_prep_rq(q, scsi_prep_fn);
 	blk_queue_softirq_done(q, scsi_softirq_done);
 	blk_queue_rq_timed_out(q, scsi_times_out);
+	blk_queue_lld_busy(q, scsi_lld_busy);
 	return q;
 }
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-10-04 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-04 18:03 [PATCH 0/2] scsi: export busy state for request stacking drivers Kiyoshi Ueda
2008-10-04 18:11 ` [PATCH 1/2] scsi: refactor sdev/starget/shost busy checking Kiyoshi Ueda
2008-10-04 18:11 ` [PATCH 2/2] scsi: export busy state via q->lld_busy_fn() Kiyoshi Ueda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®