xref: /openbmc/qemu/tests/qemu-iotests/020 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2ed4dc684SKevin Wolf#
3ed4dc684SKevin Wolf# Commit changes to backing file
4ed4dc684SKevin Wolf#
5ed4dc684SKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
6ed4dc684SKevin Wolf#
7ed4dc684SKevin Wolf# This program is free software; you can redistribute it and/or modify
8ed4dc684SKevin Wolf# it under the terms of the GNU General Public License as published by
9ed4dc684SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10ed4dc684SKevin Wolf# (at your option) any later version.
11ed4dc684SKevin Wolf#
12ed4dc684SKevin Wolf# This program is distributed in the hope that it will be useful,
13ed4dc684SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14ed4dc684SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ed4dc684SKevin Wolf# GNU General Public License for more details.
16ed4dc684SKevin Wolf#
17ed4dc684SKevin Wolf# You should have received a copy of the GNU General Public License
18e8c212d6SChristoph Hellwig# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19ed4dc684SKevin Wolf#
20ed4dc684SKevin Wolf
21ed4dc684SKevin Wolf# creator
22ed4dc684SKevin Wolfowner=kwolf@redhat.com
23ed4dc684SKevin Wolf
24ed4dc684SKevin Wolfseq=`basename $0`
25ed4dc684SKevin Wolfecho "QA output created by $seq"
26ed4dc684SKevin Wolf
27ed4dc684SKevin Wolfstatus=1	# failure is the default!
28ed4dc684SKevin Wolf
29ed4dc684SKevin Wolf_cleanup()
30ed4dc684SKevin Wolf{
31ed4dc684SKevin Wolf	_cleanup_test_img
32fef9c191SJeff Cody    rm -f "$TEST_IMG.base"
33fef9c191SJeff Cody    rm -f "$TEST_IMG.orig"
34ed4dc684SKevin Wolf}
35ed4dc684SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36ed4dc684SKevin Wolf
37ed4dc684SKevin Wolf# get standard environment, filters and checks
38ed4dc684SKevin Wolf. ./common.rc
39ed4dc684SKevin Wolf. ./common.filter
40ed4dc684SKevin Wolf. ./common.pattern
41ed4dc684SKevin Wolf
42ed4dc684SKevin Wolf# Any format supporting backing files
43f5a4bbd9SStefan Hajnoczi_supported_fmt qcow qcow2 vmdk qed
448e5decb5SMax Reitz_supported_proto file
45ed4dc684SKevin Wolf_supported_os Linux
46d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \
47d2329f27SFam Zheng                     "subformat=twoGbMaxExtentFlat" \
48d2329f27SFam Zheng                     "subformat=twoGbMaxExtentSparse"
49ed4dc684SKevin Wolf
50ed4dc684SKevin WolfTEST_OFFSETS="0 4294967296"
51ed4dc684SKevin Wolf
5271ad7617SFam ZhengTEST_IMG_SAVE="$TEST_IMG"
5371ad7617SFam ZhengTEST_IMG="$TEST_IMG.base"
5471ad7617SFam Zheng
55ed4dc684SKevin Wolf_make_test_img 6G
56ed4dc684SKevin Wolf
57ed4dc684SKevin Wolfecho "Filling base image"
58ed4dc684SKevin Wolfecho
59ed4dc684SKevin Wolf
60ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do
61ed4dc684SKevin Wolf    # Some clusters with alternating backing file/image file reads
62ed4dc684SKevin Wolf    io writev $(( offset )) 512 1024 64
63ed4dc684SKevin Wolf
64ed4dc684SKevin Wolf    # Complete backing clusters
65ed4dc684SKevin Wolf    io writev $(( offset  + 64 * 1024))  65536 65536 1
66ed4dc684SKevin Wolfdone
67ed4dc684SKevin Wolf_check_test_img
68ed4dc684SKevin Wolf
69ed4dc684SKevin Wolfecho "Creating test image with backing file"
70ed4dc684SKevin Wolfecho
71ed4dc684SKevin Wolf
7271ad7617SFam ZhengTEST_IMG="$TEST_IMG_SAVE"
73fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" 6G
74ed4dc684SKevin Wolf
75ed4dc684SKevin Wolfecho "Filling test image"
76ed4dc684SKevin Wolfecho
77ed4dc684SKevin Wolf
78ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do
79ed4dc684SKevin Wolf    # Some clusters with alternating backing file/image file reads
80ed4dc684SKevin Wolf    io writev $(( offset + 512 )) 512 1024 64
81ed4dc684SKevin Wolf
82ed4dc684SKevin Wolf    # Complete test image clusters
83ed4dc684SKevin Wolf    io writev $(( offset + 64 * 1024 + 65536))  65536 65536 1
84ed4dc684SKevin Wolfdone
85ed4dc684SKevin Wolf_check_test_img
86ed4dc684SKevin Wolf
87fef9c191SJeff Cody$QEMU_IMG commit "$TEST_IMG"
8871ad7617SFam ZhengTEST_IMG="$TEST_IMG.base"
89ed4dc684SKevin Wolf
90ed4dc684SKevin Wolfecho "Reading from the backing file"
91ed4dc684SKevin Wolfecho
92ed4dc684SKevin Wolf
93ed4dc684SKevin Wolffor offset in $TEST_OFFSETS; do
94ed4dc684SKevin Wolf    # Some clusters with alternating backing file/image file reads
95ed4dc684SKevin Wolf    io readv $(( offset )) 512 1024 64
96ed4dc684SKevin Wolf    io readv $(( offset + 512 )) 512 1024 64
97ed4dc684SKevin Wolf
98ed4dc684SKevin Wolf    # Complete test image clusters
99ed4dc684SKevin Wolf    io readv $(( offset  + 64 * 1024))  65536 65536 1
100ed4dc684SKevin Wolf    io readv $(( offset + 64 * 1024 + 65536))  65536 65536 1
101ed4dc684SKevin Wolf
102ed4dc684SKevin Wolf    # Empty sectors
103ed4dc684SKevin Wolf    io_zero readv $(( offset + 64 * 1024 + 65536 * 4 )) 65536 65536 1
104ed4dc684SKevin Wolfdone
105ed4dc684SKevin Wolf_check_test_img
1062b773193SMax Reitz_cleanup
1072b773193SMax ReitzTEST_IMG=$TEST_IMG_SAVE
1082b773193SMax Reitz
1092b773193SMax Reitzecho
1102b773193SMax Reitzecho 'Testing failing commit'
1112b773193SMax Reitzecho
1122b773193SMax Reitz
1138c97fcf4SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 1M
1148c97fcf4SMax Reitz
1152b773193SMax Reitz# Create an image with a null backing file to which committing will fail (with
1162b773193SMax Reitz# ENOSPC so we can distinguish the result from some generic EIO which may be
1172b773193SMax Reitz# generated anywhere in the block layer)
1188c97fcf4SMax Reitz_make_test_img -b "json:{'driver': '$IMGFMT',
1192b773193SMax Reitz                         'file': {
1202b773193SMax Reitz                             'driver': 'blkdebug',
1212b773193SMax Reitz                             'inject-error': [{
1222b773193SMax Reitz                                 'event': 'write_aio',
1232b773193SMax Reitz                                 'errno': 28,
1242b773193SMax Reitz                                 'once': true
1252b773193SMax Reitz                             }],
1262b773193SMax Reitz                             'image': {
1278c97fcf4SMax Reitz                                 'driver': 'file',
1288c97fcf4SMax Reitz                                 'filename': '$TEST_IMG.base'
1292b773193SMax Reitz                             }}}"
1302b773193SMax Reitz
1312b773193SMax Reitz# Just write anything so committing will not be a no-op
1322b773193SMax Reitz$QEMU_IO -c 'writev 0 64k' "$TEST_IMG" | _filter_qemu_io
1332b773193SMax Reitz
1342b773193SMax Reitz$QEMU_IMG commit "$TEST_IMG"
1358c97fcf4SMax Reitz_cleanup
136ed4dc684SKevin Wolf
137ed4dc684SKevin Wolf# success, all done
138ed4dc684SKevin Wolfecho "*** done"
139ed4dc684SKevin Wolfrm -f $seq.full
140ed4dc684SKevin Wolfstatus=0
141