]> Git Repo - qemu.git/blob - tests/qemu-iotests/223
Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging
[qemu.git] / tests / qemu-iotests / 223
1 #!/bin/bash
2 #
3 # Test reading dirty bitmap over NBD
4 #
5 # Copyright (C) 2018 Red Hat, Inc.
6 #
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
21 seq="$(basename $0)"
22 echo "QA output created by $seq"
23
24 here="$PWD"
25 status=1 # failure is the default!
26
27 _cleanup()
28 {
29     _cleanup_test_img
30     _cleanup_qemu
31     rm -f "$TEST_DIR/nbd"
32 }
33 trap "_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
39
40 _supported_fmt qcow2
41 _supported_proto file # uses NBD as well
42 _supported_os Linux
43
44 function do_run_qemu()
45 {
46     echo Testing: "$@"
47     $QEMU -nographic -qmp stdio -serial none "$@"
48     echo
49 }
50
51 function run_qemu()
52 {
53     do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
54                           | _filter_qemu | _filter_imgfmt \
55                           | _filter_actual_image_size
56 }
57
58 echo
59 echo "=== Create partially sparse image, then add dirty bitmap ==="
60 echo
61
62 _make_test_img 4M
63 $QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
64 run_qemu <<EOF
65 { "execute": "qmp_capabilities" }
66 { "execute": "blockdev-add",
67   "arguments": {
68     "driver": "$IMGFMT",
69     "node-name": "n",
70     "file": {
71       "driver": "file",
72       "filename": "$TEST_IMG"
73     }
74   }
75 }
76 { "execute": "block-dirty-bitmap-add",
77   "arguments": {
78     "node": "n",
79     "name": "b",
80     "persistent": true
81   }
82 }
83 { "execute": "quit" }
84 EOF
85
86 echo
87 echo "=== Write part of the file under active bitmap ==="
88 echo
89
90 $QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io
91
92 echo
93 echo "=== End dirty bitmap, and start serving image over NBD ==="
94 echo
95
96 _launch_qemu 2> >(_filter_nbd)
97
98 silent=
99 _send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
100 _send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add",
101   "arguments":{"driver":"qcow2", "node-name":"n",
102     "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
103 _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable",
104   "arguments":{"node":"n", "name":"b"}}' "return"
105 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
106   "arguments":{"addr":{"type":"unix",
107     "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
108 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
109   "arguments":{"device":"n"}}' "return"
110 _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap",
111   "arguments":{"name":"n", "bitmap":"b"}}' "return"
112
113 echo
114 echo "=== Contrast normal status with dirty-bitmap status ==="
115 echo
116
117 QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
118 IMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
119 $QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \
120   -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io
121 $QEMU_IMG map --output=json --image-opts \
122   "$IMG" | _filter_qemu_img_map
123 $QEMU_IMG map --output=json --image-opts \
124   "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
125
126 echo
127 echo "=== End NBD server ==="
128 echo
129
130 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
131   "arguments":{"name":"n"}}' "return"
132 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
133 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
134
135 # success, all done
136 echo '*** done'
137 rm -f $seq.full
138 status=0
This page took 0.028067 seconds and 4 git commands to generate.