xref: /openbmc/qemu/tests/qemu-iotests/225 (revision 64ed6f92)
1#!/usr/bin/env bash
2#
3# Test vmdk backing file correlation
4#
5# Copyright (C) 2018 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=mreitz@redhat.com
23
24seq=$(basename $0)
25echo "QA output created by $seq"
26
27status=1	# failure is the default!
28
29_cleanup()
30{
31    _cleanup_test_img
32    _rm_test_img "$TEST_IMG.not_base"
33}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39. ./common.qemu
40
41# This tests vmdk-specific low-level functionality
42_supported_fmt vmdk
43_supported_proto file
44_supported_os Linux
45_unsupported_imgopts "subformat=monolithicFlat" \
46                     "subformat=twoGbMaxExtentFlat" \
47                     "subformat=twoGbMaxExtentSparse"
48
49TEST_IMG="$TEST_IMG.base" _make_test_img 1M
50TEST_IMG="$TEST_IMG.not_base" _make_test_img 1M
51_make_test_img -b "$TEST_IMG.base" -F $IMGFMT
52
53make_opts()
54{
55    node_name=$1
56    filename=$2
57    backing=$3
58
59    if [ -z "$backing" ]; then
60        backing="null"
61    else
62        backing="'$backing'"
63    fi
64
65    echo "{ 'node-name': '$node_name',
66            'driver': 'vmdk',
67            'file': {
68                'driver': 'file',
69                'filename': '$filename'
70            },
71            'backing': $backing }"
72}
73
74overlay_opts=$(make_opts overlay "$TEST_IMG" backing)
75base_opts=$(make_opts backing "$TEST_IMG.base")
76not_base_opts=$(make_opts backing "$TEST_IMG.not_base")
77
78not_vmdk_opts="{ 'node-name': 'backing', 'driver': 'null-co' }"
79
80echo
81echo '=== Testing fitting VMDK backing image ==='
82echo
83
84qemu_comm_method=monitor \
85    _launch_qemu -blockdev "$base_opts" -blockdev "$overlay_opts"
86
87# Should not return an error
88_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'ops'
89
90_cleanup_qemu
91
92
93echo
94echo '=== Testing unrelated VMDK backing image ==='
95echo
96
97qemu_comm_method=monitor \
98    _launch_qemu -blockdev "$not_base_opts" -blockdev "$overlay_opts"
99
100# Should fail (gracefully)
101_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
102
103_cleanup_qemu
104
105
106echo
107echo '=== Testing non-VMDK backing image ==='
108echo
109
110# FIXME: This is the reason why we have to use two -blockdev
111# invocations.  You can only fully override the backing file options
112# if you either specify a node reference (as done here) or the new
113# options contain file.filename (which in this case they do not).
114# In other cases, file.filename will be set to whatever the image
115# header of the overlay contains (which we do not want).  I consider
116# this a FIXME because with -blockdev, you cannot specify "partial"
117# options, so setting file.filename but leaving the rest as specified
118# by the user does not make sense.
119qemu_comm_method=monitor \
120    _launch_qemu -blockdev "$not_vmdk_opts" -blockdev "$overlay_opts"
121
122# Should fail (gracefully)
123_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
124
125_cleanup_qemu
126
127
128# success, all done
129echo "*** done"
130rm -f $seq.full
131status=0
132