[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [REPOST PATCH 6/8] qemu: Introduce qemuBuildRNGCommandLine



Add new function to manage adding the RNG device options to the
command line removing that task from the mainline qemuBuildCommandLine.

Also modify the qemuBuildRNGDevStr to use const virDomainDef instead
of virDomainDefPtr.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/qemu/qemu_command.c | 85 +++++++++++++++++++++++++++++--------------------
 src/qemu/qemu_command.h |  2 +-
 2 files changed, 51 insertions(+), 36 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0f9fe60..d6f7651 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5195,7 +5195,7 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev)
 static int
 qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
                              virCommandPtr cmd,
-                             virDomainDefPtr def,
+                             const virDomainDef *def,
                              virDomainRNGDefPtr rng,
                              virQEMUCapsPtr qemuCaps,
                              char **chr)
@@ -5302,7 +5302,7 @@ qemuBuildRNGBackendStr(virDomainRNGDefPtr rng,
 
 
 char *
-qemuBuildRNGDevStr(virDomainDefPtr def,
+qemuBuildRNGDevStr(const virDomainDef *def,
                    virDomainRNGDefPtr dev,
                    virQEMUCapsPtr qemuCaps)
 {
@@ -5354,6 +5354,52 @@ qemuBuildRNGDevStr(virDomainDefPtr def,
 }
 
 
+static int
+qemuBuildRNGCommandLine(virLogManagerPtr logManager,
+                        virCommandPtr cmd,
+                        const virDomainDef *def,
+                        virQEMUCapsPtr qemuCaps)
+{
+    size_t i;
+
+    for (i = 0; i < def->nrngs; i++) {
+        virDomainRNGDefPtr rng = def->rngs[i];
+        char *tmp;
+
+        if (!rng->info.alias) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("RNG device is missing alias"));
+            return -1;
+        }
+
+        /* possibly add character device for backend */
+        if (qemuBuildRNGBackendChrdevStr(logManager, cmd, def,
+                                         rng, qemuCaps, &tmp) < 0)
+            return -1;
+
+        if (tmp) {
+            virCommandAddArgList(cmd, "-chardev", tmp, NULL);
+            VIR_FREE(tmp);
+        }
+
+        /* add the RNG source backend */
+        if (!(tmp = qemuBuildRNGBackendStr(rng, qemuCaps)))
+            return -1;
+
+        virCommandAddArgList(cmd, "-object", tmp, NULL);
+        VIR_FREE(tmp);
+
+        /* add the device */
+        if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps)))
+            return -1;
+        virCommandAddArgList(cmd, "-device", tmp, NULL);
+        VIR_FREE(tmp);
+    }
+
+    return 0;
+}
+
+
 static char *qemuBuildSmbiosBiosStr(virSysinfoBIOSDefPtr def)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -9183,39 +9229,8 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (qemuBuildMemballoonCommandLine(cmd, def, qemuCaps) < 0)
         goto error;
 
-    for (i = 0; i < def->nrngs; i++) {
-        virDomainRNGDefPtr rng = def->rngs[i];
-        char *tmp;
-
-        if (!rng->info.alias) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("RNG device is missing alias"));
-            goto error;
-        }
-
-        /* possibly add character device for backend */
-        if (qemuBuildRNGBackendChrdevStr(logManager, cmd, def,
-                                         rng, qemuCaps, &tmp) < 0)
-            goto error;
-
-        if (tmp) {
-            virCommandAddArgList(cmd, "-chardev", tmp, NULL);
-            VIR_FREE(tmp);
-        }
-
-        /* add the RNG source backend */
-        if (!(tmp = qemuBuildRNGBackendStr(rng, qemuCaps)))
-            goto error;
-
-        virCommandAddArgList(cmd, "-object", tmp, NULL);
-        VIR_FREE(tmp);
-
-        /* add the device */
-        if (!(tmp = qemuBuildRNGDevStr(def, rng, qemuCaps)))
-            goto error;
-        virCommandAddArgList(cmd, "-device", tmp, NULL);
-        VIR_FREE(tmp);
-    }
+    if (qemuBuildRNGCommandLine(logManager, cmd, def, qemuCaps) < 0)
+        goto error;
 
     if (def->nvram) {
         if (ARCH_IS_PPC64(def->os.arch) &&
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 25de1abd..7c13d45 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -155,7 +155,7 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                                 const char *configfd,
                                 virQEMUCapsPtr qemuCaps);
 
-char *qemuBuildRNGDevStr(virDomainDefPtr def,
+char *qemuBuildRNGDevStr(const virDomainDef *def,
                          virDomainRNGDefPtr dev,
                          virQEMUCapsPtr qemuCaps);
 int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
-- 
2.5.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]