|
|
404507 |
From cfbc47467f2174875f63493458a2f350ec21b65d Mon Sep 17 00:00:00 2001
|
|
|
404507 |
Message-Id: <cfbc47467f2174875f63493458a2f350ec21b65d@dist-git>
|
|
|
404507 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
Date: Wed, 31 Jan 2018 16:32:15 +0100
|
|
|
404507 |
Subject: [PATCH] util: Reintroduce virBitmapSubtract
|
|
|
404507 |
|
|
|
404507 |
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
|
|
|
404507 |
|
|
|
404507 |
Already introduced in the past with 9479642fd3c5, but then renamed to
|
|
|
404507 |
virBitmapIntersect by a908e9e45eb2. This time we'll really use it.
|
|
|
404507 |
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
Reviewed-by: John Ferlan <jferlan@redhat.com>
|
|
|
404507 |
(cherry picked from commit 449442c34d20753ca57852d9d7957dd7ba868fae)
|
|
|
404507 |
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
|
|
|
404507 |
---
|
|
|
404507 |
src/libvirt_private.syms | 1 +
|
|
|
404507 |
src/util/virbitmap.c | 22 ++++++++++++++++++++++
|
|
|
404507 |
src/util/virbitmap.h | 3 +++
|
|
|
404507 |
tests/virbitmaptest.c | 42 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
404507 |
4 files changed, 68 insertions(+)
|
|
|
404507 |
|
|
|
404507 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
404507 |
index 1d895a3bf6..8cc8cbcc90 100644
|
|
|
404507 |
--- a/src/libvirt_private.syms
|
|
|
404507 |
+++ b/src/libvirt_private.syms
|
|
|
404507 |
@@ -1383,6 +1383,7 @@ virBitmapSetAll;
|
|
|
404507 |
virBitmapSetBit;
|
|
|
404507 |
virBitmapSetBitExpand;
|
|
|
404507 |
virBitmapSize;
|
|
|
404507 |
+virBitmapSubtract;
|
|
|
404507 |
virBitmapToData;
|
|
|
404507 |
virBitmapToDataBuf;
|
|
|
404507 |
virBitmapToString;
|
|
|
404507 |
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
|
|
|
404507 |
index 47d16ee222..7338f0255a 100644
|
|
|
404507 |
--- a/src/util/virbitmap.c
|
|
|
404507 |
+++ b/src/util/virbitmap.c
|
|
|
404507 |
@@ -1174,3 +1174,25 @@ virBitmapIntersect(virBitmapPtr a,
|
|
|
404507 |
for (i = 0; i < max; i++)
|
|
|
404507 |
a->map[i] &= b->map[i];
|
|
|
404507 |
}
|
|
|
404507 |
+
|
|
|
404507 |
+
|
|
|
404507 |
+/**
|
|
|
404507 |
+ * virBitmapSubtract:
|
|
|
404507 |
+ * @a: minuend/result
|
|
|
404507 |
+ * @b: subtrahend
|
|
|
404507 |
+ *
|
|
|
404507 |
+ * Performs subtraction of two bitmaps: a = a - b
|
|
|
404507 |
+ */
|
|
|
404507 |
+void
|
|
|
404507 |
+virBitmapSubtract(virBitmapPtr a,
|
|
|
404507 |
+ virBitmapPtr b)
|
|
|
404507 |
+{
|
|
|
404507 |
+ size_t i;
|
|
|
404507 |
+ size_t max = a->map_len;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (max > b->map_len)
|
|
|
404507 |
+ max = b->map_len;
|
|
|
404507 |
+
|
|
|
404507 |
+ for (i = 0; i < max; i++)
|
|
|
404507 |
+ a->map[i] &= ~b->map[i];
|
|
|
404507 |
+}
|
|
|
404507 |
diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h
|
|
|
404507 |
index e964a3edc9..7b2bea8b53 100644
|
|
|
404507 |
--- a/src/util/virbitmap.h
|
|
|
404507 |
+++ b/src/util/virbitmap.h
|
|
|
404507 |
@@ -150,4 +150,7 @@ bool virBitmapOverlaps(virBitmapPtr b1,
|
|
|
404507 |
void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b)
|
|
|
404507 |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
404507 |
|
|
|
404507 |
+void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b)
|
|
|
404507 |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
404507 |
+
|
|
|
404507 |
#endif
|
|
|
404507 |
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
|
|
|
404507 |
index 9daa8316f3..5bf30b2b1c 100644
|
|
|
404507 |
--- a/tests/virbitmaptest.c
|
|
|
404507 |
+++ b/tests/virbitmaptest.c
|
|
|
404507 |
@@ -701,6 +701,39 @@ test13(const void *opaque ATTRIBUTE_UNUSED)
|
|
|
404507 |
|
|
|
404507 |
#undef TEST_MAP
|
|
|
404507 |
|
|
|
404507 |
+static int
|
|
|
404507 |
+test14(const void *opaque)
|
|
|
404507 |
+{
|
|
|
404507 |
+ const struct testBinaryOpData *data = opaque;
|
|
|
404507 |
+ virBitmapPtr amap = NULL;
|
|
|
404507 |
+ virBitmapPtr bmap = NULL;
|
|
|
404507 |
+ virBitmapPtr resmap = NULL;
|
|
|
404507 |
+ int ret = -1;
|
|
|
404507 |
+
|
|
|
404507 |
+ if (virBitmapParse(data->a, &amap, 256) < 0 ||
|
|
|
404507 |
+ virBitmapParse(data->b, &bmap, 256) < 0 ||
|
|
|
404507 |
+ virBitmapParse(data->res, &resmap, 256) < 0)
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
+
|
|
|
404507 |
+ virBitmapSubtract(amap, bmap);
|
|
|
404507 |
+
|
|
|
404507 |
+ if (!virBitmapEqual(amap, resmap)) {
|
|
|
404507 |
+ fprintf(stderr,
|
|
|
404507 |
+ "\n bitmap subtraction failed: '%s' - '%s' != '%s'\n",
|
|
|
404507 |
+ data->a, data->b, data->res);
|
|
|
404507 |
+ goto cleanup;
|
|
|
404507 |
+ }
|
|
|
404507 |
+
|
|
|
404507 |
+ ret = 0;
|
|
|
404507 |
+
|
|
|
404507 |
+ cleanup:
|
|
|
404507 |
+ virBitmapFree(amap);
|
|
|
404507 |
+ virBitmapFree(bmap);
|
|
|
404507 |
+ virBitmapFree(resmap);
|
|
|
404507 |
+
|
|
|
404507 |
+ return ret;
|
|
|
404507 |
+}
|
|
|
404507 |
+
|
|
|
404507 |
|
|
|
404507 |
#define TESTBINARYOP(A, B, RES, FUNC) \
|
|
|
404507 |
testBinaryOpData.a = A; \
|
|
|
404507 |
@@ -750,6 +783,15 @@ mymain(void)
|
|
|
404507 |
if (virTestRun("test13", test13, NULL) < 0)
|
|
|
404507 |
ret = -1;
|
|
|
404507 |
|
|
|
404507 |
+ virTestCounterReset("test14-");
|
|
|
404507 |
+ TESTBINARYOP("0", "0", "0,^0", test14);
|
|
|
404507 |
+ TESTBINARYOP("0-3", "0", "1-3", test14);
|
|
|
404507 |
+ TESTBINARYOP("0-3", "0,3", "1-2", test14);
|
|
|
404507 |
+ TESTBINARYOP("0,^0", "0", "0,^0", test14);
|
|
|
404507 |
+ TESTBINARYOP("0-3", "0-3", "0,^0", test14);
|
|
|
404507 |
+ TESTBINARYOP("0-3", "0,^0", "0-3", test14);
|
|
|
404507 |
+ TESTBINARYOP("0,2", "1,3", "0,2", test14);
|
|
|
404507 |
+
|
|
|
404507 |
return ret;
|
|
|
404507 |
}
|
|
|
404507 |
|
|
|
404507 |
--
|
|
|
404507 |
2.16.1
|
|
|
404507 |
|