memory, exec: Expose all memory block related flags.
[qemu/ar7.git] / tests / qemu-iotests / 223
blob8b1859c2dd3b569a8f672940141892c66d0ec2b5
1 #!/bin/bash
3 # Test reading dirty bitmap over NBD
5 # Copyright (C) 2018 Red Hat, Inc.
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.
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.
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/>.
21 seq="$(basename $0)"
22 echo "QA output created by $seq"
24 here="$PWD"
25 status=1 # failure is the default!
27 _cleanup()
29 _cleanup_test_img
30 _cleanup_qemu
31 rm -f "$TEST_DIR/nbd"
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.qemu
40 _supported_fmt qcow2
41 _supported_proto file # uses NBD as well
42 _supported_os Linux
43 # Persistent dirty bitmaps require compat=1.1
44 _unsupported_imgopts 'compat=0.10'
46 function do_run_qemu()
48 echo Testing: "$@"
49 $QEMU -nographic -qmp stdio -serial none "$@"
50 echo
53 function run_qemu()
55 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
56 | _filter_qemu | _filter_imgfmt \
57 | _filter_actual_image_size
60 echo
61 echo "=== Create partially sparse image, then add dirty bitmap ==="
62 echo
64 _make_test_img 4M
65 $QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
66 run_qemu <<EOF
67 { "execute": "qmp_capabilities" }
68 { "execute": "blockdev-add",
69 "arguments": {
70 "driver": "$IMGFMT",
71 "node-name": "n",
72 "file": {
73 "driver": "file",
74 "filename": "$TEST_IMG"
78 { "execute": "block-dirty-bitmap-add",
79 "arguments": {
80 "node": "n",
81 "name": "b",
82 "persistent": true
85 { "execute": "quit" }
86 EOF
88 echo
89 echo "=== Write part of the file under active bitmap ==="
90 echo
92 $QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io
94 echo
95 echo "=== End dirty bitmap, and start serving image over NBD ==="
96 echo
98 _launch_qemu 2> >(_filter_nbd)
100 silent=
101 _send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
102 _send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add",
103 "arguments":{"driver":"qcow2", "node-name":"n",
104 "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
105 _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable",
106 "arguments":{"node":"n", "name":"b"}}' "return"
107 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
108 "arguments":{"addr":{"type":"unix",
109 "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
110 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
111 "arguments":{"device":"n"}}' "return"
112 _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap",
113 "arguments":{"name":"n", "bitmap":"b"}}' "return"
115 echo
116 echo "=== Contrast normal status with dirty-bitmap status ==="
117 echo
119 QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
120 IMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
121 $QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \
122 -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io
123 $QEMU_IMG map --output=json --image-opts \
124 "$IMG" | _filter_qemu_img_map
125 $QEMU_IMG map --output=json --image-opts \
126 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
128 echo
129 echo "=== End NBD server ==="
130 echo
132 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
133 "arguments":{"name":"n"}}' "return"
134 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
135 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
137 # success, all done
138 echo '*** done'
139 rm -f $seq.full
140 status=0