111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 33fb23e07SKevin Wolf# 43fb23e07SKevin Wolf# Test change-backing-file command 53fb23e07SKevin Wolf# 63fb23e07SKevin Wolf# Copyright (C) 2017 Red Hat, Inc. 73fb23e07SKevin Wolf# 83fb23e07SKevin Wolf# This program is free software; you can redistribute it and/or modify 93fb23e07SKevin Wolf# it under the terms of the GNU General Public License as published by 103fb23e07SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 113fb23e07SKevin Wolf# (at your option) any later version. 123fb23e07SKevin Wolf# 133fb23e07SKevin Wolf# This program is distributed in the hope that it will be useful, 143fb23e07SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 153fb23e07SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 163fb23e07SKevin Wolf# GNU General Public License for more details. 173fb23e07SKevin Wolf# 183fb23e07SKevin Wolf# You should have received a copy of the GNU General Public License 193fb23e07SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 203fb23e07SKevin Wolf# 213fb23e07SKevin Wolf 223fb23e07SKevin Wolf# creator 233fb23e07SKevin Wolfowner=kwolf@redhat.com 243fb23e07SKevin Wolf 253fb23e07SKevin Wolfseq=`basename $0` 263fb23e07SKevin Wolfecho "QA output created by $seq" 273fb23e07SKevin Wolf 283fb23e07SKevin Wolfstatus=1 # failure is the default! 293fb23e07SKevin Wolf 303fb23e07SKevin Wolf_cleanup() 313fb23e07SKevin Wolf{ 323fb23e07SKevin Wolf _cleanup_test_img 33f91ecbd7SMax Reitz _rm_test_img "$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 4257284d2aSMax Reitz_supported_proto file fuse 433fb23e07SKevin Wolf 448cedcffdSEric 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 518cedcffdSEric 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 60b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT 61b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.mid" -F $IMGFMT 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 79b66ff2c2SEric BlakeTEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT 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