From 1a538a07c71f6ef0ce57542301d78e55e5b0b581 Mon Sep 17 00:00:00 2001
From: =?utf8?q?J=C3=A1n=20Tomko?=
Date: Mon, 16 Nov 2015 09:36:12 +0100
Subject: [PATCH] conf: add XML for input device passthrough
Add xml for the new virtio-input-host-pci device:
https://bugzilla.redhat.com/show_bug.cgi?id=1231114
---
docs/formatdomain.html.in | 12 ++++-
docs/schemas/domaincommon.rng | 49 +++++++++++++------
src/conf/domain_conf.c | 28 +++++++++--
src/conf/domain_conf.h | 4 ++
src/qemu/qemu_command.c | 2 +
.../qemuxml2argv-virtio-input-passthrough.xml | 24 +++++++++
tests/qemuxml2xmltest.c | 1 +
7 files changed, 98 insertions(+), 22 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-virtio-input-passthrough.xml
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index df54ad3d0..a8bd48e97 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4804,14 +4804,18 @@ qemu-kvm -net nic,model=? /dev/null
<input type='mouse' bus='virtio'/>
<input type='keyboard' bus='virtio'/>
<input type='tablet' bus='virtio'/>
+ <input type='passthrough' bus='virtio'>
+ <source evdev='/dev/input/event1/>
+ </input>
</devices>
...
input
The input
element has one mandatory attribute,
- the type
whose value can be 'mouse', 'tablet' or
- (since 1.2.2 ) 'keyboard'.
+ the type
whose value can be 'mouse', 'tablet',
+ (since 1.2.2 ) 'keyboard' or
+ (since 1.3.0 ) 'passthrough'.
The tablet provides absolute cursor movement,
while the mouse uses relative movement. The optional
bus
attribute can be used to refine the exact device type.
@@ -4824,6 +4828,10 @@ qemu-kvm -net nic,model=? /dev/null
sub-element <address>
which can tie the
device to a particular PCI
slot, documented above .
+
+ For type passthrough
, the mandatory sub-element source
+ must have an evdev
attribute containing the absolute path to the
+ event device passed through to guests. (KVM only)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 6d71199b1..8d126065e 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3579,23 +3579,40 @@
-
-
- tablet
- mouse
- keyboard
-
-
-
-
-
- ps2
- usb
- xen
+
+
+
+
+ tablet
+ mouse
+ keyboard
+
+
+
+
+
+ ps2
+ usb
+ xen
+ virtio
+
+
+
+
+
+
+ passthrough
+
+
virtio
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 12b3769ce..99ca81f3a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -544,7 +544,8 @@ VIR_ENUM_IMPL(virDomainVideo, VIR_DOMAIN_VIDEO_TYPE_LAST,
VIR_ENUM_IMPL(virDomainInput, VIR_DOMAIN_INPUT_TYPE_LAST,
"mouse",
"tablet",
- "keyboard")
+ "keyboard",
+ "passthrough")
VIR_ENUM_IMPL(virDomainInputBus, VIR_DOMAIN_INPUT_BUS_LAST,
"ps2",
@@ -1416,6 +1417,7 @@ void virDomainInputDefFree(virDomainInputDefPtr def)
return;
virDomainDeviceInfoClear(&def->info);
+ VIR_FREE(def->source.evdev);
VIR_FREE(def);
}
@@ -10262,15 +10264,20 @@ virDomainPanicDefParseXML(xmlNodePtr node)
static virDomainInputDefPtr
virDomainInputDefParseXML(const virDomainDef *dom,
xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
unsigned int flags)
{
+ xmlNodePtr save = ctxt->node;
virDomainInputDefPtr def;
+ char *evdev = NULL;
char *type = NULL;
char *bus = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
+ ctxt->node = node;
+
type = virXMLPropString(node, "type");
bus = virXMLPropString(node, "bus");
@@ -10377,10 +10384,20 @@ virDomainInputDefParseXML(const virDomainDef *dom,
goto error;
}
+ if ((evdev = virXPathString("string(./source/@evdev)", ctxt)))
+ def->source.evdev = virFileSanitizePath(evdev);
+ if (def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH && !def->source.evdev) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Missing evdev path for input device passthrough"));
+ goto error;
+ }
+
cleanup:
+ VIR_FREE(evdev);
VIR_FREE(type);
VIR_FREE(bus);
+ ctxt->node = save;
return def;
error:
@@ -12737,8 +12754,8 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error;
break;
case VIR_DOMAIN_DEVICE_INPUT:
- if (!(dev->data.input = virDomainInputDefParseXML(def,
- node, flags)))
+ if (!(dev->data.input = virDomainInputDefParseXML(def, node,
+ ctxt, flags)))
goto error;
break;
case VIR_DOMAIN_DEVICE_SOUND:
@@ -16115,6 +16132,7 @@ virDomainDefParseXML(xmlDocPtr xml,
for (i = 0; i < n; i++) {
virDomainInputDefPtr input = virDomainInputDefParseXML(def,
nodes[i],
+ ctxt,
flags);
if (!input)
goto error;
@@ -20961,9 +20979,11 @@ virDomainInputDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, " info, flags)) {
+ if (virDomainDeviceInfoNeedsFormat(&def->info, flags) ||
+ def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
+ virBufferEscapeString(buf, " \n", def->source.evdev);
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6d2ca55b8..315036768 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1288,6 +1288,7 @@ typedef enum {
VIR_DOMAIN_INPUT_TYPE_MOUSE,
VIR_DOMAIN_INPUT_TYPE_TABLET,
VIR_DOMAIN_INPUT_TYPE_KBD,
+ VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH,
VIR_DOMAIN_INPUT_TYPE_LAST
} virDomainInputType;
@@ -1305,6 +1306,9 @@ typedef enum {
struct _virDomainInputDef {
int type;
int bus;
+ struct {
+ char *evdev;
+ } source;
virDomainDeviceInfo info;
};
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 93be5a5d9..394cec700 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5777,6 +5777,8 @@ qemuBuildVirtioInputDevStr(virDomainDefPtr def,
}
virBufferAsprintf(&buf, "virtio-keyboard%s,id=%s", suffix, dev->info.alias);
break;
+ case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
+ /* TBD */
case VIR_DOMAIN_INPUT_TYPE_LAST:
break;
}
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-input-passthrough.xml b/tests/qemuxml2argvdata/qemuxml2argv-virtio-input-passthrough.xml
new file mode 100644
index 000000000..e2bf06310
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-input-passthrough.xml
@@ -0,0 +1,24 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 219100
+ 219100
+ 1
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 4b2cff7aa..f967ceb94 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -633,6 +633,7 @@ mymain(void)
DO_TEST("video-virtio-gpu-device");
DO_TEST("video-virtio-gpu-virgl");
DO_TEST("virtio-input");
+ DO_TEST("virtio-input-passthrough");
qemuTestDriverFree(&driver);
--
2.39.5