render / rpms / libvirt

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