Blame SOURCES/kvm-iotests-Copy-197-for-COR-filter-driver.patch

357786
From 6acc674a6d77b4d1b36545c7f00251b264f99d78 Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 18 Jun 2018 16:12:11 +0200
357786
Subject: [PATCH 35/54] iotests: Copy 197 for COR filter driver
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180618161212.14444-10-mreitz@redhat.com>
357786
Patchwork-id: 80769
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 09/10] iotests: Copy 197 for COR filter driver
357786
Bugzilla: 1518738
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
357786
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
iotest 197 tests copy-on-read using the (now old) copy-on-read flag.
357786
Copy it to 215 and modify it to use the COR filter driver instead.
357786
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Message-id: 20180421132929.21610-9-mreitz@redhat.com
357786
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit a62cbac4ce2db79c14ff299e98ee556b57467c19)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 tests/qemu-iotests/215     | 120 +++++++++++++++++++++++++++++++++++++++++++++
357786
 tests/qemu-iotests/215.out |  26 ++++++++++
357786
 tests/qemu-iotests/group   |   1 +
357786
 3 files changed, 147 insertions(+)
357786
 create mode 100755 tests/qemu-iotests/215
357786
 create mode 100644 tests/qemu-iotests/215.out
357786
357786
diff --git a/tests/qemu-iotests/215 b/tests/qemu-iotests/215
357786
new file mode 100755
357786
index 0000000..2e616ed
357786
--- /dev/null
357786
+++ b/tests/qemu-iotests/215
357786
@@ -0,0 +1,120 @@
357786
+#!/bin/bash
357786
+#
357786
+# Test case for copy-on-read into qcow2, using the COR filter driver
357786
+#
357786
+# Copyright (C) 2018 Red Hat, Inc.
357786
+#
357786
+# This program is free software; you can redistribute it and/or modify
357786
+# it under the terms of the GNU General Public License as published by
357786
+# the Free Software Foundation; either version 2 of the License, or
357786
+# (at your option) any later version.
357786
+#
357786
+# This program is distributed in the hope that it will be useful,
357786
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
357786
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
357786
+# GNU General Public License for more details.
357786
+#
357786
+# You should have received a copy of the GNU General Public License
357786
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
357786
+#
357786
+
357786
+seq="$(basename $0)"
357786
+echo "QA output created by $seq"
357786
+
357786
+here="$PWD"
357786
+status=1 # failure is the default!
357786
+
357786
+# get standard environment, filters and checks
357786
+. ./common.rc
357786
+. ./common.filter
357786
+
357786
+TEST_WRAP="$TEST_DIR/t.wrap.qcow2"
357786
+BLKDBG_CONF="$TEST_DIR/blkdebug.conf"
357786
+
357786
+# Sanity check: our use of blkdebug fails if $TEST_DIR contains spaces
357786
+# or other problems
357786
+case "$TEST_DIR" in
357786
+    *[^-_a-zA-Z0-9/]*)
357786
+        _notrun "Suspicious TEST_DIR='$TEST_DIR', cowardly refusing to run" ;;
357786
+esac
357786
+
357786
+_cleanup()
357786
+{
357786
+    _cleanup_test_img
357786
+    rm -f "$TEST_WRAP"
357786
+    rm -f "$BLKDBG_CONF"
357786
+}
357786
+trap "_cleanup; exit \$status" 0 1 2 3 15
357786
+
357786
+# Test is supported for any backing file; but we force qcow2 for our wrapper.
357786
+_supported_fmt generic
357786
+_supported_proto generic
357786
+_supported_os Linux
357786
+# LUKS support may be possible, but it complicates things.
357786
+_unsupported_fmt luks
357786
+
357786
+echo
357786
+echo '=== Copy-on-read ==='
357786
+echo
357786
+
357786
+# Prep the images
357786
+# VPC rounds image sizes to a specific geometry, force a specific size.
357786
+if [ "$IMGFMT" = "vpc" ]; then
357786
+    IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size")
357786
+fi
357786
+_make_test_img 4G
357786
+$QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io
357786
+IMGPROTO=file IMGFMT=qcow2 IMGOPTS= TEST_IMG_FILE="$TEST_WRAP" \
357786
+    _make_test_img -F "$IMGFMT" -b "$TEST_IMG" | _filter_img_create
357786
+$QEMU_IO -f qcow2 -c "write -z -u 1M 64k" "$TEST_WRAP" | _filter_qemu_io
357786
+
357786
+# Ensure that a read of two clusters, but where one is already allocated,
357786
+# does not re-write the allocated cluster
357786
+cat > "$BLKDBG_CONF" <
357786
+[inject-error]
357786
+event = "cor_write"
357786
+sector = "2048"
357786
+EOF
357786
+$QEMU_IO -c "open \
357786
+ -o driver=copy-on-read,file.driver=blkdebug,file.config=$BLKDBG_CONF,file.image.driver=qcow2 $TEST_WRAP" \
357786
+ -c "read -P 0 1M 128k" | _filter_qemu_io
357786
+
357786
+# Read the areas we want copied. A zero-length read should still be a
357786
+# no-op.  The next read is under 2G, but aligned so that rounding to
357786
+# clusters copies more than 2G of zeroes. The final read will pick up
357786
+# the non-zero data in the same cluster.  Since a 2G read may exhaust
357786
+# memory on some machines (particularly 32-bit), we skip the test if
357786
+# that fails due to memory pressure.
357786
+$QEMU_IO \
357786
+    -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
357786
+    -c "read 0 0" \
357786
+    | _filter_qemu_io
357786
+output=$($QEMU_IO \
357786
+         -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
357786
+         -c "read -P 0 1k $((2*1024*1024*1024 - 512))" \
357786
+         2>&1 | _filter_qemu_io)
357786
+case $output in
357786
+    *allocate*)
357786
+        _notrun "Insufficent memory to run test" ;;
357786
+    *) printf '%s\n' "$output" ;;
357786
+esac
357786
+$QEMU_IO \
357786
+    -c "open -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
357786
+    -c "read -P 0 $((3*1024*1024*1024 + 1024)) 1k" \
357786
+    | _filter_qemu_io
357786
+
357786
+# Copy-on-read is incompatible with read-only
357786
+$QEMU_IO \
357786
+    -c "open -r -o driver=copy-on-read,file.driver=qcow2 $TEST_WRAP" \
357786
+    2>&1 | _filter_testdir
357786
+
357786
+# Break the backing chain, and show that images are identical, and that
357786
+# we properly copied over explicit zeros.
357786
+$QEMU_IMG rebase -u -b "" -f qcow2 "$TEST_WRAP"
357786
+$QEMU_IO -f qcow2 -c map "$TEST_WRAP"
357786
+_check_test_img
357786
+$QEMU_IMG compare -f $IMGFMT -F qcow2 "$TEST_IMG" "$TEST_WRAP"
357786
+
357786
+# success, all done
357786
+echo '*** done'
357786
+status=0
357786
diff --git a/tests/qemu-iotests/215.out b/tests/qemu-iotests/215.out
357786
new file mode 100644
357786
index 0000000..70b0f5f
357786
--- /dev/null
357786
+++ b/tests/qemu-iotests/215.out
357786
@@ -0,0 +1,26 @@
357786
+QA output created by 215
357786
+
357786
+=== Copy-on-read ===
357786
+
357786
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296
357786
+wrote 1024/1024 bytes at offset 3221225472
357786
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+Formatting 'TEST_DIR/t.wrap.IMGFMT', fmt=IMGFMT size=4294967296 backing_file=TEST_DIR/t.IMGFMT backing_fmt=IMGFMT
357786
+wrote 65536/65536 bytes at offset 1048576
357786
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+read 131072/131072 bytes at offset 1048576
357786
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+read 0/0 bytes at offset 0
357786
+0 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+read 2147483136/2147483136 bytes at offset 1024
357786
+2 GiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+read 1024/1024 bytes at offset 3221226496
357786
+1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
357786
+can't open device TEST_DIR/t.wrap.qcow2: Block node is read-only
357786
+2 GiB (0x80010000) bytes     allocated at offset 0 bytes (0x0)
357786
+1023.938 MiB (0x3fff0000) bytes not allocated at offset 2 GiB (0x80010000)
357786
+64 KiB (0x10000) bytes     allocated at offset 3 GiB (0xc0000000)
357786
+1023.938 MiB (0x3fff0000) bytes not allocated at offset 3 GiB (0xc0010000)
357786
+No errors were found on the image.
357786
+Images are identical.
357786
+*** done
357786
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
357786
index ba7a2d1..cd5d26c 100644
357786
--- a/tests/qemu-iotests/group
357786
+++ b/tests/qemu-iotests/group
357786
@@ -213,4 +213,5 @@
357786
 212 rw auto quick
357786
 213 rw auto quick
357786
 214 rw auto
357786
+215 rw auto quick
357786
 218 rw auto quick
357786
-- 
357786
1.8.3.1
357786