1*184581faSAlberto Garcia#!/usr/bin/env bash 2*184581faSAlberto Garcia# 3*184581faSAlberto Garcia# Test the handling of errors in write requests with multiple allocations 4*184581faSAlberto Garcia# 5*184581faSAlberto Garcia# Copyright (C) 2020 Igalia, S.L. 6*184581faSAlberto Garcia# Author: Alberto Garcia <berto@igalia.com> 7*184581faSAlberto Garcia# 8*184581faSAlberto Garcia# This program is free software; you can redistribute it and/or modify 9*184581faSAlberto Garcia# it under the terms of the GNU General Public License as published by 10*184581faSAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 11*184581faSAlberto Garcia# (at your option) any later version. 12*184581faSAlberto Garcia# 13*184581faSAlberto Garcia# This program is distributed in the hope that it will be useful, 14*184581faSAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*184581faSAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*184581faSAlberto Garcia# GNU General Public License for more details. 17*184581faSAlberto Garcia# 18*184581faSAlberto Garcia# You should have received a copy of the GNU General Public License 19*184581faSAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*184581faSAlberto Garcia# 21*184581faSAlberto Garcia 22*184581faSAlberto Garcia# creator 23*184581faSAlberto Garciaowner=berto@igalia.com 24*184581faSAlberto Garcia 25*184581faSAlberto Garciaseq=`basename $0` 26*184581faSAlberto Garciaecho "QA output created by $seq" 27*184581faSAlberto Garcia 28*184581faSAlberto Garciastatus=1 # failure is the default! 29*184581faSAlberto Garcia 30*184581faSAlberto Garcia_cleanup() 31*184581faSAlberto Garcia{ 32*184581faSAlberto Garcia _cleanup_test_img 33*184581faSAlberto Garcia} 34*184581faSAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15 35*184581faSAlberto Garcia 36*184581faSAlberto Garcia# get standard environment, filters and checks 37*184581faSAlberto Garcia. ./common.rc 38*184581faSAlberto Garcia. ./common.filter 39*184581faSAlberto Garcia 40*184581faSAlberto Garcia_supported_fmt qcow2 41*184581faSAlberto Garcia_supported_proto file 42*184581faSAlberto Garcia_supported_os Linux 43*184581faSAlberto Garcia_unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file 44*184581faSAlberto Garcia 45*184581faSAlberto Garciaecho '### Create the image' 46*184581faSAlberto Garcia_make_test_img -o refcount_bits=64,cluster_size=1k 1M 47*184581faSAlberto Garcia 48*184581faSAlberto Garcia# The reference counts of the clusters for the first 123k of this 49*184581faSAlberto Garcia# write request are stored in the first refcount block. The last 50*184581faSAlberto Garcia# cluster (guest offset 123k) is referenced in the second refcount 51*184581faSAlberto Garcia# block. 52*184581faSAlberto Garciaecho '### Fill the first refcount block and one data cluster from the second' 53*184581faSAlberto Garcia$QEMU_IO -c 'write 0 124k' "$TEST_IMG" | _filter_qemu_io 54*184581faSAlberto Garcia 55*184581faSAlberto Garciaecho '### Discard two of the last data clusters, leave one in the middle' 56*184581faSAlberto Garcia$QEMU_IO -c 'discard 121k 1k' "$TEST_IMG" | _filter_qemu_io 57*184581faSAlberto Garcia$QEMU_IO -c 'discard 123k 1k' "$TEST_IMG" | _filter_qemu_io 58*184581faSAlberto Garcia 59*184581faSAlberto Garciaecho '### Corrupt the offset of the second refcount block' 60*184581faSAlberto Garciarefcount_table_offset=$(peek_file_be "$TEST_IMG" 48 8) 61*184581faSAlberto Garciapoke_file "$TEST_IMG" $(($refcount_table_offset+14)) "\x06" 62*184581faSAlberto Garcia 63*184581faSAlberto Garcia# This tries to allocate the two clusters discarded earlier (guest 64*184581faSAlberto Garcia# offsets 121k and 123k). Their reference counts are in the first and 65*184581faSAlberto Garcia# second refcount blocks respectively, but only the first one can be 66*184581faSAlberto Garcia# allocated correctly because the second entry of the refcount table 67*184581faSAlberto Garcia# is corrupted. 68*184581faSAlberto Garciaecho '### Try to allocate the discarded clusters again' 69*184581faSAlberto Garcia$QEMU_IO -c 'write 121k 3k' "$TEST_IMG" | _filter_qemu_io 70*184581faSAlberto Garcia 71*184581faSAlberto Garcia# success, all done 72*184581faSAlberto Garciaecho "*** done" 73*184581faSAlberto Garciarm -f $seq.full 74*184581faSAlberto Garciastatus=0 75