ia64/xen-unstable

changeset 11689:7e79259c2c17

[LINUX] Make evtchn device use a dynamic minor number.

Also update the code in tools to create the device node if udev fails.
The tools now read the sysfs system to find the minor number needed.

Original patch from Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Sep 29 14:20:52 2006 +0100 (2006-09-29)
parents 477a0084ff47
children 509ff527c59d
files linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c linux-2.6-xen-sparse/include/xen/public/evtchn.h tools/libxc/xc_linux.c tools/libxc/xenctrl.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Fri Sep 29 11:57:06 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Fri Sep 29 14:20:52 2006 +0100
     1.3 @@ -419,10 +419,9 @@ static struct file_operations evtchn_fop
     1.4  };
     1.5  
     1.6  static struct miscdevice evtchn_miscdev = {
     1.7 -	.minor        = EVTCHN_MINOR,
     1.8 +	.minor        = MISC_DYNAMIC_MINOR,
     1.9  	.name         = "evtchn",
    1.10  	.fops         = &evtchn_fops,
    1.11 -	.devfs_name   = "misc/evtchn",
    1.12  };
    1.13  
    1.14  static int __init evtchn_init(void)
     2.1 --- a/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Fri Sep 29 11:57:06 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/include/xen/public/evtchn.h	Fri Sep 29 14:20:52 2006 +0100
     2.3 @@ -33,9 +33,6 @@
     2.4  #ifndef __LINUX_PUBLIC_EVTCHN_H__
     2.5  #define __LINUX_PUBLIC_EVTCHN_H__
     2.6  
     2.7 -/* /dev/xen/evtchn resides at device number major=10, minor=201 */
     2.8 -#define EVTCHN_MINOR 201
     2.9 -
    2.10  /*
    2.11   * Bind a fresh port to VIRQ @virq.
    2.12   * Return allocated port.
     3.1 --- a/tools/libxc/xc_linux.c	Fri Sep 29 11:57:06 2006 +0100
     3.2 +++ b/tools/libxc/xc_linux.c	Fri Sep 29 14:20:52 2006 +0100
     3.3 @@ -133,27 +133,95 @@ int do_xen_hypercall(int xc_handle, priv
     3.4                        (unsigned long)hypercall);
     3.5  }
     3.6  
     3.7 +#define MTAB "/proc/mounts"
     3.8 +#define MAX_PATH 255
     3.9 +#define _STR(x) #x
    3.10 +#define STR(x) _STR(x)
    3.11 +
    3.12 +static int find_sysfsdir(char *sysfsdir)
    3.13 +{
    3.14 +    FILE *fp;
    3.15 +    char type[MAX_PATH + 1];
    3.16 +
    3.17 +    if ( (fp = fopen(MTAB, "r")) == NULL )
    3.18 +        return -1;
    3.19 +
    3.20 +    while ( fscanf(fp, "%*s %"
    3.21 +                   STR(MAX_PATH)
    3.22 +                   "s %"
    3.23 +                   STR(MAX_PATH)
    3.24 +                   "s %*s %*d %*d\n",
    3.25 +                   sysfsdir, type) == 2 )
    3.26 +    {
    3.27 +        if ( strncmp(type, "sysfs", 5) == 0 )
    3.28 +            break;
    3.29 +    }
    3.30 +
    3.31 +    fclose(fp);
    3.32 +
    3.33 +    return ((strncmp(type, "sysfs", 5) == 0) ? 0 : -1);
    3.34 +}
    3.35 +
    3.36 +int xc_find_device_number(const char *name)
    3.37 +{
    3.38 +    FILE *fp;
    3.39 +    int i, major, minor;
    3.40 +    char sysfsdir[MAX_PATH + 1];
    3.41 +    static char *classlist[] = { "xen", "misc" };
    3.42 +
    3.43 +    for ( i = 0; i < (sizeof(classlist) / sizeof(classlist[0])); i++ )
    3.44 +    {
    3.45 +        if ( find_sysfsdir(sysfsdir) < 0 )
    3.46 +            goto not_found;
    3.47 +
    3.48 +        /* <base>/class/<classname>/<devname>/dev */
    3.49 +        strncat(sysfsdir, "/class/", MAX_PATH);
    3.50 +        strncat(sysfsdir, classlist[i], MAX_PATH);
    3.51 +        strncat(sysfsdir, "/", MAX_PATH);
    3.52 +        strncat(sysfsdir, name, MAX_PATH);
    3.53 +        strncat(sysfsdir, "/dev", MAX_PATH);
    3.54 +
    3.55 +        if ( (fp = fopen(sysfsdir, "r")) != NULL )
    3.56 +            goto found;
    3.57 +    }
    3.58 +
    3.59 + not_found:
    3.60 +    errno = -ENOENT;
    3.61 +    return -1;
    3.62 +
    3.63 + found:
    3.64 +    if ( fscanf(fp, "%d:%d", &major, &minor) != 2 )
    3.65 +    {
    3.66 +        fclose(fp);
    3.67 +        goto not_found;
    3.68 +    }
    3.69 +
    3.70 +    fclose(fp);
    3.71 +
    3.72 +    return makedev(major, minor);
    3.73 +}
    3.74 +
    3.75  #define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
    3.76 -#define EVTCHN_DEV_MAJOR 10
    3.77 -#define EVTCHN_DEV_MINOR 201
    3.78  
    3.79  int xc_evtchn_open(void)
    3.80  {
    3.81      struct stat st;
    3.82      int fd;
    3.83 +    int devnum;
    3.84 +
    3.85 +    devnum = xc_find_device_number("evtchn");
    3.86  
    3.87      /* Make sure any existing device file links to correct device. */
    3.88 -    if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
    3.89 -        (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
    3.90 +    if ( (lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
    3.91 +         (st.st_rdev != devnum) )
    3.92          (void)unlink(EVTCHN_DEV_NAME);
    3.93  
    3.94 -reopen:
    3.95 + reopen:
    3.96      if ( (fd = open(EVTCHN_DEV_NAME, O_RDWR)) == -1 )
    3.97      {
    3.98          if ( (errno == ENOENT) &&
    3.99              ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
   3.100 -            (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
   3.101 -            makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0) )
   3.102 +             (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
   3.103              goto reopen;
   3.104  
   3.105          PERROR("Could not open event channel interface");
     4.1 --- a/tools/libxc/xenctrl.h	Fri Sep 29 11:57:06 2006 +0100
     4.2 +++ b/tools/libxc/xenctrl.h	Fri Sep 29 14:20:52 2006 +0100
     4.3 @@ -92,6 +92,16 @@ int xc_interface_open(void);
     4.4  int xc_interface_close(int xc_handle);
     4.5  
     4.6  /*
     4.7 + * KERNEL INTERFACES
     4.8 + */
     4.9 +
    4.10 +/*
    4.11 + * Resolve a kernel device name (e.g., "evtchn", "blktap0") into a kernel
    4.12 + * device number. Returns -1 on error (and sets errno).
    4.13 + */
    4.14 +int xc_find_device_number(const char *name);
    4.15 +
    4.16 +/*
    4.17   * DOMAIN DEBUGGING FUNCTIONS
    4.18   */
    4.19