render / rpms / libvirt

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