separate virDomainDefParseFeatureInfo from virDomainDefParseXML
---
src/conf/domain_conf.c | 221 +++++++++++++++++++++++++++----------------------
1 file changed, 122 insertions(+), 99 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 24bd240..b8fe24e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19307,94 +19307,27 @@ virDomainDefParseResourceInfo(virDomainParseTotalParamPtr
param)
}
-static virDomainDefPtr
-virDomainDefParseXML(xmlDocPtr xml,
- xmlNodePtr root,
- xmlXPathContextPtr ctxt,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- void *parseOpaque,
- unsigned int flags)
+static int
+virDomainDefParseFeatureInfo(virDomainParseTotalParamPtr param)
{
- typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params);
+ virDomainDefPtr def = param->def;
+ xmlXPathContextPtr ctxt = param->ctxt;
- xmlNodePtr *nodes = NULL, node = NULL;
- char *tmp = NULL;
- size_t i, j;
+ int ret = -1;
int n, gic_version;
- size_t fun_index = 0;
- virDomainDefPtr def;
- bool uuid_generated = false;
- virHashTablePtr bootHash = NULL;
- bool usb_none = false;
- bool usb_other = false;
- bool usb_master = false;
- char *netprefix = NULL;
- virDomainParseTotalParam param = {
- NULL,
- xml,
- root,
- ctxt,
- caps,
- xmlopt,
- parseOpaque,
- flags,
- false,
- false,
- false,
- false
-
- };
-
- virDomainPreaseInfoFunc parse_funs[] = {
- virDomainDefParseIdInfo,
- virDomainDefParseVirtTypeInfo,
- virDomainDefParseOsNodeInfo,
- virDomainDefParseDomainInfo,
- virDomainDefParseSecurityLabelInfo,
- virDomainDefParseMemoryInfo,
- virDomainDefParseBikiotuneInfo,
- virDomainDefParseVcpuInfo,
- virDomainDefParseIoThreadInfo,
- virDomainDefParseCputuneInfo,
- virDomainDefParseCpuNumaInfo,
- virDomainDefParseResourceInfo,
- NULL
- };
-
- if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) {
- char *schema = virFileFindResource("domain.rng",
- abs_topsrcdir "/docs/schemas",
- PKGDATADIR "/schemas");
- if (!schema)
- return NULL;
- if (virXMLValidateAgainstSchema(schema, xml) < 0) {
- VIR_FREE(schema);
- return NULL;
- }
- VIR_FREE(schema);
- }
-
- if (!(def = virDomainDefNew()))
- return NULL;
-
- param.def = def;
-
- while (parse_funs[fun_index]) {
- if (parse_funs[fun_index](¶m) < 0)
- goto error;
- fun_index++;
- }
+ char *tmp = NULL;
+ size_t i;
+ xmlNodePtr *nodes = NULL, node = NULL;
if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) < 0)
- goto error;
+ goto cleanup;
for (i = 0; i < n; i++) {
int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unexpected feature '%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
switch ((virDomainFeature) val) {
@@ -19405,7 +19338,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown value for attribute eoi:
'%s'"),
tmp);
- goto error;
+ goto cleanup;
}
def->apic_eoi = eoi;
VIR_FREE(tmp);
@@ -19427,7 +19360,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown policy attribute '%s' of
feature '%s'"),
tmp, virDomainFeatureTypeToString(val));
- goto error;
+ goto cleanup;
}
VIR_FREE(tmp);
} else {
@@ -19445,7 +19378,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown state attribute '%s' of
feature '%s'"),
tmp, virDomainFeatureTypeToString(val));
- goto error;
+ goto cleanup;
}
VIR_FREE(tmp);
} else {
@@ -19459,7 +19392,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if (gic_version < 0 || gic_version == VIR_GIC_VERSION_NONE) {
virReportError(VIR_ERR_XML_ERROR,
_("malformed gic version: %s"), tmp);
- goto error;
+ goto cleanup;
}
def->gic_version = gic_version;
VIR_FREE(tmp);
@@ -19475,7 +19408,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown driver mode: %s"),
tmp);
- goto error;
+ goto cleanup;
}
def->ioapic = value;
def->features[val] = VIR_TRISTATE_SWITCH_ON;
@@ -19491,7 +19424,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown HPT resizing setting: %s"),
tmp);
- goto error;
+ goto cleanup;
}
def->hpt_resizing = value;
def->features[val] = VIR_TRISTATE_SWITCH_ON;
@@ -19511,7 +19444,7 @@ virDomainDefParseXML(xmlDocPtr xml,
int value;
node = ctxt->node;
if ((n = virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) <
0)
- goto error;
+ goto cleanup;
for (i = 0; i < n; i++) {
feature = virDomainHypervTypeFromString((const char *)nodes[i]->name);
@@ -19519,7 +19452,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported HyperV Enlightenment feature:
%s"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
ctxt->node = nodes[i];
@@ -19529,7 +19462,7 @@ virDomainDefParseXML(xmlDocPtr xml,
_("missing 'state' attribute for "
"HyperV Enlightenment feature '%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
@@ -19537,7 +19470,7 @@ virDomainDefParseXML(xmlDocPtr xml,
_("invalid value of state argument "
"for HyperV Enlightenment feature
'%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
VIR_FREE(tmp);
@@ -19561,14 +19494,14 @@ virDomainDefParseXML(xmlDocPtr xml,
&def->hyperv_spinlocks) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid HyperV spinlock retry count"));
- goto error;
+ goto cleanup;
}
if (def->hyperv_spinlocks < 0xFFF) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("HyperV spinlock retry count must be "
"at least 4095"));
- goto error;
+ goto cleanup;
}
break;
@@ -19581,7 +19514,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing 'value' attribute for "
"HyperV feature 'vendor_id'"));
- goto error;
+ goto cleanup;
}
if (strlen(def->hyperv_vendor_id) >
VIR_DOMAIN_HYPERV_VENDOR_ID_MAX) {
@@ -19589,14 +19522,14 @@ virDomainDefParseXML(xmlDocPtr xml,
_("HyperV vendor_id value must not be more
"
"than %d characters."),
VIR_DOMAIN_HYPERV_VENDOR_ID_MAX);
- goto error;
+ goto cleanup;
}
/* ensure that the string can be passed to qemu */
if (strchr(def->hyperv_vendor_id, ',')) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("HyperV vendor_id value is invalid"));
- goto error;
+ goto cleanup;
}
/* coverity[dead_error_begin] */
@@ -19612,7 +19545,7 @@ virDomainDefParseXML(xmlDocPtr xml,
int feature;
int value;
if ((n = virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) <
0)
- goto error;
+ goto cleanup;
for (i = 0; i < n; i++) {
feature = virDomainKVMTypeFromString((const char *)nodes[i]->name);
@@ -19620,7 +19553,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported KVM feature: %s"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
switch ((virDomainKVM) feature) {
@@ -19630,7 +19563,7 @@ virDomainDefParseXML(xmlDocPtr xml,
_("missing 'state' attribute for
"
"KVM feature '%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
if ((value = virTristateSwitchTypeFromString(tmp)) < 0) {
@@ -19638,7 +19571,7 @@ virDomainDefParseXML(xmlDocPtr xml,
_("invalid value of state argument "
"for KVM feature '%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
VIR_FREE(tmp);
@@ -19654,14 +19587,14 @@ virDomainDefParseXML(xmlDocPtr xml,
}
if ((n = virXPathNodeSet("./features/capabilities/*", ctxt, &nodes))
< 0)
- goto error;
+ goto cleanup;
for (i = 0; i < n; i++) {
int val = virDomainCapsFeatureTypeFromString((const char *)nodes[i]->name);
if (val < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unexpected capability feature '%s'"),
nodes[i]->name);
- goto error;
+ goto cleanup;
}
if (val >= 0 && val < VIR_DOMAIN_CAPS_FEATURE_LAST) {
@@ -19670,7 +19603,7 @@ virDomainDefParseXML(xmlDocPtr xml,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown state attribute '%s' of
feature capability '%s'"),
tmp, virDomainFeatureTypeToString(val));
- goto error;
+ goto cleanup;
}
VIR_FREE(tmp);
} else {
@@ -19680,6 +19613,96 @@ virDomainDefParseXML(xmlDocPtr xml,
}
VIR_FREE(nodes);
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(tmp);
+ VIR_FREE(nodes);
+ return ret;
+}
+
+
+static virDomainDefPtr
+virDomainDefParseXML(xmlDocPtr xml,
+ xmlNodePtr root,
+ xmlXPathContextPtr ctxt,
+ virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
+ void *parseOpaque,
+ unsigned int flags)
+{
+ typedef int (*virDomainPreaseInfoFunc)(virDomainParseTotalParamPtr params);
+
+ xmlNodePtr *nodes = NULL, node = NULL;
+ char *tmp = NULL;
+ size_t i, j;
+ int n;
+ size_t fun_index = 0;
+ virDomainDefPtr def;
+ bool uuid_generated = false;
+ virHashTablePtr bootHash = NULL;
+ bool usb_none = false;
+ bool usb_other = false;
+ bool usb_master = false;
+ char *netprefix = NULL;
+ virDomainParseTotalParam param = {
+ NULL,
+ xml,
+ root,
+ ctxt,
+ caps,
+ xmlopt,
+ parseOpaque,
+ flags,
+ false,
+ false,
+ false,
+ false
+
+ };
+
+ virDomainPreaseInfoFunc parse_funs[] = {
+ virDomainDefParseIdInfo,
+ virDomainDefParseVirtTypeInfo,
+ virDomainDefParseOsNodeInfo,
+ virDomainDefParseDomainInfo,
+ virDomainDefParseSecurityLabelInfo,
+ virDomainDefParseMemoryInfo,
+ virDomainDefParseBikiotuneInfo,
+ virDomainDefParseVcpuInfo,
+ virDomainDefParseIoThreadInfo,
+ virDomainDefParseCputuneInfo,
+ virDomainDefParseCpuNumaInfo,
+ virDomainDefParseResourceInfo,
+ virDomainDefParseFeatureInfo,
+ NULL
+ };
+
+ if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) {
+ char *schema = virFileFindResource("domain.rng",
+ abs_topsrcdir "/docs/schemas",
+ PKGDATADIR "/schemas");
+ if (!schema)
+ return NULL;
+ if (virXMLValidateAgainstSchema(schema, xml) < 0) {
+ VIR_FREE(schema);
+ return NULL;
+ }
+ VIR_FREE(schema);
+ }
+
+ if (!(def = virDomainDefNew()))
+ return NULL;
+
+ param.def = def;
+
+ while (parse_funs[fun_index]) {
+ if (parse_funs[fun_index](¶m) < 0)
+ goto error;
+ fun_index++;
+ }
+
+
if (virDomainEventActionParseXML(ctxt, "on_reboot",
"string(./on_reboot[1])",
&def->onReboot,
--
2.8.3