From patchwork Mon Oct 26 13:36:32 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 36906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 77641B7BC5 for ; Tue, 27 Oct 2009 00:37:30 +1100 (EST) Received: from localhost ([127.0.0.1]:43067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2PlH-0001Sw-LC for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2009 09:37:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2Pko-0001Sj-Tr for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2Pkj-0001SH-Lw for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:57 -0400 Received: from [199.232.76.173] (port=43168 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2Pkj-0001SE-Gp for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:53 -0400 Received: from mail-yw0-f176.google.com ([209.85.211.176]:47219) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2Pkj-0005AY-3x for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:53 -0400 Received: by ywh6 with SMTP id 6so9311383ywh.4 for ; Mon, 26 Oct 2009 06:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=shi2Nyt0CKZpfo5HBiNfQwQ5rG2c0MRpBOfGw8WLpqM=; b=bfUuHjzeh0eOaRYXHepKCgLF0tmgy4p1gqV6QS3sgSLoDly36E9hMDrjQdd8P2dKGd ixxv3+zhY9WPNckxQHsrEE8LX55h/xARE2d8xFXuuVSPaXx3Ak32PqKOzVdVQ1dh+K1J hhaKKzMRCpy7cxer2voRx+eMJin6WdTn+37XY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=UPmB43PJTk2iBMaHoPlgkVcj2Qfb0sFOmShNUpRyaj8lRPf17jZxefNqs51b0rujUY V/eR34GT+JbcOPY1ZsFlXboen13TcU9Xl88gVfGPYoy2sz0mp82J45mGzFPswOBFhEQp l432rvlXOdmtiC7a8PrLChqxSA9X/tr93KVtQ= MIME-Version: 1.0 Received: by 10.100.83.4 with SMTP id g4mr4067275anb.160.1256564212133; Mon, 26 Oct 2009 06:36:52 -0700 (PDT) From: Artyom Tarasenko Date: Mon, 26 Oct 2009 15:36:32 +0200 Message-ID: To: qemu-devel , Blue Swirl X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH] scsi-disk: Inquiry with allocation length of CDB < 36 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org According to SCSI-2 specification, http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-08.html#8.2.5 , "if the allocation length of the command descriptor block (CDB) is too small to transfer all of the parameters, the additional length shall not be adjusted to reflect the truncation." The 36 mandatory bytes of response are written to outbuf, and then only the length requested in CDB is transferred. Signed-off-by: Artyom Tarasenko --- if(len > SCSI_MAX_INQUIRY_LEN) @@ -604,7 +605,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, Some later commands are also implemented. */ outbuf[2] = 3; outbuf[3] = 2; /* Format 2 */ - outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + if (len > 36) { + outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + } else { + /* If the allocation length of CDB is too small, the additional length + is not adjusted */ + outbuf[4] = 36 - 5; + } /* Sync data transfer and TCQ. */ outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0); r->iov.iov_len = len; Signed-off-by: Artyom Tarasenko --- diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2a9268a..1a7487e 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -5,6 +5,12 @@ * Based on code by Fabrice Bellard * * Written by Paul Brook + * Modifications: + * 2009-Oct-26 Artyom Tarasenko : implemented stamdard inquiry for the case + * when the allocation length of CDB is smaller + * than 36. + * 2009-Oct-13 Artyom Tarasenko : implemented the block descriptor in the + * MODE SENSE response. * * This code is licenced under the LGPL. * @@ -576,11 +582,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, "is less than 5\n", len); goto fail; } - - if (len < 36) { - BADF("Error: Inquiry (STANDARD) buffer size %d " - "is less than 36 (TODO: only 5 required)\n", len); - } } if(len > SCSI_MAX_INQUIRY_LEN) @@ -604,7 +605,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, Some later commands are also implemented. */ outbuf[2] = 3; outbuf[3] = 2; /* Format 2 */ - outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + if (len > 36) { + outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + } else { + /* If the allocation length of CDB is too small, the additional length + is not adjusted */ + outbuf[4] = 36 - 5; + } /* Sync data transfer and TCQ. */ outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0); r->iov.iov_len = len; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2a9268a..1a7487e 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -5,6 +5,12 @@ * Based on code by Fabrice Bellard * * Written by Paul Brook + * Modifications: + * 2009-Oct-26 Artyom Tarasenko : implemented stamdard inquiry for the case + * when the allocation length of CDB is smaller + * than 36. + * 2009-Oct-13 Artyom Tarasenko : implemented the block descriptor in the + * MODE SENSE response. * * This code is licenced under the LGPL. * @@ -576,11 +582,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, "is less than 5\n", len); goto fail; } - - if (len < 36) { - BADF("Error: Inquiry (STANDARD) buffer size %d " - "is less than 36 (TODO: only 5 required)\n", len); - } }