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