All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>,
	James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH 05/10] sd: don't use scsi_setup_blk_pc_cmnd for write same requests
Date: Fri, 11 Jul 2014 14:25:05 +0200	[thread overview]
Message-ID: <53BFD7A1.7040205@suse.de> (raw)
In-Reply-To: <1404048881-19526-6-git-send-email-hch@lst.de>

On 06/29/2014 03:34 PM, Christoph Hellwig wrote:
> Simplify handling of write same 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 |   44 ++++++++++++++++++++++++++++----------------
>   1 file changed, 28 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 620d32f..25f25dd 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -799,14 +799,15 @@ out:
>
>   /**
>    * sd_setup_write_same_cmnd - write the same data to multiple blocks
> - * @sdp: scsi device to operate one
> - * @rq: Request to prepare
> + * @cmd: command to prepare
>    *
>    * Will issue either WRITE SAME(10) or WRITE SAME(16) depending on
>    * preference indicated by target device.
>    **/
> -static int sd_setup_write_same_cmnd(struct scsi_device *sdp, struct request *rq)
> +static int sd_setup_write_same_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);
>   	struct bio *bio = rq->bio;
>   	sector_t sector = blk_rq_pos(rq);
> @@ -822,25 +823,36 @@ static int sd_setup_write_same_cmnd(struct scsi_device *sdp, struct request *rq)
>   	sector >>= ilog2(sdp->sector_size) - 9;
>   	nr_sectors >>= ilog2(sdp->sector_size) - 9;
>
> -	rq->__data_len = sdp->sector_size;
>   	rq->timeout = SD_WRITE_SAME_TIMEOUT;
> -	memset(rq->cmd, 0, rq->cmd_len);
>
>   	if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff) {
> -		rq->cmd_len = 16;
> -		rq->cmd[0] = WRITE_SAME_16;
> -		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;
> +		put_unaligned_be64(sector, &cmd->cmnd[2]);
> +		put_unaligned_be32(nr_sectors, &cmd->cmnd[10]);
>   	} else {
> -		rq->cmd_len = 10;
> -		rq->cmd[0] = WRITE_SAME;
> -		put_unaligned_be32(sector, &rq->cmd[2]);
> -		put_unaligned_be16(nr_sectors, &rq->cmd[7]);
> +		cmd->cmd_len = 10;
> +		cmd->cmnd[0] = WRITE_SAME;
> +		put_unaligned_be32(sector, &cmd->cmnd[2]);
> +		put_unaligned_be16(nr_sectors, &cmd->cmnd[7]);
>   	}
>
> -	ret = scsi_setup_blk_pc_cmnd(sdp, rq);
> -	rq->__data_len = nr_bytes;
> +	cmd->transfersize = sdp->sector_size;
> +	cmd->allowed = rq->retries;
>
> +	/*
> +	 * For WRITE_SAME the data transferred in the DATA IN buffer is
> +	 * different from the amount of data actually written to the target.
> +	 *
> +	 * We set up __data_len to the amount of data transferred from the
> +	 * DATA IN buffer so that blk_rq_map_sg set up the proper S/G list
> +	 * to transfer a single sector of data first, but then reset it to
> +	 * the amount of data to be written right after so that the I/O path
> +	 * knows how much to actually write.
> +	 */
> +	rq->__data_len = sdp->sector_size;
> +	ret = scsi_init_io(cmd, GFP_ATOMIC);
> +	rq->__data_len = nr_bytes;
>   	return ret;
>   }
>
Hmm? __data_len is the amount of data written _on the target_.
Do we actually care about it?
And if so, why didn't it break with the original version?
In either case a short description in the patch would be nice.

> @@ -894,7 +906,7 @@ static int sd_init_command(struct scsi_cmnd *SCpnt)
>   		ret = sd_setup_discard_cmnd(sdp, rq);
>   		goto out;
>   	} else if (rq->cmd_flags & REQ_WRITE_SAME) {
> -		ret = sd_setup_write_same_cmnd(sdp, rq);
> +		ret = sd_setup_write_same_cmnd(SCpnt);
>   		goto out;
>   	} else if (rq->cmd_flags & REQ_FLUSH) {
>   		ret = sd_setup_flush_cmnd(SCpnt);
>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-07-11 12:25 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 [this message]
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 ` [PATCH 06/10] sd: don't use scsi_setup_blk_pc_cmnd for discard requests Christoph Hellwig
2014-07-07  0:01   ` 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=53BFD7A1.7040205@suse.de \
    --to=hare@suse.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=hch@lst.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.