]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen: introduce rangeset_consume_ranges
authorRoger Pau Monne <roger.pau@citrix.com>
Mon, 18 Sep 2017 14:04:23 +0000 (15:04 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Mon, 18 Sep 2017 15:21:48 +0000 (16:21 +0100)
This function allows to iterate over a rangeset while removing the
processed regions.

It will be used by the following patches in order to store memory
regions in rangesets, and remove them while iterating.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
Changes since v5:
 - New in this version.

xen/common/rangeset.c
xen/include/xen/rangeset.h

index 6c6293c15cd8fd913ac7d9876d3b764c46b5f961..07350cfff690755eadfe92f64164170ff1dd1381 100644 (file)
@@ -298,6 +298,35 @@ int rangeset_report_ranges(
     return rc;
 }
 
+int rangeset_consume_ranges(
+    struct rangeset *r,
+    int (*cb)(unsigned long s, unsigned long e, void *, unsigned long *c),
+    void *ctxt)
+{
+    struct range *x;
+    int rc = 0;
+
+    write_lock(&r->lock);
+    while ( !rangeset_is_empty(r) )
+    {
+        unsigned long consumed = 0;
+
+        x = first_range(r);
+        rc = cb(x->s, x->e, ctxt, &consumed);
+
+        ASSERT(consumed <= x->e - x->s + 1);
+        x->s += consumed;
+        if ( x->s > x->e )
+            destroy_range(r, x);
+
+        if ( rc )
+            break;
+    }
+    write_unlock(&r->lock);
+
+    return rc;
+}
+
 int rangeset_add_singleton(
     struct rangeset *r, unsigned long s)
 {
index aa6408248b079f2e7a93db555e998e06635bd91b..dfdb193800bb400eb7a6580acd45c803facb8e3b 100644 (file)
@@ -67,6 +67,10 @@ bool_t __must_check rangeset_overlaps_range(
 int rangeset_report_ranges(
     struct rangeset *r, unsigned long s, unsigned long e,
     int (*cb)(unsigned long s, unsigned long e, void *), void *ctxt);
+int rangeset_consume_ranges(
+    struct rangeset *r,
+    int (*cb)(unsigned long s, unsigned long e, void *, unsigned long *c),
+    void *ctxt);
 
 /* Add/remove/query a single number. */
 int __must_check rangeset_add_singleton(