1#!/usr/bin/env bash 2# 3# Test which nodes are involved in internal snapshots 4# 5# Copyright (C) 2019 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27status=1 # failure is the default! 28 29_cleanup() 30{ 31 _cleanup_test_img 32 rm -f "$TEST_DIR/nbd" 33} 34trap "_cleanup; exit \$status" 0 1 2 3 15 35 36# get standard environment, filters and checks 37. ./common.rc 38. ./common.filter 39 40_supported_fmt qcow2 41_supported_proto file 42_supported_os Linux 43 44# Internal snapshots are (currently) impossible with refcount_bits=1 45_unsupported_imgopts 'refcount_bits=1[^0-9]' 46 47do_run_qemu() 48{ 49 echo Testing: "$@" 50 ( 51 if ! test -t 0; then 52 while read cmd; do 53 echo $cmd 54 done 55 fi 56 echo quit 57 ) | $QEMU -nographic -monitor stdio -nodefaults "$@" 58 echo 59} 60 61run_qemu() 62{ 63 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp | 64 _filter_generated_node_ids | _filter_imgfmt | _filter_vmstate_size 65} 66 67size=128M 68 69run_test() 70{ 71 _make_test_img $size 72 printf "savevm snap0\ninfo snapshots\nloadvm snap0\n" | run_qemu "$@" | _filter_date 73} 74 75 76echo 77echo "=== No block devices at all ===" 78echo 79 80run_test 81 82echo 83echo "=== -drive if=none ===" 84echo 85 86run_test -drive driver=file,file="$TEST_IMG",if=none 87run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=none 88run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=none -device virtio-blk,drive=none0 89 90echo 91echo "=== -drive if=virtio ===" 92echo 93 94run_test -drive driver=file,file="$TEST_IMG",if=virtio 95run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=virtio 96 97echo 98echo "=== Simple -blockdev ===" 99echo 100 101run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file 102run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 103 -blockdev driver=$IMGFMT,file=file,node-name=fmt 104run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 105 -blockdev driver=raw,file=file,node-name=raw \ 106 -blockdev driver=$IMGFMT,file=raw,node-name=fmt 107 108echo 109echo "=== -blockdev with a filter on top ===" 110echo 111 112run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 113 -blockdev driver=$IMGFMT,file=file,node-name=fmt \ 114 -blockdev driver=copy-on-read,file=fmt,node-name=filter 115 116echo 117echo "=== -blockdev with a backing file ===" 118echo 119 120TEST_IMG="$TEST_IMG.base" _make_test_img $size 121 122IMGOPTS="backing_file=$TEST_IMG.base" \ 123run_test -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \ 124 -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 125 -blockdev driver=$IMGFMT,file=file,backing=backing-file,node-name=fmt 126 127IMGOPTS="backing_file=$TEST_IMG.base" \ 128run_test -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \ 129 -blockdev driver=$IMGFMT,file=backing-file,node-name=backing-fmt \ 130 -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 131 -blockdev driver=$IMGFMT,file=file,backing=backing-fmt,node-name=fmt 132 133# A snapshot should be present on the overlay, but not the backing file 134echo Internal snapshots on overlay: 135$QEMU_IMG snapshot -l "$TEST_IMG" | _filter_date | _filter_vmstate_size 136 137echo Internal snapshots on backing file: 138$QEMU_IMG snapshot -l "$TEST_IMG.base" | _filter_date | _filter_vmstate_size 139 140echo 141echo "=== -blockdev with NBD server on the backing file ===" 142echo 143 144IMGOPTS="backing_file=$TEST_IMG.base" _make_test_img $size 145cat <<EOF | 146nbd_server_start unix:$TEST_DIR/nbd 147nbd_server_add -w backing-fmt 148savevm snap0 149info snapshots 150loadvm snap0 151EOF 152run_qemu -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \ 153 -blockdev driver=$IMGFMT,file=backing-file,node-name=backing-fmt \ 154 -blockdev driver=file,filename="$TEST_IMG",node-name=file \ 155 -blockdev driver=$IMGFMT,file=file,backing=backing-fmt,node-name=fmt | 156 _filter_date 157 158# This time, a snapshot should be created on both files 159echo Internal snapshots on overlay: 160$QEMU_IMG snapshot -l "$TEST_IMG" | _filter_date | _filter_vmstate_size 161 162echo Internal snapshots on backing file: 163$QEMU_IMG snapshot -l "$TEST_IMG.base" | _filter_date | _filter_vmstate_size 164 165# success, all done 166echo "*** done" 167rm -f $seq.full 168status=0 169