Libvirt documents that the default entropy source for the 'random'
backend of a RNG device is /dev/random. Instead of storing and
propagating NULL across our code and checking it in multiple places fill
the default in the post parse callback and use that in the other places.
---
Sending the fix as promised in the multiple-rng series.
src/conf/domain_audit.c | 10 ++--------
src/conf/domain_conf.c | 14 +++++++++-----
src/qemu/qemu_cgroup.c | 12 ++++--------
src/qemu/qemu_command.c | 5 ++---
.../qemuxml2argvdata/qemuxml2argv-virtio-rng-default.args | 2 +-
.../qemuxml2argvdata/qemuxml2argv-virtio-rng-multiple.args | 3 ++-
6 files changed, 20 insertions(+), 26 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 2d1b1fb..93625fc 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -253,10 +253,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
if (newDef) {
switch ((virDomainRNGBackend) newDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
- if (newDef->source.file)
- newsrcpath = newDef->source.file;
- else
- newsrcpath = "/dev/random";
+ newsrcpath = newDef->source.file;
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
@@ -271,10 +268,7 @@ virDomainAuditRNG(virDomainObjPtr vm,
if (oldDef) {
switch ((virDomainRNGBackend) oldDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
- if (oldDef->source.file)
- oldsrcpath = oldDef->source.file;
- else
- oldsrcpath = "/dev/random";
+ oldsrcpath = oldDef->source.file;
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9c3cd8a..910f6e2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3057,6 +3057,14 @@ virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
}
}
+ /* set default path for virtio-rng "random" backend to /dev/random */
+ if (dev->type == VIR_DOMAIN_DEVICE_RNG &&
+ dev->data.rng->backend == VIR_DOMAIN_RNG_BACKEND_RANDOM &&
+ !dev->data.rng->source.file) {
+ if (VIR_STRDUP(dev->data.rng->source.file, "/dev/random") <
0)
+ return -1;
+ }
+
return 0;
}
@@ -16546,11 +16554,7 @@ virDomainRNGDefFormat(virBufferPtr buf,
switch ((virDomainRNGBackend) def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
- if (def->source.file)
- virBufferEscapeString(buf, ">%s</backend>\n",
def->source.file);
- else
- virBufferAddLit(buf, "/>\n");
-
+ virBufferEscapeString(buf, ">%s</backend>\n",
def->source.file);
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 419be9a..43d14d4 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -587,16 +587,12 @@ qemuSetupDevicesCgroup(virQEMUDriverPtr driver,
for (i = 0; i < vm->def->nrngs; i++) {
if (vm->def->rngs[i]->backend == VIR_DOMAIN_RNG_BACKEND_RANDOM) {
VIR_DEBUG("Setting Cgroup ACL for RNG device");
- const char *rngpath = vm->def->rngs[i]->source.file;
-
- /* fix path when using the default */
- if (!rngpath)
- rngpath = "/dev/random";
-
- rv = virCgroupAllowDevicePath(priv->cgroup, rngpath,
+ rv = virCgroupAllowDevicePath(priv->cgroup,
+ vm->def->rngs[i]->source.file,
VIR_CGROUP_DEVICE_RW);
virDomainAuditCgroupPath(vm, priv->cgroup, "allow",
- rngpath, "rw", rv == 0);
+ vm->def->rngs[i]->source.file,
+ "rw", rv == 0);
if (rv < 0 &&
!virLastErrorIsSystemErrno(ENOENT))
goto cleanup;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7f9357c..cdf7740 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5626,9 +5626,8 @@ qemuBuildRNGBackendArgs(virCommandPtr cmd,
goto cleanup;
}
- virBufferAsprintf(&buf, "rng-random,id=%s", dev->info.alias);
- if (dev->source.file)
- virBufferAsprintf(&buf, ",filename=%s", dev->source.file);
+ virBufferAsprintf(&buf, "rng-random,id=%s,filename=%s",
+ dev->info.alias, dev->source.file);
virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-default.args
b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-default.args
index 4ae6257..58cc473 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-default.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-default.args
@@ -3,5 +3,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test
QEMU_AUDIO_DRV=none \
-S -M pc -m 214 -smp 1 -nographic -nodefaults \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
--object rng-random,id=rng0 \
+-object rng-random,id=rng0,filename=/dev/random \
-device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-multiple.args
b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-multiple.args
index 1082ede..d1faf09 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-multiple.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-rng-multiple.args
@@ -3,7 +3,8 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test
QEMU_AUDIO_DRV=none \
-M pc -m 214 -smp 1 -nographic -nodefaults \
-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
--object rng-random,id=rng0 -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7 \
+-object rng-random,id=rng0,filename=/dev/random \
+-device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7 \
-chardev socket,id=charrng1,host=1.2.3.4,port=1234 \
-object rng-egd,chardev=charrng1,id=rng1 \
-device virtio-rng-pci,rng=rng1,bus=pci.0,addr=0x4
--
2.0.0