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

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