xref: /openbmc/qemu/tests/qemu-iotests/110 (revision 42a5009d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto backing quick
3527ab22aSMax Reitz#
4527ab22aSMax Reitz# Test case for relative backing file names in complex BDS trees
5527ab22aSMax Reitz#
6527ab22aSMax Reitz# Copyright (C) 2014 Red Hat, Inc.
7527ab22aSMax Reitz#
8527ab22aSMax Reitz# This program is free software; you can redistribute it and/or modify
9527ab22aSMax Reitz# it under the terms of the GNU General Public License as published by
10527ab22aSMax Reitz# the Free Software Foundation; either version 2 of the License, or
11527ab22aSMax Reitz# (at your option) any later version.
12527ab22aSMax Reitz#
13527ab22aSMax Reitz# This program is distributed in the hope that it will be useful,
14527ab22aSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15527ab22aSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16527ab22aSMax Reitz# GNU General Public License for more details.
17527ab22aSMax Reitz#
18527ab22aSMax Reitz# You should have received a copy of the GNU General Public License
19527ab22aSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20527ab22aSMax Reitz#
21527ab22aSMax Reitz
22527ab22aSMax Reitz# creator
23*42a5009dSJohn Snowowner=hreitz@redhat.com
24527ab22aSMax Reitz
25527ab22aSMax Reitzseq="$(basename $0)"
26527ab22aSMax Reitzecho "QA output created by $seq"
27527ab22aSMax Reitz
28527ab22aSMax Reitzstatus=1	# failure is the default!
29527ab22aSMax Reitz
30527ab22aSMax Reitz_cleanup()
31527ab22aSMax Reitz{
32527ab22aSMax Reitz    _cleanup_test_img
33f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.copy"
34527ab22aSMax Reitz}
35527ab22aSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
36527ab22aSMax Reitz
37527ab22aSMax Reitz# get standard environment, filters and checks
38527ab22aSMax Reitz. ./common.rc
39527ab22aSMax Reitz. ./common.filter
40527ab22aSMax Reitz
41527ab22aSMax Reitz# Any format supporting backing files
42527ab22aSMax Reitz_supported_fmt qed qcow qcow2 vmdk
43527ab22aSMax Reitz_supported_proto file
44c64c3ae3SMax Reitz_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat" \
45c64c3ae3SMax Reitz                     "subformat=twoGbMaxExtentSparse"
46527ab22aSMax Reitz
47527ab22aSMax ReitzTEST_IMG_REL=$(basename "$TEST_IMG")
48527ab22aSMax Reitz
49527ab22aSMax Reitzecho
50527ab22aSMax Reitzecho '=== Reconstructable filename ==='
51527ab22aSMax Reitzecho
52527ab22aSMax Reitz
53527ab22aSMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 64M
54b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG_REL.base" -F $IMGFMT 64M
55527ab22aSMax Reitz# qemu should be able to reconstruct the filename, so relative backing names
56527ab22aSMax Reitz# should work
571278dce7SMax Reitz# (We have to filter the backing file format because vmdk always
581278dce7SMax Reitz# reports it (as vmdk), whereas other image formats would do so only
591278dce7SMax Reitz# with the backing_fmt creation option, which neither vmdk nor qcow
601278dce7SMax Reitz# support)
61527ab22aSMax ReitzTEST_IMG="json:{'driver':'$IMGFMT','file':{'driver':'file','filename':'$TEST_IMG'}}" \
621278dce7SMax Reitz    _img_info | _filter_img_info | grep -v 'backing file format'
63527ab22aSMax Reitz
64527ab22aSMax Reitzecho
65527ab22aSMax Reitzecho '=== Non-reconstructable filename ==='
66527ab22aSMax Reitzecho
67527ab22aSMax Reitz
68527ab22aSMax Reitz# Across blkdebug without a config file, you cannot reconstruct filenames, so
698df68616SMax Reitz# qemu is incapable of knowing the directory of the top image from the filename
708df68616SMax Reitz# alone. However, using bdrv_dirname(), it should still work.
71d327a942SMax Reitz# (Filter out the json:{} filename so this test works with external data files)
72527ab22aSMax ReitzTEST_IMG="json:{
73527ab22aSMax Reitz    'driver': '$IMGFMT',
74527ab22aSMax Reitz    'file': {
75527ab22aSMax Reitz        'driver': 'blkdebug',
76527ab22aSMax Reitz        'image': {
77527ab22aSMax Reitz            'driver': 'file',
78527ab22aSMax Reitz            'filename': '$TEST_IMG'
79527ab22aSMax Reitz        },
80527ab22aSMax Reitz        'set-state': [
81527ab22aSMax Reitz            {
82527ab22aSMax Reitz                'event': 'read_aio',
83527ab22aSMax Reitz                'new_state': 42
84527ab22aSMax Reitz            }
85527ab22aSMax Reitz        ]
86527ab22aSMax Reitz    }
87d327a942SMax Reitz}" _img_info | _filter_img_info | grep -v 'backing file format' \
88d327a942SMax Reitz    | _filter_json_filename
89527ab22aSMax Reitz
90527ab22aSMax Reitzecho
91527ab22aSMax Reitzecho '=== Backing name is always relative to the backed image ==='
92527ab22aSMax Reitzecho
93527ab22aSMax Reitz
94527ab22aSMax Reitz# omit the image size; it should work anyway
95b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG_REL.base" -F $IMGFMT
96527ab22aSMax Reitz
97c0625e80SMax Reitzecho
98c0625e80SMax Reitzecho '=== Nodes without a common directory ==='
99c0625e80SMax Reitzecho
100c0625e80SMax Reitz
101c0625e80SMax Reitzcp "$TEST_IMG" "$TEST_IMG.copy"
102c0625e80SMax Reitz
103c0625e80SMax Reitz# Should inform us that the actual path of the backing file cannot be determined
104c0625e80SMax ReitzTEST_IMG="json:{
105c0625e80SMax Reitz    'driver': '$IMGFMT',
106c0625e80SMax Reitz    'file': {
107c0625e80SMax Reitz        'driver': 'quorum',
108c0625e80SMax Reitz        'vote-threshold': 1,
109c0625e80SMax Reitz        'children': [
110c0625e80SMax Reitz            {
111c0625e80SMax Reitz                'driver': 'file',
112c0625e80SMax Reitz                'filename': '$TEST_IMG'
113c0625e80SMax Reitz            },
114c0625e80SMax Reitz            {
115c0625e80SMax Reitz                'driver': 'file',
116c0625e80SMax Reitz                'filename': '$TEST_IMG.copy'
117c0625e80SMax Reitz            }
118c0625e80SMax Reitz        ]
119c0625e80SMax Reitz    }
120d327a942SMax Reitz}" _img_info | _filter_img_info | grep -v 'backing file format' \
121d327a942SMax Reitz    | _filter_json_filename
122c0625e80SMax Reitz
123527ab22aSMax Reitz
124527ab22aSMax Reitz# success, all done
125527ab22aSMax Reitzecho '*** done'
126527ab22aSMax Reitzrm -f $seq.full
127527ab22aSMax Reitzstatus=0
128