xref: /openbmc/qemu/tests/qemu-iotests/217 (revision 200dbf37)
1#!/usr/bin/env bash
2#
3# I/O errors when working with internal qcow2 snapshots, and repairing
4# the result
5#
6# Copyright (C) 2018 Red Hat, Inc.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21seq=$(basename $0)
22echo "QA output created by $seq"
23
24status=1	# failure is the default!
25
26_cleanup()
27{
28    _cleanup_test_img
29    rm -f "$TEST_DIR/blkdebug.conf"
30}
31trap "_cleanup; exit \$status" 0 1 2 3 15
32
33# get standard environment, filters and checks
34. ./common.rc
35. ./common.filter
36
37# This test is specific to qcow2
38_supported_fmt qcow2
39_supported_proto file
40
41# This test needs clusters with at least a refcount of 2 so that
42# OFLAG_COPIED is not set.  refcount_bits=1 is therefore unsupported.
43_unsupported_imgopts 'refcount_bits=1[^0-9]'
44
45echo
46echo '=== Simulating an I/O error during snapshot deletion ==='
47echo
48
49_make_test_img 64M
50$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
51
52# Create the snapshot
53$QEMU_IMG snapshot -c foo "$TEST_IMG"
54
55# Verify the snapshot is there
56echo
57_img_info | grep 'Snapshot list'
58echo '(Snapshot filtered)'
59echo
60
61# Try to delete the snapshot (with an error happening when freeing the
62# then leaked clusters)
63cat > "$TEST_DIR/blkdebug.conf" <<EOF
64[inject-error]
65event = "cluster_free"
66errno = "5"
67EOF
68$QEMU_IMG snapshot -d foo "blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
69
70# Verify the snapshot is gone
71echo
72_img_info | grep 'Snapshot list'
73
74# Should only show leaks
75echo '--- Checking test image ---'
76_check_test_img
77
78echo
79
80# As there are only leaks, this should be able to fully repair the
81# image
82echo '--- Repairing test image ---'
83_check_test_img -r leaks
84
85
86# success, all done
87echo '*** done'
88rm -f $seq.full
89status=0
90