]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: block: Refactor and rename qemuGetDriveSourceProps
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jul 2017 15:37:42 +0000 (17:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Jul 2017 14:05:46 +0000 (16:05 +0200)
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
src/qemu/qemu_block.h
src/qemu/qemu_command.c

index e6b9090151324d8625b2e6c556c937980ec9a7ab..3dbb5586d21bb330b0726905402c9708d97b827c 100644 (file)
@@ -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;
 }
index 3a8950b1385f14569269491662d17b4f8116fe63..17dec799f8e5d9e159065fd372d5798aa0420336 100644 (file)
@@ -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__ */
index ebf24361b678305f52e5160e36fd40bd16f9b5df..b8326124649e0e29a0a627d0c7886aa2500af534 100644 (file)
@@ -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 &&