[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/6] rangeset: introduce rangeset_subtract
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
- Date: Thu, 8 May 2025 09:20:33 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J7QqFU341kNEQ1CkVHUs9vf850fY7Y4Ivh8PGVOXOpI=; b=eE7oH9/eKJ4JJ4OyFa6EqKHGFKxXs1PqcG1qDhCNBHkW0GPjHX+I7bjk6k2hTaLKRLLGkh0wZSOa91HzNOFYoWYqj/Q4GHze7PPL1ozrFDEqa4RiVpwJ3LCn2ooW8w6UfLRI0wU/+XBYSCz+wY/LHBH7+oTi5ucC+l2rVRoD7ccoUyXRpUbeciXBnKsx3VcF2Vcht/GtJMLOogrowvrJox31JZZWVOS7yXuI8iqaYrLWLBjgoyq/cvuWvVJBRdU4JmUQWW4OZ7V7mAXA8QtABImGMcVP4pgXSivY01jkkPjZXOGE7tWCqVJc/QGK+qqt0X2HhUQBWqP8ZLUrYWsFDA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QivDNAi660V+JVq6wiiyJu65xyw//QBuS0CM0s775D4ap5o5XA+UnBHrHq3ZQYIEIWgQIATc3G3jDs04Ng7AyUrF5qDxJnjNJFPQDglRLGUIYF9phV9zOSgG9UzIySTJg3wIjMkaabim+ywuTrXcVc7NVbsx05ukhVPDjzrkz33N++/SCC9XOp9xBl7y+RtKS+3u+e0/YlCuoU0ohavL2FasPxf/uyrrA7sEkiHB7WhKIVoeQkrAyz5JxH4ezDY2aZe2gD4k+Fe0EXnBmrvp4Jh6vEopBoHEjP+XpUIbsnbR2ilt8p2GgSiRtXkQscsG3VsBl79PzufImql+8uJLFA==
- Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- Delivery-date: Thu, 08 May 2025 13:21:33 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Introduce rangeset_subtract() to remove regions in r2 from r1.
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
---
v1->v2:
* no change
---
xen/common/rangeset.c | 12 ++++++++++++
xen/include/xen/rangeset.h | 3 +++
2 files changed, 15 insertions(+)
diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index e75871039087..b9e8912fb1c3 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -397,6 +397,18 @@ int rangeset_merge(struct rangeset *r1, struct rangeset
*r2)
return rangeset_report_ranges(r2, 0, ~0UL, merge, r1);
}
+static int cf_check subtract(unsigned long s, unsigned long e, void *data)
+{
+ struct rangeset *r = data;
+
+ return rangeset_remove_range(r, s, e);
+}
+
+int rangeset_subtract(struct rangeset *r1, struct rangeset *r2)
+{
+ return rangeset_report_ranges(r2, 0, ~0UL, subtract, r1);
+}
+
int rangeset_add_singleton(
struct rangeset *r, unsigned long s)
{
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index 96c918082501..817505badf6f 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -85,6 +85,9 @@ int rangeset_consume_ranges(struct rangeset *r,
/* Merge rangeset r2 into rangeset r1. */
int __must_check rangeset_merge(struct rangeset *r1, struct rangeset *r2);
+/* Subtract rangeset r2 from rangeset r1. */
+int __must_check rangeset_subtract(struct rangeset *r1, struct rangeset *r2);
+
/* Add/remove/query a single number. */
int __must_check rangeset_add_singleton(
struct rangeset *r, unsigned long s);
--
2.49.0
|