From 4281362a966d5194bd5ab0045d704107ef08be0a Mon Sep 17 00:00:00 2001 From: Nikolai Barybin Date: Wed, 20 Nov 2024 18:48:49 +0300 Subject: [PATCH] tests: virstoragetest: Add tests for detection of qcow2 'data_file' feature Add two test images showing the use of 'data_file' and 'data_file_raw' (although the latter is not detected by libvirt) so that we can see that the qcow2 metadata parser and backing chain populators work correctly. The example files were created by: qemu-img create -f qcow2 -o data_file=raw,data_file_raw=true,preallocation=off datafile.qcow2 1k qemu-img create -f qcow2 -o data_file=rawpreallocation=off -F qcow2 -b datafile.qcow2 qcow2datafile-datafile.qcow2 Note that 'data_file_raw' is mutually exclusive with backing images. Signed-off-by: Nikolai Barybin Reviewed-by: Peter Krempa Signed-off-by: Peter Krempa --- tests/virstoragetest.c | 30 +++++++++++++++++ .../virstoragetestdata/images/datafile.qcow2 | Bin 0 -> 327680 bytes .../images/qcow2datafile-datafile.qcow2 | Bin 0 -> 196616 bytes tests/virstoragetestdata/out/qcow2-datafile | 20 +++++++++++ .../out/qcow2datafile-qcow2_qcow2-datafile | 31 ++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 tests/virstoragetestdata/images/datafile.qcow2 create mode 100644 tests/virstoragetestdata/images/qcow2datafile-datafile.qcow2 create mode 100644 tests/virstoragetestdata/out/qcow2-datafile create mode 100644 tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 75d04e8030..4ec837eefb 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -203,6 +203,26 @@ testStorageChain(const void *args) NULLSTR(virStorageFileFormatTypeToString(elt->format)), virStorageNetProtocolTypeToString(elt->protocol), NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)); + + if (elt->dataFileStore) { + g_autofree char *strippedPathDataFileRaw = virTestStablePath(elt->dataFileRaw); + g_autofree char *strippedPathDataFile = virTestStablePath(elt->dataFileStore->path); + + virBufferAsprintf(&buf, + "dataFileRaw: %s\n\n\n" + "dataFileStoreSource:\n" + "path: %s\n" + "capacity: %lld\n" + "encryption: %d\n" + "type:%s\n" + "format:%s\n", + strippedPathDataFileRaw, + strippedPathDataFile, + elt->dataFileStore->capacity, + !!elt->dataFileStore->encryption, + NULLSTR(virStorageTypeToString(elt->dataFileStore->type)), + NULLSTR(virStorageFileFormatTypeToString(elt->dataFileStore->format))); + } } virBufferTrim(&buf, "\n"); @@ -464,6 +484,16 @@ mymain(void) testCleanupImages(); + /* qcow2 + datafile + * 1) qcow2 image with data file + * 2) qcow2 -> qcow2 backing image with data file */ + TEST_CHAIN("qcow2-datafile", + abs_srcdir "/virstoragetestdata/images/datafile.qcow2", + VIR_STORAGE_FILE_QCOW2, EXP_PASS); + TEST_CHAIN("qcow2datafile-qcow2_qcow2-datafile", + abs_srcdir "/virstoragetestdata/images/qcow2datafile-datafile.qcow2", + VIR_STORAGE_FILE_QCOW2, EXP_PASS); + /* Test various combinations of qcow2 images with missing 'backing_format' */ TEST_CHAIN("qcow2-qcow2_qcow2-qcow2_qcow2-auto", abs_srcdir "/virstoragetestdata/images/qcow2_qcow2-qcow2_qcow2-auto.qcow2", diff --git a/tests/virstoragetestdata/images/datafile.qcow2 b/tests/virstoragetestdata/images/datafile.qcow2 new file mode 100644 index 0000000000000000000000000000000000000000..32f3acff8600b169311c9a9ea17c2b12f3450e0c GIT binary patch literal 327680 zc-rmIK}y3w6b9f)lLL5!oWUCuL=fBvg6r5!G0-LS=B>-^7&!>=dx(~^U?{EWK1|e_;UaN0000000000 z00000000000000000000000000000000000000000000000000000000000000000 z061wP0ssI20000000000000000000000000000000000000000000000000000000 z0000000000000000001hiGMxf7QPyPGuM0sPpkdM;k9!+sh5Yt z;P~j`Xq~w&mYeU_`SazF`XPjA+4ie=RrX;k*`#jUMbmG)W0dat)K +backingStoreRawFormat: none(0) +capacity: 1024 +encryption: 0 +relPath: +type:file +format:qcow2 +protocol:none +hostname: + +dataFileRaw: raw + + +dataFileStoreSource: +path: ABS_SRCDIR/virstoragetestdata/images/raw +capacity: 0 +encryption: 0 +type:file +format:raw diff --git a/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile new file mode 100644 index 0000000000..cc8bac3138 --- /dev/null +++ b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile @@ -0,0 +1,31 @@ +path:ABS_SRCDIR/virstoragetestdata/images/qcow2datafile-datafile.qcow2 +backingStoreRaw: datafile.qcow2 +backingStoreRawFormat: qcow2(14) +capacity: 1024 +encryption: 0 +relPath: +type:file +format:qcow2 +protocol:none +hostname: + +path:ABS_SRCDIR/virstoragetestdata/images/datafile.qcow2 +backingStoreRaw: +backingStoreRawFormat: none(0) +capacity: 1024 +encryption: 0 +relPath:datafile.qcow2 +type:file +format:qcow2 +protocol:none +hostname: + +dataFileRaw: raw + + +dataFileStoreSource: +path: ABS_SRCDIR/virstoragetestdata/images/raw +capacity: 0 +encryption: 0 +type:file +format:raw -- 2.47.2