9ae3a8
From 36dbb9edadf3cd22fd6f0da96cf293da35b0234c Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Sat, 13 Jun 2015 16:22:05 +0200
9ae3a8
Subject: [PATCH 11/42] iotests: Add more tests for qcow2 corruption
9ae3a8
9ae3a8
Message-id: <1434212556-3927-12-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 66030
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 11/42] iotests: Add more tests for qcow2 corruption
9ae3a8
Bugzilla: 1129893
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1129893
9ae3a8
9ae3a8
Add tests for unaligned L1/L2/reftable entries and non-fatal corruption
9ae3a8
reports.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Message-id: 1409926039-29044-6-git-send-email-mreitz@redhat.com
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 5b0ed2be883238f52567ba2635ea38f34e8eb90d)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 tests/qemu-iotests/060     | 56 ++++++++++++++++++++++++++++++++++++++++++++--
9ae3a8
 tests/qemu-iotests/060.out | 51 +++++++++++++++++++++++++++++++++++++++++
9ae3a8
 2 files changed, 105 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060
9ae3a8
index 5180e23..e1187a3 100644
9ae3a8
--- a/tests/qemu-iotests/060
9ae3a8
+++ b/tests/qemu-iotests/060
9ae3a8
@@ -169,9 +169,61 @@ echo "=== Testing unallocated image header ==="
9ae3a8
 echo
9ae3a8
 _make_test_img 64M
9ae3a8
 # Create L1/L2
9ae3a8
-$QEMU_IO -c "$OPEN_RW" -c "write 0 64k" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
 poke_file "$TEST_IMG" "$rb_offset" "\x00\x00"
9ae3a8
-$QEMU_IO -c "$OPEN_RW" -c "write 64k 64k" | _filter_qemu_io
9ae3a8
+$QEMU_IO -c "write 64k 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing unaligned L1 entry ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+# This will be masked with ~(512 - 1) = ~0x1ff, so whether the lower 9 bits are
9ae3a8
+# aligned or not does not matter
9ae3a8
+poke_file "$TEST_IMG" "$l1_offset" "\x80\x00\x00\x00\x00\x04\x2a\x00"
9ae3a8
+$QEMU_IO -c "read 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing unaligned L2 entry ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00"
9ae3a8
+$QEMU_IO -c "read 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing unaligned reftable entry ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+poke_file "$TEST_IMG" "$rt_offset" "\x00\x00\x00\x00\x00\x02\x2a\x00"
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing non-fatal corruption on freeing ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00"
9ae3a8
+$QEMU_IO -c "discard 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing read-only corruption report ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "write 0 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+poke_file "$TEST_IMG" "$l2_offset" "\x80\x00\x00\x00\x00\x05\x2a\x00"
9ae3a8
+# Should only emit a single error message
9ae3a8
+$QEMU_IO -c "$OPEN_RO" -c "read 0 64k" -c "read 0 64k" | _filter_qemu_io
9ae3a8
+
9ae3a8
+echo
9ae3a8
+echo "=== Testing non-fatal and then fatal corruption report ==="
9ae3a8
+echo
9ae3a8
+_make_test_img 64M
9ae3a8
+$QEMU_IO -c "write 0 128k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
+poke_file "$TEST_IMG" "$l2_offset"        "\x80\x00\x00\x00\x00\x05\x2a\x00"
9ae3a8
+poke_file "$TEST_IMG" "$(($l2_offset+8))" "\x80\x00\x00\x00\x00\x06\x2a\x00"
9ae3a8
+# Should emit two error messages
9ae3a8
+$QEMU_IO -c "discard 0 64k" -c "read 64k 64k" "$TEST_IMG" | _filter_qemu_io
9ae3a8
 
9ae3a8
 # success, all done
9ae3a8
 echo "*** done"
9ae3a8
diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out
9ae3a8
index 30806da..4f0c6d0 100644
9ae3a8
--- a/tests/qemu-iotests/060.out
9ae3a8
+++ b/tests/qemu-iotests/060.out
9ae3a8
@@ -101,4 +101,55 @@ wrote 65536/65536 bytes at offset 0
9ae3a8
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
 qcow2: Marking image as corrupt: Preventing invalid write on metadata (overlaps with qcow2_header); further corruption events will be suppressed
9ae3a8
 write failed: Input/output error
9ae3a8
+
9ae3a8
+=== Testing unaligned L1 entry ===
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
+qcow2: Marking image as corrupt: L2 table offset 0x42a00 unaligned (L1 index: 0); further corruption events will be suppressed
9ae3a8
+read failed: Input/output error
9ae3a8
+
9ae3a8
+=== Testing unaligned L2 entry ===
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
+qcow2: Marking image as corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further corruption events will be suppressed
9ae3a8
+read failed: Input/output error
9ae3a8
+
9ae3a8
+=== Testing unaligned reftable entry ===
9ae3a8
+
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
9ae3a8
+qcow2: Marking image as corrupt: Refblock offset 0x22a00 unaligned (reftable index: 0); further corruption events will be suppressed
9ae3a8
+write failed: Input/output error
9ae3a8
+
9ae3a8
+=== Testing non-fatal corruption on freeing ===
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
+qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further non-fatal corruption events will be suppressed
9ae3a8
+discard 65536/65536 bytes at offset 0
9ae3a8
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+
9ae3a8
+=== Testing read-only corruption report ===
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
+qcow2: Image is corrupt: Data cluster offset 0x52a00 unaligned (L2 offset: 0x40000, L2 index: 0); further non-fatal corruption events will be suppressed
9ae3a8
+read failed: Input/output error
9ae3a8
+read failed: Input/output error
9ae3a8
+
9ae3a8
+=== Testing non-fatal and then fatal corruption report ===
9ae3a8
+
9ae3a8
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 
9ae3a8
+wrote 131072/131072 bytes at offset 0
9ae3a8
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+qcow2: Image is corrupt: Cannot free unaligned cluster 0x52a00; further non-fatal corruption events will be suppressed
9ae3a8
+qcow2: Marking image as corrupt: Data cluster offset 0x62a00 unaligned (L2 offset: 0x40000, L2 index: 0x1); further corruption events will be suppressed
9ae3a8
+discard 65536/65536 bytes at offset 0
9ae3a8
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
9ae3a8
+read failed: Input/output error
9ae3a8
 *** done
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8