From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDfRB-000748-8M for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:35:16 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDfR0-0006q9-HA for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:35:07 -0500 Received: from [199.232.76.173] (port=56173 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDfQz-0006pY-L2 for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:35:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59505) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDfQz-0000IM-7o for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:35:01 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAQEZ0bh008449 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Nov 2009 09:35:00 -0500 From: Gerd Hoffmann Date: Thu, 26 Nov 2009 15:34:09 +0100 Message-Id: <1259246056-5389-24-git-send-email-kraxel@redhat.com> In-Reply-To: <1259246056-5389-1-git-send-email-kraxel@redhat.com> References: <1259246056-5389-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 23/30] scsi-disk: restruct emulation: READ_CAPACITY List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Move READ_CAPACITY emulation from scsi_send_command() to scsi_disk_emulate_command(). Signed-off-by: Gerd Hoffmann --- hw/scsi-disk.c | 55 +++++++++++++++++++++++++++---------------------------- 1 files changed, 27 insertions(+), 28 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 7d59998..4f56a22 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -617,7 +617,9 @@ static int scsi_disk_emulate_mode_sense(SCSIRequest *req, uint8_t *outbuf) static int scsi_disk_emulate_command(SCSIRequest *req, uint8_t *outbuf) { + SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev); BlockDriverState *bdrv = req->dev->dinfo->bdrv; + uint64_t nb_sectors; int buflen = 0; switch (req->cmd.buf[0]) { @@ -679,6 +681,30 @@ static int scsi_disk_emulate_command(SCSIRequest *req, uint8_t *outbuf) case ALLOW_MEDIUM_REMOVAL: bdrv_set_locked(bdrv, req->cmd.buf[4] & 1); break; + case READ_CAPACITY: + /* The normal LEN field for this command is zero. */ + memset(outbuf, 0, 8); + bdrv_get_geometry(bdrv, &nb_sectors); + if (!nb_sectors) + goto not_ready; + nb_sectors /= s->cluster_size; + /* Returned value is the address of the last sector. */ + nb_sectors--; + /* Remember the new size for read/write sanity checking. */ + s->max_lba = nb_sectors; + /* Clip to 2TB, instead of returning capacity modulo 2TB. */ + if (nb_sectors > UINT32_MAX) + nb_sectors = UINT32_MAX; + outbuf[0] = (nb_sectors >> 24) & 0xff; + outbuf[1] = (nb_sectors >> 16) & 0xff; + outbuf[2] = (nb_sectors >> 8) & 0xff; + outbuf[3] = nb_sectors & 0xff; + outbuf[4] = 0; + outbuf[5] = 0; + outbuf[6] = s->cluster_size * 2; + outbuf[7] = 0; + buflen = 8; + break; default: goto illegal_request; } @@ -792,6 +818,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, case RELEASE_10: case START_STOP: case ALLOW_MEDIUM_REMOVAL: + case READ_CAPACITY: rc = scsi_disk_emulate_command(&r->req, outbuf); if (rc > 0) { r->iov.iov_len = rc; @@ -801,34 +828,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, return 0; } break; - case READ_CAPACITY: - DPRINTF("Read Capacity\n"); - /* The normal LEN field for this command is zero. */ - memset(outbuf, 0, 8); - bdrv_get_geometry(s->qdev.dinfo->bdrv, &nb_sectors); - nb_sectors /= s->cluster_size; - /* Returned value is the address of the last sector. */ - if (nb_sectors) { - nb_sectors--; - /* Remember the new size for read/write sanity checking. */ - s->max_lba = nb_sectors; - /* Clip to 2TB, instead of returning capacity modulo 2TB. */ - if (nb_sectors > UINT32_MAX) - nb_sectors = UINT32_MAX; - outbuf[0] = (nb_sectors >> 24) & 0xff; - outbuf[1] = (nb_sectors >> 16) & 0xff; - outbuf[2] = (nb_sectors >> 8) & 0xff; - outbuf[3] = nb_sectors & 0xff; - outbuf[4] = 0; - outbuf[5] = 0; - outbuf[6] = s->cluster_size * 2; - outbuf[7] = 0; - r->iov.iov_len = 8; - } else { - scsi_command_complete(r, CHECK_CONDITION, NOT_READY); - return 0; - } - break; case READ_6: case READ_10: case 0x88: -- 1.6.2.5