virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
{
xmlNodePtr *nodes = NULL;
- virStorageEncryptionPtr ret;
+ virStorageEncryptionPtr encdef = NULL;
+ virStorageEncryptionPtr ret = NULL;
char *format_str = NULL;
int n;
size_t i;
- if (VIR_ALLOC(ret) < 0)
- return NULL;
+ if (VIR_ALLOC(encdef) < 0)
+ goto cleanup;
if (!(format_str = virXPathString("string(./@format)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
goto cleanup;
}
- if ((ret->format =
+ if ((encdef->format =
virStorageEncryptionFormatTypeFromString(format_str)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume encryption format type %s"),
format_str);
goto cleanup;
}
- VIR_FREE(format_str);
if ((n = virXPathNodeSet("./secret", ctxt, &nodes)) < 0)
goto cleanup;
if (n > 0) {
- if (VIR_ALLOC_N(ret->secrets, n) < 0)
+ if (VIR_ALLOC_N(encdef->secrets, n) < 0)
goto cleanup;
- ret->nsecrets = n;
+ encdef->nsecrets = n;
for (i = 0; i < n; i++) {
- if (!(ret->secrets[i] =
+ if (!(encdef->secrets[i] =
virStorageEncryptionSecretParse(ctxt, nodes[i])))
goto cleanup;
}
- VIR_FREE(nodes);
}
- if (ret->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
+ if (encdef->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
xmlNodePtr tmpnode;
if ((tmpnode = virXPathNode("./cipher[1]", ctxt))) {
- if (virStorageEncryptionInfoParseCipher(tmpnode, &ret->encinfo) < 0)
+ if (virStorageEncryptionInfoParseCipher(tmpnode, &encdef->encinfo) < 0)
goto cleanup;
}
if ((tmpnode = virXPathNode("./ivgen[1]", ctxt))) {
/* If no cipher node, then fail */
- if (!ret->encinfo.cipher_name) {
+ if (!encdef->encinfo.cipher_name) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("ivgen element found, but cipher is missing"));
goto cleanup;
}
- if (virStorageEncryptionInfoParseIvgen(tmpnode, &ret->encinfo) < 0)
+ if (virStorageEncryptionInfoParseIvgen(tmpnode, &encdef->encinfo) < 0)
goto cleanup;
}
}
-
- return ret;
+ VIR_STEAL_PTR(ret, encdef);
cleanup:
VIR_FREE(format_str);
VIR_FREE(nodes);
- virStorageEncryptionFree(ret);
- return NULL;
+ virStorageEncryptionFree(encdef);
+ return ret;
}
virStorageEncryptionPtr