111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw backing auto quick 3ed4dc684SKevin Wolf# 4ed4dc684SKevin Wolf# Commit changes to backing file 5ed4dc684SKevin Wolf# 6ed4dc684SKevin Wolf# Copyright (C) 2009 Red Hat, Inc. 7ed4dc684SKevin Wolf# 8ed4dc684SKevin Wolf# This program is free software; you can redistribute it and/or modify 9ed4dc684SKevin Wolf# it under the terms of the GNU General Public License as published by 10ed4dc684SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11ed4dc684SKevin Wolf# (at your option) any later version. 12ed4dc684SKevin Wolf# 13ed4dc684SKevin Wolf# This program is distributed in the hope that it will be useful, 14ed4dc684SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15ed4dc684SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16ed4dc684SKevin Wolf# GNU General Public License for more details. 17ed4dc684SKevin Wolf# 18ed4dc684SKevin Wolf# You should have received a copy of the GNU General Public License 19e8c212d6SChristoph Hellwig# along with this program. If not, see <http://www.gnu.org/licenses/>. 20ed4dc684SKevin Wolf# 21ed4dc684SKevin Wolf 22ed4dc684SKevin Wolf# creator 23ed4dc684SKevin Wolfowner=kwolf@redhat.com 24ed4dc684SKevin Wolf 25ed4dc684SKevin Wolfseq=`basename $0` 26ed4dc684SKevin Wolfecho "QA output created by $seq" 27ed4dc684SKevin Wolf 28ed4dc684SKevin Wolfstatus=1 # failure is the default! 29ed4dc684SKevin Wolf 30ed4dc684SKevin Wolf_cleanup() 31ed4dc684SKevin Wolf{ 32ed4dc684SKevin Wolf _cleanup_test_img 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.base" 34f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.orig" 356c3e1106SMax Reitz 366c3e1106SMax Reitz _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base" 376c3e1106SMax Reitz _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.mid" 386c3e1106SMax Reitz _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT" 396c3e1106SMax Reitz rmdir "$TEST_DIR/subdir" &> /dev/null 40ed4dc684SKevin Wolf} 41ed4dc684SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 42ed4dc684SKevin Wolf 43ed4dc684SKevin Wolf# get standard environment, filters and checks 44ed4dc684SKevin Wolf. ./common.rc 45ed4dc684SKevin Wolf. ./common.filter 46ed4dc684SKevin Wolf. ./common.pattern 47ed4dc684SKevin Wolf 48ed4dc684SKevin Wolf# Any format supporting backing files 49f5a4bbd9SStefan Hajnoczi_supported_fmt qcow qcow2 vmdk qed 508e5decb5SMax Reitz_supported_proto file 51d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \ 52d2329f27SFam Zheng "subformat=twoGbMaxExtentFlat" \ 53325dd915SMax Reitz "subformat=twoGbMaxExtentSparse" \ 54325dd915SMax Reitz "subformat=streamOptimized" 55ed4dc684SKevin Wolf 56ed4dc684SKevin WolfTEST_OFFSETS="0 4294967296" 57ed4dc684SKevin Wolf 5871ad7617SFam ZhengTEST_IMG_SAVE="$TEST_IMG" 5971ad7617SFam ZhengTEST_IMG="$TEST_IMG.base" 6071ad7617SFam Zheng 61ed4dc684SKevin Wolf_make_test_img 6G 62ed4dc684SKevin Wolf 63ed4dc684SKevin Wolfecho "Filling base image" 64ed4dc684SKevin Wolfecho 65ed4dc684SKevin Wolf 66ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do 67ed4dc684SKevin Wolf # Some clusters with alternating backing file/image file reads 68ed4dc684SKevin Wolf io writev $(( offset )) 512 1024 64 69ed4dc684SKevin Wolf 70ed4dc684SKevin Wolf # Complete backing clusters 71ed4dc684SKevin Wolf io writev $(( offset + 64 * 1024)) 65536 65536 1 72ed4dc684SKevin Wolfdone 73ed4dc684SKevin Wolf_check_test_img 74ed4dc684SKevin Wolf 75ed4dc684SKevin Wolfecho "Creating test image with backing file" 76ed4dc684SKevin Wolfecho 77ed4dc684SKevin Wolf 7871ad7617SFam ZhengTEST_IMG="$TEST_IMG_SAVE" 79b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G 80ed4dc684SKevin Wolf 81ed4dc684SKevin Wolfecho "Filling test image" 82ed4dc684SKevin Wolfecho 83ed4dc684SKevin Wolf 84ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do 85ed4dc684SKevin Wolf # Some clusters with alternating backing file/image file reads 86ed4dc684SKevin Wolf io writev $(( offset + 512 )) 512 1024 64 87ed4dc684SKevin Wolf 88ed4dc684SKevin Wolf # Complete test image clusters 89ed4dc684SKevin Wolf io writev $(( offset + 64 * 1024 + 65536)) 65536 65536 1 90ed4dc684SKevin Wolfdone 91ed4dc684SKevin Wolf_check_test_img 92ed4dc684SKevin Wolf 93fef9c191SJeff Cody$QEMU_IMG commit "$TEST_IMG" 9471ad7617SFam ZhengTEST_IMG="$TEST_IMG.base" 95ed4dc684SKevin Wolf 96ed4dc684SKevin Wolfecho "Reading from the backing file" 97ed4dc684SKevin Wolfecho 98ed4dc684SKevin Wolf 99ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do 100ed4dc684SKevin Wolf # Some clusters with alternating backing file/image file reads 101ed4dc684SKevin Wolf io readv $(( offset )) 512 1024 64 102ed4dc684SKevin Wolf io readv $(( offset + 512 )) 512 1024 64 103ed4dc684SKevin Wolf 104ed4dc684SKevin Wolf # Complete test image clusters 105ed4dc684SKevin Wolf io readv $(( offset + 64 * 1024)) 65536 65536 1 106ed4dc684SKevin Wolf io readv $(( offset + 64 * 1024 + 65536)) 65536 65536 1 107ed4dc684SKevin Wolf 108ed4dc684SKevin Wolf # Empty sectors 109ed4dc684SKevin Wolf io_zero readv $(( offset + 64 * 1024 + 65536 * 4 )) 65536 65536 1 110ed4dc684SKevin Wolfdone 111ed4dc684SKevin Wolf_check_test_img 1122b773193SMax Reitz_cleanup 1132b773193SMax ReitzTEST_IMG=$TEST_IMG_SAVE 1142b773193SMax Reitz 1152b773193SMax Reitzecho 1162b773193SMax Reitzecho 'Testing failing commit' 1172b773193SMax Reitzecho 1182b773193SMax Reitz 1198c97fcf4SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 1M 1208c97fcf4SMax Reitz 1212b773193SMax Reitz# Create an image with a null backing file to which committing will fail (with 1222b773193SMax Reitz# ENOSPC so we can distinguish the result from some generic EIO which may be 1232b773193SMax Reitz# generated anywhere in the block layer) 1244b196cd1SMax Reitzbacking="json:{'driver': '$IMGFMT', 1252b773193SMax Reitz 'file': { 1262b773193SMax Reitz 'driver': 'blkdebug', 1272b773193SMax Reitz 'inject-error': [{ 1282b773193SMax Reitz 'event': 'write_aio', 1292b773193SMax Reitz 'errno': 28, 1302b773193SMax Reitz 'once': true 1312b773193SMax Reitz }], 1322b773193SMax Reitz 'image': { 1338c97fcf4SMax Reitz 'driver': 'file', 1348c97fcf4SMax Reitz 'filename': '$TEST_IMG.base' 1352b773193SMax Reitz }}}" 1362b773193SMax Reitz 1374b196cd1SMax Reitz# Filter out newlines and collapse spaces 1384b196cd1SMax Reitzbacking=$(echo "$backing" | tr -d '\n' | tr -s ' ') 1394b196cd1SMax Reitz 140b66ff2c2SEric Blake_make_test_img -b "$backing" -F $IMGFMT 1414b196cd1SMax Reitz 1422b773193SMax Reitz# Just write anything so committing will not be a no-op 1432b773193SMax Reitz$QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io 1442b773193SMax Reitz 1452b773193SMax Reitz$QEMU_IMG commit "$TEST_IMG" 1468c97fcf4SMax Reitz_cleanup 147ed4dc684SKevin Wolf 1486c3e1106SMax Reitz 1496c3e1106SMax Reitzecho 1506c3e1106SMax Reitzecho 'Testing commit in sub-directory with relative filenames' 1516c3e1106SMax Reitzecho 1526c3e1106SMax Reitz 1536c3e1106SMax Reitzpushd "$TEST_DIR" > /dev/null 1546c3e1106SMax Reitz 1556c3e1106SMax Reitzmkdir subdir 1566c3e1106SMax Reitz 1576c3e1106SMax ReitzTEST_IMG="subdir/t.$IMGFMT.base" _make_test_img 1M 1586c3e1106SMax ReitzTEST_IMG="subdir/t.$IMGFMT.mid" _make_test_img -b "t.$IMGFMT.base" -F $IMGFMT 1596c3e1106SMax ReitzTEST_IMG="subdir/t.$IMGFMT" _make_test_img -b "t.$IMGFMT.mid" -F $IMGFMT 1606c3e1106SMax Reitz 1616c3e1106SMax Reitz# Should work 1626c3e1106SMax Reitz$QEMU_IMG commit -b "t.$IMGFMT.mid" "subdir/t.$IMGFMT" 1636c3e1106SMax Reitz 1646c3e1106SMax Reitz# Might theoretically work, but does not in practice (we have to 1656c3e1106SMax Reitz# decide between this and the above; and since we always represent 1666c3e1106SMax Reitz# backing file names as relative to the overlay, we go for the above) 1676c3e1106SMax Reitz$QEMU_IMG commit -b "subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" 2>&1 | \ 1686c3e1106SMax Reitz _filter_imgfmt 1696c3e1106SMax Reitz 1706c3e1106SMax Reitz# This should work as well 1716c3e1106SMax Reitz$QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" "subdir/t.$IMGFMT" 1726c3e1106SMax Reitz 1736c3e1106SMax Reitzpopd > /dev/null 1746c3e1106SMax Reitz 1756c3e1106SMax Reitz# Now let's try with just absolute filenames 1766c3e1106SMax Reitz# (This will not work with external data files, though, because when 1776c3e1106SMax Reitz# using relative paths for those, qemu will always resolve them 1786c3e1106SMax Reitz# relative to its CWD. Therefore, it cannot find those data files now 1796c3e1106SMax Reitz# that we left $TEST_DIR.) 1806c3e1106SMax Reitzif _get_data_file '' > /dev/null; then 1816c3e1106SMax Reitz echo 'Image committed.' # Skip test 1826c3e1106SMax Reitzelse 1836c3e1106SMax Reitz $QEMU_IMG commit -b "$TEST_DIR/subdir/t.$IMGFMT.mid" \ 1846c3e1106SMax Reitz "$TEST_DIR/subdir/t.$IMGFMT" 1856c3e1106SMax Reitzfi 1866c3e1106SMax Reitz 187ed4dc684SKevin Wolf# success, all done 188ed4dc684SKevin Wolfecho "*** done" 189ed4dc684SKevin Wolfrm -f $seq.full 190ed4dc684SKevin Wolfstatus=0 191