mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00: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;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
|
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-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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user