xref: /openbmc/qemu/tests/qemu-iotests/161 (revision 11a82d14293cd66f428f535741717ff338c0722b)
1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
20065c455SAlberto Garcia#
36bd858b3SAlberto Garcia# Test reopening a backing image after block-stream and block-commit
40065c455SAlberto Garcia#
50065c455SAlberto Garcia# Copyright (C) 2018 Igalia, S.L.
60065c455SAlberto Garcia#
70065c455SAlberto Garcia# This program is free software; you can redistribute it and/or modify
80065c455SAlberto Garcia# it under the terms of the GNU General Public License as published by
90065c455SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
100065c455SAlberto Garcia# (at your option) any later version.
110065c455SAlberto Garcia#
120065c455SAlberto Garcia# This program is distributed in the hope that it will be useful,
130065c455SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
140065c455SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
150065c455SAlberto Garcia# GNU General Public License for more details.
160065c455SAlberto Garcia#
170065c455SAlberto Garcia# You should have received a copy of the GNU General Public License
180065c455SAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
190065c455SAlberto Garcia#
200065c455SAlberto Garcia
210065c455SAlberto Garcia# creator
220065c455SAlberto Garciaowner=berto@igalia.com
230065c455SAlberto Garcia
240065c455SAlberto Garciaseq=`basename $0`
250065c455SAlberto Garciaecho "QA output created by $seq"
260065c455SAlberto Garcia
270065c455SAlberto Garciahere=`pwd`
280065c455SAlberto Garciastatus=1	# failure is the default!
290065c455SAlberto Garcia
300065c455SAlberto Garcia_cleanup()
310065c455SAlberto Garcia{
320065c455SAlberto Garcia    _cleanup_test_img
330065c455SAlberto Garcia    rm -f "$TEST_IMG.base"
340065c455SAlberto Garcia    rm -f "$TEST_IMG.int"
350065c455SAlberto Garcia}
360065c455SAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15
370065c455SAlberto Garcia
380065c455SAlberto Garcia# get standard environment, filters and checks
390065c455SAlberto Garcia. ./common.rc
400065c455SAlberto Garcia. ./common.filter
410065c455SAlberto Garcia. ./common.qemu
420065c455SAlberto Garcia
430065c455SAlberto Garcia# Any format implementing BlockDriver.bdrv_change_backing_file
440065c455SAlberto Garcia_supported_fmt qcow2 qed
450065c455SAlberto Garcia_supported_proto file
460065c455SAlberto Garcia_supported_os Linux
470065c455SAlberto Garcia
480065c455SAlberto GarciaIMG_SIZE=1M
490065c455SAlberto Garcia
500065c455SAlberto Garcia# Create the images
510065c455SAlberto GarciaTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
520065c455SAlberto GarciaTEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
530065c455SAlberto Garcia_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
540065c455SAlberto Garcia
550065c455SAlberto Garcia# First test: reopen $TEST.IMG changing the detect-zeroes option on
560065c455SAlberto Garcia# its backing file ($TEST_IMG.int).
570065c455SAlberto Garciaecho
580065c455SAlberto Garciaecho "*** Change an option on the backing file"
590065c455SAlberto Garciaecho
600065c455SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}"
610065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
620065c455SAlberto Garcia    "{ 'execute': 'qmp_capabilities' }" \
630065c455SAlberto Garcia    'return'
640065c455SAlberto Garcia
650065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
660065c455SAlberto Garcia    "{ 'execute': 'human-monitor-command',
670065c455SAlberto Garcia       'arguments': { 'command-line':
680065c455SAlberto Garcia                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
690065c455SAlberto Garcia    "return"
700065c455SAlberto Garcia
710065c455SAlberto Garcia_cleanup_qemu
720065c455SAlberto Garcia
730065c455SAlberto Garcia# Second test: stream $TEST_IMG.base into $TEST_IMG.int and then
740065c455SAlberto Garcia# reopen $TEST.IMG changing the detect-zeroes option on its new
750065c455SAlberto Garcia# backing file ($TEST_IMG.base).
760065c455SAlberto Garciaecho
770065c455SAlberto Garciaecho "*** Stream and then change an option on the backing file"
780065c455SAlberto Garciaecho
790065c455SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}"
800065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
810065c455SAlberto Garcia    "{ 'execute': 'qmp_capabilities' }" \
820065c455SAlberto Garcia    'return'
830065c455SAlberto Garcia
840065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
850065c455SAlberto Garcia    "{ 'execute': 'block-stream', \
860065c455SAlberto Garcia       'arguments': { 'device': 'none0',
870065c455SAlberto Garcia                      'base': '${TEST_IMG}.base' } }" \
880065c455SAlberto Garcia    'return'
890065c455SAlberto Garcia
900065c455SAlberto Garcia# Wait for block-stream to finish
910065c455SAlberto Garciasleep 0.5
920065c455SAlberto Garcia
930065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
940065c455SAlberto Garcia    "{ 'execute': 'human-monitor-command',
950065c455SAlberto Garcia       'arguments': { 'command-line':
960065c455SAlberto Garcia                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
970065c455SAlberto Garcia    "return"
980065c455SAlberto Garcia
990065c455SAlberto Garcia_cleanup_qemu
1000065c455SAlberto Garcia
1016bd858b3SAlberto Garcia# Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen
1026bd858b3SAlberto Garcia# $TEST.IMG changing the detect-zeroes option on its new backing file
1036bd858b3SAlberto Garcia# ($TEST_IMG.base).
1046bd858b3SAlberto Garciaecho
1056bd858b3SAlberto Garciaecho "*** Commit and then change an option on the backing file"
1066bd858b3SAlberto Garciaecho
1076bd858b3SAlberto Garcia# Create the images again
1086bd858b3SAlberto GarciaTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
1096bd858b3SAlberto GarciaTEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
1106bd858b3SAlberto Garcia_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
1116bd858b3SAlberto Garcia
1126bd858b3SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}"
1136bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
1146bd858b3SAlberto Garcia    "{ 'execute': 'qmp_capabilities' }" \
1156bd858b3SAlberto Garcia    'return'
1166bd858b3SAlberto Garcia
1176bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
1186bd858b3SAlberto Garcia    "{ 'execute': 'block-commit', \
1196bd858b3SAlberto Garcia       'arguments': { 'device': 'none0',
1206bd858b3SAlberto Garcia                      'top': '${TEST_IMG}.int' } }" \
1216bd858b3SAlberto Garcia    'return'
1226bd858b3SAlberto Garcia
1236bd858b3SAlberto Garcia# Wait for block-commit to finish
1246bd858b3SAlberto Garciasleep 0.5
1256bd858b3SAlberto Garcia
1266bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
1276bd858b3SAlberto Garcia    "{ 'execute': 'human-monitor-command',
1286bd858b3SAlberto Garcia       'arguments': { 'command-line':
1296bd858b3SAlberto Garcia                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
1306bd858b3SAlberto Garcia    "return"
1316bd858b3SAlberto Garcia
1326bd858b3SAlberto Garcia_cleanup_qemu
1336bd858b3SAlberto Garcia
1340065c455SAlberto Garcia# success, all done
1350065c455SAlberto Garciaecho "*** done"
1360065c455SAlberto Garciarm -f $seq.full
1370065c455SAlberto Garciastatus=0
138