Along with the blktap hardcoding of a major number. It has come to my
attention that evtchn also hardcodes a minor number. Not so bad, but
can later cause conflicts. evtchn uses the misc device to get its major
number.
This patch makes evtchn use a dynamic minor number instead. It also
updates 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.
One thing that is missing though, in this patch, is the update to
./debugger/pdb/evtchn.ml, which still has the hard coded 201 as the
minor. This calls evtchn_open which is a C function that creates the
node if it doesn't already exist. I don't know much about Modula-2 but
the major and minor probably don't need to be passed in, and the C code
can do the same thing as the tools do now. But I'll let others decide
on that.
-- Steve
Signed-off-by: Steven Rostedt <srostedt@xxxxxxxxxx>
diff -r 748e3c64d8f1 linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c
--- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c Thu Sep 28 10:04:25
2006 -0400
+++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c Thu Sep 28 20:55:10
2006 -0400
@@ -419,7 +419,7 @@ static struct file_operations evtchn_fop
};
static struct miscdevice evtchn_miscdev = {
- .minor = EVTCHN_MINOR,
+ .minor = MISC_DYNAMIC_MINOR,
.name = "evtchn",
.fops = &evtchn_fops,
.devfs_name = "misc/evtchn",
diff -r 748e3c64d8f1 linux-2.6-xen-sparse/include/xen/public/evtchn.h
--- a/linux-2.6-xen-sparse/include/xen/public/evtchn.h Thu Sep 28 10:04:25
2006 -0400
+++ b/linux-2.6-xen-sparse/include/xen/public/evtchn.h Thu Sep 28 20:55:10
2006 -0400
@@ -32,9 +32,6 @@
#ifndef __LINUX_PUBLIC_EVTCHN_H__
#define __LINUX_PUBLIC_EVTCHN_H__
-
-/* /dev/xen/evtchn resides at device number major=10, minor=201 */
-#define EVTCHN_MINOR 201
/*
* Bind a fresh port to VIRQ @virq.
diff -r 748e3c64d8f1 tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c Thu Sep 28 10:04:25 2006 -0400
+++ b/tools/libxc/xc_linux.c Thu Sep 28 20:55:10 2006 -0400
@@ -135,16 +135,71 @@ int do_xen_hypercall(int xc_handle, priv
#define EVTCHN_DEV_NAME "/dev/xen/evtchn"
#define EVTCHN_DEV_MAJOR 10
-#define EVTCHN_DEV_MINOR 201
+
+#define MTAB "/proc/mounts"
+#define EVTCHN_SYSFS_PATH "/class/misc/evtchn/dev"
+
+#define MAX_PATH 255
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+static char sysfsdir[MAX_PATH + 1];
+
+static int find_sysfsdir(void)
+{
+ FILE *fp;
+ char type[MAX_PATH + 1];
+
+ if ((fp = fopen(MTAB, "r")) == NULL)
+ return -1;
+
+ while (fscanf(fp, "%*s %"
+ STR(MAX_PATH)
+ "s %"
+ STR(MAX_PATH)
+ "s %*s %*d %*d\n",
+ sysfsdir, type) == 2) {
+ if (strncmp(type, "sysfs", 5) == 0)
+ break;
+ }
+ fclose(fp);
+
+ return strncmp(type, "sysfs", 5) == 0 ? 0 : -1;
+}
+
+static int find_evtchn_minor(void)
+{
+ FILE *fp;
+ int major;
+ int minor;
+
+ if (find_sysfsdir() < 0)
+ return -1;
+
+ strncat(sysfsdir, EVTCHN_SYSFS_PATH, MAX_PATH);
+
+ if ((fp = fopen(sysfsdir, "r")) == NULL)
+ return -1;
+
+ /* Skip title */
+ fscanf(fp,"%d:%d",&major, &minor);
+
+ fclose(fp);
+
+ return minor;
+}
int xc_evtchn_open(void)
{
struct stat st;
int fd;
+ int minor;
+
+ minor = find_evtchn_minor();
/* Make sure any existing device file links to correct device. */
if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
- (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
+ (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, minor)))
(void)unlink(EVTCHN_DEV_NAME);
reopen:
@@ -153,7 +208,7 @@ reopen:
if ( (errno == ENOENT) &&
((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
(mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
- makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0) )
+ makedev(EVTCHN_DEV_MAJOR, minor)) == 0) )
goto reopen;
PERROR("Could not open event channel interface");
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|