Rename qemuBuildRNGDeviceArgs to qemuBuildRNGDevStr and change the
return type so that it can be reused in the device hotplug code later.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/qemu/qemu_command.c | 32 ++++++++++++++++----------------
src/qemu/qemu_command.h | 4 ++++
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 52741fe..c0cd3eb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5820,21 +5820,19 @@ qemuBuildRNGBackendArgs(virCommandPtr cmd,
}
-static int
-qemuBuildRNGDeviceArgs(virCommandPtr cmd,
- virDomainDefPtr def,
- virDomainRNGDefPtr dev,
- virQEMUCapsPtr qemuCaps)
+char *
+qemuBuildRNGDevStr(virDomainDefPtr def,
+ virDomainRNGDefPtr dev,
+ virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- int ret = -1;
if (dev->model != VIR_DOMAIN_RNG_MODEL_VIRTIO ||
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_RNG)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("this qemu doesn't support RNG device type
'%s'"),
virDomainRNGModelTypeToString(dev->model));
- goto cleanup;
+ goto error;
}
if (dev->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW)
@@ -5855,16 +5853,14 @@ qemuBuildRNGDeviceArgs(virCommandPtr cmd,
}
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
- goto cleanup;
-
- virCommandAddArg(cmd, "-device");
- virCommandAddArgBuffer(cmd, &buf);
-
- ret = 0;
+ goto error;
+ if (virBufferCheckError(&buf) < 0)
+ goto error;
- cleanup:
+ return virBufferContentAndReset(&buf);
+ error:
virBufferFreeAndReset(&buf);
- return ret;
+ return NULL;
}
@@ -9845,13 +9841,17 @@ qemuBuildCommandLine(virConnectPtr conn,
}
for (i = 0; i < def->nrngs; i++) {
+ char *devstr;
/* add the RNG source backend */
if (qemuBuildRNGBackendArgs(cmd, def->rngs[i], qemuCaps) < 0)
goto error;
/* add the device */
- if (qemuBuildRNGDeviceArgs(cmd, def, def->rngs[i], qemuCaps) < 0)
+ virCommandAddArg(cmd, "-device");
+ if (!(devstr = qemuBuildRNGDevStr(def, def->rngs[i], qemuCaps)))
goto error;
+ virCommandAddArg(cmd, devstr);
+ VIR_FREE(devstr);
}
if (def->nvram) {
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index fc5f50a..3959677 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -165,6 +165,10 @@ char *qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
const char *configfd,
virQEMUCapsPtr qemuCaps);
+char *qemuBuildRNGDevStr(virDomainDefPtr def,
+ virDomainRNGDefPtr dev,
+ virQEMUCapsPtr qemuCaps);
+
int qemuOpenPCIConfig(virDomainHostdevDefPtr dev);
/* Legacy, pre device support */
--
1.8.3.1