[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice |
Date: |
Mon, 31 Oct 2011 14:30:22 +0100 |
From: Paolo Bonzini <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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 af1001d..74990a8 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 4d7ad82..fcf23cd 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.4
- [Qemu-devel] [PATCH 17/55] Documentation: Add syntax for using sheepdog devices, (continued)
- [Qemu-devel] [PATCH 17/55] Documentation: Add syntax for using sheepdog devices, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 16/55] block: reinitialize across bdrv_close()/bdrv_open(), Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 18/55] scsi: pass correct sense code for ENOMEDIUM, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 35/55] scsi: allow arbitrary LUNs, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 33/55] scsi: remove devs array from SCSIBus, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 38/55] scsi-disk: fix retrying a flush, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 37/55] scsi-disk: fail READ CAPACITY if LBA != 0 but PMI == 0, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 45/55] scsi-disk: remove cluster_size, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 44/55] scsi-disk: do not duplicate BlockDriverState member, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 46/55] scsi-disk: small clean up to INQUIRY, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice,
Kevin Wolf <=
- [Qemu-devel] [PATCH 50/55] scsi: pass cdb to alloc_req, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 49/55] scsi: export scsi_generic_reqops, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 52/55] scsi-disk: bump SCSIRequest reference count until aio completion runs, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 51/55] scsi: do not call transfer_data after canceling a request, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 36/55] scsi: add channel to addressing, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 21/55] atapi: cleanup/fix mode sense results, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 20/55] atapi: move GESN definitions to scsi-defs.h, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 23/55] scsi-disk: report media changed via unit attention sense codes, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 42/55] scsi-generic: look at host status, Kevin Wolf, 2011/10/31