4 # Test reading dirty bitmap over NBD
6 # Copyright (C) 2018-2020 Red Hat, Inc.
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.
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.
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/>.
23 echo "QA output created by $seq"
25 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
43 _supported_proto
file # uses NBD as well
45 # Persistent dirty bitmaps require compat=1.1
46 _unsupported_imgopts
'compat=0.10'
51 $QEMU -nographic -qmp stdio
-serial none
"$@"
57 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qmp \
58 | _filter_qemu | _filter_imgfmt \
59 | _filter_actual_image_size
63 echo "=== Create partially sparse image, then add dirty bitmaps ==="
66 # Two bitmaps, to contrast granularity issues
67 # Also note that b will be disabled, while b2 is left enabled, to
68 # check for read-only interactions
69 _make_test_img
-o cluster_size
=4k
4M
70 $QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
72 { "execute": "qmp_capabilities" }
73 { "execute": "blockdev-add",
79 "filename": "$TEST_IMG"
83 { "execute": "block-dirty-bitmap-add",
91 { "execute": "block-dirty-bitmap-add",
103 echo "=== Write part of the file under active bitmap ==="
106 $QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \
110 echo "=== End dirty bitmaps, and start serving image over NBD ==="
113 _launch_qemu
-object iothread
,id
=io0
2> >(_filter_nbd
)
115 # Intentionally provoke some errors as well, to check error handling
117 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
118 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"blockdev-add",
119 "arguments":{"driver":"qcow2", "node-name":"n",
120 "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
121 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable",
122 "arguments":{"node":"n", "name":"b"}}' "return"
124 for attempt
in normal iothread
; do
127 echo "=== Set up NBD with $attempt access ==="
129 if [ $attempt = iothread
]; then
130 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"x-blockdev-set-iothread",
131 "arguments":{"node-name":"n", "iothread":"io0"}}' "return"
134 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
135 "arguments":{"device":"n"}}' "error" # Attempt add without server
136 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-start",
137 "arguments":{"addr":{"type":"unix",
138 "data":{"path":"'"$SOCK_DIR/nbd"'"}}}}' "return"
139 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-start",
140 "arguments":{"addr":{"type":"unix",
141 "data":{"path":"'"$SOCK_DIR/nbd"1'"}}}}' "error" # Attempt second server
142 $QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
143 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
144 "arguments":{"device":"n", "bitmap":"b"}}' "return"
145 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
146 "arguments":{"device":"nosuch"}}' "error" # Attempt to export missing node
147 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
148 "arguments":{"device":"n"}}' "error" # Attempt to export same name twice
149 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
150 "arguments":{"device":"n", "name":"n2",
151 "bitmap":"b2"}}' "error" # enabled vs. read-only
152 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
153 "arguments":{"device":"n", "name":"n2",
154 "bitmap":"b3"}}' "error" # Missing bitmap
155 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
156 "arguments":{"device":"n", "name":"n2", "writable":true,
157 "description":"some text", "bitmap":"b2"}}' "return"
158 $QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
161 echo "=== Contrast normal status to large granularity dirty-bitmap ==="
164 QEMU_IO_OPTIONS
=$QEMU_IO_OPTIONS_NO_FMT
165 IMG
="driver=nbd,export=n,server.type=unix,server.path=$SOCK_DIR/nbd"
166 $QEMU_IO -r -c 'r -P 0x22 512 512' -c 'r -P 0 512k 512k' -c 'r -P 0x11 1m 1m' \
167 -c 'r -P 0x33 2m 2m' --image-opts "$IMG" | _filter_qemu_io
168 $QEMU_IMG map
--output=json
--image-opts \
169 "$IMG" | _filter_qemu_img_map
170 $QEMU_IMG map
--output=json
--image-opts \
171 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
174 echo "=== Contrast to small granularity dirty-bitmap ==="
177 IMG
="driver=nbd,export=n2,server.type=unix,server.path=$SOCK_DIR/nbd"
178 $QEMU_IMG map
--output=json
--image-opts \
179 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
182 echo "=== End qemu NBD server ==="
185 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
186 "arguments":{"name":"n"}}' "return"
187 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
188 "arguments":{"name":"n2"}}' "return"
189 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
190 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean
191 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
192 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
196 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"quit"}' "return"
197 wait=yes _cleanup_qemu
200 echo "=== Use qemu-nbd as server ==="
203 nbd_server_start_unix_socket
-r -f $IMGFMT -B b
"$TEST_IMG"
204 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
205 $QEMU_IMG map
--output=json
--image-opts \
206 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
208 nbd_server_start_unix_socket
-f $IMGFMT -B b2
"$TEST_IMG"
209 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
210 $QEMU_IMG map
--output=json
--image-opts --max-length=12345 \
211 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
212 $QEMU_IMG map
--output=json
--image-opts --start-offset=12345 \
213 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map