yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-iotests-Add-test-for-rebasing-with-relative-paths.patch

ae23c9
From 165fabd12568ce69a14a541c762267f7a1d161d1 Mon Sep 17 00:00:00 2001
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 17:48:33 +0200
ae23c9
Subject: [PATCH 072/268] iotests: Add test for rebasing with relative paths
ae23c9
ae23c9
RH-Author: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: <20180618174833.19439-3-mreitz@redhat.com>
ae23c9
Patchwork-id: 80789
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 2/2] iotests: Add test for rebasing with relative paths
ae23c9
Bugzilla: 1569835
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Message-id: 20180509182002.8044-3-mreitz@redhat.com
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit 28036a7f7044fddb79819e3c8fcb4ae5605c60e0)
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 tests/qemu-iotests/024     | 82 ++++++++++++++++++++++++++++++++++++++++++++--
ae23c9
 tests/qemu-iotests/024.out | 30 +++++++++++++++++
ae23c9
 2 files changed, 109 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/tests/qemu-iotests/024 b/tests/qemu-iotests/024
ae23c9
index e0d77ce..4071ed6 100755
ae23c9
--- a/tests/qemu-iotests/024
ae23c9
+++ b/tests/qemu-iotests/024
ae23c9
@@ -29,9 +29,14 @@ status=1	# failure is the default!
ae23c9
 
ae23c9
 _cleanup()
ae23c9
 {
ae23c9
-	_cleanup_test_img
ae23c9
-	rm -f "$TEST_DIR/t.$IMGFMT.base_old"
ae23c9
-	rm -f "$TEST_DIR/t.$IMGFMT.base_new"
ae23c9
+    _cleanup_test_img
ae23c9
+    rm -f "$TEST_DIR/t.$IMGFMT.base_old"
ae23c9
+    rm -f "$TEST_DIR/t.$IMGFMT.base_new"
ae23c9
+
ae23c9
+    rm -f "$TEST_DIR/subdir/t.$IMGFMT"
ae23c9
+    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_old"
ae23c9
+    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_new"
ae23c9
+    rmdir "$TEST_DIR/subdir" 2> /dev/null
ae23c9
 }
ae23c9
 trap "_cleanup; exit \$status" 0 1 2 3 15
ae23c9
 
ae23c9
@@ -123,6 +128,77 @@ io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
ae23c9
 io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
ae23c9
 io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
ae23c9
 
ae23c9
+echo
ae23c9
+echo "=== Test rebase in a subdirectory of the working directory ==="
ae23c9
+echo
ae23c9
+
ae23c9
+# Clean up the old images beforehand so they do not interfere with
ae23c9
+# this test
ae23c9
+_cleanup
ae23c9
+
ae23c9
+mkdir "$TEST_DIR/subdir"
ae23c9
+
ae23c9
+# Relative to the overlay
ae23c9
+BASE_OLD_OREL="t.$IMGFMT.base_old"
ae23c9
+BASE_NEW_OREL="t.$IMGFMT.base_new"
ae23c9
+
ae23c9
+# Relative to $TEST_DIR (which is going to be our working directory)
ae23c9
+OVERLAY_WREL="subdir/t.$IMGFMT"
ae23c9
+
ae23c9
+BASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL"
ae23c9
+BASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL"
ae23c9
+OVERLAY="$TEST_DIR/$OVERLAY_WREL"
ae23c9
+
ae23c9
+# Test done here:
ae23c9
+#
ae23c9
+# Backing (old): 11 11 -- 11
ae23c9
+# Backing (new): -- 22 22 11
ae23c9
+# Overlay:       -- -- -- --
ae23c9
+#
ae23c9
+# Rebasing works, we have verified that above.  Here, we just want to
ae23c9
+# see that rebasing is done for the correct target backing file.
ae23c9
+
ae23c9
+TEST_IMG=$BASE_OLD _make_test_img 1M
ae23c9
+TEST_IMG=$BASE_NEW _make_test_img 1M
ae23c9
+TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" 1M
ae23c9
+
ae23c9
+echo
ae23c9
+
ae23c9
+$QEMU_IO "$BASE_OLD" \
ae23c9
+    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
ae23c9
+    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
ae23c9
+    | _filter_qemu_io
ae23c9
+
ae23c9
+$QEMU_IO "$BASE_NEW" \
ae23c9
+    -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
ae23c9
+    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
ae23c9
+    | _filter_qemu_io
ae23c9
+
ae23c9
+echo
ae23c9
+
ae23c9
+pushd "$TEST_DIR" >/dev/null
ae23c9
+$QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" "$OVERLAY_WREL"
ae23c9
+popd >/dev/null
ae23c9
+
ae23c9
+# Verify the backing path is correct
ae23c9
+TEST_IMG=$OVERLAY _img_info | grep '^backing file'
ae23c9
+
ae23c9
+echo
ae23c9
+
ae23c9
+# Verify the data is correct
ae23c9
+$QEMU_IO "$OVERLAY" \
ae23c9
+    -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
ae23c9
+    -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
ae23c9
+    -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
ae23c9
+    -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
ae23c9
+    | _filter_qemu_io
ae23c9
+
ae23c9
+echo
ae23c9
+
ae23c9
+# Verify that cluster #3 is not allocated (because it is the same in
ae23c9
+# $BASE_OLD and $BASE_NEW)
ae23c9
+$QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
ae23c9
+
ae23c9
 
ae23c9
 # success, all done
ae23c9
 echo "*** done"
ae23c9
diff --git a/tests/qemu-iotests/024.out b/tests/qemu-iotests/024.out
ae23c9
index 33cfaf5..024dc78 100644
ae23c9
--- a/tests/qemu-iotests/024.out
ae23c9
+++ b/tests/qemu-iotests/024.out
ae23c9
@@ -141,4 +141,34 @@ read 65536/65536 bytes at offset 917504
ae23c9
 === IO: pattern 0x00
ae23c9
 read 65536/65536 bytes at offset 983040
ae23c9
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+
ae23c9
+=== Test rebase in a subdirectory of the working directory ===
ae23c9
+
ae23c9
+Formatting 'TEST_DIR/subdir/t.IMGFMT.base_old', fmt=IMGFMT size=1048576
ae23c9
+Formatting 'TEST_DIR/subdir/t.IMGFMT.base_new', fmt=IMGFMT size=1048576
ae23c9
+Formatting 'TEST_DIR/subdir/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=t.IMGFMT.base_old
ae23c9
+
ae23c9
+wrote 131072/131072 bytes at offset 0
ae23c9
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+wrote 65536/65536 bytes at offset 196608
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+wrote 131072/131072 bytes at offset 65536
ae23c9
+128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+wrote 65536/65536 bytes at offset 196608
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+
ae23c9
+backing file: t.IMGFMT.base_new (actual path: TEST_DIR/subdir/t.IMGFMT.base_new)
ae23c9
+
ae23c9
+read 65536/65536 bytes at offset 0
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+read 65536/65536 bytes at offset 65536
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+read 65536/65536 bytes at offset 131072
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+read 65536/65536 bytes at offset 196608
ae23c9
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ae23c9
+
ae23c9
+Offset          Length          File
ae23c9
+0               0x30000         TEST_DIR/subdir/t.IMGFMT
ae23c9
+0x30000         0x10000         TEST_DIR/subdir/t.IMGFMT.base_new
ae23c9
 *** done
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9