blob: d68bc3cb6f1a2033eb8ca7283e54aff679283715 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Eric Blakea1532a22018-07-02 14:14:58 -05002#
3# Test reading dirty bitmap over NBD
4#
Eric Blaked8154b02020-05-13 12:58:34 -05005# Copyright (C) 2018-2020 Red Hat, Inc.
Eric Blakea1532a22018-07-02 14:14:58 -05006#
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
Eric Blakea1532a22018-07-02 14:14:58 -050024status=1 # failure is the default!
25
26_cleanup()
27{
Eric Blake636192c2019-01-11 13:47:20 -060028 nbd_server_stop
Eric Blakea1532a22018-07-02 14:14:58 -050029 _cleanup_test_img
30 _cleanup_qemu
Max Reitz135a4662019-10-17 15:31:52 +020031 rm -f "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -050032}
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
Eric Blake636192c2019-01-11 13:47:20 -060039. ./common.nbd
Eric Blakea1532a22018-07-02 14:14:58 -050040
41_supported_fmt qcow2
42_supported_proto file # uses NBD as well
43_supported_os Linux
Max Reitz092b9c42018-07-13 21:15:06 +020044# Persistent dirty bitmaps require compat=1.1
45_unsupported_imgopts 'compat=0.10'
Eric Blakea1532a22018-07-02 14:14:58 -050046
Eric Blake8cedcff2018-11-16 15:50:02 -060047do_run_qemu()
Eric Blakea1532a22018-07-02 14:14:58 -050048{
49 echo Testing: "$@"
50 $QEMU -nographic -qmp stdio -serial none "$@"
51 echo
52}
53
Eric Blake8cedcff2018-11-16 15:50:02 -060054run_qemu()
Eric Blakea1532a22018-07-02 14:14:58 -050055{
56 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
57 | _filter_qemu | _filter_imgfmt \
58 | _filter_actual_image_size
59}
60
61echo
Eric Blakea237dea2018-11-19 11:29:24 -060062echo "=== Create partially sparse image, then add dirty bitmaps ==="
Eric Blakea1532a22018-07-02 14:14:58 -050063echo
64
Eric Blakea237dea2018-11-19 11:29:24 -060065# Two bitmaps, to contrast granularity issues
Eric Blake702aa502019-01-11 13:47:15 -060066# Also note that b will be disabled, while b2 is left enabled, to
67# check for read-only interactions
Eric Blakea237dea2018-11-19 11:29:24 -060068_make_test_img -o cluster_size=4k 4M
Eric Blakea1532a22018-07-02 14:14:58 -050069$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",
Eric Blakea237dea2018-11-19 11:29:24 -060086 "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
Eric Blakea1532a22018-07-02 14:14:58 -050096 }
97}
98{ "execute": "quit" }
99EOF
100
101echo
102echo "=== Write part of the file under active bitmap ==="
103echo
104
Eric Blakea237dea2018-11-19 11:29:24 -0600105$QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \
106 | _filter_qemu_io
Eric Blakea1532a22018-07-02 14:14:58 -0500107
108echo
Eric Blakea237dea2018-11-19 11:29:24 -0600109echo "=== End dirty bitmaps, and start serving image over NBD ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500110echo
111
Eric Blake506902c2019-09-20 17:07:29 -0500112_launch_qemu -object iothread,id=io0 2> >(_filter_nbd)
Eric Blakea1532a22018-07-02 14:14:58 -0500113
Eric Blake2d2fd672019-01-11 13:47:13 -0600114# Intentionally provoke some errors as well, to check error handling
Eric Blakea1532a22018-07-02 14:14:58 -0500115silent=
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"
John Snow0e2b7f02018-12-21 04:35:22 -0500120_send_qemu_cmd $QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable",
Eric Blakea1532a22018-07-02 14:14:58 -0500121 "arguments":{"node":"n", "name":"b"}}' "return"
Eric Blake296416f2019-11-14 15:34:15 -0600122
123for attempt in normal iothread; do
124
125echo
126echo "=== Set up NBD with $attempt access ==="
127echo
128if [ $attempt = iothread ]; then
129_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-blockdev-set-iothread",
130 "arguments":{"node-name":"n", "iothread":"io0"}}' "return"
131fi
132
Eric Blake2d2fd672019-01-11 13:47:13 -0600133_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
134 "arguments":{"device":"n"}}' "error" # Attempt add without server
Eric Blakea1532a22018-07-02 14:14:58 -0500135_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
136 "arguments":{"addr":{"type":"unix",
Max Reitz135a4662019-10-17 15:31:52 +0200137 "data":{"path":"'"$SOCK_DIR/nbd"'"}}}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600138_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
139 "arguments":{"addr":{"type":"unix",
Max Reitz135a4662019-10-17 15:31:52 +0200140 "data":{"path":"'"$SOCK_DIR/nbd"1'"}}}}' "error" # Attempt second server
141$QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -0500142_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600143 "arguments":{"device":"n", "bitmap":"b"}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600144_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
145 "arguments":{"device":"nosuch"}}' "error" # Attempt to export missing node
146_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
147 "arguments":{"device":"n"}}' "error" # Attempt to export same name twice
Eric Blakea237dea2018-11-19 11:29:24 -0600148_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600149 "arguments":{"device":"n", "name":"n2",
150 "bitmap":"b2"}}' "error" # enabled vs. read-only
Eric Blake702aa502019-01-11 13:47:15 -0600151_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600152 "arguments":{"device":"n", "name":"n2",
153 "bitmap":"b3"}}' "error" # Missing bitmap
154_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
155 "arguments":{"device":"n", "name":"n2", "writable":true,
Eric Blakedeb6ccb2019-11-13 20:46:35 -0600156 "description":"some text", "bitmap":"b2"}}' "return"
Max Reitz135a4662019-10-17 15:31:52 +0200157$QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -0500158
159echo
Eric Blakea237dea2018-11-19 11:29:24 -0600160echo "=== Contrast normal status to large granularity dirty-bitmap ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500161echo
162
163QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
Max Reitz135a4662019-10-17 15:31:52 +0200164IMG="driver=nbd,export=n,server.type=unix,server.path=$SOCK_DIR/nbd"
Eric Blakea237dea2018-11-19 11:29:24 -0600165$QEMU_IO -r -c 'r -P 0x22 512 512' -c 'r -P 0 512k 512k' -c 'r -P 0x11 1m 1m' \
166 -c 'r -P 0x33 2m 2m' --image-opts "$IMG" | _filter_qemu_io
Eric Blakea1532a22018-07-02 14:14:58 -0500167$QEMU_IMG map --output=json --image-opts \
168 "$IMG" | _filter_qemu_img_map
169$QEMU_IMG map --output=json --image-opts \
170 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
171
172echo
Eric Blakea237dea2018-11-19 11:29:24 -0600173echo "=== Contrast to small granularity dirty-bitmap ==="
174echo
175
Max Reitz135a4662019-10-17 15:31:52 +0200176IMG="driver=nbd,export=n2,server.type=unix,server.path=$SOCK_DIR/nbd"
Eric Blakea237dea2018-11-19 11:29:24 -0600177$QEMU_IMG map --output=json --image-opts \
178 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
179
180echo
Eric Blake636192c2019-01-11 13:47:20 -0600181echo "=== End qemu NBD server ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500182echo
183
184_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
185 "arguments":{"name":"n"}}' "return"
Eric Blakea237dea2018-11-19 11:29:24 -0600186_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
187 "arguments":{"name":"n2"}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600188_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
189 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean
Eric Blakea1532a22018-07-02 14:14:58 -0500190_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
Eric Blake7801c3a2019-01-11 13:47:14 -0600191_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
Eric Blake296416f2019-11-14 15:34:15 -0600192
193done
194
Eric Blakea1532a22018-07-02 14:14:58 -0500195_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
Eric Blake054be362019-03-05 12:29:08 -0600196wait=yes _cleanup_qemu
Eric Blakea1532a22018-07-02 14:14:58 -0500197
Eric Blake636192c2019-01-11 13:47:20 -0600198echo
199echo "=== Use qemu-nbd as server ==="
200echo
201
202nbd_server_start_unix_socket -r -f $IMGFMT -B b "$TEST_IMG"
203IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
204$QEMU_IMG map --output=json --image-opts \
205 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
206
207nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG"
208IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
Eric Blaked8154b02020-05-13 12:58:34 -0500209$QEMU_IMG map --output=json --image-opts --max-length=12345 \
210 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
211$QEMU_IMG map --output=json --image-opts --start-offset=12345 \
Eric Blake636192c2019-01-11 13:47:20 -0600212 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
213
Eric Blakea1532a22018-07-02 14:14:58 -0500214# success, all done
215echo '*** done'
216rm -f $seq.full
217status=0