Blob Blame History Raw
From a8c286e9a7972833e1c8cf7da8d91406fa8d0f79 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Mar 2016 14:51:19 +0000
Subject: [PATCH] launch: Add a virtio-rng device to the guest.

(cherry picked from commit 9423c16607259b30985c46d04db9958ec079aa42)
---
 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 8d99979..25c97a7 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -454,6 +454,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 ceaa696..3df1833 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -1304,6 +1304,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");
-- 
1.8.3.1