direct-io.hg

changeset 440:91f49ffad7d5

bitkeeper revision 1.222 (3eba9f498RAq8VzoEW7GBoEnFA1WGw)

dom0_ops.c:
Fix domain creation to avoid conflicts in domain-id space.
author kaf24@scramble.cl.cam.ac.uk
date Thu May 08 18:17:45 2003 +0000 (2003-05-08)
parents 76eba4e532dd
children 3b7be708d378
files xen/common/dom0_ops.c
line diff
     1.1 --- a/xen/common/dom0_ops.c	Thu May 08 17:10:37 2003 +0000
     1.2 +++ b/xen/common/dom0_ops.c	Thu May 08 18:17:45 2003 +0000
     1.3 @@ -17,12 +17,24 @@
     1.4  
     1.5  extern unsigned int alloc_new_dom_mem(struct task_struct *, unsigned int);
     1.6  
     1.7 +/* Basically used to protect the domain-id space. */
     1.8 +static spinlock_t create_dom_lock = SPIN_LOCK_UNLOCKED;
     1.9 +
    1.10  static unsigned int get_domnr(void)
    1.11  {
    1.12      static unsigned int domnr = 0;
    1.13 -    do { domnr = (domnr+1) & ((1<<20)-1); }
    1.14 -    while ( find_domain_by_id(domnr) != NULL );
    1.15 -    return domnr;
    1.16 +    struct task_struct *p;
    1.17 +    int tries = 0;
    1.18 +
    1.19 +    for ( tries = 0; tries < 1024; tries++ )
    1.20 +    {
    1.21 +        domnr = (domnr+1) & ((1<<20)-1);
    1.22 +        if ( (p = find_domain_by_id(domnr)) == NULL )
    1.23 +            return domnr;
    1.24 +        free_task_struct(p);
    1.25 +    }
    1.26 +
    1.27 +    return 0;
    1.28  }
    1.29  
    1.30  static void build_page_list(struct task_struct *p)
    1.31 @@ -97,16 +109,18 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    1.32      {
    1.33          struct task_struct *p;
    1.34          static unsigned int pro = 0;
    1.35 -        unsigned int dom = get_domnr();
    1.36 +        unsigned int dom;
    1.37          ret = -ENOMEM;
    1.38 -
    1.39 -        if ( dom == 0 ) 
    1.40 -            break;
    1.41 +        
    1.42 +        spin_lock_irq(&create_dom_lock);
    1.43 +        
    1.44 +        if ( (dom = get_domnr()) == 0 ) 
    1.45 +            goto exit_create;
    1.46  
    1.47          pro = (pro+1) % smp_num_cpus;
    1.48          p = do_newdomain(dom, pro);
    1.49          if ( p == NULL ) 
    1.50 -            break;
    1.51 +            goto exit_create;
    1.52  
    1.53  	if (op.u.newdomain.name[0]) {
    1.54  	  strncpy (p -> name, op.u.newdomain.name, MAX_DOMAIN_NAME);
    1.55 @@ -117,7 +131,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    1.56          if ( ret != 0 ) 
    1.57          {
    1.58              __kill_domain(p);
    1.59 -            break;
    1.60 +            goto exit_create;
    1.61          }
    1.62  
    1.63          build_page_list(p);
    1.64 @@ -129,6 +143,9 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    1.65              list_entry(p->pg_head.next, struct pfn_info, list) -
    1.66              frame_table;
    1.67          copy_to_user(u_dom0_op, &op, sizeof(op));
    1.68 +
    1.69 +    exit_create:
    1.70 +        spin_unlock_irq(&create_dom_lock);
    1.71      }
    1.72      break;
    1.73