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

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