xmlXPathContextPtr ctxt = NULL;
virDomainDeviceDefPtr dev = NULL;
- if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt))) {
+ if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt)))
goto error;
- }
+
node = ctxt->node;
if (VIR_ALLOC(dev) < 0) {
if (!(dev->data.rng = virDomainRNGDefParseXML(node, ctxt, flags)))
goto error;
} else {
- virReportError(VIR_ERR_XML_ERROR,
- "%s", _("unknown device type"));
+ virReportError(VIR_ERR_XML_ERROR, "%s", _("unknown device type"));
goto error;
}
+cleanup:
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
return dev;
- error:
- xmlFreeDoc(xml);
- xmlXPathFreeContext(ctxt);
+error:
VIR_FREE(dev);
- return NULL;
+ goto cleanup;
}
def->mem.cur_balloon = def->mem.max_balloon;
}
- node = virXPathNode("./memoryBacking/hugepages", ctxt);
- if (node)
+ if ((node = virXPathNode("./memoryBacking/hugepages", ctxt)))
def->mem.hugepage_backed = true;
/* Extract blkio cgroup tunables */
}
VIR_FREE(nodes);
- n = virXPathNodeSet("./features/*", ctxt, &nodes);
- if (n < 0)
+ if ((n = virXPathNodeSet("./features/*", ctxt, &nodes)) < 0)
goto error;
- if (n) {
- for (i = 0 ; i < n ; i++) {
- int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
- if (val < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected feature %s"),
- nodes[i]->name);
- goto error;
- }
- def->features |= (1 << val);
- if (val == VIR_DOMAIN_FEATURE_APIC) {
- tmp = virXPathString("string(./features/apic/@eoi)", ctxt);
- if (tmp) {
- int eoi;
- if ((eoi = virDomainFeatureStateTypeFromString(tmp)) <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown value for attribute eoi: %s"),
- tmp);
- goto error;
- }
- def->apic_eoi = eoi;
- VIR_FREE(tmp);
+
+ for (i = 0 ; i < n ; i++) {
+ int val = virDomainFeatureTypeFromString((const char *)nodes[i]->name);
+ if (val < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected feature %s"),
+ nodes[i]->name);
+ goto error;
+ }
+ def->features |= (1 << val);
+ if (val == VIR_DOMAIN_FEATURE_APIC) {
+ tmp = virXPathString("string(./features/apic/@eoi)", ctxt);
+ if (tmp) {
+ int eoi;
+ if ((eoi = virDomainFeatureStateTypeFromString(tmp)) <= 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unknown value for attribute eoi: %s"),
+ tmp);
+ goto error;
}
+ def->apic_eoi = eoi;
+ VIR_FREE(tmp);
}
}
- VIR_FREE(nodes);
}
+ VIR_FREE(nodes);
if (def->features & (1 << VIR_DOMAIN_FEATURE_HYPERV)) {
int feature;
&def->pm.s4) < 0)
goto error;
- tmp = virXPathString("string(./clock/@offset)", ctxt);
- if (tmp) {
- if ((def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown clock offset '%s'"), tmp);
- goto error;
- }
- VIR_FREE(tmp);
- } else {
- def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
+ if ((tmp = virXPathString("string(./clock/@offset)", ctxt)) &&
+ (def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unknown clock offset '%s'"), tmp);
+ goto error;
}
+ VIR_FREE(tmp);
+
switch (def->clock.offset) {
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
case VIR_DOMAIN_CLOCK_OFFSET_UTC:
break;
}
- if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) {
+ if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
goto error;
- }
+
if (n && VIR_ALLOC_N(def->clock.timers, n) < 0)
goto no_memory;
+
for (i = 0 ; i < n ; i++) {
virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i],
ctxt);
}
}
}
- tmp = virXPathString("string(./os/smbios/@mode)", ctxt);
- if (tmp) {
+
+ if ((tmp = virXPathString("string(./os/smbios/@mode)", ctxt))) {
int mode;
if ((mode = virDomainSmbiosModeTypeFromString(tmp)) < 0) {
}
def->os.smbios_mode = mode;
VIR_FREE(tmp);
- } else {
- def->os.smbios_mode = VIR_DOMAIN_SMBIOS_NONE; /* not present */
}
/* Extract custom metadata */
- if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL) {
+ if ((node = virXPathNode("./metadata[1]", ctxt)) != NULL)
def->metadata = xmlCopyNode(node, 1);
- }
/* we have to make a copy of all of the callback pointers here since
* we won't have the virCaps structure available during free
*/
def->ns = caps->ns;
- if (def->ns.parse) {
- if ((def->ns.parse)(xml, root, ctxt, &def->namespaceData) < 0)
- goto error;
- }
+ if (def->ns.parse &&
+ (def->ns.parse)(xml, root, ctxt, &def->namespaceData) < 0)
+ goto error;
- /* Auto-add any implied controllers which aren't present
- */
+ /* Auto-add any implied controllers which aren't present */
if (virDomainDefAddImplicitControllers(def) < 0)
goto error;
no_memory:
virReportOOMError();
- /* fallthrough */
-
- error:
+error:
VIR_FREE(tmp);
VIR_FREE(nodes);
virBitmapFree(bootMap);
goto cleanup;
}
- ctxt = xmlXPathNewContext(xml);
- if (ctxt == NULL) {
+ if (!(ctxt = xmlXPathNewContext(xml))) {
virReportOOMError();
goto cleanup;
}
int ret = -1;
char *xml;
- if (!(xml = virDomainDefFormat(def,
- VIR_DOMAIN_XML_WRITE_FLAGS)))
+ if (!(xml = virDomainDefFormat(def, VIR_DOMAIN_XML_WRITE_FLAGS)))
goto cleanup;
if (virDomainSaveXML(configDir, def, xml))
if ((configFile = virDomainConfigFile(configDir, dom->def->name)) == NULL)
goto cleanup;
- if ((autostartLink = virDomainConfigFile(autostartDir, dom->def->name)) == NULL)
+ if ((autostartLink = virDomainConfigFile(autostartDir,
+ dom->def->name)) == NULL)
goto cleanup;
/* Not fatal if this doesn't work */
*virDomainConfigFile(const char *dir,
const char *name)
{
- char *ret = NULL;
+ char *ret;
- if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) {
+ if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0)
virReportOOMError();
- return NULL;
- }
return ret;
}
virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data);
virObjectUnlock(doms);
if (data.oom) {
+ for (i = 0 ; i < data.numnames ; i++)
+ VIR_FREE(data.names[i]);
virReportOOMError();
- goto cleanup;
+ return -1;
}
return data.numnames;
-
-cleanup:
- for (i = 0 ; i < data.numnames ; i++)
- VIR_FREE(data.names[i]);
- return -1;
}
write_flags |= VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_MIGRATABLE;
/* Easiest to clone via a round-trip through XML. */
- xml = virDomainDefFormat(src, write_flags);
- if (!xml)
+ if (!(xml = virDomainDefFormat(src, write_flags)))
return NULL;
ret = virDomainDefParseString(caps, xml, -1, read_flags);