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