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

[libvirt] [PATCH 04/10] Add support for -device with audio devices



The current syntax for audio devices is a horrible multiplexed
arg

    -soundhw sb16,pcspk,ac97

The new syntax is

    -device sb16
    -device ac97
---
 src/qemu/qemu_conf.c |   72 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 54 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 79b7b00..8c44a93 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1538,6 +1538,28 @@ qemuBuildHostNetStr(virConnectPtr conn,
     return 0;
 }
 
+static int
+qemuBuildSoundDevStr(virConnectPtr conn,
+                     virDomainSoundDefPtr sound,
+                     char **str)
+{
+    const char *model = virDomainSoundModelTypeToString(sound->model);
+
+    if (STREQ(model, "es1370"))
+        model = "ES1370";
+    else if (STREQ(model, "ac97"))
+        model = "AC97";
+
+    *str = strdup(model);
+    if (!(*str)) {
+        virReportOOMError(conn);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /* This function outputs a -chardev command line option which describes only the
  * host side of the character device */
 static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
@@ -2542,27 +2564,41 @@ int qemudBuildCommandLine(virConnectPtr conn,
 
     /* Add sound hardware */
     if (def->nsounds) {
-        int size = 100;
-        char *modstr;
-        if (VIR_ALLOC_N(modstr, size+1) < 0)
-            goto no_memory;
+        if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
+            for (i = 0 ; i < def->nsounds ; i++) {
+                virDomainSoundDefPtr sound = def->sounds[i];
+                char *str = NULL;
 
-        for (i = 0 ; i < def->nsounds && size > 0 ; i++) {
-            virDomainSoundDefPtr sound = def->sounds[i];
-            const char *model = virDomainSoundModelTypeToString(sound->model);
-            if (!model) {
-                VIR_FREE(modstr);
-                qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                                 "%s", _("invalid sound model"));
-                goto error;
+                ADD_ARG_LIT("-device");
+
+                if (qemuBuildSoundDevStr(conn, sound, &str) < 0)
+                    goto error;
+
+                ADD_ARG(str);
+            }
+        } else {
+            int size = 100;
+            char *modstr;
+            if (VIR_ALLOC_N(modstr, size+1) < 0)
+                goto no_memory;
+
+            for (i = 0 ; i < def->nsounds && size > 0 ; i++) {
+                virDomainSoundDefPtr sound = def->sounds[i];
+                const char *model = virDomainSoundModelTypeToString(sound->model);
+                if (!model) {
+                    VIR_FREE(modstr);
+                    qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                     "%s", _("invalid sound model"));
+                    goto error;
+                }
+                strncat(modstr, model, size);
+                size -= strlen(model);
+                if (i < (def->nsounds - 1))
+                    strncat(modstr, ",", size--);
             }
-            strncat(modstr, model, size);
-            size -= strlen(model);
-            if (i < (def->nsounds - 1))
-               strncat(modstr, ",", size--);
+            ADD_ARG_LIT("-soundhw");
+            ADD_ARG(modstr);
         }
-        ADD_ARG_LIT("-soundhw");
-        ADD_ARG(modstr);
     }
 
     /* Add watchdog hardware */
-- 
1.6.5.2


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