xref: /openbmc/qemu/tests/qemu-iotests/110 (revision 1278dce7927301bf3d004a40061dbd2c1e0846a8)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2527ab22aSMax Reitz#
3527ab22aSMax Reitz# Test case for relative backing file names in complex BDS trees
4527ab22aSMax Reitz#
5527ab22aSMax Reitz# Copyright (C) 2014 Red Hat, Inc.
6527ab22aSMax Reitz#
7527ab22aSMax Reitz# This program is free software; you can redistribute it and/or modify
8527ab22aSMax Reitz# it under the terms of the GNU General Public License as published by
9527ab22aSMax Reitz# the Free Software Foundation; either version 2 of the License, or
10527ab22aSMax Reitz# (at your option) any later version.
11527ab22aSMax Reitz#
12527ab22aSMax Reitz# This program is distributed in the hope that it will be useful,
13527ab22aSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14527ab22aSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15527ab22aSMax Reitz# GNU General Public License for more details.
16527ab22aSMax Reitz#
17527ab22aSMax Reitz# You should have received a copy of the GNU General Public License
18527ab22aSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19527ab22aSMax Reitz#
20527ab22aSMax Reitz
21527ab22aSMax Reitz# creator
22527ab22aSMax Reitzowner=mreitz@redhat.com
23527ab22aSMax Reitz
24527ab22aSMax Reitzseq="$(basename $0)"
25527ab22aSMax Reitzecho "QA output created by $seq"
26527ab22aSMax Reitz
27527ab22aSMax Reitzstatus=1	# failure is the default!
28527ab22aSMax Reitz
29527ab22aSMax Reitz_cleanup()
30527ab22aSMax Reitz{
31527ab22aSMax Reitz	_cleanup_test_img
32c0625e80SMax Reitz        rm -f "$TEST_IMG.copy"
33527ab22aSMax Reitz}
34527ab22aSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35527ab22aSMax Reitz
36527ab22aSMax Reitz# get standard environment, filters and checks
37527ab22aSMax Reitz. ./common.rc
38527ab22aSMax Reitz. ./common.filter
39527ab22aSMax Reitz
40527ab22aSMax Reitz# Any format supporting backing files
41527ab22aSMax Reitz_supported_fmt qed qcow qcow2 vmdk
42527ab22aSMax Reitz_supported_proto file
43527ab22aSMax Reitz_supported_os Linux
44527ab22aSMax Reitz_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
45527ab22aSMax Reitz
46527ab22aSMax ReitzTEST_IMG_REL=$(basename "$TEST_IMG")
47527ab22aSMax Reitz
48527ab22aSMax Reitzecho
49527ab22aSMax Reitzecho '=== Reconstructable filename ==='
50527ab22aSMax Reitzecho
51527ab22aSMax Reitz
52527ab22aSMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 64M
53527ab22aSMax Reitz_make_test_img -b "$TEST_IMG_REL.base" 64M
54527ab22aSMax Reitz# qemu should be able to reconstruct the filename, so relative backing names
55527ab22aSMax Reitz# should work
56*1278dce7SMax Reitz# (We have to filter the backing file format because vmdk always
57*1278dce7SMax Reitz# reports it (as vmdk), whereas other image formats would do so only
58*1278dce7SMax Reitz# with the backing_fmt creation option, which neither vmdk nor qcow
59*1278dce7SMax Reitz# support)
60527ab22aSMax ReitzTEST_IMG="json:{'driver':'$IMGFMT','file':{'driver':'file','filename':'$TEST_IMG'}}" \
61*1278dce7SMax Reitz    _img_info | _filter_img_info | grep -v 'backing file format'
62527ab22aSMax Reitz
63527ab22aSMax Reitzecho
64527ab22aSMax Reitzecho '=== Non-reconstructable filename ==='
65527ab22aSMax Reitzecho
66527ab22aSMax Reitz
67527ab22aSMax Reitz# Across blkdebug without a config file, you cannot reconstruct filenames, so
688df68616SMax Reitz# qemu is incapable of knowing the directory of the top image from the filename
698df68616SMax Reitz# alone. However, using bdrv_dirname(), it should still work.
70527ab22aSMax ReitzTEST_IMG="json:{
71527ab22aSMax Reitz    'driver': '$IMGFMT',
72527ab22aSMax Reitz    'file': {
73527ab22aSMax Reitz        'driver': 'blkdebug',
74527ab22aSMax Reitz        'image': {
75527ab22aSMax Reitz            'driver': 'file',
76527ab22aSMax Reitz            'filename': '$TEST_IMG'
77527ab22aSMax Reitz        },
78527ab22aSMax Reitz        'set-state': [
79527ab22aSMax Reitz            {
80527ab22aSMax Reitz                'event': 'read_aio',
81527ab22aSMax Reitz                'new_state': 42
82527ab22aSMax Reitz            }
83527ab22aSMax Reitz        ]
84527ab22aSMax Reitz    }
85*1278dce7SMax Reitz}" _img_info | _filter_img_info | grep -v 'backing file format'
86527ab22aSMax Reitz
87527ab22aSMax Reitzecho
88527ab22aSMax Reitzecho '=== Backing name is always relative to the backed image ==='
89527ab22aSMax Reitzecho
90527ab22aSMax Reitz
91527ab22aSMax Reitz# omit the image size; it should work anyway
92527ab22aSMax Reitz_make_test_img -b "$TEST_IMG_REL.base"
93527ab22aSMax Reitz
94c0625e80SMax Reitzecho
95c0625e80SMax Reitzecho '=== Nodes without a common directory ==='
96c0625e80SMax Reitzecho
97c0625e80SMax Reitz
98c0625e80SMax Reitzcp "$TEST_IMG" "$TEST_IMG.copy"
99c0625e80SMax Reitz
100c0625e80SMax Reitz# Should inform us that the actual path of the backing file cannot be determined
101c0625e80SMax ReitzTEST_IMG="json:{
102c0625e80SMax Reitz    'driver': '$IMGFMT',
103c0625e80SMax Reitz    'file': {
104c0625e80SMax Reitz        'driver': 'quorum',
105c0625e80SMax Reitz        'vote-threshold': 1,
106c0625e80SMax Reitz        'children': [
107c0625e80SMax Reitz            {
108c0625e80SMax Reitz                'driver': 'file',
109c0625e80SMax Reitz                'filename': '$TEST_IMG'
110c0625e80SMax Reitz            },
111c0625e80SMax Reitz            {
112c0625e80SMax Reitz                'driver': 'file',
113c0625e80SMax Reitz                'filename': '$TEST_IMG.copy'
114c0625e80SMax Reitz            }
115c0625e80SMax Reitz        ]
116c0625e80SMax Reitz    }
117*1278dce7SMax Reitz}" _img_info | _filter_img_info | grep -v 'backing file format'
118c0625e80SMax Reitz
119527ab22aSMax Reitz
120527ab22aSMax Reitz# success, all done
121527ab22aSMax Reitzecho '*** done'
122527ab22aSMax Reitzrm -f $seq.full
123527ab22aSMax Reitzstatus=0
124