From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
To: htejun@gmail.com
Cc: jeff@garzik.org, linux-ide@vger.kernel.org, petr@vmware.com
Subject: Re: [PATCH #upstream-fixes 2/2] libata-scsi: improve rbuf handling for simulated commands
Date: Mon, 28 Apr 2008 17:37:35 +0900 [thread overview]
Message-ID: <20080428173834Z.tomof@acm.org> (raw)
In-Reply-To: <48158826.8070209@gmail.com>
On Mon, 28 Apr 2008 17:17:42 +0900
Tejun Heo <htejun@gmail.com> wrote:
> Buffer length handling in simulated commands is error-prone and full
> of bugs. There are a number of places where necessary length checks
> are missing and if the output buffer is passed in as sglist, nothing
> works.
>
> This patch adds a static buffer ata_scsi_rbuf which is sufficiently
> large to handle the larges output from simulated commands (4k
> currently), let all simulte functions write to the buffer and removes
> all length checks as we know that there always is enough buffer space.
> Copying in (for ATAPI inquiry fix up) and out are handled by
> ata_scsi_copy_rbuf() behind ata_scsi_rbuf_get/put() interface and
> sglist is handled properly.
>
> This patch is inspired from buffer length check fix patch from Petr
> Vandrovec.
>
> Signed-off-by: Tejun Heo <htejun@gmail.com>
> Cc: Petr Vandrovec <petr@vmware.com>
> ---
> drivers/ata/libata-scsi.c | 471 +++++++++++++++++-----------------------------
> 1 file changed, 180 insertions(+), 291 deletions(-)
>
> Index: work/drivers/ata/libata-scsi.c
> ===================================================================
> --- work.orig/drivers/ata/libata-scsi.c
> +++ work/drivers/ata/libata-scsi.c
> @@ -49,7 +49,11 @@
>
> #include "libata.h"
>
> -#define SECTOR_SIZE 512
> +#define SECTOR_SIZE 512
> +#define ATA_SCSI_RBUF_SIZE 4096
> +
> +static DEFINE_SPINLOCK(ata_scsi_rbuf_lock);
> +static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE];
>
> typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc);
>
> @@ -1637,55 +1641,75 @@ defer:
> return SCSI_MLQUEUE_HOST_BUSY;
> }
>
> +static void ata_scsi_copy_rbuf(struct scsi_cmnd *cmd, bool out)
> +{
> + char *data = ata_scsi_rbuf;
> + unsigned int left = ATA_SCSI_RBUF_SIZE;
> + struct scatterlist *sg;
> + unsigned int si;
> +
> + for_each_sg(scsi_sglist(cmd), sg, scsi_sg_count(cmd), si) {
> + unsigned int len = min_t(unsigned int, sg->length, left);
> + char *page;
> +
> + page = kmap_atomic(sg_page(sg), KM_IRQ0);
> +
> + if (out)
> + memcpy(page + sg->offset, data, len);
> + else
> + memcpy(data, page + sg->offset, len);
> + data += len;
> + left -= len;
> +
> + kunmap_atomic(page, KM_IRQ0);
> +
> + if (!left)
> + break;
> + }
> +}
How about using sg_copy_from_buffer and sg_copy_to_buffer in
lib/scatterlist.c?
next prev parent reply other threads:[~2008-04-28 8:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-28 8:16 [PATCH #upstream-fixes 1/2] libata-scsi: clean up inquiry / mode sense related functions Tejun Heo
2008-04-28 8:17 ` [PATCH #upstream-fixes 2/2] libata-scsi: improve rbuf handling for simulated commands Tejun Heo
2008-04-28 8:23 ` Petr Vandrovec
2008-04-28 8:37 ` FUJITA Tomonori [this message]
2008-04-28 8:48 ` [PATCH #upstream-fixes 2/2 UPDATED] " Tejun Heo
2008-04-29 6:18 ` Jeff Garzik
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=20080428173834Z.tomof@acm.org \
--to=fujita.tomonori@lab.ntt.co.jp \
--cc=htejun@gmail.com \
--cc=jeff@garzik.org \
--cc=linux-ide@vger.kernel.org \
--cc=petr@vmware.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).