xref: /qemu/tests/qemu-iotests/115 (revision 407fb56a8e10982d6e04b7a73e0c2cea3bed88b9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
24b4d7b07SMax Reitz#
34b4d7b07SMax Reitz# Test case for non-self-referential qcow2 refcount blocks
44b4d7b07SMax Reitz#
54b4d7b07SMax Reitz# Copyright (C) 2014 Red Hat, Inc.
64b4d7b07SMax Reitz#
74b4d7b07SMax Reitz# This program is free software; you can redistribute it and/or modify
84b4d7b07SMax Reitz# it under the terms of the GNU General Public License as published by
94b4d7b07SMax Reitz# the Free Software Foundation; either version 2 of the License, or
104b4d7b07SMax Reitz# (at your option) any later version.
114b4d7b07SMax Reitz#
124b4d7b07SMax Reitz# This program is distributed in the hope that it will be useful,
134b4d7b07SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
144b4d7b07SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154b4d7b07SMax Reitz# GNU General Public License for more details.
164b4d7b07SMax Reitz#
174b4d7b07SMax Reitz# You should have received a copy of the GNU General Public License
184b4d7b07SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
194b4d7b07SMax Reitz#
204b4d7b07SMax Reitz
214b4d7b07SMax Reitz# creator
224b4d7b07SMax Reitzowner=mreitz@redhat.com
234b4d7b07SMax Reitz
244b4d7b07SMax Reitzseq="$(basename $0)"
254b4d7b07SMax Reitzecho "QA output created by $seq"
264b4d7b07SMax Reitz
274b4d7b07SMax Reitzstatus=1	# failure is the default!
284b4d7b07SMax Reitz
294b4d7b07SMax Reitz_cleanup()
304b4d7b07SMax Reitz{
314b4d7b07SMax Reitz	_cleanup_test_img
324b4d7b07SMax Reitz}
334b4d7b07SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
344b4d7b07SMax Reitz
354b4d7b07SMax Reitz# get standard environment, filters and checks
364b4d7b07SMax Reitz. ./common.rc
374b4d7b07SMax Reitz. ./common.filter
384b4d7b07SMax Reitz
394b4d7b07SMax Reitz_supported_fmt qcow2
404b4d7b07SMax Reitz_supported_proto file
414b4d7b07SMax Reitz# This test relies on refcounts being 64 bits wide (which does not work with
424b4d7b07SMax Reitz# compat=0.10)
434b4d7b07SMax Reitz_unsupported_imgopts 'refcount_bits=\([^6]\|.\([^4]\|$\)\)' 'compat=0.10'
444b4d7b07SMax Reitz
454b4d7b07SMax Reitzecho
464b4d7b07SMax Reitzecho '=== Testing large refcount and L1 table ==='
474b4d7b07SMax Reitzecho
484b4d7b07SMax Reitz
494b4d7b07SMax Reitz# Create an image with an L1 table and a refcount table that each span twice the
504b4d7b07SMax Reitz# number of clusters which can be described by a single refblock; therefore, at
514b4d7b07SMax Reitz# least two refblocks cannot count their own refcounts because all the clusters
524b4d7b07SMax Reitz# they describe are part of the L1 table or refcount table.
534b4d7b07SMax Reitz
544b4d7b07SMax Reitz# One refblock can describe (with cluster_size=512 and refcount_bits=64)
554b4d7b07SMax Reitz# 512/8 = 64 clusters, therefore the L1 table should cover 128 clusters, which
564b4d7b07SMax Reitz# equals 128 * (512/8) = 8192 entries (actually, 8192 - 512/8 = 8129 would
574b4d7b07SMax Reitz# suffice, but it does not really matter). 8192 L2 tables can in turn describe
584b4d7b07SMax Reitz# 8192 * 512/8 = 524,288 clusters which cover a space of 256 MB.
594b4d7b07SMax Reitz
604b4d7b07SMax Reitz# Since with refcount_bits=64 every refcount block entry is 64 bits wide (just
614b4d7b07SMax Reitz# like the L2 table entries), the same calculation applies to the refcount table
624b4d7b07SMax Reitz# as well; the difference is that while for the L1 table the guest disk size is
634b4d7b07SMax Reitz# concerned, for the refcount table it is the image length that has to be at
644b4d7b07SMax Reitz# least 256 MB. We can achieve that by using preallocation=metadata for an image
654b4d7b07SMax Reitz# which has a guest disk size of 256 MB.
664b4d7b07SMax Reitz
67*407fb56aSMax Reitz_make_test_img -o "refcount_bits=64,cluster_size=512,preallocation=metadata" 256M
684b4d7b07SMax Reitz
694b4d7b07SMax Reitz# We know for sure that the L1 and refcount tables do not overlap with any other
704b4d7b07SMax Reitz# structure because the metadata overlap checks would have caught that case.
714b4d7b07SMax Reitz
724b4d7b07SMax Reitz# Because qemu refuses to open qcow2 files whose L1 table does not cover the
734b4d7b07SMax Reitz# whole guest disk size, it is definitely large enough. On the other hand, to
744b4d7b07SMax Reitz# test whether the refcount table is large enough, we simply have to verify that
754b4d7b07SMax Reitz# indeed all the clusters are allocated, which is done by qemu-img check.
764b4d7b07SMax Reitz
774b4d7b07SMax Reitz# The final thing we need to test is whether the tables are actually covered by
784b4d7b07SMax Reitz# refcount blocks; since all clusters of the tables are referenced, we can use
794b4d7b07SMax Reitz# qemu-img check for that purpose, too.
804b4d7b07SMax Reitz
814b4d7b07SMax Reitz$QEMU_IMG check "$TEST_IMG" | \
824b4d7b07SMax Reitz    sed -e 's/^.* = \([0-9]\+\.[0-9]\+% allocated\).*\(clusters\)$/\1 \2/' \
834b4d7b07SMax Reitz        -e '/^Image end offset/d'
844b4d7b07SMax Reitz
854b4d7b07SMax Reitz# (Note that we cannot use _check_test_img because that function filters out the
864b4d7b07SMax Reitz# allocation status)
874b4d7b07SMax Reitz
884b4d7b07SMax Reitz# success, all done
894b4d7b07SMax Reitzecho '*** done'
904b4d7b07SMax Reitzrm -f $seq.full
914b4d7b07SMax Reitzstatus=0
92