Give virDomainDef parser & formatter their own flags

The virDomainDefParse* and virDomainDefFormat* methods both
accept the VIR_DOMAIN_XML_* flags defined in the public API,
along with a set of other VIR_DOMAIN_XML_INTERNAL_* flags
defined in domain_conf.c.

This is seriously confusing & error prone for a number of
reasons:

 - VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_MIGRATABLE and
   VIR_DOMAIN_XML_UPDATE_CPU are only relevant for the
   formatting operation
 - Some of the VIR_DOMAIN_XML_INTERNAL_* flags only apply
   to parse or to format, but not both.

This patch cleanly separates out the flags. There are two
distint VIR_DOMAIN_DEF_PARSE_* and VIR_DOMAIN_DEF_FORMAT_*
flags that are used by the corresponding methods. The
VIR_DOMAIN_XML_* flags received via public API calls must
be converted to the VIR_DOMAIN_DEF_FORMAT_* flags where
needed.

The various calls to virDomainDefParse which hardcoded the
use of the VIR_DOMAIN_XML_INACTIVE flag change to use the
VIR_DOMAIN_DEF_PARSE_INACTIVE flag.
This commit is contained in:
Daniel P. Berrange
2014-11-18 16:44:00 +00:00
parent e34473c1da
commit 0ecd685109
41 changed files with 320 additions and 272 deletions

View File

@@ -33,7 +33,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
1 << VIR_DOMAIN_VIRT_BHYVE,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto out;
vm.def = vmdef;

View File

@@ -28,10 +28,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
1 << VIR_DOMAIN_VIRT_BHYVE,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto fail;
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE)))
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
goto fail;
if (STRNEQ(outXmlData, actual)) {

View File

@@ -102,7 +102,7 @@ testCompareXMLToXMLFiles(const char *inxml,
goto cleanup;
if (!(actual = virDomainSnapshotDefFormat(uuid, def,
VIR_DOMAIN_XML_SECURE,
VIR_DOMAIN_DEF_FORMAT_SECURE,
internal)))
goto cleanup;

View File

@@ -38,7 +38,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
if (!(def = virDomainDefParseString(inXmlData, caps, xmlopt,
1 << VIR_DOMAIN_VIRT_LXC,
live ? 0 : VIR_DOMAIN_XML_INACTIVE)))
live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto fail;
if (!virDomainDefCheckABIStability(def, def)) {
@@ -46,7 +46,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
goto fail;
}
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
goto fail;
if (STRNEQ(outXmlData, actual)) {

View File

@@ -115,7 +115,7 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
goto cleanup;
}
actual = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
if (actual == NULL) {
err = virGetLastError();

View File

@@ -187,7 +187,7 @@ testQemuAgentGetFSInfo(const void *data)
if (!(def = virDomainDefParseString(domain_xml, caps, xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto cleanup;
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)

View File

@@ -67,7 +67,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
driver.caps,
driver.xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto cleanup;
priv = (*vm)->privateData;
@@ -177,7 +177,7 @@ testQemuHotplugCheckResult(virDomainObjPtr vm,
char *actual;
int ret;
actual = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE);
actual = virDomainDefFormat(vm->def, VIR_DOMAIN_DEF_FORMAT_SECURE);
if (!actual)
return -1;
@@ -246,7 +246,7 @@ testQemuHotplug(const void *data)
}
if (test->action == ATTACH)
device_parse_flags = VIR_DOMAIN_XML_INACTIVE;
device_parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
if (!(dev = virDomainDeviceDefParse(device_xml, vm->def,
caps, driver.xmlopt,

View File

@@ -287,7 +287,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE))) {
VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
if (!virtTestOOMActive() &&
(flags & FLAG_EXPECT_PARSE_ERROR))
goto ok;

View File

@@ -30,7 +30,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
char *actual = NULL;
int ret = -1;
virDomainDefPtr def = NULL;
unsigned int flags = live ? 0 : VIR_DOMAIN_XML_INACTIVE;
unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE;
unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
if (!live)
format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
@@ -38,7 +41,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
goto fail;
if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
QEMU_EXPECTED_VIRT_TYPES, flags)))
QEMU_EXPECTED_VIRT_TYPES, parse_flags)))
goto fail;
if (!virDomainDefCheckABIStability(def, def)) {
@@ -46,7 +49,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
goto fail;
}
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE | flags)))
if (!(actual = virDomainDefFormat(def, format_flags)))
goto fail;
if (STRNEQ(outXmlData, actual)) {

View File

@@ -56,7 +56,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto fail;
if (!virDomainDefCheckABIStability(vmdef, vmdef)) {

View File

@@ -90,7 +90,7 @@ testCompareFiles(const char *vmx, const char *xml)
goto cleanup;
}
if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
goto cleanup;
if (STRNEQ(xmlData, formatted)) {

View File

@@ -74,7 +74,7 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
1 << VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto fail;
if (!virDomainDefCheckABIStability(def, def)) {
@@ -140,7 +140,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
goto fail;
if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
goto fail;
if (STRNEQ(xmlData, gotxml)) {

View File

@@ -37,7 +37,7 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
1 << VIR_DOMAIN_VIRT_XEN,
VIR_DOMAIN_XML_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
goto fail;
if (!virDomainDefCheckABIStability(def, def)) {

View File

@@ -86,7 +86,7 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
def = virDomainDefParseString(xmlData, caps, xmlopt,
1 << VIR_DOMAIN_VIRT_VMWARE,
VIR_DOMAIN_XML_INACTIVE);
VIR_DOMAIN_DEF_PARSE_INACTIVE);
if (def == NULL)
goto failure;