From 4886cba76a12d15e0c43813a8e8b796f213b02b5 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 14 Dec 2009 18:16:10 +0000 Subject: [PATCH] Convert audio devices over to -device syntax The current syntax for audio devices is a horrible multiplexed arg -soundhw sb16,pcspk,ac97 The new syntax is -device sb16,id=sound0 or -device AC97,id=sound1,addr= NB, pcspk still uses the old -soundhw syntax --- src/qemu/qemu_conf.c | 97 +++++++++++++++---- .../qemuxml2argv-sound-device.args | 1 + .../qemuxml2argv-sound-device.xml | 26 +++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-sound-device.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index d726df6b84..9af7dacfdf 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -2052,7 +2052,44 @@ error: return NULL; } -/* this function outputs a -chardev command line option which describes only the + +static char * +qemuBuildSoundDevStr(virDomainSoundDefPtr sound) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + const char *model = virDomainSoundModelTypeToString(sound->model); + + if (!model) { + qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + "%s", _("invalid sound model")); + goto error; + } + + /* Hack for 2 wierdly unusal devices name in QEMU */ + if (STREQ(model, "es1370")) + model = "ES1370"; + else if (STREQ(model, "ac97")) + model = "AC97"; + + virBufferVSprintf(&buf, "%s", model); + virBufferVSprintf(&buf, ",id=%s", sound->info.alias); + if (qemuBuildDeviceAddressStr(&buf, &sound->info) < 0) + goto error; + + if (virBufferError(&buf)) { + virReportOOMError(NULL); + goto error; + } + + return virBufferContentAndReset(&buf); + +error: + virBufferFreeAndReset(&buf); + return NULL; +} + + +/* This function outputs a -chardev command line option which describes only the * host side of the character device */ static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev, virBufferPtr buf) @@ -3122,27 +3159,49 @@ 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; + /* Sadly pcspk device doesn't use -device syntax. Fortunately + * we don't need to set any PCI address on it, so we don't + * mind too much */ + if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) { + ADD_ARG_LIT("-soundhw"); + ADD_ARG_LIT("pcspk"); + } else { + ADD_ARG_LIT("-device"); + + if (!(str = qemuBuildSoundDevStr(sound))) + goto error; + + ADD_ARG(str); + } } - strncat(modstr, model, size); - size -= strlen(model); - if (i < (def->nsounds - 1)) - strncat(modstr, ",", size--); + } 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--); + } + ADD_ARG_LIT("-soundhw"); + ADD_ARG(modstr); } - ADD_ARG_LIT("-soundhw"); - ADD_ARG(modstr); } /* Add watchdog hardware */ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args new file mode 100644 index 0000000000..31ac0ee0e4 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -soundhw pcspk -device ES1370,id=sound1 -device sb16,id=sound2 -device AC97,id=sound3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml new file mode 100644 index 0000000000..8c33e6c90a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 6bfc2173d1..55e7d58bc0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -293,6 +293,7 @@ mymain(int argc, char **argv) DO_TEST("watchdog", 0); DO_TEST("watchdog-device", QEMUD_CMD_FLAG_DEVICE); DO_TEST("sound", 0); + DO_TEST("sound-device", QEMUD_CMD_FLAG_DEVICE); DO_TEST("hostdev-usb-product", 0); DO_TEST("hostdev-usb-address", 0);