Blame SOURCES/kvm-qcow2-list-of-bitmaps-new-test-242.patch

7711c0
From 171b297adccba187047045e533213ff1adad7173 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 20 Mar 2019 21:48:38 +0100
7711c0
Subject: [PATCH 045/163] qcow2: list of bitmaps new test 242
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190320214838.22027-11-jsnow@redhat.com>
7711c0
Patchwork-id: 85001
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 10/10] qcow2: list of bitmaps new test 242
7711c0
Bugzilla: 1691048
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
7711c0
7711c0
A new test file 242 added to the qemu-iotests set. It checks
7711c0
the format of qcow2 specific information for the new added
7711c0
section that lists details of bitmaps.
7711c0
7711c0
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
7711c0
Message-Id: <1549638368-530182-4-git-send-email-andrey.shinkevich@virtuozzo.com>
7711c0
Reviewed-by: Eric Blake <eblake@redhat.com>
7711c0
[eblake: pep8 compliance, avoid trailing blank line]
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
(cherry picked from commit ddd113beedd22908e676d53803843d2f85bf91ab)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 tests/qemu-iotests/242     | 104 ++++++++++++++++++++++++++++
7711c0
 tests/qemu-iotests/242.out | 166 +++++++++++++++++++++++++++++++++++++++++++++
7711c0
 tests/qemu-iotests/group   |   1 +
7711c0
 3 files changed, 271 insertions(+)
7711c0
 create mode 100755 tests/qemu-iotests/242
7711c0
 create mode 100644 tests/qemu-iotests/242.out
7711c0
7711c0
diff --git a/tests/qemu-iotests/242 b/tests/qemu-iotests/242
7711c0
new file mode 100755
7711c0
index 0000000..16c65ed
7711c0
--- /dev/null
7711c0
+++ b/tests/qemu-iotests/242
7711c0
@@ -0,0 +1,104 @@
7711c0
+#!/usr/bin/env python
7711c0
+#
7711c0
+# Test for qcow2 bitmap printed information
7711c0
+#
7711c0
+# Copyright (c) 2019 Virtuozzo International GmbH
7711c0
+#
7711c0
+# This program is free software; you can redistribute it and/or modify
7711c0
+# it under the terms of the GNU General Public License as published by
7711c0
+# the Free Software Foundation; either version 2 of the License, or
7711c0
+# (at your option) any later version.
7711c0
+#
7711c0
+# This program is distributed in the hope that it will be useful,
7711c0
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7711c0
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7711c0
+# GNU General Public License for more details.
7711c0
+#
7711c0
+# You should have received a copy of the GNU General Public License
7711c0
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7711c0
+#
7711c0
+
7711c0
+import iotests
7711c0
+import json
7711c0
+from iotests import qemu_img_create, qemu_io, qemu_img_pipe, \
7711c0
+    file_path, img_info_log, log, filter_qemu_io
7711c0
+
7711c0
+iotests.verify_image_format(supported_fmts=['qcow2'])
7711c0
+
7711c0
+disk = file_path('disk')
7711c0
+chunk = 256 * 1024
7711c0
+bitmap_flag_unknown = 1 << 2
7711c0
+# flag_offset = 5*cluster_size + flag_offset_in_bitmap_directory_entry
7711c0
+flag_offset = 0x5000f
7711c0
+
7711c0
+
7711c0
+def print_bitmap(extra_args):
7711c0
+    log('qemu-img info dump:\n')
7711c0
+    img_info_log(disk, extra_args=extra_args)
7711c0
+    result = json.loads(qemu_img_pipe('info', '--force-share',
7711c0
+                                      '--output=json', disk))
7711c0
+    if 'bitmaps' in result['format-specific']['data']:
7711c0
+        bitmaps = result['format-specific']['data']['bitmaps']
7711c0
+        log('The same bitmaps in JSON format:')
7711c0
+        log(bitmaps, indent=2)
7711c0
+    else:
7711c0
+        log('No bitmap in JSON format output')
7711c0
+
7711c0
+
7711c0
+def add_bitmap(bitmap_number, persistent, disabled):
7711c0
+    granularity = 1 << (13 + bitmap_number)
7711c0
+    bitmap_name = 'bitmap-' + str(bitmap_number-1)
7711c0
+    vm = iotests.VM().add_drive(disk)
7711c0
+    vm.launch()
7711c0
+    vm.qmp_log('block-dirty-bitmap-add', node='drive0', name=bitmap_name,
7711c0
+               granularity=granularity, persistent=persistent,
7711c0
+               disabled=disabled)
7711c0
+    vm.shutdown()
7711c0
+
7711c0
+
7711c0
+def write_to_disk(offset, size):
7711c0
+    write = 'write {} {}'.format(offset, size)
7711c0
+    log(qemu_io('-c', write, disk), filters=[filter_qemu_io])
7711c0
+
7711c0
+
7711c0
+def toggle_flag(offset):
7711c0
+    with open(disk, "r+b") as f:
7711c0
+        f.seek(offset, 0)
7711c0
+        c = f.read(1)
7711c0
+        toggled = chr(ord(c) ^ bitmap_flag_unknown)
7711c0
+        f.seek(-1, 1)
7711c0
+        f.write(toggled)
7711c0
+
7711c0
+
7711c0
+qemu_img_create('-f', iotests.imgfmt, disk, '1M')
7711c0
+
7711c0
+for num in range(1, 4):
7711c0
+    disabled = False
7711c0
+    if num == 2:
7711c0
+        disabled = True
7711c0
+    log('Test {}'.format(num))
7711c0
+    add_bitmap(num, num > 1, disabled)
7711c0
+    write_to_disk((num-1) * chunk, chunk)
7711c0
+    print_bitmap([])
7711c0
+    log('')
7711c0
+
7711c0
+vm = iotests.VM().add_drive(disk)
7711c0
+vm.launch()
7711c0
+num += 1
7711c0
+log('Test {}\nChecking "in-use" flag...'.format(num))
7711c0
+print_bitmap(['--force-share'])
7711c0
+vm.shutdown()
7711c0
+
7711c0
+num += 1
7711c0
+log('\nTest {}'.format(num))
7711c0
+qemu_img_create('-f', iotests.imgfmt, disk, '1M')
7711c0
+add_bitmap(1, True, False)
7711c0
+log('Write an unknown bitmap flag \'{}\' into a new QCOW2 image at offset {}'
7711c0
+    .format(hex(bitmap_flag_unknown), flag_offset))
7711c0
+toggle_flag(flag_offset)
7711c0
+img_info_log(disk)
7711c0
+toggle_flag(flag_offset)
7711c0
+log('Unset the unknown bitmap flag \'{}\' in the bitmap directory entry:\n'
7711c0
+    .format(hex(bitmap_flag_unknown)))
7711c0
+img_info_log(disk)
7711c0
+log('Test complete')
7711c0
diff --git a/tests/qemu-iotests/242.out b/tests/qemu-iotests/242.out
7711c0
new file mode 100644
7711c0
index 0000000..fbe05d7
7711c0
--- /dev/null
7711c0
+++ b/tests/qemu-iotests/242.out
7711c0
@@ -0,0 +1,166 @@
7711c0
+Test 1
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": false, "granularity": 16384, "name": "bitmap-0", "node": "drive0", "persistent": false}}
7711c0
+{"return": {}}
7711c0
+wrote 262144/262144 bytes at offset 0
7711c0
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
7711c0
+
7711c0
+qemu-img info dump:
7711c0
+
7711c0
+image: TEST_IMG
7711c0
+file format: IMGFMT
7711c0
+virtual size: 1.0M (1048576 bytes)
7711c0
+cluster_size: 65536
7711c0
+Format specific information:
7711c0
+    compat: 1.1
7711c0
+    lazy refcounts: false
7711c0
+    refcount bits: 16
7711c0
+    corrupt: false
7711c0
+
7711c0
+No bitmap in JSON format output
7711c0
+
7711c0
+Test 2
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": true, "granularity": 32768, "name": "bitmap-1", "node": "drive0", "persistent": true}}
7711c0
+{"return": {}}
7711c0
+wrote 262144/262144 bytes at offset 262144
7711c0
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
7711c0
+
7711c0
+qemu-img info dump:
7711c0
+
7711c0
+image: TEST_IMG
7711c0
+file format: IMGFMT
7711c0
+virtual size: 1.0M (1048576 bytes)
7711c0
+cluster_size: 65536
7711c0
+Format specific information:
7711c0
+    compat: 1.1
7711c0
+    lazy refcounts: false
7711c0
+    bitmaps:
7711c0
+        [0]:
7711c0
+            flags:
7711c0
+            name: bitmap-1
7711c0
+            granularity: 32768
7711c0
+    refcount bits: 16
7711c0
+    corrupt: false
7711c0
+
7711c0
+The same bitmaps in JSON format:
7711c0
+[
7711c0
+  {
7711c0
+    "flags": [],
7711c0
+    "granularity": 32768,
7711c0
+    "name": "bitmap-1"
7711c0
+  }
7711c0
+]
7711c0
+
7711c0
+Test 3
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": false, "granularity": 65536, "name": "bitmap-2", "node": "drive0", "persistent": true}}
7711c0
+{"return": {}}
7711c0
+wrote 262144/262144 bytes at offset 524288
7711c0
+256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
7711c0
+
7711c0
+qemu-img info dump:
7711c0
+
7711c0
+image: TEST_IMG
7711c0
+file format: IMGFMT
7711c0
+virtual size: 1.0M (1048576 bytes)
7711c0
+cluster_size: 65536
7711c0
+Format specific information:
7711c0
+    compat: 1.1
7711c0
+    lazy refcounts: false
7711c0
+    bitmaps:
7711c0
+        [0]:
7711c0
+            flags:
7711c0
+            name: bitmap-1
7711c0
+            granularity: 32768
7711c0
+        [1]:
7711c0
+            flags:
7711c0
+                [0]: auto
7711c0
+            name: bitmap-2
7711c0
+            granularity: 65536
7711c0
+    refcount bits: 16
7711c0
+    corrupt: false
7711c0
+
7711c0
+The same bitmaps in JSON format:
7711c0
+[
7711c0
+  {
7711c0
+    "flags": [],
7711c0
+    "granularity": 32768,
7711c0
+    "name": "bitmap-1"
7711c0
+  },
7711c0
+  {
7711c0
+    "flags": [
7711c0
+      "auto"
7711c0
+    ],
7711c0
+    "granularity": 65536,
7711c0
+    "name": "bitmap-2"
7711c0
+  }
7711c0
+]
7711c0
+
7711c0
+Test 4
7711c0
+Checking "in-use" flag...
7711c0
+qemu-img info dump:
7711c0
+
7711c0
+image: TEST_IMG
7711c0
+file format: IMGFMT
7711c0
+virtual size: 1.0M (1048576 bytes)
7711c0
+cluster_size: 65536
7711c0
+Format specific information:
7711c0
+    compat: 1.1
7711c0
+    lazy refcounts: false
7711c0
+    bitmaps:
7711c0
+        [0]:
7711c0
+            flags:
7711c0
+                [0]: in-use
7711c0
+            name: bitmap-1
7711c0
+            granularity: 32768
7711c0
+        [1]:
7711c0
+            flags:
7711c0
+                [0]: in-use
7711c0
+                [1]: auto
7711c0
+            name: bitmap-2
7711c0
+            granularity: 65536
7711c0
+    refcount bits: 16
7711c0
+    corrupt: false
7711c0
+
7711c0
+The same bitmaps in JSON format:
7711c0
+[
7711c0
+  {
7711c0
+    "flags": [
7711c0
+      "in-use"
7711c0
+    ],
7711c0
+    "granularity": 32768,
7711c0
+    "name": "bitmap-1"
7711c0
+  },
7711c0
+  {
7711c0
+    "flags": [
7711c0
+      "in-use",
7711c0
+      "auto"
7711c0
+    ],
7711c0
+    "granularity": 65536,
7711c0
+    "name": "bitmap-2"
7711c0
+  }
7711c0
+]
7711c0
+
7711c0
+Test 5
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"disabled": false, "granularity": 16384, "name": "bitmap-0", "node": "drive0", "persistent": true}}
7711c0
+{"return": {}}
7711c0
+Write an unknown bitmap flag '0x4' into a new QCOW2 image at offset 327695
7711c0
+qemu-img: Could not open 'TEST_IMG': Bitmap 'bitmap-0' doesn't satisfy the constraints
7711c0
+
7711c0
+Unset the unknown bitmap flag '0x4' in the bitmap directory entry:
7711c0
+
7711c0
+image: TEST_IMG
7711c0
+file format: IMGFMT
7711c0
+virtual size: 1.0M (1048576 bytes)
7711c0
+cluster_size: 65536
7711c0
+Format specific information:
7711c0
+    compat: 1.1
7711c0
+    lazy refcounts: false
7711c0
+    bitmaps:
7711c0
+        [0]:
7711c0
+            flags:
7711c0
+                [0]: auto
7711c0
+            name: bitmap-0
7711c0
+            granularity: 16384
7711c0
+    refcount bits: 16
7711c0
+    corrupt: false
7711c0
+
7711c0
+Test complete
7711c0
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
7711c0
index 8662839..bee2855 100644
7711c0
--- a/tests/qemu-iotests/group
7711c0
+++ b/tests/qemu-iotests/group
7711c0
@@ -228,3 +228,4 @@
7711c0
 232 auto quick
7711c0
 234 auto quick migration
7711c0
 236 auto quick
7711c0
+242 rw auto quick
7711c0
-- 
7711c0
1.8.3.1
7711c0