]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage_file_probe: Treat qcow2 images with protocol drivers in backing store field...
authorPeter Krempa <pkrempa@redhat.com>
Thu, 23 Nov 2023 21:37:46 +0000 (22:37 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Nov 2023 09:12:34 +0000 (10:12 +0100)
qemu allows and in some cases uses protocol driver names ('file',
'host_device', 'nbd', ...) in the 'backing file format' field of a qcow
to denote a image where the dummy 'raw' driver was not used on top.

Adapt our backing store parser for such cases. The examples added in
previous patch show the difference in behaviour.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage_file/storage_file_probe.c
tests/virstoragetest.c
tests/virstoragetestdata/out/qcow2-protocol-backing-file
tests/virstoragetestdata/out/qcow2-protocol-backing-nbd [new file with mode: 0644]

index 16298f76c7f4adec5a65153c5320bf0c876ca2f7..243927d50a78c23ed0cfbf7ee95ff5ab498c91d9 100644 (file)
@@ -474,9 +474,15 @@ qcow2GetExtensions(const char *buf,
             memcpy(tmp, buf + offset, len);
             tmp[len] = '\0';
 
+            /* qemu and qemu-img allow using the protocol driver name inside
+             * of the format field in cases when the dummy 'raw' driver should
+             * not be created. Thus libvirt needs to consider anything that
+             * doesn't look like a format driver name to be a protocol driver
+             * directly and thus the image is in fact still considered raw
+             */
             *backingFormat = virStorageFileFormatTypeFromString(tmp);
             if (*backingFormat <= VIR_STORAGE_FILE_NONE)
-                return -1;
+                *backingFormat = VIR_STORAGE_FILE_RAW;
             break;
         }
 
index 53533d5885e6fd42e0cf14226b3199032aed00a3..d07a05d04b92b5bf809f3e7d5bc08ba3daddef47 100644 (file)
@@ -484,7 +484,7 @@ mymain(void)
                VIR_STORAGE_FILE_QCOW2, EXP_PASS);
     TEST_CHAIN("qcow2-protocol-backing-nbd",
                abs_srcdir "/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2",
-               VIR_STORAGE_FILE_QCOW2, EXP_FAIL);
+               VIR_STORAGE_FILE_QCOW2, EXP_PASS);
 
     /* Qcow2 file with missing backing file but specified type */
     TEST_CHAIN("qcow2-qcow2_missing",
index b565bdba772789463ebb129d87fa3f351d14ae85..d9d4c1316c8b097575200bf9ccf141e7bb625d62 100644 (file)
@@ -1,6 +1,6 @@
 path:ABS_SRCDIR/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2
 backingStoreRaw: raw
-backingStoreRawFormat: <null>(-1)
+backingStoreRawFormat: raw(1)
 capacity: 1024
 encryption: 0
 relPath:<null>
diff --git a/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd b/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd
new file mode 100644 (file)
index 0000000..360a496
--- /dev/null
@@ -0,0 +1,21 @@
+path:ABS_SRCDIR/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2
+backingStoreRaw: nbd+tcp://example.org:6000/blah
+backingStoreRawFormat: raw(1)
+capacity: 10485760
+encryption: 0
+relPath:<null>
+type:file
+format:qcow2
+protocol:none
+hostname:<null>
+
+path:blah
+backingStoreRaw: <null>
+backingStoreRawFormat: none(0)
+capacity: 0
+encryption: 0
+relPath:<null>
+type:network
+format:raw
+protocol:nbd
+hostname:example.org