Skip to contentSkip to conversation

qdev: Let BusRealize() return a boolean value to indicate error

PATCH In review Philippe Mathieu-Daudé 4 participants 8 messages Sep 20, 2020 – Sep 21, 2020

lore
Share & tools
lore
#0 lore raw

cover qdev: Let BusRealize() return a boolean value to indicate error

To ease error checking in DeviceRealize handlers, let BusRealize return a boolean value, as qbus_realize() does.

Having DeviceRealize similarly return a boolean value is left as an exercice for volunteers :)

Philippe Mathieu-Daudé (2):
qdev: Document qbus_realize() and qbus_unrealize()
qdev: Let BusRealize() return a boolean value to indicate error

 include/hw/qdev-core.h | 26 +++++++++++++++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 43 insertions(+), 10 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 qdev: Document qbus_realize() and qbus_unrealize()

Add some documentation for the qbus_realize() and qbus_unrealize() functions introduced in commit 9940b2cfbc0.

---
 include/hw/qdev-core.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/hw/qdev-core.h +12 -0
index e025ba9653f..02ac1c50b7f 100644
@@ -675,7 +675,19 @@ typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
 void qbus_create_inplace(void *bus, size_t size, const char *typename,
                          DeviceState *parent, const char *name);
 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
+/**
+ * qbus_realize: Realize a bus
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
 bool qbus_realize(BusState *bus, Error **errp);
+/**
+ * qbus_realize: Unrealize a bus
+ * @bus: bus to unrealize
+ */
 void qbus_unrealize(BusState *bus);
 
 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 qdev: Let BusRealize() return a boolean value to indicate error

In reply to Philippe Mathieu-Daudé

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize() with the ability to return a boolean value if an error occured, thus the caller does not need to check if the Error* pointer is set.
Provide the same ability to the BusRealize type.

---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)
include/hw/qdev-core.h +13 -1
index 02ac1c50b7f..eecfe794a71 100644
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
hw/hyperv/vmbus.c +3 -2
index 6ef895bc352..8a0452b2464 100644
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
hw/nubus/nubus-bus.c +3 -2
index 942a6d5342d..d20d9c0f72c 100644
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
hw/pci/pci.c +9 -3
index de0fae10ab9..f535ebac847 100644
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }
 
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
hw/xen/xen-bus.c +3 -2
index 9ce1c9540b9..d7ef5d05e37 100644
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }
 
-    return;
+    return true;
 
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,
Signature · 1 line
2.26.2
Acked-by on v1 2/2
#3 lore raw
Quoted 17 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]> On Behalf Of Philippe Mathieu-Daudé
Sent: 20 September 2020 12:44
To: Markus Armbruster <[email protected]>; [email protected]
Cc: Laurent Vivier <[email protected]>; Paolo Bonzini <[email protected]>; Anthony Perard <[email protected]>; Stefano Stabellini <[email protected]>; Daniel P. Berrangé <[email protected]>; Eduardo Habkost <[email protected]>; Paul Durrant <[email protected]>; Marcel Apfelbaum <[email protected]>; Michael S. Tsirkin <[email protected]>; xen- [email protected]; Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 2/2] qdev: Let BusRealize() return a boolean value to indicate error

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize() with the ability to return a boolean value if an error occured, thus the caller does not need to check if the Error* pointer is set.
Provide the same ability to the BusRealize type.

Quoted 7 lines
---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 110 lines · Philippe Mathieu-Daudé

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize() with the ability to return a boolean value if an error occured, thus the caller does not need to check if the Error* pointer is set.
Provide the same ability to the BusRealize type.

---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)
include/hw/qdev-core.h +13 -1
index 02ac1c50b7f..eecfe794a71 100644
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
hw/hyperv/vmbus.c +3 -2
index 6ef895bc352..8a0452b2464 100644
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
hw/nubus/nubus-bus.c +3 -2
index 942a6d5342d..d20d9c0f72c 100644
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
hw/pci/pci.c +3 -1
index de0fae10ab9..f535ebac847 100644
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }

hw/pci/pci.c static void pci_bus_realize(BusState *qbus, Error **errp) · line 136

Quoted 10 lines
hw/pci/pci.c +4 -2
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }

We now update bus->flags only when pci_bus_realize() succeeds. Is this a bug fix?

Quoted 28 lines
hw/pci/pci.c +2 -0
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
hw/xen/xen-bus.c +1 -1
index 9ce1c9540b9..d7ef5d05e37 100644
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }

hw/xen/xen-bus.c static void xen_bus_realize(BusState *bus, Error **errp) · line 488

Quoted 10 lines
hw/xen/xen-bus.c +2 -1
 
-    return;
+    return true;
 
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,

I can't see an actual use of the new return value. Am I blind?

#5 lore raw
Quoted 118 lines · Markus Armbruster
Quoted 116 lines · Philippe Mathieu-Daudé

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize() with the ability to return a boolean value if an error occured, thus the caller does not need to check if the Error* pointer is set.
Provide the same ability to the BusRealize type.

---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)
include/hw/qdev-core.h +13 -1
index 02ac1c50b7f..eecfe794a71 100644
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
hw/hyperv/vmbus.c +3 -2
index 6ef895bc352..8a0452b2464 100644
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
hw/nubus/nubus-bus.c +3 -2
index 942a6d5342d..d20d9c0f72c 100644
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
hw/pci/pci.c +4 -2
index de0fae10ab9..f535ebac847 100644
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
Quoted 7 lines

hw/pci/pci.c static void pci_bus_realize(BusState *qbus, Error **errp) · line 136

Quoted 4 lines
hw/pci/pci.c +3 -1
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }

We now update bus->flags only when pci_bus_realize() succeeds. Is this a bug fix?

Fortunate side effect :) I'll let the PCI maintainers have a look at it.

Quoted 33 lines
Quoted 33 lines
hw/pci/pci.c +2 -0
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
hw/xen/xen-bus.c +2 -2
index 9ce1c9540b9..d7ef5d05e37 100644
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }
 
-    return;
+    return true;
 
Quoted 8 lines

hw/xen/xen-bus.c static void xen_bus_realize(BusState *bus, Error **errp) · line 488

Quoted 6 lines
hw/xen/xen-bus.c +1 -0
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,

I can't see an actual use of the new return value. Am I blind?

You aren't, I'm trying to make a 240 patches series digestible by splitting it. One device is a (hotplug) PCIe bridge, as we can plug/unplug it, this calls multiple realize/unrealize, and I want to be sure the children objects are properly realized so I care about this return value.

As it seems an improvement from an API PoV (following your recent cleanup and code style change: simplify returning boolean for Error instead of checking *errp is set). I thought merging it the sooner is better, but I don't have problem reposting that later.

Regards,

Phil.

#6 lore raw
Quoted 127 lines · Philippe Mathieu-Daudé
Quoted 118 lines · Markus Armbruster
Quoted 116 lines · Philippe Mathieu-Daudé

Commit 9940b2cfbc0 introduced qdev_realize() and qbus_realize() with the ability to return a boolean value if an error occured, thus the caller does not need to check if the Error* pointer is set.
Provide the same ability to the BusRealize type.

---
 include/hw/qdev-core.h | 14 +++++++++++++-
 hw/hyperv/vmbus.c      |  5 +++--
 hw/nubus/nubus-bus.c   |  5 +++--
 hw/pci/pci.c           | 12 +++++++++---
 hw/xen/xen-bus.c       |  5 +++--
 5 files changed, 31 insertions(+), 10 deletions(-)
include/hw/qdev-core.h +13 -1
index 02ac1c50b7f..eecfe794a71 100644
@@ -32,7 +32,19 @@ typedef enum DeviceCategory {
 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
 typedef void (*DeviceUnrealize)(DeviceState *dev);
 typedef void (*DeviceReset)(DeviceState *dev);
-typedef void (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusRealize: Realize @bus.
+ * @bus: bus to realize
+ * @errp: pointer to error object
+ *
+ * On success, return true.
+ * On failure, store an error through @errp and return false.
+ */
+typedef bool (*BusRealize)(BusState *bus, Error **errp);
+/**
+ * BusUnrealize: Unrealize @bus.
+ * @bus: bus to unrealize
+ */
 typedef void (*BusUnrealize)(BusState *bus);
 
 /**
hw/hyperv/vmbus.c +3 -2
index 6ef895bc352..8a0452b2464 100644
@@ -2487,7 +2487,7 @@ static const TypeInfo vmbus_dev_type_info = {
     .instance_init = vmbus_dev_instance_init,
 };
 
-static void vmbus_realize(BusState *bus, Error **errp)
+static bool vmbus_realize(BusState *bus, Error **errp)
 {
     int ret = 0;
     Error *local_err = NULL;
@@ -2519,7 +2519,7 @@ static void vmbus_realize(BusState *bus, Error **errp)
         goto clear_event_notifier;
     }
 
-    return;
+    return true;
 
 clear_event_notifier:
     event_notifier_cleanup(&vmbus->notifier);
@@ -2528,6 +2528,7 @@ remove_msg_handler:
 error_out:
     qemu_mutex_destroy(&vmbus->rx_queue_lock);
     error_propagate(errp, local_err);
+    return false;
 }
 
 static void vmbus_unrealize(BusState *bus)
hw/nubus/nubus-bus.c +3 -2
index 942a6d5342d..d20d9c0f72c 100644
@@ -65,12 +65,13 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
-static void nubus_realize(BusState *bus, Error **errp)
+static bool nubus_realize(BusState *bus, Error **errp)
 {
     if (!nubus_find()) {
         error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
-        return;
+        return false;
     }
+    return true;
 }
 
 static void nubus_init(Object *obj)
hw/pci/pci.c +4 -2
index de0fae10ab9..f535ebac847 100644
@@ -115,7 +115,7 @@ static void pcibus_machine_done(Notifier *notifier, void *data)
     }
 }
 
-static void pci_bus_realize(BusState *qbus, Error **errp)
+static bool pci_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
@@ -123,13 +123,17 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
     qemu_add_machine_init_done_notifier(&bus->machine_done);
 
     vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_pcibus, bus);
+
+    return true;
 }
 
-static void pcie_bus_realize(BusState *qbus, Error **errp)
+static bool pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
 
Quoted 7 lines

hw/pci/pci.c static void pci_bus_realize(BusState *qbus, Error **errp) · line 136

Quoted 4 lines
hw/pci/pci.c +3 -1
-    pci_bus_realize(qbus, errp);
+    if (!pci_bus_realize(qbus, errp)) {
+        return false;
+    }

We now update bus->flags only when pci_bus_realize() succeeds. Is this a bug fix?

Quoted 2 lines

Fortunate side effect :) I'll let the PCI maintainers have a look at it.

If it's an observable change, the commit message must mention it. I'd put it in its own commit then.

Even if it's not observable, explaining why in the commit message would help, I think.

Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
hw/pci/pci.c +2 -0
     /*
      * A PCI-E bus can support extended config space if it's the root
@@ -144,6 +148,8 @@ static void pcie_bus_realize(BusState *qbus, Error **errp)
             bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
         }
     }
+
+    return true;
 }
 
 static void pci_bus_unrealize(BusState *qbus)
hw/xen/xen-bus.c +2 -2
index 9ce1c9540b9..d7ef5d05e37 100644
@@ -444,7 +444,7 @@ static void xen_bus_unrealize(BusState *bus)
     }
 }
 
-static void xen_bus_realize(BusState *bus, Error **errp)
+static bool xen_bus_realize(BusState *bus, Error **errp)
 {
     XenBus *xenbus = XEN_BUS(bus);
     unsigned int domid;
@@ -478,10 +478,11 @@ static void xen_bus_realize(BusState *bus, Error **errp)
                           "failed to set up enumeration watch: ");
     }
 
-    return;
+    return true;
 
Quoted 8 lines

hw/xen/xen-bus.c static void xen_bus_realize(BusState *bus, Error **errp) · line 488

Quoted 6 lines
hw/xen/xen-bus.c +1 -0
 fail:
     xen_bus_unrealize(bus);
+    return false;
 }
 
 static void xen_bus_unplug_request(HotplugHandler *hotplug,

I can't see an actual use of the new return value. Am I blind?

Quoted 5 lines

You aren't, I'm trying to make a 240 patches series digestible by splitting it. One device is a (hotplug) PCIe bridge, as we can plug/unplug it, this calls multiple realize/unrealize, and I want to be sure the children objects are properly realized so I care about this return value.

I wonder why you need to realize buses. Current code only ever does that via device_set_realized() -> qbus_realize() -> object_property_set_bool() -> bus_set_realized(), i.e. when realizing the device that provides the bus.

Even if you do need to, why can't you call qbus_realize()? It already returns true on success, false on failure.

Quoted 4 lines

As it seems an improvement from an API PoV (following your recent cleanup and code style change: simplify returning boolean for Error instead of checking *errp is set). I thought merging it the sooner is better, but I don't have problem reposting that later.

Reviewing API improvements is always hard when we can't see the users, yet.