17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3 2e8f6ea6fSKevin Wolf# 3e8f6ea6fSKevin Wolf# Test parallels and file image creation 4e8f6ea6fSKevin Wolf# 5e8f6ea6fSKevin Wolf# Copyright (C) 2018 Red Hat, Inc. 6e8f6ea6fSKevin Wolf# 72d7abfbeSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com> 82d7abfbeSKevin Wolf# 9e8f6ea6fSKevin Wolf# This program is free software; you can redistribute it and/or modify 10e8f6ea6fSKevin Wolf# it under the terms of the GNU General Public License as published by 11e8f6ea6fSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 12e8f6ea6fSKevin Wolf# (at your option) any later version. 13e8f6ea6fSKevin Wolf# 14e8f6ea6fSKevin Wolf# This program is distributed in the hope that it will be useful, 15e8f6ea6fSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 16e8f6ea6fSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17e8f6ea6fSKevin Wolf# GNU General Public License for more details. 18e8f6ea6fSKevin Wolf# 19e8f6ea6fSKevin Wolf# You should have received a copy of the GNU General Public License 20e8f6ea6fSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 21e8f6ea6fSKevin Wolf# 22e8f6ea6fSKevin Wolf 232d7abfbeSKevin Wolfimport iotests 242d7abfbeSKevin Wolffrom iotests import imgfmt 25e8f6ea6fSKevin Wolf 26*7d814059SJohn Snowiotests.script_initialize( 27*7d814059SJohn Snow supported_fmts=['parallels'], 28*7d814059SJohn Snow supported_protocols=['file'], 29*7d814059SJohn Snow) 30e8f6ea6fSKevin Wolf 312d7abfbeSKevin Wolfwith iotests.FilePath('t.parallels') as disk_path, \ 322d7abfbeSKevin Wolf iotests.VM() as vm: 33e8f6ea6fSKevin Wolf 342d7abfbeSKevin Wolf # 352d7abfbeSKevin Wolf # Successful image creation (defaults) 362d7abfbeSKevin Wolf # 372d7abfbeSKevin Wolf iotests.log("=== Successful image creation (defaults) ===") 382d7abfbeSKevin Wolf iotests.log("") 39e8f6ea6fSKevin Wolf 402d7abfbeSKevin Wolf size = 128 * 1024 * 1024 41e8f6ea6fSKevin Wolf 422d7abfbeSKevin Wolf vm.launch() 4308b17138SKevin Wolf vm.blockdev_create({ 'driver': 'file', 442d7abfbeSKevin Wolf 'filename': disk_path, 452d7abfbeSKevin Wolf 'size': 0 }) 46e8f6ea6fSKevin Wolf 472d7abfbeSKevin Wolf vm.qmp_log('blockdev-add', driver='file', filename=disk_path, 48250c04f5SMax Reitz node_name='imgfile', filters=[iotests.filter_qmp_testfiles]) 49e8f6ea6fSKevin Wolf 5008b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 512d7abfbeSKevin Wolf 'file': 'imgfile', 522d7abfbeSKevin Wolf 'size': size }) 532d7abfbeSKevin Wolf vm.shutdown() 54e8f6ea6fSKevin Wolf 552d7abfbeSKevin Wolf iotests.img_info_log(disk_path) 56e8f6ea6fSKevin Wolf 572d7abfbeSKevin Wolf # 582d7abfbeSKevin Wolf # Successful image creation (explicit defaults) 592d7abfbeSKevin Wolf # 602d7abfbeSKevin Wolf iotests.log("=== Successful image creation (explicit defaults) ===") 612d7abfbeSKevin Wolf iotests.log("") 62e8f6ea6fSKevin Wolf 63e8f6ea6fSKevin Wolf # Choose a different size to show that we got a new image 642d7abfbeSKevin Wolf size = 64 * 1024 * 1024 65e8f6ea6fSKevin Wolf 662d7abfbeSKevin Wolf vm.launch() 6708b17138SKevin Wolf vm.blockdev_create({ 'driver': 'file', 682d7abfbeSKevin Wolf 'filename': disk_path, 692d7abfbeSKevin Wolf 'size': 0 }) 7008b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 712d7abfbeSKevin Wolf 'file': { 722d7abfbeSKevin Wolf 'driver': 'file', 732d7abfbeSKevin Wolf 'filename': disk_path, 74e8f6ea6fSKevin Wolf }, 752d7abfbeSKevin Wolf 'size': size, 762d7abfbeSKevin Wolf 'cluster-size': 1048576 }) 772d7abfbeSKevin Wolf vm.shutdown() 78e8f6ea6fSKevin Wolf 792d7abfbeSKevin Wolf iotests.img_info_log(disk_path) 80e8f6ea6fSKevin Wolf 812d7abfbeSKevin Wolf # 822d7abfbeSKevin Wolf # Successful image creation (with non-default options) 832d7abfbeSKevin Wolf # 842d7abfbeSKevin Wolf iotests.log("=== Successful image creation (with non-default options) ===") 852d7abfbeSKevin Wolf iotests.log("") 86e8f6ea6fSKevin Wolf 87e8f6ea6fSKevin Wolf # Choose a different size to show that we got a new image 882d7abfbeSKevin Wolf size = 32 * 1024 * 1024 89e8f6ea6fSKevin Wolf 902d7abfbeSKevin Wolf vm.launch() 9108b17138SKevin Wolf vm.blockdev_create({ 'driver': 'file', 922d7abfbeSKevin Wolf 'filename': disk_path, 932d7abfbeSKevin Wolf 'size': 0 }) 9408b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 952d7abfbeSKevin Wolf 'file': { 962d7abfbeSKevin Wolf 'driver': 'file', 972d7abfbeSKevin Wolf 'filename': disk_path, 98e8f6ea6fSKevin Wolf }, 992d7abfbeSKevin Wolf 'size': size, 1002d7abfbeSKevin Wolf 'cluster-size': 65536 }) 1012d7abfbeSKevin Wolf vm.shutdown() 102e8f6ea6fSKevin Wolf 1032d7abfbeSKevin Wolf iotests.img_info_log(disk_path) 104e8f6ea6fSKevin Wolf 1052d7abfbeSKevin Wolf # 1062d7abfbeSKevin Wolf # Invalid BlockdevRef 1072d7abfbeSKevin Wolf # 1082d7abfbeSKevin Wolf iotests.log("=== Invalid BlockdevRef ===") 1092d7abfbeSKevin Wolf iotests.log("") 110e8f6ea6fSKevin Wolf 1112d7abfbeSKevin Wolf vm.launch() 11208b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1132d7abfbeSKevin Wolf 'file': "this doesn't exist", 1142d7abfbeSKevin Wolf 'size': size }) 1152d7abfbeSKevin Wolf vm.shutdown() 116e8f6ea6fSKevin Wolf 1172d7abfbeSKevin Wolf # 1182d7abfbeSKevin Wolf # Zero size 1192d7abfbeSKevin Wolf # 1202d7abfbeSKevin Wolf iotests.log("=== Zero size ===") 1212d7abfbeSKevin Wolf iotests.log("") 122e8f6ea6fSKevin Wolf 1232d7abfbeSKevin Wolf vm.add_blockdev('driver=file,filename=%s,node-name=node0' % (disk_path)) 1242d7abfbeSKevin Wolf vm.launch() 12508b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1262d7abfbeSKevin Wolf 'file': 'node0', 1272d7abfbeSKevin Wolf 'size': 0 }) 1282d7abfbeSKevin Wolf vm.shutdown() 129e8f6ea6fSKevin Wolf 1302d7abfbeSKevin Wolf iotests.img_info_log(disk_path) 131e8f6ea6fSKevin Wolf 1322d7abfbeSKevin Wolf # 1332d7abfbeSKevin Wolf # Maximum size 1342d7abfbeSKevin Wolf # 1352d7abfbeSKevin Wolf iotests.log("=== Maximum size ===") 1362d7abfbeSKevin Wolf iotests.log("") 137e8f6ea6fSKevin Wolf 1382d7abfbeSKevin Wolf vm.launch() 13908b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1402d7abfbeSKevin Wolf 'file': 'node0', 1412d7abfbeSKevin Wolf 'size': 4503599627369984}) 1422d7abfbeSKevin Wolf vm.shutdown() 143e8f6ea6fSKevin Wolf 1442d7abfbeSKevin Wolf iotests.img_info_log(disk_path) 145e8f6ea6fSKevin Wolf 1462d7abfbeSKevin Wolf # 1472d7abfbeSKevin Wolf # Invalid sizes 1482d7abfbeSKevin Wolf # 149e8f6ea6fSKevin Wolf 150e8f6ea6fSKevin Wolf # TODO Negative image sizes aren't handled correctly, but this is a problem 1512d7abfbeSKevin Wolf # with QAPI's implementation of the 'size' type and affects other commands 1522d7abfbeSKevin Wolf # as well. Once this is fixed, we may want to add a test case here. 153e8f6ea6fSKevin Wolf 154e8f6ea6fSKevin Wolf # 1. Misaligned image size 155e8f6ea6fSKevin Wolf # 2. 2^64 - 512 156e8f6ea6fSKevin Wolf # 3. 2^63 = 8 EB (qemu-img enforces image sizes less than this) 157e8f6ea6fSKevin Wolf # 4. 2^63 - 512 (generally valid, but with the image header the file will 158e8f6ea6fSKevin Wolf # exceed 63 bits) 159e8f6ea6fSKevin Wolf # 5. 2^52 (512 bytes more than maximum image size) 160e8f6ea6fSKevin Wolf 1612d7abfbeSKevin Wolf iotests.log("=== Invalid sizes ===") 1622d7abfbeSKevin Wolf iotests.log("") 163e8f6ea6fSKevin Wolf 1642d7abfbeSKevin Wolf vm.launch() 1652d7abfbeSKevin Wolf for size in [ 1234, 18446744073709551104, 9223372036854775808, 1662d7abfbeSKevin Wolf 9223372036854775296, 4503599627370497 ]: 16708b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1682d7abfbeSKevin Wolf 'file': 'node0', 1692d7abfbeSKevin Wolf 'size': size }) 1702d7abfbeSKevin Wolf vm.shutdown() 171e8f6ea6fSKevin Wolf 1722d7abfbeSKevin Wolf # 1732d7abfbeSKevin Wolf # Invalid cluster size 1742d7abfbeSKevin Wolf # 1752d7abfbeSKevin Wolf iotests.log("=== Invalid cluster size ===") 1762d7abfbeSKevin Wolf iotests.log("") 177e8f6ea6fSKevin Wolf 1782d7abfbeSKevin Wolf vm.launch() 1792d7abfbeSKevin Wolf for csize in [ 1234, 128, 4294967296, 9223372036854775808, 1802d7abfbeSKevin Wolf 18446744073709551104, 0 ]: 18108b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1822d7abfbeSKevin Wolf 'file': 'node0', 1832d7abfbeSKevin Wolf 'size': 67108864, 1842d7abfbeSKevin Wolf 'cluster-size': csize }) 18508b17138SKevin Wolf vm.blockdev_create({ 'driver': imgfmt, 1862d7abfbeSKevin Wolf 'file': 'node0', 1872d7abfbeSKevin Wolf 'size': 281474976710656, 1882d7abfbeSKevin Wolf 'cluster-size': 512 }) 1892d7abfbeSKevin Wolf vm.shutdown() 190