Rename it to qemuBlockStorageSourceGetBackendProps and refactor it to
return the JSON object instead of filling a pointer since now it's
always expected to return data.
---
src/qemu/qemu_block.c | 49 +++++++++++++++++++++++++++++++++++--------------
src/qemu/qemu_block.h | 6 ++----
src/qemu/qemu_command.c | 2 +-
3 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index e6b909015..3dbb5586d 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -519,14 +519,19 @@ qemuBuildGlusterDriveJSON(virStorageSourcePtr src)
}
-int
-qemuGetDriveSourceProps(virStorageSourcePtr src,
- virJSONValuePtr *props)
+/**
+ * qemuBlockStorageSourceGetBackendProps:
+ * @src: disk source
+ *
+ * Creates a JSON object describing the underlying storage or protocol of a
+ * storage source. Returns NULL on error and reports an appropriate error message.
+ */
+virJSONValuePtr
+qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src)
{
int actualType = virStorageSourceGetActualType(src);
virJSONValuePtr fileprops = NULL;
-
- *props = NULL;
+ virJSONValuePtr ret = NULL;
switch ((virStorageType) actualType) {
case VIR_STORAGE_TYPE_BLOCK:
@@ -538,19 +543,35 @@ qemuGetDriveSourceProps(virStorageSourcePtr src,
break;
case VIR_STORAGE_TYPE_NETWORK:
- if (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
- src->nhosts > 1) {
+ switch ((virStorageNetProtocol) src->protocol) {
+ case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
if (!(fileprops = qemuBuildGlusterDriveJSON(src)))
- return -1;
+ goto cleanup;
+ break;
+
+ case VIR_STORAGE_NET_PROTOCOL_NBD:
+ case VIR_STORAGE_NET_PROTOCOL_RBD:
+ case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
+ case VIR_STORAGE_NET_PROTOCOL_ISCSI:
+ case VIR_STORAGE_NET_PROTOCOL_HTTP:
+ case VIR_STORAGE_NET_PROTOCOL_HTTPS:
+ case VIR_STORAGE_NET_PROTOCOL_FTP:
+ case VIR_STORAGE_NET_PROTOCOL_FTPS:
+ case VIR_STORAGE_NET_PROTOCOL_TFTP:
+ case VIR_STORAGE_NET_PROTOCOL_SSH:
+ case VIR_STORAGE_NET_PROTOCOL_NONE:
+ case VIR_STORAGE_NET_PROTOCOL_LAST:
+ break;
}
break;
}
- if (fileprops &&
- virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0) {
- virJSONValueFree(fileprops);
- return -1;
- }
+ if (virJSONValueObjectCreate(&ret, "a:file", fileprops, NULL) < 0)
+ goto cleanup;
- return 0;
+ fileprops = NULL;
+
+ cleanup:
+ virJSONValueFree(fileprops);
+ return ret;
}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 3a8950b13..17dec799f 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -53,9 +53,7 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
virHashTablePtr
qemuBlockGetNodeData(virJSONValuePtr data);
-
-int
-qemuGetDriveSourceProps(virStorageSourcePtr src,
- virJSONValuePtr *props);
+virJSONValuePtr
+qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src);
#endif /* __QEMU_BLOCK_H__ */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 963224335..c20dd64dc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1348,7 +1348,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
int ret = -1;
if (qemuDiskSourceNeedsProps(disk->src) &&
- qemuGetDriveSourceProps(disk->src, &srcprops) < 0)
+ !(srcprops = qemuBlockStorageSourceGetBackendProps(disk->src)))
goto cleanup;
if (!srcprops &&
--
2.12.2