1*39218a77SKevin Wolf#!/bin/bash 2*39218a77SKevin Wolf# 3*39218a77SKevin Wolf# Test qcow2 and file image creation 4*39218a77SKevin Wolf# 5*39218a77SKevin Wolf# Copyright (C) 2018 Red Hat, Inc. 6*39218a77SKevin Wolf# 7*39218a77SKevin Wolf# This program is free software; you can redistribute it and/or modify 8*39218a77SKevin Wolf# it under the terms of the GNU General Public License as published by 9*39218a77SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*39218a77SKevin Wolf# (at your option) any later version. 11*39218a77SKevin Wolf# 12*39218a77SKevin Wolf# This program is distributed in the hope that it will be useful, 13*39218a77SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*39218a77SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*39218a77SKevin Wolf# GNU General Public License for more details. 16*39218a77SKevin Wolf# 17*39218a77SKevin Wolf# You should have received a copy of the GNU General Public License 18*39218a77SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*39218a77SKevin Wolf# 20*39218a77SKevin Wolf 21*39218a77SKevin Wolf# creator 22*39218a77SKevin Wolfowner=kwolf@redhat.com 23*39218a77SKevin Wolf 24*39218a77SKevin Wolfseq=`basename $0` 25*39218a77SKevin Wolfecho "QA output created by $seq" 26*39218a77SKevin Wolf 27*39218a77SKevin Wolfhere=`pwd` 28*39218a77SKevin Wolfstatus=1 # failure is the default! 29*39218a77SKevin Wolf 30*39218a77SKevin Wolf# get standard environment, filters and checks 31*39218a77SKevin Wolf. ./common.rc 32*39218a77SKevin Wolf. ./common.filter 33*39218a77SKevin Wolf 34*39218a77SKevin Wolf_supported_fmt qcow2 35*39218a77SKevin Wolf_supported_proto file 36*39218a77SKevin Wolf_supported_os Linux 37*39218a77SKevin Wolf 38*39218a77SKevin Wolffunction do_run_qemu() 39*39218a77SKevin Wolf{ 40*39218a77SKevin Wolf echo Testing: "$@" 41*39218a77SKevin Wolf $QEMU -nographic -qmp stdio -serial none "$@" 42*39218a77SKevin Wolf echo 43*39218a77SKevin Wolf} 44*39218a77SKevin Wolf 45*39218a77SKevin Wolffunction run_qemu() 46*39218a77SKevin Wolf{ 47*39218a77SKevin Wolf do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 48*39218a77SKevin Wolf | _filter_qemu | _filter_imgfmt \ 49*39218a77SKevin Wolf | _filter_actual_image_size 50*39218a77SKevin Wolf} 51*39218a77SKevin Wolf 52*39218a77SKevin Wolfecho 53*39218a77SKevin Wolfecho "=== Successful image creation (defaults) ===" 54*39218a77SKevin Wolfecho 55*39218a77SKevin Wolf 56*39218a77SKevin Wolfsize=$((128 * 1024 * 1024)) 57*39218a77SKevin Wolf 58*39218a77SKevin Wolfrun_qemu <<EOF 59*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 60*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 61*39218a77SKevin Wolf "arguments": { 62*39218a77SKevin Wolf "driver": "file", 63*39218a77SKevin Wolf "filename": "$TEST_IMG", 64*39218a77SKevin Wolf "size": 0 65*39218a77SKevin Wolf } 66*39218a77SKevin Wolf} 67*39218a77SKevin Wolf{ "execute": "blockdev-add", 68*39218a77SKevin Wolf "arguments": { 69*39218a77SKevin Wolf "driver": "file", 70*39218a77SKevin Wolf "node-name": "imgfile", 71*39218a77SKevin Wolf "filename": "$TEST_IMG" 72*39218a77SKevin Wolf } 73*39218a77SKevin Wolf} 74*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 75*39218a77SKevin Wolf "arguments": { 76*39218a77SKevin Wolf "driver": "$IMGFMT", 77*39218a77SKevin Wolf "file": "imgfile", 78*39218a77SKevin Wolf "size": $size 79*39218a77SKevin Wolf } 80*39218a77SKevin Wolf} 81*39218a77SKevin Wolf{ "execute": "quit" } 82*39218a77SKevin WolfEOF 83*39218a77SKevin Wolf 84*39218a77SKevin Wolf_img_info --format-specific 85*39218a77SKevin Wolf 86*39218a77SKevin Wolfecho 87*39218a77SKevin Wolfecho "=== Successful image creation (inline blockdev-add, explicit defaults) ===" 88*39218a77SKevin Wolfecho 89*39218a77SKevin Wolf 90*39218a77SKevin Wolf# Choose a different size to show that we got a new image 91*39218a77SKevin Wolfsize=$((64 * 1024 * 1024)) 92*39218a77SKevin Wolf 93*39218a77SKevin Wolfrun_qemu <<EOF 94*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 95*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 96*39218a77SKevin Wolf "arguments": { 97*39218a77SKevin Wolf "driver": "file", 98*39218a77SKevin Wolf "filename": "$TEST_IMG", 99*39218a77SKevin Wolf "size": 0, 100*39218a77SKevin Wolf "preallocation": "off", 101*39218a77SKevin Wolf "nocow": false 102*39218a77SKevin Wolf } 103*39218a77SKevin Wolf} 104*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 105*39218a77SKevin Wolf "arguments": { 106*39218a77SKevin Wolf "driver": "$IMGFMT", 107*39218a77SKevin Wolf "file": { 108*39218a77SKevin Wolf "driver": "file", 109*39218a77SKevin Wolf "filename": "$TEST_IMG" 110*39218a77SKevin Wolf }, 111*39218a77SKevin Wolf "size": $size, 112*39218a77SKevin Wolf "version": "v3", 113*39218a77SKevin Wolf "cluster-size": 65536, 114*39218a77SKevin Wolf "preallocation": "off", 115*39218a77SKevin Wolf "lazy-refcounts": false, 116*39218a77SKevin Wolf "refcount-bits": 16 117*39218a77SKevin Wolf } 118*39218a77SKevin Wolf} 119*39218a77SKevin Wolf{ "execute": "quit" } 120*39218a77SKevin WolfEOF 121*39218a77SKevin Wolf 122*39218a77SKevin Wolf_img_info --format-specific 123*39218a77SKevin Wolf 124*39218a77SKevin Wolfecho 125*39218a77SKevin Wolfecho "=== Successful image creation (v3 non-default options) ===" 126*39218a77SKevin Wolfecho 127*39218a77SKevin Wolf 128*39218a77SKevin Wolf# Choose a different size to show that we got a new image 129*39218a77SKevin Wolfsize=$((32 * 1024 * 1024)) 130*39218a77SKevin Wolf 131*39218a77SKevin Wolfrun_qemu <<EOF 132*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 133*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 134*39218a77SKevin Wolf "arguments": { 135*39218a77SKevin Wolf "driver": "file", 136*39218a77SKevin Wolf "filename": "$TEST_IMG", 137*39218a77SKevin Wolf "size": 0, 138*39218a77SKevin Wolf "preallocation": "falloc", 139*39218a77SKevin Wolf "nocow": true 140*39218a77SKevin Wolf } 141*39218a77SKevin Wolf} 142*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 143*39218a77SKevin Wolf "arguments": { 144*39218a77SKevin Wolf "driver": "$IMGFMT", 145*39218a77SKevin Wolf "file": { 146*39218a77SKevin Wolf "driver": "file", 147*39218a77SKevin Wolf "filename": "$TEST_IMG" 148*39218a77SKevin Wolf }, 149*39218a77SKevin Wolf "size": $size, 150*39218a77SKevin Wolf "version": "v3", 151*39218a77SKevin Wolf "cluster-size": 2097152, 152*39218a77SKevin Wolf "preallocation": "metadata", 153*39218a77SKevin Wolf "lazy-refcounts": true, 154*39218a77SKevin Wolf "refcount-bits": 1 155*39218a77SKevin Wolf } 156*39218a77SKevin Wolf} 157*39218a77SKevin Wolf{ "execute": "quit" } 158*39218a77SKevin WolfEOF 159*39218a77SKevin Wolf 160*39218a77SKevin Wolf_img_info --format-specific 161*39218a77SKevin Wolf 162*39218a77SKevin Wolfecho 163*39218a77SKevin Wolfecho "=== Successful image creation (v2 non-default options) ===" 164*39218a77SKevin Wolfecho 165*39218a77SKevin Wolf 166*39218a77SKevin Wolfmv $TEST_IMG $TEST_IMG.base 167*39218a77SKevin Wolf 168*39218a77SKevin Wolfrun_qemu <<EOF 169*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 170*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 171*39218a77SKevin Wolf "arguments": { 172*39218a77SKevin Wolf "driver": "file", 173*39218a77SKevin Wolf "filename": "$TEST_IMG", 174*39218a77SKevin Wolf "size": 0 175*39218a77SKevin Wolf } 176*39218a77SKevin Wolf} 177*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 178*39218a77SKevin Wolf "arguments": { 179*39218a77SKevin Wolf "driver": "$IMGFMT", 180*39218a77SKevin Wolf "file": { 181*39218a77SKevin Wolf "driver": "file", 182*39218a77SKevin Wolf "filename": "$TEST_IMG" 183*39218a77SKevin Wolf }, 184*39218a77SKevin Wolf "size": $size, 185*39218a77SKevin Wolf "backing-file": "$TEST_IMG.base", 186*39218a77SKevin Wolf "backing-fmt": "qcow2", 187*39218a77SKevin Wolf "version": "v2", 188*39218a77SKevin Wolf "cluster-size": 512 189*39218a77SKevin Wolf } 190*39218a77SKevin Wolf} 191*39218a77SKevin Wolf{ "execute": "quit" } 192*39218a77SKevin WolfEOF 193*39218a77SKevin Wolf 194*39218a77SKevin Wolf_img_info --format-specific 195*39218a77SKevin Wolf 196*39218a77SKevin Wolfecho 197*39218a77SKevin Wolfecho "=== Successful image creation (encrypted) ===" 198*39218a77SKevin Wolfecho 199*39218a77SKevin Wolf 200*39218a77SKevin Wolfrun_qemu -object secret,id=keysec0,data="foo" <<EOF 201*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 202*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 203*39218a77SKevin Wolf "arguments": { 204*39218a77SKevin Wolf "driver": "$IMGFMT", 205*39218a77SKevin Wolf "file": { 206*39218a77SKevin Wolf "driver": "file", 207*39218a77SKevin Wolf "filename": "$TEST_IMG" 208*39218a77SKevin Wolf }, 209*39218a77SKevin Wolf "size": $size, 210*39218a77SKevin Wolf "encrypt": { 211*39218a77SKevin Wolf "format": "luks", 212*39218a77SKevin Wolf "key-secret": "keysec0", 213*39218a77SKevin Wolf "cipher-alg": "twofish-128", 214*39218a77SKevin Wolf "cipher-mode": "ctr", 215*39218a77SKevin Wolf "ivgen-alg": "plain64", 216*39218a77SKevin Wolf "ivgen-hash-alg": "md5", 217*39218a77SKevin Wolf "hash-alg": "sha1", 218*39218a77SKevin Wolf "iter-time": 10 219*39218a77SKevin Wolf } 220*39218a77SKevin Wolf } 221*39218a77SKevin Wolf} 222*39218a77SKevin Wolf{ "execute": "quit" } 223*39218a77SKevin WolfEOF 224*39218a77SKevin Wolf 225*39218a77SKevin Wolf_img_info --format-specific | _filter_img_info --format-specific 226*39218a77SKevin Wolf 227*39218a77SKevin Wolfecho 228*39218a77SKevin Wolfecho "=== Invalid BlockdevRef ===" 229*39218a77SKevin Wolfecho 230*39218a77SKevin Wolf 231*39218a77SKevin Wolfrun_qemu <<EOF 232*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 233*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 234*39218a77SKevin Wolf "arguments": { 235*39218a77SKevin Wolf "driver": "$IMGFMT", 236*39218a77SKevin Wolf "file": "this doesn't exist", 237*39218a77SKevin Wolf "size": $size 238*39218a77SKevin Wolf } 239*39218a77SKevin Wolf} 240*39218a77SKevin Wolf{ "execute": "quit" } 241*39218a77SKevin WolfEOF 242*39218a77SKevin Wolf 243*39218a77SKevin Wolf 244*39218a77SKevin Wolfecho 245*39218a77SKevin Wolfecho "=== Invalid sizes ===" 246*39218a77SKevin Wolfecho 247*39218a77SKevin Wolf 248*39218a77SKevin Wolf# TODO Negative image sizes aren't handled correctly, but this is a problem 249*39218a77SKevin Wolf# with QAPI's implementation of the 'size' type and affects other commands as 250*39218a77SKevin Wolf# well. Once this is fixed, we may want to add a test case here. 251*39218a77SKevin Wolf 252*39218a77SKevin Wolf# 1. Misaligned image size 253*39218a77SKevin Wolf# 2. 2^64 - 512 254*39218a77SKevin Wolf# 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this) 255*39218a77SKevin Wolf# 4. 2^63 - 512 (generally valid, but qcow2 can't handle images this size) 256*39218a77SKevin Wolf 257*39218a77SKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 258*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 259*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 260*39218a77SKevin Wolf "arguments": { 261*39218a77SKevin Wolf "driver": "$IMGFMT", 262*39218a77SKevin Wolf "file": "node0", 263*39218a77SKevin Wolf "size": 1234 264*39218a77SKevin Wolf } 265*39218a77SKevin Wolf} 266*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 267*39218a77SKevin Wolf "arguments": { 268*39218a77SKevin Wolf "driver": "$IMGFMT", 269*39218a77SKevin Wolf "file": "node0", 270*39218a77SKevin Wolf "size": 18446744073709551104 271*39218a77SKevin Wolf } 272*39218a77SKevin Wolf} 273*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 274*39218a77SKevin Wolf "arguments": { 275*39218a77SKevin Wolf "driver": "$IMGFMT", 276*39218a77SKevin Wolf "file": "node0", 277*39218a77SKevin Wolf "size": 9223372036854775808 278*39218a77SKevin Wolf } 279*39218a77SKevin Wolf} 280*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 281*39218a77SKevin Wolf "arguments": { 282*39218a77SKevin Wolf "driver": "$IMGFMT", 283*39218a77SKevin Wolf "file": "node0", 284*39218a77SKevin Wolf "size": 9223372036854775296 285*39218a77SKevin Wolf } 286*39218a77SKevin Wolf} 287*39218a77SKevin Wolf{ "execute": "quit" } 288*39218a77SKevin WolfEOF 289*39218a77SKevin Wolf 290*39218a77SKevin Wolfecho 291*39218a77SKevin Wolfecho "=== Invalid version ===" 292*39218a77SKevin Wolfecho 293*39218a77SKevin Wolf 294*39218a77SKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 295*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 296*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 297*39218a77SKevin Wolf "arguments": { 298*39218a77SKevin Wolf "driver": "$IMGFMT", 299*39218a77SKevin Wolf "file": "node0", 300*39218a77SKevin Wolf "size": 67108864, 301*39218a77SKevin Wolf "version": "v1" 302*39218a77SKevin Wolf } 303*39218a77SKevin Wolf} 304*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 305*39218a77SKevin Wolf "arguments": { 306*39218a77SKevin Wolf "driver": "$IMGFMT", 307*39218a77SKevin Wolf "file": "node0", 308*39218a77SKevin Wolf "size": 67108864, 309*39218a77SKevin Wolf "version": "v2", 310*39218a77SKevin Wolf "lazy-refcounts": true 311*39218a77SKevin Wolf } 312*39218a77SKevin Wolf} 313*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 314*39218a77SKevin Wolf "arguments": { 315*39218a77SKevin Wolf "driver": "$IMGFMT", 316*39218a77SKevin Wolf "file": "node0", 317*39218a77SKevin Wolf "size": 67108864, 318*39218a77SKevin Wolf "version": "v2", 319*39218a77SKevin Wolf "refcount-bits": 8 320*39218a77SKevin Wolf } 321*39218a77SKevin Wolf} 322*39218a77SKevin Wolf{ "execute": "quit" } 323*39218a77SKevin WolfEOF 324*39218a77SKevin Wolf 325*39218a77SKevin Wolfecho 326*39218a77SKevin Wolfecho "=== Invalid backing file options ===" 327*39218a77SKevin Wolfecho 328*39218a77SKevin Wolf 329*39218a77SKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 330*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 331*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 332*39218a77SKevin Wolf "arguments": { 333*39218a77SKevin Wolf "driver": "$IMGFMT", 334*39218a77SKevin Wolf "file": "node0", 335*39218a77SKevin Wolf "size": 67108864, 336*39218a77SKevin Wolf "backing-file": "/dev/null", 337*39218a77SKevin Wolf "preallocation": "full" 338*39218a77SKevin Wolf } 339*39218a77SKevin Wolf} 340*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 341*39218a77SKevin Wolf "arguments": { 342*39218a77SKevin Wolf "driver": "$IMGFMT", 343*39218a77SKevin Wolf "file": "node0", 344*39218a77SKevin Wolf "size": 67108864, 345*39218a77SKevin Wolf "backing-fmt": "$IMGFMT" 346*39218a77SKevin Wolf } 347*39218a77SKevin Wolf} 348*39218a77SKevin Wolf{ "execute": "quit" } 349*39218a77SKevin WolfEOF 350*39218a77SKevin Wolf 351*39218a77SKevin Wolfecho 352*39218a77SKevin Wolfecho "=== Invalid cluster size ===" 353*39218a77SKevin Wolfecho 354*39218a77SKevin Wolf 355*39218a77SKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 356*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 357*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 358*39218a77SKevin Wolf "arguments": { 359*39218a77SKevin Wolf "driver": "$IMGFMT", 360*39218a77SKevin Wolf "file": "node0", 361*39218a77SKevin Wolf "size": 67108864, 362*39218a77SKevin Wolf "cluster-size": 1234 363*39218a77SKevin Wolf } 364*39218a77SKevin Wolf} 365*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 366*39218a77SKevin Wolf "arguments": { 367*39218a77SKevin Wolf "driver": "$IMGFMT", 368*39218a77SKevin Wolf "file": "node0", 369*39218a77SKevin Wolf "size": 67108864, 370*39218a77SKevin Wolf "cluster-size": 128 371*39218a77SKevin Wolf } 372*39218a77SKevin Wolf} 373*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 374*39218a77SKevin Wolf "arguments": { 375*39218a77SKevin Wolf "driver": "$IMGFMT", 376*39218a77SKevin Wolf "file": "node0", 377*39218a77SKevin Wolf "size": 67108864, 378*39218a77SKevin Wolf "cluster-size": 4194304 379*39218a77SKevin Wolf } 380*39218a77SKevin Wolf} 381*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 382*39218a77SKevin Wolf "arguments": { 383*39218a77SKevin Wolf "driver": "$IMGFMT", 384*39218a77SKevin Wolf "file": "node0", 385*39218a77SKevin Wolf "size": 67108864, 386*39218a77SKevin Wolf "cluster-size": 0 387*39218a77SKevin Wolf } 388*39218a77SKevin Wolf} 389*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 390*39218a77SKevin Wolf "arguments": { 391*39218a77SKevin Wolf "driver": "$IMGFMT", 392*39218a77SKevin Wolf "file": "node0", 393*39218a77SKevin Wolf "size": 281474976710656, 394*39218a77SKevin Wolf "cluster-size": 512 395*39218a77SKevin Wolf } 396*39218a77SKevin Wolf} 397*39218a77SKevin Wolf{ "execute": "quit" } 398*39218a77SKevin WolfEOF 399*39218a77SKevin Wolf 400*39218a77SKevin Wolfecho 401*39218a77SKevin Wolfecho "=== Invalid refcount width ===" 402*39218a77SKevin Wolfecho 403*39218a77SKevin Wolf 404*39218a77SKevin Wolfrun_qemu -blockdev driver=file,filename="$TEST_IMG",node-name=node0 <<EOF 405*39218a77SKevin Wolf{ "execute": "qmp_capabilities" } 406*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 407*39218a77SKevin Wolf "arguments": { 408*39218a77SKevin Wolf "driver": "$IMGFMT", 409*39218a77SKevin Wolf "file": "node0", 410*39218a77SKevin Wolf "size": 67108864, 411*39218a77SKevin Wolf "refcount-bits": 128 412*39218a77SKevin Wolf } 413*39218a77SKevin Wolf} 414*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 415*39218a77SKevin Wolf "arguments": { 416*39218a77SKevin Wolf "driver": "$IMGFMT", 417*39218a77SKevin Wolf "file": "node0", 418*39218a77SKevin Wolf "size": 67108864, 419*39218a77SKevin Wolf "refcount-bits": 0 420*39218a77SKevin Wolf } 421*39218a77SKevin Wolf} 422*39218a77SKevin Wolf{ "execute": "x-blockdev-create", 423*39218a77SKevin Wolf "arguments": { 424*39218a77SKevin Wolf "driver": "$IMGFMT", 425*39218a77SKevin Wolf "file": "node0", 426*39218a77SKevin Wolf "size": 67108864, 427*39218a77SKevin Wolf "refcount-bits": 7 428*39218a77SKevin Wolf } 429*39218a77SKevin Wolf} 430*39218a77SKevin Wolf{ "execute": "quit" } 431*39218a77SKevin WolfEOF 432*39218a77SKevin Wolf 433*39218a77SKevin Wolf# success, all done 434*39218a77SKevin Wolfecho "*** done" 435*39218a77SKevin Wolfrm -f $seq.full 436*39218a77SKevin Wolfstatus=0 437