xref: /openbmc/qemu/tests/qemu-iotests/019 (revision fef80ea073c4862bc9eaddb6ddb0ed970b8ad7c4)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw backing auto quick
39128ae5eSKevin Wolf#
49128ae5eSKevin Wolf# When using a backing file for the output image in qemu-img convert,
59128ae5eSKevin Wolf# the backing file clusters must not copied. The data must still be
69128ae5eSKevin Wolf# read correctly.
79128ae5eSKevin Wolf#
89128ae5eSKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
99128ae5eSKevin Wolf#
109128ae5eSKevin Wolf# This program is free software; you can redistribute it and/or modify
119128ae5eSKevin Wolf# it under the terms of the GNU General Public License as published by
129128ae5eSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
139128ae5eSKevin Wolf# (at your option) any later version.
149128ae5eSKevin Wolf#
159128ae5eSKevin Wolf# This program is distributed in the hope that it will be useful,
169128ae5eSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
179128ae5eSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
189128ae5eSKevin Wolf# GNU General Public License for more details.
199128ae5eSKevin Wolf#
209128ae5eSKevin Wolf# You should have received a copy of the GNU General Public License
21e8c212d6SChristoph Hellwig# along with this program.  If not, see <http://www.gnu.org/licenses/>.
229128ae5eSKevin Wolf#
239128ae5eSKevin Wolf
249128ae5eSKevin Wolf# creator
259128ae5eSKevin Wolfowner=kwolf@redhat.com
269128ae5eSKevin Wolf
279128ae5eSKevin Wolfseq=`basename $0`
289128ae5eSKevin Wolfecho "QA output created by $seq"
299128ae5eSKevin Wolf
309128ae5eSKevin Wolfstatus=1	# failure is the default!
319128ae5eSKevin Wolf
329128ae5eSKevin Wolf_cleanup()
339128ae5eSKevin Wolf{
349128ae5eSKevin Wolf    _cleanup_test_img
35f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.base"
36f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.orig"
379128ae5eSKevin Wolf}
389128ae5eSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
399128ae5eSKevin Wolf
409128ae5eSKevin Wolf# get standard environment, filters and checks
419128ae5eSKevin Wolf. ./common.rc
429128ae5eSKevin Wolf. ./common.filter
439128ae5eSKevin Wolf. ./common.pattern
449128ae5eSKevin Wolf
459128ae5eSKevin Wolf# Any format supporting backing files
46f5a4bbd9SStefan Hajnoczi_supported_fmt qcow qcow2 vmdk qed
471f7bf7d0SPeter Lieven_supported_proto file
489128ae5eSKevin Wolf_supported_os Linux
49d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \
50d2329f27SFam Zheng                     "subformat=twoGbMaxExtentFlat" \
51325dd915SMax Reitz                     "subformat=twoGbMaxExtentSparse" \
52325dd915SMax Reitz                     "subformat=streamOptimized"
539128ae5eSKevin Wolf
549128ae5eSKevin WolfTEST_OFFSETS="0 4294967296"
558fc1024cSKevin WolfCLUSTER_SIZE=65536
569128ae5eSKevin Wolf
57f2bbcd3fSFam ZhengTEST_IMG_SAVE="$TEST_IMG"
58f2bbcd3fSFam ZhengTEST_IMG="$TEST_IMG.base"
59f2bbcd3fSFam Zheng
609128ae5eSKevin Wolf_make_test_img 6G
619128ae5eSKevin Wolf
629128ae5eSKevin Wolfecho "Filling base image"
639128ae5eSKevin Wolfecho
649128ae5eSKevin Wolf
659128ae5eSKevin Wolffor offset in $TEST_OFFSETS; do
669128ae5eSKevin Wolf    # Some clusters with alternating backing file/image file reads
672547caa1SKevin Wolf    io_pattern writev $(( offset )) 512 1024 64 42
689128ae5eSKevin Wolf
699128ae5eSKevin Wolf    # Complete backing clusters
702547caa1SKevin Wolf    io_pattern writev $(( offset  + 1024 * 1024))  $CLUSTER_SIZE $CLUSTER_SIZE 1 42
719128ae5eSKevin Wolfdone
729128ae5eSKevin Wolf_check_test_img
739128ae5eSKevin Wolf
749128ae5eSKevin Wolfecho "Creating test image with backing file"
759128ae5eSKevin Wolfecho
769128ae5eSKevin Wolf
77f2bbcd3fSFam ZhengTEST_IMG="$TEST_IMG_SAVE.orig"
78b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG_SAVE.base" -F $IMGFMT 6G
799128ae5eSKevin Wolf
809128ae5eSKevin Wolfecho "Filling test image"
819128ae5eSKevin Wolfecho
829128ae5eSKevin Wolf
839128ae5eSKevin Wolffor offset in $TEST_OFFSETS; do
849128ae5eSKevin Wolf    # Some clusters with alternating backing file/image file reads
852547caa1SKevin Wolf    io_pattern writev $(( offset + 512 )) 512 1024 64 43
869128ae5eSKevin Wolf
879128ae5eSKevin Wolf    # Complete test image clusters
882547caa1SKevin Wolf    io_pattern writev $(( offset + 1024 * 1024 + $CLUSTER_SIZE))  $CLUSTER_SIZE $CLUSTER_SIZE 1 43
899128ae5eSKevin Wolfdone
909128ae5eSKevin Wolf_check_test_img
919128ae5eSKevin Wolf
92f2bbcd3fSFam ZhengTEST_IMG="$TEST_IMG_SAVE"
932547caa1SKevin Wolf
942547caa1SKevin Wolf# Test the conversion twice: One test with the old-style -B option and another
952547caa1SKevin Wolf# one with -o backing_file
962547caa1SKevin Wolf
973cbe3e8dSJeff Codyfor backing_option in "-B " "-o backing_file="; do
982547caa1SKevin Wolf
992547caa1SKevin Wolf    echo
100cc8a7e56SJeff Cody    echo Testing conversion with $backing_option"$TEST_IMG.base" | _filter_testdir | _filter_imgfmt
1012547caa1SKevin Wolf    echo
102b66ff2c2SEric Blake    $QEMU_IMG convert -f $IMGFMT -O $IMGFMT $backing_option"$TEST_IMG.base" \
103b66ff2c2SEric Blake        -o backing_fmt=$IMGFMT "$TEST_IMG.orig" "$TEST_IMG"
1049128ae5eSKevin Wolf
1059128ae5eSKevin Wolf    echo "Checking if backing clusters are allocated when they shouldn't"
1069128ae5eSKevin Wolf    echo
1079128ae5eSKevin Wolf    for offset in $TEST_OFFSETS; do
1089128ae5eSKevin Wolf        # Complete backing clusters
1093da9c8fbSKevin Wolf        is_allocated $(( offset  + 1024 * 1024))  $CLUSTER_SIZE $CLUSTER_SIZE 1
1109128ae5eSKevin Wolf    done
1119128ae5eSKevin Wolf
1129128ae5eSKevin Wolf    echo "Reading"
1139128ae5eSKevin Wolf    echo
1149128ae5eSKevin Wolf
1159128ae5eSKevin Wolf    for offset in $TEST_OFFSETS; do
1169128ae5eSKevin Wolf        # Some clusters with alternating backing file/image file reads
1172547caa1SKevin Wolf        io_pattern readv $(( offset )) 512 1024 64 42
1182547caa1SKevin Wolf        io_pattern readv $(( offset + 512 )) 512 1024 64 43
1199128ae5eSKevin Wolf
1209128ae5eSKevin Wolf        # Complete test image clusters
1212547caa1SKevin Wolf        io_pattern readv $(( offset  + 1024 * 1024))  $CLUSTER_SIZE $CLUSTER_SIZE 1 42
1222547caa1SKevin Wolf        io_pattern readv $(( offset + 1024 * 1024 + $CLUSTER_SIZE))  $CLUSTER_SIZE $CLUSTER_SIZE 1 43
1239128ae5eSKevin Wolf
1249128ae5eSKevin Wolf        # Empty sectors
1253da9c8fbSKevin Wolf        io_zero readv $(( offset + 1024 * 1024 + $CLUSTER_SIZE * 4 )) $CLUSTER_SIZE $CLUSTER_SIZE 1
1269128ae5eSKevin Wolf    done
1279128ae5eSKevin Wolf    _check_test_img
1289128ae5eSKevin Wolf
1292547caa1SKevin Wolfdone
1302547caa1SKevin Wolf
1319128ae5eSKevin Wolf# success, all done
1329128ae5eSKevin Wolfecho "*** done"
1339128ae5eSKevin Wolfrm -f $seq.full
1349128ae5eSKevin Wolfstatus=0
135