mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 23:25:24 +00:00
qemu: block: Use VIR_RETURN_PTR
Demonstrate how VIR_RETURN_PTR is used by refactoring qemu_block.c Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
267f1e6da5
commit
0ef161c88f
@ -234,7 +234,6 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namednodes,
|
|||||||
struct qemuBlockNodeNameGetBackingChainData data;
|
struct qemuBlockNodeNameGetBackingChainData data;
|
||||||
VIR_AUTOPTR(virHashTable) namednodestable = NULL;
|
VIR_AUTOPTR(virHashTable) namednodestable = NULL;
|
||||||
VIR_AUTOPTR(virHashTable) disks = NULL;
|
VIR_AUTOPTR(virHashTable) disks = NULL;
|
||||||
virHashTablePtr ret = NULL;
|
|
||||||
|
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
|
|
||||||
@ -257,8 +256,7 @@ qemuBlockNodeNameGetBackingChain(virJSONValuePtr namednodes,
|
|||||||
&data) < 0)
|
&data) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, disks);
|
VIR_RETURN_PTR(disks);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -375,7 +373,6 @@ virHashTablePtr
|
|||||||
qemuBlockGetNodeData(virJSONValuePtr data)
|
qemuBlockGetNodeData(virJSONValuePtr data)
|
||||||
{
|
{
|
||||||
VIR_AUTOPTR(virHashTable) nodedata = NULL;
|
VIR_AUTOPTR(virHashTable) nodedata = NULL;
|
||||||
virHashTablePtr ret = NULL;
|
|
||||||
|
|
||||||
if (!(nodedata = virHashCreate(50, virJSONValueHashFree)))
|
if (!(nodedata = virHashCreate(50, virJSONValueHashFree)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -384,8 +381,7 @@ qemuBlockGetNodeData(virJSONValuePtr data)
|
|||||||
qemuBlockNamedNodesArrayToHash, nodedata) < 0)
|
qemuBlockNamedNodesArrayToHash, nodedata) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, nodedata);
|
VIR_RETURN_PTR(nodedata);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -414,7 +410,6 @@ virURIPtr
|
|||||||
qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
|
qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
VIR_AUTOPTR(virURI) uri = NULL;
|
VIR_AUTOPTR(virURI) uri = NULL;
|
||||||
virURIPtr ret = NULL;
|
|
||||||
|
|
||||||
if (src->nhosts != 1) {
|
if (src->nhosts != 1) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -455,8 +450,7 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
|
|||||||
if (VIR_STRDUP(uri->server, src->hosts->name) < 0)
|
if (VIR_STRDUP(uri->server, src->hosts->name) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, uri);
|
VIR_RETURN_PTR(uri);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -478,7 +472,6 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
|
|||||||
bool legacy)
|
bool legacy)
|
||||||
{
|
{
|
||||||
VIR_AUTOPTR(virJSONValue) server = NULL;
|
VIR_AUTOPTR(virJSONValue) server = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
const char *transport;
|
const char *transport;
|
||||||
const char *field;
|
const char *field;
|
||||||
VIR_AUTOFREE(char *) port = NULL;
|
VIR_AUTOFREE(char *) port = NULL;
|
||||||
@ -522,8 +515,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, server);
|
VIR_RETURN_PTR(server);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -541,7 +533,6 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
|||||||
{
|
{
|
||||||
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
||||||
VIR_AUTOPTR(virJSONValue) server = NULL;
|
VIR_AUTOPTR(virJSONValue) server = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
virStorageNetHostDefPtr host;
|
virStorageNetHostDefPtr host;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -560,8 +551,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
|
|||||||
server = NULL;
|
server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, servers);
|
VIR_RETURN_PTR(servers);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -610,7 +600,6 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
|
|||||||
{
|
{
|
||||||
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
||||||
VIR_AUTOPTR(virJSONValue) server = NULL;
|
VIR_AUTOPTR(virJSONValue) server = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
virStorageNetHostDefPtr host;
|
virStorageNetHostDefPtr host;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -629,8 +618,7 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
|
|||||||
server = NULL;
|
server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, servers);
|
VIR_RETURN_PTR(servers);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -640,7 +628,6 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
|
|||||||
{
|
{
|
||||||
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
VIR_AUTOPTR(virJSONValue) servers = NULL;
|
||||||
VIR_AUTOPTR(virJSONValue) props = NULL;
|
VIR_AUTOPTR(virJSONValue) props = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
|
|
||||||
if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, legacy)))
|
if (!(servers = qemuBlockStorageSourceBuildHostsJSONSocketAddress(src, legacy)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -662,8 +649,7 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
|
|||||||
virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0)
|
virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, props);
|
VIR_RETURN_PTR(props);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1048,7 +1034,6 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
|||||||
{
|
{
|
||||||
int actualType = virStorageSourceGetActualType(src);
|
int actualType = virStorageSourceGetActualType(src);
|
||||||
VIR_AUTOPTR(virJSONValue) fileprops = NULL;
|
VIR_AUTOPTR(virJSONValue) fileprops = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
|
|
||||||
switch ((virStorageType)actualType) {
|
switch ((virStorageType)actualType) {
|
||||||
case VIR_STORAGE_TYPE_BLOCK:
|
case VIR_STORAGE_TYPE_BLOCK:
|
||||||
@ -1137,8 +1122,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, fileprops);
|
VIR_RETURN_PTR(fileprops);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1266,7 +1250,6 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSourcePtr src)
|
|||||||
int detectZeroesMode = virDomainDiskGetDetectZeroesMode(src->discard,
|
int detectZeroesMode = virDomainDiskGetDetectZeroesMode(src->discard,
|
||||||
src->detect_zeroes);
|
src->detect_zeroes);
|
||||||
VIR_AUTOPTR(virJSONValue) props = NULL;
|
VIR_AUTOPTR(virJSONValue) props = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
|
|
||||||
if (qemuBlockNodeNameValidate(src->nodeformat) < 0)
|
if (qemuBlockNodeNameValidate(src->nodeformat) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1292,8 +1275,7 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSourcePtr src)
|
|||||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
|
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, props);
|
VIR_RETURN_PTR(props);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1302,7 +1284,6 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src)
|
|||||||
{
|
{
|
||||||
const char *driver = NULL;
|
const char *driver = NULL;
|
||||||
VIR_AUTOPTR(virJSONValue) props = NULL;
|
VIR_AUTOPTR(virJSONValue) props = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
|
|
||||||
if (!(props = qemuBlockStorageSourceGetBlockdevFormatCommonProps(src)))
|
if (!(props = qemuBlockStorageSourceGetBlockdevFormatCommonProps(src)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1366,8 +1347,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src)
|
|||||||
virJSONValueObjectAdd(props, "s:driver", driver, NULL) < 0)
|
virJSONValueObjectAdd(props, "s:driver", driver, NULL) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, props);
|
VIR_RETURN_PTR(props);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1385,7 +1365,6 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
|
|||||||
{
|
{
|
||||||
bool backingSupported = src->format >= VIR_STORAGE_FILE_BACKING;
|
bool backingSupported = src->format >= VIR_STORAGE_FILE_BACKING;
|
||||||
VIR_AUTOPTR(virJSONValue) props = NULL;
|
VIR_AUTOPTR(virJSONValue) props = NULL;
|
||||||
virJSONValuePtr ret = NULL;
|
|
||||||
|
|
||||||
if (virStorageSourceHasBacking(src) && !backingSupported) {
|
if (virStorageSourceHasBacking(src) && !backingSupported) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
@ -1413,8 +1392,7 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, props);
|
VIR_RETURN_PTR(props);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1457,7 +1435,6 @@ qemuBlockStorageSourceAttachDataPtr
|
|||||||
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
|
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
|
||||||
{
|
{
|
||||||
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
|
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
|
||||||
qemuBlockStorageSourceAttachDataPtr ret = NULL;
|
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
if (VIR_ALLOC(data) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1469,8 +1446,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
|
|||||||
data->storageNodeName = src->nodestorage;
|
data->storageNodeName = src->nodestorage;
|
||||||
data->formatNodeName = src->nodeformat;
|
data->formatNodeName = src->nodeformat;
|
||||||
|
|
||||||
VIR_STEAL_PTR(ret, data);
|
VIR_RETURN_PTR(data);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user