From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58578 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrApm-0007N8-C2 for qemu-devel@nongnu.org; Thu, 02 Sep 2010 10:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrApl-00043i-16 for qemu-devel@nongnu.org; Thu, 02 Sep 2010 10:32:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56196) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrApk-00043T-Qb for qemu-devel@nongnu.org; Thu, 02 Sep 2010 10:32:09 -0400 Message-ID: <4C7FB574.7090906@redhat.com> Date: Thu, 02 Sep 2010 16:32:20 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] scsi-generic: don't report negative length to the SCSI adapter References: <1283434052-11866-1-git-send-email-bernhard.kohl@nsn.com> In-Reply-To: <1283434052-11866-1-git-send-email-bernhard.kohl@nsn.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bernhard Kohl Cc: qemu-devel@nongnu.org Am 02.09.2010 15:27, schrieb Bernhard Kohl: > Some drivers report an incorrect number for 'resid'. I found that for > MODE_SENSE(6) on an IET iSCSI device. This device reports the > available mode data length minus actually transferred length. > > This is already a known problem: > http://tldp.org/HOWTO/SCSI-Generic-HOWTO/x356.html > > Signed-off-by: Bernhard Kohl > --- > hw/scsi-generic.c | 6 +++++- > 1 files changed, 5 insertions(+), 1 deletions(-) > > diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c > index 9538027..836678c 100644 > --- a/hw/scsi-generic.c > +++ b/hw/scsi-generic.c > @@ -169,7 +169,11 @@ static void scsi_read_complete(void * opaque, int ret) > return; > } > len = r->io_header.dxfer_len - r->io_header.resid; > - DPRINTF("Data ready tag=0x%x len=%d\n", r->req.tag, len); > + if (len < 0) { > + len = r->io_header.dxfer_len; > + } > + DPRINTF("Data ready tag=0x%x len=%d dxfer_len=%d resid=%d\n", > + r->req.tag, len, r->io_header.dxfer_len, r->io_header.resid); > > r->len = -1; > r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, len); Can we add a comment why len can become < 0 and that this is a workaround for buggy drivers? It's in your commit message, but I prefer this kind of things to be explained in the code. Also, are we sure that broken drivers always return negative numbers when their result is wrong, or can we still get incorrect results? Kevin