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