提交 c9cec6a8 编写于 作者: P Peter Krempa

qemu: block: Remove unneeded cleanup jumps

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