Patchwork [RFC,v2,01/13] scsi: cleanup reset and destroy callbacks

login
register
mail settings
Submitter Paolo Bonzini
Date June 6, 2011, 4:04 p.m.
Message ID <1307376262-1255-2-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/98966/
State New
Headers show

Comments

Paolo Bonzini - June 6, 2011, 4:04 p.m.
Push scsi_device_purge_requests up from scsi-disk and scsi-generic to
SCSIDevice.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-bus.c     |   12 ++++++++++++
 hw/scsi-disk.c    |   13 +++++--------
 hw/scsi-generic.c |    9 ---------
 hw/scsi.h         |    4 ++--
 4 files changed, 19 insertions(+), 19 deletions(-)

Patch

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index ad6a730..3918662 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -71,6 +71,7 @@  static int scsi_qdev_exit(DeviceState *qdev)
     SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
 
     assert(bus->devs[dev->id] != NULL);
+    scsi_device_purge_requests(bus->devs[dev->id]);
     if (bus->devs[dev->id]->info->destroy) {
         bus->devs[dev->id]->info->destroy(bus->devs[dev->id]);
     }
@@ -78,12 +79,23 @@  static int scsi_qdev_exit(DeviceState *qdev)
     return 0;
 }
 
+static void scsi_qdev_reset(DeviceState *qdev)
+{
+    SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+
+    scsi_device_purge_requests(dev);
+    if (dev->info->reset) {
+        dev->info->reset(dev);
+    }
+}
+
 void scsi_qdev_register(SCSIDeviceInfo *info)
 {
     info->qdev.bus_info = &scsi_bus_info;
     info->qdev.init     = scsi_qdev_init;
     info->qdev.unplug   = qdev_simple_unplug_cb;
     info->qdev.exit     = scsi_qdev_exit;
+    info->qdev.reset    = scsi_qdev_reset;
     qdev_register(&info->qdev);
 }
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a8c7372..76c1748 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1160,13 +1160,11 @@  static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
     }
 }
 
-static void scsi_disk_reset(DeviceState *dev)
+static void scsi_disk_reset(SCSIDevice *dev)
 {
-    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev.qdev, dev);
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
     uint64_t nb_sectors;
 
-    scsi_device_purge_requests(&s->qdev);
-
     bdrv_get_geometry(s->bs, &nb_sectors);
     nb_sectors /= s->cluster_size;
     if (nb_sectors) {
@@ -1179,7 +1177,6 @@  static void scsi_destroy(SCSIDevice *dev)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
 
-    scsi_device_purge_requests(&s->qdev);
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
@@ -1266,7 +1263,7 @@  static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI disk",
         .qdev.size    = sizeof(SCSIDiskState),
-        .qdev.reset   = scsi_disk_reset,
+        .reset        = scsi_disk_reset,
         .init         = scsi_hd_initfn,
         .destroy      = scsi_destroy,
         .alloc_req    = scsi_new_request,
@@ -1287,7 +1284,7 @@  static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI CD-ROM",
         .qdev.size    = sizeof(SCSIDiskState),
-        .qdev.reset   = scsi_disk_reset,
+        .reset        = scsi_disk_reset,
         .init         = scsi_cd_initfn,
         .destroy      = scsi_destroy,
         .alloc_req    = scsi_new_request,
@@ -1307,7 +1304,7 @@  static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI disk or CD-ROM (legacy)",
         .qdev.size    = sizeof(SCSIDiskState),
-        .qdev.reset   = scsi_disk_reset,
+        .reset        = scsi_disk_reset,
         .init         = scsi_disk_initfn,
         .destroy      = scsi_destroy,
         .alloc_req    = scsi_new_request,
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 8e59c7e..b67e154 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -456,18 +456,10 @@  static int get_stream_blocksize(BlockDriverState *bdrv)
     return (buf[9] << 16) | (buf[10] << 8) | buf[11];
 }
 
-static void scsi_generic_reset(DeviceState *dev)
-{
-    SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev.qdev, dev);
-
-    scsi_device_purge_requests(&s->qdev);
-}
-
 static void scsi_destroy(SCSIDevice *d)
 {
     SCSIGenericState *s = DO_UPCAST(SCSIGenericState, qdev, d);
 
-    scsi_device_purge_requests(&s->qdev);
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
@@ -541,7 +533,6 @@  static SCSIDeviceInfo scsi_generic_info = {
     .qdev.name    = "scsi-generic",
     .qdev.desc    = "pass through generic scsi device (/dev/sg*)",
     .qdev.size    = sizeof(SCSIGenericState),
-    .qdev.reset   = scsi_generic_reset,
     .init         = scsi_generic_initfn,
     .destroy      = scsi_destroy,
     .alloc_req    = scsi_new_request,
diff --git a/hw/scsi.h b/hw/scsi.h
index c1dca35..8d60c3a 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -62,11 +62,11 @@  int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track);
 int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
 
 /* scsi-bus.c */
-typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
 struct SCSIDeviceInfo {
     DeviceInfo qdev;
-    scsi_qdev_initfn init;
+    int (*init)(SCSIDevice *dev);
     void (*destroy)(SCSIDevice *s);
+    void (*reset)(SCSIDevice *s);
     SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun);
     void (*free_req)(SCSIRequest *req);
     int32_t (*send_command)(SCSIRequest *req, uint8_t *buf);