[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction |
Date: |
Thu, 24 Sep 2009 21:15:22 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) |
Gerd Hoffmann <address@hidden> writes:
> Signed-off-by: Gerd Hoffmann <address@hidden>
> ---
> 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);
> }
If I understand this correctly, SCSI devices "overwrite": if you add a
new one with an existing SCSI ID, the old one gets disconnected
automatically. Isn't that inconsistent with other buses? PCI,
specifically. Question applies before your patch already.
> 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;
> }
You have scsi_qdev_exit() as qdev callback exit(). It does the generic
stuff, then runs the SCSIDevice callback destroy() for the specific
stuff. Shouldn't the two callbacks be named the same, to make their
relation more obvious?
>
> 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);
> }
>
[...]
- [Qemu-devel] [PATCH 00/13] qdev: bus management updates., Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 05/13] inplace allocation for pci, split irq init., Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 02/13] switch scsi bus to inplace allocation., Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 04/13] switch ide bus to inplace allocation., Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 03/13] switch usb bus to inplace allocation., Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 01/13] allow qdev busses allocations be inplace, Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 07/13] piix_pci: kill PIIX3IrqState, Gerd Hoffmann, 2009/09/22
- [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Gerd Hoffmann, 2009/09/22
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction,
Markus Armbruster <=
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Gerd Hoffmann, 2009/09/25
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Markus Armbruster, 2009/09/25
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Gerd Hoffmann, 2009/09/25
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Artyom Tarasenko, 2009/09/25
- Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction, Markus Armbruster, 2009/09/25
[Qemu-devel] [PATCH 12/13] pci: move unregister from PCIDevice to PCIDeviceInfo, Gerd Hoffmann, 2009/09/22