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