All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 21/24] drive cleanup fixes.
Date: Fri, 25 Sep 2009 21:42:46 +0200	[thread overview]
Message-ID: <1253907769-1067-22-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1253907769-1067-1-git-send-email-kraxel@redhat.com>

Changes:
  * drive_uninit() wants a DriveInfo now.
  * drive_uninit() also calls bdrv_delete(),
    so callers don't need to do that.
  * drive_uninit() calls are moved over to the ->exit()
    callbacks, destroy_bdrvs() is zapped.
  * setting bdrv->private is not needed any more as the
    only user (destroy_bdrvs) is gone.
  * usb-storage needs no drive_uninit, scsi-disk will
    handle that.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/device-hotplug.c |   18 ------------------
 hw/pci-hotplug.c    |    3 ---
 hw/scsi-disk.c      |    8 ++++++++
 hw/scsi-generic.c   |    2 ++
 hw/usb-msd.c        |    8 --------
 hw/virtio-blk.c     |    1 -
 hw/virtio-pci.c     |    9 +++++++++
 sysemu.h            |    3 +--
 vl.c                |   16 +++++-----------
 9 files changed, 25 insertions(+), 43 deletions(-)

diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c
index 69779ca..c0cfd31 100644
--- a/hw/device-hotplug.c
+++ b/hw/device-hotplug.c
@@ -62,21 +62,3 @@ void destroy_nic(dev_match_fn *match_fn, void *arg)
         }
     }
 }
-
-void destroy_bdrvs(dev_match_fn *match_fn, void *arg)
-{
-    DriveInfo *dinfo;
-    struct BlockDriverState *bs;
-
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        bs = dinfo->bdrv;
-        if (bs) {
-            if (bs->private && match_fn(bs->private, arg)) {
-                drive_uninit(bs);
-                bdrv_delete(bs);
-            }
-        }
-    }
-}
-
-
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index ac3d1ae..6a08555 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -230,9 +230,6 @@ void pci_device_hot_remove_success(PCIDevice *d)
     class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1);
 
     switch(class_code) {
-    case PCI_BASE_CLASS_STORAGE:
-        destroy_bdrvs(pci_match_fn, d);
-        break;
     case PCI_BASE_CLASS_NETWORK:
         destroy_nic(pci_match_fn, d);
         break;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 0f029f8..3940726 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -936,6 +936,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
     }
 }
 
+static void scsi_destroy(SCSIDevice *dev)
+{
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
+
+    drive_uninit(s->dinfo);
+}
+
 static int scsi_disk_initfn(SCSIDevice *dev)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
@@ -969,6 +976,7 @@ static SCSIDeviceInfo scsi_disk_info = {
     .qdev.desc    = "virtual scsi disk or cdrom",
     .qdev.size    = sizeof(SCSIDiskState),
     .init         = scsi_disk_initfn,
+    .destroy      = scsi_destroy,
     .send_command = scsi_send_command,
     .read_data    = scsi_read_data,
     .write_data   = scsi_write_data,
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 86d1e54..6a89989 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -668,6 +668,8 @@ static void scsi_destroy(SCSIDevice *d)
         qemu_free(r);
         r = n;
     }
+
+    drive_uninit(s->dinfo);
 }
 
 static int scsi_generic_initfn(SCSIDevice *dev)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index a19b31d..e090014 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -508,13 +508,6 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
     return ret;
 }
 
-static void usb_msd_handle_destroy(USBDevice *dev)
-{
-    MSDState *s = (MSDState *)dev;
-
-    drive_uninit(s->dinfo->bdrv);
-}
-
 static int usb_msd_initfn(USBDevice *dev)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
@@ -599,7 +592,6 @@ static struct USBDeviceInfo msd_info = {
     .handle_reset   = usb_msd_handle_reset,
     .handle_control = usb_msd_handle_control,
     .handle_data    = usb_msd_handle_data,
-    .handle_destroy = usb_msd_handle_destroy,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_DRIVE("drive", MSDState, dinfo),
         DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 2d6d71a..2630b99 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -504,7 +504,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo)
         strncpy(s->serial_str, ps, sizeof(s->serial_str));
     else
         snprintf(s->serial_str, sizeof(s->serial_str), "0");
-    s->bs->private = dev;
     bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
     bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
 
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index c6fbaac..7b86bfc 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -458,6 +458,14 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
+static int virtio_blk_exit_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    drive_uninit(proxy->dinfo);
+    return 0;
+}
+
 static int virtio_console_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -519,6 +527,7 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.name = "virtio-blk-pci",
         .qdev.size = sizeof(VirtIOPCIProxy),
         .init      = virtio_blk_init_pci,
+        .exit      = virtio_blk_exit_pci,
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
             DEFINE_PROP_DRIVE("drive", VirtIOPCIProxy, dinfo),
diff --git a/sysemu.h b/sysemu.h
index 0ebbb03..3f0d3bf 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -188,7 +188,7 @@ extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
 extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 extern DriveInfo *drive_get_by_id(const char *id);
 extern int drive_get_max_bus(BlockInterfaceType type);
-extern void drive_uninit(BlockDriverState *bdrv);
+extern void drive_uninit(DriveInfo *dinfo);
 extern const char *drive_get_serial(BlockDriverState *bdrv);
 extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
 
@@ -203,7 +203,6 @@ typedef int (dev_match_fn)(void *dev_private, void *arg);
 
 DriveInfo *add_init_drive(const char *opts);
 void destroy_nic(dev_match_fn *match_fn, void *arg);
-void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
 
 /* pci-hotplug */
 void pci_device_hot_add(Monitor *mon, const QDict *qdict);
diff --git a/vl.c b/vl.c
index 7df9328..3f4bb22 100644
--- a/vl.c
+++ b/vl.c
@@ -1875,18 +1875,12 @@ static void bdrv_format_print(void *opaque, const char *name)
     fprintf(stderr, " %s", name);
 }
 
-void drive_uninit(BlockDriverState *bdrv)
+void drive_uninit(DriveInfo *dinfo)
 {
-    DriveInfo *dinfo;
-
-    QTAILQ_FOREACH(dinfo, &drives, next) {
-        if (dinfo->bdrv != bdrv)
-            continue;
-        qemu_opts_del(dinfo->opts);
-        QTAILQ_REMOVE(&drives, dinfo, next);
-        qemu_free(dinfo);
-        break;
-    }
+    qemu_opts_del(dinfo->opts);
+    bdrv_delete(dinfo->bdrv);
+    QTAILQ_REMOVE(&drives, dinfo, next);
+    qemu_free(dinfo);
 }
 
 DriveInfo *drive_init(QemuOpts *opts, void *opaque,
-- 
1.6.2.5

  parent reply	other threads:[~2009-09-25 19:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25 19:42 [Qemu-devel] [PATCH 00/24] qdev: bus management updates Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 01/24] unbreak usb pass-through on linux Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 02/24] allow qdev busses allocations be inplace Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 03/24] switch scsi bus to inplace allocation Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 04/24] switch usb " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 05/24] switch ide " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 06/24] inplace allocation for pci, split irq init Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 07/24] convert pci bridge to qdev Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 08/24] piix_pci: kill PIIX3IrqState Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 09/24] qdev: device free fixups Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 10/24] Add exit callback to DeviceInfo Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 11/24] Implement scsi device destruction Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 12/24] pci: use qdev for " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 13/24] pci: move unregister from PCIDevice to PCIDeviceInfo Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 14/24] usb: hook unplug into qdev, cleanups + fixes Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 15/24] switch qemu-config to qemu_error Gerd Hoffmann
2009-09-28 20:40   ` Markus Armbruster
2009-09-29  8:57     ` Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 16/24] qdev hotplug: infrastructure and monitor commands Gerd Hoffmann
2009-09-28 20:32   ` Markus Armbruster
2009-09-29  9:08     ` Gerd Hoffmann
2009-09-29 12:25       ` Markus Armbruster
2009-09-29 13:23         ` Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 17/24] usb: hotplug windup Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 18/24] scsi: " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 19/24] pci: " Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 20/24] pci: windup acpi-based hotplug Gerd Hoffmann
2009-09-25 19:42 ` Gerd Hoffmann [this message]
2009-09-25 19:42 ` [Qemu-devel] [PATCH 22/24] refactor drive_hot_add Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 23/24] allow if=none for drive_add Gerd Hoffmann
2009-09-25 19:42 ` [Qemu-devel] [PATCH 24/24] store a pointer to QemuOpts in DeviceState, release it when zapping a device Gerd Hoffmann
2009-09-25 20:57 ` [Qemu-devel] [PATCH 00/24] qdev: bus management updates Anthony Liguori
2009-09-28 20:40 ` Markus Armbruster

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=1253907769-1067-22-git-send-email-kraxel@redhat.com \
    --to=kraxel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.