linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 30/39] scsi: centralize command re-queueing in scsi_dispatch_fn
Date: Mon, 17 Mar 2014 06:28:03 -0700	[thread overview]
Message-ID: <20140317133135.836674066@bombadil.infradead.org> (raw)
In-Reply-To: 20140317132733.789623766@bombadil.infradead.org

[-- Attachment #1: 0030-scsi-centralize-command-re-queueing-in-scsi_dispatch.patch --]
[-- Type: text/plain, Size: 3248 bytes --]

Make sure we only have the logic for requeing commands in one place.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/scsi.c     |   36 +++++++++++++-----------------------
 drivers/scsi/scsi_lib.c |    9 ++++++---
 2 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 0e8a077..0df3913 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -639,9 +639,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
 		 * returns an immediate error upwards, and signals
 		 * that the device is no longer present */
 		cmd->result = DID_NO_CONNECT << 16;
-		scsi_done(cmd);
-		/* return 0 (because the command has been processed) */
-		goto out;
+		goto done;
 	}
 
 	/* Check to see if the scsi lld made this device blocked. */
@@ -653,16 +651,8 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
 		 * occur until the device transitions out of the
 		 * suspend state.
 		 */
-
-		scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
-
 		SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n"));
-
-		/*
-		 * NOTE: rtn is still zero here because we don't need the
-		 * queue to be plugged on return (it's already stopped)
-		 */
-		goto out;
+		return SCSI_MLQUEUE_DEVICE_BUSY;
 	}
 
 	/* 
@@ -686,35 +676,35 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
 			       "cdb_size=%d host->max_cmd_len=%d\n",
 			       cmd->cmd_len, cmd->device->host->max_cmd_len));
 		cmd->result = (DID_ABORT << 16);
-
-		scsi_done(cmd);
-		goto out;
+		goto done;
 	}
 
 	if (unlikely(host->shost_state == SHOST_DEL)) {
 		cmd->result = (DID_NO_CONNECT << 16);
-		scsi_done(cmd);
-	} else {
-		trace_scsi_dispatch_cmd_start(cmd);
-		cmd->scsi_done = scsi_done;
-		rtn = host->hostt->queuecommand(host, cmd);
+		goto done;
+
 	}
 
+	trace_scsi_dispatch_cmd_start(cmd);
+
+	cmd->scsi_done = scsi_done;
+	rtn = host->hostt->queuecommand(host, cmd);
 	if (rtn) {
 		trace_scsi_dispatch_cmd_error(cmd, rtn);
 		if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
 		    rtn != SCSI_MLQUEUE_TARGET_BUSY)
 			rtn = SCSI_MLQUEUE_HOST_BUSY;
 
-		scsi_queue_insert(cmd, rtn);
-
 		SCSI_LOG_MLQUEUE(3,
 		    printk("queuecommand : request rejected\n"));
 	}
 
- out:
 	SCSI_LOG_MLQUEUE(3, printk("leaving scsi_dispatch_cmnd()\n"));
 	return rtn;
+ done:
+	SCSI_LOG_MLQUEUE(3, printk("scsi_dispatch_cmnd() failed\n"));
+	scsi_done(cmd);
+	return 0;
 }
 
 /**
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9889c75..53d06e8 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1598,9 +1598,12 @@ static void scsi_request_fn(struct request_queue *q)
 		 * Dispatch the command to the low-level driver.
 		 */
 		rtn = scsi_dispatch_cmd(cmd);
-		spin_lock_irq(q->queue_lock);
-		if (rtn)
+		if (rtn) {
+			scsi_queue_insert(cmd, rtn);
+			spin_lock_irq(q->queue_lock);
 			goto out_delay;
+		}
+		spin_lock_irq(q->queue_lock);
 	}
 
 	return;
@@ -1620,7 +1623,7 @@ static void scsi_request_fn(struct request_queue *q)
 	blk_requeue_request(q, req);
 	atomic_dec(&sdev->device_busy);
 out_delay:
-	if (atomic_read(&sdev->device_busy) == 0)
+	if (atomic_read(&sdev->device_busy) == 0 && !scsi_device_blocked(sdev))
 		blk_delay_queue(q, SCSI_QUEUE_DELAY);
 }
 
-- 
1.7.10.4



  parent reply	other threads:[~2014-03-17 13:37 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-17 13:27 [PATCH 00/39] [WIP] scsi multiqueue Christoph Hellwig
2014-03-17 13:27 ` [PATCH 01/39] block: fix q->flush_rq NULL pointer crash on dm-mpath flush Christoph Hellwig
2014-03-17 13:27 ` [PATCH 02/39] block: change flush sequence list addition back to front add Christoph Hellwig
2014-03-17 13:27 ` [PATCH 03/39] blk-mq: fix blk_mq_end_io_partial Christoph Hellwig
2014-03-17 13:27 ` [PATCH 04/39] blk-mq: initialize resid_len Christoph Hellwig
2014-03-17 13:27 ` [PATCH 05/39] blk-mq: replace blk_mq_init_commands with a ->init_request method Christoph Hellwig
2014-03-17 13:27 ` [PATCH 06/39] blk-mq: add a exit_request method Christoph Hellwig
2014-03-17 13:27 ` [PATCH 07/39] scsi: avoid useless free_list lock roundtrips Christoph Hellwig
2014-03-17 13:27 ` [PATCH 08/39] scsi: avoid taking host_lock in scsi_run_queue unless nessecary Christoph Hellwig
2014-03-17 13:27 ` [PATCH 09/39] scsi: do not manipulate device reference counts in scsi_get/put_command Christoph Hellwig
2014-03-17 13:27 ` [PATCH 10/39] scsi: remove a useless get/put_device pair in scsi_request_fn Christoph Hellwig
2014-03-17 13:27 ` [PATCH 11/39] scsi: remove a useless get/put_device pair in scsi_next_command Christoph Hellwig
2014-03-17 13:27 ` [PATCH 12/39] scsi: remove a useless get/put_device pair in scsi_requeue_command Christoph Hellwig
2014-03-17 13:27 ` [PATCH 13/39] megaraid: simplify internal command handling Christoph Hellwig
2014-03-21  1:12   ` adam radford
2014-03-17 13:27 ` [PATCH 14/39] scsi: simplify command allocation and freeing a bit Christoph Hellwig
2014-03-17 13:27 ` [PATCH 15/39] scsi: add support for per-host cmd pools Christoph Hellwig
2014-03-17 13:27 ` [PATCH 16/39] virtio_scsi: use cmd_size Christoph Hellwig
2014-03-25 15:31   ` Christoph Hellwig
2014-03-25 15:36     ` Paolo Bonzini
2014-03-27 15:28       ` James Bottomley
2014-03-17 13:27 ` [PATCH 17/39] scsi: explicitly release bidi buffers Christoph Hellwig
2014-03-17 13:27 ` [PATCH 18/39] scsi: remove scsi_end_request Christoph Hellwig
2014-03-17 13:27 ` [PATCH 19/39] scsi: push host_lock down into scsi_{host,target}_queue_ready Christoph Hellwig
2014-03-17 13:27 ` [PATCH 20/39] scsi: convert target_busy to an atomic_t Christoph Hellwig
2014-03-17 13:27 ` [PATCH 21/39] scsi: convert host_busy to atomic_t Christoph Hellwig
2014-03-17 13:27 ` [PATCH 22/39] scsi: convert device_busy " Christoph Hellwig
2014-03-17 13:27 ` [PATCH 23/39] scsi: fix the {host,target,device}_blocked counter mess Christoph Hellwig
2014-03-17 13:27 ` [PATCH 24/39] blk-mq: add blk_mq_requeue_request Christoph Hellwig
2014-03-17 13:27 ` [PATCH 25/39] blk-mq: add async paramter to blk_mq_start_stopped_hw_queues Christoph Hellwig
2014-03-17 13:27 ` [PATCH 26/39] HACK: support blk_delay_queue for blk-mq Christoph Hellwig
2014-03-17 13:28 ` [PATCH 27/39] blk-mq: export blk_mq_insert_request Christoph Hellwig
2014-03-17 13:28 ` [PATCH 28/39] scsi: reintroduce scsi_driver.init_command Christoph Hellwig
2014-03-26  9:46   ` Christoph Hellwig
2014-03-17 13:28 ` [PATCH 29/39] block: remove unprep_rq_fn Christoph Hellwig
2014-03-17 13:28 ` Christoph Hellwig [this message]
2014-03-17 13:28 ` [PATCH 31/39] scsi: split __scsi_queue_insert Christoph Hellwig
2014-03-17 13:28 ` [PATCH 32/39] scsi: unwind blk_end_request_all and blk_end_request_err calls Christoph Hellwig
2014-03-17 13:28 ` [PATCH 33/39] scsi: initial blk-mq support Christoph Hellwig
2014-03-17 13:28 ` [PATCH 34/39] scsi: partially stub out scsi_adjust_queue_depth when using blk-mq Christoph Hellwig
2014-03-17 13:28 ` [PATCH 35/39] virtio_scsi: use blk_mq Christoph Hellwig
2014-03-17 13:28 ` [PATCH 36/39] iscsi_tcp: " Christoph Hellwig
2014-03-17 13:28 ` [PATCH 37/39] ata_piix: " Christoph Hellwig
2014-03-17 13:28 ` [PATCH 38/39] blk-mq: make blk_mq_start_stopped_hw_queues run a queue even if not stopped Christoph Hellwig
2014-03-17 13:28 ` [PATCH 39/39] scsi: implement ->init_request and ->exit_request Christoph Hellwig
2014-03-17 13:33 ` [PATCH 00/39] [WIP] scsi multiqueue Christoph Hellwig

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=20140317133135.836674066@bombadil.infradead.org \
    --to=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).