qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 31/35] scsi: move max_lba to SCSIDevice
Date: Thu, 13 Oct 2011 13:04:01 +0200	[thread overview]
Message-ID: <1318503845-11473-32-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1318503845-11473-1-git-send-email-pbonzini@redhat.com>

The field was only in scsi-disk until now.  Moving it up to SCSIDevice
will make it easier to reuse the scsi-generic reqops elsewhere.  In
the future, range checking of LBA arguments might also be pushed up
to SCSIDevice.

At the same time, make scsi-generic get max_lba from the guest's READ
CAPACITY commands, as well.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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 cc3998e..26aa46a 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;
@@ -1172,7 +1171,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;
@@ -1222,7 +1221,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;
@@ -1339,7 +1338,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);
         r->sector_count = len * (s->qdev.blocksize / 512);
@@ -1355,7 +1354,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);
         r->sector_count = len * (s->qdev.blocksize / 512);
@@ -1380,7 +1379,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;
@@ -1390,7 +1389,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;
         }
 
@@ -1449,7 +1448,7 @@ static void scsi_disk_reset(DeviceState *dev)
         if (nb_sectors) {
             nb_sectors--;
         }
-        s->max_lba = nb_sectors;
+        s->qdev.max_lba = nb_sectors;
     }
 }
 
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index cb02a7e..06089ab 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 */
-- 
1.7.6

  parent reply	other threads:[~2011-10-13 11:05 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-13 11:03 [Qemu-devel] [PULL 00/35] SCSI uber-patch Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 01/35] scsi: pass correct sense code for ENOMEDIUM Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 02/35] atapi/scsi: unify definitions for MMC Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 03/35] atapi: move GESN definitions to scsi-defs.h Paolo Bonzini
2011-10-17 13:41   ` Kevin Wolf
2011-10-17 13:53     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 04/35] atapi: fill in AUDIO_CTL page correctly Paolo Bonzini
2011-10-17 14:05   ` Kevin Wolf
2011-10-17 14:04     ` Paolo Bonzini
2011-10-17 14:10       ` Kevin Wolf
2011-10-17 14:22         ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 05/35] scsi: notify the device when unit attention is reported Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 06/35] scsi-disk: report media changed via unit attention sense codes Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 07/35] scsi-disk: add stubs for more MMC commands Paolo Bonzini
2011-10-17 14:27   ` Kevin Wolf
2011-10-17 14:28     ` Paolo Bonzini
2011-10-17 14:44       ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 08/35] scsi-disk: store valid mode pages in a table Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 09/35] atapi/scsi-disk: make mode page values coherent between the two Paolo Bonzini
2011-10-17 15:05   ` Kevin Wolf
2011-10-17 15:06     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 10/35] scsi-disk: support DVD profile in GET CONFIGURATION Paolo Bonzini
2011-10-17 15:20   ` Kevin Wolf
2011-10-17 15:28     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 11/35] scsi-disk: support READ DVD STRUCTURE Paolo Bonzini
2011-10-21 11:42   ` Kevin Wolf
2011-10-21 13:11     ` Paolo Bonzini
2011-10-21 13:12     ` Paolo Bonzini
2011-10-21 13:32       ` Kevin Wolf
2011-10-21 13:36         ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 12/35] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Paolo Bonzini
2011-10-21 11:54   ` Kevin Wolf
2011-10-21 13:08     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 13/35] scsi: move tcq/ndev to SCSIBusOps (now SCSIBusInfo) Paolo Bonzini
2011-10-21 12:01   ` Kevin Wolf
2011-10-21 12:21     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 14/35] qdev: switch children device list to QTAILQ Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 15/35] scsi: remove devs array from SCSIBus Paolo Bonzini
2011-10-21 12:31   ` Kevin Wolf
2011-10-21 13:03     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 16/35] scsi: implement REPORT LUNS for arbitrary LUNs Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 17/35] scsi: allow " Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 18/35] scsi: add channel to addressing Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 19/35] scsi-disk: fail READ CAPACITY if LBA != 0 but PMI == 0 Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 20/35] scsi-disk: do not complete requests twice Paolo Bonzini
2011-10-19 13:13   ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 21/35] scsi-disk: bump SCSIRequest reference count until aio completion runs Paolo Bonzini
2011-10-17 15:37   ` [Qemu-devel] [PATCH v2 " Paolo Bonzini
2011-10-19 13:13     ` Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 22/35] scsi-disk: fix retrying a flush Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 23/35] scsi-generic: drop SCSIGenericState Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 24/35] scsi-generic: remove scsi_req_fixup Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 25/35] scsi-generic: check ioctl statuses when SG_IO succeeds Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 26/35] scsi-generic: look at host status Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 27/35] scsi-generic: snoop READ CAPACITY commands to get block size Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 28/35] scsi-disk: do not duplicate BlockDriverState member Paolo Bonzini
2011-10-13 11:03 ` [Qemu-devel] [PATCH 29/35] scsi-disk: remove cluster_size Paolo Bonzini
2011-10-24 15:10   ` Kevin Wolf
2011-10-24 15:36     ` Paolo Bonzini
2011-10-13 11:04 ` [Qemu-devel] [PATCH 30/35] scsi-disk: small clean up to INQUIRY Paolo Bonzini
2011-10-13 11:04 ` Paolo Bonzini [this message]
2011-10-13 11:04 ` [Qemu-devel] [PATCH 32/35] scsi: make reqops static const Paolo Bonzini
2011-10-13 11:04 ` [Qemu-devel] [PATCH 33/35] scsi: export scsi_generic_reqops Paolo Bonzini
2011-10-13 11:04 ` [Qemu-devel] [PATCH 34/35] scsi: pass cdb to alloc_req Paolo Bonzini
2011-10-13 11:04 ` [Qemu-devel] [PATCH 35/35] scsi-disk: add scsi-block for device passthrough Paolo Bonzini
2011-10-24 15:28   ` Kevin Wolf
2011-10-24 15:28     ` Paolo Bonzini
2011-10-24 15:38       ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1318503845-11473-32-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).