Thanks to DV for knocking together the Relax-NG changes
quickly for me.
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 | 12 ++++++++
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 | 12 ++++++-
10 files changed, 123 insertions(+), 10 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..4117a62 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">
+ <text/>
+ </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 973a752..d2e4ec9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -531,7 +531,7 @@ static void qemuDomainObjExitMonitorWithDriver(struct qemud_driver
*driver, virD
}
}
-static void qemuDomainDefNamespaceFree(void *nsdata)
+void qemuDomainDefNamespaceFree(void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
int i;
@@ -551,10 +551,10 @@ static void qemuDomainDefNamespaceFree(void *nsdata)
VIR_FREE(cmd);
}
-static int qemuDomainDefNamespaceParse(xmlDocPtr xml,
- xmlNodePtr root,
- xmlXPathContextPtr ctxt,
- void **data)
+int qemuDomainDefNamespaceParse(xmlDocPtr xml,
+ xmlNodePtr root,
+ xmlXPathContextPtr ctxt,
+ 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;
int i;
@@ -665,7 +665,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 f061cba..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
@@ -52,4 +54,14 @@ 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..c2cc901
--- /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>-unknown</qemu:arg>
+ <qemu:arg>parameter</qemu:arg>
+ </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..6101124
--- /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>-unknown</qemu:arg>
+ <qemu:arg>parameter</qemu:arg>
+ <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 8dd26d4..84f06dc 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -6,6 +6,7 @@
# include "testutilsqemu.h"
# include "testutils.h"
# include "memory.h"
+# include "qemu/qemu_driver.h"
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
@@ -57,8 +58,8 @@ virCapsPtr testQemuCapsInit(void) {
struct utsname utsname;
virCapsPtr caps;
virCapsGuestPtr guest;
- virCapsGuestMachinePtr *machines;
- int nmachines;
+ virCapsGuestMachinePtr *machines = NULL;
+ int nmachines = 0;
static const char *const xen_machines[] = {
"xenner"
};
@@ -68,6 +69,13 @@ virCapsPtr testQemuCapsInit(void) {
0, 0)) == NULL)
return NULL;
+ if (VIR_ALLOC(caps->ns) < 0)
+ goto cleanup;
+ caps->ns->parse = qemuDomainDefNamespaceParse;
+ caps->ns->free = qemuDomainDefNamespaceFree;
+ caps->ns->format = qemuDomainDefNamespaceFormatXML;
+ caps->ns->href = qemuDomainDefNamespaceHref;
+
if ((machines = testQemuAllocMachines(&nmachines)) == NULL)
goto cleanup;
--
1.6.6.1