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'
45 # Filter irrelevant format-specific information from the qemu-img info
46 # output (we only want the bitmaps, basically)
47 _filter_irrelevant_img_info
()
49 grep -v -e 'compat' -e 'compression type' -e 'data file' -e 'extended l2' \
50 -e 'lazy refcounts' -e 'refcount bits'
54 echo "=== Initial image setup ==="
57 # Create backing image with one bitmap
58 TEST_IMG
="$TEST_IMG.base" _make_test_img
10M
59 $QEMU_IMG bitmap
--add -f $IMGFMT "$TEST_IMG.base" b0
60 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io
62 # Create initial image and populate two bitmaps: one active, one inactive.
64 TEST_IMG
=$TEST_IMG.orig
65 _make_test_img
-b "$ORIG_IMG.base" -F $IMGFMT 10M
66 $QEMU_IO -c 'w 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
67 $QEMU_IMG bitmap
--add -g 512k
-f $IMGFMT "$TEST_IMG" b1
68 $QEMU_IMG bitmap
--add --disable -f $IMGFMT "$TEST_IMG" b2
69 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
70 $QEMU_IMG bitmap
--clear -f $IMGFMT "$TEST_IMG" b1
71 $QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
72 $QEMU_IMG bitmap
--disable -f $IMGFMT "$TEST_IMG" b1
73 $QEMU_IMG bitmap
--enable -f $IMGFMT "$TEST_IMG" b2
74 $QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
77 echo "=== Bitmap preservation not possible to non-qcow2 ==="
81 $QEMU_IMG convert
--bitmaps -O raw
"$TEST_IMG.orig" "$TEST_IMG" &&
82 echo "unexpected success"
85 echo "=== Convert with bitmap preservation ==="
88 # Only bitmaps from the active layer are copied
89 $QEMU_IMG convert
--bitmaps -O qcow2
"$TEST_IMG.orig" "$TEST_IMG"
90 _img_info
--format-specific | _filter_irrelevant_img_info
91 # But we can also merge in bitmaps from other layers. This test is a bit
92 # contrived to cover more code paths, in reality, you could merge directly
93 # into b0 without going through tmp
94 $QEMU_IMG bitmap
--add --disable -f $IMGFMT "$TEST_IMG" b0
95 $QEMU_IMG bitmap
--add --merge b0
-b "$TEST_IMG.base" -F $IMGFMT \
96 -f $IMGFMT "$TEST_IMG" tmp
97 $QEMU_IMG bitmap
--merge tmp
-f $IMGFMT "$TEST_IMG" b0
98 $QEMU_IMG bitmap
--remove --image-opts \
99 driver
=$IMGFMT,file.driver
=file,file.filename
="$TEST_IMG" tmp
100 _img_info
--format-specific | _filter_irrelevant_img_info
103 echo "=== Merge from top layer into backing image ==="
106 $QEMU_IMG rebase
-u -F qcow2
-b "$TEST_IMG.base" "$TEST_IMG"
107 $QEMU_IMG bitmap
--add --merge b2
-b "$TEST_IMG" -F $IMGFMT \
108 -f $IMGFMT "$TEST_IMG.base" b3
109 _img_info
--format-specific --backing-chain | _filter_irrelevant_img_info
112 echo "=== Check bitmap contents ==="
115 # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to
116 # report "data":false for portions of the bitmap which are set
117 IMG
="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
118 nbd_server_start_unix_socket
-r -f qcow2 \
119 -B b0
-B b1
-B b2
-B b3
"$TEST_IMG"
120 $QEMU_IMG map
--output=json
--image-opts \
121 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
122 $QEMU_IMG map
--output=json
--image-opts \
123 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map
124 $QEMU_IMG map
--output=json
--image-opts \
125 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
126 $QEMU_IMG map
--output=json
--image-opts \
127 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map