xref: /qemu/tests/qemu-iotests/138 (revision 097b500c2dff7addfcd5f4c8a111f6bfd0cb3977)
1*097b500cSMax Reitz#!/bin/bash
2*097b500cSMax Reitz#
3*097b500cSMax Reitz# General test case for qcow2's image check
4*097b500cSMax Reitz#
5*097b500cSMax Reitz# Copyright (C) 2015 Red Hat, Inc.
6*097b500cSMax Reitz#
7*097b500cSMax Reitz# This program is free software; you can redistribute it and/or modify
8*097b500cSMax Reitz# it under the terms of the GNU General Public License as published by
9*097b500cSMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*097b500cSMax Reitz# (at your option) any later version.
11*097b500cSMax Reitz#
12*097b500cSMax Reitz# This program is distributed in the hope that it will be useful,
13*097b500cSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*097b500cSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*097b500cSMax Reitz# GNU General Public License for more details.
16*097b500cSMax Reitz#
17*097b500cSMax Reitz# You should have received a copy of the GNU General Public License
18*097b500cSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*097b500cSMax Reitz#
20*097b500cSMax Reitz
21*097b500cSMax Reitz# creator
22*097b500cSMax Reitzowner=mreitz@redhat.com
23*097b500cSMax Reitz
24*097b500cSMax Reitzseq="$(basename $0)"
25*097b500cSMax Reitzecho "QA output created by $seq"
26*097b500cSMax Reitz
27*097b500cSMax Reitzhere="$PWD"
28*097b500cSMax Reitztmp=/tmp/$$
29*097b500cSMax Reitzstatus=1	# failure is the default!
30*097b500cSMax Reitz
31*097b500cSMax Reitz_cleanup()
32*097b500cSMax Reitz{
33*097b500cSMax Reitz	_cleanup_test_img
34*097b500cSMax Reitz}
35*097b500cSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36*097b500cSMax Reitz
37*097b500cSMax Reitz# get standard environment, filters and checks
38*097b500cSMax Reitz. ./common.rc
39*097b500cSMax Reitz. ./common.filter
40*097b500cSMax Reitz
41*097b500cSMax Reitz# This tests qocw2-specific low-level functionality
42*097b500cSMax Reitz_supported_fmt qcow2
43*097b500cSMax Reitz_supported_proto file
44*097b500cSMax Reitz_supported_os Linux
45*097b500cSMax Reitz
46*097b500cSMax Reitzecho
47*097b500cSMax Reitzecho '=== Check on an image with a multiple of 2^32 clusters ==='
48*097b500cSMax Reitzecho
49*097b500cSMax Reitz
50*097b500cSMax ReitzIMGOPTS=$(_optstr_add "$IMGOPTS" "cluster_size=512") \
51*097b500cSMax Reitz    _make_test_img 512
52*097b500cSMax Reitz
53*097b500cSMax Reitz# Allocate L2 table
54*097b500cSMax Reitz$QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io
55*097b500cSMax Reitz
56*097b500cSMax Reitz# Put the data cluster at a multiple of 2 TB, resulting in the image apparently
57*097b500cSMax Reitz# having a multiple of 2^32 clusters
58*097b500cSMax Reitz# (To be more specific: It is at 32 PB)
59*097b500cSMax Reitzpoke_file "$TEST_IMG" 2048 "\x80\x80\x00\x00\x00\x00\x00\x00"
60*097b500cSMax Reitz
61*097b500cSMax Reitz# An offset of 32 PB results in qemu-img check having to allocate an in-memory
62*097b500cSMax Reitz# refcount table of 128 TB (16 bit refcounts, 512 byte clusters).
63*097b500cSMax Reitz# This should be generally too much for any system and thus fail.
64*097b500cSMax Reitz# What this test is checking is that the qcow2 driver actually tries to allocate
65*097b500cSMax Reitz# such a large amount of memory (and is consequently aborting) instead of having
66*097b500cSMax Reitz# truncated the cluster count somewhere (which would result in much less memory
67*097b500cSMax Reitz# being allocated and then a segfault occurring).
68*097b500cSMax Reitz_check_test_img
69*097b500cSMax Reitz
70*097b500cSMax Reitz# success, all done
71*097b500cSMax Reitzecho "*** done"
72*097b500cSMax Reitzrm -f $seq.full
73*097b500cSMax Reitzstatus=0
74