提交 4886cba7 编写于 作者: D Daniel P. Berrange

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
上级 38a22fbf
...@@ -2052,7 +2052,44 @@ error: ...@@ -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, ...@@ -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;
/* 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");
for (i = 0 ; i < def->nsounds && size > 0 ; i++) { if (!(str = qemuBuildSoundDevStr(sound)))
virDomainSoundDefPtr sound = def->sounds[i]; goto error;
const char *model = virDomainSoundModelTypeToString(sound->model);
if (!model) { ADD_ARG(str);
VIR_FREE(modstr); }
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, }
"%s", _("invalid sound model")); } else {
goto error; 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); ADD_ARG_LIT("-soundhw");
size -= strlen(model); ADD_ARG(modstr);
if (i < (def->nsounds - 1))
strncat(modstr, ",", size--);
} }
ADD_ARG_LIT("-soundhw");
ADD_ARG(modstr);
} }
/* Add watchdog hardware */ /* Add watchdog hardware */
......
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
<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) ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册