xen: format xen config for USB keyboard

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Li Zhang 2014-02-17 18:17:57 +08:00 committed by Ján Tomko
parent 78730478aa
commit 2a81430c85
2 changed files with 41 additions and 16 deletions

View File

@ -724,21 +724,23 @@ xenParseSxprUSB(virDomainDefPtr def,
tmp = sexpr_node(node, "usbdevice");
if (tmp && *tmp) {
if (STREQ(tmp, "tablet") ||
STREQ(tmp, "mouse")) {
STREQ(tmp, "mouse") ||
STREQ(tmp, "keyboard")) {
virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0)
goto error;
input->bus = VIR_DOMAIN_INPUT_BUS_USB;
if (STREQ(tmp, "tablet"))
input->type = VIR_DOMAIN_INPUT_TYPE_TABLET;
else
else if (STREQ(tmp, "mouse"))
input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
else
input->type = VIR_DOMAIN_INPUT_TYPE_KBD;
if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) {
if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) {
VIR_FREE(input);
goto error;
}
def->inputs[def->ninputs++] = input;
} else {
/* XXX Handle other non-input USB devices later */
}
@ -2144,15 +2146,24 @@ xenFormatSxprInput(virDomainInputDefPtr input,
return 0;
if (input->type != VIR_DOMAIN_INPUT_TYPE_MOUSE &&
input->type != VIR_DOMAIN_INPUT_TYPE_TABLET) {
input->type != VIR_DOMAIN_INPUT_TYPE_TABLET &&
input->type != VIR_DOMAIN_INPUT_TYPE_KBD) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected input type %d"), input->type);
return -1;
}
virBufferAsprintf(buf, "(usbdevice %s)",
input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
"mouse" : "tablet");
switch (input->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
virBufferAsprintf(buf, "(usbdevice %s)", "mouse");
break;
case VIR_DOMAIN_INPUT_TYPE_TABLET:
virBufferAsprintf(buf, "(usbdevice %s)", "tablet");
break;
case VIR_DOMAIN_INPUT_TYPE_KBD:
virBufferAsprintf(buf, "(usbdevice %s)", "keyboard");
break;
}
return 0;
}

View File

@ -886,14 +886,18 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup;
if (str &&
(STREQ(str, "tablet") ||
STREQ(str, "mouse"))) {
STREQ(str, "mouse") ||
STREQ(str, "keyboard"))) {
virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0)
goto cleanup;
input->bus = VIR_DOMAIN_INPUT_BUS_USB;
input->type = STREQ(str, "tablet") ?
VIR_DOMAIN_INPUT_TYPE_TABLET :
VIR_DOMAIN_INPUT_TYPE_MOUSE;
if (STREQ(str, "mouse"))
input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE;
else if (STREQ(str, "tablet"))
input->type = VIR_DOMAIN_INPUT_TYPE_TABLET;
else if (STREQ(str, "keyboard"))
input->type = VIR_DOMAIN_INPUT_TYPE_KBD;
if (VIR_ALLOC_N(def->inputs, 1) < 0) {
virDomainInputDefFree(input);
goto cleanup;
@ -1746,11 +1750,21 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
if (xenXMConfigSetInt(conf, "usb", 1) < 0)
goto cleanup;
if (xenXMConfigSetString(conf, "usbdevice",
def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
"mouse" : "tablet") < 0)
switch (def->inputs[i]->type) {
case VIR_DOMAIN_INPUT_TYPE_MOUSE:
if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0)
goto cleanup;
break;
case VIR_DOMAIN_INPUT_TYPE_TABLET:
if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0)
goto cleanup;
break;
case VIR_DOMAIN_INPUT_TYPE_KBD:
if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0)
goto cleanup;
break;
}
break;
}
}
}