From patchwork Tue Oct 25 10:40:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 121637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C86E51007D9 for ; Tue, 25 Oct 2011 23:19:21 +1100 (EST) Received: from localhost ([::1]:47757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeSj-0002Aq-Bz for incoming@patchwork.ozlabs.org; Tue, 25 Oct 2011 06:42:29 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeRs-0000lp-Sn for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIeRf-0006Pl-N3 for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:41:36 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:35123) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIeRe-0006Mv-FX for qemu-devel@nongnu.org; Tue, 25 Oct 2011 06:41:22 -0400 Received: by mail-ww0-f53.google.com with SMTP id 36so464318wwi.10 for ; Tue, 25 Oct 2011 03:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=MnOXWOyZ2zL8PJQhqH53cpyeNcgq1tEwr+oQA0zEgTM=; b=oszn/c1l705oQ4cBaovgV8+SRPpMoUWgqf97+QIm1Ff/B6hYoMRbUeBYjyfzUVTL9g RxaCguty22cs6lx6r3IvhyQOc/5G9jMru0euJ/ise9iUU+bwVSZXdyN9mmu+56mWqI+Q J8+/A5A0/30j10nExMKmRZWJoodbL0cXtZKRs= Received: by 10.216.134.82 with SMTP id r60mr10010015wei.105.1319539281553; Tue, 25 Oct 2011 03:41:21 -0700 (PDT) Received: from localhost.localdomain (93-34-199-98.ip51.fastwebnet.it. [93.34.199.98]) by mx.google.com with ESMTPS id fr4sm15677349wbb.0.2011.10.25.03.41.20 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Oct 2011 03:41:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Oct 2011 12:40:38 +0200 Message-Id: <1319539241-26436-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1319539241-26436-1-git-send-email-pbonzini@redhat.com> References: <1319539241-26436-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.53 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH v2 30/33] scsi: move max_lba to SCSIDevice 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 The field is only in scsi-disk for now. Moving it up to SCSIDevice makes it easier to reuse the scsi-generic reqops elsewhere. At the same time, make scsi-generic get max_lba from snooped READ CAPACITY commands as well. Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 15 +++++++-------- hw/scsi-generic.c | 2 ++ hw/scsi.h | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 723fffe..4544f1c 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -66,7 +66,6 @@ struct SCSIDiskState { SCSIDevice qdev; uint32_t removable; - uint64_t max_lba; bool media_changed; bool media_event; QEMUBH *bh; @@ -1175,7 +1174,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) /* 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; + s->qdev.max_lba = nb_sectors; /* Clip to 2TB, instead of returning capacity modulo 2TB. */ if (nb_sectors > UINT32_MAX) { nb_sectors = UINT32_MAX; @@ -1230,7 +1229,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r) /* 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; + s->qdev.max_lba = nb_sectors; outbuf[0] = (nb_sectors >> 56) & 0xff; outbuf[1] = (nb_sectors >> 48) & 0xff; outbuf[2] = (nb_sectors >> 40) & 0xff; @@ -1345,7 +1344,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) case READ_16: len = r->req.cmd.xfer / s->qdev.blocksize; DPRINTF("Read (sector %" PRId64 ", count %d)\n", r->req.cmd.lba, len); - if (r->req.cmd.lba > s->max_lba) { + if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); @@ -1362,7 +1361,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) DPRINTF("Write %s(sector %" PRId64 ", count %d)\n", (command & 0xe) == 0xe ? "And Verify " : "", r->req.cmd.lba, len); - if (r->req.cmd.lba > s->max_lba) { + if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512); @@ -1388,7 +1387,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) case SEEK_10: DPRINTF("Seek(%d) (sector %" PRId64 ")\n", command == SEEK_6 ? 6 : 10, r->req.cmd.lba); - if (r->req.cmd.lba > s->max_lba) { + if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } break; @@ -1398,7 +1397,7 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) DPRINTF("WRITE SAME(16) (sector %" PRId64 ", count %d)\n", r->req.cmd.lba, len); - if (r->req.cmd.lba > s->max_lba) { + if (r->req.cmd.lba > s->qdev.max_lba) { goto illegal_lba; } @@ -1457,7 +1456,7 @@ static void scsi_disk_reset(DeviceState *dev) if (nb_sectors) { nb_sectors--; } - s->max_lba = nb_sectors; + s->qdev.max_lba = nb_sectors; } static void scsi_destroy(SCSIDevice *dev) diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c index 9fd1a6d..9e293ee 100644 --- a/hw/scsi-generic.c +++ b/hw/scsi-generic.c @@ -174,9 +174,11 @@ static void scsi_read_complete(void * opaque, int ret) /* Snoop READ CAPACITY output to set the blocksize. */ if (r->req.cmd.buf[0] == READ_CAPACITY_10) { s->blocksize = ldl_be_p(&r->buf[4]); + s->max_lba = ldl_be_p(&r->buf[0]); } else if (r->req.cmd.buf[0] == SERVICE_ACTION_IN_16 && (r->req.cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) { s->blocksize = ldl_be_p(&r->buf[8]); + s->max_lba = ldq_be_p(&r->buf[0]); } bdrv_set_buffer_alignment(s->conf.bs, s->blocksize); diff --git a/hw/scsi.h b/hw/scsi.h index c8649cf..d56e875 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -70,6 +70,7 @@ struct SCSIDevice uint32_t lun; int blocksize; int type; + uint64_t max_lba; }; /* cdrom.c */