yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-iotests-Add-tests-for-refcount-table-growth.patch

05bba0
From 65d01862c82d46a2f440dab3818e8e08e6879551 Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Sat, 13 Jun 2015 16:22:34 +0200
05bba0
Subject: [PATCH 40/42] iotests: Add tests for refcount table growth
05bba0
05bba0
Message-id: <1434212556-3927-41-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 66059
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 40/42] iotests: Add tests for refcount table growth
05bba0
Bugzilla: 1129893
05bba0
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
BZ: 1129893
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
Message-id: 1423598552-24301-3-git-send-email-mreitz@redhat.com
05bba0
Reviewed-by: Eric Blake <eblake@redhat.com>
05bba0
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
(cherry picked from commit 0e8a371468ce24513b15a9ae362f12822e1973a3)
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
05bba0
Conflicts:
05bba0
	tests/qemu-iotests/group
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
---
05bba0
 tests/qemu-iotests/121     | 102 +++++++++++++++++++++++++++++++++++++++++++++
05bba0
 tests/qemu-iotests/121.out |  23 ++++++++++
05bba0
 tests/qemu-iotests/group   |   1 +
05bba0
 3 files changed, 126 insertions(+)
05bba0
 create mode 100755 tests/qemu-iotests/121
05bba0
 create mode 100644 tests/qemu-iotests/121.out
05bba0
05bba0
diff --git a/tests/qemu-iotests/121 b/tests/qemu-iotests/121
05bba0
new file mode 100755
05bba0
index 0000000..0912c3f
05bba0
--- /dev/null
05bba0
+++ b/tests/qemu-iotests/121
05bba0
@@ -0,0 +1,102 @@
05bba0
+#!/bin/bash
05bba0
+#
05bba0
+# Test cases for qcow2 refcount table growth
05bba0
+#
05bba0
+# Copyright (C) 2015 Red Hat, Inc.
05bba0
+#
05bba0
+# This program is free software; you can redistribute it and/or modify
05bba0
+# it under the terms of the GNU General Public License as published by
05bba0
+# the Free Software Foundation; either version 2 of the License, or
05bba0
+# (at your option) any later version.
05bba0
+#
05bba0
+# This program is distributed in the hope that it will be useful,
05bba0
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
05bba0
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
05bba0
+# GNU General Public License for more details.
05bba0
+#
05bba0
+# You should have received a copy of the GNU General Public License
05bba0
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
05bba0
+#
05bba0
+
05bba0
+# creator
05bba0
+owner=mreitz@redhat.com
05bba0
+
05bba0
+seq="$(basename $0)"
05bba0
+echo "QA output created by $seq"
05bba0
+
05bba0
+here="$PWD"
05bba0
+tmp=/tmp/$$
05bba0
+status=1	# failure is the default!
05bba0
+
05bba0
+_cleanup()
05bba0
+{
05bba0
+	_cleanup_test_img
05bba0
+}
05bba0
+trap "_cleanup; exit \$status" 0 1 2 3 15
05bba0
+
05bba0
+# get standard environment, filters and checks
05bba0
+. ./common.rc
05bba0
+. ./common.filter
05bba0
+
05bba0
+_supported_fmt qcow2
05bba0
+_supported_proto file
05bba0
+_supported_os Linux
05bba0
+
05bba0
+echo
05bba0
+echo '=== New refcount structures may not conflict with existing structures ==='
05bba0
+
05bba0
+echo
05bba0
+echo '--- Test 1 ---'
05bba0
+echo
05bba0
+
05bba0
+# Preallocation speeds up the write operation, but preallocating everything will
05bba0
+# destroy the purpose of the write; so preallocate one KB less than what would
05bba0
+# cause a reftable growth...
05bba0
+IMGOPTS='preallocation=metadata,cluster_size=1k' _make_test_img 64512K
05bba0
+# ...and make the image the desired size afterwards.
05bba0
+$QEMU_IMG resize "$TEST_IMG" 65M
05bba0
+
05bba0
+# The first write results in a growth of the refcount table during an allocation
05bba0
+# which has precisely the required size so that the new refcount block allocated
05bba0
+# in alloc_refcount_block() is right after cluster_index; this did lead to a
05bba0
+# different refcount block being written to disk (a zeroed cluster) than what is
05bba0
+# cached (a refblock with one entry having a refcount of 1), and the second
05bba0
+# write would then result in that cached cluster being marked dirty and then
05bba0
+# in it being written to disk.
05bba0
+# This should not happen, the new refcount structures may not conflict with
05bba0
+# new_block.
05bba0
+# (Note that for some reason, 'write 63M 1K' does not trigger the problem)
05bba0
+$QEMU_IO -c 'write 62M 1025K' -c 'write 64M 1M' "$TEST_IMG" | _filter_qemu_io
05bba0
+
05bba0
+_check_test_img
05bba0
+
05bba0
+
05bba0
+echo
05bba0
+echo '--- Test 2 ---'
05bba0
+echo
05bba0
+
05bba0
+IMGOPTS='preallocation=metadata,cluster_size=1k' _make_test_img 64513K
05bba0
+# This results in an L1 table growth which in turn results in some clusters at
05bba0
+# the start of the image becoming free
05bba0
+$QEMU_IMG resize "$TEST_IMG" 65M
05bba0
+
05bba0
+# This write results in a refcount table growth; but the refblock allocated
05bba0
+# immediately before that (new_block) takes cluster index 4 (which is now free)
05bba0
+# and is thus not self-describing (in contrast to test 1, where new_block was
05bba0
+# self-describing). The refcount table growth algorithm then used to place the
05bba0
+# new refcount structures at cluster index 65536 (which is the same as the
05bba0
+# cluster_index parameter in this case), allocating a new refcount block for
05bba0
+# that cluster while new_block already existed, leaking new_block.
05bba0
+# Therefore, the new refcount structures may not be put at cluster_index
05bba0
+# (because new_block already describes that cluster, and the new structures try
05bba0
+# to be self-describing).
05bba0
+$QEMU_IO -c 'write 63M 130K' "$TEST_IMG" | _filter_qemu_io
05bba0
+
05bba0
+_check_test_img
05bba0
+
05bba0
+
05bba0
+# success, all done
05bba0
+echo
05bba0
+echo '*** done'
05bba0
+rm -f $seq.full
05bba0
+status=0
05bba0
diff --git a/tests/qemu-iotests/121.out b/tests/qemu-iotests/121.out
05bba0
new file mode 100644
05bba0
index 0000000..ff18e2c
05bba0
--- /dev/null
05bba0
+++ b/tests/qemu-iotests/121.out
05bba0
@@ -0,0 +1,23 @@
05bba0
+QA output created by 121
05bba0
+
05bba0
+=== New refcount structures may not conflict with existing structures ===
05bba0
+
05bba0
+--- Test 1 ---
05bba0
+
05bba0
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=66060288 preallocation='metadata'
05bba0
+Image resized.
05bba0
+wrote 1049600/1049600 bytes at offset 65011712
05bba0
+1.001 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
05bba0
+wrote 1048576/1048576 bytes at offset 67108864
05bba0
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
05bba0
+No errors were found on the image.
05bba0
+
05bba0
+--- Test 2 ---
05bba0
+
05bba0
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=66061312 preallocation='metadata'
05bba0
+Image resized.
05bba0
+wrote 133120/133120 bytes at offset 66060288
05bba0
+130 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
05bba0
+No errors were found on the image.
05bba0
+
05bba0
+*** done
05bba0
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
05bba0
index 5867cf7..dbb2a36 100644
05bba0
--- a/tests/qemu-iotests/group
05bba0
+++ b/tests/qemu-iotests/group
05bba0
@@ -89,3 +89,4 @@
05bba0
 107 rw auto quick
05bba0
 108 rw auto quick
05bba0
 114 rw auto quick
05bba0
+121 rw auto
05bba0
-- 
05bba0
1.8.3.1
05bba0