223 (7585B)
1 #!/usr/bin/env bash 2 # group: rw quick 3 # 4 # Test reading dirty bitmap over NBD 5 # 6 # Copyright (C) 2018-2020 Red Hat, Inc. 7 # 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 22 seq="$(basename $0)" 23 echo "QA output created by $seq" 24 25 status=1 # failure is the default! 26 27 _cleanup() 28 { 29 nbd_server_stop 30 _cleanup_test_img 31 _cleanup_qemu 32 rm -f "$SOCK_DIR/nbd" 33 } 34 trap "_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 40 . ./common.nbd 41 42 _supported_fmt qcow2 43 _supported_proto file # uses NBD as well 44 _supported_os Linux 45 # Persistent dirty bitmaps require compat=1.1 46 _unsupported_imgopts 'compat=0.10' 47 48 do_run_qemu() 49 { 50 echo Testing: "$@" 51 $QEMU -nographic -qmp stdio -serial none "$@" 52 echo 53 } 54 55 run_qemu() 56 { 57 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 58 | _filter_qemu | _filter_imgfmt \ 59 | _filter_actual_image_size 60 } 61 62 echo 63 echo "=== Create partially sparse image, then add dirty bitmaps ===" 64 echo 65 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 71 run_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", 87 "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 97 } 98 } 99 { "execute": "quit" } 100 EOF 101 102 echo 103 echo "=== Write part of the file under active bitmap ===" 104 echo 105 106 $QEMU_IO -c 'w -P 0x22 512 512' -c 'w -P 0x33 2M 2M' "$TEST_IMG" \ 107 | _filter_qemu_io 108 109 echo 110 echo "=== End dirty bitmaps, and start serving image over NBD ===" 111 echo 112 113 _launch_qemu -object iothread,id=io0 2> >(_filter_nbd) 114 115 # Intentionally provoke some errors as well, to check error handling 116 silent= 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" 123 _send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add", 124 "arguments":{"driver":"null-co", "node-name":"null", 125 "size": 4194304}}' "return" 126 _send_qemu_cmd $QEMU_HANDLE '{"execute":"block-dirty-bitmap-add", 127 "arguments":{"node":"null", "name":"b3"}}' "return" 128 129 for attempt in normal iothread; do 130 131 echo 132 echo "=== Set up NBD with $attempt access ===" 133 echo 134 if [ $attempt = iothread ]; then 135 _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-blockdev-set-iothread", 136 "arguments":{"node-name":"n", "iothread":"io0"}}' "return" 137 fi 138 139 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 140 "arguments":{"device":"n"}}' "error" # Attempt add without server 141 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start", 142 "arguments":{"addr":{"type":"unix", 143 "data":{"path":"'"$SOCK_DIR/nbd"'"}}}}' "return" 144 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start", 145 "arguments":{"addr":{"type":"unix", 146 "data":{"path":"'"$SOCK_DIR/nbd"1'"}}}}' "error" # Attempt second server 147 $QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd" 148 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 149 "arguments":{"device":"n", "bitmap":"b"}}' "return" 150 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 151 "arguments":{"device":"nosuch"}}' "error" # Attempt to export missing node 152 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 153 "arguments":{"device":"n"}}' "error" # Attempt to export same name twice 154 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 155 "arguments":{"device":"n", "name":"n2", 156 "bitmap":"b2"}}' "error" # enabled vs. read-only 157 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 158 "arguments":{"device":"n", "name":"n2", 159 "bitmap":"b3"}}' "error" # Missing bitmap 160 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 161 "arguments":{"device":"n", "name":"n2", "writable":true, 162 "description":"some text", "bitmap":"b2"}}' "return" 163 _send_qemu_cmd $QEMU_HANDLE '{"execute":"block-export-add", 164 "arguments":{"type": "nbd", "node-name":"n", "id":"n3", "name": "n3", 165 "bitmaps":[{"node":"null","name":"b3"}]}}' "return" 166 $QEMU_NBD_PROG -L -k "$SOCK_DIR/nbd" 167 168 echo 169 echo "=== Contrast normal status to large granularity dirty-bitmap ===" 170 echo 171 172 QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 173 IMG="driver=nbd,export=n,server.type=unix,server.path=$SOCK_DIR/nbd" 174 $QEMU_IO -r -c 'r -P 0x22 512 512' -c 'r -P 0 512k 512k' -c 'r -P 0x11 1m 1m' \ 175 -c 'r -P 0x33 2m 2m' --image-opts "$IMG" | _filter_qemu_io 176 $QEMU_IMG map --output=json --image-opts \ 177 "$IMG" | _filter_qemu_img_map 178 $QEMU_IMG map --output=json --image-opts \ 179 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map 180 181 echo 182 echo "=== Contrast to small granularity dirty-bitmap ===" 183 echo 184 185 IMG="driver=nbd,export=n2,server.type=unix,server.path=$SOCK_DIR/nbd" 186 $QEMU_IMG map --output=json --image-opts \ 187 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map 188 189 echo 190 echo "=== Check bitmap taken from another node ===" 191 echo 192 193 IMG="driver=nbd,export=n3,server.type=unix,server.path=$SOCK_DIR/nbd" 194 $QEMU_IMG map --output=json --image-opts \ 195 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map 196 197 echo 198 echo "=== End qemu NBD server ===" 199 echo 200 201 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", 202 "arguments":{"name":"n"}}' "return" 203 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", 204 "arguments":{"name":"n2"}}' "return" 205 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", 206 "arguments":{"name":"n2"}}' "error" # Attempt duplicate clean 207 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" 208 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again 209 210 done 211 212 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" 213 wait=yes _cleanup_qemu 214 215 echo 216 echo "=== Use qemu-nbd as server ===" 217 echo 218 219 nbd_server_start_unix_socket -r -f $IMGFMT -B b "$TEST_IMG" 220 IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" 221 $QEMU_IMG map --output=json --image-opts \ 222 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map 223 224 nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG" 225 IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" 226 $QEMU_IMG map --output=json --image-opts --max-length=12345 \ 227 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map 228 $QEMU_IMG map --output=json --image-opts --start-offset=12345 \ 229 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map 230 231 # success, all done 232 echo '*** done' 233 rm -f $seq.full 234 status=0