13fb23e07SKevin Wolf#!/bin/bash 23fb23e07SKevin Wolf# 33fb23e07SKevin Wolf# Test change-backing-file command 43fb23e07SKevin Wolf# 53fb23e07SKevin Wolf# Copyright (C) 2017 Red Hat, Inc. 63fb23e07SKevin Wolf# 73fb23e07SKevin Wolf# This program is free software; you can redistribute it and/or modify 83fb23e07SKevin Wolf# it under the terms of the GNU General Public License as published by 93fb23e07SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 103fb23e07SKevin Wolf# (at your option) any later version. 113fb23e07SKevin Wolf# 123fb23e07SKevin Wolf# This program is distributed in the hope that it will be useful, 133fb23e07SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 143fb23e07SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 153fb23e07SKevin Wolf# GNU General Public License for more details. 163fb23e07SKevin Wolf# 173fb23e07SKevin Wolf# You should have received a copy of the GNU General Public License 183fb23e07SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 193fb23e07SKevin Wolf# 203fb23e07SKevin Wolf 213fb23e07SKevin Wolf# creator 223fb23e07SKevin Wolfowner=kwolf@redhat.com 233fb23e07SKevin Wolf 243fb23e07SKevin Wolfseq=`basename $0` 253fb23e07SKevin Wolfecho "QA output created by $seq" 263fb23e07SKevin Wolf 273fb23e07SKevin Wolfhere=`pwd` 283fb23e07SKevin Wolfstatus=1 # failure is the default! 293fb23e07SKevin Wolf 303fb23e07SKevin Wolf_cleanup() 313fb23e07SKevin Wolf{ 323fb23e07SKevin Wolf _cleanup_test_img 333fb23e07SKevin Wolf rm -f "$TEST_IMG.mid" 343fb23e07SKevin Wolf} 353fb23e07SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 363fb23e07SKevin Wolf 373fb23e07SKevin Wolf# get standard environment, filters and checks 383fb23e07SKevin Wolf. ./common.rc 393fb23e07SKevin Wolf. ./common.filter 403fb23e07SKevin Wolf 413fb23e07SKevin Wolf_supported_fmt qcow2 423fb23e07SKevin Wolf_supported_proto file 433fb23e07SKevin Wolf_supported_os Linux 443fb23e07SKevin Wolf 453fb23e07SKevin Wolffunction do_run_qemu() 463fb23e07SKevin Wolf{ 47*47500c67SMax Reitz echo Testing: "$@" 483fb23e07SKevin Wolf $QEMU -nographic -qmp-pretty stdio -serial none "$@" 493fb23e07SKevin Wolf echo 503fb23e07SKevin Wolf} 513fb23e07SKevin Wolf 523fb23e07SKevin Wolffunction run_qemu() 533fb23e07SKevin Wolf{ 54*47500c67SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \ 55*47500c67SMax Reitz | _filter_qmp | _filter_qemu_io \ 56*47500c67SMax Reitz | _filter_generated_node_ids 573fb23e07SKevin Wolf} 583fb23e07SKevin Wolf 593fb23e07SKevin Wolfsize=64M 603fb23e07SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 613fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 623fb23e07SKevin Wolf_make_test_img -b "$TEST_IMG.mid" 633fb23e07SKevin Wolf 643fb23e07SKevin Wolfecho 653fb23e07SKevin Wolfecho "Change backing file of mid (opened read-only)" 663fb23e07SKevin Wolfecho 673fb23e07SKevin Wolf 683fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",backing.node-name=mid <<EOF 693fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 703fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"mid","backing-file":"/dev/null"}} 713fb23e07SKevin Wolf{"execute":"quit"} 723fb23e07SKevin WolfEOF 733fb23e07SKevin Wolf 743fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _img_info 753fb23e07SKevin Wolf 763fb23e07SKevin Wolfecho 773fb23e07SKevin Wolfecho "Change backing file of top (opened writable)" 783fb23e07SKevin Wolfecho 793fb23e07SKevin Wolf 803fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 813fb23e07SKevin Wolf 823fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",node-name=top <<EOF 833fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 843fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"top","backing-file":"/dev/null"}} 853fb23e07SKevin Wolf{"execute":"quit"} 863fb23e07SKevin WolfEOF 873fb23e07SKevin Wolf 883fb23e07SKevin Wolf_img_info 893fb23e07SKevin Wolf 903fb23e07SKevin Wolf# success, all done 913fb23e07SKevin Wolfecho "*** done" 923fb23e07SKevin Wolfrm -f $seq.full 933fb23e07SKevin Wolfstatus=0 94