]>
Commit | Line | Data |
---|---|---|
a1532a22 EB |
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 | ||
a1532a22 EB |
24 | status=1 # failure is the default! |
25 | ||
26 | _cleanup() | |
27 | { | |
28 | _cleanup_test_img | |
29 | _cleanup_qemu | |
30 | rm -f "$TEST_DIR/nbd" | |
31 | } | |
32 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
33 | ||
34 | # get standard environment, filters and checks | |
35 | . ./common.rc | |
36 | . ./common.filter | |
37 | . ./common.qemu | |
38 | ||
39 | _supported_fmt qcow2 | |
40 | _supported_proto file # uses NBD as well | |
41 | _supported_os Linux | |
092b9c40 HR |
42 | # Persistent dirty bitmaps require compat=1.1 |
43 | _unsupported_imgopts 'compat=0.10' | |
a1532a22 EB |
44 | |
45 | function do_run_qemu() | |
46 | { | |
47 | echo Testing: "$@" | |
48 | $QEMU -nographic -qmp stdio -serial none "$@" | |
49 | echo | |
50 | } | |
51 | ||
52 | function run_qemu() | |
53 | { | |
54 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ | |
55 | | _filter_qemu | _filter_imgfmt \ | |
56 | | _filter_actual_image_size | |
57 | } | |
58 | ||
59 | echo | |
60 | echo "=== Create partially sparse image, then add dirty bitmap ===" | |
61 | echo | |
62 | ||
63 | _make_test_img 4M | |
64 | $QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io | |
65 | run_qemu <<EOF | |
66 | { "execute": "qmp_capabilities" } | |
67 | { "execute": "blockdev-add", | |
68 | "arguments": { | |
69 | "driver": "$IMGFMT", | |
70 | "node-name": "n", | |
71 | "file": { | |
72 | "driver": "file", | |
73 | "filename": "$TEST_IMG" | |
74 | } | |
75 | } | |
76 | } | |
77 | { "execute": "block-dirty-bitmap-add", | |
78 | "arguments": { | |
79 | "node": "n", | |
80 | "name": "b", | |
81 | "persistent": true | |
82 | } | |
83 | } | |
84 | { "execute": "quit" } | |
85 | EOF | |
86 | ||
87 | echo | |
88 | echo "=== Write part of the file under active bitmap ===" | |
89 | echo | |
90 | ||
91 | $QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io | |
92 | ||
93 | echo | |
94 | echo "=== End dirty bitmap, and start serving image over NBD ===" | |
95 | echo | |
96 | ||
97 | _launch_qemu 2> >(_filter_nbd) | |
98 | ||
99 | silent= | |
100 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return" | |
101 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add", | |
102 | "arguments":{"driver":"qcow2", "node-name":"n", | |
103 | "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return" | |
104 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable", | |
105 | "arguments":{"node":"n", "name":"b"}}' "return" | |
106 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start", | |
107 | "arguments":{"addr":{"type":"unix", | |
108 | "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return" | |
109 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", | |
110 | "arguments":{"device":"n"}}' "return" | |
111 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap", | |
112 | "arguments":{"name":"n", "bitmap":"b"}}' "return" | |
113 | ||
114 | echo | |
115 | echo "=== Contrast normal status with dirty-bitmap status ===" | |
116 | echo | |
117 | ||
118 | QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT | |
119 | IMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd" | |
120 | $QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \ | |
121 | -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io | |
122 | $QEMU_IMG map --output=json --image-opts \ | |
123 | "$IMG" | _filter_qemu_img_map | |
124 | $QEMU_IMG map --output=json --image-opts \ | |
125 | "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map | |
126 | ||
127 | echo | |
128 | echo "=== End NBD server ===" | |
129 | echo | |
130 | ||
131 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", | |
132 | "arguments":{"name":"n"}}' "return" | |
133 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" | |
134 | _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" | |
135 | ||
136 | # success, all done | |
137 | echo '*** done' | |
138 | rm -f $seq.full | |
139 | status=0 |