xref: /openbmc/qemu/tests/qemu-iotests/225 (revision f91ecbd7)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
285456e0dSMax Reitz#
385456e0dSMax Reitz# Test vmdk backing file correlation
485456e0dSMax Reitz#
585456e0dSMax Reitz# Copyright (C) 2018 Red Hat, Inc.
685456e0dSMax Reitz#
785456e0dSMax Reitz# This program is free software; you can redistribute it and/or modify
885456e0dSMax Reitz# it under the terms of the GNU General Public License as published by
985456e0dSMax Reitz# the Free Software Foundation; either version 2 of the License, or
1085456e0dSMax Reitz# (at your option) any later version.
1185456e0dSMax Reitz#
1285456e0dSMax Reitz# This program is distributed in the hope that it will be useful,
1385456e0dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
1485456e0dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1585456e0dSMax Reitz# GNU General Public License for more details.
1685456e0dSMax Reitz#
1785456e0dSMax Reitz# You should have received a copy of the GNU General Public License
1885456e0dSMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1985456e0dSMax Reitz#
2085456e0dSMax Reitz
2185456e0dSMax Reitz# creator
2285456e0dSMax Reitzowner=mreitz@redhat.com
2385456e0dSMax Reitz
2485456e0dSMax Reitzseq=$(basename $0)
2585456e0dSMax Reitzecho "QA output created by $seq"
2685456e0dSMax Reitz
2785456e0dSMax Reitzstatus=1	# failure is the default!
2885456e0dSMax Reitz
2985456e0dSMax Reitz_cleanup()
3085456e0dSMax Reitz{
3185456e0dSMax Reitz    _cleanup_test_img
32*f91ecbd7SMax Reitz    _rm_test_img "$TEST_IMG.not_base"
3385456e0dSMax Reitz}
3485456e0dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
3585456e0dSMax Reitz
3685456e0dSMax Reitz# get standard environment, filters and checks
3785456e0dSMax Reitz. ./common.rc
3885456e0dSMax Reitz. ./common.filter
3985456e0dSMax Reitz. ./common.qemu
4085456e0dSMax Reitz
4185456e0dSMax Reitz# This tests vmdk-specific low-level functionality
4285456e0dSMax Reitz_supported_fmt vmdk
4385456e0dSMax Reitz_supported_proto file
4485456e0dSMax Reitz_supported_os Linux
4585456e0dSMax Reitz_unsupported_imgopts "subformat=monolithicFlat" \
4685456e0dSMax Reitz                     "subformat=twoGbMaxExtentFlat" \
4785456e0dSMax Reitz                     "subformat=twoGbMaxExtentSparse"
4885456e0dSMax Reitz
4985456e0dSMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 1M
5085456e0dSMax ReitzTEST_IMG="$TEST_IMG.not_base" _make_test_img 1M
5185456e0dSMax Reitz_make_test_img -b "$TEST_IMG.base"
5285456e0dSMax Reitz
5385456e0dSMax Reitzmake_opts()
5485456e0dSMax Reitz{
5585456e0dSMax Reitz    node_name=$1
5685456e0dSMax Reitz    filename=$2
5785456e0dSMax Reitz    backing=$3
5885456e0dSMax Reitz
5985456e0dSMax Reitz    if [ -z "$backing" ]; then
6085456e0dSMax Reitz        backing="null"
6185456e0dSMax Reitz    else
6285456e0dSMax Reitz        backing="'$backing'"
6385456e0dSMax Reitz    fi
6485456e0dSMax Reitz
6585456e0dSMax Reitz    echo "{ 'node-name': '$node_name',
6685456e0dSMax Reitz            'driver': 'vmdk',
6785456e0dSMax Reitz            'file': {
6885456e0dSMax Reitz                'driver': 'file',
6985456e0dSMax Reitz                'filename': '$filename'
7085456e0dSMax Reitz            },
7185456e0dSMax Reitz            'backing': $backing }"
7285456e0dSMax Reitz}
7385456e0dSMax Reitz
7485456e0dSMax Reitzoverlay_opts=$(make_opts overlay "$TEST_IMG" backing)
7585456e0dSMax Reitzbase_opts=$(make_opts backing "$TEST_IMG.base")
7685456e0dSMax Reitznot_base_opts=$(make_opts backing "$TEST_IMG.not_base")
7785456e0dSMax Reitz
7885456e0dSMax Reitznot_vmdk_opts="{ 'node-name': 'backing', 'driver': 'null-co' }"
7985456e0dSMax Reitz
8085456e0dSMax Reitzecho
8185456e0dSMax Reitzecho '=== Testing fitting VMDK backing image ==='
8285456e0dSMax Reitzecho
8385456e0dSMax Reitz
8485456e0dSMax Reitzqemu_comm_method=monitor \
8585456e0dSMax Reitz    _launch_qemu -blockdev "$base_opts" -blockdev "$overlay_opts"
8685456e0dSMax Reitz
8785456e0dSMax Reitz# Should not return an error
8885456e0dSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'ops'
8985456e0dSMax Reitz
9085456e0dSMax Reitz_cleanup_qemu
9185456e0dSMax Reitz
9285456e0dSMax Reitz
9385456e0dSMax Reitzecho
9485456e0dSMax Reitzecho '=== Testing unrelated VMDK backing image ==='
9585456e0dSMax Reitzecho
9685456e0dSMax Reitz
9785456e0dSMax Reitzqemu_comm_method=monitor \
9885456e0dSMax Reitz    _launch_qemu -blockdev "$not_base_opts" -blockdev "$overlay_opts"
9985456e0dSMax Reitz
10085456e0dSMax Reitz# Should fail (gracefully)
10185456e0dSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
10285456e0dSMax Reitz
10385456e0dSMax Reitz_cleanup_qemu
10485456e0dSMax Reitz
10585456e0dSMax Reitz
10685456e0dSMax Reitzecho
10785456e0dSMax Reitzecho '=== Testing non-VMDK backing image ==='
10885456e0dSMax Reitzecho
10985456e0dSMax Reitz
11085456e0dSMax Reitz# FIXME: This is the reason why we have to use two -blockdev
11185456e0dSMax Reitz# invocations.  You can only fully override the backing file options
11285456e0dSMax Reitz# if you either specify a node reference (as done here) or the new
11385456e0dSMax Reitz# options contain file.filename (which in this case they do not).
11485456e0dSMax Reitz# In other cases, file.filename will be set to whatever the image
11585456e0dSMax Reitz# header of the overlay contains (which we do not want).  I consider
11685456e0dSMax Reitz# this a FIXME because with -blockdev, you cannot specify "partial"
11785456e0dSMax Reitz# options, so setting file.filename but leaving the rest as specified
11885456e0dSMax Reitz# by the user does not make sense.
11985456e0dSMax Reitzqemu_comm_method=monitor \
12085456e0dSMax Reitz    _launch_qemu -blockdev "$not_vmdk_opts" -blockdev "$overlay_opts"
12185456e0dSMax Reitz
12285456e0dSMax Reitz# Should fail (gracefully)
12385456e0dSMax Reitz_send_qemu_cmd $QEMU_HANDLE 'qemu-io overlay "read 0 512"' 'failed'
12485456e0dSMax Reitz
12585456e0dSMax Reitz_cleanup_qemu
12685456e0dSMax Reitz
12785456e0dSMax Reitz
12885456e0dSMax Reitz# success, all done
12985456e0dSMax Reitzecho "*** done"
13085456e0dSMax Reitzrm -f $seq.full
13185456e0dSMax Reitzstatus=0
132