This is new allocator for virDomainMemoryDef struct which also
sets some default values: @model and @targetNode.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 26 +++++++++++++++++++-------
src/conf/domain_conf.h | 1 +
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 622f83590f..d3b8ef3656 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13088,9 +13088,6 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
ctxt->node = node;
- /* initialize to value which marks that the user didn't specify it */
- def->targetNode = -1;
-
if ((rv = virXPathInt("string(./node)", ctxt, &def->targetNode)) ==
-2 ||
(rv == 0 && def->targetNode < 0)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -13226,6 +13223,20 @@ virDomainSecDefParseXML(xmlNodePtr lsecNode,
}
+virDomainMemoryDef *
+virDomainMemoryDefNew(virDomainMemoryModel model)
+{
+ virDomainMemoryDef *def = NULL;
+
+ def = g_new0(virDomainMemoryDef, 1);
+ def->model = model;
+ /* initialize to value which marks that the user didn't specify it */
+ def->targetNode = -1;
+
+ return def;
+}
+
+
static virDomainMemoryDef *
virDomainMemoryDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr memdevNode,
@@ -13234,18 +13245,19 @@ virDomainMemoryDefParseXML(virDomainXMLOption *xmlopt,
{
VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr node;
- virDomainMemoryDef *def;
+ virDomainMemoryDef *def = NULL;
+ virDomainMemoryModel model;
g_autofree char *tmp = NULL;
- def = g_new0(virDomainMemoryDef, 1);
-
ctxt->node = memdevNode;
if (virXMLPropEnum(memdevNode, "model",
virDomainMemoryModelTypeFromString,
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
- &def->model) < 0)
+ &model) < 0)
goto error;
+ def = virDomainMemoryDefNew(model);
+
if (virXMLPropEnum(memdevNode, "access",
virDomainMemoryAccessTypeFromString,
VIR_XML_PROP_NONZERO, &def->access) < 0)
goto error;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e16558988d..d29ebf8b8a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2619,6 +2619,7 @@ struct _virDomainMemoryDef {
virDomainDeviceInfo info;
};
+virDomainMemoryDef *virDomainMemoryDefNew(virDomainMemoryModel model);
void virDomainMemoryDefFree(virDomainMemoryDef *def);
struct _virDomainIdMapEntry {
--
2.37.4