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