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/>.
22 echo "QA output created by $seq"
24 status
=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
41 _require_command QEMU_NBD
42 # compat=0.10 does not support bitmaps
43 _unsupported_imgopts
'compat=0.10'
46 echo "=== Initial image setup ==="
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.
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
69 echo "=== Bitmap preservation not possible to non-qcow2 ==="
73 $QEMU_IMG convert
--bitmaps -O raw
"$TEST_IMG.orig" "$TEST_IMG" &&
74 echo "unexpected success"
77 echo "=== Convert with bitmap preservation ==="
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
95 echo "=== Merge from top layer into backing image ==="
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
104 echo "=== Check bitmap contents ==="
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