mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-03 20:01:16 +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 *
|
virJSONValue *
|
||||||
qemuBuildRNGDevStr(const virDomainDef *def,
|
qemuBuildRNGDevProps(const virDomainDef *def,
|
||||||
virDomainRNGDef *dev,
|
virDomainRNGDef *dev,
|
||||||
virQEMUCaps *qemuCaps)
|
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;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
virBufferAsprintf(&buf, ",rng=obj%s,id=%s",
|
|
||||||
dev->info.alias, dev->info.alias);
|
|
||||||
|
|
||||||
if (dev->rate > 0) {
|
if (dev->rate > 0) {
|
||||||
virBufferAsprintf(&buf, ",max-bytes=%u", dev->rate);
|
period = dev->period;
|
||||||
if (dev->period)
|
|
||||||
virBufferAsprintf(&buf, ",period=%u", dev->period);
|
if (period == 0)
|
||||||
else
|
period = 1000;
|
||||||
virBufferAddLit(&buf, ",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 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;
|
g_autoptr(virJSONValue) props = NULL;
|
||||||
virDomainRNGDef *rng = def->rngs[i];
|
virDomainRNGDef *rng = def->rngs[i];
|
||||||
g_autofree char *chardev = NULL;
|
g_autofree char *chardev = NULL;
|
||||||
g_autofree char *devstr = NULL;
|
g_autoptr(virJSONValue) devprops = NULL;
|
||||||
|
|
||||||
if (!rng->info.alias) {
|
if (!rng->info.alias) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -5881,9 +5886,11 @@ qemuBuildRNGCommandLine(virLogManager *logManager,
|
|||||||
if (qemuCommandAddExtDevice(cmd, &rng->info) < 0)
|
if (qemuCommandAddExtDevice(cmd, &rng->info) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(devstr = qemuBuildRNGDevStr(def, rng, qemuCaps)))
|
if (!(devprops = qemuBuildRNGDevProps(def, rng, qemuCaps)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
virCommandAddArgList(cmd, "-device", devstr, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -169,9 +169,10 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
|
|||||||
virDomainHostdevDef *dev,
|
virDomainHostdevDef *dev,
|
||||||
virQEMUCaps *qemuCaps);
|
virQEMUCaps *qemuCaps);
|
||||||
|
|
||||||
char *qemuBuildRNGDevStr(const virDomainDef *def,
|
virJSONValue *
|
||||||
virDomainRNGDef *dev,
|
qemuBuildRNGDevProps(const virDomainDef *def,
|
||||||
virQEMUCaps *qemuCaps);
|
virDomainRNGDef *dev,
|
||||||
|
virQEMUCaps *qemuCaps);
|
||||||
int qemuBuildRNGBackendProps(virDomainRNGDef *rng,
|
int qemuBuildRNGBackendProps(virDomainRNGDef *rng,
|
||||||
virJSONValue **props);
|
virJSONValue **props);
|
||||||
|
|
||||||
|
@ -2309,7 +2309,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
|||||||
qemuDomainObjPrivate *priv = vm->privateData;
|
qemuDomainObjPrivate *priv = vm->privateData;
|
||||||
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
|
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_RNG, { .rng = rng } };
|
||||||
virErrorPtr orig_err;
|
virErrorPtr orig_err;
|
||||||
g_autofree char *devstr = NULL;
|
g_autoptr(virJSONValue) devprops = NULL;
|
||||||
g_autofree char *charAlias = NULL;
|
g_autofree char *charAlias = NULL;
|
||||||
g_autofree char *objAlias = NULL;
|
g_autofree char *objAlias = NULL;
|
||||||
g_autofree char *tlsAlias = NULL;
|
g_autofree char *tlsAlias = NULL;
|
||||||
@ -2338,7 +2338,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
|||||||
teardowncgroup = true;
|
teardowncgroup = true;
|
||||||
|
|
||||||
/* build required metadata */
|
/* build required metadata */
|
||||||
if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps)))
|
if (!(devprops = qemuBuildRNGDevProps(vm->def, rng, priv->qemuCaps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuBuildRNGBackendProps(rng, &props) < 0)
|
if (qemuBuildRNGBackendProps(rng, &props) < 0)
|
||||||
@ -2369,7 +2369,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver,
|
|||||||
if (qemuDomainAttachExtensionDevice(priv->mon, &rng->info) < 0)
|
if (qemuDomainAttachExtensionDevice(priv->mon, &rng->info) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
|
|
||||||
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
|
if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) {
|
||||||
ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info));
|
ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info));
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user