ia64/xen-unstable

changeset 8461:65430a8f80d7

Extend the range abstraction by adding an internal
insert_range() helper function. Pretty printer uses
the internal abstractions rather than accessing the
linked list directly.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Dec 29 18:39:50 2005 +0100 (2005-12-29)
parents 4937d9f496ab
children 19f1f4fa7745
files xen/common/rangeset.c
line diff
     1.1 --- a/xen/common/rangeset.c	Thu Dec 29 18:16:01 2005 +0100
     1.2 +++ b/xen/common/rangeset.c	Thu Dec 29 18:39:50 2005 +0100
     1.3 @@ -32,6 +32,10 @@ struct rangeset {
     1.4      unsigned int     flags;
     1.5  };
     1.6  
     1.7 +/*****************************
     1.8 + * Private range functions hide the underlying linked-list implemnetation.
     1.9 + */
    1.10 +
    1.11  /* Find highest range lower than or containing s. NULL if no such range. */
    1.12  static struct range *find_range(
    1.13      struct rangeset *r, unsigned long s)
    1.14 @@ -66,6 +70,13 @@ static struct range *next_range(
    1.15      return list_entry(x->list.next, struct range, list);
    1.16  }
    1.17  
    1.18 +/* Insert range y after range x in r. Insert as first range if x is NULL. */
    1.19 +static void insert_range(
    1.20 +    struct rangeset *r, struct range *x, struct range *y)
    1.21 +{
    1.22 +    list_add(&y->list, (x != NULL) ? &x->list : &r->range_list);
    1.23 +}
    1.24 +
    1.25  /* Remove a range from its list and free it. */
    1.26  static void destroy_range(
    1.27      struct range *x)
    1.28 @@ -74,6 +85,10 @@ static void destroy_range(
    1.29      xfree(x);
    1.30  }
    1.31  
    1.32 +/*****************************
    1.33 + * Core public functions
    1.34 + */
    1.35 +
    1.36  int rangeset_add_range(
    1.37      struct rangeset *r, unsigned long s, unsigned long e)
    1.38  {
    1.39 @@ -99,10 +114,9 @@ int rangeset_add_range(
    1.40              x->s = s;
    1.41              x->e = e;
    1.42  
    1.43 -            list_add(&x->list, (y != NULL) ? &y->list : &r->range_list);
    1.44 +            insert_range(r, y, x);
    1.45          }
    1.46 -        
    1.47 -        if ( x->e < e )
    1.48 +        else if ( x->e < e )
    1.49              x->e = e;
    1.50      }
    1.51      else
    1.52 @@ -165,10 +179,12 @@ int rangeset_remove_range(
    1.53                  rc = -ENOMEM;
    1.54                  goto out;
    1.55              }
    1.56 +
    1.57              y->s = e + 1;
    1.58              y->e = x->e;
    1.59              x->e = s - 1;
    1.60 -            list_add(&y->list, &x->list);
    1.61 +
    1.62 +            insert_range(r, x, y);
    1.63          }
    1.64          else if ( (x->s == s) && (x->e <= e) )
    1.65              destroy_range(x);
    1.66 @@ -317,6 +333,10 @@ void rangeset_domain_destroy(
    1.67      }
    1.68  }
    1.69  
    1.70 +/*****************************
    1.71 + * Pretty-printing functions
    1.72 + */
    1.73 +
    1.74  static void print_limit(struct rangeset *r, unsigned long s)
    1.75  {
    1.76      printk((r->flags & RANGESETF_prettyprint_hex) ? "%lx" : "%lu", s);
    1.77 @@ -332,7 +352,7 @@ void rangeset_printk(
    1.78  
    1.79      printk("%10s {", r->name);
    1.80  
    1.81 -    list_for_each_entry ( x, &r->range_list, list )
    1.82 +    for ( x = first_range(r); x != NULL; x = next_range(r, x) )
    1.83      {
    1.84          if ( nr_printed++ )
    1.85              printk(",");