aboutsummaryrefslogtreecommitdiff
path: root/hw/scsi-disk.c
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2010-05-04 14:20:59 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-05-10 11:36:03 -0500
commite9447f35718439c1affdee3ef69b2fee50c8106c (patch)
treeef6b2170c73be5d1293208fda8b1f6be658ca59a /hw/scsi-disk.c
parent4c64d5b52ed5287bb31489bba39cf41628230bce (diff)
SCSI: Add disk reset handler
Ensure that pending requests of an SCSI disk are purged on system reset and also restore max_lba. The latter is no only present in the reset handler as that one is called after init as well. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/scsi-disk.c')
-rw-r--r--hw/scsi-disk.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 77cb1daec8..b8d805fb51 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1010,22 +1010,45 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
}
}
-static void scsi_destroy(SCSIDevice *dev)
+static void scsi_disk_purge_requests(SCSIDiskState *s)
{
- SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
SCSIDiskReq *r;
while (!QTAILQ_EMPTY(&s->qdev.requests)) {
r = DO_UPCAST(SCSIDiskReq, req, QTAILQ_FIRST(&s->qdev.requests));
+ if (r->req.aiocb) {
+ bdrv_aio_cancel(r->req.aiocb);
+ }
scsi_remove_request(r);
}
+}
+
+static void scsi_disk_reset(DeviceState *dev)
+{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);
+ uint64_t nb_sectors;
+
+ scsi_disk_purge_requests(s);
+
+ bdrv_get_geometry(s->bs, &nb_sectors);
+ nb_sectors /= s->cluster_size;
+ if (nb_sectors) {
+ nb_sectors--;
+ }
+ s->max_lba = nb_sectors;
+}
+
+static void scsi_destroy(SCSIDevice *dev)
+{
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
+
+ scsi_disk_purge_requests(s);
drive_uninit(s->qdev.conf.dinfo);
}
static int scsi_disk_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
- uint64_t nb_sectors;
if (!s->qdev.conf.dinfo || !s->qdev.conf.dinfo->bdrv) {
error_report("scsi-disk: drive property not set");
@@ -1046,11 +1069,6 @@ static int scsi_disk_initfn(SCSIDevice *dev)
s->cluster_size = s->qdev.blocksize / 512;
s->qdev.type = TYPE_DISK;
- bdrv_get_geometry(s->bs, &nb_sectors);
- nb_sectors /= s->cluster_size;
- if (nb_sectors)
- nb_sectors--;
- s->max_lba = nb_sectors;
qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
return 0;
}
@@ -1059,6 +1077,7 @@ static SCSIDeviceInfo scsi_disk_info = {
.qdev.name = "scsi-disk",
.qdev.desc = "virtual scsi disk or cdrom",
.qdev.size = sizeof(SCSIDiskState),
+ .qdev.reset = scsi_disk_reset,
.init = scsi_disk_initfn,
.destroy = scsi_destroy,
.send_command = scsi_send_command,