From: FUJITA Tomonori <tomof@acm.org>
To: stern@rowland.harvard.edu
Cc: fujita.tomonori@lab.ntt.co.jp, tomof@acm.org,
bharrosh@panasas.com, linux-ide@vger.kernel.org,
linux-scsi@vger.kernel.org,
James.Bottomley@HansenPartnership.com, jens.axboe@oracle.com,
dougg@torque.net, Geert.Uytterhoeven@sonycom.com,
tony.luck@intel.com, Mark_Salyzyn@adaptec.com,
ed.lin@promise.com, linuxraid@amcc.com,
linux-usb@vger.kernel.orgfujita.tomonori@lab.ntt.co.jp
Subject: Re: [PATCH 00/10] sg buffer copy helper functions
Date: Thu, 13 Mar 2008 09:03:26 +0900 [thread overview]
Message-ID: <20080313090258Z.tomof@acm.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0803121202150.4595-100000@iolanthe.rowland.org>
On Wed, 12 Mar 2008 12:04:26 -0400 (EDT)
Alan Stern <stern@rowland.harvard.edu> wrote:
> On Wed, 12 Mar 2008, FUJITA Tomonori wrote:
>
> > It enables us to simplify usb_stor_access_xfer_buf like this, I think
> > (it's not tested).
> >
> > diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
> > index b9b8ede..0992809 100644
> > --- a/drivers/usb/storage/protocol.c
> > +++ b/drivers/usb/storage/protocol.c
> > @@ -156,70 +156,11 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
> > unsigned int buflen, struct scsi_cmnd *srb, struct scatterlist **sgptr,
> > unsigned int *offset, enum xfer_buf_dir dir)
> > {
> > - unsigned int cnt;
> > - struct scatterlist *sg = *sgptr;
> > -
> > - /* We have to go through the list one entry
> > - * at a time. Each s-g entry contains some number of pages, and
> > - * each page has to be kmap()'ed separately. If the page is already
> > - * in kernel-addressable memory then kmap() will return its address.
> > - * If the page is not directly accessible -- such as a user buffer
> > - * located in high memory -- then kmap() will map it to a temporary
> > - * position in the kernel's virtual address space.
> > - */
> > -
> > - if (!sg)
> > - sg = scsi_sglist(srb);
> > + if (!*sgptr)
> > + *sgptr = scsi_sglist(srb);
> >
> > - /* This loop handles a single s-g list entry, which may
> > - * include multiple pages. Find the initial page structure
> > - * and the starting offset within the page, and update
> > - * the *offset and **sgptr values for the next loop.
> > - */
> > - cnt = 0;
> > - while (cnt < buflen && sg) {
> > - struct page *page = sg_page(sg) +
> > - ((sg->offset + *offset) >> PAGE_SHIFT);
> > - unsigned int poff = (sg->offset + *offset) & (PAGE_SIZE-1);
> > - unsigned int sglen = sg->length - *offset;
> > -
> > - if (sglen > buflen - cnt) {
> > -
> > - /* Transfer ends within this s-g entry */
> > - sglen = buflen - cnt;
> > - *offset += sglen;
> > - } else {
> > -
> > - /* Transfer continues to next s-g entry */
> > - *offset = 0;
> > - sg = sg_next(sg);
> > - }
> > -
> > - /* Transfer the data for all the pages in this
> > - * s-g entry. For each page: call kmap(), do the
> > - * transfer, and call kunmap() immediately after. */
> > - while (sglen > 0) {
> > - unsigned int plen = min(sglen, (unsigned int)
> > - PAGE_SIZE - poff);
> > - unsigned char *ptr = kmap(page);
> > -
> > - if (dir == TO_XFER_BUF)
> > - memcpy(ptr + poff, buffer + cnt, plen);
> > - else
> > - memcpy(buffer + cnt, ptr + poff, plen);
> > - kunmap(page);
> > -
> > - /* Start at the beginning of the next page */
> > - poff = 0;
> > - ++page;
> > - cnt += plen;
> > - sglen -= plen;
> > - }
> > - }
> > - *sgptr = sg;
> > -
> > - /* Return the amount actually transferred */
> > - return cnt;
> > + return sg_copy_buffer(sgptr, scsi_sg_count(srb),
> > + offset, buffer, buflen, dir != TO_XFER_BUF);
> > }
>
> It's a big simplification!
>
> There are two problems. One is the types of the arguments and return
> value.
They should be ok with the updated patch.
> The other is that local interrupts need to be disabled.
Can you disable local interrupts here?
Basically, the APIs are used in queuecommand.
next prev parent reply other threads:[~2008-03-13 0:05 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-09 4:44 [PATCH 00/10] sg buffer copy helper functions FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 01/10] block: add " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 02/10] scsi: add wrapper functions for " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 03/10] scsi_debug: use " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 04/10] ps3rom: use sg buffer copy helper funcitons FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 05/10] simscsi: " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 06/10] ips: " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 07/10] aacraid: use sg buffer copy helper functions FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 08/10] stex: " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 09/10] 3w-xxxx: " FUJITA Tomonori
2008-03-09 4:44 ` [PATCH 10/10] 3w-9xxx: " FUJITA Tomonori
2008-03-10 12:45 ` [PATCH 07/10] aacraid: " Mark Salyzyn
2008-03-10 12:46 ` [PATCH 06/10] ips: use sg buffer copy helper funcitons Mark Salyzyn
2008-03-10 10:15 ` [PATCH 04/10] ps3rom: " Geert Uytterhoeven
2008-03-10 14:37 ` [PATCH 01/10] block: add sg buffer copy helper functions Jens Axboe
2008-03-10 10:14 ` [PATCH 00/10] " Geert Uytterhoeven
2008-03-10 14:34 ` FUJITA Tomonori
[not found] ` <1205037877-12843-1-git-send-email-fujita.tomonori-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org>
2008-03-10 14:10 ` Boaz Harrosh
2008-03-10 22:39 ` FUJITA Tomonori
2008-03-11 10:05 ` Boaz Harrosh
2008-03-11 20:09 ` Alan Stern
2008-03-12 0:14 ` FUJITA Tomonori
2008-03-12 0:28 ` FUJITA Tomonori
2008-03-12 2:24 ` FUJITA Tomonori
2008-03-12 16:04 ` Alan Stern
2008-03-13 0:03 ` FUJITA Tomonori [this message]
2008-03-13 0:18 ` FUJITA Tomonori
2008-03-13 18:34 ` Alan Stern
2008-03-12 16:01 ` Alan Stern
2008-03-12 16:26 ` Boaz Harrosh
2008-03-13 0:03 ` FUJITA Tomonori
2008-03-13 18:32 ` Alan Stern
2008-03-14 9:35 ` FUJITA Tomonori
[not found] ` <20080314183434J.tomof-HInyCGIudOg@public.gmane.org>
2008-03-14 14:46 ` Alan Stern
2008-03-16 11:55 ` FUJITA Tomonori
2008-03-16 17:18 ` Alan Stern
2008-03-17 3:23 ` FUJITA Tomonori
2008-03-17 14:06 ` Alan Stern
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=20080313090258Z.tomof@acm.org \
--to=tomof@acm.org \
--cc=Geert.Uytterhoeven@sonycom.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=Mark_Salyzyn@adaptec.com \
--cc=bharrosh@panasas.com \
--cc=dougg@torque.net \
--cc=ed.lin@promise.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=jens.axboe@oracle.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-usb@vger.kernel.orgfujita.tomonori \
--cc=linuxraid@amcc.com \
--cc=stern@rowland.harvard.edu \
--cc=tony.luck@intel.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.