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