mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
qemuBuildRNGCommandLine: Generate via JSON
The 'virtio-rng' has the following property types according to QEMU: rng=<link<rng-backend>> max-bytes=<uint64> - (default: 9223372036854775807) period=<uint32> - (default: 65536) Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c234430b73
commit
172f64bb81
@ -5810,32 +5810,37 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng,
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
qemuBuildRNGDevStr(const virDomainDef *def,
|
||||
virDomainRNGDef *dev,
|
||||
virQEMUCaps *qemuCaps)
|
||||
virJSONValue *
|
||||
qemuBuildRNGDevProps(const virDomainDef *def,
|
||||
virDomainRNGDef *dev,
|
||||
virQEMUCaps *qemuCaps)
|
||||
{
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
g_autofree char *rng = g_strdup_printf("obj%s", dev->info.alias);
|
||||
unsigned int period = 0;
|
||||
|
||||
if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_RNG, dev) < 0) {
|
||||
if (!(props = qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_RNG, dev, qemuCaps)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virBufferAsprintf(&buf, ",rng=obj%s,id=%s",
|
||||
dev->info.alias, dev->info.alias);
|
||||
|
||||
if (dev->rate > 0) {
|
||||
virBufferAsprintf(&buf, ",max-bytes=%u", dev->rate);
|
||||
if (dev->period)
|
||||
virBufferAsprintf(&buf, ",period=%u", dev->period);
|
||||
else
|
||||
virBufferAddLit(&buf, ",period=1000");
|
||||
period = dev->period;
|
||||
|
||||
if (period == 0)
|
||||
period = 1000;
|
||||
}
|
||||
|
||||
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0)
|
||||
if (virJSONValueObjectAdd(props,
|
||||
"s:rng", rng,
|
||||
"s:id", dev->info.alias,
|
||||
"p:max-bytes", dev->rate,
|
||||
"p:period", period,
|
||||
NULL) < 0)
|
||||
return NULL;
|
||||
|
||||
return virBufferContentAndReset(&buf);
|
||||
if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&props);
|
||||
}
|
||||
|
||||
|
||||
@ -5854,7 +5859,7 @@ qemuBuildRNGCommandLine(virLogManager *logManager,
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
virDomainRNGDef *rng = def->rngs[i];
|
||||
g_autofree char *chardev = NULL;
|
||||
g_autofree char *devstr = NULL;
|
||||
g_autoptr(virJSONValue) devprops = NULL;
|
||||
|
||||
if (!rng->info.alias) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
@ -5881,9 +5886,11 @@ qemuBuildRNGCommandLine(virLogManager *logManager,
|
||||
if (qemuCommandAddExtDevice(cmd, &rng->info) < 0)
|
||||
return -1;
|
||||
|
||||
if (!(devstr = qemuBuildRNGDevStr(def, rng, qemuCaps)))
|
||||
if (!(devprops = qemuBuildRNGDevProps(def, rng, qemuCaps)))
|
||||
return -1;
|
||||
|
||||
if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
|
||||
return -1;
|
||||
virCommandAddArgList(cmd, "-device", devstr, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -169,9 +169,10 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
|
||||
virDomainHostdevDef *dev,
|
||||
virQEMUCaps *qemuCaps);
|
||||
|
||||
char *qemuBuildRNGDevStr(const virDomainDef *def,
|
||||
virDomainRNGDef *dev,
|
||||
virQEMUCaps *qemuCaps);
|
||||
virJSONValue *
|
||||
qemuBuildRNGDevProps(const virDomainDef *def,
|
||||
virDomainRNGDef *dev,
|
||||
virQEMUCaps *qemuCaps);
|
||||
int qemuBuildRNGBackendProps(virDomainRNGDef *rng,
|
||||
virJSONValue **props);
|
||||
|
||||
|
@ -2309,7 +2309,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
||||
qemuDomainObjPrivate *priv = vm->privateData;
|
||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
|
||||
virErrorPtr orig_err;
|
||||
g_autofree char *devstr = NULL;
|
||||
g_autoptr(virJSONValue) devprops = NULL;
|
||||
g_autofree char *charAlias = NULL;
|
||||
g_autofree char *objAlias = NULL;
|
||||
g_autofree char *tlsAlias = NULL;
|
||||
@ -2338,7 +2338,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
||||
teardowncgroup = true;
|
||||
|
||||
/* build required metadata */
|
||||
if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps)))
|
||||
if (!(devprops = qemuBuildRNGDevProps(vm->def, rng, priv->qemuCaps)))
|
||||
goto cleanup;
|
||||
|
||||
if (qemuBuildRNGBackendProps(rng, &props) < 0)
|
||||
@ -2369,7 +2369,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
||||
if (qemuDomainAttachExtensionDevice(priv->mon, &rng->info) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
|
||||
if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) {
|
||||
ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info));
|
||||
goto exit_monitor;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user