cryptospore / rpms / qemu-kvm

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