]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBlockStorageSourceAttachPrepareBlockdev: Prepare for optionally missing format...
authorPeter Krempa <pkrempa@redhat.com>
Fri, 3 Nov 2023 13:26:35 +0000 (14:26 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Nov 2023 09:14:20 +0000 (10:14 +0100)
Restructure the code logic so that the function is prepared for the
possibility that the 'format' blockdev layer may be missing if not
needed.

To achieve this we need to introduce logic that selects which node
(format/slice/storage) becomes the effective node and thus formats the
correct set of arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_block.c

index 7ee565c15f43e0282a16deedd907bb847717ea18..9d8b3012c7028b0323d46c3396ffa21d701d68b4 100644 (file)
@@ -1533,23 +1533,35 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSource *src,
                                             virStorageSource *backingStore)
 {
     g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
+    bool effective = true;
     unsigned int backendpropsflags = 0;
 
     data = g_new0(qemuBlockStorageSourceAttachData, 1);
 
-    if (!(data->formatProps = qemuBlockStorageSourceGetFormatProps(src, backingStore)) ||
-        !(data->storageProps = qemuBlockStorageSourceGetBackendProps(src,
-                                                                     backendpropsflags)))
-        return NULL;
+    if (qemuBlockStorageSourceGetFormatNodename(src)) {
+        if (!(data->formatProps = qemuBlockStorageSourceGetFormatProps(src, backingStore)))
+            return NULL;
 
-    data->storageNodeName = qemuBlockStorageSourceGetStorageNodename(src);
-    data->formatNodeName = qemuBlockStorageSourceGetFormatNodename(src);
+        data->formatNodeName = qemuBlockStorageSourceGetFormatNodename(src);
+
+        effective = false;
+    }
 
     if ((data->storageSliceNodeName = qemuBlockStorageSourceGetSliceNodename(src))) {
-        if (!(data->storageSliceProps = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, false)))
+        if (!(data->storageSliceProps = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, effective)))
             return NULL;
+
+        effective = false;
     }
 
+    if (effective)
+        backendpropsflags = QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE;
+
+    if (!(data->storageProps = qemuBlockStorageSourceGetBackendProps(src, backendpropsflags)))
+        return NULL;
+
+    data->storageNodeName = qemuBlockStorageSourceGetStorageNodename(src);
+
     return g_steal_pointer(&data);
 }