conf: RNG: Always fill in default random source path for default backend

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.
This commit is contained in:
Peter Krempa 2014-07-25 10:00:49 +02:00
parent e2e711aeaa
commit 1c6999d340
6 changed files with 20 additions and 26 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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