]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qemu-iotests/291
Update version for v6.1.0-rc0 release
[mirror_qemu.git] / tests / qemu-iotests / 291
CommitLineData
cf2d1203 1#!/usr/bin/env bash
9dd003a9 2# group: rw quick
cf2d1203
EB
3#
4# Test qemu-img bitmap handling
5#
6# Copyright (C) 2018-2020 Red Hat, Inc.
7#
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.
12#
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.
17#
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/>.
20#
21
22seq="$(basename $0)"
23echo "QA output created by $seq"
24
25status=1 # failure is the default!
26
27_cleanup()
28{
29 _cleanup_test_img
30 nbd_server_stop
31}
32trap "_cleanup; exit \$status" 0 1 2 3 15
33
34# get standard environment, filters and checks
35. ./common.rc
36. ./common.filter
37. ./common.nbd
38
39_supported_fmt qcow2
57284d2a 40_supported_proto file fuse
cf2d1203
EB
41_supported_os Linux
42_require_command QEMU_NBD
2e3becf9
HR
43# compat=0.10 does not support bitmaps
44_unsupported_imgopts 'compat=0.10'
cf2d1203 45
b4af1df0
HR
46# Filter irrelevant format-specific information from the qemu-img info
47# output (we only want the bitmaps, basically)
48_filter_irrelevant_img_info()
49{
50 grep -v -e 'compat' -e 'compression type' -e 'data file' -e 'extended l2' \
51 -e 'lazy refcounts' -e 'refcount bits'
52}
53
cf2d1203
EB
54echo
55echo "=== Initial image setup ==="
56echo
57
58# Create backing image with one bitmap
59TEST_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
62
63# Create initial image and populate two bitmaps: one active, one inactive.
64ORIG_IMG=$TEST_IMG
65TEST_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
76
77echo
78echo "=== Bitmap preservation not possible to non-qcow2 ==="
79echo
80
81TEST_IMG=$ORIG_IMG
82$QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" &&
83 echo "unexpected success"
84
85echo
86echo "=== Convert with bitmap preservation ==="
87echo
88
89# Only bitmaps from the active layer are copied
90$QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG"
b4af1df0 91_img_info --format-specific | _filter_irrelevant_img_info
cf2d1203
EB
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
b4af1df0 101_img_info --format-specific | _filter_irrelevant_img_info
cf2d1203 102
14f16bf9
EB
103echo
104echo "=== Merge from top layer into backing image ==="
105echo
106
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
b4af1df0 110_img_info --format-specific --backing-chain | _filter_irrelevant_img_info
14f16bf9 111
cf2d1203
EB
112echo
113echo "=== Check bitmap contents ==="
114echo
115
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
118IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
3b1f244c
EB
119nbd_server_start_unix_socket -r -f qcow2 \
120 -B b0 -B b1 -B b2 -B b3 "$TEST_IMG"
cf2d1203
EB
121$QEMU_IMG map --output=json --image-opts \
122 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
cf2d1203
EB
123$QEMU_IMG map --output=json --image-opts \
124 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map
cf2d1203
EB
125$QEMU_IMG map --output=json --image-opts \
126 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
14f16bf9
EB
127$QEMU_IMG map --output=json --image-opts \
128 "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b3" | _filter_qemu_img_map
cf2d1203 129
cb7223ac
HR
130nbd_server_stop
131
cf2d1203
EB
132# success, all done
133echo '*** done'
134rm -f $seq.full
135status=0