xref: /qemu/tests/qemu-iotests/066 (revision 048c5fd1bfc787adcb1b726ce997e87fe44545fd)
1975a93c0SMax Reitz#!/bin/bash
2975a93c0SMax Reitz#
3975a93c0SMax Reitz# Test case for discarding preallocated zero clusters in qcow2
4975a93c0SMax Reitz#
5975a93c0SMax Reitz# Copyright (C) 2013 Red Hat, Inc.
6975a93c0SMax Reitz#
7975a93c0SMax Reitz# This program is free software; you can redistribute it and/or modify
8975a93c0SMax Reitz# it under the terms of the GNU General Public License as published by
9975a93c0SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10975a93c0SMax Reitz# (at your option) any later version.
11975a93c0SMax Reitz#
12975a93c0SMax Reitz# This program is distributed in the hope that it will be useful,
13975a93c0SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14975a93c0SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15975a93c0SMax Reitz# GNU General Public License for more details.
16975a93c0SMax Reitz#
17975a93c0SMax Reitz# You should have received a copy of the GNU General Public License
18975a93c0SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19975a93c0SMax Reitz#
20975a93c0SMax Reitz
21975a93c0SMax Reitz# creator
22975a93c0SMax Reitzowner=mreitz@redhat.com
23975a93c0SMax Reitz
24975a93c0SMax Reitzseq="$(basename $0)"
25975a93c0SMax Reitzecho "QA output created by $seq"
26975a93c0SMax Reitz
27975a93c0SMax Reitzhere="$PWD"
28975a93c0SMax Reitzstatus=1	# failure is the default!
29975a93c0SMax Reitz
30975a93c0SMax Reitz_cleanup()
31975a93c0SMax Reitz{
32975a93c0SMax Reitz	_cleanup_test_img
33975a93c0SMax Reitz}
34975a93c0SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35975a93c0SMax Reitz
36975a93c0SMax Reitz# get standard environment, filters and checks
37975a93c0SMax Reitz. ./common.rc
38975a93c0SMax Reitz. ./common.filter
39975a93c0SMax Reitz
40975a93c0SMax Reitz# This tests qocw2-specific low-level functionality
41975a93c0SMax Reitz_supported_fmt qcow2
42975a93c0SMax Reitz_supported_proto generic
43975a93c0SMax Reitz_supported_os Linux
44975a93c0SMax Reitz
45*048c5fd1SEric Blake# Intentionally create an unaligned image
46975a93c0SMax ReitzIMGOPTS="compat=1.1"
47*048c5fd1SEric BlakeIMG_SIZE=$((64 * 1024 * 1024 + 512))
48975a93c0SMax Reitz
49975a93c0SMax Reitzecho
50*048c5fd1SEric Blakeecho "=== Testing cluster discards ==="
51975a93c0SMax Reitzecho
52975a93c0SMax Reitz_make_test_img $IMG_SIZE
53*048c5fd1SEric Blake# Write some normal clusters, zero some of them (creating preallocated
54*048c5fd1SEric Blake# zero clusters) and discard everything. Everything should now read as 0.
55*048c5fd1SEric Blake$QEMU_IO -c "write 0 256k" -c "write -z 0 256k" -c "write 64M 512" \
56*048c5fd1SEric Blake	 -c "discard 0 $IMG_SIZE" -c "read -P 0 0 $IMG_SIZE" "$TEST_IMG" \
57975a93c0SMax Reitz         | _filter_qemu_io
58975a93c0SMax Reitz# Check the image (there shouldn't be any leaks)
59975a93c0SMax Reitz_check_test_img
60975a93c0SMax Reitz
61975a93c0SMax Reitz# success, all done
62975a93c0SMax Reitzecho "*** done"
63975a93c0SMax Reitzrm -f $seq.full
64975a93c0SMax Reitzstatus=0
65