]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Introduce qemuBuildMonitorCommandLine
authorJohn Ferlan <jferlan@redhat.com>
Wed, 17 Feb 2016 22:27:21 +0000 (17:27 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 18 Feb 2016 12:03:30 +0000 (07:03 -0500)
Add new function to manage adding the '-mon' or '-monitor' options to
the command line removing that task from the mainline qemuBuildCommandLine.

Also adjusted qemuBuildChrChardevStr and qemuBuildChrArgStr to use
const virDomainChrSourceDef *def rather than virDomainChrSourceDefPtr def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_command.c

index 289023c03150b87eba969fcc47afa4ed8fee3d55..b751f043a4b8b2a0ce1194bffc64a67478f25841 100644 (file)
@@ -3847,7 +3847,8 @@ qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
 /* This function outputs a -chardev command line option which describes only the
  * host side of the character device */
 static char *
-qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias,
+qemuBuildChrChardevStr(const virDomainChrSourceDef *dev,
+                       const char *alias,
                        virQEMUCapsPtr qemuCaps)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -3975,7 +3976,8 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias,
 
 
 static char *
-qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix)
+qemuBuildChrArgStr(const virDomainChrSourceDef *dev,
+                   const char *prefix)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
@@ -4068,6 +4070,47 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix)
 }
 
 
+static int
+qemuBuildMonitorCommandLine(virCommandPtr cmd,
+                            virQEMUCapsPtr qemuCaps,
+                            const virDomainChrSourceDef *monitor_chr,
+                            bool monitor_json)
+{
+    char *chrdev;
+
+    if (!monitor_chr)
+        return 0;
+
+    /* Use -chardev if it's available */
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV)) {
+
+        virCommandAddArg(cmd, "-chardev");
+        if (!(chrdev = qemuBuildChrChardevStr(monitor_chr, "monitor",
+                                              qemuCaps)))
+            return -1;
+        virCommandAddArg(cmd, chrdev);
+        VIR_FREE(chrdev);
+
+        virCommandAddArg(cmd, "-mon");
+        virCommandAddArgFormat(cmd,
+                               "chardev=charmonitor,id=monitor,mode=%s",
+                               monitor_json ? "control" : "readline");
+    } else {
+        const char *prefix = NULL;
+        if (monitor_json)
+            prefix = "control,";
+
+        virCommandAddArg(cmd, "-monitor");
+        if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix)))
+            return -1;
+        virCommandAddArg(cmd, chrdev);
+        VIR_FREE(chrdev);
+    }
+
+    return 0;
+}
+
+
 static char *
 qemuBuildVirtioSerialPortDevStr(virDomainDefPtr def,
                                 virDomainChrDefPtr dev,
@@ -7106,34 +7149,9 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (qemuBuildSgaCommandLine(cmd, def, qemuCaps) < 0)
         goto error;
 
-    if (monitor_chr) {
-        char *chrdev;
-        /* Use -chardev if it's available */
-        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV)) {
-
-            virCommandAddArg(cmd, "-chardev");
-            if (!(chrdev = qemuBuildChrChardevStr(monitor_chr, "monitor",
-                                                  qemuCaps)))
-                goto error;
-            virCommandAddArg(cmd, chrdev);
-            VIR_FREE(chrdev);
-
-            virCommandAddArg(cmd, "-mon");
-            virCommandAddArgFormat(cmd,
-                                   "chardev=charmonitor,id=monitor,mode=%s",
-                                   monitor_json ? "control" : "readline");
-        } else {
-            const char *prefix = NULL;
-            if (monitor_json)
-                prefix = "control,";
-
-            virCommandAddArg(cmd, "-monitor");
-            if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix)))
-                goto error;
-            virCommandAddArg(cmd, chrdev);
-            VIR_FREE(chrdev);
-        }
-    }
+    if (qemuBuildMonitorCommandLine(cmd, qemuCaps, monitor_chr,
+                                    monitor_json) < 0)
+        goto error;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_RTC)) {
         char *rtcopt;