From patchwork Fri Jul 27 15:02:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 173741 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 347872C0087 for ; Sat, 28 Jul 2012 02:32:51 +1000 (EST) Received: from localhost ([::1]:49248 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5k-000892-En for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 11:04:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum52-0007B3-9L for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:03:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sum50-0007Nq-Ql for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:03:52 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:42319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum50-0007JU-Mz for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:03:50 -0400 Received: by mail-gh0-f173.google.com with SMTP id r14so3231906ghr.4 for ; Fri, 27 Jul 2012 08:03:50 -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=v13kune8ArLCYYX+NFOPoZJDZgGf5OLsb42btrCsXng=; b=aa+V4FwWlpES94KQ3StqfgL0tDq1089Sy/8xjZIBDIvIedKcbKHwBDZAYgqK2Xki5e 7xQevM/pBLAmaBcjGBiS4Sfv9BDh982HOp74DEPs77XIIShQqnJbP50/YrcFnePMGD6J i6BQObiKygQC0qUJqCUYESHFXys1lsMLwEVUwtVgb5tkdjh945hUQN54vS5g5BHIHpJK M4iBBB8pGe17vxFTO/0UXODjrgyirlGlzi2RF09pd7HasQd5H2MgppInRH5H4738C8s0 DP3bhLC98l+F/UVUfOQLg8z1vpnSRVjTjhY5fjIhZ4bEx/frCVePP8Y1jUqsgfP9G37y xe2g== Received: by 10.68.204.129 with SMTP id ky1mr15233421pbc.32.1343401430158; Fri, 27 Jul 2012 08:03:50 -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 nk3sm2062530pbc.27.2012.07.27.08.03.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jul 2012 08:03:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 17:02:40 +0200 Message-Id: <1343401379-19495-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> References: <1343401379-19495-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.173 Subject: [Qemu-devel] [PATCH 13/32] 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 1633177..b8d6086 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1274,7 +1274,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) @@ -1283,7 +1302,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: @@ -1309,7 +1328,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 @@ -1326,6 +1344,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: @@ -1500,7 +1519,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. @@ -1517,7 +1535,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; @@ -1552,7 +1569,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) { @@ -1834,10 +1856,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,