[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] add the facility to limit ranges per rangeset



commit 236f3d2ae4ecac5044465bf3bec47025b0dc327d
Author:     Paul Durrant <paul.durrant@xxxxxxxxxx>
AuthorDate: Mon May 12 12:04:45 2014 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon May 12 12:04:45 2014 +0200

    add the facility to limit ranges per rangeset
    
    A subsequent patch exposes rangesets to secondary emulators, so to allow a
    limit to be placed on the amount of xenheap that an emulator can cause to be
    consumed, the function rangeset_limit() has been created to set the allowed
    number of ranges in a rangeset. By default, there is no limit.
    
    Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/common/rangeset.c      |   56 ++++++++++++++++++++++++++++++++++++-------
 xen/include/xen/rangeset.h |   17 +++++++++++++
 2 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index 2b986fb..93a3ef2 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -25,6 +25,9 @@ struct rangeset {
 
     /* Ordered list of ranges contained in this set, and protecting lock. */
     struct list_head range_list;
+
+    /* Number of ranges that can be allocated */
+    long             nr_ranges;
     spinlock_t       lock;
 
     /* Pretty-printing name. */
@@ -81,12 +84,30 @@ static void insert_range(
 
 /* Remove a range from its list and free it. */
 static void destroy_range(
-    struct range *x)
+    struct rangeset *r, struct range *x)
 {
+    r->nr_ranges++;
+
     list_del(&x->list);
     xfree(x);
 }
 
+/* Allocate a new range */
+static struct range *alloc_range(
+    struct rangeset *r)
+{
+    struct range *x;
+
+    if ( r->nr_ranges == 0 )
+        return NULL;
+
+    x = xmalloc(struct range);
+    if ( x )
+        --r->nr_ranges;
+
+    return x;
+}
+
 /*****************************
  * Core public functions
  */
@@ -108,7 +129,7 @@ int rangeset_add_range(
     {
         if ( (x == NULL) || ((x->e < s) && ((x->e + 1) != s)) )
         {
-            x = xmalloc(struct range);
+            x = alloc_range(r);
             if ( x == NULL )
             {
                 rc = -ENOMEM;
@@ -143,7 +164,7 @@ int rangeset_add_range(
             y = next_range(r, x);
             if ( (y == NULL) || (y->e > x->e) )
                 break;
-            destroy_range(y);
+            destroy_range(r, y);
         }
     }
 
@@ -151,7 +172,7 @@ int rangeset_add_range(
     if ( (y != NULL) && ((x->e + 1) == y->s) )
     {
         x->e = y->e;
-        destroy_range(y);
+        destroy_range(r, y);
     }
 
  out:
@@ -179,7 +200,7 @@ int rangeset_remove_range(
 
         if ( (x->s < s) && (x->e > e) )
         {
-            y = xmalloc(struct range);
+            y = alloc_range(r);
             if ( y == NULL )
             {
                 rc = -ENOMEM;
@@ -193,7 +214,7 @@ int rangeset_remove_range(
             insert_range(r, x, y);
         }
         else if ( (x->s == s) && (x->e <= e) )
-            destroy_range(x);
+            destroy_range(r, x);
         else if ( x->s == s )
             x->s = e + 1;
         else if ( x->e <= e )
@@ -214,12 +235,12 @@ int rangeset_remove_range(
         {
             t = x;
             x = next_range(r, x);
-            destroy_range(t);
+            destroy_range(r, t);
         }
 
         x->s = e + 1;
         if ( x->s > x->e )
-            destroy_range(x);
+            destroy_range(r, x);
     }
 
  out:
@@ -312,6 +333,7 @@ struct rangeset *rangeset_new(
 
     spin_lock_init(&r->lock);
     INIT_LIST_HEAD(&r->range_list);
+    r->nr_ranges = -1;
 
     BUG_ON(flags & ~RANGESETF_prettyprint_hex);
     r->flags = flags;
@@ -351,11 +373,17 @@ void rangeset_destroy(
     }
 
     while ( (x = first_range(r)) != NULL )
-        destroy_range(x);
+        destroy_range(r, x);
 
     xfree(r);
 }
 
+void rangeset_limit(
+    struct rangeset *r, unsigned int limit)
+{
+    r->nr_ranges = limit;
+}
+
 void rangeset_domain_initialise(
     struct domain *d)
 {
@@ -461,3 +489,13 @@ void rangeset_domain_printk(
 
     spin_unlock(&d->rangesets_lock);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index 2c122c1..5ed6817 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -38,6 +38,13 @@ struct rangeset *rangeset_new(
 void rangeset_destroy(
     struct rangeset *r);
 
+/*
+ * Set a limit on the number of ranges that may exist in set @r.
+ * NOTE: This must be called while @r is empty.
+ */
+void rangeset_limit(
+    struct rangeset *r, unsigned int limit);
+
 /* Flags for passing to rangeset_new(). */
  /* Pretty-print range limits in hexadecimal. */
 #define _RANGESETF_prettyprint_hex 0
@@ -77,3 +84,13 @@ void rangeset_domain_printk(
     struct domain *d);
 
 #endif /* __XEN_RANGESET_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.