xref: /openbmc/qemu/tests/qemu-iotests/223 (revision 092b9c408fb22010747f17e2fb19521cfafd45d6)
1a1532a22SEric Blake#!/bin/bash
2a1532a22SEric Blake#
3a1532a22SEric Blake# Test reading dirty bitmap over NBD
4a1532a22SEric Blake#
5a1532a22SEric Blake# Copyright (C) 2018 Red Hat, Inc.
6a1532a22SEric Blake#
7a1532a22SEric Blake# This program is free software; you can redistribute it and/or modify
8a1532a22SEric Blake# it under the terms of the GNU General Public License as published by
9a1532a22SEric Blake# the Free Software Foundation; either version 2 of the License, or
10a1532a22SEric Blake# (at your option) any later version.
11a1532a22SEric Blake#
12a1532a22SEric Blake# This program is distributed in the hope that it will be useful,
13a1532a22SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of
14a1532a22SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15a1532a22SEric Blake# GNU General Public License for more details.
16a1532a22SEric Blake#
17a1532a22SEric Blake# You should have received a copy of the GNU General Public License
18a1532a22SEric Blake# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19a1532a22SEric Blake#
20a1532a22SEric Blake
21a1532a22SEric Blakeseq="$(basename $0)"
22a1532a22SEric Blakeecho "QA output created by $seq"
23a1532a22SEric Blake
24a1532a22SEric Blakehere="$PWD"
25a1532a22SEric Blakestatus=1 # failure is the default!
26a1532a22SEric Blake
27a1532a22SEric Blake_cleanup()
28a1532a22SEric Blake{
29a1532a22SEric Blake    _cleanup_test_img
30a1532a22SEric Blake    _cleanup_qemu
31a1532a22SEric Blake    rm -f "$TEST_DIR/nbd"
32a1532a22SEric Blake}
33a1532a22SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15
34a1532a22SEric Blake
35a1532a22SEric Blake# get standard environment, filters and checks
36a1532a22SEric Blake. ./common.rc
37a1532a22SEric Blake. ./common.filter
38a1532a22SEric Blake. ./common.qemu
39a1532a22SEric Blake
40a1532a22SEric Blake_supported_fmt qcow2
41a1532a22SEric Blake_supported_proto file # uses NBD as well
42a1532a22SEric Blake_supported_os Linux
43*092b9c40SMax Reitz# Persistent dirty bitmaps require compat=1.1
44*092b9c40SMax Reitz_unsupported_imgopts 'compat=0.10'
45a1532a22SEric Blake
46a1532a22SEric Blakefunction do_run_qemu()
47a1532a22SEric Blake{
48a1532a22SEric Blake    echo Testing: "$@"
49a1532a22SEric Blake    $QEMU -nographic -qmp stdio -serial none "$@"
50a1532a22SEric Blake    echo
51a1532a22SEric Blake}
52a1532a22SEric Blake
53a1532a22SEric Blakefunction run_qemu()
54a1532a22SEric Blake{
55a1532a22SEric Blake    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
56a1532a22SEric Blake                          | _filter_qemu | _filter_imgfmt \
57a1532a22SEric Blake                          | _filter_actual_image_size
58a1532a22SEric Blake}
59a1532a22SEric Blake
60a1532a22SEric Blakeecho
61a1532a22SEric Blakeecho "=== Create partially sparse image, then add dirty bitmap ==="
62a1532a22SEric Blakeecho
63a1532a22SEric Blake
64a1532a22SEric Blake_make_test_img 4M
65a1532a22SEric Blake$QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
66a1532a22SEric Blakerun_qemu <<EOF
67a1532a22SEric Blake{ "execute": "qmp_capabilities" }
68a1532a22SEric Blake{ "execute": "blockdev-add",
69a1532a22SEric Blake  "arguments": {
70a1532a22SEric Blake    "driver": "$IMGFMT",
71a1532a22SEric Blake    "node-name": "n",
72a1532a22SEric Blake    "file": {
73a1532a22SEric Blake      "driver": "file",
74a1532a22SEric Blake      "filename": "$TEST_IMG"
75a1532a22SEric Blake    }
76a1532a22SEric Blake  }
77a1532a22SEric Blake}
78a1532a22SEric Blake{ "execute": "block-dirty-bitmap-add",
79a1532a22SEric Blake  "arguments": {
80a1532a22SEric Blake    "node": "n",
81a1532a22SEric Blake    "name": "b",
82a1532a22SEric Blake    "persistent": true
83a1532a22SEric Blake  }
84a1532a22SEric Blake}
85a1532a22SEric Blake{ "execute": "quit" }
86a1532a22SEric BlakeEOF
87a1532a22SEric Blake
88a1532a22SEric Blakeecho
89a1532a22SEric Blakeecho "=== Write part of the file under active bitmap ==="
90a1532a22SEric Blakeecho
91a1532a22SEric Blake
92a1532a22SEric Blake$QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io
93a1532a22SEric Blake
94a1532a22SEric Blakeecho
95a1532a22SEric Blakeecho "=== End dirty bitmap, and start serving image over NBD ==="
96a1532a22SEric Blakeecho
97a1532a22SEric Blake
98a1532a22SEric Blake_launch_qemu 2> >(_filter_nbd)
99a1532a22SEric Blake
100a1532a22SEric Blakesilent=
101a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
102a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add",
103a1532a22SEric Blake  "arguments":{"driver":"qcow2", "node-name":"n",
104a1532a22SEric Blake    "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
105a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable",
106a1532a22SEric Blake  "arguments":{"node":"n", "name":"b"}}' "return"
107a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
108a1532a22SEric Blake  "arguments":{"addr":{"type":"unix",
109a1532a22SEric Blake    "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
110a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
111a1532a22SEric Blake  "arguments":{"device":"n"}}' "return"
112a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap",
113a1532a22SEric Blake  "arguments":{"name":"n", "bitmap":"b"}}' "return"
114a1532a22SEric Blake
115a1532a22SEric Blakeecho
116a1532a22SEric Blakeecho "=== Contrast normal status with dirty-bitmap status ==="
117a1532a22SEric Blakeecho
118a1532a22SEric Blake
119a1532a22SEric BlakeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
120a1532a22SEric BlakeIMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
121a1532a22SEric Blake$QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \
122a1532a22SEric Blake  -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io
123a1532a22SEric Blake$QEMU_IMG map --output=json --image-opts \
124a1532a22SEric Blake  "$IMG" | _filter_qemu_img_map
125a1532a22SEric Blake$QEMU_IMG map --output=json --image-opts \
126a1532a22SEric Blake  "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
127a1532a22SEric Blake
128a1532a22SEric Blakeecho
129a1532a22SEric Blakeecho "=== End NBD server ==="
130a1532a22SEric Blakeecho
131a1532a22SEric Blake
132a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
133a1532a22SEric Blake  "arguments":{"name":"n"}}' "return"
134a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
135a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
136a1532a22SEric Blake
137a1532a22SEric Blake# success, all done
138a1532a22SEric Blakeecho '*** done'
139a1532a22SEric Blakerm -f $seq.full
140a1532a22SEric Blakestatus=0
141