Blame SOURCES/libvirt-qemublocktest-Add-tests-for-handling-of-bitmaps-during-block-commit.patch

fbe740
From ff6e22d991a2681488c3c52b00dcf5289bf97bd3 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <ff6e22d991a2681488c3c52b00dcf5289bf97bd3@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:12:25 +0100
fbe740
Subject: [PATCH] qemublocktest: Add tests for handling of bitmaps during
fbe740
 block-commit
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Add code for testing the two necessary steps of handling bitmaps during
fbe740
block commit and exercise the code on the test data which we have for
fbe740
bitmap handling.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Eric Blake <eblake@redhat.com>
fbe740
(cherry picked from commit 77b9d574b41e79bbeb87ee0443dd60c4fde8a79a)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1799013
fbe740
Message-Id: <551872a6e70f8136c2bd8e9f7be194b8f7091046.1584391727.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 tests/qemublocktest.c                         |  95 ++++++++++++++
fbe740
 .../bitmapblockcommit/basic-1-2               | 119 ++++++++++++++++++
fbe740
 .../bitmapblockcommit/basic-1-3               | 119 ++++++++++++++++++
fbe740
 .../bitmapblockcommit/basic-2-3               |   2 +
fbe740
 4 files changed, 335 insertions(+)
fbe740
 create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-1-2
fbe740
 create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-1-3
fbe740
 create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-2-3
fbe740
fbe740
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
fbe740
index 6ccc2328b3..63ac80b584 100644
fbe740
--- a/tests/qemublocktest.c
fbe740
+++ b/tests/qemublocktest.c
fbe740
@@ -665,6 +665,21 @@ testQemuBackupIncrementalBitmapCalculateGetFakeChain(void)
fbe740
 }
fbe740
 
fbe740
 
fbe740
+static virStorageSourcePtr
fbe740
+testQemuBitmapGetFakeChainEntry(virStorageSourcePtr src,
fbe740
+                                size_t idx)
fbe740
+{
fbe740
+    virStorageSourcePtr n;
fbe740
+
fbe740
+    for (n = src; n; n = n->backingStore) {
fbe740
+        if (n->id == idx)
fbe740
+            return n;
fbe740
+    }
fbe740
+
fbe740
+    return NULL;
fbe740
+}
fbe740
+
fbe740
+
fbe740
 typedef virDomainMomentDefPtr testMomentList;
fbe740
 
fbe740
 static void
fbe740
@@ -919,6 +934,68 @@ testQemuBlockBitmapBlockcopy(const void *opaque)
fbe740
     return virTestCompareToFile(actual, expectpath);
fbe740
 }
fbe740
 
fbe740
+static const char *blockcommitPrefix = "qemublocktestdata/bitmapblockcommit/";
fbe740
+
fbe740
+struct testQemuBlockBitmapBlockcommitData {
fbe740
+    const char *name;
fbe740
+    virStorageSourcePtr top;
fbe740
+    virStorageSourcePtr base;
fbe740
+    virStorageSourcePtr chain;
fbe740
+    const char *nodedatafile;
fbe740
+};
fbe740
+
fbe740
+
fbe740
+static int
fbe740
+testQemuBlockBitmapBlockcommit(const void *opaque)
fbe740
+{
fbe740
+    const struct testQemuBlockBitmapBlockcommitData *data = opaque;
fbe740
+
fbe740
+    g_autofree char *actual = NULL;
fbe740
+    g_autofree char *expectpath = NULL;
fbe740
+    g_autoptr(virJSONValue) actionsDisable = NULL;
fbe740
+    g_autoptr(virJSONValue) actionsMerge = NULL;
fbe740
+    g_autoptr(virJSONValue) nodedatajson = NULL;
fbe740
+    g_autoptr(virHashTable) nodedata = NULL;
fbe740
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
fbe740
+    VIR_AUTOSTRINGLIST bitmapsDisable = NULL;
fbe740
+
fbe740
+    expectpath = g_strdup_printf("%s/%s%s", abs_srcdir,
fbe740
+                                 blockcommitPrefix, data->name);
fbe740
+
fbe740
+    if (!(nodedatajson = virTestLoadFileJSON(bitmapDetectPrefix, data->nodedatafile,
fbe740
+                                             ".json", NULL)))
fbe740
+        return -1;
fbe740
+
fbe740
+    if (!(nodedata = qemuMonitorJSONBlockGetNamedNodeDataJSON(nodedatajson))) {
fbe740
+        VIR_TEST_VERBOSE("failed to load nodedata JSON\n");
fbe740
+        return -1;
fbe740
+    }
fbe740
+
fbe740
+    if (qemuBlockBitmapsHandleCommitStart(data->top, data->base, nodedata,
fbe740
+                                          &actionsDisable, &bitmapsDisable) < 0)
fbe740
+        return -1;
fbe740
+
fbe740
+    virBufferAddLit(&buf, "pre job bitmap disable:\n");
fbe740
+
fbe740
+    if (actionsDisable &&
fbe740
+        virJSONValueToBuffer(actionsDisable, &buf, true) < 0)
fbe740
+        return -1;
fbe740
+
fbe740
+    virBufferAddLit(&buf, "merge bitmpas:\n");
fbe740
+
fbe740
+    if (qemuBlockBitmapsHandleCommitFinish(data->top, data->base, nodedata,
fbe740
+                                           &actionsMerge, bitmapsDisable) < 0)
fbe740
+        return -1;
fbe740
+
fbe740
+    if (actionsMerge &&
fbe740
+        virJSONValueToBuffer(actionsMerge, &buf, true) < 0)
fbe740
+        return -1;
fbe740
+
fbe740
+    actual = virBufferContentAndReset(&buf;;
fbe740
+
fbe740
+    return virTestCompareToFile(actual, expectpath);
fbe740
+}
fbe740
+
fbe740
 
fbe740
 static int
fbe740
 mymain(void)
fbe740
@@ -933,6 +1010,7 @@ mymain(void)
fbe740
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
fbe740
     struct testQemuBlockBitmapValidateData blockbitmapvalidatedata;
fbe740
     struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
fbe740
+    struct testQemuBlockBitmapBlockcommitData blockbitmapblockcommitdata;
fbe740
     char *capslatest_x86_64 = NULL;
fbe740
     virQEMUCapsPtr caps_x86_64 = NULL;
fbe740
     g_autoptr(virHashTable) qmp_schema_x86_64 = NULL;
fbe740
@@ -1297,6 +1375,23 @@ mymain(void)
fbe740
     TEST_BITMAP_BLOCKCOPY("snapshots-shallow", true, "snapshots");
fbe740
     TEST_BITMAP_BLOCKCOPY("snapshots-deep", false, "snapshots");
fbe740
 
fbe740
+
fbe740
+#define TEST_BITMAP_BLOCKCOMMIT(testname, topimg, baseimg, ndf) \
fbe740
+    do {\
fbe740
+        blockbitmapblockcommitdata.name = testname; \
fbe740
+        blockbitmapblockcommitdata.top = testQemuBitmapGetFakeChainEntry(bitmapSourceChain, topimg); \
fbe740
+        blockbitmapblockcommitdata.base = testQemuBitmapGetFakeChainEntry(bitmapSourceChain, baseimg); \
fbe740
+        blockbitmapblockcommitdata.nodedatafile = ndf; \
fbe740
+        if (virTestRun("bitmap block commit " testname, \
fbe740
+                       testQemuBlockBitmapBlockcommit, \
fbe740
+                       &blockbitmapblockcommitdata) < 0) \
fbe740
+        ret = -1; \
fbe740
+    } while (0)
fbe740
+
fbe740
+    TEST_BITMAP_BLOCKCOMMIT("basic-1-2", 1, 2, "basic");
fbe740
+    TEST_BITMAP_BLOCKCOMMIT("basic-1-3", 1, 3, "basic");
fbe740
+    TEST_BITMAP_BLOCKCOMMIT("basic-2-3", 2, 3, "basic");
fbe740
+
fbe740
  cleanup:
fbe740
     qemuTestDriverFree(&driver);
fbe740
     VIR_FREE(capslatest_x86_64);
fbe740
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-1-2 b/tests/qemublocktestdata/bitmapblockcommit/basic-1-2
fbe740
new file mode 100644
fbe740
index 0000000000..8eeb4c3a11
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/bitmapblockcommit/basic-1-2
fbe740
@@ -0,0 +1,119 @@
fbe740
+pre job bitmap disable:
fbe740
+merge bitmpas:
fbe740
+[
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "name": "a",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "target": "a",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "a"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "name": "b",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "target": "b",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "b"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "name": "current",
fbe740
+      "persistent": true,
fbe740
+      "disabled": false,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "target": "current",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "current"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "name": "c",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "target": "c",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "c"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "name": "d",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-2-format",
fbe740
+      "target": "d",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "d"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  }
fbe740
+]
fbe740
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-1-3 b/tests/qemublocktestdata/bitmapblockcommit/basic-1-3
fbe740
new file mode 100644
fbe740
index 0000000000..71b48e31a5
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/bitmapblockcommit/basic-1-3
fbe740
@@ -0,0 +1,119 @@
fbe740
+pre job bitmap disable:
fbe740
+merge bitmpas:
fbe740
+[
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "name": "a",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "target": "a",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "a"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "name": "b",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "target": "b",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "b"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "name": "current",
fbe740
+      "persistent": true,
fbe740
+      "disabled": false,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "target": "current",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "current"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "name": "c",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "target": "c",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "c"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-add",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "name": "d",
fbe740
+      "persistent": true,
fbe740
+      "disabled": true,
fbe740
+      "granularity": 65536
fbe740
+    }
fbe740
+  },
fbe740
+  {
fbe740
+    "type": "block-dirty-bitmap-merge",
fbe740
+    "data": {
fbe740
+      "node": "libvirt-3-format",
fbe740
+      "target": "d",
fbe740
+      "bitmaps": [
fbe740
+        {
fbe740
+          "node": "libvirt-1-format",
fbe740
+          "name": "d"
fbe740
+        }
fbe740
+      ]
fbe740
+    }
fbe740
+  }
fbe740
+]
fbe740
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-2-3 b/tests/qemublocktestdata/bitmapblockcommit/basic-2-3
fbe740
new file mode 100644
fbe740
index 0000000000..bfc58f994e
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/bitmapblockcommit/basic-2-3
fbe740
@@ -0,0 +1,2 @@
fbe740
+pre job bitmap disable:
fbe740
+merge bitmpas:
fbe740
-- 
fbe740
2.25.1
fbe740