|
|
c313de |
From 6ee2c599db989189e639c3de88d20045c62a1d2c Mon Sep 17 00:00:00 2001
|
|
|
c313de |
Message-Id: <6ee2c599db989189e639c3de88d20045c62a1d2c@dist-git>
|
|
|
c313de |
From: Andrea Bolognani <abologna@redhat.com>
|
|
|
c313de |
Date: Tue, 11 Jun 2019 10:55:01 +0200
|
|
|
c313de |
Subject: [PATCH] util: Introduce virBitmapUnion()
|
|
|
c313de |
MIME-Version: 1.0
|
|
|
c313de |
Content-Type: text/plain; charset=UTF-8
|
|
|
c313de |
Content-Transfer-Encoding: 8bit
|
|
|
c313de |
|
|
|
c313de |
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
c313de |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c313de |
(cherry picked from commit 1b2ac8010cc1fe871f538b3f48c5e48213c5c074)
|
|
|
c313de |
|
|
|
c313de |
https://bugzilla.redhat.com/show_bug.cgi?id=1716908
|
|
|
c313de |
|
|
|
c313de |
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
c313de |
Message-Id: <20190611085506.12564-2-abologna@redhat.com>
|
|
|
c313de |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
c313de |
---
|
|
|
c313de |
src/libvirt_private.syms | 1 +
|
|
|
c313de |
src/util/virbitmap.c | 27 +++++++++++++++++++++++++++
|
|
|
c313de |
src/util/virbitmap.h | 4 ++++
|
|
|
c313de |
tests/virbitmaptest.c | 38 ++++++++++++++++++++++++++++++++++++++
|
|
|
c313de |
4 files changed, 70 insertions(+)
|
|
|
c313de |
|
|
|
c313de |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
c313de |
index ee7625b0f3..05c96c29e2 100644
|
|
|
c313de |
--- a/src/libvirt_private.syms
|
|
|
c313de |
+++ b/src/libvirt_private.syms
|
|
|
c313de |
@@ -1476,6 +1476,7 @@ virBitmapSubtract;
|
|
|
c313de |
virBitmapToData;
|
|
|
c313de |
virBitmapToDataBuf;
|
|
|
c313de |
virBitmapToString;
|
|
|
c313de |
+virBitmapUnion;
|
|
|
c313de |
|
|
|
c313de |
|
|
|
c313de |
# util/virbuffer.h
|
|
|
c313de |
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
|
|
|
c313de |
index ef18dad255..49e542a4e6 100644
|
|
|
c313de |
--- a/src/util/virbitmap.c
|
|
|
c313de |
+++ b/src/util/virbitmap.c
|
|
|
c313de |
@@ -1265,6 +1265,33 @@ virBitmapIntersect(virBitmapPtr a,
|
|
|
c313de |
}
|
|
|
c313de |
|
|
|
c313de |
|
|
|
c313de |
+/**
|
|
|
c313de |
+ * virBitmapUnion:
|
|
|
c313de |
+ * @a: bitmap, modified to contain result
|
|
|
c313de |
+ * @b: other bitmap
|
|
|
c313de |
+ *
|
|
|
c313de |
+ * Performs union of two bitmaps: a = union(a, b)
|
|
|
c313de |
+ *
|
|
|
c313de |
+ * Returns 0 on success, <0 on failure.
|
|
|
c313de |
+ */
|
|
|
c313de |
+int
|
|
|
c313de |
+virBitmapUnion(virBitmapPtr a,
|
|
|
c313de |
+ const virBitmap *b)
|
|
|
c313de |
+{
|
|
|
c313de |
+ size_t i;
|
|
|
c313de |
+
|
|
|
c313de |
+ if (a->nbits < b->nbits &&
|
|
|
c313de |
+ virBitmapExpand(a, b->nbits - 1) < 0) {
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+ }
|
|
|
c313de |
+
|
|
|
c313de |
+ for (i = 0; i < b->map_len; i++)
|
|
|
c313de |
+ a->map[i] |= b->map[i];
|
|
|
c313de |
+
|
|
|
c313de |
+ return 0;
|
|
|
c313de |
+}
|
|
|
c313de |
+
|
|
|
c313de |
+
|
|
|
c313de |
/**
|
|
|
c313de |
* virBitmapSubtract:
|
|
|
c313de |
* @a: minuend/result
|
|
|
c313de |
diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h
|
|
|
c313de |
index 312e7e2933..5934508d11 100644
|
|
|
c313de |
--- a/src/util/virbitmap.h
|
|
|
c313de |
+++ b/src/util/virbitmap.h
|
|
|
c313de |
@@ -151,6 +151,10 @@ bool virBitmapOverlaps(virBitmapPtr b1,
|
|
|
c313de |
void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b)
|
|
|
c313de |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
c313de |
|
|
|
c313de |
+int virBitmapUnion(virBitmapPtr a,
|
|
|
c313de |
+ const virBitmap *b)
|
|
|
c313de |
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
c313de |
+
|
|
|
c313de |
void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b)
|
|
|
c313de |
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
c313de |
|
|
|
c313de |
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
|
|
|
c313de |
index 2fbafc0a76..cafe865dde 100644
|
|
|
c313de |
--- a/tests/virbitmaptest.c
|
|
|
c313de |
+++ b/tests/virbitmaptest.c
|
|
|
c313de |
@@ -740,6 +740,34 @@ test14(const void *opaque)
|
|
|
c313de |
return ret;
|
|
|
c313de |
}
|
|
|
c313de |
|
|
|
c313de |
+/* virBitmapUnion() */
|
|
|
c313de |
+static int
|
|
|
c313de |
+test15(const void *opaque)
|
|
|
c313de |
+{
|
|
|
c313de |
+ const struct testBinaryOpData *data = opaque;
|
|
|
c313de |
+ VIR_AUTOPTR(virBitmap) amap = NULL;
|
|
|
c313de |
+ VIR_AUTOPTR(virBitmap) bmap = NULL;
|
|
|
c313de |
+ VIR_AUTOPTR(virBitmap) resmap = NULL;
|
|
|
c313de |
+
|
|
|
c313de |
+ if (!(amap = virBitmapParseUnlimited(data->a)) ||
|
|
|
c313de |
+ !(bmap = virBitmapParseUnlimited(data->b)) ||
|
|
|
c313de |
+ !(resmap = virBitmapParseUnlimited(data->res))) {
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+ }
|
|
|
c313de |
+
|
|
|
c313de |
+ if (virBitmapUnion(amap, bmap) < 0)
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+
|
|
|
c313de |
+ if (!virBitmapEqual(amap, resmap)) {
|
|
|
c313de |
+ fprintf(stderr,
|
|
|
c313de |
+ "\n bitmap union failed: union('%s', '%s') != '%s'\n",
|
|
|
c313de |
+ data->a, data->b, data->res);
|
|
|
c313de |
+ return -1;
|
|
|
c313de |
+ }
|
|
|
c313de |
+
|
|
|
c313de |
+ return 0;
|
|
|
c313de |
+}
|
|
|
c313de |
+
|
|
|
c313de |
|
|
|
c313de |
#define TESTBINARYOP(A, B, RES, FUNC) \
|
|
|
c313de |
testBinaryOpData.a = A; \
|
|
|
c313de |
@@ -798,6 +826,16 @@ mymain(void)
|
|
|
c313de |
TESTBINARYOP("0-3", "0,^0", "0-3", test14);
|
|
|
c313de |
TESTBINARYOP("0,2", "1,3", "0,2", test14);
|
|
|
c313de |
|
|
|
c313de |
+ /* virBitmapUnion() */
|
|
|
c313de |
+ virTestCounterReset("test15-");
|
|
|
c313de |
+ TESTBINARYOP("0-1", "0-1", "0-1", test15);
|
|
|
c313de |
+ TESTBINARYOP("0", "1", "0-1", test15);
|
|
|
c313de |
+ TESTBINARYOP("0-1", "2-3", "0-3", test15);
|
|
|
c313de |
+ TESTBINARYOP("0-3", "1-2", "0-3", test15);
|
|
|
c313de |
+ TESTBINARYOP("0,^0", "12345", "12345", test15);
|
|
|
c313de |
+ TESTBINARYOP("12345", "0,^0", "12345", test15);
|
|
|
c313de |
+ TESTBINARYOP("0,^0", "0,^0", "0,^0", test15);
|
|
|
c313de |
+
|
|
|
c313de |
return ret;
|
|
|
c313de |
}
|
|
|
c313de |
|
|
|
c313de |
--
|
|
|
c313de |
2.22.0
|
|
|
c313de |
|