}
if ((topology = virXPathNode("./topology[1]", ctxt))) {
- int rc;
if (virXMLPropUInt(topology, "sockets", 10,
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
return -1;
}
- if ((rc = virXMLPropUInt(topology, "dies", 10,
- VIR_XML_PROP_NONZERO,
- &def->dies)) < 0) {
+ if (virXMLPropUIntDefault(topology, "dies", 10,
+ VIR_XML_PROP_NONZERO,
+ &def->dies, 1) < 0) {
return -1;
- } else if (rc == 0) {
- def->dies = 1;
}
if (virXMLPropUInt(topology, "cores", 10,
unsigned int vcpus;
g_autofree char *tmp = NULL;
g_autofree xmlNodePtr *nodes = NULL;
- int rc;
vcpus = maxvcpus = 1;
}
VIR_FREE(tmp);
- if ((rc = virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vcpus)) < 0) {
+ if (virXMLPropUIntDefault(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vcpus, maxvcpus) < 0)
return -1;
- } else if (rc == 0) {
- vcpus = maxvcpus;
- }
if (virXMLPropEnumDefault(vcpuNode, "placement",
virDomainCpuPlacementModeTypeFromString,
for (i = 0; i < n; i++) {
VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree char *tmp = NULL;
- int rc;
unsigned int cur_cell;
- if ((rc = virXMLPropUInt(cell[i], "id", 10, VIR_XML_PROP_NONE,
- &cur_cell)) < 0)
+ if (virXMLPropUIntDefault(cell[i], "id", 10, VIR_XML_PROP_NONE, &cur_cell, i) < 0)
return -1;
- if (rc == 0)
- cur_cell = i;
-
/* cells are in order of parsing or explicitly numbered */
if (cur_cell >= n) {
virReportError(VIR_ERR_XML_ERROR, "%s",
int base,
virXMLPropFlags flags,
unsigned int *result)
+{
+ return virXMLPropUIntDefault(node, name, base, flags, result, 0);
+}
+
+
+/**
+ * virXMLPropUIntDefault:
+ * @node: XML dom node pointer
+ * @name: Name of the property (attribute) to get
+ * @base: Number base, see strtol
+ * @flags: Bitwise-OR of virXMLPropFlags
+ * @result: The returned value
+ * @defaultResult: Default value of @result in case the property is not found
+ *
+ * Convenience function to return value of an unsigned integer attribute.
+ *
+ * Returns 1 in case of success in which case @result is set,
+ * or 0 if the attribute is not present,
+ * or -1 and reports an error on failure.
+ */
+int
+virXMLPropUIntDefault(xmlNodePtr node,
+ const char *name,
+ int base,
+ virXMLPropFlags flags,
+ unsigned int *result,
+ unsigned int defaultResult)
{
g_autofree char *tmp = NULL;
int ret;
unsigned int val;
- *result = 0;
+ *result = defaultResult;
if (!(tmp = virXMLPropString(node, name))) {
if (!(flags & VIR_XML_PROP_REQUIRED))
unsigned int *result)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
+int
+virXMLPropUIntDefault(xmlNodePtr node,
+ const char *name,
+ int base,
+ virXMLPropFlags flags,
+ unsigned int *result,
+ unsigned int defaultResult)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
+
int
virXMLPropLongLong(xmlNodePtr node,
const char *name,