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

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