[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 1/8] qdev: add an Error parameter to the DeviceListener hi
From: |
Laurent Vivier |
Subject: |
[RFC PATCH v2 1/8] qdev: add an Error parameter to the DeviceListener hide_device() function |
Date: |
Fri, 20 Aug 2021 16:19:55 +0200 |
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(-)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index bafc311bfa1b..e23b23a2f8d6 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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. */
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index cefc5eaa0a92..13f4c1e696bf 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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;
}
}
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 16d20cdee52a..542f9e167eb4 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -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;
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 721dec2d8200..7adf0d22beb1 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -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;
--
2.31.1
- [RFC PATCH v2 0/8] virtio-net failover cleanup and new features, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 1/8] qdev: add an Error parameter to the DeviceListener hide_device() function,
Laurent Vivier <=
- [RFC PATCH v2 2/8] qdev/qbus: remove failover specific code, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 3/8] failover: virtio-net: remove failover_primary_hidden flag, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 5/8] failover: hide the PCI device if the virtio-net device is not present, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 4/8] failover: pci: move failover hotplug/unplug code into pci subsystem, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 6/8] failover: pci: unregister ROM on unplug, Laurent Vivier, 2021/08/20
- [RFC PATCH v2 7/8] pci: automatically unplug a PCI card before migration, Laurent Vivier, 2021/08/20