From nobody Thu May 15 06:43:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510563053249404.14205987566504; Mon, 13 Nov 2017 00:50:53 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEBCD6868A; Mon, 13 Nov 2017 08:50:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BFEB5E27D; Mon, 13 Nov 2017 08:50:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 65C893D382; Mon, 13 Nov 2017 08:50:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAD8okHG016283 for ; Mon, 13 Nov 2017 03:50:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2B0FC703A7; Mon, 13 Nov 2017 08:50:46 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB9FA703A9 for ; Mon, 13 Nov 2017 08:50:45 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 77392123A7C for ; Mon, 13 Nov 2017 09:50:41 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 09:50:23 +0100 Message-Id: <2d64711d5ed1323cd1b1b60c355101d99fd83ecd.1510560300.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/21] util: Reintroduce virBitmapSubtract X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Nov 2017 08:50:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Already introduced in the past with 9479642fd3c5, but then renamed to virBitmapIntersect by a908e9e45eb2. This time we'll really use it. Signed-off-by: Martin Kletzander Reviewed-by: John Ferlan --- src/libvirt_private.syms | 1 + src/util/virbitmap.c | 22 ++++++++++++++++++++++ src/util/virbitmap.h | 3 +++ tests/virbitmaptest.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 57df411602b9..0b78a0681c5e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1370,6 +1370,7 @@ virBitmapSetAll; virBitmapSetBit; virBitmapSetBitExpand; virBitmapSize; +virBitmapSubtract; virBitmapToData; virBitmapToDataBuf; virBitmapToString; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 02d1f264d859..ac6ff4f6d26d 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1169,3 +1169,25 @@ virBitmapIntersect(virBitmapPtr a, for (i =3D 0; i < max; i++) a->map[i] &=3D b->map[i]; } + + +/** + * virBitmapSubtract: + * @a: minuend/result + * @b: subtrahend + * + * Performs subtraction of two bitmaps: a =3D a - b + */ +void +virBitmapSubtract(virBitmapPtr a, + virBitmapPtr b) +{ + size_t i; + size_t max =3D a->map_len; + + if (max > b->map_len) + max =3D b->map_len; + + for (i =3D 0; i < max; i++) + a->map[i] &=3D ~b->map[i]; +} diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index e964a3edc9cb..7b2bea8b534c 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -150,4 +150,7 @@ bool virBitmapOverlaps(virBitmapPtr b1, void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + #endif diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 3ea63e1295af..120c074d3def 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -701,6 +701,39 @@ test13(const void *opaque ATTRIBUTE_UNUSED) =20 #undef TEST_MAP =20 +static int +test14(const void *opaque) +{ + const struct testBinaryOpData *data =3D opaque; + virBitmapPtr amap =3D NULL; + virBitmapPtr bmap =3D NULL; + virBitmapPtr resmap =3D NULL; + int ret =3D -1; + + if (virBitmapParse(data->a, &amap, 256) < 0 || + virBitmapParse(data->b, &bmap, 256) < 0 || + virBitmapParse(data->res, &resmap, 256) < 0) + goto cleanup; + + virBitmapSubtract(amap, bmap); + + if (!virBitmapEqual(amap, resmap)) { + fprintf(stderr, + "\n bitmap subtraction failed: '%s' - '%s' !=3D '%s'\n", + data->a, data->b, data->res); + goto cleanup; + } + + ret =3D 0; + + cleanup: + virBitmapFree(amap); + virBitmapFree(bmap); + virBitmapFree(resmap); + + return ret; +} + =20 #define TESTBINARYOP(A, B, RES, FUNC) \ testBinaryOpData.a =3D A; \ @@ -750,6 +783,15 @@ mymain(void) if (virTestRun("test13", test13, NULL) < 0) ret =3D -1; =20 + virTestCounterReset("test14-"); + TESTBINARYOP("0", "0", "0,^0", test14); + TESTBINARYOP("0-3", "0", "1-3", test14); + TESTBINARYOP("0-3", "0,3", "1-2", test14); + TESTBINARYOP("0,^0", "0", "0,^0", test14); + TESTBINARYOP("0-3", "0-3", "0,^0", test14); + TESTBINARYOP("0-3", "0,^0", "0-3", test14); + TESTBINARYOP("0,2", "1,3", "0,2", test14); + return ret; } =20 --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list