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