]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
lxc: use virDomainDefPostParse for parsing LXC config string
authorPavel Hrdina <phrdina@redhat.com>
Sun, 29 Nov 2015 02:55:32 +0000 (03:55 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 9 Dec 2015 11:59:02 +0000 (12:59 +0100)
This change ensures to call driver specific post-parse code to modify
domain definition after parsing hypervisor config the same way we do
after parsing XML.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
16 files changed:
src/lxc/lxc_driver.c
src/lxc/lxc_native.c
src/lxc/lxc_native.h
tests/Makefile.am
tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml
tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
tests/lxcconf2xmldata/lxcconf2xml-idmap.xml
tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml
tests/lxcconf2xmldata/lxcconf2xml-simple.xml
tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml
tests/lxcconf2xmltest.c

index 1a9550e438ae0dd9a5fb55bc48ca79cae5dba404..b2ab2c08e3acbb7ae53e4647c06ae3ae86fbf010 100644 (file)
@@ -1055,6 +1055,8 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
 {
     char *xml = NULL;
     virDomainDefPtr def = NULL;
+    virLXCDriverPtr driver = conn->privateData;
+    virCapsPtr caps = virLXCDriverGetCapabilities(driver, false);
 
     virCheckFlags(0, NULL);
 
@@ -1067,12 +1069,13 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!(def = lxcParseConfigString(nativeConfig)))
+    if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt)))
         goto cleanup;
 
     xml = virDomainDefFormat(def, 0);
 
  cleanup:
+    virObjectUnref(caps);
     virDomainDefFree(def);
     return xml;
 }
index 2f9559735a46f8f3ca7928fa6899eb64a2f66b72..8ff2253b46cc2f15b5a555c916fce0b68e019fc9 100644 (file)
@@ -991,7 +991,9 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
 }
 
 virDomainDefPtr
-lxcParseConfigString(const char *config)
+lxcParseConfigString(const char *config,
+                     virCapsPtr caps,
+                     virDomainXMLOptionPtr xmlopt)
 {
     virDomainDefPtr vmdef = NULL;
     virConfPtr properties = NULL;
@@ -1088,6 +1090,10 @@ lxcParseConfigString(const char *config)
     /* lxc.cap.drop */
     lxcSetCapDrop(vmdef, properties);
 
+    if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
+                              xmlopt) < 0)
+        goto cleanup;
+
     goto cleanup;
 
  error:
index a80f2b1eaf11d0faeed99b99fb0391e00dc2c5c0..15fa0d54748797b4f7f16c77aa3ce41e2e55e203 100644 (file)
@@ -27,6 +27,8 @@
 
 # define LXC_CONFIG_FORMAT "lxc-tools"
 
-virDomainDefPtr lxcParseConfigString(const char *config);
+virDomainDefPtr lxcParseConfigString(const char *config,
+                                     virCapsPtr caps,
+                                     virDomainXMLOptionPtr xmlopt);
 
 #endif /* __LXC_NATIVE_H__ */
index e1e28eca93f1c5ad242261b5714a5d08f5449b69..1d57b391084adc27e69b055cdbc8181c54995103 100644 (file)
@@ -659,7 +659,7 @@ lxcxml2xmltest_SOURCES = \
 lxcxml2xmltest_LDADD = $(lxc_LDADDS)
 
 lxcconf2xmltest_SOURCES = \
-       lxcconf2xmltest.c \
+       lxcconf2xmltest.c testutilslxc.c testutilslxc.h \
        testutils.c testutils.h
 lxcconf2xmltest_LDADD = $(lxc_LDADDS)
 else ! WITH_LXC
index c9c046969ace4f3aa41253eacc2da5fa4b224115..641edb94fab66777eb7189cb75fd0334876ae449 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <blkiotune>
     <weight>500</weight>
     <device>
@@ -33,6 +33,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index e7863fa13f84e7356af174bffe480efedd7e2c04..bafaa960f8839f7ae3f4ffb8e3578bdbf440ad0d 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static' cpuset='1-2,5-7'>1</vcpu>
   <numatune>
     <memory mode='strict' nodeset='1-4'/>
@@ -21,6 +21,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 50c5358abef63accd9ffff30fac8ac6992f58a71..f7f8041dd6d2667676824ae1e183383440aaa74f 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <cputune>
     <shares>1024</shares>
@@ -23,6 +23,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 80a83ff78ab0624ac97b962a883d42c7f260137e..dd3843d5cbdd594635e98455a17fe44e1148f384 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -22,6 +22,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 3105b8cefc9322f335207b296703686a0401e47c..a345e8e019e2436a68fdb18be4c527a5795e7474 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -17,6 +17,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 7df1ef0e98b0e9278750806e41a31b627d18093a..57e751aabab88de5ab6da73175cfcdc02081ef2d 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>1048576</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
   <memtune>
     <hard_limit unit='KiB'>1048576</hard_limit>
     <soft_limit unit='KiB'>131072</soft_limit>
@@ -23,6 +23,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index e002b99a6625317e7b27fa2f892029fe5f60561c..0122ab05c7a059a9f95aa5d111e8be7c2276fc2f 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -17,6 +17,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index dc9d6350f5c67e98682f4345e5c857ce9d730891..04ea280b3c3adbee02c60b7c4018a5e3394f9895 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -18,6 +18,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 79bcfa003ef2d9291d2bdce9505ce4207bd2a799..4fb3f954e02c03638656922e589300dd3101ff3c 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -17,6 +17,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 45a2012c5ad64c7c2d763aa0d695a890405043e5..5234bab7f2007fa10ddd0bc9c397b9340242389f 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type arch='i686'>exe</type>
@@ -21,6 +21,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 712be3e1ec45f59da6712942cc266f4b476b21bb..47ed898b0f1ad2b81d049dc826947231048ae6d6 100644 (file)
@@ -2,7 +2,7 @@
   <name>migrate_test</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>65536</memory>
-  <currentMemory unit='KiB'>0</currentMemory>
+  <currentMemory unit='KiB'>65536</currentMemory>
   <vcpu placement='static'>1</vcpu>
   <os>
     <type>exe</type>
@@ -17,6 +17,7 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <emulator>/usr/libexec/libvirt_lxc</emulator>
     <filesystem type='mount' accessmode='passthrough'>
       <source dir='/var/lib/lxc/migrate_test/rootfs'/>
       <target dir='/'/>
index 6255942cb0cb35db87f18e22b3b323f6dce0e3f5..ed21e8a389be256552b10b3b0aa33ac67d6ef709 100644 (file)
@@ -5,9 +5,14 @@
 #ifdef WITH_LXC
 
 # include "lxc/lxc_native.h"
+# include "lxc/lxc_conf.h"
+# include "testutilslxc.h"
 
 # define VIR_FROM_THIS VIR_FROM_NONE
 
+static virCapsPtr caps;
+static virDomainXMLOptionPtr xmlopt;
+
 static int
 blankProblemElements(char *data)
 {
@@ -30,7 +35,7 @@ testCompareXMLToConfigFiles(const char *xml,
     if (virtTestLoadFile(configfile, &config) < 0)
         goto fail;
 
-    vmdef = lxcParseConfigString(config);
+    vmdef = lxcParseConfigString(config, caps, xmlopt);
     if ((vmdef && expectError) || (!vmdef && !expectError))
         goto fail;
 
@@ -93,6 +98,14 @@ mymain(void)
 {
     int ret = EXIT_SUCCESS;
 
+    if (!(caps = testLXCCapsInit()))
+        return EXIT_FAILURE;
+
+    if (!(xmlopt = lxcDomainXMLConfInit())) {
+        virObjectUnref(caps);
+        return EXIT_FAILURE;
+    }
+
 # define DO_TEST(name, expectError)                         \
     do {                                                    \
         const struct testInfo info = { name, expectError }; \
@@ -115,6 +128,9 @@ mymain(void)
     DO_TEST("cpusettune", false);
     DO_TEST("blkiotune", false);
 
+    virObjectUnref(xmlopt);
+    virObjectUnref(caps);
+
     return ret;
 }