1184581faSAlberto Garcia#!/usr/bin/env bash 2184581faSAlberto Garcia# 3184581faSAlberto Garcia# Test the handling of errors in write requests with multiple allocations 4184581faSAlberto Garcia# 5184581faSAlberto Garcia# Copyright (C) 2020 Igalia, S.L. 6184581faSAlberto Garcia# Author: Alberto Garcia <berto@igalia.com> 7184581faSAlberto Garcia# 8184581faSAlberto Garcia# This program is free software; you can redistribute it and/or modify 9184581faSAlberto Garcia# it under the terms of the GNU General Public License as published by 10184581faSAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 11184581faSAlberto Garcia# (at your option) any later version. 12184581faSAlberto Garcia# 13184581faSAlberto Garcia# This program is distributed in the hope that it will be useful, 14184581faSAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 15184581faSAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16184581faSAlberto Garcia# GNU General Public License for more details. 17184581faSAlberto Garcia# 18184581faSAlberto Garcia# You should have received a copy of the GNU General Public License 19184581faSAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 20184581faSAlberto Garcia# 21184581faSAlberto Garcia 22184581faSAlberto Garcia# creator 23184581faSAlberto Garciaowner=berto@igalia.com 24184581faSAlberto Garcia 25184581faSAlberto Garciaseq=`basename $0` 26184581faSAlberto Garciaecho "QA output created by $seq" 27184581faSAlberto Garcia 28184581faSAlberto Garciastatus=1 # failure is the default! 29184581faSAlberto Garcia 30184581faSAlberto Garcia_cleanup() 31184581faSAlberto Garcia{ 32184581faSAlberto Garcia _cleanup_test_img 33184581faSAlberto Garcia} 34184581faSAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15 35184581faSAlberto Garcia 36184581faSAlberto Garcia# get standard environment, filters and checks 37184581faSAlberto Garcia. ./common.rc 38184581faSAlberto Garcia. ./common.filter 39184581faSAlberto Garcia 40184581faSAlberto Garcia_supported_fmt qcow2 41*57284d2aSMax Reitz_supported_proto file fuse 42184581faSAlberto Garcia_supported_os Linux 43184581faSAlberto Garcia_unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file 44184581faSAlberto Garcia 45184581faSAlberto Garciaecho '### Create the image' 46184581faSAlberto Garcia_make_test_img -o refcount_bits=64,cluster_size=1k 1M 47184581faSAlberto Garcia 48184581faSAlberto Garcia# The reference counts of the clusters for the first 123k of this 49184581faSAlberto Garcia# write request are stored in the first refcount block. The last 50184581faSAlberto Garcia# cluster (guest offset 123k) is referenced in the second refcount 51184581faSAlberto Garcia# block. 52184581faSAlberto Garciaecho '### Fill the first refcount block and one data cluster from the second' 53184581faSAlberto Garcia$QEMU_IO -c 'write 0 124k' "$TEST_IMG" | _filter_qemu_io 54184581faSAlberto Garcia 55184581faSAlberto Garciaecho '### Discard two of the last data clusters, leave one in the middle' 56184581faSAlberto Garcia$QEMU_IO -c 'discard 121k 1k' "$TEST_IMG" | _filter_qemu_io 57184581faSAlberto Garcia$QEMU_IO -c 'discard 123k 1k' "$TEST_IMG" | _filter_qemu_io 58184581faSAlberto Garcia 59184581faSAlberto Garciaecho '### Corrupt the offset of the second refcount block' 60184581faSAlberto Garciarefcount_table_offset=$(peek_file_be "$TEST_IMG" 48 8) 61184581faSAlberto Garciapoke_file "$TEST_IMG" $(($refcount_table_offset+14)) "\x06" 62184581faSAlberto Garcia 63184581faSAlberto Garcia# This tries to allocate the two clusters discarded earlier (guest 64184581faSAlberto Garcia# offsets 121k and 123k). Their reference counts are in the first and 65184581faSAlberto Garcia# second refcount blocks respectively, but only the first one can be 66184581faSAlberto Garcia# allocated correctly because the second entry of the refcount table 67184581faSAlberto Garcia# is corrupted. 68184581faSAlberto Garciaecho '### Try to allocate the discarded clusters again' 69184581faSAlberto Garcia$QEMU_IO -c 'write 121k 3k' "$TEST_IMG" | _filter_qemu_io 70184581faSAlberto Garcia 71184581faSAlberto Garcia# success, all done 72184581faSAlberto Garciaecho "*** done" 73184581faSAlberto Garciarm -f $seq.full 74184581faSAlberto Garciastatus=0 75