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