[PATCH 0/7] storage_file_probe: Handle qcow2 images with 'protocol' driver name in 'backing file format' field (part 1 - the fix)

See 6/7 and 7/7 for the rationale. Further patches will be posted to refactor the rest of the parsers which are bitrotten. Peter Krempa (7): storage_file_probe: Remove unused state 'BACKING_STORE_ERROR' virStorageFileProbeGetMetadata: Do not partially skip probing of the image storage_file_probe: Remove BACKING_STORE_OK,BACKING_STORE_INVALID states virstoragetest: Use strings for storage type and format in output data virstoragetest: Format detected/unprocessed backing store format into output files virstoragetest: Add test cases for QCOW2 files with a protocol name as backing file format storage_file_probe: Treat qcow2 images with protocol drivers in backing store field as raw src/storage_file/storage_file_probe.c | 71 ++++++++---------- tests/virstoragetest.c | 19 ++++- .../images/qcow2-protocol-backing-file.qcow2 | Bin 0 -> 196616 bytes .../images/qcow2-protocol-backing-nbd.qcow2 | Bin 0 -> 196616 bytes tests/virstoragetestdata/out/directory-dir | 5 +- tests/virstoragetestdata/out/directory-none | 5 +- tests/virstoragetestdata/out/directory-raw | 5 +- .../out/qcow2-auto_qcow2-qcow2_raw-raw | 5 +- .../out/qcow2-auto_raw-raw-relative | 5 +- .../out/qcow2-protocol-backing-file | 21 ++++++ .../out/qcow2-protocol-backing-nbd | 21 ++++++ .../out/qcow2-qcow2_nbd-raw | 10 ++- .../out/qcow2-qcow2_qcow2-auto | 10 ++- .../out/qcow2-qcow2_qcow2-qcow2_qcow2-auto | 15 ++-- .../out/qcow2-qcow2_qcow2-qcow2_raw-auto | 15 ++-- .../out/qcow2-qcow2_qcow2-qcow2_raw-raw | 15 ++-- .../out/qcow2-qcow2_raw-raw-relative | 10 ++- tests/virstoragetestdata/out/qcow2-symlinks | 15 ++-- tests/virstoragetestdata/out/qed-auto_raw | 5 +- tests/virstoragetestdata/out/qed-qed_raw | 10 ++- tests/virstoragetestdata/out/raw-auto | 5 +- tests/virstoragetestdata/out/raw-raw | 5 +- 22 files changed, 173 insertions(+), 99 deletions(-) create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-file create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-nbd -- 2.42.0

None of the backing store parser functions actually use it. Remove it to avoid confusion. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/storage_file/storage_file_probe.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index 19f77086da..c73f533d2d 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -46,7 +46,6 @@ enum lv_endian { enum { BACKING_STORE_OK, BACKING_STORE_INVALID, - BACKING_STORE_ERROR, }; #define FILE_TYPE_VERSIONS_LAST 3 @@ -963,9 +962,6 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, if (store == BACKING_STORE_INVALID) return 0; - - if (store == BACKING_STORE_ERROR) - return -1; } g_clear_pointer(&meta->features, virBitmapFree); -- 2.42.0

Since we consider the failure of parsing the backing store to be actually success based on the value we return to the caller, we should continue parsing also features and the 'compat' field so that we don't have a partial definition if e.g. the backing store format is not known. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/storage_file/storage_file_probe.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index c73f533d2d..4cf052c03d 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -955,13 +955,9 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, VIR_FREE(meta->backingStoreRaw); if (fileTypeInfo[meta->format].getBackingStore != NULL) { - int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw, - &format, - buf, len); + fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw, + &format, buf, len); meta->backingStoreRawFormat = format; - - if (store == BACKING_STORE_INVALID) - return 0; } g_clear_pointer(&meta->features, virBitmapFree); -- 2.42.0

Replace the return values by 0 because none of the callers care and some of the backing store parser functions return this state also in cases the rest of the code would consider as success. Subsequently the parsers will be refactored and proper error reporting returned. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/storage_file/storage_file_probe.c | 51 ++++++++++++--------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index 4cf052c03d..16298f76c7 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -43,11 +43,6 @@ enum lv_endian { LV_BIG_ENDIAN /* 4321 */ }; -enum { - BACKING_STORE_OK, - BACKING_STORE_INVALID, -}; - #define FILE_TYPE_VERSIONS_LAST 3 struct FileEncryptionInfo { @@ -382,14 +377,14 @@ cowGetBackingStore(char **res, *format = VIR_STORAGE_FILE_AUTO; if (buf_size < 4+4+ COW_FILENAME_MAXLEN) - return BACKING_STORE_INVALID; + return 0; if (buf[4+4] == '\0') { /* cow_header_v2.backing_file[0] */ *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } *res = g_strndup((const char *)buf + 4 + 4, COW_FILENAME_MAXLEN); - return BACKING_STORE_OK; + return 0; } @@ -527,34 +522,34 @@ qcowXGetBackingStore(char **res, *format = VIR_STORAGE_FILE_AUTO; if (buf_size < QCOWX_HDR_BACKING_FILE_OFFSET+8+4) - return BACKING_STORE_INVALID; + return 0; offset = virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSET); if (offset > buf_size) - return BACKING_STORE_INVALID; + return 0; if (offset == 0) { *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } size = virReadBufInt32BE(buf + QCOWX_HDR_BACKING_FILE_SIZE); if (size == 0) { *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } if (size > 1023) - return BACKING_STORE_INVALID; + return 0; if (offset + size > buf_size || offset + size < offset) - return BACKING_STORE_INVALID; + return 0; *res = g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] = '\0'; if (qcow2GetExtensions(buf, buf_size, format) < 0) - return BACKING_STORE_INVALID; + return 0; - return BACKING_STORE_OK; + return 0; } @@ -582,7 +577,7 @@ vmdk4GetBackingStore(char **res, *format = VIR_STORAGE_FILE_AUTO; if (buf_size <= 0x200) - return BACKING_STORE_INVALID; + return 0; len = buf_size - 0x200; if (len >= VIR_STORAGE_MAX_HEADER) @@ -592,21 +587,21 @@ vmdk4GetBackingStore(char **res, start = strstr(desc, prefix); if (start == NULL) { *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } start += strlen(prefix); end = strchr(start, '"'); if (end == NULL) - return BACKING_STORE_INVALID; + return 0; if (end == start) { *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } *end = '\0'; *res = g_strdup(start); - return BACKING_STORE_OK; + return 0; } static int @@ -621,24 +616,24 @@ qedGetBackingStore(char **res, *res = NULL; /* Check if this image has a backing file */ if (buf_size < QED_HDR_FEATURES_OFFSET+8) - return BACKING_STORE_INVALID; + return 0; flags = virReadBufInt64LE(buf + QED_HDR_FEATURES_OFFSET); if (!(flags & QED_F_BACKING_FILE)) { *format = VIR_STORAGE_FILE_NONE; - return BACKING_STORE_OK; + return 0; } /* Parse the backing file */ if (buf_size < QED_HDR_BACKING_FILE_OFFSET+8) - return BACKING_STORE_INVALID; + return 0; offset = virReadBufInt32LE(buf + QED_HDR_BACKING_FILE_OFFSET); if (offset > buf_size) - return BACKING_STORE_INVALID; + return 0; size = virReadBufInt32LE(buf + QED_HDR_BACKING_FILE_SIZE); if (size == 0) - return BACKING_STORE_OK; + return 0; if (offset + size > buf_size || offset + size < offset) - return BACKING_STORE_INVALID; + return 0; *res = g_new0(char, size + 1); memcpy(*res, buf + offset, size); (*res)[size] = '\0'; @@ -648,7 +643,7 @@ qedGetBackingStore(char **res, else *format = VIR_STORAGE_FILE_AUTO_SAFE; - return BACKING_STORE_OK; + return 0; } -- 2.42.0

Make it easier for the humans to read/compare the outputs. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virstoragetest.c | 8 ++++---- tests/virstoragetestdata/out/directory-dir | 4 ++-- tests/virstoragetestdata/out/directory-none | 4 ++-- tests/virstoragetestdata/out/directory-raw | 4 ++-- .../out/qcow2-auto_qcow2-qcow2_raw-raw | 4 ++-- .../out/qcow2-auto_raw-raw-relative | 4 ++-- tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw | 8 ++++---- tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto | 8 ++++---- .../out/qcow2-qcow2_qcow2-qcow2_qcow2-auto | 12 ++++++------ .../out/qcow2-qcow2_qcow2-qcow2_raw-auto | 12 ++++++------ .../out/qcow2-qcow2_qcow2-qcow2_raw-raw | 12 ++++++------ .../out/qcow2-qcow2_raw-raw-relative | 8 ++++---- tests/virstoragetestdata/out/qcow2-symlinks | 12 ++++++------ tests/virstoragetestdata/out/qed-auto_raw | 4 ++-- tests/virstoragetestdata/out/qed-qed_raw | 8 ++++---- tests/virstoragetestdata/out/raw-auto | 4 ++-- tests/virstoragetestdata/out/raw-raw | 4 ++-- 17 files changed, 60 insertions(+), 60 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 11f7abbda6..c7421c55de 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -187,8 +187,8 @@ testStorageChain(const void *args) "capacity: %lld\n" "encryption: %d\n" "relPath:%s\n" - "type:%d\n" - "format:%d\n" + "type:%s\n" + "format:%s\n" "protocol:%s\n" "hostname:%s\n\n", strippedPath, @@ -196,8 +196,8 @@ testStorageChain(const void *args) elt->capacity, !!elt->encryption, strippedRelPath, - elt->type, - elt->format, + NULLSTR(virStorageTypeToString(elt->type)), + NULLSTR(virStorageFileFormatTypeToString(elt->format)), virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)); } diff --git a/tests/virstoragetestdata/out/directory-dir b/tests/virstoragetestdata/out/directory-dir index 65b7b91912..298c6cfb4a 100644 --- a/tests/virstoragetestdata/out/directory-dir +++ b/tests/virstoragetestdata/out/directory-dir @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:3 -format:2 +type:dir +format:dir protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/directory-none b/tests/virstoragetestdata/out/directory-none index 65b7b91912..298c6cfb4a 100644 --- a/tests/virstoragetestdata/out/directory-none +++ b/tests/virstoragetestdata/out/directory-none @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:3 -format:2 +type:dir +format:dir protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/directory-raw b/tests/virstoragetestdata/out/directory-raw index 5def2c4b8b..42589746b8 100644 --- a/tests/virstoragetestdata/out/directory-raw +++ b/tests/virstoragetestdata/out/directory-raw @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:3 -format:1 +type:dir +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw b/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw index 2ea087592e..7c299542a4 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative b/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative index f9afc138f0..9f8246900d 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw b/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw index 08a93b9f32..761e65b234 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw @@ -3,8 +3,8 @@ backingStoreRaw: nbd+tcp://example.org:6000/blah capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,7 +13,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:4 -format:1 +type:network +format:raw protocol:nbd hostname:example.org diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto index e23c43f328..57f2f51108 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto @@ -3,8 +3,8 @@ backingStoreRaw: qcow2 capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,7 +13,7 @@ backingStoreRaw: <null> capacity: 1024 encryption: 0 relPath:qcow2 -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto index 17f53f3ed0..99d3c4c273 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto @@ -3,8 +3,8 @@ backingStoreRaw: qcow2_qcow2-auto.qcow2 capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,8 +13,8 @@ backingStoreRaw: qcow2 capacity: 1024 encryption: 0 relPath:qcow2_qcow2-auto.qcow2 -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -23,7 +23,7 @@ backingStoreRaw: <null> capacity: 1024 encryption: 0 relPath:qcow2 -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto index 1be5a82cc9..9734cf22b9 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto @@ -3,8 +3,8 @@ backingStoreRaw: qcow2_raw-auto.qcow2 capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,8 +13,8 @@ backingStoreRaw: raw capacity: 1024 encryption: 0 relPath:qcow2_raw-auto.qcow2 -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -23,7 +23,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:raw -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw index 5f93fe746b..0c90e9858d 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw @@ -3,8 +3,8 @@ backingStoreRaw: ABS_BUILDDIR/virstoragedata/qcow2 capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,8 +13,8 @@ backingStoreRaw: ABS_BUILDDIR/virstoragedata/raw capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -23,7 +23,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative b/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative index 6e3f7ab339..552353e980 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative @@ -3,8 +3,8 @@ backingStoreRaw: raw capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,7 +13,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:raw -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qcow2-symlinks b/tests/virstoragetestdata/out/qcow2-symlinks index 34c3a37c2e..8e531e4cf8 100644 --- a/tests/virstoragetestdata/out/qcow2-symlinks +++ b/tests/virstoragetestdata/out/qcow2-symlinks @@ -3,8 +3,8 @@ backingStoreRaw: ../sub/link1 capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -13,8 +13,8 @@ backingStoreRaw: ../raw capacity: 1024 encryption: 0 relPath:../sub/link1 -type:1 -format:14 +type:file +format:qcow2 protocol:none hostname:<null> @@ -23,7 +23,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:../raw -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qed-auto_raw b/tests/virstoragetestdata/out/qed-auto_raw index 292a8fa7fb..a75ef8189b 100644 --- a/tests/virstoragetestdata/out/qed-auto_raw +++ b/tests/virstoragetestdata/out/qed-auto_raw @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/qed-qed_raw b/tests/virstoragetestdata/out/qed-qed_raw index 043ec4240b..18a5091e6f 100644 --- a/tests/virstoragetestdata/out/qed-qed_raw +++ b/tests/virstoragetestdata/out/qed-qed_raw @@ -3,8 +3,8 @@ backingStoreRaw: raw capacity: 1024 encryption: 0 relPath:<null> -type:1 -format:15 +type:file +format:qed protocol:none hostname:<null> @@ -13,7 +13,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:raw -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/raw-auto b/tests/virstoragetestdata/out/raw-auto index d98b6e8bf5..90a9dfceda 100644 --- a/tests/virstoragetestdata/out/raw-auto +++ b/tests/virstoragetestdata/out/raw-auto @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> diff --git a/tests/virstoragetestdata/out/raw-raw b/tests/virstoragetestdata/out/raw-raw index d98b6e8bf5..90a9dfceda 100644 --- a/tests/virstoragetestdata/out/raw-raw +++ b/tests/virstoragetestdata/out/raw-raw @@ -3,7 +3,7 @@ backingStoreRaw: <null> capacity: 0 encryption: 0 relPath:<null> -type:1 -format:1 +type:file +format:raw protocol:none hostname:<null> -- 2.42.0

Compare also the detected format of the backing file ('backingStoreRawFormat' field) into the outptu data for comparison with others. Since the ToString function can't convert VIR_STORAGE_FILE_AUTO use also the numeric value. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virstoragetest.c | 3 +++ tests/virstoragetestdata/out/directory-dir | 1 + tests/virstoragetestdata/out/directory-none | 1 + tests/virstoragetestdata/out/directory-raw | 1 + tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw | 1 + tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative | 1 + tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw | 2 ++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto | 2 ++ .../virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative | 2 ++ tests/virstoragetestdata/out/qcow2-symlinks | 3 +++ tests/virstoragetestdata/out/qed-auto_raw | 1 + tests/virstoragetestdata/out/qed-qed_raw | 2 ++ tests/virstoragetestdata/out/raw-auto | 1 + tests/virstoragetestdata/out/raw-raw | 1 + 17 files changed, 31 insertions(+) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index c7421c55de..c28a23e332 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -184,6 +184,7 @@ testStorageChain(const void *args) virBufferAsprintf(&buf, "path:%s\n" "backingStoreRaw: %s\n" + "backingStoreRawFormat: %s(%d)\n" "capacity: %lld\n" "encryption: %d\n" "relPath:%s\n" @@ -193,6 +194,8 @@ testStorageChain(const void *args) "hostname:%s\n\n", strippedPath, strippedBackingStoreRaw, + NULLSTR(virStorageFileFormatTypeToString(elt->backingStoreRawFormat)), + elt->backingStoreRawFormat, elt->capacity, !!elt->encryption, strippedRelPath, diff --git a/tests/virstoragetestdata/out/directory-dir b/tests/virstoragetestdata/out/directory-dir index 298c6cfb4a..c6a2fa3673 100644 --- a/tests/virstoragetestdata/out/directory-dir +++ b/tests/virstoragetestdata/out/directory-dir @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/directory-none b/tests/virstoragetestdata/out/directory-none index 298c6cfb4a..c6a2fa3673 100644 --- a/tests/virstoragetestdata/out/directory-none +++ b/tests/virstoragetestdata/out/directory-none @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/directory-raw b/tests/virstoragetestdata/out/directory-raw index 42589746b8..6e190c97f4 100644 --- a/tests/virstoragetestdata/out/directory-raw +++ b/tests/virstoragetestdata/out/directory-raw @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw b/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw index 7c299542a4..0540be0c09 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw @@ -1,5 +1,6 @@ path:ABS_BUILDDIR/virstoragedata/wrap backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative b/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative index 9f8246900d..e145cca417 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-raw-relative.qcow2 backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw b/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw index 761e65b234..0c2bb0ddc4 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_nbd-raw.qcow2 backingStoreRaw: nbd+tcp://example.org:6000/blah +backingStoreRawFormat: raw(1) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:blah backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto index 57f2f51108..58f1dd6d9e 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-auto.qcow2 backingStoreRaw: qcow2 +backingStoreRawFormat: <null>(-1) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/qcow2 backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 1024 encryption: 0 relPath:qcow2 diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto index 99d3c4c273..81263c4bc0 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-qcow2_qcow2-auto.qcow2 backingStoreRaw: qcow2_qcow2-auto.qcow2 +backingStoreRawFormat: qcow2(14) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-auto.qcow2 backingStoreRaw: qcow2 +backingStoreRawFormat: <null>(-1) capacity: 1024 encryption: 0 relPath:qcow2_qcow2-auto.qcow2 @@ -20,6 +22,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/qcow2 backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 1024 encryption: 0 relPath:qcow2 diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto index 9734cf22b9..cbb8d6a33f 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-qcow2_raw-auto.qcow2 backingStoreRaw: qcow2_raw-auto.qcow2 +backingStoreRawFormat: qcow2(14) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-auto.qcow2 backingStoreRaw: raw +backingStoreRawFormat: <null>(-1) capacity: 1024 encryption: 0 relPath:qcow2_raw-auto.qcow2 @@ -20,6 +22,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw index 0c90e9858d..de11029922 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw @@ -1,5 +1,6 @@ path:ABS_BUILDDIR/virstoragedata/wrap backingStoreRaw: ABS_BUILDDIR/virstoragedata/qcow2 +backingStoreRawFormat: qcow2(14) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_BUILDDIR/virstoragedata/qcow2 backingStoreRaw: ABS_BUILDDIR/virstoragedata/raw +backingStoreRawFormat: raw(1) capacity: 1024 encryption: 0 relPath:<null> @@ -20,6 +22,7 @@ hostname:<null> path:ABS_BUILDDIR/virstoragedata/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative b/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative index 552353e980..b4bfd432ad 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-raw-relative.qcow2 backingStoreRaw: raw +backingStoreRawFormat: raw(1) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/qcow2-symlinks b/tests/virstoragetestdata/out/qcow2-symlinks index 8e531e4cf8..f053f95fd7 100644 --- a/tests/virstoragetestdata/out/qcow2-symlinks +++ b/tests/virstoragetestdata/out/qcow2-symlinks @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/sub/link2 backingStoreRaw: ../sub/link1 +backingStoreRawFormat: qcow2(14) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/sub/../sub/link1 backingStoreRaw: ../raw +backingStoreRawFormat: raw(1) capacity: 1024 encryption: 0 relPath:../sub/link1 @@ -20,6 +22,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/sub/../sub/../raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:../raw diff --git a/tests/virstoragetestdata/out/qed-auto_raw b/tests/virstoragetestdata/out/qed-auto_raw index a75ef8189b..260c3fbc79 100644 --- a/tests/virstoragetestdata/out/qed-auto_raw +++ b/tests/virstoragetestdata/out/qed-auto_raw @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qed_raw-raw-relative backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/qed-qed_raw b/tests/virstoragetestdata/out/qed-qed_raw index 18a5091e6f..a13d407a5f 100644 --- a/tests/virstoragetestdata/out/qed-qed_raw +++ b/tests/virstoragetestdata/out/qed-qed_raw @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/qed_raw-raw-relative backingStoreRaw: raw +backingStoreRawFormat: raw(1) capacity: 1024 encryption: 0 relPath:<null> @@ -10,6 +11,7 @@ hostname:<null> path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/raw-auto b/tests/virstoragetestdata/out/raw-auto index 90a9dfceda..70ec22f309 100644 --- a/tests/virstoragetestdata/out/raw-auto +++ b/tests/virstoragetestdata/out/raw-auto @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> diff --git a/tests/virstoragetestdata/out/raw-raw b/tests/virstoragetestdata/out/raw-raw index 90a9dfceda..70ec22f309 100644 --- a/tests/virstoragetestdata/out/raw-raw +++ b/tests/virstoragetestdata/out/raw-raw @@ -1,5 +1,6 @@ path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: <null> +backingStoreRawFormat: none(0) capacity: 0 encryption: 0 relPath:<null> -- 2.42.0

On a Friday in 2023, Peter Krempa wrote:
Compare also the detected format of the backing file ('backingStoreRawFormat' field) into the outptu data for comparison with
*output Jano
others. Since the ToString function can't convert VIR_STORAGE_FILE_AUTO use also the numeric value.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virstoragetest.c | 3 +++ tests/virstoragetestdata/out/directory-dir | 1 + tests/virstoragetestdata/out/directory-none | 1 + tests/virstoragetestdata/out/directory-raw | 1 + tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw | 1 + tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative | 1 + tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw | 2 ++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto | 2 ++ .../virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw | 3 +++ tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative | 2 ++ tests/virstoragetestdata/out/qcow2-symlinks | 3 +++ tests/virstoragetestdata/out/qed-auto_raw | 1 + tests/virstoragetestdata/out/qed-qed_raw | 2 ++ tests/virstoragetestdata/out/raw-auto | 1 + tests/virstoragetestdata/out/raw-raw | 1 + 17 files changed, 31 insertions(+)

QEMU allows and in cases where you omit the not-strictly-needed 'raw' driver on top of raw images automatically uses the protocol name inside of the 'backing file format' field of the qcow2 image. Libvirt expects only format names in that field. Add example images showing this scenario, which will be fixed later. The qcow2 image files in this commit were formatted as: qemu-img create -f qcow2 -F nbd -b nbd+tcp://example.org:6000/blah -u qcow2-protocol-backing-nbd.qcow2 10M and qemu-img create -f qcow2 -F file -b raw qcow2-protocol-backing-file.qcow2 thus using 'nbd' and 'file' as backing format respectively. (note that '-b raw' refers to the file in the example image folder) To satisfy the test, note that the NBD image is also rejected as we can't probe it, thus such configuration would not work. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virstoragetest.c | 8 +++++++ .../images/qcow2-protocol-backing-file.qcow2 | Bin 0 -> 196616 bytes .../images/qcow2-protocol-backing-nbd.qcow2 | Bin 0 -> 196616 bytes .../out/qcow2-protocol-backing-file | 21 ++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-file diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index c28a23e332..53533d5885 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -478,6 +478,14 @@ mymain(void) abs_srcdir "/virstoragetestdata/images/qcow2_qcow2-auto.qcow2", VIR_STORAGE_FILE_QCOW2, EXP_PASS); + /* QCOW2 with protocol recorded inside the 'backing file format field */ + TEST_CHAIN("qcow2-protocol-backing-file", + abs_srcdir "/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2", + 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); + /* Qcow2 file with missing backing file but specified type */ TEST_CHAIN("qcow2-qcow2_missing", abs_srcdir "/virstoragetestdata/images/qcow2_qcow2-missing.qcow2", diff --git a/tests/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 b/tests/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 new file mode 100644 index 0000000000000000000000000000000000000000..b3fe320f0f521820f2c4a614fed4cea18fdca55c GIT binary patch literal 196616 zcmeIuJx;?g6aZi+?EyGKW=0Nygv7$c9GX-_YLh4pf-rGDj=?FASaABIib`$S`#DN% zKR?@f-^1<QPY7WW-`LWt_!-AzAKP@(g^;WV+pO(u6We7R@5e*h-SXFP{Tav8d9^6V z*z@H3F&_UBLQ!@7kUdrX7(U;US<`hdZU5gLY5CTdU7atoBJcBTcmL6gCbMSQcI9eS zHFeex?fP$zX2*)g^XsB4viqB?toyDiS0~bwu*lzstSjfU=B4gWrLIp&LzG$O?b*cb zooUkLui2lPPyEe(Del@&j0g}QK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oShDf%Ni9Rxtqr1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72pk9`Ve=e>O$iVnK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ;4%e% E0pRvEvj6}9 literal 0 HcmV?d00001 diff --git a/tests/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 b/tests/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 new file mode 100644 index 0000000000000000000000000000000000000000..0ae422d8f550cc6bacf3d4d757110177ce457865 GIT binary patch literal 196616 zcmeIv!EVzq00v+u-2?Cj<O~w6IB?hlOhV$qiF4X`EK-_8t|wMbJPOalWAGG6Tu8f) zi35RMt1nS($Np`{U*2E6{TV`7OwV+c&!*z}^c?CCz8=d%Q5;*R)amWM?|0;{jf-hy zd>H+{fAMW<FZy+J?7CU}_%JR1C4{C;d0(yD{1Bb5i_MVI?U?^}Mj7vNOnu!|O`YrN zy6xiZ28+$G9aG%x+M%!Vew<H-aB*0_Z(>uudtJpor#9|pHYh?@f8JLqUT=omKF>vu ztCV4q+1BGfgQq>qBGsR&Kh8Y!HIGBne|ecV<K=Q0@9OQ?#aBc6c==|vS}oUIee)R9 zB0zuu0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK;S$D%JV#yQxPCQfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ zz!L<DaDP8xiYNgB1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ ofB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72%N9LFOzFO8UO$Q literal 0 HcmV?d00001 diff --git a/tests/virstoragetestdata/out/qcow2-protocol-backing-file b/tests/virstoragetestdata/out/qcow2-protocol-backing-file new file mode 100644 index 0000000000..b565bdba77 --- /dev/null +++ b/tests/virstoragetestdata/out/qcow2-protocol-backing-file @@ -0,0 +1,21 @@ +path:ABS_SRCDIR/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 +backingStoreRaw: raw +backingStoreRawFormat: <null>(-1) +capacity: 1024 +encryption: 0 +relPath:<null> +type:file +format:qcow2 +protocol:none +hostname:<null> + +path:ABS_SRCDIR/virstoragetestdata/images/raw +backingStoreRaw: <null> +backingStoreRawFormat: none(0) +capacity: 0 +encryption: 0 +relPath:raw +type:file +format:raw +protocol:none +hostname:<null> -- 2.42.0

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> --- src/storage_file/storage_file_probe.c | 8 ++++++- tests/virstoragetest.c | 2 +- .../out/qcow2-protocol-backing-file | 2 +- .../out/qcow2-protocol-backing-nbd | 21 +++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-nbd diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index 16298f76c7..243927d50a 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -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; } diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 53533d5885..d07a05d04b 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -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", diff --git a/tests/virstoragetestdata/out/qcow2-protocol-backing-file b/tests/virstoragetestdata/out/qcow2-protocol-backing-file index b565bdba77..d9d4c1316c 100644 --- a/tests/virstoragetestdata/out/qcow2-protocol-backing-file +++ b/tests/virstoragetestdata/out/qcow2-protocol-backing-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 index 0000000000..360a496ab0 --- /dev/null +++ b/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd @@ -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 -- 2.42.0

On a Friday in 2023, Peter Krempa wrote:
See 6/7 and 7/7 for the rationale. Further patches will be posted to refactor the rest of the parsers which are bitrotten.
Peter Krempa (7): storage_file_probe: Remove unused state 'BACKING_STORE_ERROR' virStorageFileProbeGetMetadata: Do not partially skip probing of the image storage_file_probe: Remove BACKING_STORE_OK,BACKING_STORE_INVALID states virstoragetest: Use strings for storage type and format in output data virstoragetest: Format detected/unprocessed backing store format into output files virstoragetest: Add test cases for QCOW2 files with a protocol name as backing file format storage_file_probe: Treat qcow2 images with protocol drivers in backing store field as raw
src/storage_file/storage_file_probe.c | 71 ++++++++---------- tests/virstoragetest.c | 19 ++++- .../images/qcow2-protocol-backing-file.qcow2 | Bin 0 -> 196616 bytes [...] tests/virstoragetestdata/out/raw-raw | 5 +- 22 files changed, 173 insertions(+), 99 deletions(-) create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 create mode 100644 tests/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-file create mode 100644 tests/virstoragetestdata/out/qcow2-protocol-backing-nbd
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Peter Krempa