1#!/bin/bash 2# 3# Test luks and file image creation 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=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28status=1 # failure is the default! 29 30# get standard environment, filters and checks 31. ./common.rc 32. ./common.filter 33 34_supported_fmt luks 35_supported_proto file 36_supported_os Linux 37 38function do_run_qemu() 39{ 40 echo Testing: "$@" 41 $QEMU -nographic -qmp stdio -serial none "$@" 42 echo 43} 44 45function run_qemu() 46{ 47 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 48 | _filter_qemu | _filter_imgfmt \ 49 | _filter_actual_image_size 50} 51 52echo 53echo "=== Successful image creation (defaults) ===" 54echo 55 56size=$((128 * 1024 * 1024)) 57 58run_qemu -object secret,id=keysec0,data="foo" <<EOF 59{ "execute": "qmp_capabilities" } 60{ "execute": "x-blockdev-create", 61 "arguments": { 62 "driver": "file", 63 "filename": "$TEST_IMG_FILE", 64 "size": 0 65 } 66} 67{ "execute": "blockdev-add", 68 "arguments": { 69 "driver": "file", 70 "node-name": "imgfile", 71 "filename": "$TEST_IMG_FILE" 72 } 73} 74{ "execute": "x-blockdev-create", 75 "arguments": { 76 "driver": "$IMGFMT", 77 "file": "imgfile", 78 "key-secret": "keysec0", 79 "size": $size, 80 "iter-time": 10 81 } 82} 83{ "execute": "quit" } 84EOF 85 86_img_info --format-specific | _filter_img_info --format-specific 87 88echo 89echo "=== Successful image creation (with non-default options) ===" 90echo 91 92# Choose a different size to show that we got a new image 93size=$((64 * 1024 * 1024)) 94 95run_qemu -object secret,id=keysec0,data="foo" <<EOF 96{ "execute": "qmp_capabilities" } 97{ "execute": "x-blockdev-create", 98 "arguments": { 99 "driver": "file", 100 "filename": "$TEST_IMG_FILE", 101 "size": 0 102 } 103} 104{ "execute": "x-blockdev-create", 105 "arguments": { 106 "driver": "$IMGFMT", 107 "file": { 108 "driver": "file", 109 "filename": "$TEST_IMG_FILE" 110 }, 111 "size": $size, 112 "key-secret": "keysec0", 113 "cipher-alg": "twofish-128", 114 "cipher-mode": "ctr", 115 "ivgen-alg": "plain64", 116 "ivgen-hash-alg": "md5", 117 "hash-alg": "sha1", 118 "iter-time": 10 119 } 120} 121{ "execute": "quit" } 122EOF 123 124_img_info --format-specific | _filter_img_info --format-specific 125 126echo 127echo "=== Invalid BlockdevRef ===" 128echo 129 130run_qemu <<EOF 131{ "execute": "qmp_capabilities" } 132{ "execute": "x-blockdev-create", 133 "arguments": { 134 "driver": "$IMGFMT", 135 "file": "this doesn't exist", 136 "size": $size 137 } 138} 139{ "execute": "quit" } 140EOF 141 142echo 143echo "=== Zero size ===" 144echo 145 146run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \ 147 -object secret,id=keysec0,data="foo" <<EOF 148{ "execute": "qmp_capabilities" } 149{ "execute": "x-blockdev-create", 150 "arguments": { 151 "driver": "$IMGFMT", 152 "file": "node0", 153 "key-secret": "keysec0", 154 "size": 0, 155 "iter-time": 10 156 } 157} 158{ "execute": "quit" } 159EOF 160 161_img_info | _filter_img_info 162 163 164echo 165echo "=== Invalid sizes ===" 166echo 167 168# TODO Negative image sizes aren't handled correctly, but this is a problem 169# with QAPI's implementation of the 'size' type and affects other commands as 170# well. Once this is fixed, we may want to add a test case here. 171 172# 1. 2^64 - 512 173# 2. 2^63 = 8 EB (qemu-img enforces image sizes less than this) 174# 3. 2^63 - 512 (generally valid, but with the crypto header the file will 175# exceed 63 bits) 176 177run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \ 178 -object secret,id=keysec0,data="foo" <<EOF 179{ "execute": "qmp_capabilities" } 180{ "execute": "x-blockdev-create", 181 "arguments": { 182 "driver": "$IMGFMT", 183 "file": "node0", 184 "key-secret": "keysec0", 185 "size": 18446744073709551104 186 } 187} 188{ "execute": "x-blockdev-create", 189 "arguments": { 190 "driver": "$IMGFMT", 191 "file": "node0", 192 "key-secret": "keysec0", 193 "size": 9223372036854775808 194 } 195} 196{ "execute": "x-blockdev-create", 197 "arguments": { 198 "driver": "$IMGFMT", 199 "file": "node0", 200 "key-secret": "keysec0", 201 "size": 9223372036854775296 202 } 203} 204{ "execute": "quit" } 205EOF 206 207echo 208echo "=== Resize image with invalid sizes ===" 209echo 210 211run_qemu -blockdev driver=file,filename="$TEST_IMG_FILE",node-name=node0 \ 212 -blockdev driver=luks,file=node0,key-secret=keysec0,node-name=node1 \ 213 -object secret,id=keysec0,data="foo" <<EOF 214{ "execute": "qmp_capabilities" } 215{ "execute": "block_resize", 216 "arguments": { 217 "node-name": "node1", 218 "size": 9223372036854775296 219 } 220} 221{ "execute": "block_resize", 222 "arguments": { 223 "node-name": "node1", 224 "size": 9223372036854775808 225 } 226} 227{ "execute": "block_resize", 228 "arguments": { 229 "node-name": "node1", 230 "size": 18446744073709551104 231 } 232} 233{ "execute": "block_resize", 234 "arguments": { 235 "node-name": "node1", 236 "size": -9223372036854775808 237 } 238} 239{ "execute": "quit" } 240EOF 241 242_img_info | _filter_img_info 243 244# success, all done 245echo "*** done" 246rm -f $seq.full 247status=0 248