virStoragePoolDefParseSource: Use virXMLProp*

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-05-11 17:01:55 +02:00 committed by Michal Privoznik
parent 3681a53933
commit 0f8fd45482

View File

@ -531,7 +531,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
virStoragePoolOptions *options; virStoragePoolOptions *options;
int n; int n;
g_autoptr(virStorageAuthDef) authdef = NULL; g_autoptr(virStorageAuthDef) authdef = NULL;
g_autofree char *port = NULL;
g_autofree char *ver = NULL; g_autofree char *ver = NULL;
g_autofree xmlNodePtr *nodeset = NULL; g_autofree xmlNodePtr *nodeset = NULL;
g_autofree char *sourcedir = NULL; g_autofree char *sourcedir = NULL;
@ -580,16 +579,9 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
goto cleanup; goto cleanup;
} }
port = virXMLPropString(nodeset[i], "port"); if (virXMLPropInt(nodeset[i], "port", 10, VIR_XML_PROP_NONE,
if (port) { &source->hosts[i].port, 0) < 0)
if (virStrToLong_i(port, NULL, 10, &source->hosts[i].port) < 0) { goto cleanup;
virReportError(VIR_ERR_XML_ERROR,
_("Invalid port number: %s"),
port);
goto cleanup;
}
}
VIR_FREE(port);
} }
} }
@ -602,7 +594,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
goto cleanup; goto cleanup;
for (i = 0; i < nsource; i++) { for (i = 0; i < nsource; i++) {
g_autofree char *partsep = NULL;
virStoragePoolSourceDevice dev = { .path = NULL }; virStoragePoolSourceDevice dev = { .path = NULL };
dev.path = virXMLPropString(nodeset[i], "path"); dev.path = virXMLPropString(nodeset[i], "path");
@ -612,17 +603,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
goto cleanup; goto cleanup;
} }
partsep = virXMLPropString(nodeset[i], "part_separator"); if (virXMLPropTristateBool(nodeset[i], "part_separator",
if (partsep) { VIR_XML_PROP_NONE,
int value = virTristateBoolTypeFromString(partsep); &dev.part_separator) < 0) {
if (value <= 0) { virStoragePoolSourceDeviceClear(&dev);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, goto cleanup;
_("invalid part_separator setting '%s'"),
partsep);
virStoragePoolSourceDeviceClear(&dev);
goto cleanup;
}
dev.part_separator = value;
} }
if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0) { if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0) {