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