From: Anthony Liguori Date: Fri, 26 Oct 2012 17:05:49 +0000 (-0500) Subject: virtio-rng-pci: create a default backend if none exists X-Git-Tag: v1.3.0-rc0~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=500054f161c29ff9db125c0b872809191ad6920b;p=thirdparty%2Fqemu.git virtio-rng-pci: create a default backend if none exists This allows you to specify: $ qemu -device virtio-rng-pci And things will Just Work with a reasonable default. Signed-off-by: Anthony Liguori --- diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index f90296d6728..71f4fb5dc6a 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -857,6 +857,19 @@ static int virtio_rng_init_pci(PCIDevice *pci_dev) VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIODevice *vdev; + if (proxy->rng.rng == NULL) { + proxy->rng.default_backend = RNG_RANDOM(object_new(TYPE_RNG_RANDOM)); + + object_property_add_child(OBJECT(pci_dev), + "default-backend", + OBJECT(proxy->rng.default_backend), + NULL); + + object_property_set_link(OBJECT(pci_dev), + OBJECT(proxy->rng.default_backend), + "rng", NULL); + } + vdev = virtio_rng_init(&pci_dev->qdev, &proxy->rng); if (!vdev) { return -1; diff --git a/hw/virtio-rng.h b/hw/virtio-rng.h index 7324d0ab57e..f42d748eba3 100644 --- a/hw/virtio-rng.h +++ b/hw/virtio-rng.h @@ -13,6 +13,7 @@ #define _QEMU_VIRTIO_RNG_H #include "qemu/rng.h" +#include "qemu/rng-random.h" /* The Virtio ID for the virtio rng device */ #define VIRTIO_ID_RNG 4 @@ -21,6 +22,7 @@ struct VirtIORNGConf { RngBackend *rng; uint64_t max_bytes; uint32_t period_ms; + RndRandom *default_backend; }; #endif