From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 11/24] Implement scsi device destruction
Date: Fri, 25 Sep 2009 21:42:36 +0200 [thread overview]
Message-ID: <1253907769-1067-12-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1253907769-1067-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/scsi-bus.c | 24 +++++++++++++++++++++---
hw/scsi-disk.c | 6 ------
hw/scsi-generic.c | 2 --
3 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 881e363..27defc4 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -30,6 +30,7 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
+ int rc = -1;
if (dev->id == -1) {
for (dev->id = 0; dev->id < bus->ndev; dev->id++) {
@@ -43,21 +44,38 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
}
if (bus->devs[dev->id]) {
- bus->devs[dev->id]->info->destroy(bus->devs[dev->id]);
+ qdev_free(&bus->devs[dev->id]->qdev);
}
bus->devs[dev->id] = dev;
dev->info = info;
- return dev->info->init(dev);
+ rc = dev->info->init(dev);
+ if (rc != 0) {
+ bus->devs[dev->id] = NULL;
+ }
err:
- return -1;
+ return rc;
+}
+
+static int scsi_qdev_exit(DeviceState *qdev)
+{
+ SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
+
+ assert(bus->devs[dev->id] != NULL);
+ if (bus->devs[dev->id]->info->destroy) {
+ bus->devs[dev->id]->info->destroy(bus->devs[dev->id]);
+ }
+ bus->devs[dev->id] = NULL;
+ return 0;
}
void scsi_qdev_register(SCSIDeviceInfo *info)
{
info->qdev.bus_info = &scsi_bus_info;
info->qdev.init = scsi_qdev_init;
+ info->qdev.exit = scsi_qdev_exit;
qdev_register(&info->qdev);
}
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index de8e314..0f029f8 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -936,11 +936,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
}
}
-static void scsi_destroy(SCSIDevice *d)
-{
- qemu_free(d);
-}
-
static int scsi_disk_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
@@ -974,7 +969,6 @@ 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 f8c010b..86d1e54 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -668,8 +668,6 @@ static void scsi_destroy(SCSIDevice *d)
qemu_free(r);
r = n;
}
-
- qemu_free(d);
}
static int scsi_generic_initfn(SCSIDevice *dev)
--
1.6.2.5
next prev 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 ` Gerd Hoffmann [this message]
2009-09-25 19:42 ` [Qemu-devel] [PATCH 12/24] pci: use qdev for device destruction 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 ` [Qemu-devel] [PATCH 21/24] drive cleanup fixes Gerd Hoffmann
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-12-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 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).