Thanks to DV for knocking together the Relax-NG changes
quickly for me.
Changes since v1:
- Change the domain.rng to correspond to the new schema
- Don't allocate caps->ns in testQemuCapsInit since it is a static table
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
docs/schemas/domain.rng | 26 +++++++++++++++++
src/qemu/qemu_driver.c | 16 +++++-----
src/qemu/qemu_driver.h | 15 ++++++++++
tests/qemuargv2xmltest.c | 5 +++
.../qemuxml2argv-qemu-ns-no-env.args | 1 +
.../qemuxml2argv-qemu-ns-no-env.xml | 28 ++++++++++++++++++
tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.args | 1 +
tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.xml | 30 ++++++++++++++++++++
tests/qemuxml2argvtest.c | 2 +
tests/testutilsqemu.c | 6 ++++
10 files changed, 122 insertions(+), 8 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.xml
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 56b6705..1a615ef 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -41,6 +41,9 @@
<optional>
<ref name="seclabel"/>
</optional>
+ <optional>
+ <ref name='qemucmdline'/>
+ </optional>
</interleave>
</element>
</define>
@@ -1600,6 +1603,29 @@
</define>
<!--
+ Optional hypervisor extensions in their own namespace:
+ QEmu
+ -->
+ <define name="qemucmdline">
+ <element name="commandline"
ns="http://libvirt.org/schemas/domain/qemu/1.0">
+ <zeroOrMore>
+ <element name="arg">
+ <attribute name='value'/>
+ </element>
+ </zeroOrMore>
+ <zeroOrMore>
+ <element name="env">
+ <attribute name='name'/>
+ <optional>
+ <attribute name='value'/>
+ </optional>
+ <empty/>
+ </element>
+ </zeroOrMore>
+ </element>
+ </define>
+
+ <!--
Type library
Our unsignedInt doesn't allow a leading '+' in its lexical form
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d4e4de5..26d2217 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -530,7 +530,7 @@ static void qemuDomainObjExitMonitorWithDriver(struct qemud_driver
*driver, virD
}
}
-static void qemuDomainDefNamespaceFree(void *nsdata)
+void qemuDomainDefNamespaceFree(void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
unsigned int i;
@@ -550,10 +550,10 @@ static void qemuDomainDefNamespaceFree(void *nsdata)
VIR_FREE(cmd);
}
-static int qemuDomainDefNamespaceParse(xmlDocPtr xml,
- xmlNodePtr root,
- xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
- void **data)
+int qemuDomainDefNamespaceParse(xmlDocPtr xml,
+ xmlNodePtr root,
+ xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
+ void **data)
{
qemuDomainCmdlineDefPtr cmd = NULL;
xmlNsPtr ns;
@@ -643,8 +643,8 @@ error:
return -1;
}
-static int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
- void *nsdata)
+int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
+ void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
unsigned int i;
@@ -666,7 +666,7 @@ static int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
return 0;
}
-static const char *qemuDomainDefNamespaceHref(void)
+const char *qemuDomainDefNamespaceHref(void)
{
return "xmlns:qemu='" QEMU_NAMESPACE_HREF "'";
}
diff --git a/src/qemu/qemu_driver.h b/src/qemu/qemu_driver.h
index 95b8bff..99e011f 100644
--- a/src/qemu/qemu_driver.h
+++ b/src/qemu/qemu_driver.h
@@ -27,6 +27,8 @@
# include <config.h>
+# include <libxml/xpath.h>
+
# include "internal.h"
# if HAVE_LINUX_KVM_H
@@ -49,4 +51,17 @@
int qemuRegister(void);
+int qemuMonitorCommand(virDomainPtr domain, const char *cmd,
+ char **result, unsigned int flags);
+
+
+void qemuDomainDefNamespaceFree(void *nsdata);
+int qemuDomainDefNamespaceParse(xmlDocPtr xml,
+ xmlNodePtr root,
+ xmlXPathContextPtr ctxt,
+ void **data);
+int qemuDomainDefNamespaceFormatXML(virBufferPtr buf,
+ void *nsdata);
+const char *qemuDomainDefNamespaceHref(void);
+
#endif /* QEMUD_DRIVER_H */
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index bd81018..501bc75 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -228,6 +228,11 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC,
"exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP,
"tcp:10.0.0.1:5000");
+ /* it's not really possible to handle the environment variables in a
+ * generic way, so we run the qemu namespace test without them
+ */
+ DO_TEST("qemu-ns-no-env", 0);
+
free(driver.stateDir);
virCapabilitiesFree(driver.caps);
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.args
b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.args
new file mode 100644
index 0000000..b02eb26
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214
-smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda
/dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -unknown parameter
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.xml
b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.xml
new file mode 100644
index 0000000..38399f0
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.xml
@@ -0,0 +1,28 @@
+<domain type='qemu'
xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
+ <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'/>
+ <address type='drive' controller='0' bus='0'
unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ </devices>
+ <qemu:commandline>
+ <qemu:arg value='-unknown'/>
+ <qemu:arg value='parameter'/>
+ </qemu:commandline>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.args
b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.args
new file mode 100644
index 0000000..b7055d5
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test NS=ns BAR= /usr/bin/qemu -S -M
pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c
-hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb -unknown parameter
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.xml
b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.xml
new file mode 100644
index 0000000..c48c248
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-qemu-ns.xml
@@ -0,0 +1,30 @@
+<domain type='qemu'
xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
+ <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'/>
+ <address type='drive' controller='0' bus='0'
unit='0'/>
+ </disk>
+ <controller type='ide' index='0'/>
+ </devices>
+ <qemu:commandline>
+ <qemu:arg value='-unknown'/>
+ <qemu:arg value='parameter'/>
+ <qemu:env name='NS' value='ns'/>
+ <qemu:env name='BAR'/>
+ </qemu:commandline>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 9e4d5bf..19137ba 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -346,6 +346,8 @@ mymain(int argc, char **argv)
DO_TEST_FULL("restore-v2", QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC,
"exec:cat");
DO_TEST_FULL("migrate", QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP,
"tcp:10.0.0.1:5000");
+ DO_TEST("qemu-ns", 0);
+
free(driver.stateDir);
virCapabilitiesFree(driver.caps);
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 7fee21a..3659ff6 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -7,6 +7,7 @@
# include "testutils.h"
# include "memory.h"
# include "cpu_conf.h"
+# include "qemu/qemu_driver.h"
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
@@ -99,6 +100,11 @@ virCapsPtr testQemuCapsInit(void) {
(machines = testQemuAllocMachines(&nmachines)) == NULL)
goto cleanup;
+ caps->ns.parse = qemuDomainDefNamespaceParse;
+ caps->ns.free = qemuDomainDefNamespaceFree;
+ caps->ns.format = qemuDomainDefNamespaceFormatXML;
+ caps->ns.href = qemuDomainDefNamespaceHref;
+
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/bin/qemu", NULL,
nmachines, machines)) == NULL)
--
1.6.6.1