1*4b4d7b07SMax Reitz#!/bin/bash 2*4b4d7b07SMax Reitz# 3*4b4d7b07SMax Reitz# Test case for non-self-referential qcow2 refcount blocks 4*4b4d7b07SMax Reitz# 5*4b4d7b07SMax Reitz# Copyright (C) 2014 Red Hat, Inc. 6*4b4d7b07SMax Reitz# 7*4b4d7b07SMax Reitz# This program is free software; you can redistribute it and/or modify 8*4b4d7b07SMax Reitz# it under the terms of the GNU General Public License as published by 9*4b4d7b07SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10*4b4d7b07SMax Reitz# (at your option) any later version. 11*4b4d7b07SMax Reitz# 12*4b4d7b07SMax Reitz# This program is distributed in the hope that it will be useful, 13*4b4d7b07SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*4b4d7b07SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*4b4d7b07SMax Reitz# GNU General Public License for more details. 16*4b4d7b07SMax Reitz# 17*4b4d7b07SMax Reitz# You should have received a copy of the GNU General Public License 18*4b4d7b07SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*4b4d7b07SMax Reitz# 20*4b4d7b07SMax Reitz 21*4b4d7b07SMax Reitz# creator 22*4b4d7b07SMax Reitzowner=mreitz@redhat.com 23*4b4d7b07SMax Reitz 24*4b4d7b07SMax Reitzseq="$(basename $0)" 25*4b4d7b07SMax Reitzecho "QA output created by $seq" 26*4b4d7b07SMax Reitz 27*4b4d7b07SMax Reitzhere="$PWD" 28*4b4d7b07SMax Reitztmp=/tmp/$$ 29*4b4d7b07SMax Reitzstatus=1 # failure is the default! 30*4b4d7b07SMax Reitz 31*4b4d7b07SMax Reitz_cleanup() 32*4b4d7b07SMax Reitz{ 33*4b4d7b07SMax Reitz _cleanup_test_img 34*4b4d7b07SMax Reitz} 35*4b4d7b07SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 36*4b4d7b07SMax Reitz 37*4b4d7b07SMax Reitz# get standard environment, filters and checks 38*4b4d7b07SMax Reitz. ./common.rc 39*4b4d7b07SMax Reitz. ./common.filter 40*4b4d7b07SMax Reitz 41*4b4d7b07SMax Reitz_supported_fmt qcow2 42*4b4d7b07SMax Reitz_supported_proto file 43*4b4d7b07SMax Reitz_supported_os Linux 44*4b4d7b07SMax Reitz# This test relies on refcounts being 64 bits wide (which does not work with 45*4b4d7b07SMax Reitz# compat=0.10) 46*4b4d7b07SMax Reitz_unsupported_imgopts 'refcount_bits=\([^6]\|.\([^4]\|$\)\)' 'compat=0.10' 47*4b4d7b07SMax Reitz 48*4b4d7b07SMax Reitzecho 49*4b4d7b07SMax Reitzecho '=== Testing large refcount and L1 table ===' 50*4b4d7b07SMax Reitzecho 51*4b4d7b07SMax Reitz 52*4b4d7b07SMax Reitz# Create an image with an L1 table and a refcount table that each span twice the 53*4b4d7b07SMax Reitz# number of clusters which can be described by a single refblock; therefore, at 54*4b4d7b07SMax Reitz# least two refblocks cannot count their own refcounts because all the clusters 55*4b4d7b07SMax Reitz# they describe are part of the L1 table or refcount table. 56*4b4d7b07SMax Reitz 57*4b4d7b07SMax Reitz# One refblock can describe (with cluster_size=512 and refcount_bits=64) 58*4b4d7b07SMax Reitz# 512/8 = 64 clusters, therefore the L1 table should cover 128 clusters, which 59*4b4d7b07SMax Reitz# equals 128 * (512/8) = 8192 entries (actually, 8192 - 512/8 = 8129 would 60*4b4d7b07SMax Reitz# suffice, but it does not really matter). 8192 L2 tables can in turn describe 61*4b4d7b07SMax Reitz# 8192 * 512/8 = 524,288 clusters which cover a space of 256 MB. 62*4b4d7b07SMax Reitz 63*4b4d7b07SMax Reitz# Since with refcount_bits=64 every refcount block entry is 64 bits wide (just 64*4b4d7b07SMax Reitz# like the L2 table entries), the same calculation applies to the refcount table 65*4b4d7b07SMax Reitz# as well; the difference is that while for the L1 table the guest disk size is 66*4b4d7b07SMax Reitz# concerned, for the refcount table it is the image length that has to be at 67*4b4d7b07SMax Reitz# least 256 MB. We can achieve that by using preallocation=metadata for an image 68*4b4d7b07SMax Reitz# which has a guest disk size of 256 MB. 69*4b4d7b07SMax Reitz 70*4b4d7b07SMax ReitzIMGOPTS="$IMGOPTS,refcount_bits=64,cluster_size=512,preallocation=metadata" \ 71*4b4d7b07SMax Reitz _make_test_img 256M 72*4b4d7b07SMax Reitz 73*4b4d7b07SMax Reitz# We know for sure that the L1 and refcount tables do not overlap with any other 74*4b4d7b07SMax Reitz# structure because the metadata overlap checks would have caught that case. 75*4b4d7b07SMax Reitz 76*4b4d7b07SMax Reitz# Because qemu refuses to open qcow2 files whose L1 table does not cover the 77*4b4d7b07SMax Reitz# whole guest disk size, it is definitely large enough. On the other hand, to 78*4b4d7b07SMax Reitz# test whether the refcount table is large enough, we simply have to verify that 79*4b4d7b07SMax Reitz# indeed all the clusters are allocated, which is done by qemu-img check. 80*4b4d7b07SMax Reitz 81*4b4d7b07SMax Reitz# The final thing we need to test is whether the tables are actually covered by 82*4b4d7b07SMax Reitz# refcount blocks; since all clusters of the tables are referenced, we can use 83*4b4d7b07SMax Reitz# qemu-img check for that purpose, too. 84*4b4d7b07SMax Reitz 85*4b4d7b07SMax Reitz$QEMU_IMG check "$TEST_IMG" | \ 86*4b4d7b07SMax Reitz sed -e 's/^.* = \([0-9]\+\.[0-9]\+% allocated\).*\(clusters\)$/\1 \2/' \ 87*4b4d7b07SMax Reitz -e '/^Image end offset/d' 88*4b4d7b07SMax Reitz 89*4b4d7b07SMax Reitz# (Note that we cannot use _check_test_img because that function filters out the 90*4b4d7b07SMax Reitz# allocation status) 91*4b4d7b07SMax Reitz 92*4b4d7b07SMax Reitz# success, all done 93*4b4d7b07SMax Reitzecho '*** done' 94*4b4d7b07SMax Reitzrm -f $seq.full 95*4b4d7b07SMax Reitzstatus=0 96