public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Higdon <jeremy@sgi.com>
To: Matthew Wilcox <willy@debian.org>
Cc: Christoph Hellwig <hch@lst.de>,
	Emoore@lsil.com, linux-scsi@vger.kernel.org
Subject: Re: [PATCH] fusion update to current APIs
Date: Fri, 11 Jun 2004 22:13:53 -0700	[thread overview]
Message-ID: <20040612051353.GA152829@sgi.com> (raw)
In-Reply-To: <20040612034518.GN24864@parcelfarce.linux.theplanet.co.uk>

On Sat, Jun 12, 2004 at 04:45:18AM +0100, Matthew Wilcox wrote:
> On Fri, Jun 11, 2004 at 05:36:08PM -0700, Jeremy Higdon wrote:
> > Christoph, the midlayer gets it wrong sometimes.
> 
> ... then the midlayer needs to get fixed rather than have all this code
> duplicated in a million different drivers with subtly different bugs in
> each one.

That makes sense to me.  In fact, I think we could just fix it in sg.
It's only a problem with the older sg interfaces that don't specify
a direction.

To review, the problem is that many sg1 and sg2 apps don't tightly
trim the reply length.  Thus, even though they're issuing a Write
command, they will set the reply length to a value greater than
SZ_SG_HEADER.

so in sg_write(), hp->dxfer_direction gets set to SG_DXFER_TO_FROM_DEV:
	if (input_size > 0)
                hp->dxfer_direction = (old_hdr.reply_len > SZ_SG_HEADER) ?
                    SG_DXFER_TO_FROM_DEV : SG_DXFER_TO_DEV;
        else
                hp->dxfer_direction = (mxsize > 0) ? SG_DXFER_FROM_DEV : SG_DXFER_NONE;

then in sg_common_write, the data direction of the SCSI request is
set to SCSI_DATA_READ:
        switch (hp->dxfer_direction) {
        case SG_DXFER_TO_FROM_DEV:
        case SG_DXFER_FROM_DEV:
                SRpnt->sr_data_direction = SCSI_DATA_READ;
                break;
        case SG_DXFER_TO_DEV:
                SRpnt->sr_data_direction = SCSI_DATA_WRITE;
                break;
        case SG_DXFER_UNKNOWN:
                SRpnt->sr_data_direction = SCSI_DATA_UNKNOWN;
                break;
        default:
                SRpnt->sr_data_direction = SCSI_DATA_NONE;
                break;
        }


Then when the host driver sends the Write command to the disk with the
data direction set the other way, you usually get a SCSI bus reset.

So we should probably put the direction interpretation in sg_write() near
the bottom just before calling sg_common_write().

Something like this, where sg_direction() does what the host drivers
are currently doing.  I haven't actually tried this yet, but I can
code something up and give it a whirl if folks would like (I'm a little
short on time tonight :-).

===== drivers/scsi/sg.c 1.90 vs edited =====
--- 1.90/drivers/scsi/sg.c	Sat May 29 10:57:23 2004
+++ edited/drivers/scsi/sg.c	Fri Jun 11 22:11:20 2004
@@ -552,11 +552,6 @@
 	hp->cmd_len = (unsigned char) cmd_size;
 	hp->iovec_count = 0;
 	hp->mx_sb_len = 0;
-	if (input_size > 0)
-		hp->dxfer_direction = (old_hdr.reply_len > SZ_SG_HEADER) ?
-		    SG_DXFER_TO_FROM_DEV : SG_DXFER_TO_DEV;
-	else
-		hp->dxfer_direction = (mxsize > 0) ? SG_DXFER_FROM_DEV : SG_DXFER_NONE;
 	hp->dxfer_len = mxsize;
 	hp->dxferp = (char __user *)buf + cmd_size;
 	hp->sbp = NULL;
@@ -566,6 +561,7 @@
 	hp->usr_ptr = NULL;
 	if (__copy_from_user(cmnd, buf, cmd_size))
 		return -EFAULT;
+	hp->dxfer_direction = sg_direction(cmnd);
 	k = sg_common_write(sfp, srp, cmnd, sfp->timeout, blocking);
 	return (k < 0) ? k : count;
 }


jeremy

  reply	other threads:[~2004-06-12  5:15 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-31 11:52 [PATCH] fusion update to current APIs Christoph Hellwig
2004-06-12  0:36 ` Jeremy Higdon
2004-06-12  3:45   ` Matthew Wilcox
2004-06-12  5:13     ` Jeremy Higdon [this message]
2004-06-12  5:20       ` Matthew Wilcox
2004-06-15  6:08         ` [PATCH] sg.c to set direction more reliably (was Re: [PATCH] fusion update to current APIs) Jeremy Higdon
2004-06-15  6:47           ` Douglas Gilbert
2004-06-15  7:41             ` Jeremy Higdon
2004-06-15 15:07               ` Jeff Garzik
2004-06-15 21:34                 ` Jeremy Higdon
2004-06-15 22:10                   ` Jeff Garzik
2004-06-15 22:15                   ` Jeremy Higdon
2004-08-26  7:09                     ` Jeremy Higdon
2004-08-26  8:44                       ` Douglas Gilbert
2004-08-27  1:12                         ` Jeremy Higdon
2004-08-27  8:10                           ` Jeremy Higdon
2004-08-28  5:08                             ` Douglas Gilbert
2004-08-28  9:39                               ` Jeremy Higdon
2004-08-30  7:08                                 ` [PATCH] sg.c to warn about ambiguous data direction Jeremy Higdon
2004-06-15  6:54           ` [PATCH] sg.c to set direction more reliably (was Re: [PATCH] fusion update to current APIs) Jeff Garzik
2004-06-15  7:50             ` Jeremy Higdon
2004-06-15  7:57               ` Arjan van de Ven
2004-06-15  8:40                 ` Jeremy Higdon
2004-06-15  8:17           ` Christoph Hellwig
2004-06-15  8:48             ` Jeremy Higdon
2004-06-15  9:10               ` Jeremy Higdon
2004-06-15  9:31                 ` Jeremy Higdon
2004-06-15 17:42                   ` Patrick Mansfield

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=20040612051353.GA152829@sgi.com \
    --to=jeremy@sgi.com \
    --cc=Emoore@lsil.com \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=willy@debian.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox