[PATCH 3/7] qemu: Implement builtin rng backend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since v4.2-rc0, QEMU introduced a builtin rng backend that uses
getrandom() syscall to generate random. Add it to libvirt with the
backend model 'builtin'.

https://bugzilla.redhat.com/show_bug.cgi?id=1785091

Signed-off-by: Han Han <hhan@xxxxxxxxxx>
---
 src/conf/domain_audit.c |  2 ++
 src/conf/domain_conf.c  |  9 +++++++++
 src/conf/domain_conf.h  |  1 +
 src/qemu/qemu_command.c | 15 +++++++++++++++
 src/qemu/qemu_domain.c  |  3 +++
 5 files changed, 30 insertions(+)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index fdccc585..138f2701 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -227,6 +227,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
             newsrcpath = virDomainChrSourceDefGetPath(newDef->source.chardev);
             break;
 
+        case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
         case VIR_DOMAIN_RNG_BACKEND_LAST:
             break;
         }
@@ -242,6 +243,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
             oldsrcpath = virDomainChrSourceDefGetPath(oldDef->source.chardev);
             break;
 
+        case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
         case VIR_DOMAIN_RNG_BACKEND_LAST:
             break;
         }
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index afa072e1..76599806 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1112,6 +1112,7 @@ VIR_ENUM_IMPL(virDomainRNGBackend,
               VIR_DOMAIN_RNG_BACKEND_LAST,
               "random",
               "egd",
+              "builtin",
 );
 
 VIR_ENUM_IMPL(virDomainTPMModel,
@@ -14821,6 +14822,7 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt,
             goto error;
         break;
 
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         break;
     }
@@ -17764,6 +17766,7 @@ virDomainRNGFind(virDomainDefPtr def,
                 continue;
             break;
 
+        case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
         case VIR_DOMAIN_RNG_BACKEND_LAST:
             break;
         }
@@ -26443,6 +26446,11 @@ virDomainRNGDefFormat(virBufferPtr buf,
             return -1;
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</backend>\n");
+        break;
+
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
+        virBufferAddLit(buf, "/>\n");
+        break;
 
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         break;
@@ -26474,6 +26482,7 @@ virDomainRNGDefFree(virDomainRNGDefPtr def)
     case VIR_DOMAIN_RNG_BACKEND_EGD:
         virObjectUnref(def->source.chardev);
         break;
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         break;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e012975f..ac1db682 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2103,6 +2103,7 @@ typedef enum {
 typedef enum {
     VIR_DOMAIN_RNG_BACKEND_RANDOM,
     VIR_DOMAIN_RNG_BACKEND_EGD,
+    VIR_DOMAIN_RNG_BACKEND_BUILTIN,
 
     VIR_DOMAIN_RNG_BACKEND_LAST
 } virDomainRNGBackend;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a8137b3a..d372d289 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5579,6 +5579,7 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
 
     switch ((virDomainRNGBackend) rng->backend) {
     case VIR_DOMAIN_RNG_BACKEND_RANDOM:
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         /* no chardev backend is needed */
         return 0;
@@ -5640,6 +5641,20 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
 
         break;
 
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_BUILTIN)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                    _("this qemu doesn't support the rng-builtin "
+                        "backend"));
+            return -1;
+        }
+
+        if (qemuMonitorCreateObjectProps(props, "rng-builtin", objAlias,
+                                         NULL) < 0)
+            return -1;
+
+        break;
+
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("unknown rng-random backend"));
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ff87720f..19636e6f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -14807,6 +14807,7 @@ qemuDomainSetupRNG(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
             return -1;
 
     case VIR_DOMAIN_RNG_BACKEND_EGD:
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         /* nada */
         break;
@@ -15786,6 +15787,7 @@ qemuDomainNamespaceSetupRNG(virDomainObjPtr vm,
         break;
 
     case VIR_DOMAIN_RNG_BACKEND_EGD:
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         break;
     }
@@ -15809,6 +15811,7 @@ qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm,
         break;
 
     case VIR_DOMAIN_RNG_BACKEND_EGD:
+    case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
         break;
     }
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux