From patchwork Fri Aug 18 09:37:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9908175 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D781600CC for ; Fri, 18 Aug 2017 09:38:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F1CB28C63 for ; Fri, 18 Aug 2017 09:38:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8381128C84; Fri, 18 Aug 2017 09:38:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA6F828C63 for ; Fri, 18 Aug 2017 09:38:03 +0000 (UTC) Received: from localhost ([::1]:39017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1didj8-0006xC-Gk for patchwork-qemu-devel@patchwork.kernel.org; Fri, 18 Aug 2017 05:38:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1didiL-0006vF-70 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 05:37:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1didiI-0000B9-3p for qemu-devel@nongnu.org; Fri, 18 Aug 2017 05:37:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:49712 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1didiH-0000Am-TN for qemu-devel@nongnu.org; Fri, 18 Aug 2017 05:37:10 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 7D218AC1A; Fri, 18 Aug 2017 09:37:08 +0000 (UTC) From: Hannes Reinecke To: Paolo Bonzini Date: Fri, 18 Aug 2017 11:37:02 +0200 Message-Id: <1503049022-14749-1-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 Subject: [Qemu-devel] [PATCH] scsi-bus: correct responses for INQUIRY and REQUEST SENSE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hannes Reinecke , Lazlo Ersek , qemu-devel@nongnu.org, Hannes Reinecke Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP According to SPC-3 INQUIRY and REQUEST SENSE should return GOOD even on unsupported LUNS. Signed-off-by: Hannes Reinecke Tested-by: Laszlo Ersek Reported-by: Laszlo Ersek --- hw/scsi/scsi-bus.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index e364410a23..ade31c11f5 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -516,8 +516,10 @@ static size_t scsi_sense_len(SCSIRequest *req) static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) { SCSITargetReq *r = DO_UPCAST(SCSITargetReq, req, req); + int fixed_sense = (req->cmd.buf[1] & 1) == 0; - if (req->lun != 0) { + if (req->lun != 0 && + buf[0] != INQUIRY && buf[0] != REQUEST_SENSE) { scsi_req_build_sense(req, SENSE_CODE(LUN_NOT_SUPPORTED)); scsi_req_complete(req, CHECK_CONDITION); return 0; @@ -535,9 +537,28 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) break; case REQUEST_SENSE: scsi_target_alloc_buf(&r->req, scsi_sense_len(req)); - r->len = scsi_device_get_sense(r->req.dev, r->buf, - MIN(req->cmd.xfer, r->buf_len), - (req->cmd.buf[1] & 1) == 0); + if (req->lun != 0) { + const struct SCSISense sense = SENSE_CODE(LUN_NOT_SUPPORTED); + + if (fixed_sense) { + r->buf[0] = 0x70; + r->buf[2] = sense.key; + r->buf[10] = 10; + r->buf[12] = sense.asc; + r->buf[13] = sense.ascq; + r->len = MIN(req->cmd.xfer, SCSI_SENSE_LEN); + } else { + r->buf[0] = 0x72; + r->buf[1] = sense.key; + r->buf[2] = sense.asc; + r->buf[3] = sense.ascq; + r->len = 8; + } + } else { + r->len = scsi_device_get_sense(r->req.dev, r->buf, + MIN(req->cmd.xfer, r->buf_len), + fixed_sense); + } if (r->req.dev->sense_is_ua) { scsi_device_unit_attention_reported(req->dev); r->req.dev->sense_len = 0;