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 Wolfstatus=1 # failure is the default! 283fb23e07SKevin Wolf 293fb23e07SKevin Wolf_cleanup() 303fb23e07SKevin Wolf{ 313fb23e07SKevin Wolf _cleanup_test_img 323fb23e07SKevin Wolf rm -f "$TEST_IMG.mid" 333fb23e07SKevin Wolf} 343fb23e07SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 353fb23e07SKevin Wolf 363fb23e07SKevin Wolf# get standard environment, filters and checks 373fb23e07SKevin Wolf. ./common.rc 383fb23e07SKevin Wolf. ./common.filter 393fb23e07SKevin Wolf 403fb23e07SKevin Wolf_supported_fmt qcow2 413fb23e07SKevin Wolf_supported_proto file 423fb23e07SKevin Wolf_supported_os Linux 433fb23e07SKevin Wolf 44*8cedcffdSEric Blakedo_run_qemu() 453fb23e07SKevin Wolf{ 4647500c67SMax Reitz echo Testing: "$@" 473fb23e07SKevin Wolf $QEMU -nographic -qmp-pretty stdio -serial none "$@" 483fb23e07SKevin Wolf echo 493fb23e07SKevin Wolf} 503fb23e07SKevin Wolf 51*8cedcffdSEric Blakerun_qemu() 523fb23e07SKevin Wolf{ 5347500c67SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \ 5447500c67SMax Reitz | _filter_qmp | _filter_qemu_io \ 5547500c67SMax Reitz | _filter_generated_node_ids 563fb23e07SKevin Wolf} 573fb23e07SKevin Wolf 583fb23e07SKevin Wolfsize=64M 593fb23e07SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img $size 603fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 613fb23e07SKevin Wolf_make_test_img -b "$TEST_IMG.mid" 623fb23e07SKevin Wolf 633fb23e07SKevin Wolfecho 643fb23e07SKevin Wolfecho "Change backing file of mid (opened read-only)" 653fb23e07SKevin Wolfecho 663fb23e07SKevin Wolf 673fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",backing.node-name=mid <<EOF 683fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 693fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"mid","backing-file":"/dev/null"}} 703fb23e07SKevin Wolf{"execute":"quit"} 713fb23e07SKevin WolfEOF 723fb23e07SKevin Wolf 733fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _img_info 743fb23e07SKevin Wolf 753fb23e07SKevin Wolfecho 763fb23e07SKevin Wolfecho "Change backing file of top (opened writable)" 773fb23e07SKevin Wolfecho 783fb23e07SKevin Wolf 793fb23e07SKevin WolfTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" 803fb23e07SKevin Wolf 813fb23e07SKevin Wolfrun_qemu -drive if=none,file="$TEST_IMG",node-name=top <<EOF 823fb23e07SKevin Wolf{"execute":"qmp_capabilities"} 833fb23e07SKevin Wolf{"execute":"change-backing-file", "arguments":{"device":"none0","image-node-name":"top","backing-file":"/dev/null"}} 843fb23e07SKevin Wolf{"execute":"quit"} 853fb23e07SKevin WolfEOF 863fb23e07SKevin Wolf 873fb23e07SKevin Wolf_img_info 883fb23e07SKevin Wolf 893fb23e07SKevin Wolf# success, all done 903fb23e07SKevin Wolfecho "*** done" 913fb23e07SKevin Wolfrm -f $seq.full 923fb23e07SKevin Wolfstatus=0 93