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