Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_block.c | 206 +++++++++++++++---------------------------
1 file changed, 72 insertions(+), 134 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 2017eca139..31800919a7 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -142,7 +142,6 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr next,
const char *drvparent = NULL;
const char *parentnodename = NULL;
const char *filename = NULL;
- int ret = -1;
if (!nodename)
return 0;
@@ -172,27 +171,24 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr next,
}
if (VIR_ALLOC(data) < 0)
- goto cleanup;
+ return -1;
if (VIR_STRDUP(data->nodeformat, nodename) < 0 ||
VIR_STRDUP(data->nodestorage, parentnodename) < 0 ||
VIR_STRDUP(data->qemufilename, filename) < 0 ||
VIR_STRDUP(data->drvformat, drvname) < 0 ||
VIR_STRDUP(data->drvstorage, drvparent) < 0)
- goto cleanup;
+ return -1;
if (backing &&
qemuBlockNodeNameGetBackingChainBacking(backing, nodenamestable,
&backingdata) < 0)
- goto cleanup;
+ return -1;
VIR_STEAL_PTR(data->backing, backingdata);
VIR_STEAL_PTR(*nodenamedata, data);
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
@@ -204,22 +200,17 @@ qemuBlockNodeNameGetBackingChainDisk(size_t pos ATTRIBUTE_UNUSED,
struct qemuBlockNodeNameGetBackingChainData *data = opaque;
const char *device = virJSONValueObjectGetString(item, "device");
VIR_AUTOPTR(qemuBlockNodeNameBackingChainData) devicedata = NULL;
- int ret = -1;
if (qemuBlockNodeNameGetBackingChainBacking(item, data->nodenamestable,
&devicedata) < 0)
- goto cleanup;
+ return -1;
if (devicedata &&
virHashAddEntry(data->disks, device, devicedata) < 0)
- goto cleanup;
+ return -1;
devicedata = NULL;
- ret = 1; /* we don't really want to steal @item */
-
- cleanup:
-
- return ret;
+ return 1; /* we don't really want to steal @item */
}
@@ -248,15 +239,15 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namednodes,
memset(&data, 0, sizeof(data));
if (!(namednodestable = virHashCreate(50, virJSONValueHashFree)))
- goto cleanup;
+ return NULL;
if (virJSONValueArrayForeachSteal(namednodes,
qemuBlockNamedNodesArrayToHash,
namednodestable) < 0)
- goto cleanup;
+ return NULL;
if (!(disks = virHashCreate(50, qemuBlockNodeNameBackingChainDataHashEntryFree)))
- goto cleanup;
+ return NULL;
data.nodenamestable = namednodestable;
data.disks = disks;
@@ -264,13 +255,10 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namednodes,
if (virJSONValueArrayForeachSteal(blockstats,
qemuBlockNodeNameGetBackingChainDisk,
&data) < 0)
- goto cleanup;
+ return NULL;
VIR_STEAL_PTR(ret, disks);
-
- cleanup:
-
- return ret;
+ return ret;
}
@@ -347,7 +335,6 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
VIR_AUTOPTR(virJSONValue) blockstats = NULL;
virDomainDiskDefPtr disk;
size_t i;
- int ret = -1;
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_NAMED_BLOCK_NODES))
return 0;
@@ -359,23 +346,19 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
blockstats = qemuMonitorQueryBlockstats(qemuDomainGetMonitor(vm));
if (qemuDomainObjExitMonitor(driver, vm) < 0 || !data || !blockstats)
- goto cleanup;
+ return -1;
if (!(disktable = qemuBlockNodeNameGetBackingChain(data, blockstats)))
- goto cleanup;
+ return -1;
for (i = 0; i < vm->def->ndisks; i++) {
disk = vm->def->disks[i];
if (qemuBlockDiskDetectNodes(disk, disktable) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
-
- return ret;
+ return 0;
}
@@ -399,13 +382,10 @@ qemuBlockGetNodeData(virJSONValuePtr data)
if (virJSONValueArrayForeachSteal(data,
qemuBlockNamedNodesArrayToHash, nodedata) < 0)
- goto error;
+ return NULL;
VIR_STEAL_PTR(ret, nodedata);
return ret;
-
- error:
- return NULL;
}
@@ -440,44 +420,42 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("protocol '%s' accepts only one host"),
virStorageNetProtocolTypeToString(src->protocol));
- goto cleanup;
+ return NULL;
}
if (VIR_ALLOC(uri) < 0)
- goto cleanup;
+ return NULL;
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
uri->port = src->hosts->port;
if (VIR_STRDUP(uri->scheme,
virStorageNetProtocolTypeToString(src->protocol)) < 0)
- goto cleanup;
+ return NULL;
} else {
if (virAsprintf(&uri->scheme, "%s+%s",
virStorageNetProtocolTypeToString(src->protocol),
virStorageNetHostTransportTypeToString(src->hosts->transport)) < 0)
- goto cleanup;
+ return NULL;
}
if (src->path) {
if (src->volume) {
if (virAsprintf(&uri->path, "/%s/%s",
src->volume, src->path) < 0)
- goto cleanup;
+ return NULL;
} else {
if (virAsprintf(&uri->path, "%s%s",
src->path[0] == '/' ? "" :
"/",
src->path) < 0)
- goto cleanup;
+ return NULL;
}
}
if (VIR_STRDUP(uri->server, src->hosts->name) < 0)
- goto cleanup;
+ return NULL;
VIR_STEAL_PTR(ret, uri);
-
- cleanup:
return ret;
}
@@ -513,14 +491,14 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr
host,
transport = "inet";
if (virAsprintf(&port, "%u", host->port) < 0)
- goto cleanup;
+ return NULL;
if (virJSONValueObjectCreate(&server,
"s:type", transport,
"s:host", host->name,
"s:port", port,
NULL) < 0)
- goto cleanup;
+ return NULL;
break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
@@ -533,7 +511,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr
host,
"s:type", "unix",
field, host->socket,
NULL) < 0)
- goto cleanup;
+ return NULL;
break;
case VIR_STORAGE_NET_HOST_TRANS_RDMA:
@@ -541,13 +519,10 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr
host,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("transport protocol '%s' is not yet
supported"),
virStorageNetHostTransportTypeToString(host->transport));
- goto cleanup;
+ return NULL;
}
VIR_STEAL_PTR(ret, server);
-
- cleanup:
-
return ret;
}
@@ -571,24 +546,21 @@
qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
size_t i;
if (!(servers = virJSONValueNewArray()))
- goto cleanup;
+ return NULL;
for (i = 0; i < src->nhosts; i++) {
host = src->hosts + i;
if (!(server = qemuBlockStorageSourceBuildJSONSocketAddress(host, legacy)))
- goto cleanup;
+ return NULL;
if (virJSONValueArrayAppend(servers, server) < 0)
- goto cleanup;
+ return NULL;
server = NULL;
}
VIR_STEAL_PTR(ret, servers);
-
- cleanup:
-
return ret;
}
@@ -643,24 +615,21 @@
qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
size_t i;
if (!(servers = virJSONValueNewArray()))
- goto cleanup;
+ return NULL;
for (i = 0; i < src->nhosts; i++) {
host = src->hosts + i;
if (!(server = qemuBlockStorageSourceBuildJSONInetSocketAddress(host)))
- goto cleanup;
+ return NULL;
if (virJSONValueArrayAppend(servers, server) < 0)
- goto cleanup;
+ return NULL;
server = NULL;
}
VIR_STEAL_PTR(ret, servers);
-
- cleanup:
-
return ret;
}
@@ -687,16 +656,13 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
"s:volume", src->volume,
"s:path", src->path,
"a:server", &servers, NULL) < 0)
- goto cleanup;
+ return NULL;
if (src->debug &&
virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) <
0)
- goto cleanup;
+ return NULL;
VIR_STEAL_PTR(ret, props);
-
- cleanup:
-
return ret;
}
@@ -759,10 +725,10 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src)
driver = virStorageNetProtocolTypeToString(src->protocol);
if (!(uri = qemuBlockStorageSourceGetURI(src)))
- goto cleanup;
+ return NULL;
if (!(uristr = virURIFormat(uri)))
- goto cleanup;
+ return NULL;
if (src->auth) {
username = src->auth->username;
@@ -776,8 +742,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src)
"S:password-secret", passwordalias,
NULL));
- cleanup:
-
return ret;
}
@@ -807,7 +771,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
*/
if (VIR_STRDUP(target, src->path) < 0)
- goto cleanup;
+ return NULL;
/* Separate the target and lun */
if ((lunStr = strchr(target, '/'))) {
@@ -816,7 +780,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse target for lunStr '%s'"),
target);
- goto cleanup;
+ return NULL;
}
}
@@ -824,11 +788,11 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
if (virSocketAddrNumericFamily(src->hosts[0].name) == AF_INET6) {
if (virAsprintf(&portal, "[%s]:%u",
src->hosts[0].name, src->hosts[0].port) < 0)
- goto cleanup;
+ return NULL;
} else {
if (virAsprintf(&portal, "%s:%u",
src->hosts[0].name, src->hosts[0].port) < 0)
- goto cleanup;
+ return NULL;
}
if (src->auth) {
@@ -846,9 +810,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
"S:password-secret", objalias,
"S:initiator-name",
src->initiator.iqn,
NULL));
- goto cleanup;
-
- cleanup:
return ret;
}
@@ -876,9 +837,8 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src)
"S:export", src->path,
"S:tls-creds", src->tlsAlias,
NULL) < 0)
- goto cleanup;
+ return NULL;
- cleanup:
return ret;
}
@@ -903,17 +863,17 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src)
keysecret = srcPriv->secinfo->s.aes.alias;
/* the auth modes are modelled after our old command line generator */
if (!(authmodes = virJSONValueNewArray()))
- goto cleanup;
+ return NULL;
if (!(mode = virJSONValueNewString("cephx")) ||
virJSONValueArrayAppend(authmodes, mode) < 0)
- goto cleanup;
+ return NULL;
mode = NULL;
if (!(mode = virJSONValueNewString("none")) ||
virJSONValueArrayAppend(authmodes, mode) < 0)
- goto cleanup;
+ return NULL;
mode = NULL;
}
@@ -929,9 +889,8 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src)
"A:auth-client-required", &authmodes,
"S:key-secret", keysecret,
NULL) < 0)
- goto cleanup;
+ return NULL;
- cleanup:
return ret;
}
@@ -959,9 +918,8 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSourcePtr src)
"a:server", &serverprops,
"s:vdi", src->path,
NULL) < 0)
- goto cleanup;
+ return NULL;
- cleanup:
return ret;
}
@@ -992,9 +950,8 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src)
"a:server", &serverprops,
"S:user", username,
NULL) < 0)
- goto cleanup;
+ return NULL;
- cleanup:
return ret;
}
@@ -1167,22 +1124,20 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
if (qemuBlockNodeNameValidate(src->nodestorage) < 0 ||
virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage,
NULL) < 0)
- goto cleanup;
+ return NULL;
if (!legacy) {
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, fileprops) < 0)
- goto cleanup;
+ return NULL;
if (virJSONValueObjectAdd(fileprops,
"b:read-only", src->readonly,
"s:discard", "unmap",
NULL) < 0)
- goto cleanup;
+ return NULL;
}
VIR_STEAL_PTR(ret, fileprops);
-
- cleanup:
return ret;
}
@@ -1266,7 +1221,6 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virStorageSourcePtr
src,
virJSONValuePtr props)
{
VIR_AUTOPTR(virJSONValue) encprops = NULL;
- int ret = -1;
if (qemuBlockStorageSourceGetCryptoProps(src, &encprops) < 0)
return -1;
@@ -1274,12 +1228,9 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virStorageSourcePtr
src,
if (virJSONValueObjectAdd(props,
"s:driver", format,
"A:encrypt", &encprops, NULL) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
@@ -1339,11 +1290,9 @@
qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSourcePtr src)
return NULL;
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
- goto cleanup;
+ return NULL;
VIR_STEAL_PTR(ret, props);
-
- cleanup:
return ret;
}
@@ -1356,7 +1305,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr
src)
virJSONValuePtr ret = NULL;
if (!(props = qemuBlockStorageSourceGetBlockdevFormatCommonProps(src)))
- goto cleanup;
+ return NULL;
switch ((virStorageFileFormat) src->format) {
case VIR_STORAGE_FILE_FAT:
@@ -1364,17 +1313,17 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr
src)
* put a raw layer on top */
case VIR_STORAGE_FILE_RAW:
if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0)
- goto cleanup;
+ return NULL;
break;
case VIR_STORAGE_FILE_QCOW2:
if (qemuBlockStorageSourceGetFormatQcow2Props(src, props) < 0)
- goto cleanup;
+ return NULL;
break;
case VIR_STORAGE_FILE_QCOW:
if (qemuBlockStorageSourceGetFormatQcowGenericProps(src, "qcow", props)
< 0)
- goto cleanup;
+ return NULL;
break;
/* formats without any special parameters */
@@ -1405,22 +1354,19 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr
src)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("mishandled storage format '%s'"),
virStorageFileFormatTypeToString(src->format));
- goto cleanup;
+ return NULL;
case VIR_STORAGE_FILE_LAST:
default:
virReportEnumRangeError(virStorageFileFormat, src->format);
- goto cleanup;
+ return NULL;
}
if (driver &&
virJSONValueObjectAdd(props, "s:driver", driver, NULL) < 0)
- goto cleanup;
+ return NULL;
VIR_STEAL_PTR(ret, props);
-
- cleanup:
-
return ret;
}
@@ -1445,31 +1391,29 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("storage format '%s' does not support backing
store"),
virStorageFileFormatTypeToString(src->format));
- goto cleanup;
+ return NULL;
}
if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src)))
- goto cleanup;
+ return NULL;
if (virJSONValueObjectAppendString(props, "file", src->nodestorage) <
0)
- goto cleanup;
+ return NULL;
if (src->backingStore && backingSupported) {
if (virStorageSourceHasBacking(src)) {
if (virJSONValueObjectAppendString(props, "backing",
src->backingStore->nodeformat) <
0)
- goto cleanup;
+ return NULL;
} else {
/* chain is terminated, indicate that no detection should happen
* in qemu */
if (virJSONValueObjectAppendNull(props, "backing") < 0)
- goto cleanup;
+ return NULL;
}
}
VIR_STEAL_PTR(ret, props);
-
- cleanup:
return ret;
}
@@ -1520,14 +1464,12 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr
src)
if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src)) ||
!(data->storageProps = qemuBlockStorageSourceGetBackendProps(src, false)))
- goto cleanup;
+ return NULL;
data->storageNodeName = src->nodestorage;
data->formatNodeName = src->nodeformat;
VIR_STEAL_PTR(ret, data);
-
- cleanup:
return ret;
}
@@ -1690,13 +1632,12 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions,
const char *format = virStorageFileFormatTypeToString(newsrc->format);
VIR_AUTOFREE(char *) device = NULL;
VIR_AUTOFREE(char *) source = NULL;
- int ret = -1;
if (!(device = qemuAliasDiskDriveFromDisk(disk)))
- goto cleanup;
+ return -1;
if (qemuGetDriveSourceString(newsrc, NULL, &source) < 0)
- goto cleanup;
+ return -1;
if (qemuMonitorJSONTransactionAdd(actions, "blockdev-snapshot-sync",
"s:device", device,
@@ -1704,12 +1645,9 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions,
"s:format", format,
"S:mode", reuse ? "existing" :
NULL,
NULL) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
--
2.20.1