blob: da87f2f4a233d73e8368d8f8c7c8e7911361c030 [file] [log] [blame]
Philippe Mathieu-Daudé11a82d12019-03-07 15:58:38 +01001#!/usr/bin/env bash
Vladimir Sementsov-Ogievskiy9dd003a2021-01-16 16:44:19 +03002# group: rw quick
Eric Blakea1532a22018-07-02 14:14:58 -05003#
4# Test reading dirty bitmap over NBD
5#
Eric Blaked8154b02020-05-13 12:58:34 -05006# Copyright (C) 2018-2020 Red Hat, Inc.
Eric Blakea1532a22018-07-02 14:14:58 -05007#
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.
12#
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.
17#
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/>.
20#
21
22seq="$(basename $0)"
23echo "QA output created by $seq"
24
Eric Blakea1532a22018-07-02 14:14:58 -050025status=1 # failure is the default!
26
27_cleanup()
28{
Eric Blake636192c2019-01-11 13:47:20 -060029 nbd_server_stop
Eric Blakea1532a22018-07-02 14:14:58 -050030 _cleanup_test_img
31 _cleanup_qemu
Max Reitz135a4662019-10-17 15:31:52 +020032 rm -f "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -050033}
34trap "_cleanup; exit \$status" 0 1 2 3 15
35
36# get standard environment, filters and checks
37. ./common.rc
38. ./common.filter
39. ./common.qemu
Eric Blake636192c2019-01-11 13:47:20 -060040. ./common.nbd
Eric Blakea1532a22018-07-02 14:14:58 -050041
42_supported_fmt qcow2
43_supported_proto file # uses NBD as well
44_supported_os Linux
Max Reitz092b9c42018-07-13 21:15:06 +020045# Persistent dirty bitmaps require compat=1.1
46_unsupported_imgopts 'compat=0.10'
Eric Blakea1532a22018-07-02 14:14:58 -050047
Eric Blake8cedcff2018-11-16 15:50:02 -060048do_run_qemu()
Eric Blakea1532a22018-07-02 14:14:58 -050049{
50 echo Testing: "$@"
51 $QEMU -nographic -qmp stdio -serial none "$@"
52 echo
53}
54
Eric Blake8cedcff2018-11-16 15:50:02 -060055run_qemu()
Eric Blakea1532a22018-07-02 14:14:58 -050056{
57 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
58 | _filter_qemu | _filter_imgfmt \
59 | _filter_actual_image_size
60}
61
62echo
Eric Blakea237dea2018-11-19 11:29:24 -060063echo "=== Create partially sparse image, then add dirty bitmaps ==="
Eric Blakea1532a22018-07-02 14:14:58 -050064echo
65
Eric Blakea237dea2018-11-19 11:29:24 -060066# Two bitmaps, to contrast granularity issues
Eric Blake702aa502019-01-11 13:47:15 -060067# Also note that b will be disabled, while b2 is left enabled, to
68# check for read-only interactions
Eric Blakea237dea2018-11-19 11:29:24 -060069_make_test_img -o cluster_size=4k 4M
Eric Blakea1532a22018-07-02 14:14:58 -050070$QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
71run_qemu <<EOF
72{ "execute": "qmp_capabilities" }
73{ "execute": "blockdev-add",
74 "arguments": {
75 "driver": "$IMGFMT",
76 "node-name": "n",
77 "file": {
78 "driver": "file",
79 "filename": "$TEST_IMG"
80 }
81 }
82}
83{ "execute": "block-dirty-bitmap-add",
84 "arguments": {
85 "node": "n",
86 "name": "b",
Eric Blakea237dea2018-11-19 11:29:24 -060087 "persistent": true,
88 "granularity": 65536
89 }
90}
91{ "execute": "block-dirty-bitmap-add",
92 "arguments": {
93 "node": "n",
94 "name": "b2",
95 "persistent": true,
96 "granularity": 512
Eric Blakea1532a22018-07-02 14:14:58 -050097 }
98}
99{ "execute": "quit" }
100EOF
101
102echo
103echo "=== Write part of the file under active bitmap ==="
104echo
105
Eric Blakea237dea2018-11-19 11:29:24 -0600106$QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \
107 | _filter_qemu_io
Eric Blakea1532a22018-07-02 14:14:58 -0500108
109echo
Eric Blakea237dea2018-11-19 11:29:24 -0600110echo "=== End dirty bitmaps, and start serving image over NBD ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500111echo
112
Eric Blake506902c2019-09-20 17:07:29 -0500113_launch_qemu -object iothread,id=io0 2> >(_filter_nbd)
Eric Blakea1532a22018-07-02 14:14:58 -0500114
Eric Blake2d2fd672019-01-11 13:47:13 -0600115# Intentionally provoke some errors as well, to check error handling
Eric Blakea1532a22018-07-02 14:14:58 -0500116silent=
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"
John Snow0e2b7f02018-12-21 04:35:22 -0500121_send_qemu_cmd $QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable",
Eric Blakea1532a22018-07-02 14:14:58 -0500122 "arguments":{"node":"n", "name":"b"}}' "return"
Eric Blake296416f2019-11-14 15:34:15 -0600123
124for attempt in normal iothread; do
125
126echo
127echo "=== Set up NBD with $attempt access ==="
128echo
129if [ $attempt = iothread ]; then
130_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-blockdev-set-iothread",
131 "arguments":{"node-name":"n", "iothread":"io0"}}' "return"
132fi
133
Eric Blake2d2fd672019-01-11 13:47:13 -0600134_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
135 "arguments":{"device":"n"}}' "error" # Attempt add without server
Eric Blakea1532a22018-07-02 14:14:58 -0500136_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
137 "arguments":{"addr":{"type":"unix",
Max Reitz135a4662019-10-17 15:31:52 +0200138 "data":{"path":"'"$SOCK_DIR/nbd"'"}}}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600139_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
140 "arguments":{"addr":{"type":"unix",
Max Reitz135a4662019-10-17 15:31:52 +0200141 "data":{"path":"'"$SOCK_DIR/nbd"1'"}}}}' "error" # Attempt second server
142$QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -0500143_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600144 "arguments":{"device":"n", "bitmap":"b"}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600145_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
Eric Blakea237dea2018-11-19 11:29:24 -0600149_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600150 "arguments":{"device":"n", "name":"n2",
151 "bitmap":"b2"}}' "error" # enabled vs. read-only
Eric Blake702aa502019-01-11 13:47:15 -0600152_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
Eric Blake5fcbeb02019-01-11 13:47:17 -0600153 "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,
Eric Blakedeb6ccb2019-11-13 20:46:35 -0600157 "description":"some text", "bitmap":"b2"}}' "return"
Max Reitz135a4662019-10-17 15:31:52 +0200158$QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd"
Eric Blakea1532a22018-07-02 14:14:58 -0500159
160echo
Eric Blakea237dea2018-11-19 11:29:24 -0600161echo "=== Contrast normal status to large granularity dirty-bitmap ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500162echo
163
164QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
Max Reitz135a4662019-10-17 15:31:52 +0200165IMG="driver=nbd,export=n,server.type=unix,server.path=$SOCK_DIR/nbd"
Eric Blakea237dea2018-11-19 11:29:24 -0600166$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
Eric Blakea1532a22018-07-02 14:14:58 -0500168$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
172
173echo
Eric Blakea237dea2018-11-19 11:29:24 -0600174echo "=== Contrast to small granularity dirty-bitmap ==="
175echo
176
Max Reitz135a4662019-10-17 15:31:52 +0200177IMG="driver=nbd,export=n2,server.type=unix,server.path=$SOCK_DIR/nbd"
Eric Blakea237dea2018-11-19 11:29:24 -0600178$QEMU_IMG map --output=json --image-opts \
179 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
180
181echo
Eric Blake636192c2019-01-11 13:47:20 -0600182echo "=== End qemu NBD server ==="
Eric Blakea1532a22018-07-02 14:14:58 -0500183echo
184
185_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
186 "arguments":{"name":"n"}}' "return"
Eric Blakea237dea2018-11-19 11:29:24 -0600187_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
188 "arguments":{"name":"n2"}}' "return"
Eric Blake2d2fd672019-01-11 13:47:13 -0600189_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
190 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean
Eric Blakea1532a22018-07-02 14:14:58 -0500191_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
Eric Blake7801c3a2019-01-11 13:47:14 -0600192_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
Eric Blake296416f2019-11-14 15:34:15 -0600193
194done
195
Eric Blakea1532a22018-07-02 14:14:58 -0500196_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
Eric Blake054be362019-03-05 12:29:08 -0600197wait=yes _cleanup_qemu
Eric Blakea1532a22018-07-02 14:14:58 -0500198
Eric Blake636192c2019-01-11 13:47:20 -0600199echo
200echo "=== Use qemu-nbd as server ==="
201echo
202
203nbd_server_start_unix_socket -r -f $IMGFMT -B b "$TEST_IMG"
204IMG="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
207
208nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG"
209IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
Eric Blaked8154b02020-05-13 12:58:34 -0500210$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 \
Eric Blake636192c2019-01-11 13:47:20 -0600213 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
214
Eric Blakea1532a22018-07-02 14:14:58 -0500215# success, all done
216echo '*** done'
217rm -f $seq.full
218status=0