26ba25
From 79f400ed6efa42347cd551a4a2da3ba1688c431c Mon Sep 17 00:00:00 2001
26ba25
From: Max Reitz <mreitz@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 18:04:51 +0200
26ba25
Subject: [PATCH 074/268] iotests: Test post-backing convert target behavior
26ba25
26ba25
RH-Author: Max Reitz <mreitz@redhat.com>
26ba25
Message-id: <20180618180451.23808-3-mreitz@redhat.com>
26ba25
Patchwork-id: 80797
26ba25
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 2/2] iotests: Test post-backing convert target behavior
26ba25
Bugzilla: 1527898
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
26ba25
This adds a test case to 122 for what happens when you convert to a
26ba25
target with a backing file that is shorter than the target, and the
26ba25
image format does not support efficient zero writes (as is the case with
26ba25
qcow2 v2).
26ba25
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
Message-id: 20180501165750.19242-3-mreitz@redhat.com
26ba25
Reviewed-by: Eric Blake <eblake@redhat.com>
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit 0682854f899d03c78befce9f5aae4a7e37655d25)
26ba25
Signed-off-by: Max Reitz <mreitz@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 tests/qemu-iotests/122     | 42 ++++++++++++++++++++++++++++++++++++++++++
26ba25
 tests/qemu-iotests/122.out | 18 ++++++++++++++++++
26ba25
 2 files changed, 60 insertions(+)
26ba25
26ba25
diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122
26ba25
index 45b359c..d8c8ad7 100755
26ba25
--- a/tests/qemu-iotests/122
26ba25
+++ b/tests/qemu-iotests/122
26ba25
@@ -77,6 +77,48 @@ $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_t
26ba25
 
26ba25
 
26ba25
 echo
26ba25
+echo "=== Converting to an overlay larger than its backing file ==="
26ba25
+echo
26ba25
+
26ba25
+TEST_IMG="$TEST_IMG".base _make_test_img 256M
26ba25
+# Needs to be at least how much an L2 table covers
26ba25
+# (64 kB/entry * 64 kB / 8 B/entry = 512 MB)
26ba25
+# That way, qcow2 will yield at least two status request responses.
26ba25
+# With just a single response, it would always say "Allocated in the
26ba25
+# backing file", so the optimization qemu-img convert tries to do is
26ba25
+# done automatically.  Once it has to be queried twice, however (and
26ba25
+# one of the queries is completely after the end of the backing file),
26ba25
+# the block layer will automatically add a ZERO flag that qemu-img
26ba25
+# convert used to follow up with a zero write to the target.
26ba25
+# We do not want such a zero write, however, because we are past the
26ba25
+# end of the backing file on the target as well, so we do not need to
26ba25
+# write anything there.
26ba25
+_make_test_img -b "$TEST_IMG".base 768M
26ba25
+
26ba25
+# Use compat=0.10 as the output so there is no zero cluster support
26ba25
+$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
26ba25
+    "$TEST_IMG" "$TEST_IMG".orig
26ba25
+# See that nothing has been allocated past 64M
26ba25
+$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
26ba25
+
26ba25
+echo
26ba25
+
26ba25
+# Just before the end of the backing file
26ba25
+$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io
26ba25
+# Somewhere in the second L2 table
26ba25
+$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io
26ba25
+
26ba25
+$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
26ba25
+    "$TEST_IMG" "$TEST_IMG".orig
26ba25
+
26ba25
+$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
26ba25
+$QEMU_IO -c 'read -P 0x11 255M 1M' \
26ba25
+         -c 'read -P 0x22 600M 1M' \
26ba25
+         "$TEST_IMG".orig \
26ba25
+    | _filter_qemu_io
26ba25
+
26ba25
+
26ba25
+echo
26ba25
 echo "=== Concatenate multiple source images ==="
26ba25
 echo
26ba25
 
26ba25
diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out
26ba25
index 47d8656..6c7ee1d 100644
26ba25
--- a/tests/qemu-iotests/122.out
26ba25
+++ b/tests/qemu-iotests/122.out
26ba25
@@ -28,6 +28,24 @@ read 3145728/3145728 bytes at offset 0
26ba25
 read 3145728/3145728 bytes at offset 0
26ba25
 3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
26ba25
 
26ba25
+=== Converting to an overlay larger than its backing file ===
26ba25
+
26ba25
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=268435456
26ba25
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=805306368 backing_file=TEST_DIR/t.IMGFMT.base
26ba25
+Offset          Length          File
26ba25
+
26ba25
+wrote 1048576/1048576 bytes at offset 267386880
26ba25
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
26ba25
+wrote 1048576/1048576 bytes at offset 629145600
26ba25
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
26ba25
+Offset          Length          File
26ba25
+0xff00000       0x100000        TEST_DIR/t.IMGFMT.base
26ba25
+0x25800000      0x100000        TEST_DIR/t.IMGFMT.orig
26ba25
+read 1048576/1048576 bytes at offset 267386880
26ba25
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
26ba25
+read 1048576/1048576 bytes at offset 629145600
26ba25
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
26ba25
+
26ba25
 === Concatenate multiple source images ===
26ba25
 
26ba25
 Formatting 'TEST_DIR/t.IMGFMT.1', fmt=IMGFMT size=4194304
26ba25
-- 
26ba25
1.8.3.1
26ba25