From: Christoph Hellwig <hch@lst.de>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org
Subject: [PATCH 06/10] sd: don't use scsi_setup_blk_pc_cmnd for discard requests
Date: Sun, 29 Jun 2014 15:34:37 +0200 [thread overview]
Message-ID: <1404048881-19526-7-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1404048881-19526-1-git-send-email-hch@lst.de>
Simplify handling of discard requests by setting up the command directly
instead of initializing request fields and then calling
scsi_setup_blk_pc_cmnd to propagate the information into the command.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/scsi/sd.c | 43 ++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 25f25dd..9737e78 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -691,8 +691,10 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
* Will issue either UNMAP or WRITE SAME(16) depending on preference
* indicated by target device.
**/
-static int sd_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
+static int sd_setup_discard_cmnd(struct scsi_cmnd *cmd)
{
+ struct request *rq = cmd->request;
+ struct scsi_device *sdp = cmd->device;
struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
sector_t sector = blk_rq_pos(rq);
unsigned int nr_sectors = blk_rq_sectors(rq);
@@ -704,9 +706,6 @@ static int sd_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
sector >>= ilog2(sdp->sector_size) - 9;
nr_sectors >>= ilog2(sdp->sector_size) - 9;
- rq->timeout = SD_TIMEOUT;
-
- memset(rq->cmd, 0, rq->cmd_len);
page = alloc_page(GFP_ATOMIC | __GFP_ZERO);
if (!page)
@@ -716,9 +715,9 @@ static int sd_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
case SD_LBP_UNMAP:
buf = page_address(page);
- rq->cmd_len = 10;
- rq->cmd[0] = UNMAP;
- rq->cmd[8] = 24;
+ cmd->cmd_len = 10;
+ cmd->cmnd[0] = UNMAP;
+ cmd->cmnd[8] = 24;
put_unaligned_be16(6 + 16, &buf[0]);
put_unaligned_be16(16, &buf[2]);
@@ -729,23 +728,23 @@ static int sd_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
break;
case SD_LBP_WS16:
- rq->cmd_len = 16;
- rq->cmd[0] = WRITE_SAME_16;
- rq->cmd[1] = 0x8; /* UNMAP */
- put_unaligned_be64(sector, &rq->cmd[2]);
- put_unaligned_be32(nr_sectors, &rq->cmd[10]);
+ cmd->cmd_len = 16;
+ cmd->cmnd[0] = WRITE_SAME_16;
+ cmd->cmnd[1] = 0x8; /* UNMAP */
+ put_unaligned_be64(sector, &cmd->cmnd[2]);
+ put_unaligned_be32(nr_sectors, &cmd->cmnd[10]);
len = sdkp->device->sector_size;
break;
case SD_LBP_WS10:
case SD_LBP_ZERO:
- rq->cmd_len = 10;
- rq->cmd[0] = WRITE_SAME;
+ cmd->cmd_len = 10;
+ cmd->cmnd[0] = WRITE_SAME;
if (sdkp->provisioning_mode == SD_LBP_WS10)
- rq->cmd[1] = 0x8; /* UNMAP */
- put_unaligned_be32(sector, &rq->cmd[2]);
- put_unaligned_be16(nr_sectors, &rq->cmd[7]);
+ cmd->cmnd[1] = 0x8; /* UNMAP */
+ put_unaligned_be32(sector, &cmd->cmnd[2]);
+ put_unaligned_be16(nr_sectors, &cmd->cmnd[7]);
len = sdkp->device->sector_size;
break;
@@ -756,8 +755,14 @@ static int sd_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
}
rq->completion_data = page;
+ rq->timeout = SD_TIMEOUT;
+
blk_add_request_payload(rq, page, len);
- ret = scsi_setup_blk_pc_cmnd(sdp, rq);
+
+ cmd->transfersize = len;
+ cmd->allowed = rq->retries;
+
+ ret = scsi_init_io(cmd, GFP_ATOMIC);
rq->__data_len = nr_bytes;
out:
@@ -903,7 +908,7 @@ static int sd_init_command(struct scsi_cmnd *SCpnt)
* block PC requests to make life easier.
*/
if (rq->cmd_flags & REQ_DISCARD) {
- ret = sd_setup_discard_cmnd(sdp, rq);
+ ret = sd_setup_discard_cmnd(SCpnt);
goto out;
} else if (rq->cmd_flags & REQ_WRITE_SAME) {
ret = sd_setup_write_same_cmnd(SCpnt);
--
1.7.10.4
next prev parent reply other threads:[~2014-06-29 13:32 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-29 13:34 RFC: clean up command setup Christoph Hellwig
2014-06-29 13:34 ` [PATCH 01/10] scsi: move the nr_phys_segments assert into scsi_init_io Christoph Hellwig
2014-07-11 12:17 ` Hannes Reinecke
2014-07-13 14:03 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 02/10] scsi: restructure command initialization for TYPE_FS requests Christoph Hellwig
2014-07-11 12:18 ` Hannes Reinecke
2014-07-13 14:04 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 03/10] scsi: set sc_data_direction in common code Christoph Hellwig
2014-07-11 12:19 ` Hannes Reinecke
2014-07-13 14:06 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 04/10] sd: don't use scsi_setup_blk_pc_cmnd for flush requests Christoph Hellwig
2014-07-11 12:20 ` Hannes Reinecke
2014-07-13 14:07 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 05/10] sd: don't use scsi_setup_blk_pc_cmnd for write same requests Christoph Hellwig
2014-07-11 12:25 ` Hannes Reinecke
2014-07-11 15:15 ` Christoph Hellwig
2014-07-13 14:14 ` Martin K. Petersen
2014-07-17 15:29 ` Christoph Hellwig
2014-06-29 13:34 ` Christoph Hellwig [this message]
2014-07-07 0:01 ` [PATCH 06/10] sd: don't use scsi_setup_blk_pc_cmnd for discard requests Elliott, Robert (Server Storage)
2014-07-07 2:01 ` Elliott, Robert (Server Storage)
2014-07-07 9:24 ` Christoph Hellwig
2014-07-11 12:26 ` Hannes Reinecke
2014-07-11 15:15 ` Christoph Hellwig
2014-07-13 14:35 ` Martin K. Petersen
2014-07-13 14:52 ` Douglas Gilbert
2014-07-13 14:56 ` Christoph Hellwig
2014-07-13 15:03 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 07/10] sd: retry write same commands Christoph Hellwig
2014-07-11 12:26 ` Hannes Reinecke
2014-07-13 14:36 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 08/10] sd: retry discard commands Christoph Hellwig
2014-07-11 12:27 ` Hannes Reinecke
2014-07-13 14:36 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 09/10] sd: split sd_init_command Christoph Hellwig
2014-07-11 12:33 ` Hannes Reinecke
2014-07-13 14:37 ` Martin K. Petersen
2014-06-29 13:34 ` [PATCH 10/10] scsi: mark scsi_setup_blk_pc_cmnd static Christoph Hellwig
2014-07-11 12:33 ` Hannes Reinecke
2014-07-13 14:38 ` Martin K. Petersen
2014-07-11 9:16 ` RFC: clean up command setup 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=1404048881-19526-7-git-send-email-hch@lst.de \
--to=hch@lst.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).