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