Blame SOURCES/kvm-iotests-Repairing-error-during-snapshot-deletion.patch

ae23c9
From d18ad7f9dc56a87b3dc6ea111e753ebe3c2b0173 Mon Sep 17 00:00:00 2001
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 17:16:55 +0200
ae23c9
Subject: [PATCH 055/268] iotests: Repairing error during snapshot deletion
ae23c9
ae23c9
RH-Author: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: <20180618171655.25987-3-mreitz@redhat.com>
ae23c9
Patchwork-id: 80784
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 2/2] iotests: Repairing error during snapshot deletion
ae23c9
Bugzilla: 1527085
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
ae23c9
This adds a test for an I/O error during snapshot deletion, and maybe
ae23c9
more importantly, for how to repair the resulting image.  If the
ae23c9
snapshot has been deleted before the error occurs, the only negative
ae23c9
result will be leaked clusters -- and those should be repairable with
ae23c9
qemu-img check -r leaks.
ae23c9
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Message-id: 20180509200059.31125-3-mreitz@redhat.com
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit b41ad73a3bb972eb43cf52d28669f67ea3fe1762)
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 tests/qemu-iotests/217     | 90 ++++++++++++++++++++++++++++++++++++++++++++++
ae23c9
 tests/qemu-iotests/217.out | 42 ++++++++++++++++++++++
ae23c9
 tests/qemu-iotests/group   |  1 +
ae23c9
 3 files changed, 133 insertions(+)
ae23c9
 create mode 100755 tests/qemu-iotests/217
ae23c9
 create mode 100644 tests/qemu-iotests/217.out
ae23c9
ae23c9
diff --git a/tests/qemu-iotests/217 b/tests/qemu-iotests/217
ae23c9
new file mode 100755
ae23c9
index 0000000..d3ab5d7
ae23c9
--- /dev/null
ae23c9
+++ b/tests/qemu-iotests/217
ae23c9
@@ -0,0 +1,90 @@
ae23c9
+#!/bin/bash
ae23c9
+#
ae23c9
+# I/O errors when working with internal qcow2 snapshots, and repairing
ae23c9
+# the result
ae23c9
+#
ae23c9
+# Copyright (C) 2018 Red Hat, Inc.
ae23c9
+#
ae23c9
+# This program is free software; you can redistribute it and/or modify
ae23c9
+# it under the terms of the GNU General Public License as published by
ae23c9
+# the Free Software Foundation; either version 2 of the License, or
ae23c9
+# (at your option) any later version.
ae23c9
+#
ae23c9
+# This program is distributed in the hope that it will be useful,
ae23c9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ae23c9
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ae23c9
+# GNU General Public License for more details.
ae23c9
+#
ae23c9
+# You should have received a copy of the GNU General Public License
ae23c9
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ae23c9
+
ae23c9
+seq=$(basename $0)
ae23c9
+echo "QA output created by $seq"
ae23c9
+
ae23c9
+status=1	# failure is the default!
ae23c9
+
ae23c9
+_cleanup()
ae23c9
+{
ae23c9
+    _cleanup_test_img
ae23c9
+    rm -f "$TEST_DIR/blkdebug.conf"
ae23c9
+}
ae23c9
+trap "_cleanup; exit \$status" 0 1 2 3 15
ae23c9
+
ae23c9
+# get standard environment, filters and checks
ae23c9
+. ./common.rc
ae23c9
+. ./common.filter
ae23c9
+
ae23c9
+# This test is specific to qcow2
ae23c9
+_supported_fmt qcow2
ae23c9
+_supported_proto file
ae23c9
+_supported_os Linux
ae23c9
+
ae23c9
+# This test needs clusters with at least a refcount of 2 so that
ae23c9
+# OFLAG_COPIED is not set.  refcount_bits=1 is therefore unsupported.
ae23c9
+_unsupported_imgopts 'refcount_bits=1[^0-9]'
ae23c9
+
ae23c9
+echo
ae23c9
+echo '=== Simulating an I/O error during snapshot deletion ==='
ae23c9
+echo
ae23c9
+
ae23c9
+_make_test_img 64M
ae23c9
+$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
ae23c9
+
ae23c9
+# Create the snapshot
ae23c9
+$QEMU_IMG snapshot -c foo "$TEST_IMG"
ae23c9
+
ae23c9
+# Verify the snapshot is there
ae23c9
+echo
ae23c9
+_img_info | grep 'Snapshot list'
ae23c9
+echo '(Snapshot filtered)'
ae23c9
+echo
ae23c9
+
ae23c9
+# Try to delete the snapshot (with an error happening when freeing the
ae23c9
+# then leaked clusters)
ae23c9
+cat > "$TEST_DIR/blkdebug.conf" <
ae23c9
+[inject-error]
ae23c9
+event = "cluster_free"
ae23c9
+errno = "5"
ae23c9
+EOF
ae23c9
+$QEMU_IMG snapshot -d foo "blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG"
ae23c9
+
ae23c9
+# Verify the snapshot is gone
ae23c9
+echo
ae23c9
+_img_info | grep 'Snapshot list'
ae23c9
+
ae23c9
+# Should only show leaks
ae23c9
+echo '--- Checking test image ---'
ae23c9
+_check_test_img
ae23c9
+
ae23c9
+echo
ae23c9
+
ae23c9
+# As there are only leaks, this should be able to fully repair the
ae23c9
+# image
ae23c9
+echo '--- Repairing test image ---'
ae23c9
+_check_test_img -r leaks
ae23c9
+
ae23c9
+
ae23c9
+# success, all done
ae23c9
+echo '*** done'
ae23c9
+rm -f $seq.full
ae23c9
+status=0
ae23c9
diff --git a/tests/qemu-iotests/217.out b/tests/qemu-iotests/217.out
ae23c9
new file mode 100644
ae23c9
index 0000000..e3fc40a
ae23c9
--- /dev/null
ae23c9
+++ b/tests/qemu-iotests/217.out
ae23c9
@@ -0,0 +1,42 @@
ae23c9
+QA output created by 217
ae23c9
+
ae23c9
+=== Simulating an I/O error during snapshot deletion ===
ae23c9
+
ae23c9
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
ae23c9
+wrote 65536/65536 bytes at offset 0
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+
ae23c9
+Snapshot list:
ae23c9
+(Snapshot filtered)
ae23c9
+
ae23c9
+qcow2_free_clusters failed: Input/output error
ae23c9
+qemu-img: Could not delete snapshot 'foo': Failed to free the cluster and L1 table: Input/output error
ae23c9
+
ae23c9
+--- Checking test image ---
ae23c9
+Leaked cluster 4 refcount=2 reference=1
ae23c9
+Leaked cluster 5 refcount=2 reference=1
ae23c9
+Leaked cluster 6 refcount=1 reference=0
ae23c9
+Leaked cluster 7 refcount=1 reference=0
ae23c9
+
ae23c9
+4 leaked clusters were found on the image.
ae23c9
+This means waste of disk space, but no harm to data.
ae23c9
+
ae23c9
+--- Repairing test image ---
ae23c9
+Leaked cluster 4 refcount=2 reference=1
ae23c9
+Leaked cluster 5 refcount=2 reference=1
ae23c9
+Leaked cluster 6 refcount=1 reference=0
ae23c9
+Leaked cluster 7 refcount=1 reference=0
ae23c9
+Repairing cluster 4 refcount=2 reference=1
ae23c9
+Repairing cluster 5 refcount=2 reference=1
ae23c9
+Repairing cluster 6 refcount=1 reference=0
ae23c9
+Repairing cluster 7 refcount=1 reference=0
ae23c9
+Repairing OFLAG_COPIED L2 cluster: l1_index=0 l1_entry=40000 refcount=1
ae23c9
+Repairing OFLAG_COPIED data cluster: l2_entry=50000 refcount=1
ae23c9
+The following inconsistencies were found and repaired:
ae23c9
+
ae23c9
+    4 leaked clusters
ae23c9
+    2 corruptions
ae23c9
+
ae23c9
+Double checking the fixed image now...
ae23c9
+No errors were found on the image.
ae23c9
+*** done
ae23c9
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
ae23c9
index d228008..cd7bc29 100644
ae23c9
--- a/tests/qemu-iotests/group
ae23c9
+++ b/tests/qemu-iotests/group
ae23c9
@@ -215,4 +215,5 @@
ae23c9
 214 rw auto
ae23c9
 215 rw auto quick
ae23c9
 216 rw auto quick
ae23c9
+217 rw auto quick
ae23c9
 218 rw auto quick
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9