@@ -202,7 +202,8 @@ struct DeviceListener {
* hide a failover device depending for example on the device
* opts.
*/
- bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts);
+ bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts,
+ Error **errp);
QTAILQ_ENTRY(DeviceListener) link;
};
@@ -804,12 +805,13 @@ void device_listener_unregister(DeviceListener *listener);
/**
* @qdev_should_hide_device:
* @opts: QemuOpts as passed on cmdline.
+ * @errp: pointer to error object
*
* Check if a device should be added.
* When a device is added via qdev_device_add() this will be called,
* and return if the device should be added now or not.
*/
-bool qdev_should_hide_device(QemuOpts *opts);
+bool qdev_should_hide_device(QemuOpts *opts, Error **errp);
typedef enum MachineInitPhase {
/* current_machine is NULL. */
@@ -211,13 +211,13 @@ void device_listener_unregister(DeviceListener *listener)
QTAILQ_REMOVE(&device_listeners, listener, link);
}
-bool qdev_should_hide_device(QemuOpts *opts)
+bool qdev_should_hide_device(QemuOpts *opts, Error **errp)
{
DeviceListener *listener;
QTAILQ_FOREACH(listener, &device_listeners, link) {
if (listener->hide_device) {
- if (listener->hide_device(listener, opts)) {
+ if (listener->hide_device(listener, opts, errp)) {
return true;
}
}
@@ -3279,7 +3279,7 @@ static void virtio_net_migration_state_notifier(Notifier *notifier, void *data)
}
static bool failover_hide_primary_device(DeviceListener *listener,
- QemuOpts *device_opts)
+ QemuOpts *device_opts, Error **errp)
{
VirtIONet *n = container_of(listener, VirtIONet, primary_listener);
const char *standby_id;
@@ -627,8 +627,8 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
error_setg(errp, "Device with failover_pair_id don't have id");
return NULL;
}
- if (qdev_should_hide_device(opts)) {
- if (bus && !qbus_is_hotpluggable(bus)) {
+ if (qdev_should_hide_device(opts, errp)) {
+ if (errp && !*errp && bus && !qbus_is_hotpluggable(bus)) {
error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);
}
return NULL;
This allows an error to be reported to the caller of qdev_device_add() Signed-off-by: Laurent Vivier <lvivier@redhat.com> --- include/hw/qdev-core.h | 6 ++++-- hw/core/qdev.c | 4 ++-- hw/net/virtio-net.c | 2 +- softmmu/qdev-monitor.c | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-)