Support qemu commandline passthrough in the domXML to native config
converter. Add tests to check the conversion.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
I had to add a small hack to xlconfigtest.c to set def->ns after
parsing the xl.cfg file to virDomainDef object. The hack could also
be added to xenParseXL in src/libxl/xen_xl.c, where the virDomainDef
object is created. Opinions much welcomed :-).
src/libxl/xen_xl.c | 88 ++++++++++++++++++++
tests/xlconfigdata/test-qemu-passthrough.cfg | 26 ++++++
tests/xlconfigdata/test-qemu-passthrough.xml | 53 ++++++++++++
tests/xlconfigtest.c | 4 +
4 files changed, 171 insertions(+)
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index f9dc18ab18..a5d70d4039 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -32,6 +32,7 @@
#include "virstoragefile.h"
#include "xen_xl.h"
#include "libxl_capabilities.h"
+#include "libxl_conf.h"
#include "cpu/cpu.h"
#define VIR_FROM_THIS VIR_FROM_XENXL
@@ -1158,6 +1159,40 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
return -1;
}
+static int
+xenParseXLNamespaceData(virConfPtr conf, virDomainDefPtr def)
+{
+ virConfValuePtr list = virConfGetValue(conf, "device_model_args");
+ VIR_AUTOSTRINGLIST args = NULL;
+ size_t nargs;
+ libxlDomainXmlNsDefPtr nsdata = NULL;
+
+ if (list && list->type == VIR_CONF_LIST) {
+ list = list->list;
+ while (list) {
+ if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) {
+ list = list->next;
+ continue;
+ }
+
+ virStringListAdd(&args, list->str);
+ list = list->next;
+ }
+ }
+
+ nargs = virStringListLength((const char **)args);
+ if (nargs > 0) {
+ if (VIR_ALLOC(nsdata) < 0)
+ return -1;
+
+ nsdata->args = g_steal_pointer(&args);
+ nsdata->num_args = nargs;
+ def->namespaceData = nsdata;
+ }
+
+ return 0;
+}
+
virDomainDefPtr
xenParseXL(virConfPtr conf,
virCapsPtr caps,
@@ -1207,6 +1242,9 @@ xenParseXL(virConfPtr conf,
if (xenParseXLChannel(conf, def) < 0)
goto cleanup;
+ if (xenParseXLNamespaceData(conf, def) < 0)
+ goto cleanup;
+
if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
xmlopt, NULL) < 0)
goto cleanup;
@@ -2165,6 +2203,53 @@ xenFormatXLDomainChannels(virConfPtr conf, virDomainDefPtr def)
return -1;
}
+static int
+xenFormatXLDomainNamespaceData(virConfPtr conf, virDomainDefPtr def)
+{
+ libxlDomainXmlNsDefPtr nsdata = def->namespaceData;
+ virConfValuePtr args = NULL;
+ size_t i;
+
+ if (!nsdata)
+ return 0;
+
+ if (nsdata->num_args == 0)
+ return 0;
+
+ if (VIR_ALLOC(args) < 0)
+ return -1;
+
+ args->type = VIR_CONF_LIST;
+ args->list = NULL;
+
+ for (i = 0; i < nsdata->num_args; i++) {
+ virConfValuePtr val, tmp;
+
+ if (VIR_ALLOC(val) < 0)
+ goto error;
+
+ val->type = VIR_CONF_STRING;
+ val->str = g_strdup(nsdata->args[i]);
+ tmp = args->list;
+ while (tmp && tmp->next)
+ tmp = tmp->next;
+ if (tmp)
+ tmp->next = val;
+ else
+ args->list = val;
+ }
+
+ if (args->list != NULL)
+ if (virConfSetValue(conf, "device_model_args", args) < 0)
+ goto error;
+
+ return 0;
+
+ error:
+ virConfFreeValue(args);
+ return -1;
+}
+
virConfPtr
xenFormatXL(virDomainDefPtr def, virConnectPtr conn)
{
@@ -2208,5 +2293,8 @@ xenFormatXL(virDomainDefPtr def, virConnectPtr conn)
if (xenFormatXLDomainChannels(conf, def) < 0)
return NULL;
+ if (xenFormatXLDomainNamespaceData(conf, def) < 0)
+ return NULL;
+
return g_steal_pointer(&conf);
}
diff --git a/tests/xlconfigdata/test-qemu-passthrough.cfg
b/tests/xlconfigdata/test-qemu-passthrough.cfg
new file mode 100644
index 0000000000..42aad92205
--- /dev/null
+++ b/tests/xlconfigdata/test-qemu-passthrough.cfg
@@ -0,0 +1,26 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-system-i386"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "d"
+disk = [
"format=raw,vdev=hda,access=rw,backendtype=qdisk,target=/var/lib/libvirt/images/XenGuest2"
]
+device_model_args = [ "-debugcon", "file:/tmp/debug.log",
"-global", "isa-debugcon.iobase=0x402" ]
diff --git a/tests/xlconfigdata/test-qemu-passthrough.xml
b/tests/xlconfigdata/test-qemu-passthrough.xml
new file mode 100644
index 0000000000..c7174cab06
--- /dev/null
+++ b/tests/xlconfigdata/test-qemu-passthrough.xml
@@ -0,0 +1,53 @@
+<domain type='xen'
xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
+ <name>XenGuest2</name>
+ <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>592896</memory>
+ <currentMemory unit='KiB'>403456</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='xenfv'>hvm</type>
+ <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+ <boot dev='cdrom'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='variable' adjustment='0' basis='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/lib/xen/bin/qemu-system-i386</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='/var/lib/libvirt/images/XenGuest2'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0'
target='0' unit='0'/>
+ </disk>
+ <controller type='xenbus' index='0'/>
+ <controller type='ide' index='0'/>
+ <interface type='bridge'>
+ <mac address='00:16:3e:66:92:9c'/>
+ <source bridge='xenbr1'/>
+ <script path='vif-bridge'/>
+ <model type='e1000'/>
+ </interface>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'
listen='127.0.0.1'>
+ <listen type='address' address='127.0.0.1'/>
+ </graphics>
+ <video>
+ <model type='cirrus' vram='8192' heads='1'
primary='yes'/>
+ </video>
+ <memballoon model='xen'/>
+ </devices>
+ <qemu:commandline>
+ <qemu:arg value='-debugcon'/>
+ <qemu:arg value='file:/tmp/debug.log'/>
+ <qemu:arg value='-global'/>
+ <qemu:arg value='isa-debugcon.iobase=0x402'/>
+ </qemu:commandline>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index b2e045dfa5..82b640f768 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -145,6 +145,9 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool
replaceVars)
if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt)))
goto fail;
+ /* Set def->ns before formating to XML */
+ def->ns = *(virDomainXMLOptionGetNamespace(driver->xmlopt));
+
if (!(gotxml = virDomainDefFormat(def, driver->xmlopt,
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE)))
@@ -304,6 +307,7 @@ mymain(void)
#ifdef LIBXL_HAVE_CREATEINFO_PASSTHROUGH
DO_TEST("fullvirt-hypervisor-features");
#endif
+ DO_TEST("qemu-passthrough");
testXLFreeDriver(driver);
--
2.26.2