Add a new test covering the feature added in the previous patch. Signed-off-by: Eric Blake <ebl...@redhat.com> --- tests/qemu-iotests/291 | 143 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/291.out | 56 +++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 200 insertions(+) create mode 100755 tests/qemu-iotests/291 create mode 100644 tests/qemu-iotests/291.out
diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291 new file mode 100755 index 000000000000..dfdcc8e352c8 --- /dev/null +++ b/tests/qemu-iotests/291 @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# +# Test qemu-img convert --bitmaps +# +# Copyright (C) 2018-2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +seq="$(basename $0)" +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + nbd_server_stop +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.nbd + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +_require_command QEMU_NBD + +do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ + | _filter_qemu | _filter_imgfmt \ + | _filter_actual_image_size | _filter_qemu_io +} + +# Create initial image and populate two bitmaps: one active, one inactive +_make_test_img 10M +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "n", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "human-monitor-command", + "arguments": { + "command-line": 'qemu-io n "write 0 1M"' + } +} +{ "execute": "block-dirty-bitmap-add", + "arguments": { + "node": "n", + "name": "b1", + "persistent": true, + "granularity": 65536 + } +} +{ "execute": "human-monitor-command", + "arguments": { + "command-line": 'qemu-io n "write 1M 1M"' + } +} +{ "execute": "transaction", + "arguments": { + "actions": [ + { "type": "block-dirty-bitmap-disable", + "data": { + "node": "n", + "name": "b1" + } }, + { "type": "block-dirty-bitmap-add", + "data": { + "node": "n", + "name": "b2", + "persistent": true + } } + ] + } +} +{ "execute": "human-monitor-command", + "arguments": { + "command-line": 'qemu-io n "write 2M 1M"' + } +} +{ "execute": "quit" } +EOF + +echo +echo "=== Bitmap preservation not possible to non-qcow2 ===" +echo + +mv "$TEST_IMG" "$TEST_IMG.orig" +$QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" + +echo +echo "=== convert with bitmap preservation ===" +echo + +$QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG" +$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific + +echo +echo "=== check bitmap contents ===" +echo + +IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket" +nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG" +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map +nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG" +$QEMU_IMG map --output=json --image-opts \ + "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map + +# success, all done +echo '*** done' +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out new file mode 100644 index 000000000000..3e826f93ca82 --- /dev/null +++ b/tests/qemu-iotests/291.out @@ -0,0 +1,56 @@ +QA output created by 291 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=10485760 +Testing: +QMP_VERSION +{"return": {}} +{"return": {}} +wrote 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"return": ""} +{"return": {}} +wrote 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"return": ""} +{"return": {}} +wrote 1048576/1048576 bytes at offset 2097152 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +{"return": ""} +{"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} + + +=== Bitmap preservation not possible to non-qcow2 === + +qemu-img: Format driver 'raw' does not support bitmaps + +=== convert with bitmap preservation === + +image: TEST_DIR/t.IMGFMT +file format: IMGFMT +virtual size: 10 MiB (10485760 bytes) +disk size: 3.39 MiB +Format specific information: + compat: 1.1 + lazy refcounts: false + bitmaps: + [0]: + flags: + [0]: auto + name: b2 + granularity: 65536 + [1]: + flags: + name: b1 + granularity: 65536 + refcount bits: 16 + corrupt: false + +=== check bitmap contents === + +[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, +{ "start": 1048576, "length": 1048576, "depth": 0, "zero": false, "data": false}, +{ "start": 2097152, "length": 8388608, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] +[{ "start": 0, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET}, +{ "start": 2097152, "length": 1048576, "depth": 0, "zero": false, "data": false}, +{ "start": 3145728, "length": 7340032, "depth": 0, "zero": false, "data": true, "offset": OFFSET}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 435dccd5af90..8e9b9513a091 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -297,3 +297,4 @@ 288 quick 289 rw quick 290 rw auto quick +291 rw quick -- 2.26.0