xref: /openbmc/qemu/tests/qemu-iotests/027 (revision 42a5009d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick
389d22bc3SStefan Hajnoczi#
489d22bc3SStefan Hajnoczi# Test that sub-cluster allocating writes zero the rest of the cluster
589d22bc3SStefan Hajnoczi#
689d22bc3SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp.
789d22bc3SStefan Hajnoczi#
889d22bc3SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
989d22bc3SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
1089d22bc3SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
1189d22bc3SStefan Hajnoczi# (at your option) any later version.
1289d22bc3SStefan Hajnoczi#
1389d22bc3SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
1489d22bc3SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
1589d22bc3SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1689d22bc3SStefan Hajnoczi# GNU General Public License for more details.
1789d22bc3SStefan Hajnoczi#
1889d22bc3SStefan Hajnoczi# You should have received a copy of the GNU General Public License
1989d22bc3SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2089d22bc3SStefan Hajnoczi#
2189d22bc3SStefan Hajnoczi
2289d22bc3SStefan Hajnoczi# creator
23*42a5009dSJohn Snowowner=stefanha@redhat.com
2489d22bc3SStefan Hajnoczi
2589d22bc3SStefan Hajnocziseq=`basename $0`
2689d22bc3SStefan Hajnocziecho "QA output created by $seq"
2789d22bc3SStefan Hajnoczi
2889d22bc3SStefan Hajnoczistatus=1	# failure is the default!
2989d22bc3SStefan Hajnoczi
3089d22bc3SStefan Hajnoczi_cleanup()
3189d22bc3SStefan Hajnoczi{
3289d22bc3SStefan Hajnoczi	_cleanup_test_img
3389d22bc3SStefan Hajnoczi}
3489d22bc3SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
3589d22bc3SStefan Hajnoczi
3689d22bc3SStefan Hajnoczi# get standard environment, filters and checks
3789d22bc3SStefan Hajnoczi. ./common.rc
3889d22bc3SStefan Hajnoczi. ./common.filter
3989d22bc3SStefan Hajnoczi
40f5a4bbd9SStefan Hajnoczi_supported_fmt vmdk qcow qcow2 qed
419cdfa1b3SMORITA Kazutaka_supported_proto generic
42325dd915SMax Reitz_unsupported_imgopts "subformat=streamOptimized"
4389d22bc3SStefan Hajnoczi
4489d22bc3SStefan Hajnoczi
4589d22bc3SStefan Hajnoczisize=128M
4689d22bc3SStefan Hajnoczicluster_size=65536
4789d22bc3SStefan Hajnoczisubcluster_offset=1024
4889d22bc3SStefan Hajnoczisubcluster_size=2048
4989d22bc3SStefan Hajnoczi_make_test_img $size
5089d22bc3SStefan Hajnoczi
5189d22bc3SStefan Hajnoczi# This first write causes an L2 table to be allocated so that the next write
5289d22bc3SStefan Hajnoczi# doesn't need to allocate one and is therefore at the end of the image file.
5389d22bc3SStefan Hajnoczi# Otherwise an L2 table could get in the way after the data cluster.
5489d22bc3SStefan Hajnocziecho
5589d22bc3SStefan Hajnocziecho "== writing first cluster to populate metadata =="
56fef9c191SJeff Cody$QEMU_IO -c "write -pP 0xde $cluster_size $cluster_size" "$TEST_IMG" | _filter_qemu_io
5789d22bc3SStefan Hajnoczi
5889d22bc3SStefan Hajnocziecho
5989d22bc3SStefan Hajnocziecho "== writing at sub-cluster granularity =="
60fef9c191SJeff Cody$QEMU_IO -c "write -pP 0xa $subcluster_offset $subcluster_size" "$TEST_IMG" | _filter_qemu_io
6189d22bc3SStefan Hajnoczi
6289d22bc3SStefan Hajnocziecho
6389d22bc3SStefan Hajnocziecho "== verify pattern =="
64fef9c191SJeff Cody$QEMU_IO -c "read -pP 0xa $subcluster_offset $subcluster_size" "$TEST_IMG" | _filter_qemu_io
6589d22bc3SStefan Hajnoczi
6689d22bc3SStefan Hajnocziecho
6789d22bc3SStefan Hajnocziecho "== verify zeroes before sub-cluster pattern =="
68fef9c191SJeff Cody$QEMU_IO -c "read -pP 0 -l $subcluster_offset 0 $subcluster_size" "$TEST_IMG" | _filter_qemu_io
6989d22bc3SStefan Hajnoczi
7089d22bc3SStefan Hajnocziecho
7189d22bc3SStefan Hajnocziecho "== verify zeroes after sub-cluster pattern =="
72fef9c191SJeff Cody$QEMU_IO -c "read -pP 0 -l 512 -s $subcluster_size $subcluster_offset $(( subcluster_size + 512 ))" "$TEST_IMG" | _filter_qemu_io
7389d22bc3SStefan Hajnoczi
7489d22bc3SStefan Hajnoczi# success, all done
7589d22bc3SStefan Hajnocziecho "*** done"
7689d22bc3SStefan Hajnoczirm -f $seq.full
7789d22bc3SStefan Hajnoczistatus=0
78