1#!/usr/bin/env bash 2# 3# Test unsupported blockdev-add cases 4# 5# Copyright (C) 2014 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=kwolf@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} 33trap "_cleanup; exit \$status" 0 1 2 3 15 34 35# get standard environment, filters and checks 36. ./common.rc 37. ./common.filter 38 39_supported_fmt qcow2 40_supported_proto file 41_supported_os Linux 42 43do_run_qemu() 44{ 45 echo Testing: "$@" 46 $QEMU -nographic -qmp stdio -serial none "$@" 47 echo 48} 49 50run_qemu() 51{ 52 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 53 | _filter_qemu | _filter_imgfmt \ 54 | _filter_actual_image_size 55} 56 57size=128M 58 59_make_test_img $size 60 61echo 62echo === Missing ID and node-name === 63echo 64 65run_qemu <<EOF 66{ "execute": "qmp_capabilities" } 67{ "execute": "blockdev-add", 68 "arguments": { 69 "driver": "$IMGFMT", 70 "file": { 71 "driver": "file", 72 "filename": "$TEST_IMG" 73 } 74 } 75 } 76{ "execute": "quit" } 77EOF 78 79echo 80echo === Duplicate ID === 81echo 82 83run_qemu -drive driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <<EOF 84{ "execute": "qmp_capabilities" } 85{ "execute": "blockdev-add", 86 "arguments": { 87 "driver": "$IMGFMT", 88 "node-name": "disk", 89 "file": { 90 "driver": "null-co" 91 } 92 } 93 } 94{ "execute": "blockdev-add", 95 "arguments": { 96 "driver": "$IMGFMT", 97 "node-name": "test-node", 98 "file": { 99 "driver": "null-co" 100 } 101 } 102 } 103{ "execute": "quit" } 104EOF 105 106echo 107echo === aio=native without O_DIRECT === 108echo 109 110# Skip this test if AIO is not enabled in this build 111run_qemu_filter_aio() 112{ 113 run_qemu "$@" | \ 114 sed -e 's/is not supported in this build/it requires cache.direct=on, which was not specified/' 115} 116 117run_qemu_filter_aio <<EOF 118{ "execute": "qmp_capabilities" } 119{ "execute": "blockdev-add", 120 "arguments": { 121 "driver": "$IMGFMT", 122 "node-name": "disk", 123 "file": { 124 "driver": "file", 125 "filename": "$TEST_IMG", 126 "aio": "native" 127 } 128 } 129 } 130{ "execute": "quit" } 131EOF 132 133echo 134echo === Encrypted image QCow === 135echo 136 137_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size 138run_qemu <<EOF 139{ "execute": "qmp_capabilities" } 140{ "execute": "object-add", 141 "arguments": { 142 "qom-type": "secret", 143 "id": "sec0", 144 "props": { 145 "data": "123456" 146 } 147 } 148} 149{ "execute": "blockdev-add", 150 "arguments": { 151 "driver": "$IMGFMT", 152 "node-name": "disk", 153 "file": { 154 "driver": "file", 155 "filename": "$TEST_IMG" 156 }, 157 "encrypt": { 158 "format": "aes", 159 "key-secret": "sec0" 160 } 161 } 162 } 163{ "execute": "quit" } 164EOF 165 166echo 167echo === Encrypted image LUKS === 168echo 169 170_make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $size 171run_qemu <<EOF 172{ "execute": "qmp_capabilities" } 173{ "execute": "object-add", 174 "arguments": { 175 "qom-type": "secret", 176 "id": "sec0", 177 "props": { 178 "data": "123456" 179 } 180 } 181} 182{ "execute": "blockdev-add", 183 "arguments": { 184 "driver": "$IMGFMT", 185 "node-name": "disk", 186 "file": { 187 "driver": "file", 188 "filename": "$TEST_IMG" 189 }, 190 "encrypt": { 191 "format": "luks", 192 "key-secret": "sec0" 193 } 194 } 195 } 196{ "execute": "quit" } 197EOF 198 199echo 200echo === Missing driver === 201echo 202 203_make_test_img --object secret,id=sec0,data=123456 -o encryption=on,encrypt.key-secret=sec0 $size 204run_qemu -S <<EOF 205{ "execute": "qmp_capabilities" } 206{ "execute": "blockdev-add", 207 "arguments": { 208 "node-name": "disk" 209 } 210 } 211{ "execute": "quit" } 212EOF 213 214# success, all done 215echo "*** done" 216rm -f $seq.full 217status=0 218