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