thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-iotests-Test-unaligned-raw-images-with-O_DIRECT.patch

4ec855
From d193f7ee2bf7822408fa9a92b7e170330b7f6ec4 Mon Sep 17 00:00:00 2001
4ec855
From: Max Reitz <mreitz@redhat.com>
4ec855
Date: Tue, 23 Jul 2019 14:45:41 +0100
4ec855
Subject: [PATCH 03/14] iotests: Test unaligned raw images with O_DIRECT
4ec855
4ec855
RH-Author: Max Reitz <mreitz@redhat.com>
4ec855
Message-id: <20190723144546.23701-3-mreitz@redhat.com>
4ec855
Patchwork-id: 89648
4ec855
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 2/7] iotests: Test unaligned raw images with O_DIRECT
4ec855
Bugzilla: 1678979
4ec855
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
4ec855
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
4ec855
RH-Acked-by: John Snow <jsnow@redhat.com>
4ec855
4ec855
We already have 221 for accesses through the page cache, but it is
4ec855
better to create a new file for O_DIRECT instead of integrating those
4ec855
test cases into 221.  This way, we can make use of
4ec855
_supported_cache_modes (and _default_cache_mode) so the test is
4ec855
automatically skipped on filesystems that do not support O_DIRECT.
4ec855
4ec855
As part of the split, add _supported_cache_modes to 221.  With that, it
4ec855
no longer fails when run with -c none or -c directsync.
4ec855
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
Reviewed-by: Eric Blake <eblake@redhat.com>
4ec855
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
4ec855
(cherry picked from commit 2fab30c80b33cdc6157c7efe6207e54b6835cf92)
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 tests/qemu-iotests/221     |  4 +++
4ec855
 tests/qemu-iotests/253     | 84 ++++++++++++++++++++++++++++++++++++++++++++++
4ec855
 tests/qemu-iotests/253.out | 14 ++++++++
4ec855
 tests/qemu-iotests/group   |  1 +
4ec855
 4 files changed, 103 insertions(+)
4ec855
 create mode 100755 tests/qemu-iotests/253
4ec855
 create mode 100644 tests/qemu-iotests/253.out
4ec855
4ec855
diff --git a/tests/qemu-iotests/221 b/tests/qemu-iotests/221
4ec855
index 41c4e4b..2cc29ba 100755
4ec855
--- a/tests/qemu-iotests/221
4ec855
+++ b/tests/qemu-iotests/221
4ec855
@@ -1,6 +1,7 @@
4ec855
 #!/bin/bash
4ec855
 #
4ec855
 # Test qemu-img vs. unaligned images
4ec855
+# (See also 253, which is the O_DIRECT version)
4ec855
 #
4ec855
 # Copyright (C) 2018 Red Hat, Inc.
4ec855
 #
4ec855
@@ -38,6 +39,9 @@ _supported_fmt raw
4ec855
 _supported_proto file
4ec855
 _supported_os Linux
4ec855
 
4ec855
+_default_cache_mode writeback
4ec855
+_supported_cache_modes writeback writethrough unsafe
4ec855
+
4ec855
 echo
4ec855
 echo "=== Check mapping of unaligned raw image ==="
4ec855
 echo
4ec855
diff --git a/tests/qemu-iotests/253 b/tests/qemu-iotests/253
4ec855
new file mode 100755
4ec855
index 0000000..d88d5af
4ec855
--- /dev/null
4ec855
+++ b/tests/qemu-iotests/253
4ec855
@@ -0,0 +1,84 @@
4ec855
+#!/usr/bin/env bash
4ec855
+#
4ec855
+# Test qemu-img vs. unaligned images; O_DIRECT version
4ec855
+# (Originates from 221)
4ec855
+#
4ec855
+# Copyright (C) 2019 Red Hat, Inc.
4ec855
+#
4ec855
+# This program is free software; you can redistribute it and/or modify
4ec855
+# it under the terms of the GNU General Public License as published by
4ec855
+# the Free Software Foundation; either version 2 of the License, or
4ec855
+# (at your option) any later version.
4ec855
+#
4ec855
+# This program is distributed in the hope that it will be useful,
4ec855
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
4ec855
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4ec855
+# GNU General Public License for more details.
4ec855
+#
4ec855
+# You should have received a copy of the GNU General Public License
4ec855
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
4ec855
+#
4ec855
+
4ec855
+seq="$(basename $0)"
4ec855
+echo "QA output created by $seq"
4ec855
+
4ec855
+status=1 # failure is the default!
4ec855
+
4ec855
+_cleanup()
4ec855
+{
4ec855
+    _cleanup_test_img
4ec855
+}
4ec855
+trap "_cleanup; exit \$status" 0 1 2 3 15
4ec855
+
4ec855
+# get standard environment, filters and checks
4ec855
+. ./common.rc
4ec855
+. ./common.filter
4ec855
+
4ec855
+_supported_fmt raw
4ec855
+_supported_proto file
4ec855
+_supported_os Linux
4ec855
+
4ec855
+_default_cache_mode none
4ec855
+_supported_cache_modes none directsync
4ec855
+
4ec855
+echo
4ec855
+echo "=== Check mapping of unaligned raw image ==="
4ec855
+echo
4ec855
+
4ec855
+# We do not know how large a physical sector is, but it is certainly
4ec855
+# going to be a factor of 1 MB
4ec855
+size=$((1 * 1024 * 1024 - 1))
4ec855
+
4ec855
+# qemu-img create rounds size up to BDRV_SECTOR_SIZE
4ec855
+_make_test_img $size
4ec855
+$QEMU_IMG map --output=json --image-opts \
4ec855
+    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
4ec855
+    | _filter_qemu_img_map
4ec855
+
4ec855
+# so we resize it and check again
4ec855
+truncate --size=$size "$TEST_IMG"
4ec855
+$QEMU_IMG map --output=json --image-opts \
4ec855
+    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
4ec855
+    | _filter_qemu_img_map
4ec855
+
4ec855
+# qemu-io with O_DIRECT always writes whole physical sectors.  Again,
4ec855
+# we do not know how large a physical sector is, so we just start
4ec855
+# writing from a 64 kB boundary, which should always be aligned.
4ec855
+offset=$((1 * 1024 * 1024 - 64 * 1024))
4ec855
+$QEMU_IO -c "w $offset $((size - offset))" "$TEST_IMG" | _filter_qemu_io
4ec855
+$QEMU_IMG map --output=json --image-opts \
4ec855
+    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
4ec855
+    | _filter_qemu_img_map
4ec855
+
4ec855
+# Resize it and check again -- contrary to 221, we may not get partial
4ec855
+# sectors here, so there should be only two areas (one zero, one
4ec855
+# data).
4ec855
+truncate --size=$size "$TEST_IMG"
4ec855
+$QEMU_IMG map --output=json --image-opts \
4ec855
+    "driver=$IMGFMT,file.driver=file,file.filename=$TEST_IMG,cache.direct=on" \
4ec855
+    | _filter_qemu_img_map
4ec855
+
4ec855
+# success, all done
4ec855
+echo '*** done'
4ec855
+rm -f $seq.full
4ec855
+status=0
4ec855
diff --git a/tests/qemu-iotests/253.out b/tests/qemu-iotests/253.out
4ec855
new file mode 100644
4ec855
index 0000000..607c0ba
4ec855
--- /dev/null
4ec855
+++ b/tests/qemu-iotests/253.out
4ec855
@@ -0,0 +1,14 @@
4ec855
+QA output created by 253
4ec855
+
4ec855
+=== Check mapping of unaligned raw image ===
4ec855
+
4ec855
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048575
4ec855
+[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
4ec855
+[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false, "offset": OFFSET}]
4ec855
+wrote 65535/65535 bytes at offset 983040
4ec855
+63.999 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
4ec855
+[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
4ec855
+{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
4ec855
+[{ "start": 0, "length": 983040, "depth": 0, "zero": true, "data": false, "offset": OFFSET},
4ec855
+{ "start": 983040, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
4ec855
+*** done
4ec855
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
4ec855
index 5cbdc24..b356d82 100644
4ec855
--- a/tests/qemu-iotests/group
4ec855
+++ b/tests/qemu-iotests/group
4ec855
@@ -227,3 +227,4 @@
4ec855
 232 auto quick
4ec855
 234 auto quick migration
4ec855
 240 auto quick
4ec855
+253 rw auto quick
4ec855
-- 
4ec855
1.8.3.1
4ec855