Blame SOURCES/kvm-iotests-add-iotest-236-for-testing-bitmap-merge.patch

7711c0
From 85a2175420c8c79bf947f1f2af3d544548098b6e Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 20 Mar 2019 16:16:24 +0100
7711c0
Subject: [PATCH 026/163] iotests: add iotest 236 for testing bitmap merge
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190320161631.14841-13-jsnow@redhat.com>
7711c0
Patchwork-id: 84950
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 12/19] iotests: add iotest 236 for testing bitmap merge
7711c0
Bugzilla: 1668956
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
New interface, new smoke test.
7711c0
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
Reviewed-by: Eric Blake <eblake@redhat.com>
7711c0
Message-Id: <20181221093529.23855-12-jsnow@redhat.com>
7711c0
[eblake: fix last-minute change to echo text]
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
(cherry picked from commit 14da540f2a68b3f730b1a7c31de783f3d68f6fc7)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 tests/qemu-iotests/236     | 161 +++++++++++++++++++++
7711c0
 tests/qemu-iotests/236.out | 351 +++++++++++++++++++++++++++++++++++++++++++++
7711c0
 tests/qemu-iotests/group   |   1 +
7711c0
 3 files changed, 513 insertions(+)
7711c0
 create mode 100755 tests/qemu-iotests/236
7711c0
 create mode 100644 tests/qemu-iotests/236.out
7711c0
7711c0
diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236
7711c0
new file mode 100755
7711c0
index 0000000..79a6381
7711c0
--- /dev/null
7711c0
+++ b/tests/qemu-iotests/236
7711c0
@@ -0,0 +1,161 @@
7711c0
+#!/usr/bin/env python
7711c0
+#
7711c0
+# Test bitmap merges.
7711c0
+#
7711c0
+# Copyright (c) 2018 John Snow for Red Hat, Inc.
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
+# owner=jsnow@redhat.com
7711c0
+
7711c0
+import iotests
7711c0
+from iotests import log
7711c0
+
7711c0
+iotests.verify_image_format(supported_fmts=['generic'])
7711c0
+size = 64 * 1024 * 1024
7711c0
+granularity = 64 * 1024
7711c0
+
7711c0
+patterns = [("0x5d", "0",         "64k"),
7711c0
+            ("0xd5", "1M",        "64k"),
7711c0
+            ("0xdc", "32M",       "64k"),
7711c0
+            ("0xcd", "0x3ff0000", "64k")]  # 64M - 64K
7711c0
+
7711c0
+overwrite = [("0xab", "0",         "64k"), # Full overwrite
7711c0
+             ("0xad", "0x00f8000", "64k"), # Partial-left (1M-32K)
7711c0
+             ("0x1d", "0x2008000", "64k"), # Partial-right (32M+32K)
7711c0
+             ("0xea", "0x3fe0000", "64k")] # Adjacent-left (64M - 128K)
7711c0
+
7711c0
+def query_bitmaps(vm):
7711c0
+    res = vm.qmp("query-block")
7711c0
+    return { "bitmaps": { device['device']: device.get('dirty-bitmaps', []) for
7711c0
+                          device in res['return'] } }
7711c0
+
7711c0
+with iotests.FilePath('img') as img_path, \
7711c0
+     iotests.VM() as vm:
7711c0
+
7711c0
+    log('--- Preparing image & VM ---\n')
7711c0
+    iotests.qemu_img_create('-f', iotests.imgfmt, img_path, str(size))
7711c0
+    vm.add_drive(img_path)
7711c0
+    vm.launch()
7711c0
+
7711c0
+    log('\n--- Adding preliminary bitmaps A & B ---\n')
7711c0
+    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
7711c0
+               name="bitmapA", granularity=granularity)
7711c0
+    vm.qmp_log("block-dirty-bitmap-add", node="drive0",
7711c0
+               name="bitmapB", granularity=granularity)
7711c0
+
7711c0
+    # Dirties 4 clusters. count=262144
7711c0
+    log('\n--- Emulating writes ---\n')
7711c0
+    for p in patterns:
7711c0
+        cmd = "write -P%s %s %s" % p
7711c0
+        log(cmd)
7711c0
+        log(vm.hmp_qemu_io("drive0", cmd))
7711c0
+
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    log('\n--- Submitting & Aborting Transaction ---\n')
7711c0
+    vm.qmp_log("transaction", indent=2, actions=[
7711c0
+        { "type": "block-dirty-bitmap-disable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapB" }},
7711c0
+        { "type": "block-dirty-bitmap-add",
7711c0
+          "data": { "node": "drive0", "name": "bitmapC",
7711c0
+                    "granularity": granularity }},
7711c0
+        { "type": "block-dirty-bitmap-clear",
7711c0
+          "data": { "node": "drive0", "name": "bitmapA" }},
7711c0
+        { "type": "abort", "data": {}}
7711c0
+    ])
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    log('\n--- Disabling B & Adding C ---\n')
7711c0
+    vm.qmp_log("transaction", indent=2, actions=[
7711c0
+        { "type": "block-dirty-bitmap-disable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapB" }},
7711c0
+        { "type": "block-dirty-bitmap-add",
7711c0
+          "data": { "node": "drive0", "name": "bitmapC",
7711c0
+                    "granularity": granularity }},
7711c0
+        # Purely extraneous, but test that it works:
7711c0
+        { "type": "block-dirty-bitmap-disable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapC" }},
7711c0
+        { "type": "block-dirty-bitmap-enable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapC" }},
7711c0
+    ])
7711c0
+
7711c0
+    log('\n--- Emulating further writes ---\n')
7711c0
+    # Dirties 6 clusters, 3 of which are new in contrast to "A".
7711c0
+    # A = 64 * 1024 * (4 + 3) = 458752
7711c0
+    # C = 64 * 1024 * 6       = 393216
7711c0
+    for p in overwrite:
7711c0
+        cmd = "write -P%s %s %s" % p
7711c0
+        log(cmd)
7711c0
+        log(vm.hmp_qemu_io("drive0", cmd))
7711c0
+
7711c0
+    log('\n--- Disabling A & C ---\n')
7711c0
+    vm.qmp_log("transaction", indent=2, actions=[
7711c0
+        { "type": "block-dirty-bitmap-disable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapA" }},
7711c0
+        { "type": "block-dirty-bitmap-disable",
7711c0
+          "data": { "node": "drive0", "name": "bitmapC" }}
7711c0
+    ])
7711c0
+
7711c0
+    # A: 7 clusters
7711c0
+    # B: 4 clusters
7711c0
+    # C: 6 clusters
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    log('\n--- Submitting & Aborting Merge Transaction ---\n')
7711c0
+    vm.qmp_log("transaction", indent=2, actions=[
7711c0
+        { "type": "block-dirty-bitmap-add",
7711c0
+          "data": { "node": "drive0", "name": "bitmapD",
7711c0
+                    "disabled": True, "granularity": granularity }},
7711c0
+        { "type": "block-dirty-bitmap-merge",
7711c0
+          "data": { "node": "drive0", "target": "bitmapD",
7711c0
+                    "bitmaps": ["bitmapB", "bitmapC"] }},
7711c0
+        { "type": "abort", "data": {}}
7711c0
+    ])
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    log('\n--- Creating D as a merge of B & C ---\n')
7711c0
+    # Good hygiene: create a disabled bitmap as a merge target.
7711c0
+    vm.qmp_log("transaction", indent=2, actions=[
7711c0
+        { "type": "block-dirty-bitmap-add",
7711c0
+          "data": { "node": "drive0", "name": "bitmapD",
7711c0
+                    "disabled": True, "granularity": granularity }},
7711c0
+        { "type": "block-dirty-bitmap-merge",
7711c0
+          "data": { "node": "drive0", "target": "bitmapD",
7711c0
+                    "bitmaps": ["bitmapB", "bitmapC"] }}
7711c0
+    ])
7711c0
+
7711c0
+    # A and D should now both have 7 clusters apiece.
7711c0
+    # B and C remain unchanged with 4 and 6 respectively.
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    # A and D should be equivalent.
7711c0
+    # Some formats round the size of the disk, so don't print the checksums.
7711c0
+    check_a = vm.qmp('x-debug-block-dirty-bitmap-sha256',
7711c0
+                     node="drive0", name="bitmapA")['return']['sha256']
7711c0
+    check_d = vm.qmp('x-debug-block-dirty-bitmap-sha256',
7711c0
+                     node="drive0", name="bitmapD")['return']['sha256']
7711c0
+    assert(check_a == check_d)
7711c0
+
7711c0
+    log('\n--- Removing bitmaps A, B, C, and D ---\n')
7711c0
+    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="bitmapA")
7711c0
+    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="bitmapB")
7711c0
+    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="bitmapC")
7711c0
+    vm.qmp_log("block-dirty-bitmap-remove", node="drive0", name="bitmapD")
7711c0
+
7711c0
+    log('\n--- Final Query ---\n')
7711c0
+    log(query_bitmaps(vm), indent=2)
7711c0
+
7711c0
+    log('\n--- Done ---\n')
7711c0
+    vm.shutdown()
7711c0
diff --git a/tests/qemu-iotests/236.out b/tests/qemu-iotests/236.out
7711c0
new file mode 100644
7711c0
index 0000000..1dad24d
7711c0
--- /dev/null
7711c0
+++ b/tests/qemu-iotests/236.out
7711c0
@@ -0,0 +1,351 @@
7711c0
+--- Preparing image & VM ---
7711c0
+
7711c0
+
7711c0
+--- Adding preliminary bitmaps A & B ---
7711c0
+
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmapA", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+{"execute": "block-dirty-bitmap-add", "arguments": {"granularity": 65536, "name": "bitmapB", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+
7711c0
+--- Emulating writes ---
7711c0
+
7711c0
+write -P0x5d 0 64k
7711c0
+{"return": ""}
7711c0
+write -P0xd5 1M 64k
7711c0
+{"return": ""}
7711c0
+write -P0xdc 32M 64k
7711c0
+{"return": ""}
7711c0
+write -P0xcd 0x3ff0000 64k
7711c0
+{"return": ""}
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": [
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapB",
7711c0
+        "status": "active"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapA",
7711c0
+        "status": "active"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Submitting & Aborting Transaction ---
7711c0
+
7711c0
+{
7711c0
+  "execute": "transaction",
7711c0
+  "arguments": {
7711c0
+    "actions": [
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapB"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-disable"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapC",
7711c0
+          "granularity": 65536
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-add"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapA"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-clear"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {},
7711c0
+        "type": "abort"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "error": {
7711c0
+    "class": "GenericError",
7711c0
+    "desc": "Transaction aborted using Abort action"
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": [
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapB",
7711c0
+        "status": "active"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapA",
7711c0
+        "status": "active"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Disabling B & Adding C ---
7711c0
+
7711c0
+{
7711c0
+  "execute": "transaction",
7711c0
+  "arguments": {
7711c0
+    "actions": [
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapB"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-disable"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapC",
7711c0
+          "granularity": 65536
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-add"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapC"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-disable"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapC"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-enable"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "return": {}
7711c0
+}
7711c0
+
7711c0
+--- Emulating further writes ---
7711c0
+
7711c0
+write -P0xab 0 64k
7711c0
+{"return": ""}
7711c0
+write -P0xad 0x00f8000 64k
7711c0
+{"return": ""}
7711c0
+write -P0x1d 0x2008000 64k
7711c0
+{"return": ""}
7711c0
+write -P0xea 0x3fe0000 64k
7711c0
+{"return": ""}
7711c0
+
7711c0
+--- Disabling A & C ---
7711c0
+
7711c0
+{
7711c0
+  "execute": "transaction",
7711c0
+  "arguments": {
7711c0
+    "actions": [
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapA"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-disable"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "name": "bitmapC"
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-disable"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "return": {}
7711c0
+}
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": [
7711c0
+      {
7711c0
+        "count": 393216,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapC",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapB",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 458752,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapA",
7711c0
+        "status": "disabled"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Submitting & Aborting Merge Transaction ---
7711c0
+
7711c0
+{
7711c0
+  "execute": "transaction",
7711c0
+  "arguments": {
7711c0
+    "actions": [
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "disabled": true,
7711c0
+          "name": "bitmapD",
7711c0
+          "granularity": 65536
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-add"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "target": "bitmapD",
7711c0
+          "bitmaps": [
7711c0
+            "bitmapB",
7711c0
+            "bitmapC"
7711c0
+          ]
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-merge"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {},
7711c0
+        "type": "abort"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "error": {
7711c0
+    "class": "GenericError",
7711c0
+    "desc": "Transaction aborted using Abort action"
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": [
7711c0
+      {
7711c0
+        "count": 393216,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapC",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapB",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 458752,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapA",
7711c0
+        "status": "disabled"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Creating D as a merge of B & C ---
7711c0
+
7711c0
+{
7711c0
+  "execute": "transaction",
7711c0
+  "arguments": {
7711c0
+    "actions": [
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "disabled": true,
7711c0
+          "name": "bitmapD",
7711c0
+          "granularity": 65536
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-add"
7711c0
+      },
7711c0
+      {
7711c0
+        "data": {
7711c0
+          "node": "drive0",
7711c0
+          "target": "bitmapD",
7711c0
+          "bitmaps": [
7711c0
+            "bitmapB",
7711c0
+            "bitmapC"
7711c0
+          ]
7711c0
+        },
7711c0
+        "type": "block-dirty-bitmap-merge"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+{
7711c0
+  "return": {}
7711c0
+}
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": [
7711c0
+      {
7711c0
+        "count": 458752,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapD",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 393216,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapC",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 262144,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapB",
7711c0
+        "status": "disabled"
7711c0
+      },
7711c0
+      {
7711c0
+        "count": 458752,
7711c0
+        "granularity": 65536,
7711c0
+        "name": "bitmapA",
7711c0
+        "status": "disabled"
7711c0
+      }
7711c0
+    ]
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Removing bitmaps A, B, C, and D ---
7711c0
+
7711c0
+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmapA", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmapB", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmapC", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmapD", "node": "drive0"}}
7711c0
+{"return": {}}
7711c0
+
7711c0
+--- Final Query ---
7711c0
+
7711c0
+{
7711c0
+  "bitmaps": {
7711c0
+    "drive0": []
7711c0
+  }
7711c0
+}
7711c0
+
7711c0
+--- Done ---
7711c0
+
7711c0
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
7711c0
index 0998dcd..8662839 100644
7711c0
--- a/tests/qemu-iotests/group
7711c0
+++ b/tests/qemu-iotests/group
7711c0
@@ -227,3 +227,4 @@
7711c0
 231 auto quick
7711c0
 232 auto quick
7711c0
 234 auto quick migration
7711c0
+236 auto quick
7711c0
-- 
7711c0
1.8.3.1
7711c0