1f3d07ce8SThomas Huth#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 376b90e23SKevin Wolf# 476b90e23SKevin Wolf# Test qcow2 with external data files 576b90e23SKevin Wolf# 676b90e23SKevin Wolf# Copyright (C) 2019 Red Hat, Inc. 776b90e23SKevin Wolf# 876b90e23SKevin Wolf# This program is free software; you can redistribute it and/or modify 976b90e23SKevin Wolf# it under the terms of the GNU General Public License as published by 1076b90e23SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1176b90e23SKevin Wolf# (at your option) any later version. 1276b90e23SKevin Wolf# 1376b90e23SKevin Wolf# This program is distributed in the hope that it will be useful, 1476b90e23SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1576b90e23SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1676b90e23SKevin Wolf# GNU General Public License for more details. 1776b90e23SKevin Wolf# 1876b90e23SKevin Wolf# You should have received a copy of the GNU General Public License 1976b90e23SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 2076b90e23SKevin Wolf# 2176b90e23SKevin Wolf 2276b90e23SKevin Wolf# creator 2376b90e23SKevin Wolfowner=kwolf@redhat.com 2476b90e23SKevin Wolf 2576b90e23SKevin Wolfseq=$(basename $0) 2676b90e23SKevin Wolfecho "QA output created by $seq" 2776b90e23SKevin Wolf 2876b90e23SKevin Wolfstatus=1 # failure is the default! 2976b90e23SKevin Wolf 3076b90e23SKevin Wolf_cleanup() 3176b90e23SKevin Wolf{ 3276b90e23SKevin Wolf _cleanup_test_img 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.data" 34f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.src" 3576b90e23SKevin Wolf} 3676b90e23SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3776b90e23SKevin Wolf 3876b90e23SKevin Wolf# get standard environment, filters and checks 3976b90e23SKevin Wolf. ./common.rc 4076b90e23SKevin Wolf. ./common.filter 412ec7e8a9SMax Reitz. ./common.qemu 4276b90e23SKevin Wolf 4376b90e23SKevin Wolf_supported_fmt qcow2 4476b90e23SKevin Wolf_supported_proto file 4576b90e23SKevin Wolf_supported_os Linux 463be2024aSMax Reitz# External data files do not work with compat=0.10, and because we use 473be2024aSMax Reitz# our own external data file, we cannot let the user specify one 483be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' data_file 4976b90e23SKevin Wolf 5076b90e23SKevin Wolfecho 5176b90e23SKevin Wolfecho "=== Create and open image with external data file ===" 5276b90e23SKevin Wolfecho 5376b90e23SKevin Wolf 5476b90e23SKevin Wolfecho "With data file name in the image:" 55407fb56aSMax Reitz_make_test_img -o "data_file=$TEST_IMG.data" 64M 5676b90e23SKevin Wolf_check_test_img 5776b90e23SKevin Wolf 5876b90e23SKevin Wolf$QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 5976b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 6076b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 6176b90e23SKevin Wolf 6276b90e23SKevin Wolfecho 6376b90e23SKevin Wolfecho "Data file required, but without data file name in the image:" 6476b90e23SKevin Wolf$QEMU_IMG amend -odata_file= $TEST_IMG 6576b90e23SKevin Wolf 6676b90e23SKevin Wolf$QEMU_IO -c "open $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 6776b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 6876b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 6976b90e23SKevin Wolf 7076b90e23SKevin Wolfecho 7176b90e23SKevin Wolfecho "Setting data-file for an image with internal data:" 7276b90e23SKevin Wolf_make_test_img 64M 7376b90e23SKevin Wolf 7476b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=$TEST_IMG.data $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 7576b90e23SKevin Wolf$QEMU_IO -c "open -odata-file.filename=inexistent $TEST_IMG" -c "read -P 0 0 64k" 2>&1 | _filter_qemu_io | _filter_testdir 7676b90e23SKevin Wolf 7776b90e23SKevin Wolfecho 7876b90e23SKevin Wolfecho "=== Conflicting features ===" 7976b90e23SKevin Wolfecho 8076b90e23SKevin Wolf 8176b90e23SKevin Wolfecho "Convert to compressed target with data file:" 8276b90e23SKevin WolfTEST_IMG="$TEST_IMG.src" _make_test_img 64M 8376b90e23SKevin Wolf 8476b90e23SKevin Wolf$QEMU_IO -c 'write -P 0x11 0 1M' \ 8576b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG.src" | 8676b90e23SKevin Wolf _filter_qemu_io 8776b90e23SKevin Wolf 8876b90e23SKevin Wolf$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c -odata_file="$TEST_IMG.data" \ 8976b90e23SKevin Wolf "$TEST_IMG.src" "$TEST_IMG" 9076b90e23SKevin Wolf 9176b90e23SKevin Wolfecho 9276b90e23SKevin Wolfecho "Convert uncompressed, then write compressed data manually:" 9376b90e23SKevin Wolf$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -odata_file="$TEST_IMG.data" \ 9476b90e23SKevin Wolf "$TEST_IMG.src" "$TEST_IMG" 9576b90e23SKevin Wolf$QEMU_IMG compare "$TEST_IMG.src" "$TEST_IMG" 9676b90e23SKevin Wolf 9776b90e23SKevin Wolf$QEMU_IO -c 'write -c -P 0x22 0 1M' \ 9876b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG" | 9976b90e23SKevin Wolf _filter_qemu_io 10076b90e23SKevin Wolf_check_test_img 10176b90e23SKevin Wolf 10276b90e23SKevin Wolfecho 10376b90e23SKevin Wolfecho "Take an internal snapshot:" 10476b90e23SKevin Wolf 10576b90e23SKevin Wolf$QEMU_IMG snapshot -c test "$TEST_IMG" 10676b90e23SKevin Wolf_check_test_img 10776b90e23SKevin Wolf 10876b90e23SKevin Wolfecho 10976b90e23SKevin Wolfecho "=== Standalone image with external data file (efficient) ===" 11076b90e23SKevin Wolfecho 11176b90e23SKevin Wolf 112407fb56aSMax Reitz_make_test_img -o "data_file=$TEST_IMG.data" 64M 11376b90e23SKevin Wolf 11476b90e23SKevin Wolfecho -n "qcow2 file size before I/O: " 11576b90e23SKevin Wolfdu -b $TEST_IMG | cut -f1 11676b90e23SKevin Wolf 11776b90e23SKevin Wolf# Create image with the following layout 11876b90e23SKevin Wolf# 0-1 MB: Unallocated 11976b90e23SKevin Wolf# 1-2 MB: Written (pattern 0x11) 12076b90e23SKevin Wolf# 2-3 MB: Discarded 12176b90e23SKevin Wolf# 3-4 MB: Zero write over discarded space 12276b90e23SKevin Wolf# 4-5 MB: Zero write over written space 12376b90e23SKevin Wolf# 5-6 MB: Zero write over unallocated space 12476b90e23SKevin Wolf 12576b90e23SKevin Wolfecho 12676b90e23SKevin Wolf$QEMU_IO -c 'write -P 0x11 1M 4M' \ 12776b90e23SKevin Wolf -c 'discard 2M 2M' \ 12876b90e23SKevin Wolf -c 'write -z 3M 3M' \ 12976b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG" | 13076b90e23SKevin Wolf _filter_qemu_io 13176b90e23SKevin Wolf_check_test_img 13276b90e23SKevin Wolf 13376b90e23SKevin Wolfecho 13476b90e23SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" 13576b90e23SKevin Wolf 13676b90e23SKevin Wolfecho 13776b90e23SKevin Wolf$QEMU_IO -c 'read -P 0 0 1M' \ 13876b90e23SKevin Wolf -c 'read -P 0x11 1M 1M' \ 13976b90e23SKevin Wolf -c 'read -P 0 2M 4M' \ 14076b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG" | 14176b90e23SKevin Wolf _filter_qemu_io 14276b90e23SKevin Wolf 14376b90e23SKevin Wolf# Zero clusters are only marked as such in the qcow2 metadata, but contain 14476b90e23SKevin Wolf# stale data in the external data file 14576b90e23SKevin Wolfecho 14676b90e23SKevin Wolf$QEMU_IO -c 'read -P 0 0 1M' \ 14776b90e23SKevin Wolf -c 'read -P 0x11 1M 1M' \ 14876b90e23SKevin Wolf -c 'read -P 0x11 4M 1M' \ 14976b90e23SKevin Wolf -c 'read -P 0 5M 1M' \ 15076b90e23SKevin Wolf -f raw "$TEST_IMG.data" | 15176b90e23SKevin Wolf _filter_qemu_io 15276b90e23SKevin Wolf 15376b90e23SKevin Wolf 15476b90e23SKevin Wolfecho -n "qcow2 file size after I/O: " 15576b90e23SKevin Wolfdu -b $TEST_IMG | cut -f1 15676b90e23SKevin Wolf 15776b90e23SKevin Wolfecho 15876b90e23SKevin Wolfecho "=== Standalone image with external data file (valid raw) ===" 15976b90e23SKevin Wolfecho 16076b90e23SKevin Wolf 161407fb56aSMax Reitz_make_test_img -o "data_file=$TEST_IMG.data,data_file_raw=on" 64M 16276b90e23SKevin Wolf 16376b90e23SKevin Wolfecho -n "qcow2 file size before I/O: " 16476b90e23SKevin Wolfdu -b $TEST_IMG | cut -f1 16576b90e23SKevin Wolf 16676b90e23SKevin Wolfecho 16776b90e23SKevin Wolf$QEMU_IO -c 'write -P 0x11 1M 4M' \ 16876b90e23SKevin Wolf -c 'discard 2M 2M' \ 16976b90e23SKevin Wolf -c 'write -z 3M 3M' \ 17076b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG" | 17176b90e23SKevin Wolf _filter_qemu_io 17276b90e23SKevin Wolf_check_test_img 17376b90e23SKevin Wolf 17476b90e23SKevin Wolfecho 17576b90e23SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" 17676b90e23SKevin Wolf 17776b90e23SKevin Wolfecho 17876b90e23SKevin Wolf$QEMU_IO -c 'read -P 0 0 1M' \ 17976b90e23SKevin Wolf -c 'read -P 0x11 1M 1M' \ 18076b90e23SKevin Wolf -c 'read -P 0 2M 4M' \ 18176b90e23SKevin Wolf -f $IMGFMT "$TEST_IMG" | 18276b90e23SKevin Wolf _filter_qemu_io 18376b90e23SKevin Wolf 1843fb61087SPaolo Bonzini# Discarded clusters are only marked as such in the qcow2 metadata, but 1853fb61087SPaolo Bonzini# they can contain stale data in the external data file. Instead, zero 1863fb61087SPaolo Bonzini# clusters must be zeroed in the external data file too. 18776b90e23SKevin Wolfecho 1883fb61087SPaolo Bonzini$QEMU_IO -c 'read -P 0 0 1M' \ 1893fb61087SPaolo Bonzini -c 'read -P 0x11 1M 1M' \ 1903fb61087SPaolo Bonzini -c 'read -P 0 3M 3M' \ 1913fb61087SPaolo Bonzini -f raw "$TEST_IMG".data | 1923fb61087SPaolo Bonzini _filter_qemu_io 19376b90e23SKevin Wolf 19476b90e23SKevin Wolfecho -n "qcow2 file size after I/O: " 19576b90e23SKevin Wolfdu -b $TEST_IMG | cut -f1 19676b90e23SKevin Wolf 19776b90e23SKevin Wolfecho 19876b90e23SKevin Wolfecho "=== bdrv_co_block_status test for file and offset=0 ===" 19976b90e23SKevin Wolfecho 20076b90e23SKevin Wolf 201407fb56aSMax Reitz_make_test_img -o "data_file=$TEST_IMG.data" 64M 20276b90e23SKevin Wolf 20376b90e23SKevin Wolf$QEMU_IO -c 'write -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io 20476b90e23SKevin Wolf$QEMU_IO -c 'read -P 0x11 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io 20576b90e23SKevin Wolf$QEMU_IMG map --output=human "$TEST_IMG" | _filter_testdir 20676b90e23SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" 20776b90e23SKevin Wolf 208a0cf8dafSKevin Wolfecho 209a0cf8dafSKevin Wolfecho "=== Copy offloading ===" 210a0cf8dafSKevin Wolfecho 211a0cf8dafSKevin Wolf 212a0cf8dafSKevin Wolf# Make use of copy offloading if the test host can provide it 213a0cf8dafSKevin Wolf_make_test_img -o "data_file=$TEST_IMG.data" 64M 214a0cf8dafSKevin Wolf$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$TEST_IMG" 215a0cf8dafSKevin Wolf$QEMU_IMG compare -f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$TEST_IMG" 216a0cf8dafSKevin Wolf 217a0cf8dafSKevin Wolf# blkdebug doesn't support copy offloading, so this tests the error path 218*2eb42a72SKevin Wolftest_img_with_blkdebug="json:{ 219*2eb42a72SKevin Wolf 'driver': 'qcow2', 220*2eb42a72SKevin Wolf 'file': { 221*2eb42a72SKevin Wolf 'driver': 'file', 222*2eb42a72SKevin Wolf 'filename': '$TEST_IMG' 223*2eb42a72SKevin Wolf }, 224*2eb42a72SKevin Wolf 'data-file': { 225*2eb42a72SKevin Wolf 'driver': 'blkdebug', 226*2eb42a72SKevin Wolf 'image': { 227*2eb42a72SKevin Wolf 'driver': 'file', 228*2eb42a72SKevin Wolf 'filename': '$TEST_IMG.data' 229*2eb42a72SKevin Wolf } 230*2eb42a72SKevin Wolf } 231*2eb42a72SKevin Wolf}" 232*2eb42a72SKevin Wolf$QEMU_IMG convert -f $IMGFMT -O $IMGFMT -n -C "$TEST_IMG.src" "$test_img_with_blkdebug" 233*2eb42a72SKevin Wolf$QEMU_IMG compare -f $IMGFMT -F $IMGFMT "$TEST_IMG.src" "$test_img_with_blkdebug" 234a0cf8dafSKevin Wolf 235c365625bSMax Reitzecho 236c365625bSMax Reitzecho "=== Flushing should flush the data file ===" 237c365625bSMax Reitzecho 238c365625bSMax Reitz 239c365625bSMax Reitz# We are going to flush a qcow2 file with a blkdebug node inserted 240c365625bSMax Reitz# between the qcow2 node and its data file node. The blkdebug node 241c365625bSMax Reitz# will return an error for all flushes and so we if the data file is 242c365625bSMax Reitz# flushed, we will see qemu-io return an error. 243c365625bSMax Reitz 244c365625bSMax Reitz# We need to write something or the flush will not do anything; we 245c365625bSMax Reitz# also need -t writeback so the write is not done as a FUA write 246c365625bSMax Reitz# (which would then fail thanks to the implicit flush) 247c365625bSMax Reitz$QEMU_IO -c 'write 0 512' -c flush \ 248c365625bSMax Reitz -t writeback \ 249c365625bSMax Reitz "json:{ 250c365625bSMax Reitz 'driver': 'qcow2', 251c365625bSMax Reitz 'file': { 252c365625bSMax Reitz 'driver': 'file', 253c365625bSMax Reitz 'filename': '$TEST_IMG' 254c365625bSMax Reitz }, 255c365625bSMax Reitz 'data-file': { 256c365625bSMax Reitz 'driver': 'blkdebug', 257c365625bSMax Reitz 'inject-error': [{ 258c365625bSMax Reitz 'event': 'none', 259c365625bSMax Reitz 'iotype': 'flush' 260c365625bSMax Reitz }], 261c365625bSMax Reitz 'image': { 262c365625bSMax Reitz 'driver': 'file', 263c365625bSMax Reitz 'filename': '$TEST_IMG.data' 264c365625bSMax Reitz } 265c365625bSMax Reitz } 266c365625bSMax Reitz }" \ 267c365625bSMax Reitz | _filter_qemu_io 268c365625bSMax Reitz 269c365625bSMax Reitzresult=${PIPESTATUS[0]} 270c365625bSMax Reitzecho 271c365625bSMax Reitz 272c365625bSMax Reitzcase $result in 273c365625bSMax Reitz 0) 274c365625bSMax Reitz echo "ERROR: qemu-io succeeded, so the data file was not flushed" 275c365625bSMax Reitz ;; 276c365625bSMax Reitz 1) 277c365625bSMax Reitz echo "Success: qemu-io failed, so the data file was flushed" 278c365625bSMax Reitz ;; 279c365625bSMax Reitz *) 280c365625bSMax Reitz echo "ERROR: qemu-io returned unknown exit code $result" 281c365625bSMax Reitz ;; 282c365625bSMax Reitzesac 283c365625bSMax Reitz 2842ec7e8a9SMax Reitzecho 2852ec7e8a9SMax Reitzecho '=== Preallocation with data-file-raw ===' 2862ec7e8a9SMax Reitz 2872ec7e8a9SMax Reitzecho 2882ec7e8a9SMax Reitzecho '--- Using a non-zeroed data file ---' 2892ec7e8a9SMax Reitz 2902ec7e8a9SMax Reitz# Using data-file-raw must enforce at least metadata preallocation so 2912ec7e8a9SMax Reitz# that it does not matter whether one reads the raw file or the qcow2 2922ec7e8a9SMax Reitz# file 2932ec7e8a9SMax Reitz 2942ec7e8a9SMax Reitz# Pre-create the data file, write some data. Real-world use cases for 2952ec7e8a9SMax Reitz# this are adding a qcow2 metadata file to a block device (i.e., using 2962ec7e8a9SMax Reitz# the device as the data file) or adding qcow2 features to pre-existing 2972ec7e8a9SMax Reitz# raw images (e.g. because the user now wants persistent dirty bitmaps). 2982ec7e8a9SMax Reitztruncate -s 1M "$TEST_IMG.data" 2992ec7e8a9SMax Reitz$QEMU_IO -f raw -c 'write -P 42 0 1M' "$TEST_IMG.data" | _filter_qemu_io 3002ec7e8a9SMax Reitz 3012ec7e8a9SMax Reitz# We cannot use qemu-img to create the qcow2 image, because it would 3022ec7e8a9SMax Reitz# clear the data file. Use the blockdev-create job instead, which will 3032ec7e8a9SMax Reitz# only format the qcow2 image file. 3042ec7e8a9SMax Reitztouch "$TEST_IMG" 3052ec7e8a9SMax Reitz_launch_qemu \ 3062ec7e8a9SMax Reitz -blockdev file,node-name=data,filename="$TEST_IMG.data" \ 3072ec7e8a9SMax Reitz -blockdev file,node-name=meta,filename="$TEST_IMG" 3082ec7e8a9SMax Reitz 3092ec7e8a9SMax Reitz_send_qemu_cmd $QEMU_HANDLE '{ "execute": "qmp_capabilities" }' 'return' 3102ec7e8a9SMax Reitz 3112ec7e8a9SMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 3122ec7e8a9SMax Reitz '{ "execute": "blockdev-create", 3132ec7e8a9SMax Reitz "arguments": { 3142ec7e8a9SMax Reitz "job-id": "create", 3152ec7e8a9SMax Reitz "options": { 3162ec7e8a9SMax Reitz "driver": "qcow2", 3172ec7e8a9SMax Reitz "size": '"$((1 * 1024 * 1024))"', 3182ec7e8a9SMax Reitz "file": "meta", 3192ec7e8a9SMax Reitz "data-file": "data", 3202ec7e8a9SMax Reitz "data-file-raw": true 3212ec7e8a9SMax Reitz } } }' \ 3222ec7e8a9SMax Reitz '"status": "concluded"' 3232ec7e8a9SMax Reitz 3242ec7e8a9SMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 3252ec7e8a9SMax Reitz '{ "execute": "job-dismiss", "arguments": { "id": "create" } }' \ 3262ec7e8a9SMax Reitz 'return' 3272ec7e8a9SMax Reitz 3282ec7e8a9SMax Reitz_cleanup_qemu 3292ec7e8a9SMax Reitz 3302ec7e8a9SMax Reitzecho 3312ec7e8a9SMax Reitzecho 'Comparing pattern:' 3322ec7e8a9SMax Reitz 3332ec7e8a9SMax Reitz# Reading from either the qcow2 file or the data file should return 3342ec7e8a9SMax Reitz# the same result: 3352ec7e8a9SMax Reitz$QEMU_IO -f raw -c 'read -P 42 0 1M' "$TEST_IMG.data" | _filter_qemu_io 3362ec7e8a9SMax Reitz$QEMU_IO -f $IMGFMT -c 'read -P 42 0 1M' "$TEST_IMG" | _filter_qemu_io 3372ec7e8a9SMax Reitz 3382ec7e8a9SMax Reitz# For good measure 3392ec7e8a9SMax Reitz$QEMU_IMG compare -f raw "$TEST_IMG.data" "$TEST_IMG" 3402ec7e8a9SMax Reitz 3412ec7e8a9SMax Reitzecho 3422ec7e8a9SMax Reitzecho '--- Truncation (growing) ---' 3432ec7e8a9SMax Reitz 3442ec7e8a9SMax Reitz# Append some new data to the raw file, then resize the qcow2 image 3452ec7e8a9SMax Reitz# accordingly and see whether the new data is visible. Technically 3462ec7e8a9SMax Reitz# that is not allowed, but it is reasonable behavior, so test it. 3472ec7e8a9SMax Reitztruncate -s 2M "$TEST_IMG.data" 3482ec7e8a9SMax Reitz$QEMU_IO -f raw -c 'write -P 84 1M 1M' "$TEST_IMG.data" | _filter_qemu_io 3492ec7e8a9SMax Reitz 3502ec7e8a9SMax Reitz$QEMU_IMG resize "$TEST_IMG" 2M 3512ec7e8a9SMax Reitz 3522ec7e8a9SMax Reitzecho 3532ec7e8a9SMax Reitzecho 'Comparing pattern:' 3542ec7e8a9SMax Reitz 3552ec7e8a9SMax Reitz$QEMU_IO -f raw -c 'read -P 42 0 1M' -c 'read -P 84 1M 1M' "$TEST_IMG.data" \ 3562ec7e8a9SMax Reitz | _filter_qemu_io 3572ec7e8a9SMax Reitz$QEMU_IO -f $IMGFMT -c 'read -P 42 0 1M' -c 'read -P 84 1M 1M' "$TEST_IMG" \ 3582ec7e8a9SMax Reitz | _filter_qemu_io 3592ec7e8a9SMax Reitz 3602ec7e8a9SMax Reitz$QEMU_IMG compare -f raw "$TEST_IMG.data" "$TEST_IMG" 3612ec7e8a9SMax Reitz 3622ec7e8a9SMax Reitzecho 3632ec7e8a9SMax Reitzecho '--- Giving a backing file at runtime ---' 3642ec7e8a9SMax Reitz 3652ec7e8a9SMax Reitz# qcow2 files with data-file-raw cannot have backing files given by 3662ec7e8a9SMax Reitz# their image header, but qemu will allow you to set a backing node at 3672ec7e8a9SMax Reitz# runtime -- it should not have any effect, though (because reading 3682ec7e8a9SMax Reitz# from the qcow2 node should return the same data as reading from the 3692ec7e8a9SMax Reitz# raw node). 3702ec7e8a9SMax Reitz 3712ec7e8a9SMax Reitz_make_test_img -o "data_file=$TEST_IMG.data,data_file_raw=on" 1M 3722ec7e8a9SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 1M 3732ec7e8a9SMax Reitz 3742ec7e8a9SMax Reitz# Write something that is not zero into the base image 3752ec7e8a9SMax Reitz$QEMU_IO -c 'write -P 42 0 1M' "$TEST_IMG.base" | _filter_qemu_io 3762ec7e8a9SMax Reitz 3772ec7e8a9SMax Reitzecho 3782ec7e8a9SMax Reitzecho 'Comparing qcow2 image and raw data file:' 3792ec7e8a9SMax Reitz 3802ec7e8a9SMax Reitz# $TEST_IMG and $TEST_IMG.data must show the same data at all times; 3812ec7e8a9SMax Reitz# that is, the qcow2 node must not fall through to the backing image 3822ec7e8a9SMax Reitz# at any point 3832ec7e8a9SMax Reitz$QEMU_IMG compare --image-opts \ 3842ec7e8a9SMax Reitz "driver=raw,file.filename=$TEST_IMG.data" \ 3852ec7e8a9SMax Reitz "file.filename=$TEST_IMG,backing.file.filename=$TEST_IMG.base" 3862ec7e8a9SMax Reitz 38776b90e23SKevin Wolf# success, all done 38876b90e23SKevin Wolfecho "*** done" 38976b90e23SKevin Wolfrm -f $seq.full 39076b90e23SKevin Wolfstatus=0 391