ia64/xen-unstable

changeset 402:43ddfd337a59

bitkeeper revision 1.190 (3ead448aQqsmoDogGpVw6XGWve4LIg)

xen_segment.c:
Fix virtblk offset/length remapping in Xen.
author kaf24@scramble.cl.cam.ac.uk
date Mon Apr 28 15:11:06 2003 +0000 (2003-04-28)
parents 5b76fd9dd30c
children b695c18bad2d
files xen/drivers/block/xen_segment.c
line diff
     1.1 --- a/xen/drivers/block/xen_segment.c	Mon Apr 28 14:30:52 2003 +0000
     1.2 +++ b/xen/drivers/block/xen_segment.c	Mon Apr 28 15:11:06 2003 +0000
     1.3 @@ -27,10 +27,8 @@ segment_t xsegments[XEN_MAX_SEGMENTS];
     1.4   * xen_segment_map_request
     1.5   *
     1.6   * xen_device must be a valid device.
     1.7 - */
     1.8 -
     1.9 -/*
    1.10 - * NB. Al offsets and sizes here are in sector units.
    1.11 + * 
    1.12 + * NB. All offsets and sizes here are in sector units.
    1.13   * eg. 'size == 1' means an actual size of 512 bytes.
    1.14   */
    1.15  int xen_segment_map_request(
    1.16 @@ -45,32 +43,36 @@ int xen_segment_map_request(
    1.17      segment_number &= XENDEV_IDX_MASK;
    1.18      if ( segment_number >= XEN_MAX_SEGMENTS )
    1.19      {
    1.20 -      DPRINTK("invalid segment number. %d %d\n",
    1.21 -	      segment_number, XEN_MAX_SEGMENTS);
    1.22 -      goto fail;
    1.23 +        DPRINTK("invalid segment number. %d %d\n",
    1.24 +                segment_number, XEN_MAX_SEGMENTS);
    1.25 +        goto fail;
    1.26      }
    1.27  
    1.28      seg = p->segment_list[segment_number];
    1.29      if ( seg == NULL ) 
    1.30      {
    1.31 -      DPRINTK("segment is null. %d\n", segment_number);
    1.32 -      goto fail;
    1.33 +        DPRINTK("segment is null. %d\n", segment_number);
    1.34 +        goto fail;
    1.35      }
    1.36  
    1.37      /* check domain permissions */
    1.38      if ( seg->domain != p->domain )
    1.39      {
    1.40 -      DPRINTK("segment is for another domain. %d %d\n",
    1.41 -	      seg->domain, p->domain);
    1.42 -      goto fail;
    1.43 +        DPRINTK("seg is for another domain. %d %d\n", seg->domain, p->domain);
    1.44 +        goto fail;
    1.45      }
    1.46  
    1.47      /* check rw access */
    1.48 -    if ((operation == WRITE && seg->mode != XEN_SEGMENT_RW) ||
    1.49 -        (operation == READ  && seg->mode == XEN_SEGMENT_UNUSED))
    1.50 +    if ( ((operation == WRITE) && (seg->mode != XEN_SEGMENT_RW)) ||
    1.51 +         ((operation == READ)  && (seg->mode == XEN_SEGMENT_UNUSED)) )
    1.52      {
    1.53 -        DPRINTK("illegal operation: %d %d\n",
    1.54 -		operation, seg->mode);
    1.55 +        DPRINTK("illegal operation: %d %d\n", operation, seg->mode);
    1.56 +        goto fail;
    1.57 +    }
    1.58 +
    1.59 +    if ( (nr_sects + sect_nr) <= sect_nr )
    1.60 +    {
    1.61 +        DPRINTK("sector + size wrap! %08lx %04x\n", sect_nr, nr_sects);
    1.62          goto fail;
    1.63      }
    1.64  
    1.65 @@ -86,9 +88,9 @@ int xen_segment_map_request(
    1.66  
    1.67      if ( (sum + ext->size) <= sect_nr ) 
    1.68      {
    1.69 -      DPRINTK("extent size mismatch: %d %d : %d %ld %ld\n",
    1.70 -	      i, seg->num_extents, sum, ext->size, sect_nr);
    1.71 -      goto fail;
    1.72 +        DPRINTK("extent size mismatch: %d %d : %d %ld %ld\n",
    1.73 +                i, seg->num_extents, sum, ext->size, sect_nr);
    1.74 +        goto fail;
    1.75      }
    1.76  
    1.77      pseg->sector_number = (sect_nr - sum) + ext->offset;
    1.78 @@ -98,8 +100,8 @@ int xen_segment_map_request(
    1.79      if ( pseg->dev == 0 ) 
    1.80      {
    1.81          DPRINTK ("invalid device 0x%x 0x%lx 0x%lx\n", 
    1.82 -		 ext->disk, ext->offset, ext->size);
    1.83 -	goto fail;
    1.84 +                 ext->disk, ext->offset, ext->size);
    1.85 +        goto fail;
    1.86      }
    1.87  
    1.88      /* We're finished if the virtual extent didn't overrun the phys extent. */
    1.89 @@ -110,8 +112,8 @@ int xen_segment_map_request(
    1.90      if ( (i+1) == seg->num_extents ) 
    1.91      {
    1.92          DPRINTK ("not enough extents %d %d\n",
    1.93 -		 i, seg->num_extents);
    1.94 -	goto fail;
    1.95 +                 i, seg->num_extents);
    1.96 +        goto fail;
    1.97      }
    1.98  
    1.99      pseg[1].nr_sects = (sect_nr + nr_sects) - (sum + ext->size);
   1.100 @@ -122,50 +124,27 @@ int xen_segment_map_request(
   1.101      if ( pseg[1].dev == 0 ) 
   1.102      {
   1.103          DPRINTK ("bogus device for pseg[1] \n");
   1.104 -	goto fail;
   1.105 +        goto fail;
   1.106      }
   1.107  
   1.108      /* We don't allow overrun onto a third physical extent. */
   1.109 -    if ( (sum + ext[0].size + ext[1].size) < 
   1.110 -         (pseg[1].sector_number + pseg[1].nr_sects) )
   1.111 +    if ( pseg[1].nr_sects > ext[1].size )
   1.112      {
   1.113          DPRINTK ("third extent\n");
   1.114          DPRINTK (" sum:%d, e0:%ld, e1:%ld   p1.sect:%ld p1.nr:%d\n",
   1.115 -		 sum, ext[0].size, ext[1].size, 
   1.116 -		 pseg[1].sector_number, pseg[1].nr_sects);
   1.117 +                 sum, ext[0].size, ext[1].size, 
   1.118 +                 pseg[1].sector_number, pseg[1].nr_sects);
   1.119          goto fail;    
   1.120      }
   1.121  
   1.122      return 2;                   /* We overran onto a second physical extent. */
   1.123  
   1.124   fail:
   1.125 -
   1.126      DPRINTK ("xen_segment_map_request failure\n");
   1.127      DPRINTK ("operation: %d\n", operation);
   1.128      DPRINTK ("segment number: %d\n", segment_number);
   1.129      DPRINTK ("sect_nr: %ld 0x%lx\n", sect_nr, sect_nr);
   1.130      DPRINTK ("nr_sects: %d 0x%x\n", nr_sects, nr_sects);
   1.131 -
   1.132 -    if (0)
   1.133 -    {
   1.134 -      segment_t *xseg;
   1.135 -      extent_t  *xext;
   1.136 -      int xsum, xi;
   1.137 -
   1.138 -      xseg = p->segment_list[segment_number];
   1.139 -
   1.140 -      xsum = 0; xi = 0;
   1.141 -      xext = xseg->extents;
   1.142 -
   1.143 -      while ( (xi < xseg->num_extents) && ((xsum + xext->size) <= sect_nr) )
   1.144 -      {
   1.145 -	DPRINTK (" xi:%d, num_ext:%d, xsum:%d, size:%lx, sect_nr:%lx\n",
   1.146 -		 xi, xseg->num_extents, xsum, xext->size, sect_nr);
   1.147 -	xsum += xext->size;
   1.148 -        xext++; xi++;
   1.149 -      }
   1.150 -    }
   1.151 -
   1.152      return -1;
   1.153  }
   1.154  
   1.155 @@ -238,8 +217,8 @@ int xen_segment_create(xv_disk_t *xvd_in
   1.156      for (idx = 0; idx < XEN_MAX_SEGMENTS; idx++)
   1.157      {
   1.158          if (xsegments[idx].mode == XEN_SEGMENT_UNUSED ||
   1.159 -	    (xsegments[idx].domain == xvd->domain &&
   1.160 -	     xsegments[idx].segment_number == xvd->segment)) break;
   1.161 +            (xsegments[idx].domain == xvd->domain &&
   1.162 +             xsegments[idx].segment_number == xvd->segment)) break;
   1.163      }
   1.164      if (idx == XEN_MAX_SEGMENTS)
   1.165      {
   1.166 @@ -274,12 +253,12 @@ int xen_segment_create(xv_disk_t *xvd_in
   1.167      p = current;
   1.168      do
   1.169      {
   1.170 -      p = p->next_task;
   1.171 +        p = p->next_task;
   1.172      } while (p != current && p->domain != xvd->domain);
   1.173  
   1.174      if (p->domain == xvd->domain)
   1.175      {
   1.176 -      p->segment_list[xvd->segment] = &xsegments[idx];
   1.177 +        p->segment_list[xvd->segment] = &xsegments[idx];
   1.178      }
   1.179  
   1.180      unmap_domain_mem(xvd);
   1.181 @@ -330,12 +309,12 @@ static void dump_segments(u_char key, vo
   1.182          printk("  domain %d: ", p->domain);
   1.183          for (loop = 0; loop < XEN_MAX_SEGMENTS; loop++)
   1.184          {
   1.185 -	  if (p->segment_list[loop])
   1.186 -	  {
   1.187 -	    printk (" %d", p->segment_list[loop] - xsegments);
   1.188 -	  }
   1.189 +            if (p->segment_list[loop])
   1.190 +            {
   1.191 +                printk (" %d", p->segment_list[loop] - xsegments);
   1.192 +            }
   1.193          }
   1.194 -	printk("\n");
   1.195 +        printk("\n");
   1.196          p = p->next_task;
   1.197      } while (p != current);
   1.198  }