Merge remote-tracking branch 'remotes/nvme/tags/nvme-fixes-20210407-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 291
blob20efb080a6c0a509bcdc7fbfcd8a1cea76789871
1 #!/usr/bin/env bash
2 # group: rw quick
4 # Test qemu-img bitmap handling
6 # Copyright (C) 2018-2020 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 seq="$(basename $0)"
23 echo "QA output created by $seq"
25 status=1 # failure is the default!
27 _cleanup()
29 _cleanup_test_img
30 nbd_server_stop
32 trap "_cleanup; exit \$status" 0 1 2 3 15
34 # get standard environment, filters and checks
35 . ./common.rc
36 . ./common.filter
37 . ./common.nbd
39 _supported_fmt qcow2
40 _supported_proto file fuse
41 _supported_os Linux
42 _require_command QEMU_NBD
43 # compat=0.10 does not support bitmaps
44 _unsupported_imgopts 'compat=0.10'
46 # Filter irrelevant format-specific information from the qemu-img info
47 # output (we only want the bitmaps, basically)
48 _filter_irrelevant_img_info()
50 grep -v -e 'compat' -e 'compression type' -e 'data file' -e 'extended l2' \
51 -e 'lazy refcounts' -e 'refcount bits'
54 echo
55 echo "=== Initial image setup ==="
56 echo
58 # Create backing image with one bitmap
59 TEST_IMG="$TEST_IMG.base" _make_test_img 10M
60 $QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG.base" b0
61 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io
63 # Create initial image and populate two bitmaps: one active, one inactive.
64 ORIG_IMG=$TEST_IMG
65 TEST_IMG=$TEST_IMG.orig
66 _make_test_img -b "$ORIG_IMG.base" -F $IMGFMT 10M
67 $QEMU_IO -c 'w 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IMG bitmap --add -g 512k -f $IMGFMT "$TEST_IMG" b1
69 $QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b2
70 $QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
71 $QEMU_IMG bitmap --clear -f $IMGFMT "$TEST_IMG" b1
72 $QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
73 $QEMU_IMG bitmap --disable -f $IMGFMT "$TEST_IMG" b1
74 $QEMU_IMG bitmap --enable -f $IMGFMT "$TEST_IMG" b2
75 $QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
77 echo
78 echo "=== Bitmap preservation not possible to non-qcow2 ==="
79 echo
81 TEST_IMG=$ORIG_IMG
82 $QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" &&
83 echo "unexpected success"
85 echo
86 echo "=== Convert with bitmap preservation ==="
87 echo
89 # Only bitmaps from the active layer are copied
90 $QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG"
91 _img_info --format-specific | _filter_irrelevant_img_info
92 # But we can also merge in bitmaps from other layers. This test is a bit
93 # contrived to cover more code paths, in reality, you could merge directly
94 # into b0 without going through tmp
95 $QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b0
96 $QEMU_IMG bitmap --add --merge b0 -b "$TEST_IMG.base" -F $IMGFMT \
97 -f $IMGFMT "$TEST_IMG" tmp
98 $QEMU_IMG bitmap --merge tmp -f $IMGFMT "$TEST_IMG" b0
99 $QEMU_IMG bitmap --remove --image-opts \
100 driver=$IMGFMT,file.driver=file,file.filename="$TEST_IMG" tmp
101 _img_info --format-specific | _filter_irrelevant_img_info
103 echo
104 echo "=== Merge from top layer into backing image ==="
105 echo
107 $QEMU_IMG rebase -u -F qcow2 -b "$TEST_IMG.base" "$TEST_IMG"
108 $QEMU_IMG bitmap --add --merge b2 -b "$TEST_IMG" -F $IMGFMT \
109 -f $IMGFMT "$TEST_IMG.base" b3
110 _img_info --format-specific --backing-chain | _filter_irrelevant_img_info
112 echo
113 echo "=== Check bitmap contents ==="
114 echo
116 # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to
117 # report "data":false for portions of the bitmap which are set
118 IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
119 nbd_server_start_unix_socket -r -f qcow2 \
120 -B b0 -B b1 -B b2 -B b3 "$TEST_IMG"
121 $QEMU_IMG map --output=json --image-opts \
122 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
123 $QEMU_IMG map --output=json --image-opts \
124 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map
125 $QEMU_IMG map --output=json --image-opts \
126 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
127 $QEMU_IMG map --output=json --image-opts \
128 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map
130 nbd_server_stop
132 # success, all done
133 echo '*** done'
134 rm -f $seq.full
135 status=0