xref: /openbmc/qemu/tests/qemu-iotests/267 (revision 8de702cb)
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 "$SOCK_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_require_drivers copy-on-read
44
45# Internal snapshots are (currently) impossible with refcount_bits=1,
46# and generally impossible with external data files
47_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file
48
49do_run_qemu()
50{
51    echo Testing: "$@"
52    (
53        if ! test -t 0; then
54            while read cmd; do
55                echo $cmd
56            done
57        fi
58        echo quit
59    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
60    echo
61}
62
63run_qemu()
64{
65    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
66        _filter_generated_node_ids | _filter_imgfmt | _filter_vmstate_size
67}
68
69size=128M
70
71run_test()
72{
73    if [ -n "$BACKING_FILE" ]; then
74        _make_test_img -b "$BACKING_FILE" $size
75    else
76        _make_test_img $size
77    fi
78    printf "savevm snap0\ninfo snapshots\nloadvm snap0\n" | run_qemu "$@" | _filter_date
79}
80
81
82echo
83echo "=== No block devices at all ==="
84echo
85
86run_test
87
88echo
89echo "=== -drive if=none ==="
90echo
91
92run_test -drive driver=file,file="$TEST_IMG",if=none
93run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=none
94run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=none -device virtio-blk,drive=none0
95
96echo
97echo "=== -drive if=virtio ==="
98echo
99
100run_test -drive driver=file,file="$TEST_IMG",if=virtio
101run_test -drive driver=$IMGFMT,file="$TEST_IMG",if=virtio
102
103echo
104echo "=== Simple -blockdev ==="
105echo
106
107run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file
108run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \
109         -blockdev driver=$IMGFMT,file=file,node-name=fmt
110run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \
111         -blockdev driver=raw,file=file,node-name=raw \
112         -blockdev driver=$IMGFMT,file=raw,node-name=fmt
113
114echo
115echo "=== -blockdev with a filter on top ==="
116echo
117
118run_test -blockdev driver=file,filename="$TEST_IMG",node-name=file \
119         -blockdev driver=$IMGFMT,file=file,node-name=fmt \
120         -blockdev driver=copy-on-read,file=fmt,node-name=filter
121
122echo
123echo "=== -blockdev with a backing file ==="
124echo
125
126TEST_IMG="$TEST_IMG.base" _make_test_img $size
127
128BACKING_FILE="$TEST_IMG.base" \
129run_test -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \
130         -blockdev driver=file,filename="$TEST_IMG",node-name=file \
131         -blockdev driver=$IMGFMT,file=file,backing=backing-file,node-name=fmt
132
133BACKING_FILE="$TEST_IMG.base" \
134run_test -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \
135         -blockdev driver=$IMGFMT,file=backing-file,node-name=backing-fmt \
136         -blockdev driver=file,filename="$TEST_IMG",node-name=file \
137         -blockdev driver=$IMGFMT,file=file,backing=backing-fmt,node-name=fmt
138
139# A snapshot should be present on the overlay, but not the backing file
140echo Internal snapshots on overlay:
141$QEMU_IMG snapshot -l "$TEST_IMG" | _filter_date | _filter_vmstate_size
142
143echo Internal snapshots on backing file:
144$QEMU_IMG snapshot -l "$TEST_IMG.base" | _filter_date | _filter_vmstate_size
145
146echo
147echo "=== -blockdev with NBD server on the backing file ==="
148echo
149
150_make_test_img -b "$TEST_IMG.base" $size
151cat <<EOF |
152nbd_server_start unix:$SOCK_DIR/nbd
153nbd_server_add -w backing-fmt
154savevm snap0
155info snapshots
156loadvm snap0
157EOF
158run_qemu -blockdev driver=file,filename="$TEST_IMG.base",node-name=backing-file \
159         -blockdev driver=$IMGFMT,file=backing-file,node-name=backing-fmt \
160         -blockdev driver=file,filename="$TEST_IMG",node-name=file \
161         -blockdev driver=$IMGFMT,file=file,backing=backing-fmt,node-name=fmt |
162         _filter_date
163
164# This time, a snapshot should be created on both files
165echo Internal snapshots on overlay:
166$QEMU_IMG snapshot -l "$TEST_IMG" | _filter_date | _filter_vmstate_size
167
168echo Internal snapshots on backing file:
169$QEMU_IMG snapshot -l "$TEST_IMG.base" | _filter_date | _filter_vmstate_size
170
171# success, all done
172echo "*** done"
173rm -f $seq.full
174status=0
175