From ff6e22d991a2681488c3c52b00dcf5289bf97bd3 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Mon, 16 Mar 2020 22:12:25 +0100 Subject: [PATCH] qemublocktest: Add tests for handling of bitmaps during block-commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Eric Blake (cherry picked from commit 77b9d574b41e79bbeb87ee0443dd60c4fde8a79a) https://bugzilla.redhat.com/show_bug.cgi?id=1799013 Message-Id: <551872a6e70f8136c2bd8e9f7be194b8f7091046.1584391727.git.pkrempa@redhat.com> Reviewed-by: Ján Tomko --- tests/qemublocktest.c | 95 ++++++++++++++ .../bitmapblockcommit/basic-1-2 | 119 ++++++++++++++++++ .../bitmapblockcommit/basic-1-3 | 119 ++++++++++++++++++ .../bitmapblockcommit/basic-2-3 | 2 + 4 files changed, 335 insertions(+) create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-1-2 create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-1-3 create mode 100644 tests/qemublocktestdata/bitmapblockcommit/basic-2-3 diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 6ccc2328b3..63ac80b584 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -665,6 +665,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 @@ -919,6 +934,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) @@ -933,6 +1010,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; @@ -1297,6 +1375,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 index 0000000000..8eeb4c3a11 --- /dev/null +++ b/tests/qemublocktestdata/bitmapblockcommit/basic-1-2 @@ -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 index 0000000000..71b48e31a5 --- /dev/null +++ b/tests/qemublocktestdata/bitmapblockcommit/basic-1-3 @@ -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 index 0000000000..bfc58f994e --- /dev/null +++ b/tests/qemublocktestdata/bitmapblockcommit/basic-2-3 @@ -0,0 +1,2 @@ +pre job bitmap disable: +merge bitmpas: -- 2.25.1