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