ia64/xen-unstable

changeset 533:35727deb8b0a

bitkeeper revision 1.289.2.3 (3f0aa9b8UnE6gBCHx3nuPzmgUovuqA)

Split partition and device number parts of physdisk extent
id.

Also some minor sanity checking.
author sos22@labyrinth.cl.cam.ac.uk
date Tue Jul 08 11:23:36 2003 +0000 (2003-07-08)
parents 4e67516e7fa8
children 49232d5003e6
files tools/internal/xi_phys_grant.c tools/internal/xi_phys_probe.c xen/drivers/block/xen_physdisk.c xen/include/hypervisor-ifs/block.h xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_physdisk_proc.c xenolinux-2.4.21-sparse/fs/partitions/xeno.c
line diff
     1.1 --- a/tools/internal/xi_phys_grant.c	Tue Jul 08 09:06:03 2003 +0000
     1.2 +++ b/tools/internal/xi_phys_grant.c	Tue Jul 08 11:23:36 2003 +0000
     1.3 @@ -29,9 +29,10 @@ int main(int argc, char *argv[])
     1.4    else if (argv[1][1] == 'w')
     1.5      buf.mode |= 2;
     1.6    
     1.7 -  buf.device = atol(argv[3]) + atol(argv[6]);
     1.8 +  buf.device = atol(argv[3]);
     1.9    buf.start_sect = atol(argv[4]);
    1.10    buf.n_sectors = atol(argv[5]);
    1.11 +  buf.partition = atol(argv[6]);
    1.12  
    1.13    asprintf(&strbuf, "/proc/xeno/dom%s/phd", argv[2]);
    1.14    fd = open(strbuf, O_WRONLY);
     2.1 --- a/tools/internal/xi_phys_probe.c	Tue Jul 08 09:06:03 2003 +0000
     2.2 +++ b/tools/internal/xi_phys_probe.c	Tue Jul 08 11:23:36 2003 +0000
     2.3 @@ -39,7 +39,8 @@ int main(int argc, char *argv[])
     2.4      for (x = 0; x < buf.n_aces; x++) {
     2.5        char read = ( buf.entries[x].mode & 1 ? 'r' : ' ' );
     2.6        char write = ( buf.entries[x].mode & 2 ? 'w' : ' ' );
     2.7 -      printf("%x %lx %lx %c%c\n", buf.entries[x].device,
     2.8 +      printf("%x %x %lx %lx %c%c\n", buf.entries[x].device,
     2.9 +	     buf.entries[x].partition,
    2.10  	     buf.entries[x].start_sect,
    2.11  	     buf.entries[x].n_sectors,
    2.12  	     read,
     3.1 --- a/xen/drivers/block/xen_physdisk.c	Tue Jul 08 09:06:03 2003 +0000
     3.2 +++ b/xen/drivers/block/xen_physdisk.c	Tue Jul 08 11:23:36 2003 +0000
     3.3 @@ -25,6 +25,7 @@ struct physdisk_ace {
     3.4    struct list_head list;
     3.5  
     3.6    unsigned short device;
     3.7 +  unsigned short partition;
     3.8    unsigned long start_sect;
     3.9    unsigned long n_sectors;
    3.10    int mode;
    3.11 @@ -40,8 +41,6 @@ static struct physdisk_ace *find_ace(con
    3.12    struct list_head *cur_ace_head;
    3.13    struct physdisk_ace *cur_ace;
    3.14  
    3.15 -  dev &= ~0x1f; /* ignore the partition part */
    3.16 -
    3.17    list_for_each(cur_ace_head, &p->physdisk_aces) {
    3.18      cur_ace = list_entry(cur_ace_head, struct physdisk_ace,
    3.19  			 list);
    3.20 @@ -50,7 +49,7 @@ static struct physdisk_ace *find_ace(con
    3.21  	    sect);
    3.22      if (sect >= cur_ace->start_sect &&
    3.23  	sect < cur_ace->start_sect + cur_ace->n_sectors &&
    3.24 -	dev == (cur_ace->device & ~0x1f) && /* ignore partition part */
    3.25 +	dev == cur_ace->device &&
    3.26  	((operation == READ && (cur_ace->mode & PHYSDISK_MODE_R)) ||
    3.27  	 (operation == WRITE && (cur_ace->mode & PHYSDISK_MODE_W)))) {
    3.28        DPRINTK("Yes.\n");
    3.29 @@ -85,7 +84,7 @@ static void xen_physdisk_revoke_access(u
    3.30      ace_end = cur_ace->start_sect + cur_ace->n_sectors;
    3.31      if (cur_ace->start_sect >= kill_zone_end ||
    3.32  	ace_end <= start_sect ||
    3.33 -	(cur_ace->device & ~0x1f) != (dev & ~0x1f))
    3.34 +	cur_ace->device != dev)
    3.35        continue;
    3.36      
    3.37      DPRINTK("Killing ace [%lx, %lx) against kill zone [%lx, %lx)\n",
    3.38 @@ -111,7 +110,7 @@ static void xen_physdisk_revoke_access(u
    3.39        /* Cut the current ace down to just the bit before the kzone,
    3.40  	 create a new ace for the bit just after it. */ 
    3.41        new_ace = kmalloc(sizeof(*cur_ace), GFP_KERNEL);
    3.42 -      new_ace->device = dev & ~0x1f;
    3.43 +      new_ace->device = dev;
    3.44        new_ace->start_sect = kill_zone_end;
    3.45        new_ace->n_sectors = ace_end - kill_zone_end;
    3.46        new_ace->mode = cur_ace->mode;
    3.47 @@ -125,6 +124,7 @@ static void xen_physdisk_revoke_access(u
    3.48  
    3.49  /* Hold the lock on entry, it remains held on exit. */
    3.50  static int xen_physdisk_grant_access(unsigned short dev,
    3.51 +				     unsigned short partition,
    3.52  				     unsigned long start_sect,
    3.53  				     unsigned long n_sectors,
    3.54  				     int mode,
    3.55 @@ -143,6 +143,7 @@ static int xen_physdisk_grant_access(uns
    3.56      cur_ace->start_sect = start_sect;
    3.57      cur_ace->n_sectors = n_sectors;
    3.58      cur_ace->mode = mode;
    3.59 +    cur_ace->partition = partition;
    3.60  
    3.61      list_add_tail(&cur_ace->list, &p->physdisk_aces);
    3.62    }
    3.63 @@ -167,6 +168,7 @@ static void xen_physdisk_probe_access(ph
    3.64        cur_ace = list_entry(cur_ace_head, struct physdisk_ace,
    3.65  			   list);
    3.66        buf->entries[n_aces].device = cur_ace->device;
    3.67 +      buf->entries[n_aces].partition = cur_ace->partition;
    3.68        buf->entries[n_aces].start_sect = cur_ace->start_sect;
    3.69        buf->entries[n_aces].n_sectors = cur_ace->n_sectors;
    3.70        buf->entries[n_aces].mode = cur_ace->mode;
    3.71 @@ -196,6 +198,7 @@ int xen_physdisk_grant(xp_disk_t *xpd_in
    3.72    }
    3.73    spin_lock(&p->physdev_lock);
    3.74    res = xen_physdisk_grant_access(xpd->device,
    3.75 +				  xpd->partition,
    3.76  				  xpd->start_sect,
    3.77  				  xpd->n_sectors,
    3.78  				  xpd->mode,
     4.1 --- a/xen/include/hypervisor-ifs/block.h	Tue Jul 08 09:06:03 2003 +0000
     4.2 +++ b/xen/include/hypervisor-ifs/block.h	Tue Jul 08 11:23:36 2003 +0000
     4.3 @@ -149,18 +149,20 @@ typedef struct xp_disk
     4.4    int mode; /* 0 -> revoke existing access, otherwise bitmask of
     4.5  	       PHYSDISK_MODE_? constants */
     4.6    int domain;
     4.7 -  unsigned short device;
     4.8 +  unsigned short device; /* XENDEV_??? + idx */
     4.9 +  unsigned short partition; /* partition number */
    4.10    unsigned long start_sect;
    4.11    unsigned long n_sectors;
    4.12  } xp_disk_t;
    4.13  
    4.14 -#define PHYSDISK_MAX_ACES_PER_REQUEST 254
    4.15 +#define PHYSDISK_MAX_ACES_PER_REQUEST 254 /* Make it fit in one page */
    4.16  typedef struct {
    4.17    int n_aces;
    4.18    int domain;
    4.19    int start_ind;
    4.20    struct {
    4.21 -    unsigned short device;
    4.22 +    unsigned short device; /* XENDEV_??? + idx */
    4.23 +    unsigned short partition; /* partition number */
    4.24      unsigned long start_sect;
    4.25      unsigned long n_sectors;
    4.26      unsigned mode;
     5.1 --- a/xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_physdisk_proc.c	Tue Jul 08 09:06:03 2003 +0000
     5.2 +++ b/xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_physdisk_proc.c	Tue Jul 08 11:23:36 2003 +0000
     5.3 @@ -8,7 +8,35 @@
     5.4  #include <asm/uaccess.h>
     5.5  #include <linux/proc_fs.h>
     5.6  
     5.7 +#include "xl_block.h"
     5.8 +
     5.9  extern int xenolinux_control_msg(int operration, char *buffer, int size);
    5.10 +extern unsigned short xldev_to_physdev(kdev_t xldev);
    5.11 +
    5.12 +static dev_t physdev_to_xldev(unsigned short physdev)
    5.13 +{
    5.14 +  switch (physdev & XENDEV_TYPE_MASK) {
    5.15 +  case XENDEV_IDE:
    5.16 +    switch (physdev & XENDEV_IDX_MASK) {
    5.17 +    case 0 ... (XLIDE_DEVS_PER_MAJOR-1):
    5.18 +      return MKDEV(XLIDE_MAJOR_0,
    5.19 +		   (physdev & XENDEV_IDX_MASK) << XLIDE_PARTN_SHIFT);
    5.20 +    case XLIDE_DEVS_PER_MAJOR ... (XLIDE_DEVS_PER_MAJOR * 2 - 1):
    5.21 +      return MKDEV(XLIDE_MAJOR_1,
    5.22 +		   (physdev & XENDEV_IDX_MASK) << XLIDE_PARTN_SHIFT);
    5.23 +    }
    5.24 +    break;
    5.25 +  case XENDEV_SCSI:
    5.26 +    return MKDEV(XLSCSI_MAJOR,
    5.27 +		 (physdev & XENDEV_IDX_MASK) << XLSCSI_PARTN_SHIFT);
    5.28 +  case XENDEV_VIRTUAL:
    5.29 +    return MKDEV(XLVIRT_MAJOR,
    5.30 +		 (physdev & XENDEV_IDX_MASK) << XLVIRT_PARTN_SHIFT);
    5.31 +  }
    5.32 +  printk(KERN_ALERT "Unrecognised xl device: %x\n", physdev);
    5.33 +  BUG();
    5.34 +  return -1;
    5.35 +}
    5.36  
    5.37  static ssize_t proc_read_phd(struct file * file, char * buff, size_t size,
    5.38  			     loff_t * off)
    5.39 @@ -16,6 +44,7 @@ static ssize_t proc_read_phd(struct file
    5.40    physdisk_probebuf_t *buf;
    5.41    int res;
    5.42    struct proc_dir_entry *pde;
    5.43 +  int x;
    5.44  
    5.45    if (size != sizeof(physdisk_probebuf_t))
    5.46      return -EINVAL;
    5.47 @@ -24,11 +53,6 @@ static ssize_t proc_read_phd(struct file
    5.48    if (!buf)
    5.49      return -ENOMEM;
    5.50  
    5.51 -  if (copy_from_user(buf, buff, size)) {
    5.52 -    kfree(buf);
    5.53 -    return -EFAULT;
    5.54 -  }
    5.55 -
    5.56    pde = file->f_dentry->d_inode->u.generic_ip;
    5.57    buf->domain = (int)pde->data;
    5.58  
    5.59 @@ -43,6 +67,8 @@ static ssize_t proc_read_phd(struct file
    5.60    if (res)
    5.61      res = -EINVAL;
    5.62    else {
    5.63 +    for (x = 0; x < buf->n_aces; x++)
    5.64 +      buf->entries[x].device = physdev_to_xldev(buf->entries[x].device);
    5.65      res = sizeof(physdisk_probebuf_t);
    5.66      if (copy_to_user(buff, buf, sizeof(physdisk_probebuf_t))) {
    5.67        res = -EFAULT;
    5.68 @@ -75,6 +101,7 @@ static int proc_write_phd(struct file *f
    5.69  
    5.70    pde = file->f_dentry->d_inode->u.generic_ip;
    5.71    xpd->domain = (int)pde->data;
    5.72 +  xpd->device = xldev_to_physdev(xpd->device);
    5.73  
    5.74    res = xenolinux_control_msg(XEN_BLOCK_PHYSDEV_GRANT, local, count);
    5.75    if (res == 0)
     6.1 --- a/xenolinux-2.4.21-sparse/fs/partitions/xeno.c	Tue Jul 08 09:06:03 2003 +0000
     6.2 +++ b/xenolinux-2.4.21-sparse/fs/partitions/xeno.c	Tue Jul 08 11:23:36 2003 +0000
     6.3 @@ -43,18 +43,18 @@ int xeno_partition(struct gendisk *hd,
     6.4    count = 0;
     6.5  
     6.6    for (i = 0; i < buf->n_aces; i++) {
     6.7 -    if ((buf->entries[i].device & 0x1f) == 0)
     6.8 +    if (buf->entries[i].partition == 0)
     6.9        continue;
    6.10      /* Make sure the partition is actually supposed to be on this
    6.11         disk.  This assumes that Xen and XenoLinux block device
    6.12         numbers match up. */
    6.13 -    if ((buf->entries[i].device & ~0x1f) != bdev->bd_dev)
    6.14 +    if (buf->entries[i].device != bdev->bd_dev)
    6.15        continue;
    6.16      /* This is a bit of a hack - the partition numbers are specified
    6.17         by the hypervisor, and if we want them to match up, this is
    6.18         what we need to do. */
    6.19      count ++;
    6.20 -    minor = (buf->entries[i].device & 0x1f) + first_part_minor - 1;
    6.21 +    minor = buf->entries[i].partition + first_part_minor - 1;
    6.22      add_gd_partition(hd,
    6.23  		     minor,
    6.24  		     buf->entries[i].start_sect,