mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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=<PCI SLOT> NB, pcspk still uses the old -soundhw syntax
This commit is contained in:
parent
38a22fbfaa
commit
4886cba76a
@ -2052,7 +2052,44 @@ error:
|
|||||||
return NULL;
|
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 */
|
* host side of the character device */
|
||||||
static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
|
static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
|
||||||
virBufferPtr buf)
|
virBufferPtr buf)
|
||||||
@ -3122,27 +3159,49 @@ int qemudBuildCommandLine(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Add sound hardware */
|
/* Add sound hardware */
|
||||||
if (def->nsounds) {
|
if (def->nsounds) {
|
||||||
int size = 100;
|
if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
|
||||||
char *modstr;
|
for (i = 0 ; i < def->nsounds ; i++) {
|
||||||
if (VIR_ALLOC_N(modstr, size+1) < 0)
|
virDomainSoundDefPtr sound = def->sounds[i];
|
||||||
goto no_memory;
|
char *str = NULL;
|
||||||
|
|
||||||
for (i = 0 ; i < def->nsounds && size > 0 ; i++) {
|
/* Sadly pcspk device doesn't use -device syntax. Fortunately
|
||||||
virDomainSoundDefPtr sound = def->sounds[i];
|
* we don't need to set any PCI address on it, so we don't
|
||||||
const char *model = virDomainSoundModelTypeToString(sound->model);
|
* mind too much */
|
||||||
if (!model) {
|
if (sound->model == VIR_DOMAIN_SOUND_MODEL_PCSPK) {
|
||||||
VIR_FREE(modstr);
|
ADD_ARG_LIT("-soundhw");
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
ADD_ARG_LIT("pcspk");
|
||||||
"%s", _("invalid sound model"));
|
} else {
|
||||||
goto error;
|
ADD_ARG_LIT("-device");
|
||||||
|
|
||||||
|
if (!(str = qemuBuildSoundDevStr(sound)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
ADD_ARG(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
strncat(modstr, model, size);
|
} else {
|
||||||
size -= strlen(model);
|
int size = 100;
|
||||||
if (i < (def->nsounds - 1))
|
char *modstr;
|
||||||
strncat(modstr, ",", size--);
|
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 */
|
/* Add watchdog hardware */
|
||||||
|
1
tests/qemuxml2argvdata/qemuxml2argv-sound-device.args
Normal file
1
tests/qemuxml2argvdata/qemuxml2argv-sound-device.args
Normal file
@ -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
|
26
tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml
Normal file
26
tests/qemuxml2argvdata/qemuxml2argv-sound-device.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory>219200</memory>
|
||||||
|
<currentMemory>219200</currentMemory>
|
||||||
|
<vcpu>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu</emulator>
|
||||||
|
<disk type='block' device='disk'>
|
||||||
|
<source dev='/dev/HostVG/QEMUGuest1'/>
|
||||||
|
<target dev='hda' bus='ide'/>
|
||||||
|
</disk>
|
||||||
|
<sound model='pcspk'/>
|
||||||
|
<sound model='es1370'/>
|
||||||
|
<sound model='sb16'/>
|
||||||
|
<sound model='ac97'/>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -293,6 +293,7 @@ mymain(int argc, char **argv)
|
|||||||
DO_TEST("watchdog", 0);
|
DO_TEST("watchdog", 0);
|
||||||
DO_TEST("watchdog-device", QEMUD_CMD_FLAG_DEVICE);
|
DO_TEST("watchdog-device", QEMUD_CMD_FLAG_DEVICE);
|
||||||
DO_TEST("sound", 0);
|
DO_TEST("sound", 0);
|
||||||
|
DO_TEST("sound-device", QEMUD_CMD_FLAG_DEVICE);
|
||||||
|
|
||||||
DO_TEST("hostdev-usb-product", 0);
|
DO_TEST("hostdev-usb-product", 0);
|
||||||
DO_TEST("hostdev-usb-address", 0);
|
DO_TEST("hostdev-usb-address", 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user