10065c455SAlberto Garcia#!/bin/bash 20065c455SAlberto Garcia# 3*6bd858b3SAlberto 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 101*6bd858b3SAlberto Garcia# Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen 102*6bd858b3SAlberto Garcia# $TEST.IMG changing the detect-zeroes option on its new backing file 103*6bd858b3SAlberto Garcia# ($TEST_IMG.base). 104*6bd858b3SAlberto Garciaecho 105*6bd858b3SAlberto Garciaecho "*** Commit and then change an option on the backing file" 106*6bd858b3SAlberto Garciaecho 107*6bd858b3SAlberto Garcia# Create the images again 108*6bd858b3SAlberto GarciaTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt 109*6bd858b3SAlberto GarciaTEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt 110*6bd858b3SAlberto Garcia_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt 111*6bd858b3SAlberto Garcia 112*6bd858b3SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}" 113*6bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \ 114*6bd858b3SAlberto Garcia "{ 'execute': 'qmp_capabilities' }" \ 115*6bd858b3SAlberto Garcia 'return' 116*6bd858b3SAlberto Garcia 117*6bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \ 118*6bd858b3SAlberto Garcia "{ 'execute': 'block-commit', \ 119*6bd858b3SAlberto Garcia 'arguments': { 'device': 'none0', 120*6bd858b3SAlberto Garcia 'top': '${TEST_IMG}.int' } }" \ 121*6bd858b3SAlberto Garcia 'return' 122*6bd858b3SAlberto Garcia 123*6bd858b3SAlberto Garcia# Wait for block-commit to finish 124*6bd858b3SAlberto Garciasleep 0.5 125*6bd858b3SAlberto Garcia 126*6bd858b3SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \ 127*6bd858b3SAlberto Garcia "{ 'execute': 'human-monitor-command', 128*6bd858b3SAlberto Garcia 'arguments': { 'command-line': 129*6bd858b3SAlberto Garcia 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \ 130*6bd858b3SAlberto Garcia "return" 131*6bd858b3SAlberto Garcia 132*6bd858b3SAlberto Garcia_cleanup_qemu 133*6bd858b3SAlberto Garcia 1340065c455SAlberto Garcia# success, all done 1350065c455SAlberto Garciaecho "*** done" 1360065c455SAlberto Garciarm -f $seq.full 1370065c455SAlberto Garciastatus=0 138