Cloud Hypervisor supports virtio-rng devices and the configuration of
the randomness source (e.g. /dev/random or /dev/urandom).
This commit adds support for configuring the RNG device via libvirt for
the ch driver.
Signed-off-by: Stefan Kober <stefan.kober(a)cyberus-technology.de>
---
src/ch/ch_domain.c | 8 +++++++-
src/ch/ch_monitor.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c
index c0c9acd85b..7231fdc49f 100644
--- a/src/ch/ch_domain.c
+++ b/src/ch/ch_domain.c
@@ -163,6 +163,7 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
case VIR_DOMAIN_DEVICE_CONTROLLER:
case VIR_DOMAIN_DEVICE_CHR:
case VIR_DOMAIN_DEVICE_HOSTDEV:
+ case VIR_DOMAIN_DEVICE_RNG:
break;
case VIR_DOMAIN_DEVICE_LEASE:
@@ -177,7 +178,6 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
- case VIR_DOMAIN_DEVICE_RNG:
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
@@ -218,6 +218,12 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev,
return -1;
}
+ if (def->nrngs > 1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Only a single RNG device can be configured for this
domain"));
+ return -1;
+ }
+
if (def->nserials > 1) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Only a single serial can be configured for this
domain"));
diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 5a490b75f6..3d3b4cb87d 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -302,6 +302,44 @@ virCHMonitorBuildDisksJson(virJSONValue *content, virDomainDef
*vmdef)
return 0;
}
+static int
+virCHMonitorBuildRngJson(virJSONValue *content, virDomainDef *vmdef)
+{
+ g_autoptr(virJSONValue) rng = virJSONValueNewObject();
+
+ if (vmdef->nrngs == 0) {
+ return 0;
+ }
+
+ if (vmdef->rngs[0]->model != VIR_DOMAIN_RNG_MODEL_VIRTIO) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Only virtio model is supported for RNG devices"));
+ return -1;
+ }
+
+ switch (vmdef->rngs[0]->backend) {
+ case VIR_DOMAIN_RNG_BACKEND_RANDOM:
+ if (virJSONValueObjectAppendString(rng, "src",
vmdef->rngs[0]->source.file) < 0)
+ return -1;
+
+ if (virJSONValueObjectAppend(content, "rng", &rng) < 0)
+ return -1;
+
+ break;
+
+ case VIR_DOMAIN_RNG_BACKEND_EGD:
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Only RANDOM backend is supported for RNG devices"));
+ return -1;
+
+ case VIR_DOMAIN_RNG_BACKEND_LAST:
+ break;
+ }
+
+ return 0;
+}
+
/**
* virCHMonitorBuildNetJson:
* @net: pointer to a guest network definition
@@ -501,6 +539,9 @@ virCHMonitorBuildVMJson(virCHDriver *driver, virDomainDef *vmdef,
if (virCHMonitorBuildDisksJson(content, vmdef) < 0)
return -1;
+ if (virCHMonitorBuildRngJson(content, vmdef) < 0)
+ return -1;
+
if (virCHMonitorBuildDevicesJson(content, vmdef) < 0)
return -1;
--
2.49.0
Show replies by date
On 5/16/25 09:57, Stefan Kober wrote:
Cloud Hypervisor supports virtio-rng devices and the configuration
of
the randomness source (e.g. /dev/random or /dev/urandom).
This commit adds support for configuring the RNG device via libvirt for
the ch driver.
Signed-off-by: Stefan Kober <stefan.kober(a)cyberus-technology.de>
---
src/ch/ch_domain.c | 8 +++++++-
src/ch/ch_monitor.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
Reviewed-by: Michal Privoznik <mprivozn(a)redhat.com>
and merged. Congratulations on your first libvirt contribution!
Michal
Awesome!
Looking forward for more.
Stefan