All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Jeff Garzik <jeff@garzik.org>
Cc: linux-ide@vger.kernel.org
Subject: Re: [RFC] Read/Write Buffer support
Date: Sat, 15 Mar 2008 18:46:09 -0600	[thread overview]
Message-ID: <20080316004609.GZ613@parisc-linux.org> (raw)
In-Reply-To: <47DC5223.6080105@garzik.org>

On Sat, Mar 15, 2008 at 06:48:03PM -0400, Jeff Garzik wrote:
> You arrived at the proper conclusion -- it doesn't happen in practice 
> for a variety of reasons, the main one being that it's largely in the 
> realm of something the superuser must do intentionally, the way kernel 
> and userland code is written today.

I think it could easily happen accidentally.  In any case, it's worth
fxing.

> Thus, the code intentionally avoids the silly complexity for a case that 
> never truly happens outside of synthetic superuser experiments.
> 
> Remember, this and all the other code originated in the days of "if 
> (use_sg)", when scatterlists were not used often for !(read|write) commands.

I have no desire to increase the complexity of libata, but I think it's
possible to fix this in a couple of different ways without adding extra
complexity.

One possible way would be for simulate to allocate a page and pass that
into the actor functions to fill in.  Then simulate could copy that page
into the sg lists.  This doesn't fix my problem where I need to
part-simulate, part-translate, but it's a possible solution for all the
various inquiries.

Another would be for the actor functions to set up their own buffers and
call something similar to the copy_buffer() function I had as part of
the scsi_ram driver I wrote.  I happened to write it for the use of
INQUIRY too ;-)

+static void copy_buffer(struct scsi_cmnd *cmnd, char *buf, int len)
+{
+       char *p;
+       struct scatterlist *sg;
+       int i;
+
+       scsi_for_each_sg(cmnd, sg, scsi_sg_count(cmnd), i) {
+               int tocopy = sg->length;
+               if (tocopy > len)
+                       tocopy = len;
+
+               p = kmap_atomic(sg_page(sg), KM_USER0);
+               memcpy(p + sg->offset, buf, tocopy);
+               kunmap_atomic(p, KM_USER0);
+
+               len -= tocopy;
+               if (!len)
+                       break;
+               buf += tocopy;
+       }
+
+       scsi_set_resid(cmnd, len);
+}

> P.S.  I encourage others to investigate making the libata SCSI simulator 
> an optional kernel module.
> 
> Long term, a preferred solution would be to use SCSI layer for ATAPI 
> devices, and a kernel block device for ATA devices.

I think that's the right method to take, though we probably still want
to emulate the scsi ioctls.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  parent reply	other threads:[~2008-03-16  0:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-15 15:37 [RFC] Read/Write Buffer support Matthew Wilcox
2008-03-15 17:18 ` Jeff Garzik
2008-03-15 17:49   ` Matthew Wilcox
2008-03-15 22:48     ` Jeff Garzik
2008-03-15 23:09       ` Alan Cox
2008-03-16  0:46       ` Matthew Wilcox [this message]
2008-03-16  1:47         ` 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=20080316004609.GZ613@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=jeff@garzik.org \
    --cc=linux-ide@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 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.