From: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx> There is no keyboard for PPC64 platform when grapchic is enabled. It's preferred to add one USB keyboard. This patch is to add keyboard input device type. Signed-off-by: Li Zhang <zhlcindy@xxxxxxxxxxxxxxxxxx> --- src/conf/domain_conf.c | 62 +++++++++++++++++++++++++++++++++++------------- src/conf/domain_conf.h | 5 ++++ src/libvirt_private.syms | 1 + 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 65bd9b1..b714b6b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -504,7 +504,8 @@ VIR_ENUM_IMPL(virDomainVideo, VIR_DOMAIN_VIDEO_TYPE_LAST, VIR_ENUM_IMPL(virDomainInput, VIR_DOMAIN_INPUT_TYPE_LAST, "mouse", - "tablet") + "tablet", + "kbd") VIR_ENUM_IMPL(virDomainInputBus, VIR_DOMAIN_INPUT_BUS_LAST, "ps2", @@ -10821,6 +10822,41 @@ virDomainDefMaybeAddController(virDomainDefPtr def, return 0; } +int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus) +{ + size_t i; + virDomainInputDefPtr input; + + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->type == type && + def->inputs[i]->bus == bus) + return 0; + } + + if (VIR_ALLOC(input) < 0) { + goto error; + } + input->type = type; + input->bus = bus; + + if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { + virDomainInputDefFree(input); + goto error; + } + + def->inputs[def->ninputs] = input; + def->ninputs ++; + return 0; + +error: + virReportOOMError(); + return -1; +} + + /* Parse a memory element located at XPATH within CTXT, and store the * result into MEM. If REQUIRED, then the value must exist; @@ -12232,25 +12268,17 @@ virDomainDefParseXML(xmlDocPtr xml, /* If graphics are enabled, there's an implicit PS2 mouse */ if (def->ngraphics > 0) { - virDomainInputDefPtr input; - - if (VIR_ALLOC(input) < 0) { - goto error; - } if (STREQ(def->os.type, "hvm")) { - input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; - input->bus = VIR_DOMAIN_INPUT_BUS_PS2; + if (virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_MOUSE, + VIR_DOMAIN_INPUT_BUS_PS2) < 0) + goto error; } else { - input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; - input->bus = VIR_DOMAIN_INPUT_BUS_XEN; - } - - if (VIR_REALLOC_N(def->inputs, def->ninputs + 1) < 0) { - virDomainInputDefFree(input); - goto error; + if (virDomainDefMaybeAddInput(def, + VIR_DOMAIN_INPUT_TYPE_MOUSE, + VIR_DOMAIN_INPUT_BUS_XEN) < 0) + goto error; } - def->inputs[def->ninputs] = input; - def->ninputs++; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4934911..8616066 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1223,6 +1223,7 @@ struct _virDomainTPMDef { enum virDomainInputType { VIR_DOMAIN_INPUT_TYPE_MOUSE, VIR_DOMAIN_INPUT_TYPE_TABLET, + VIR_DOMAIN_INPUT_TYPE_KBD, VIR_DOMAIN_INPUT_TYPE_LAST }; @@ -2763,6 +2764,10 @@ virDomainDefMaybeAddController(virDomainDefPtr def, int type, int idx, int model); +int +virDomainDefMaybeAddInput(virDomainDefPtr def, + int type, + int bus); char *virDomainDefGetDefaultEmulator(virDomainDefPtr def, virCapsPtr caps); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b2c7a8e..e37931c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -165,6 +165,7 @@ virDomainDefGenSecurityLabelDef; virDomainDefGetDefaultEmulator; virDomainDefGetSecurityLabelDef; virDomainDefMaybeAddController; +virDomainDefMaybeAddInput; virDomainDefNew; virDomainDefParseFile; virDomainDefParseNode; -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list