[Libguestfs] [PATCH v3 10/11] launch: Add a virtio-rng device to the guest.

Richard W.M. Jones rjones at redhat.com
Tue Mar 22 19:05:29 UTC 2016


---
 src/launch-direct.c  | 11 +++++++++++
 src/launch-libvirt.c | 14 ++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/launch-direct.c b/src/launch-direct.c
index d0af04d..52badc2 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -451,6 +451,17 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
   ADD_CMDLINE ("-initrd");
   ADD_CMDLINE (initrd);
 
+  /* Add a random number generator (backend for virtio-rng).  This
+   * isn't strictly necessary but means we won't need to hang around
+   * when needing entropy.
+   */
+  if (qemu_supports_device (g, data, "virtio-rng-pci")) {
+    ADD_CMDLINE ("-object");
+    ADD_CMDLINE ("rng-random,filename=/dev/urandom,id=rng0");
+    ADD_CMDLINE ("-device");
+    ADD_CMDLINE ("virtio-rng-pci,rng=rng0");
+  }
+
   /* Add drives */
   virtio_scsi = qemu_supports_virtio_scsi (g, data);
 
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 9f2672d..c6cc740 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -1251,6 +1251,20 @@ construct_libvirt_xml_devices (guestfs_h *g,
     }
 #endif
 
+    /* Add a random number generator (backend for virtio-rng). */
+    start_element ("rng") {
+      attribute ("model", "virtio");
+      start_element ("backend") {
+        attribute ("model", "random");
+        /* It'd be nice to do this, but libvirt says:
+         *   file '/dev/urandom' is not a supported random source
+         * Let libvirt pick /dev/random automatically instead.
+         * See also: https://bugzilla.redhat.com/show_bug.cgi?id=1074464
+         */
+        //string ("/dev/urandom");
+      } end_element ();
+    } end_element ();
+
     /* virtio-scsi controller. */
     start_element ("controller") {
       attribute ("type", "scsi");
-- 
2.7.4




More information about the Libguestfs mailing list