From patchwork Tue Jul 10 14:15:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 170194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC6392C0088 for ; Wed, 11 Jul 2012 00:17:22 +1000 (EST) Received: from localhost ([::1]:36580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobFg-0006Hh-Gw for incoming@patchwork.ozlabs.org; Tue, 10 Jul 2012 10:17:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobEF-0003JK-EJ for qemu-devel@nongnu.org; Tue, 10 Jul 2012 10:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SobE5-0002EJ-3j for qemu-devel@nongnu.org; Tue, 10 Jul 2012 10:15:50 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:59253) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SobE4-00025c-QY for qemu-devel@nongnu.org; Tue, 10 Jul 2012 10:15:41 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so369507pbb.4 for ; Tue, 10 Jul 2012 07:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=prlu/2chFgt55m+rlp2I749aT2eeYOQAP49FAQC2m1o=; b=Rk696v85tH3pQ1dJkycAbq/74xB2KBwBYVL+xqD+DGvf4AKcuhKj0rHJrlyN1o0oxB Fkt6Cgvy2WY71eep1/b7hl3EEpyLlwxH43IjM/e3/qKXPN/Zv/trcmT6pgBgiyv73yRd DRaeM7XjG9amNDJeBDu7Opdoo4Ku+Lo1tDfunVfcNCtU9KIY/BYH/vG5naouHIFBWLcg /MhJsqS5Cohp45F0hWkxLF2DbFSBbWDBoPeNddmu/MGLIT7b3qnB9jXLerfNiTPHqvFQ 8spSSevz3gvCNl4pHp8xQePvkdWbfOE+GI61nSJ5G+CeMe4JqWIh0SkCBdTZxDcAhrYN 2MmA== Received: by 10.68.213.234 with SMTP id nv10mr69288216pbc.56.1341929739867; Tue, 10 Jul 2012 07:15:39 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id ru4sm29941485pbc.66.2012.07.10.07.15.36 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 07:15:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2012 16:15:07 +0200 Message-Id: <1341929710-21574-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1341929710-21574-1-git-send-email-pbonzini@redhat.com> References: <1341929710-21574-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 5/8] scsi-disk: support emulated TO_DEV requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This adds the implementation of write_data for the emulated command case. The first time through it asks for more data, the second time it finishes the processing of the command. MODE SELECT and MODE SELECT(10) can now be re-enabled, but they will not do much. Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index a03d200..e64d659 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1278,7 +1278,26 @@ static void scsi_disk_emulate_read_data(SCSIRequest *req) static void scsi_disk_emulate_write_data(SCSIRequest *req) { - abort(); + SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); + + if (r->iov.iov_len) { + int buflen = r->iov.iov_len; + DPRINTF("Write buf_len=%zd\n", buflen); + r->iov.iov_len = 0; + scsi_req_data(&r->req, buflen); + return; + } + + switch (req->cmd.buf[0]) { + case MODE_SELECT: + case MODE_SELECT_10: + /* This also clears the sense buffer for REQUEST SENSE. */ + scsi_req_complete(&r->req, GOOD); + break; + + default: + abort(); + } } static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) @@ -1287,7 +1306,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev); uint64_t nb_sectors; uint8_t *outbuf; - int buflen = 0; + int buflen; switch (req->cmd.buf[0]) { case INQUIRY: @@ -1313,7 +1332,6 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) break; } - assert(req->cmd.mode != SCSI_XFER_TO_DEV); if (!r->iov.iov_base) { /* * FIXME: we shouldn't return anything bigger than 4k, but the code @@ -1330,6 +1348,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen); } + buflen = req->cmd.xfer; outbuf = r->iov.iov_base; switch (req->cmd.buf[0]) { case TEST_UNIT_READY: @@ -1504,7 +1523,6 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) goto illegal_lba; } break; -#if 0 case MODE_SELECT: DPRINTF("Mode Select(6) (len %lu)\n", (long)r->req.cmd.xfer); /* We don't support mode parameter changes. @@ -1521,7 +1539,6 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) goto illegal_request; } break; -#endif case WRITE_SAME_10: nb_sectors = lduw_be_p(&req->cmd.buf[7]); goto write_same; @@ -1556,7 +1573,12 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf) if (r->iov.iov_len == 0) { scsi_req_complete(&r->req, GOOD); } - return r->iov.iov_len; + if (r->req.cmd.mode == SCSI_XFER_TO_DEV) { + assert(r->iov.iov_len == req->cmd.xfer); + return -r->iov.iov_len; + } else { + return r->iov.iov_len; + } illegal_request: if (r->req.status == -1) { @@ -1845,10 +1867,8 @@ static const SCSIReqOps *const scsi_disk_reqops_dispatch[256] = { [REQUEST_SENSE] = &scsi_disk_emulate_reqops, [SYNCHRONIZE_CACHE] = &scsi_disk_emulate_reqops, [SEEK_10] = &scsi_disk_emulate_reqops, -#if 0 [MODE_SELECT] = &scsi_disk_emulate_reqops, [MODE_SELECT_10] = &scsi_disk_emulate_reqops, -#endif [WRITE_SAME_10] = &scsi_disk_emulate_reqops, [WRITE_SAME_16] = &scsi_disk_emulate_reqops,