[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen stable-4.10] xen: introduce rangeset_claim_range
commit 1fa54448348d6cc36b89bb9e1729ea601013b00f Author: Wei Liu <wei.liu2@xxxxxxxxxx> AuthorDate: Wed Jan 3 16:38:54 2018 +0000 Commit: Roger Pau Monne <roger.pau@xxxxxxxxxx> CommitDate: Thu Jan 11 17:51:19 2018 +0000 xen: introduce rangeset_claim_range Reserve a hole in a rangeset. Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx> Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- Changes since v1: - Change function name. - Use a local variable instead of *s. - Add unlikely to the !prev case. - Move the function prototype position in the header file. --- xen/common/rangeset.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/rangeset.h | 4 +++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index 6c6293c15c..ade34f6a50 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -298,6 +298,58 @@ int rangeset_report_ranges( return rc; } +int rangeset_claim_range(struct rangeset *r, unsigned long size, + unsigned long *s) +{ + struct range *prev, *next; + unsigned long start = 0; + + write_lock(&r->lock); + + for ( prev = NULL, next = first_range(r); + next; + prev = next, next = next_range(r, next) ) + { + if ( (next->s - start) >= size ) + goto insert; + + if ( next->e == ~0UL ) + goto out; + + start = next->e + 1; + } + + if ( (~0UL - start) + 1 >= size ) + goto insert; + + out: + write_unlock(&r->lock); + return -ENOSPC; + + insert: + if ( unlikely(!prev) ) + { + next = alloc_range(r); + if ( !next ) + { + write_unlock(&r->lock); + return -ENOMEM; + } + + next->s = start; + next->e = start + size - 1; + insert_range(r, prev, next); + } + else + prev->e += size; + + write_unlock(&r->lock); + + *s = start; + + return 0; +} + 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 aa6408248b..1f83b1f44b 100644 --- a/xen/include/xen/rangeset.h +++ b/xen/include/xen/rangeset.h @@ -55,9 +55,11 @@ void rangeset_limit( bool_t __must_check rangeset_is_empty( const struct rangeset *r); -/* Add/remove/query a numeric range. */ +/* Add/claim/remove/query a numeric range. */ int __must_check rangeset_add_range( struct rangeset *r, unsigned long s, unsigned long e); +int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size, + unsigned long *s); int __must_check rangeset_remove_range( struct rangeset *r, unsigned long s, unsigned long e); bool_t __must_check rangeset_contains_range( -- generated by git-patchbot for /home/xen/git/xen.git#stable-4.10 _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |