yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-iotests-Test-allocate_first_block-with-O_DIRECT.patch

4ec855
From b4841fd40fefcffc99c4b52c8a06720edb4ef9ef Mon Sep 17 00:00:00 2001
4ec855
From: Thomas Huth <thuth@redhat.com>
4ec855
Date: Fri, 30 Aug 2019 12:56:28 +0100
4ec855
Subject: [PATCH 10/10] iotests: Test allocate_first_block() with O_DIRECT
4ec855
4ec855
RH-Author: Thomas Huth <thuth@redhat.com>
4ec855
Message-id: <20190830125628.23668-6-thuth@redhat.com>
4ec855
Patchwork-id: 90212
4ec855
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH v2 5/5] iotests: Test allocate_first_block() with O_DIRECT
4ec855
Bugzilla: 1738839
4ec855
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
4ec855
RH-Acked-by: Max Reitz <mreitz@redhat.com>
4ec855
RH-Acked-by: David Hildenbrand <david@redhat.com>
4ec855
4ec855
From: Nir Soffer <nirsof@gmail.com>
4ec855
4ec855
Using block_resize we can test allocate_first_block() with file
4ec855
descriptor opened with O_DIRECT, ensuring that it works for any size
4ec855
larger than 4096 bytes.
4ec855
4ec855
Testing smaller sizes is tricky as the result depends on the filesystem
4ec855
used for testing. For example on NFS any size will work since O_DIRECT
4ec855
does not require any alignment.
4ec855
4ec855
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
4ec855
Reviewed-by: Max Reitz <mreitz@redhat.com>
4ec855
Message-id: 20190827010528.8818-3-nsoffer@redhat.com
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
(cherry picked from commit 4656fb5ebbece8c7bbca0bef56bea882c94b9132)
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 tests/qemu-iotests/175     | 28 ++++++++++++++++++++++++++++
4ec855
 tests/qemu-iotests/175.out |  8 ++++++++
4ec855
 2 files changed, 36 insertions(+)
4ec855
4ec855
diff --git a/tests/qemu-iotests/175 b/tests/qemu-iotests/175
4ec855
index b3b7712..74ca49d 100755
4ec855
--- a/tests/qemu-iotests/175
4ec855
+++ b/tests/qemu-iotests/175
4ec855
@@ -50,6 +50,23 @@ _filter_blocks()
4ec855
         -e "s/blocks=$((extra_blocks + img_size / 512))\\(\$\\|[^0-9]\\)/max allocation/"
4ec855
 }
4ec855
 
4ec855
+# Resize image using block_resize.
4ec855
+# Parameter 1: image path
4ec855
+# Parameter 2: new size
4ec855
+_block_resize()
4ec855
+{
4ec855
+    local path=$1
4ec855
+    local size=$2
4ec855
+
4ec855
+    $QEMU -qmp stdio -nographic -nodefaults \
4ec855
+        -blockdev file,node-name=file,filename=$path,cache.direct=on \
4ec855
+        <
4ec855
+{'execute': 'qmp_capabilities'}
4ec855
+{'execute': 'block_resize', 'arguments': {'node-name': 'file', 'size': $size}}
4ec855
+{'execute': 'quit'}
4ec855
+EOF
4ec855
+}
4ec855
+
4ec855
 # get standard environment, filters and checks
4ec855
 . ./common.rc
4ec855
 . ./common.filter
4ec855
@@ -58,6 +75,9 @@ _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
 size=$((1 * 1024 * 1024))
4ec855
 
4ec855
 touch "$TEST_DIR/empty"
4ec855
@@ -80,6 +100,14 @@ for mode in off full falloc; do
4ec855
     stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $size
4ec855
 done
4ec855
 
4ec855
+for new_size in 4096 1048576; do
4ec855
+    echo
4ec855
+    echo "== resize empty image with block_resize =="
4ec855
+    _make_test_img 0 | _filter_imgfmt
4ec855
+    _block_resize $TEST_IMG $new_size >/dev/null
4ec855
+    stat -c "size=%s, blocks=%b" $TEST_IMG | _filter_blocks $extra_blocks $min_blocks $new_size
4ec855
+done
4ec855
+
4ec855
 # success, all done
4ec855
 echo "*** done"
4ec855
 rm -f $seq.full
4ec855
diff --git a/tests/qemu-iotests/175.out b/tests/qemu-iotests/175.out
4ec855
index 263e521..39c2ee0 100644
4ec855
--- a/tests/qemu-iotests/175.out
4ec855
+++ b/tests/qemu-iotests/175.out
4ec855
@@ -15,4 +15,12 @@ size=1048576, max allocation
4ec855
 == creating image with preallocation falloc ==
4ec855
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=falloc
4ec855
 size=1048576, max allocation
4ec855
+
4ec855
+== resize empty image with block_resize ==
4ec855
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
4ec855
+size=4096, min allocation
4ec855
+
4ec855
+== resize empty image with block_resize ==
4ec855
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=0
4ec855
+size=1048576, min allocation
4ec855
  *** done
4ec855
-- 
4ec855
1.8.3.1
4ec855