]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemublocktest: Add tests for handling of bitmaps during block-commit
authorPeter Krempa <pkrempa@redhat.com>
Mon, 2 Mar 2020 16:16:17 +0000 (17:16 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 16:33:08 +0000 (17:33 +0100)
Add code for testing the two necessary steps of handling bitmaps during
block commit and exercise the code on the test data which we have for
bitmap handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
tests/qemublocktest.c
tests/qemublocktestdata/bitmapblockcommit/basic-1-2 [new file with mode: 0644]
tests/qemublocktestdata/bitmapblockcommit/basic-1-3 [new file with mode: 0644]
tests/qemublocktestdata/bitmapblockcommit/basic-2-3 [new file with mode: 0644]

index fa1ccc7e85d15b64f7fd3846b0b6cc966f42e31e..98c2416200ba94aac961c5106e3d00f811ff9929 100644 (file)
@@ -669,6 +669,21 @@ testQemuBackupIncrementalBitmapCalculateGetFakeChain(void)
 }
 
 
+static virStorageSourcePtr
+testQemuBitmapGetFakeChainEntry(virStorageSourcePtr src,
+                                size_t idx)
+{
+    virStorageSourcePtr n;
+
+    for (n = src; n; n = n->backingStore) {
+        if (n->id == idx)
+            return n;
+    }
+
+    return NULL;
+}
+
+
 typedef virDomainMomentDefPtr testMomentList;
 
 static void
@@ -923,6 +938,68 @@ testQemuBlockBitmapBlockcopy(const void *opaque)
     return virTestCompareToFile(actual, expectpath);
 }
 
+static const char *blockcommitPrefix = "qemublocktestdata/bitmapblockcommit/";
+
+struct testQemuBlockBitmapBlockcommitData {
+    const char *name;
+    virStorageSourcePtr top;
+    virStorageSourcePtr base;
+    virStorageSourcePtr chain;
+    const char *nodedatafile;
+};
+
+
+static int
+testQemuBlockBitmapBlockcommit(const void *opaque)
+{
+    const struct testQemuBlockBitmapBlockcommitData *data = opaque;
+
+    g_autofree char *actual = NULL;
+    g_autofree char *expectpath = NULL;
+    g_autoptr(virJSONValue) actionsDisable = NULL;
+    g_autoptr(virJSONValue) actionsMerge = NULL;
+    g_autoptr(virJSONValue) nodedatajson = NULL;
+    g_autoptr(virHashTable) nodedata = NULL;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    VIR_AUTOSTRINGLIST bitmapsDisable = NULL;
+
+    expectpath = g_strdup_printf("%s/%s%s", abs_srcdir,
+                                 blockcommitPrefix, data->name);
+
+    if (!(nodedatajson = virTestLoadFileJSON(bitmapDetectPrefix, data->nodedatafile,
+                                             ".json", NULL)))
+        return -1;
+
+    if (!(nodedata = qemuMonitorJSONBlockGetNamedNodeDataJSON(nodedatajson))) {
+        VIR_TEST_VERBOSE("failed to load nodedata JSON\n");
+        return -1;
+    }
+
+    if (qemuBlockBitmapsHandleCommitStart(data->top, data->base, nodedata,
+                                          &actionsDisable, &bitmapsDisable) < 0)
+        return -1;
+
+    virBufferAddLit(&buf, "pre job bitmap disable:\n");
+
+    if (actionsDisable &&
+        virJSONValueToBuffer(actionsDisable, &buf, true) < 0)
+        return -1;
+
+    virBufferAddLit(&buf, "merge bitmpas:\n");
+
+    if (qemuBlockBitmapsHandleCommitFinish(data->top, data->base, nodedata,
+                                           &actionsMerge, bitmapsDisable) < 0)
+        return -1;
+
+    if (actionsMerge &&
+        virJSONValueToBuffer(actionsMerge, &buf, true) < 0)
+        return -1;
+
+    actual = virBufferContentAndReset(&buf);
+
+    return virTestCompareToFile(actual, expectpath);
+}
+
 
 static int
 mymain(void)
@@ -937,6 +1014,7 @@ mymain(void)
     struct testQemuCheckpointDeleteMergeData checkpointdeletedata;
     struct testQemuBlockBitmapValidateData blockbitmapvalidatedata;
     struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
+    struct testQemuBlockBitmapBlockcommitData blockbitmapblockcommitdata;
     char *capslatest_x86_64 = NULL;
     virQEMUCapsPtr caps_x86_64 = NULL;
     g_autoptr(virHashTable) qmp_schema_x86_64 = NULL;
@@ -1301,6 +1379,23 @@ mymain(void)
     TEST_BITMAP_BLOCKCOPY("snapshots-shallow", true, "snapshots");
     TEST_BITMAP_BLOCKCOPY("snapshots-deep", false, "snapshots");
 
+
+#define TEST_BITMAP_BLOCKCOMMIT(testname, topimg, baseimg, ndf) \
+    do {\
+        blockbitmapblockcommitdata.name = testname; \
+        blockbitmapblockcommitdata.top = testQemuBitmapGetFakeChainEntry(bitmapSourceChain, topimg); \
+        blockbitmapblockcommitdata.base = testQemuBitmapGetFakeChainEntry(bitmapSourceChain, baseimg); \
+        blockbitmapblockcommitdata.nodedatafile = ndf; \
+        if (virTestRun("bitmap block commit " testname, \
+                       testQemuBlockBitmapBlockcommit, \
+                       &blockbitmapblockcommitdata) < 0) \
+        ret = -1; \
+    } while (0)
+
+    TEST_BITMAP_BLOCKCOMMIT("basic-1-2", 1, 2, "basic");
+    TEST_BITMAP_BLOCKCOMMIT("basic-1-3", 1, 3, "basic");
+    TEST_BITMAP_BLOCKCOMMIT("basic-2-3", 2, 3, "basic");
+
  cleanup:
     qemuTestDriverFree(&driver);
     VIR_FREE(capslatest_x86_64);
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-1-2 b/tests/qemublocktestdata/bitmapblockcommit/basic-1-2
new file mode 100644 (file)
index 0000000..8eeb4c3
--- /dev/null
@@ -0,0 +1,119 @@
+pre job bitmap disable:
+merge bitmpas:
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-2-format",
+      "name": "a",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-2-format",
+      "target": "a",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "a"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-2-format",
+      "name": "b",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-2-format",
+      "target": "b",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "b"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-2-format",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-2-format",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-2-format",
+      "name": "c",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-2-format",
+      "target": "c",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "c"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-2-format",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-2-format",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-1-3 b/tests/qemublocktestdata/bitmapblockcommit/basic-1-3
new file mode 100644 (file)
index 0000000..71b48e3
--- /dev/null
@@ -0,0 +1,119 @@
+pre job bitmap disable:
+merge bitmpas:
+[
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-3-format",
+      "name": "a",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-3-format",
+      "target": "a",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "a"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-3-format",
+      "name": "b",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-3-format",
+      "target": "b",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "b"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-3-format",
+      "name": "current",
+      "persistent": true,
+      "disabled": false,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-3-format",
+      "target": "current",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "current"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-3-format",
+      "name": "c",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-3-format",
+      "target": "c",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "c"
+        }
+      ]
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-add",
+    "data": {
+      "node": "libvirt-3-format",
+      "name": "d",
+      "persistent": true,
+      "disabled": true,
+      "granularity": 65536
+    }
+  },
+  {
+    "type": "block-dirty-bitmap-merge",
+    "data": {
+      "node": "libvirt-3-format",
+      "target": "d",
+      "bitmaps": [
+        {
+          "node": "libvirt-1-format",
+          "name": "d"
+        }
+      ]
+    }
+  }
+]
diff --git a/tests/qemublocktestdata/bitmapblockcommit/basic-2-3 b/tests/qemublocktestdata/bitmapblockcommit/basic-2-3
new file mode 100644 (file)
index 0000000..bfc58f9
--- /dev/null
@@ -0,0 +1,2 @@
+pre job bitmap disable:
+merge bitmpas: