ia64/xen-unstable

changeset 599:f33864f401d8

bitkeeper revision 1.331.1.1 (3f0d5ce2ty7t1xKoi_XfrqGCd6L9mg)

Clean up segments when the domain dies.
author sos22@labyrinth.cl.cam.ac.uk
date Thu Jul 10 12:32:34 2003 +0000 (2003-07-10)
parents 681598b3259f
children 75e23848b238
files xen/common/domain.c xen/drivers/block/xen_segment.c xen/include/xeno/segment.h
line diff
     1.1 --- a/xen/common/domain.c	Thu Jul 10 11:04:02 2003 +0000
     1.2 +++ b/xen/common/domain.c	Thu Jul 10 12:32:34 2003 +0000
     1.3 @@ -143,6 +143,9 @@ void __kill_domain(struct task_struct *p
     1.4  
     1.5      unlink_blkdev_info(p);
     1.6  
     1.7 +    for ( i = 0; i < XEN_MAX_SEGMENTS; i++ )
     1.8 +	xen_segment_delete(p, i);
     1.9 +
    1.10      for ( i = 0; i < MAX_DOMAIN_VIFS; i++ )
    1.11          unlink_net_vif(p->net_vif_list[i]);
    1.12  
     2.1 --- a/xen/drivers/block/xen_segment.c	Thu Jul 10 11:04:02 2003 +0000
     2.2 +++ b/xen/drivers/block/xen_segment.c	Thu Jul 10 12:32:34 2003 +0000
     2.3 @@ -15,7 +15,7 @@
     2.4  #include <asm/domain_page.h>
     2.5  #include <hypervisor-ifs/block.h>
     2.6  
     2.7 -segment_t xsegments[XEN_MAX_SEGMENTS];
     2.8 +static segment_t xsegments[XEN_MAX_SEGMENTS];
     2.9  
    2.10  #if 0
    2.11  #define DPRINTK(_f, _a...) printk( _f , ## _a )
    2.12 @@ -23,6 +23,9 @@ segment_t xsegments[XEN_MAX_SEGMENTS];
    2.13  #define DPRINTK(_f, _a...) ((void)0)
    2.14  #endif
    2.15  
    2.16 +/* XXX XXX XXX Why are there absolutely no calls to any locking
    2.17 +   primitives anywhere in this? */
    2.18 +
    2.19  /*
    2.20   * xen_segment_map_request
    2.21   *
    2.22 @@ -186,7 +189,6 @@ void xen_segment_probe_all(xen_segment_i
    2.23  {
    2.24      int loop;
    2.25      xen_segment_info_t *xsi = map_domain_mem(virt_to_phys(raw_xsi));
    2.26 -    unsigned long device;
    2.27  
    2.28      xsi->count = 0;
    2.29      for ( loop = 0; loop < XEN_MAX_SEGMENTS; loop++ )
    2.30 @@ -234,7 +236,6 @@ void xen_refresh_segment_list (struct ta
    2.31   * if we see the same DOM#/SEG# combination, we reuse the slot in
    2.32   * the segment table (overwriting what was there before).
    2.33   * an alternative would be to raise an error if the slot is reused.
    2.34 - * bug: we don't free the xtents array when we re-use a slot.
    2.35   */
    2.36  int xen_segment_create(xv_disk_t *xvd_in)
    2.37  {
    2.38 @@ -261,6 +262,8 @@ int xen_segment_create(xv_disk_t *xvd_in
    2.39      xsegments[idx].segment_number = xvd->segment;
    2.40      memcpy(xsegments[idx].key, xvd->key, XEN_SEGMENT_KEYSIZE);
    2.41      xsegments[idx].num_extents = xvd->ext_count;
    2.42 +    if (xsegments[idx].extents)
    2.43 +	kfree(xsegments[idx].extents);
    2.44      xsegments[idx].extents = (extent_t *)kmalloc(
    2.45          sizeof(extent_t)*xvd->ext_count,
    2.46          GFP_KERNEL);
    2.47 @@ -296,10 +299,43 @@ int xen_segment_create(xv_disk_t *xvd_in
    2.48   *
    2.49   * return 0 on success, 1 on failure
    2.50   *
    2.51 - * TODO: caller must ensure that only domain 0 calls this function
    2.52   */
    2.53 -int xen_segment_delete(struct task_struct *p, xv_disk_t *xvd)
    2.54 +int xen_segment_delete(struct task_struct *p, int segnr)
    2.55  {
    2.56 +    segment_t *seg;
    2.57 +
    2.58 +    if (!p) {
    2.59 +	printk("xen_segment delete called with NULL domain?\n");
    2.60 +	BUG();
    2.61 +	return 1;
    2.62 +    }
    2.63 +
    2.64 +    if (segnr < 0 || segnr > XEN_MAX_SEGMENTS) {
    2.65 +	printk("xen_segment_delete called with bad segnr?\n");
    2.66 +	BUG();
    2.67 +	return 1;
    2.68 +    }
    2.69 +
    2.70 +    if (!p->segment_list[segnr])
    2.71 +	return 1;
    2.72 +
    2.73 +    seg = p->segment_list[segnr];
    2.74 +
    2.75 +    /* sanity checking */
    2.76 +    if (seg->domain != p->domain || seg->segment_number != segnr ||
    2.77 +	(seg->mode != XEN_SEGMENT_RO && seg->mode != XEN_SEGMENT_RW) ||
    2.78 +	seg->num_extents <= 0 || seg->extents == NULL) {
    2.79 +	printk("segment is insane!\n");
    2.80 +	BUG();
    2.81 +	return 1;
    2.82 +    }
    2.83 +
    2.84 +    p->segment_list[segnr] = NULL;
    2.85 +    seg->domain = -1;
    2.86 +    seg->segment_number = -1;
    2.87 +    kfree(seg->extents);
    2.88 +    seg->mode = XEN_SEGMENT_UNUSED;
    2.89 +
    2.90      return 0;
    2.91  }
    2.92  
     3.1 --- a/xen/include/xeno/segment.h	Thu Jul 10 11:04:02 2003 +0000
     3.2 +++ b/xen/include/xeno/segment.h	Thu Jul 10 12:32:34 2003 +0000
     3.3 @@ -17,6 +17,7 @@ struct task_struct;
     3.4  void xen_segment_initialize(void);
     3.5  void xen_refresh_segment_list (struct task_struct *p);
     3.6  int xen_segment_create(xv_disk_t *xvd);
     3.7 +int xen_segment_delete(struct task_struct *p, int segnr);
     3.8  int xen_segment_map_request(
     3.9      phys_seg_t *pseg, struct task_struct *p, int operation,
    3.10      unsigned short segment_number,