yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-iotests-Add-test-291-to-for-qemu-img-bitmap-coverage.patch

ddf19c
From eccae2f252513d2965ef919022c3ed068da275bd Mon Sep 17 00:00:00 2001
ddf19c
From: Eric Blake <eblake@redhat.com>
ddf19c
Date: Tue, 2 Jun 2020 02:34:20 +0100
ddf19c
Subject: [PATCH 15/26] iotests: Add test 291 to for qemu-img bitmap coverage
ddf19c
ddf19c
RH-Author: Eric Blake <eblake@redhat.com>
ddf19c
Message-id: <20200602023420.2133649-13-eblake@redhat.com>
ddf19c
Patchwork-id: 97079
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 12/12] iotests: Add test 291 to for qemu-img bitmap coverage
ddf19c
Bugzilla: 1779893 1779904
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ddf19c
ddf19c
Add a new test covering the 'qemu-img bitmap' subcommand, as well as
ddf19c
'qemu-img convert --bitmaps', both added in recent patches.
ddf19c
ddf19c
Signed-off-by: Eric Blake <eblake@redhat.com>
ddf19c
Reviewed-by: Max Reitz <mreitz@redhat.com>
ddf19c
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
ddf19c
Message-Id: <20200521192137.1120211-6-eblake@redhat.com>
ddf19c
(cherry picked from commit cf2d1203dcfc2bf964453d83a2302231ce77f2dc)
ddf19c
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
ddf19c
Conflicts:
ddf19c
	tests/qemu-iotests/group - context: other tests not backported
ddf19c
	tests/qemu-iotests/291.out - zstd compression not backported
ddf19c
Signed-off-by: Eric Blake <eblake@redhat.com>
ddf19c
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 tests/qemu-iotests/291     | 112 +++++++++++++++++++++++++++++++++++++++++++++
ddf19c
 tests/qemu-iotests/291.out |  78 +++++++++++++++++++++++++++++++
ddf19c
 tests/qemu-iotests/group   |   1 +
ddf19c
 3 files changed, 191 insertions(+)
ddf19c
 create mode 100755 tests/qemu-iotests/291
ddf19c
 create mode 100644 tests/qemu-iotests/291.out
ddf19c
ddf19c
diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291
ddf19c
new file mode 100755
ddf19c
index 0000000..3ca83b9
ddf19c
--- /dev/null
ddf19c
+++ b/tests/qemu-iotests/291
ddf19c
@@ -0,0 +1,112 @@
ddf19c
+#!/usr/bin/env bash
ddf19c
+#
ddf19c
+# Test qemu-img bitmap handling
ddf19c
+#
ddf19c
+# Copyright (C) 2018-2020 Red Hat, Inc.
ddf19c
+#
ddf19c
+# This program is free software; you can redistribute it and/or modify
ddf19c
+# it under the terms of the GNU General Public License as published by
ddf19c
+# the Free Software Foundation; either version 2 of the License, or
ddf19c
+# (at your option) any later version.
ddf19c
+#
ddf19c
+# This program is distributed in the hope that it will be useful,
ddf19c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ddf19c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ddf19c
+# GNU General Public License for more details.
ddf19c
+#
ddf19c
+# You should have received a copy of the GNU General Public License
ddf19c
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ddf19c
+#
ddf19c
+
ddf19c
+seq="$(basename $0)"
ddf19c
+echo "QA output created by $seq"
ddf19c
+
ddf19c
+status=1 # failure is the default!
ddf19c
+
ddf19c
+_cleanup()
ddf19c
+{
ddf19c
+    _cleanup_test_img
ddf19c
+    nbd_server_stop
ddf19c
+}
ddf19c
+trap "_cleanup; exit \$status" 0 1 2 3 15
ddf19c
+
ddf19c
+# get standard environment, filters and checks
ddf19c
+. ./common.rc
ddf19c
+. ./common.filter
ddf19c
+. ./common.nbd
ddf19c
+
ddf19c
+_supported_fmt qcow2
ddf19c
+_supported_proto file
ddf19c
+_supported_os Linux
ddf19c
+_require_command QEMU_NBD
ddf19c
+
ddf19c
+echo
ddf19c
+echo "=== Initial image setup ==="
ddf19c
+echo
ddf19c
+
ddf19c
+# Create backing image with one bitmap
ddf19c
+TEST_IMG="$TEST_IMG.base" _make_test_img 10M
ddf19c
+$QEMU_IMG bitmap --add -f $IMGFMT "$TEST_IMG.base" b0
ddf19c
+$QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io
ddf19c
+
ddf19c
+# Create initial image and populate two bitmaps: one active, one inactive.
ddf19c
+ORIG_IMG=$TEST_IMG
ddf19c
+TEST_IMG=$TEST_IMG.orig
ddf19c
+_make_test_img -b "$ORIG_IMG.base" -F $IMGFMT 10M
ddf19c
+$QEMU_IO -c 'w 0 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
ddf19c
+$QEMU_IMG bitmap --add -g 512k -f $IMGFMT "$TEST_IMG" b1
ddf19c
+$QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b2
ddf19c
+$QEMU_IO -c 'w 3M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
ddf19c
+$QEMU_IMG bitmap --clear -f $IMGFMT "$TEST_IMG" b1
ddf19c
+$QEMU_IO -c 'w 1M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
ddf19c
+$QEMU_IMG bitmap --disable -f $IMGFMT "$TEST_IMG" b1
ddf19c
+$QEMU_IMG bitmap --enable -f $IMGFMT "$TEST_IMG" b2
ddf19c
+$QEMU_IO -c 'w 2M 1M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io
ddf19c
+
ddf19c
+echo
ddf19c
+echo "=== Bitmap preservation not possible to non-qcow2 ==="
ddf19c
+echo
ddf19c
+
ddf19c
+TEST_IMG=$ORIG_IMG
ddf19c
+$QEMU_IMG convert --bitmaps -O raw "$TEST_IMG.orig" "$TEST_IMG" &&
ddf19c
+    echo "unexpected success"
ddf19c
+
ddf19c
+echo
ddf19c
+echo "=== Convert with bitmap preservation ==="
ddf19c
+echo
ddf19c
+
ddf19c
+# Only bitmaps from the active layer are copied
ddf19c
+$QEMU_IMG convert --bitmaps -O qcow2 "$TEST_IMG.orig" "$TEST_IMG"
ddf19c
+$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific
ddf19c
+# But we can also merge in bitmaps from other layers.  This test is a bit
ddf19c
+# contrived to cover more code paths, in reality, you could merge directly
ddf19c
+# into b0 without going through tmp
ddf19c
+$QEMU_IMG bitmap --add --disable -f $IMGFMT "$TEST_IMG" b0
ddf19c
+$QEMU_IMG bitmap --add --merge b0 -b "$TEST_IMG.base" -F $IMGFMT \
ddf19c
+     -f $IMGFMT "$TEST_IMG" tmp
ddf19c
+$QEMU_IMG bitmap --merge tmp -f $IMGFMT "$TEST_IMG" b0
ddf19c
+$QEMU_IMG bitmap --remove --image-opts \
ddf19c
+    driver=$IMGFMT,file.driver=file,file.filename="$TEST_IMG" tmp
ddf19c
+$QEMU_IMG info "$TEST_IMG" | _filter_img_info --format-specific
ddf19c
+
ddf19c
+echo
ddf19c
+echo "=== Check bitmap contents ==="
ddf19c
+echo
ddf19c
+
ddf19c
+# x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to
ddf19c
+# report "data":false for portions of the bitmap which are set
ddf19c
+IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
ddf19c
+nbd_server_start_unix_socket -r -f qcow2 -B b0 "$TEST_IMG"
ddf19c
+$QEMU_IMG map --output=json --image-opts \
ddf19c
+    "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b0" | _filter_qemu_img_map
ddf19c
+nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG"
ddf19c
+$QEMU_IMG map --output=json --image-opts \
ddf19c
+    "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b1" | _filter_qemu_img_map
ddf19c
+nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG"
ddf19c
+$QEMU_IMG map --output=json --image-opts \
ddf19c
+    "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
ddf19c
+
ddf19c
+# success, all done
ddf19c
+echo '*** done'
ddf19c
+rm -f $seq.full
ddf19c
+status=0
ddf19c
diff --git a/tests/qemu-iotests/291.out b/tests/qemu-iotests/291.out
ddf19c
new file mode 100644
ddf19c
index 0000000..14e5cfc
ddf19c
--- /dev/null
ddf19c
+++ b/tests/qemu-iotests/291.out
ddf19c
@@ -0,0 +1,78 @@
ddf19c
+QA output created by 291
ddf19c
+
ddf19c
+=== Initial image setup ===
ddf19c
+
ddf19c
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=10485760
ddf19c
+wrote 1048576/1048576 bytes at offset 3145728
ddf19c
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ddf19c
+Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=10485760 backing_file=TEST_DIR/t.IMGFMT.base backing_fmt=IMGFMT
ddf19c
+wrote 1048576/1048576 bytes at offset 0
ddf19c
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ddf19c
+wrote 1048576/1048576 bytes at offset 3145728
ddf19c
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ddf19c
+wrote 1048576/1048576 bytes at offset 1048576
ddf19c
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ddf19c
+wrote 1048576/1048576 bytes at offset 2097152
ddf19c
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
ddf19c
+
ddf19c
+=== Bitmap preservation not possible to non-qcow2 ===
ddf19c
+
ddf19c
+qemu-img: Format driver 'raw' does not support bitmaps
ddf19c
+
ddf19c
+=== Convert with bitmap preservation ===
ddf19c
+
ddf19c
+image: TEST_DIR/t.IMGFMT
ddf19c
+file format: IMGFMT
ddf19c
+virtual size: 10 MiB (10485760 bytes)
ddf19c
+disk size: 4.39 MiB
ddf19c
+Format specific information:
ddf19c
+    compat: 1.1
ddf19c
+    lazy refcounts: false
ddf19c
+    bitmaps:
ddf19c
+        [0]:
ddf19c
+            flags:
ddf19c
+            name: b1
ddf19c
+            granularity: 524288
ddf19c
+        [1]:
ddf19c
+            flags:
ddf19c
+                [0]: auto
ddf19c
+            name: b2
ddf19c
+            granularity: 65536
ddf19c
+    refcount bits: 16
ddf19c
+    corrupt: false
ddf19c
+image: TEST_DIR/t.IMGFMT
ddf19c
+file format: IMGFMT
ddf19c
+virtual size: 10 MiB (10485760 bytes)
ddf19c
+disk size: 4.48 MiB
ddf19c
+Format specific information:
ddf19c
+    compat: 1.1
ddf19c
+    lazy refcounts: false
ddf19c
+    bitmaps:
ddf19c
+        [0]:
ddf19c
+            flags:
ddf19c
+            name: b1
ddf19c
+            granularity: 524288
ddf19c
+        [1]:
ddf19c
+            flags:
ddf19c
+                [0]: auto
ddf19c
+            name: b2
ddf19c
+            granularity: 65536
ddf19c
+        [2]:
ddf19c
+            flags:
ddf19c
+            name: b0
ddf19c
+            granularity: 65536
ddf19c
+    refcount bits: 16
ddf19c
+    corrupt: false
ddf19c
+
ddf19c
+=== Check bitmap contents ===
ddf19c
+
ddf19c
+[{ "start": 0, "length": 3145728, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
ddf19c
+{ "start": 3145728, "length": 1048576, "depth": 0, "zero": false, "data": false},
ddf19c
+{ "start": 4194304, "length": 6291456, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
ddf19c
+[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
ddf19c
+{ "start": 1048576, "length": 1048576, "depth": 0, "zero": false, "data": false},
ddf19c
+{ "start": 2097152, "length": 8388608, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
ddf19c
+[{ "start": 0, "length": 2097152, "depth": 0, "zero": false, "data": true, "offset": OFFSET},
ddf19c
+{ "start": 2097152, "length": 1048576, "depth": 0, "zero": false, "data": false},
ddf19c
+{ "start": 3145728, "length": 7340032, "depth": 0, "zero": false, "data": true, "offset": OFFSET}]
ddf19c
+*** done
ddf19c
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
ddf19c
index 9c565cf..033b54d 100644
ddf19c
--- a/tests/qemu-iotests/group
ddf19c
+++ b/tests/qemu-iotests/group
ddf19c
@@ -290,3 +290,4 @@
ddf19c
 280 rw migration quick
ddf19c
 281 rw quick
ddf19c
 284 rw
ddf19c
+291 rw quick
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c