From: Liu Ping Fan <pingf...@linux.vnet.ibm.com> Unplug divides into two steps: request and complete The name "req" show more clearly about its meaning and as to the complete, it is qdev_delete_subtree()
Also adding ret to indicate the request can be eject or not Signed-off-by: Liu Ping Fan <pingf...@linux.vnet.ibm.com> --- hw/pci-hotplug.c | 4 ++-- hw/qdev-monitor.c | 2 +- hw/qdev.c | 7 ++++--- hw/qdev.h | 2 +- hw/scsi-bus.c | 4 ++-- hw/usb/dev-storage.c | 2 +- hw/xen_platform.c | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index e7fb780..6faff33 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -192,7 +192,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, dev = NULL; if (dev && dinfo) { if (scsi_hot_add(mon, &dev->qdev, dinfo, 0) != 0) { - qdev_unplug(&dev->qdev, NULL); + qdev_unplug_req(&dev->qdev, NULL); dev = NULL; } } @@ -271,7 +271,7 @@ static int pci_device_hot_remove(Monitor *mon, const char *pci_addr) return -1; } - qdev_unplug(&d->qdev, &local_err); + qdev_unplug_req(&d->qdev, &local_err); if (error_is_set(&local_err)) { monitor_printf(mon, "%s\n", error_get_pretty(local_err)); error_free(local_err); diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 018b386..fdd9539 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -606,7 +606,7 @@ void qmp_device_del(const char *id, Error **errp) return; } - qdev_unplug(dev, errp); + qdev_unplug_req(dev, errp); } void qdev_machine_init(void) diff --git a/hw/qdev.c b/hw/qdev.c index d6c8130..e2339a1 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -194,13 +194,13 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, dev->alias_required_for_version = required_for_version; } -void qdev_unplug(DeviceState *dev, Error **errp) +int qdev_unplug_req(DeviceState *dev, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(dev); if (!dev->parent_bus->allow_hotplug) { error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); - return; + return -1; } assert(dc->unplug != NULL); @@ -208,8 +208,9 @@ void qdev_unplug(DeviceState *dev, Error **errp) if (dc->unplug(dev) < 0) { error_set(errp, QERR_UNDEFINED_ERROR); - return; + return -1; } + return 0; } static int qdev_reset_one(DeviceState *dev, void *opaque) diff --git a/hw/qdev.h b/hw/qdev.h index 6f97990..182cfa5 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -160,7 +160,7 @@ int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; void qdev_init_nofail(DeviceState *dev); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version); -void qdev_unplug(DeviceState *dev, Error **errp); +int qdev_unplug_req(DeviceState *dev, Error **errp); void qdev_free(DeviceState *dev); void qdev_delete_subtree(DeviceState *dev); int qdev_simple_unplug_cb(DeviceState *dev); diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 4981a02..023211a 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1802,7 +1802,7 @@ static int get_scsi_requests(QEMUFile *f, void *pv, size_t size) return 0; } -static int scsi_qdev_unplug(DeviceState *qdev) +static int scsi_qdev_unplug_req(DeviceState *qdev) { SCSIDevice *dev = SCSI_DEVICE(qdev); SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus); @@ -1849,7 +1849,7 @@ static void scsi_device_class_init(ObjectClass *klass, void *data) DeviceClass *k = DEVICE_CLASS(klass); k->bus_type = TYPE_SCSI_BUS; k->init = scsi_qdev_init; - k->unplug = scsi_qdev_unplug; + k->unplug = scsi_qdev_unplug_req; k->exit = scsi_qdev_exit; k->props = scsi_props; } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index ff48d91..8871b2b 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -510,7 +510,7 @@ static void usb_msd_password_cb(void *opaque, int err) err = usb_device_attach(&s->dev); if (err) - qdev_unplug(&s->dev.qdev, NULL); + qdev_unplug_req(&s->dev.qdev, NULL); } static void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req) diff --git a/hw/xen_platform.c b/hw/xen_platform.c index c1fe984..0231a40 100644 --- a/hw/xen_platform.c +++ b/hw/xen_platform.c @@ -103,7 +103,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) { if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_STORAGE_IDE) { - qdev_unplug(&(d->qdev), NULL); + qdev_unplug_req(&(d->qdev), NULL); } } -- 1.7.4.4