yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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