virtio-rng-pci: create a default backend if none exists
authorAnthony Liguori <aliguori@us.ibm.com>
Fri, 26 Oct 2012 17:05:49 +0000 (12:05 -0500)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 16 Nov 2012 14:36:14 +0000 (08:36 -0600)
This allows you to specify:

  $ qemu -device virtio-rng-pci

And things will Just Work with a reasonable default.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/virtio-pci.c
hw/virtio-rng.h

index f90296d6728fb612e6182040ed943a3389c1ea7e..71f4fb5dc6ad03d8091abdab3822befc2d31b590 100644 (file)
@@ -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;
index 7324d0ab57ef1959f704e5c37866792c599710de..f42d748eba3a550a1bec0bc9a7911a641162e4c4 100644 (file)
@@ -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