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