3 # Test reading dirty bitmap over NBD
5 # Copyright (C) 2018-2019 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/>.
22 echo "QA output created by $seq"
24 status
=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
42 _supported_proto
file # uses NBD as well
44 # Persistent dirty bitmaps require compat=1.1
45 _unsupported_imgopts
'compat=0.10'
50 $QEMU -nographic -qmp stdio
-serial none
"$@"
56 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qmp \
57 | _filter_qemu | _filter_imgfmt \
58 | _filter_actual_image_size
62 echo "=== Create partially sparse image, then add dirty bitmaps ==="
65 # Two bitmaps, to contrast granularity issues
66 # Also note that b will be disabled, while b2 is left enabled, to
67 # check for read-only interactions
68 _make_test_img
-o cluster_size
=4k
4M
69 $QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
71 { "execute": "qmp_capabilities" }
72 { "execute": "blockdev-add",
78 "filename": "$TEST_IMG"
82 { "execute": "block-dirty-bitmap-add",
90 { "execute": "block-dirty-bitmap-add",
102 echo "=== Write part of the file under active bitmap ==="
105 $QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \
109 echo "=== End dirty bitmaps, and start serving image over NBD ==="
112 _launch_qemu
-object iothread
,id
=io0
2> >(_filter_nbd
)
114 # Intentionally provoke some errors as well, to check error handling
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"
120 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"x-blockdev-set-iothread",
121 "arguments":{"node-name":"n", "iothread":"io0"}}' "return"
122 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable",
123 "arguments":{"node":"n", "name":"b"}}' "return"
124 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
125 "arguments":{"device":"n"}}' "error" # Attempt add without server
126 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-start",
127 "arguments":{"addr":{"type":"unix",
128 "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
129 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-start",
130 "arguments":{"addr":{"type":"unix",
131 "data":{"path":"'"$TEST_DIR/nbd"1'"}}}}' "error" # Attempt second server
132 $QEMU_NBD_PROG -L -k "$TEST_DIR/nbd"
133 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
134 "arguments":{"device":"n", "bitmap":"b"}}' "return"
135 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
136 "arguments":{"device":"nosuch"}}' "error" # Attempt to export missing node
137 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
138 "arguments":{"device":"n"}}' "error" # Attempt to export same name twice
139 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
140 "arguments":{"device":"n", "name":"n2",
141 "bitmap":"b2"}}' "error" # enabled vs. read-only
142 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
143 "arguments":{"device":"n", "name":"n2",
144 "bitmap":"b3"}}' "error" # Missing bitmap
145 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-add",
146 "arguments":{"device":"n", "name":"n2", "writable":true,
147 "bitmap":"b2"}}' "return"
148 $QEMU_NBD_PROG -L -k "$TEST_DIR/nbd"
151 echo "=== Contrast normal status to large granularity dirty-bitmap ==="
154 QEMU_IO_OPTIONS
=$QEMU_IO_OPTIONS_NO_FMT
155 IMG
="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
156 $QEMU_IO -r -c 'r -P 0x22 512 512' -c 'r -P 0 512k 512k' -c 'r -P 0x11 1m 1m' \
157 -c 'r -P 0x33 2m 2m' --image-opts "$IMG" | _filter_qemu_io
158 $QEMU_IMG map
--output=json
--image-opts \
159 "$IMG" | _filter_qemu_img_map
160 $QEMU_IMG map
--output=json
--image-opts \
161 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
164 echo "=== Contrast to small granularity dirty-bitmap ==="
167 IMG
="driver=nbd,export=n2,server.type=unix,server.path=$TEST_DIR/nbd"
168 $QEMU_IMG map
--output=json
--image-opts \
169 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
172 echo "=== End qemu NBD server ==="
175 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
176 "arguments":{"name":"n"}}' "return"
177 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
178 "arguments":{"name":"n2"}}' "return"
179 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-remove",
180 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean
181 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
182 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
183 _send_qemu_cmd
$QEMU_HANDLE '{"execute":"quit"}' "return"
184 wait=yes _cleanup_qemu
187 echo "=== Use qemu-nbd as server ==="
190 nbd_server_start_unix_socket
-r -f $IMGFMT -B b
"$TEST_IMG"
191 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
192 $QEMU_IMG map
--output=json
--image-opts \
193 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
195 nbd_server_start_unix_socket
-f $IMGFMT -B b2
"$TEST_IMG"
196 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
197 $QEMU_IMG map
--output=json
--image-opts \
198 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map