提交 1933b878 编写于 作者: J John Ferlan

util: Clean up code formatting in virstorageencryption

Bring style more in line with more recent code.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 cc874efb
...@@ -112,8 +112,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, ...@@ -112,8 +112,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
{ {
xmlNodePtr old_node; xmlNodePtr old_node;
virStorageEncryptionSecretPtr ret; virStorageEncryptionSecretPtr ret;
char *type_str; char *type_str = NULL;
int type;
char *uuidstr = NULL; char *uuidstr = NULL;
if (VIR_ALLOC(ret) < 0) if (VIR_ALLOC(ret) < 0)
...@@ -122,25 +121,21 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, ...@@ -122,25 +121,21 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
old_node = ctxt->node; old_node = ctxt->node;
ctxt->node = node; ctxt->node = node;
type_str = virXPathString("string(./@type)", ctxt); if (!(type_str = virXPathString("string(./@type)", ctxt))) {
if (type_str == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("unknown volume encryption secret type")); _("unknown volume encryption secret type"));
goto cleanup; goto cleanup;
} }
type = virStorageEncryptionSecretTypeFromString(type_str);
if (type < 0) { if ((ret->type = virStorageEncryptionSecretTypeFromString(type_str)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume encryption secret type %s"), _("unknown volume encryption secret type %s"),
type_str); type_str);
VIR_FREE(type_str);
goto cleanup; goto cleanup;
} }
VIR_FREE(type_str); VIR_FREE(type_str);
ret->type = type;
uuidstr = virXPathString("string(./@uuid)", ctxt); if ((uuidstr = virXPathString("string(./@uuid)", ctxt))) {
if (uuidstr) {
if (virUUIDParse(uuidstr, ret->uuid) < 0) { if (virUUIDParse(uuidstr, ret->uuid) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("malformed volume encryption uuid '%s'"), _("malformed volume encryption uuid '%s'"),
...@@ -157,6 +152,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, ...@@ -157,6 +152,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
return ret; return ret;
cleanup: cleanup:
VIR_FREE(type_str);
virStorageEncryptionSecretFree(ret); virStorageEncryptionSecretFree(ret);
VIR_FREE(uuidstr); VIR_FREE(uuidstr);
ctxt->node = old_node; ctxt->node = old_node;
...@@ -168,46 +164,48 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) ...@@ -168,46 +164,48 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
{ {
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
virStorageEncryptionPtr ret; virStorageEncryptionPtr ret;
char *format_str; char *format_str = NULL;
int format, n; int n;
size_t i; size_t i;
if (VIR_ALLOC(ret) < 0) if (VIR_ALLOC(ret) < 0)
return NULL; return NULL;
format_str = virXPathString("string(./@format)", ctxt); if (!(format_str = virXPathString("string(./@format)", ctxt))) {
if (format_str == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("unknown volume encryption format")); _("unknown volume encryption format"));
goto cleanup; goto cleanup;
} }
format = virStorageEncryptionFormatTypeFromString(format_str);
if (format < 0) { if ((ret->format =
virStorageEncryptionFormatTypeFromString(format_str)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume encryption format type %s"), _("unknown volume encryption format type %s"),
format_str); format_str);
VIR_FREE(format_str);
goto cleanup; goto cleanup;
} }
VIR_FREE(format_str); VIR_FREE(format_str);
ret->format = format;
n = virXPathNodeSet("./secret", ctxt, &nodes); if ((n = virXPathNodeSet("./secret", ctxt, &nodes)) < 0)
if (n < 0)
goto cleanup; goto cleanup;
if (n != 0 && VIR_ALLOC_N(ret->secrets, n) < 0)
goto cleanup; if (n > 0) {
ret->nsecrets = n; if (VIR_ALLOC_N(ret->secrets, n) < 0)
for (i = 0; i < n; i++) {
ret->secrets[i] = virStorageEncryptionSecretParse(ctxt, nodes[i]);
if (ret->secrets[i] == NULL)
goto cleanup; goto cleanup;
ret->nsecrets = n;
for (i = 0; i < n; i++) {
if (!(ret->secrets[i] =
virStorageEncryptionSecretParse(ctxt, nodes[i])))
goto cleanup;
}
VIR_FREE(nodes);
} }
VIR_FREE(nodes);
return ret; return ret;
cleanup: cleanup:
VIR_FREE(format_str);
VIR_FREE(nodes); VIR_FREE(nodes);
virStorageEncryptionFree(ret); virStorageEncryptionFree(ret);
return NULL; return NULL;
...@@ -248,8 +246,7 @@ virStorageEncryptionSecretFormat(virBufferPtr buf, ...@@ -248,8 +246,7 @@ virStorageEncryptionSecretFormat(virBufferPtr buf,
const char *type; const char *type;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
type = virStorageEncryptionSecretTypeToString(secret->type); if (!(type = virStorageEncryptionSecretTypeToString(secret->type))) {
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("unexpected volume encryption secret type")); _("unexpected volume encryption secret type"));
return -1; return -1;
...@@ -268,8 +265,7 @@ virStorageEncryptionFormat(virBufferPtr buf, ...@@ -268,8 +265,7 @@ virStorageEncryptionFormat(virBufferPtr buf,
const char *format; const char *format;
size_t i; size_t i;
format = virStorageEncryptionFormatTypeToString(enc->format); if (!(format = virStorageEncryptionFormatTypeToString(enc->format))) {
if (!format) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("unexpected encryption format")); "%s", _("unexpected encryption format"));
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册