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