]> Git Repo - qemu.git/blame - tests/qemu-iotests/223
tests/bios-tables: Improve portability by searching bash in the $PATH
[qemu.git] / tests / qemu-iotests / 223
CommitLineData
a1532a22
EB
1#!/bin/bash
2#
3# Test reading dirty bitmap over NBD
4#
5# Copyright (C) 2018 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
21seq="$(basename $0)"
22echo "QA output created by $seq"
23
a1532a22
EB
24status=1 # failure is the default!
25
26_cleanup()
27{
636192c4 28 nbd_server_stop
a1532a22
EB
29 _cleanup_test_img
30 _cleanup_qemu
31 rm -f "$TEST_DIR/nbd"
32}
33trap "_cleanup; exit \$status" 0 1 2 3 15
34
35# get standard environment, filters and checks
36. ./common.rc
37. ./common.filter
38. ./common.qemu
636192c4 39. ./common.nbd
a1532a22
EB
40
41_supported_fmt qcow2
42_supported_proto file # uses NBD as well
43_supported_os Linux
092b9c40
HR
44# Persistent dirty bitmaps require compat=1.1
45_unsupported_imgopts 'compat=0.10'
a1532a22 46
8cedcffd 47do_run_qemu()
a1532a22
EB
48{
49 echo Testing: "$@"
50 $QEMU -nographic -qmp stdio -serial none "$@"
51 echo
52}
53
8cedcffd 54run_qemu()
a1532a22
EB
55{
56 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
57 | _filter_qemu | _filter_imgfmt \
58 | _filter_actual_image_size
59}
60
61echo
a237dea3 62echo "=== Create partially sparse image, then add dirty bitmaps ==="
a1532a22
EB
63echo
64
a237dea3 65# Two bitmaps, to contrast granularity issues
702aa50d
EB
66# Also note that b will be disabled, while b2 is left enabled, to
67# check for read-only interactions
a237dea3 68_make_test_img -o cluster_size=4k 4M
a1532a22
EB
69$QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
70run_qemu <<EOF
71{ "execute": "qmp_capabilities" }
72{ "execute": "blockdev-add",
73 "arguments": {
74 "driver": "$IMGFMT",
75 "node-name": "n",
76 "file": {
77 "driver": "file",
78 "filename": "$TEST_IMG"
79 }
80 }
81}
82{ "execute": "block-dirty-bitmap-add",
83 "arguments": {
84 "node": "n",
85 "name": "b",
a237dea3
EB
86 "persistent": true,
87 "granularity": 65536
88 }
89}
90{ "execute": "block-dirty-bitmap-add",
91 "arguments": {
92 "node": "n",
93 "name": "b2",
94 "persistent": true,
95 "granularity": 512
a1532a22
EB
96 }
97}
98{ "execute": "quit" }
99EOF
100
101echo
102echo "=== Write part of the file under active bitmap ==="
103echo
104
a237dea3
EB
105$QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \
106 | _filter_qemu_io
a1532a22
EB
107
108echo
a237dea3 109echo "=== End dirty bitmaps, and start serving image over NBD ==="
a1532a22
EB
110echo
111
112_launch_qemu 2> >(_filter_nbd)
113
2d2fd674 114# Intentionally provoke some errors as well, to check error handling
a1532a22
EB
115silent=
116_send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
117_send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add",
118 "arguments":{"driver":"qcow2", "node-name":"n",
119 "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
0e2b7f09 120_send_qemu_cmd $QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable",
a1532a22 121 "arguments":{"node":"n", "name":"b"}}' "return"
2d2fd674
EB
122_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
123 "arguments":{"device":"n"}}' "error" # Attempt add without server
a1532a22
EB
124_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
125 "arguments":{"addr":{"type":"unix",
126 "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
2d2fd674
EB
127_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
128 "arguments":{"addr":{"type":"unix",
129 "data":{"path":"'"$TEST_DIR/nbd"1'"}}}}' "error" # Attempt second server
ddd09448 130$QEMU_NBD_PROG -L -k "$TEST_DIR/nbd"
a1532a22 131_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
5fcbeb06 132 "arguments":{"device":"n", "bitmap":"b"}}' "return"
2d2fd674
EB
133_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
134 "arguments":{"device":"nosuch"}}' "error" # Attempt to export missing node
135_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
136 "arguments":{"device":"n"}}' "error" # Attempt to export same name twice
a237dea3 137_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
5fcbeb06
EB
138 "arguments":{"device":"n", "name":"n2",
139 "bitmap":"b2"}}' "error" # enabled vs. read-only
702aa50d 140_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
5fcbeb06
EB
141 "arguments":{"device":"n", "name":"n2",
142 "bitmap":"b3"}}' "error" # Missing bitmap
143_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
144 "arguments":{"device":"n", "name":"n2", "writable":true,
145 "bitmap":"b2"}}' "return"
ddd09448 146$QEMU_NBD_PROG -L -k "$TEST_DIR/nbd"
a1532a22
EB
147
148echo
a237dea3 149echo "=== Contrast normal status to large granularity dirty-bitmap ==="
a1532a22
EB
150echo
151
152QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
153IMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
a237dea3
EB
154$QEMU_IO -r -c 'r -P 0x22 512 512' -c 'r -P 0 512k 512k' -c 'r -P 0x11 1m 1m' \
155 -c 'r -P 0x33 2m 2m' --image-opts "$IMG" | _filter_qemu_io
a1532a22
EB
156$QEMU_IMG map --output=json --image-opts \
157 "$IMG" | _filter_qemu_img_map
158$QEMU_IMG map --output=json --image-opts \
159 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
160
a237dea3
EB
161echo
162echo "=== Contrast to small granularity dirty-bitmap ==="
163echo
164
165IMG="driver=nbd,export=n2,server.type=unix,server.path=$TEST_DIR/nbd"
166$QEMU_IMG map --output=json --image-opts \
167 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
168
a1532a22 169echo
636192c4 170echo "=== End qemu NBD server ==="
a1532a22
EB
171echo
172
173_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
174 "arguments":{"name":"n"}}' "return"
a237dea3
EB
175_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
176 "arguments":{"name":"n2"}}' "return"
2d2fd674
EB
177_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
178 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean
a1532a22 179_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
7801c3a7 180_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
a1532a22
EB
181_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
182
636192c4
EB
183echo
184echo "=== Use qemu-nbd as server ==="
185echo
186
187nbd_server_start_unix_socket -r -f $IMGFMT -B b "$TEST_IMG"
188IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
189$QEMU_IMG map --output=json --image-opts \
190 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
191
192nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG"
193IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
194$QEMU_IMG map --output=json --image-opts \
195 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
196
a1532a22
EB
197# success, all done
198echo '*** done'
199rm -f $seq.full
200status=0
This page took 0.101276 seconds and 4 git commands to generate.