提交 1dc38b72 编写于 作者: P Pavel Hrdina

lxc: use virDomainDefPostParse for parsing LXC config string

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: NPavel Hrdina <phrdina@redhat.com>
上级 eba20715
...@@ -1055,6 +1055,8 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn, ...@@ -1055,6 +1055,8 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
{ {
char *xml = NULL; char *xml = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virLXCDriverPtr driver = conn->privateData;
virCapsPtr caps = virLXCDriverGetCapabilities(driver, false);
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -1067,12 +1069,13 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn, ...@@ -1067,12 +1069,13 @@ static char *lxcConnectDomainXMLFromNative(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (!(def = lxcParseConfigString(nativeConfig))) if (!(def = lxcParseConfigString(nativeConfig, caps, driver->xmlopt)))
goto cleanup; goto cleanup;
xml = virDomainDefFormat(def, 0); xml = virDomainDefFormat(def, 0);
cleanup: cleanup:
virObjectUnref(caps);
virDomainDefFree(def); virDomainDefFree(def);
return xml; return xml;
} }
......
...@@ -991,7 +991,9 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties) ...@@ -991,7 +991,9 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
} }
virDomainDefPtr virDomainDefPtr
lxcParseConfigString(const char *config) lxcParseConfigString(const char *config,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt)
{ {
virDomainDefPtr vmdef = NULL; virDomainDefPtr vmdef = NULL;
virConfPtr properties = NULL; virConfPtr properties = NULL;
...@@ -1088,6 +1090,10 @@ lxcParseConfigString(const char *config) ...@@ -1088,6 +1090,10 @@ lxcParseConfigString(const char *config)
/* lxc.cap.drop */ /* lxc.cap.drop */
lxcSetCapDrop(vmdef, properties); lxcSetCapDrop(vmdef, properties);
if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
xmlopt) < 0)
goto cleanup;
goto cleanup; goto cleanup;
error: error:
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
# define LXC_CONFIG_FORMAT "lxc-tools" # define LXC_CONFIG_FORMAT "lxc-tools"
virDomainDefPtr lxcParseConfigString(const char *config); virDomainDefPtr lxcParseConfigString(const char *config,
virCapsPtr caps,
virDomainXMLOptionPtr xmlopt);
#endif /* __LXC_NATIVE_H__ */ #endif /* __LXC_NATIVE_H__ */
...@@ -659,7 +659,7 @@ lxcxml2xmltest_SOURCES = \ ...@@ -659,7 +659,7 @@ lxcxml2xmltest_SOURCES = \
lxcxml2xmltest_LDADD = $(lxc_LDADDS) lxcxml2xmltest_LDADD = $(lxc_LDADDS)
lxcconf2xmltest_SOURCES = \ lxcconf2xmltest_SOURCES = \
lxcconf2xmltest.c \ lxcconf2xmltest.c testutilslxc.c testutilslxc.h \
testutils.c testutils.h testutils.c testutils.h
lxcconf2xmltest_LDADD = $(lxc_LDADDS) lxcconf2xmltest_LDADD = $(lxc_LDADDS)
else ! WITH_LXC else ! WITH_LXC
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<blkiotune> <blkiotune>
<weight>500</weight> <weight>500</weight>
<device> <device>
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <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> <vcpu placement='static' cpuset='1-2,5-7'>1</vcpu>
<numatune> <numatune>
<memory mode='strict' nodeset='1-4'/> <memory mode='strict' nodeset='1-4'/>
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<cputune> <cputune>
<shares>1024</shares> <shares>1024</shares>
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>1048576</memory> <memory unit='KiB'>1048576</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>1048576</currentMemory>
<memtune> <memtune>
<hard_limit unit='KiB'>1048576</hard_limit> <hard_limit unit='KiB'>1048576</hard_limit>
<soft_limit unit='KiB'>131072</soft_limit> <soft_limit unit='KiB'>131072</soft_limit>
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type arch='i686'>exe</type> <type arch='i686'>exe</type>
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<name>migrate_test</name> <name>migrate_test</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>65536</memory> <memory unit='KiB'>65536</memory>
<currentMemory unit='KiB'>0</currentMemory> <currentMemory unit='KiB'>65536</currentMemory>
<vcpu placement='static'>1</vcpu> <vcpu placement='static'>1</vcpu>
<os> <os>
<type>exe</type> <type>exe</type>
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<on_reboot>restart</on_reboot> <on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash> <on_crash>destroy</on_crash>
<devices> <devices>
<emulator>/usr/libexec/libvirt_lxc</emulator>
<filesystem type='mount' accessmode='passthrough'> <filesystem type='mount' accessmode='passthrough'>
<source dir='/var/lib/lxc/migrate_test/rootfs'/> <source dir='/var/lib/lxc/migrate_test/rootfs'/>
<target dir='/'/> <target dir='/'/>
......
...@@ -5,9 +5,14 @@ ...@@ -5,9 +5,14 @@
#ifdef WITH_LXC #ifdef WITH_LXC
# include "lxc/lxc_native.h" # include "lxc/lxc_native.h"
# include "lxc/lxc_conf.h"
# include "testutilslxc.h"
# define VIR_FROM_THIS VIR_FROM_NONE # define VIR_FROM_THIS VIR_FROM_NONE
static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;
static int static int
blankProblemElements(char *data) blankProblemElements(char *data)
{ {
...@@ -30,7 +35,7 @@ testCompareXMLToConfigFiles(const char *xml, ...@@ -30,7 +35,7 @@ testCompareXMLToConfigFiles(const char *xml,
if (virtTestLoadFile(configfile, &config) < 0) if (virtTestLoadFile(configfile, &config) < 0)
goto fail; goto fail;
vmdef = lxcParseConfigString(config); vmdef = lxcParseConfigString(config, caps, xmlopt);
if ((vmdef && expectError) || (!vmdef && !expectError)) if ((vmdef && expectError) || (!vmdef && !expectError))
goto fail; goto fail;
...@@ -93,6 +98,14 @@ mymain(void) ...@@ -93,6 +98,14 @@ mymain(void)
{ {
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
if (!(caps = testLXCCapsInit()))
return EXIT_FAILURE;
if (!(xmlopt = lxcDomainXMLConfInit())) {
virObjectUnref(caps);
return EXIT_FAILURE;
}
# define DO_TEST(name, expectError) \ # define DO_TEST(name, expectError) \
do { \ do { \
const struct testInfo info = { name, expectError }; \ const struct testInfo info = { name, expectError }; \
...@@ -115,6 +128,9 @@ mymain(void) ...@@ -115,6 +128,9 @@ mymain(void)
DO_TEST("cpusettune", false); DO_TEST("cpusettune", false);
DO_TEST("blkiotune", false); DO_TEST("blkiotune", false);
virObjectUnref(xmlopt);
virObjectUnref(caps);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册