python/qemu: make 'args' style arguments immutable
[qemu.git] / tests / qemu-iotests / 291
blob4f837b205655e944ac8ae3f6da3284b248267f3d
1 #!/usr/bin/env bash
3 # Test qemu-img bitmap handling
5 # Copyright (C) 2018-2020 Red Hat, Inc.
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.
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.
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/>.
21 seq="$(basename $0)"
22 echo "QA output created by $seq"
24 status=1 # failure is the default!
26 _cleanup()
28 _cleanup_test_img
29 nbd_server_stop
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
34 . ./common.rc
35 . ./common.filter
36 . ./common.nbd
38 _supported_fmt qcow2
39 _supported_proto file
40 _supported_os Linux
41 _require_command QEMU_NBD
42 # compat=0.10 does not support bitmaps
43 _unsupported_imgopts 'compat=0.10'
45 echo
46 echo "=== Initial image setup ==="
47 echo
49 # Create backing image with one bitmap
50 TEST_IMG="$TEST_IMG.base" _make_test_img 10M
51 $QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG.base" b0
52 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io
54 # Create initial image and populate two bitmaps: one active, one inactive.
55 ORIG_IMG=$TEST_IMG
56 TEST_IMG=$TEST_IMG.orig
57 _make_test_img -b "$ORIG_IMG.base" -F $IMGFMT 10M
58 $QEMU_IO -c 'w 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
59 $QEMU_IMG bitmap --add -g 512k -f $IMGFMT "$TEST_IMG" b1
60 $QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b2
61 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
62 $QEMU_IMG bitmap --clear -f $IMGFMT "$TEST_IMG" b1
63 $QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
64 $QEMU_IMG bitmap --disable -f $IMGFMT "$TEST_IMG" b1
65 $QEMU_IMG bitmap --enable -f $IMGFMT "$TEST_IMG" b2
66 $QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
68 echo
69 echo "=== Bitmap preservation not possible to non-qcow2 ==="
70 echo
72 TEST_IMG=$ORIG_IMG
73 $QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" &&
74 echo "unexpected success"
76 echo
77 echo "=== Convert with bitmap preservation ==="
78 echo
80 # Only bitmaps from the active layer are copied
81 $QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG"
82 _img_info --format-specific
83 # But we can also merge in bitmaps from other layers. This test is a bit
84 # contrived to cover more code paths, in reality, you could merge directly
85 # into b0 without going through tmp
86 $QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b0
87 $QEMU_IMG bitmap --add --merge b0 -b "$TEST_IMG.base" -F $IMGFMT \
88 -f $IMGFMT "$TEST_IMG" tmp
89 $QEMU_IMG bitmap --merge tmp -f $IMGFMT "$TEST_IMG" b0
90 $QEMU_IMG bitmap --remove --image-opts \
91 driver=$IMGFMT,file.driver=file,file.filename="$TEST_IMG" tmp
92 _img_info --format-specific
94 echo
95 echo "=== Merge from top layer into backing image ==="
96 echo
98 $QEMU_IMG rebase -u -F qcow2 -b "$TEST_IMG.base" "$TEST_IMG"
99 $QEMU_IMG bitmap --add --merge b2 -b "$TEST_IMG" -F $IMGFMT \
100 -f $IMGFMT "$TEST_IMG.base" b3
101 _img_info --format-specific --backing-chain
103 echo
104 echo "=== Check bitmap contents ==="
105 echo
107 # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to
108 # report "data":false for portions of the bitmap which are set
109 IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
110 nbd_server_start_unix_socket -r -f qcow2 -B b0 "$TEST_IMG"
111 $QEMU_IMG map --output=json --image-opts \
112 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
113 nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG"
114 $QEMU_IMG map --output=json --image-opts \
115 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map
116 nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG"
117 $QEMU_IMG map --output=json --image-opts \
118 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
119 nbd_server_start_unix_socket -r -f qcow2 -B b3 "$TEST_IMG"
120 $QEMU_IMG map --output=json --image-opts \
121 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map
123 # success, all done
124 echo '*** done'
125 rm -f $seq.full
126 status=0