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