xref: /openbmc/qemu/tests/qemu-iotests/028 (revision 42a5009d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw backing quick
38268b767SStefan Hajnoczi#
48268b767SStefan Hajnoczi# Test that backing files can be smaller than the image
58268b767SStefan Hajnoczi#
68268b767SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp.
78268b767SStefan Hajnoczi#
88268b767SStefan Hajnoczi# Based on 017:
98268b767SStefan Hajnoczi# Copyright (C) 2009 Red Hat, Inc.
108268b767SStefan Hajnoczi#
118268b767SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
128268b767SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
138268b767SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
148268b767SStefan Hajnoczi# (at your option) any later version.
158268b767SStefan Hajnoczi#
168268b767SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
178268b767SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
188268b767SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
198268b767SStefan Hajnoczi# GNU General Public License for more details.
208268b767SStefan Hajnoczi#
218268b767SStefan Hajnoczi# You should have received a copy of the GNU General Public License
228268b767SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
238268b767SStefan Hajnoczi#
248268b767SStefan Hajnoczi
258268b767SStefan Hajnoczi# creator
26*42a5009dSJohn Snowowner=stefanha@redhat.com
278268b767SStefan Hajnoczi
288268b767SStefan Hajnocziseq=`basename $0`
298268b767SStefan Hajnocziecho "QA output created by $seq"
308268b767SStefan Hajnoczi
318268b767SStefan Hajnoczistatus=1	# failure is the default!
328268b767SStefan Hajnoczi
338268b767SStefan Hajnoczi_cleanup()
348268b767SStefan Hajnoczi{
35ecfa1854SJeff Cody    _cleanup_qemu
36f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.copy"
378268b767SStefan Hajnoczi    _cleanup_test_img
388268b767SStefan Hajnoczi}
398268b767SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
408268b767SStefan Hajnoczi
418268b767SStefan Hajnoczi# get standard environment, filters and checks
428268b767SStefan Hajnoczi. ./common.rc
438268b767SStefan Hajnoczi. ./common.filter
448268b767SStefan Hajnoczi. ./common.pattern
45d40593ddSKevin Wolf. ./common.qemu
468268b767SStefan Hajnoczi
478268b767SStefan Hajnoczi# Any format supporting backing files except vmdk and qcow which do not support
488268b767SStefan Hajnoczi# smaller backing files.
49f5a4bbd9SStefan Hajnoczi_supported_fmt qcow2 qed
5057284d2aSMax Reitz_supported_proto file fuse
518268b767SStefan Hajnoczi_supported_os Linux
528268b767SStefan Hajnoczi
538268b767SStefan Hajnoczi# Choose a size that is not necessarily a cluster size multiple for image
548268b767SStefan Hajnoczi# formats that use clusters.  This will ensure that the base image doesn't end
558268b767SStefan Hajnoczi# precisely on a cluster boundary (the easy case).
568268b767SStefan Hajnocziimage_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 ))
578268b767SStefan Hajnoczi
588268b767SStefan Hajnoczi# The base image is smaller than the image file
598268b767SStefan Hajnoczibase_size=$(( image_size - 1024 * 1024 * 1024 ))
608268b767SStefan Hajnoczi
618268b767SStefan Hajnoczioffset=$(( base_size - 32 * 1024 ))
628268b767SStefan Hajnoczi
6349557d65SFam ZhengTEST_IMG_SAVE="$TEST_IMG"
6449557d65SFam ZhengTEST_IMG="$TEST_IMG.base"
6549557d65SFam Zheng
668268b767SStefan Hajnoczi_make_test_img $base_size
678268b767SStefan Hajnoczi
688268b767SStefan Hajnocziecho "Filling base image"
698268b767SStefan Hajnocziecho
708268b767SStefan Hajnoczi
718268b767SStefan Hajnoczi# Fill end of base image with a pattern, skipping every other sector
72dd0c35d6SStefan Hajnocziio writev $offset 512 1024 32
738268b767SStefan Hajnoczi
748268b767SStefan Hajnoczi_check_test_img
758268b767SStefan Hajnoczi
768268b767SStefan Hajnocziecho "Creating test image with backing file"
778268b767SStefan Hajnocziecho
788268b767SStefan Hajnoczi
7949557d65SFam ZhengTEST_IMG="$TEST_IMG_SAVE"
80b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size
818268b767SStefan Hajnoczi
828268b767SStefan Hajnocziecho "Filling test image"
838268b767SStefan Hajnocziecho
848268b767SStefan Hajnoczi
858268b767SStefan Hajnoczi# Write every other sector around where the base image ends
86dd0c35d6SStefan Hajnocziio writev $(( offset + 512 )) 512 1024 64
878268b767SStefan Hajnoczi
888268b767SStefan Hajnoczi_check_test_img
898268b767SStefan Hajnoczi
908268b767SStefan Hajnocziecho "Reading"
918268b767SStefan Hajnocziecho
928268b767SStefan Hajnoczi
938268b767SStefan Hajnoczi# Base image sectors
94dd0c35d6SStefan Hajnocziio readv $(( offset )) 512 1024 32
958268b767SStefan Hajnoczi
968268b767SStefan Hajnoczi# Image sectors
97dd0c35d6SStefan Hajnocziio readv $(( offset + 512 )) 512 1024 64
988268b767SStefan Hajnoczi
998268b767SStefan Hajnoczi# Zero sectors beyond end of base image
100dd0c35d6SStefan Hajnocziio_zero readv $(( offset + 32 * 1024 )) 512 1024 32
1018268b767SStefan Hajnoczi
1028268b767SStefan Hajnoczi_check_test_img
1038268b767SStefan Hajnoczi
1046ce2d77aSKevin Wolf# Rebase it on top of its base image
105b66ff2c2SEric Blake$QEMU_IMG rebase -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG"
1066ce2d77aSKevin Wolf
107d40593ddSKevin Wolfecho
108d40593ddSKevin Wolfecho block-backup
109d40593ddSKevin Wolfecho
110d40593ddSKevin Wolf
111d40593ddSKevin Wolfqemu_comm_method="monitor"
1128dff69b9SAarushi Mehta_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk
113d40593ddSKevin Wolfh=$QEMU_HANDLE
114fbd1c378SAndrey Shinkevichif [ "${VALGRIND_QEMU}" == "y" ]; then
115fbd1c378SAndrey Shinkevich    QEMU_COMM_TIMEOUT=7
116fbd1c378SAndrey Shinkevichelse
117d40593ddSKevin Wolf    QEMU_COMM_TIMEOUT=1
118fbd1c378SAndrey Shinkevichfi
119d40593ddSKevin Wolf
120620a628dSMax ReitzTEST_IMG="$TEST_IMG.copy" _make_test_img $image_size
121620a628dSMax Reitz_send_qemu_cmd $h "drive_backup -n disk ${TEST_IMG}.copy" "(qemu)" \
122620a628dSMax Reitz    | _filter_imgfmt
123620a628dSMax Reitz
12448c8d3ceSMax Reitzsilent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs"
125a174da36SEric Blake_send_qemu_cmd $h "info block-jobs" "No active jobs"
126d40593ddSKevin Wolf_send_qemu_cmd $h 'quit' ""
127d40593ddSKevin Wolf
128d40593ddSKevin Wolf# Base image sectors
129d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32
130d40593ddSKevin Wolf
131d40593ddSKevin Wolf# Image sectors
132d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64
133d40593ddSKevin Wolf
134d40593ddSKevin Wolf# Zero sectors beyond end of base image
135d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
136d40593ddSKevin Wolf
137d40593ddSKevin Wolf
1386ce2d77aSKevin Wolf_check_test_img
1396ce2d77aSKevin Wolf
140ae159450SMax Reitzecho
141ae159450SMax Reitzecho '=== Reading across backing EOF in one operation ==='
142ae159450SMax Reitzecho
143ae159450SMax Reitz
144ae159450SMax Reitz# Use a cluster boundary as the base end here
145ae159450SMax Reitzbase_size=$((3 * 1024 * 1024 * 1024))
146ae159450SMax Reitz
147ae159450SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img $base_size
148ae159450SMax Reitz_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size
149ae159450SMax Reitz
150ae159450SMax Reitz# Write 16 times 42 at the end of the base image
151ae159450SMax Reitz$QEMU_IO -c "write -P 42 $((base_size - 16)) 16" "$TEST_IMG.base" \
152ae159450SMax Reitz    | _filter_qemu_io
153ae159450SMax Reitz
154ae159450SMax Reitz# Read 32 bytes across the base EOF from the top;
155ae159450SMax Reitz# should be 16 times 0x2a, then 16 times 0x00
156ae159450SMax Reitz$QEMU_IO -c "read -v $((base_size - 16)) 32" "$TEST_IMG" \
157ae159450SMax Reitz    | _filter_qemu_io
158ae159450SMax Reitz
1598268b767SStefan Hajnoczi# success, all done
1608268b767SStefan Hajnocziecho "*** done"
1618268b767SStefan Hajnoczirm -f $seq.full
1628268b767SStefan Hajnoczistatus=0
163