diff options
author | Jens Freimann | 2019-10-29 12:48:55 +0100 |
---|---|---|
committer | Michael S. Tsirkin | 2019-10-29 23:55:26 +0100 |
commit | f3a8505656935cde32e28c1c6317f725084da1e0 (patch) | |
tree | c86d50bd3de257e80dd8dbc1c44318f256ee8fdc /hw/core/qdev.c | |
parent | Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2019-10-29' into ... (diff) | |
download | qemu-f3a8505656935cde32e28c1c6317f725084da1e0.tar.gz qemu-f3a8505656935cde32e28c1c6317f725084da1e0.tar.xz qemu-f3a8505656935cde32e28c1c6317f725084da1e0.zip |
qdev/qbus: add hidden device support
This adds support for hiding a device to the qbus and qdev APIs. The
first user of this will be the virtio-net failover feature but the API
introduced with this patch could be used to implement other features as
well, for example hiding pci devices when a pci bus is powered off.
qdev_device_add() is modified to check for a failover_pair_id
argument in the option string. A DeviceListener callback
should_be_hidden() is added. It can be used by a standby device to
inform qdev that this device should not be added now. The standby device
handler can store the device options to plug the device in at a later
point in time.
One reason for hiding the device is that we don't want to expose both
devices to the guest kernel until the respective virtio feature bit
VIRTIO_NET_F_STANDBY was negotiated and we know that the devices will be
handled correctly by the guest.
More information on the kernel feature this is using:
https://www.kernel.org/doc/html/latest/networking/net_failover.html
An example where the primary device is a vfio-pci device and the standby
device is a virtio-net device:
A device is hidden when it has an "failover_pair_id" option, e.g.
-device virtio-net-pci,...,failover=on,...
-device vfio-pci,...,failover_pair_id=net1,...
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
Message-Id: <20191029114905.6856-2-jfreimann@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/core/qdev.c')
-rw-r--r-- | hw/core/qdev.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cbad6c1d55..3b8d43d0fd 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -212,6 +212,30 @@ void device_listener_unregister(DeviceListener *listener) QTAILQ_REMOVE(&device_listeners, listener, link); } +bool qdev_should_hide_device(QemuOpts *opts) +{ + int rc = -1; + DeviceListener *listener; + + QTAILQ_FOREACH(listener, &device_listeners, link) { + if (listener->should_be_hidden) { + /* + * should_be_hidden_will return + * 1 if device matches opts and it should be hidden + * 0 if device matches opts and should not be hidden + * -1 if device doesn't match ops + */ + rc = listener->should_be_hidden(listener, opts); + } + + if (rc > 0) { + break; + } + } + + return rc > 0; +} + void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version) { |