WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xc: deal with xen/evtchn and xen/gntdev d

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xc: deal with xen/evtchn and xen/gntdev device names
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 31 May 2010 23:15:24 -0700
Delivery-date: Mon, 31 May 2010 23:15:52 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1275372275 -3600
# Node ID 0610f0de49fe3cf34b72ea6b01064c5c424f5737
# Parent  f41f1ae36b66ab9db88aa35ab3b161af34196ba1
xc: deal with xen/evtchn and xen/gntdev device names

This patch makes xc_linux properly deal with:
 1. discovering and creating device nodes if necessary
 2. the new form of xen/<dev> device names soon to be used by the
 kernel

This changes the logic slightly:
 - If a device node already exists with the proper name, then it uses
 it as-is, assuming it has already been correctly created.
 - If the path doesn't exist, or it exists but isn't a device node,
 and
   it has successfully found the major/minor for the device, then
   (re)create the device node.

Since this logic is identical for gntdev and evtchn, make a common
function to handle both.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
---
 tools/libxc/xc_linux.c |  106 +++++++++++++++++++++++++------------------------
 1 files changed, 56 insertions(+), 50 deletions(-)

diff -r f41f1ae36b66 -r 0610f0de49fe tools/libxc/xc_linux.c
--- a/tools/libxc/xc_linux.c    Tue Jun 01 06:55:23 2010 +0100
+++ b/tools/libxc/xc_linux.c    Tue Jun 01 07:04:35 2010 +0100
@@ -378,33 +378,64 @@ int xc_find_device_number(const char *na
     return makedev(major, minor);
 }
 
-#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
+#define DEVXEN "/dev/xen"
+
+static int make_dev_xen(void)
+{
+    if ( mkdir(DEVXEN, 0755) != 0 )
+    {
+        struct stat st;
+        if ( (stat(DEVXEN, &st) != 0) || !S_ISDIR(st.st_mode) )
+            return -1;
+    }
+
+    return 0;
+}
+
+static int xendev_open(const char *dev)
+{
+    int fd, devnum;
+    struct stat st;
+    char *devname, *devpath;
+
+    devname = devpath = NULL;
+    fd = -1;
+
+    if ( asprintf(&devname, "xen!%s", dev) == 0 )
+        goto fail;
+
+    if ( asprintf(&devpath, "%s/%s", DEVXEN, dev) == 0 )
+        goto fail;
+
+    devnum = xc_find_device_number(dev);
+    if ( devnum == -1 )
+        devnum = xc_find_device_number(devname);
+
+    /*
+     * If we know what the correct device is and the path doesn't exist or 
+     * isn't a device, then remove it so we can create the device.
+     */
+    if ( (devnum != -1) &&
+         ((stat(devpath, &st) != 0) || !S_ISCHR(st.st_mode)) )
+    {
+        unlink(devpath);
+        if ( (make_dev_xen() == -1) ||
+             (mknod(devpath, S_IFCHR|0600, devnum) != 0) )
+            goto fail;
+    }
+
+    fd = open(devpath, O_RDWR);
+
+ fail:
+    free(devname);
+    free(devpath);
+
+    return fd;
+}
 
 int xc_evtchn_open(void)
 {
-    struct stat st;
-    int fd;
-    int devnum;
-
-    devnum = xc_find_device_number("evtchn");
-
-    /* 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 != devnum) )
-        (void)unlink(EVTCHN_DEV_NAME);
-
- reopen:
-    if ( (fd = open(EVTCHN_DEV_NAME, O_RDWR)) == -1 )
-    {
-        if ( (errno == ENOENT) &&
-             ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
-             (mknod(EVTCHN_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
-            goto reopen;
-
-        return -1;
-    }
-
-    return fd;
+    return xendev_open("evtchn");
 }
 
 int xc_evtchn_close(int xce_handle)
@@ -518,34 +549,9 @@ void discard_file_cache(xc_interface *xc
     errno = saved_errno;
 }
 
-#define GNTTAB_DEV_NAME "/dev/xen/gntdev"
-
 int xc_gnttab_open(xc_interface *xch)
 {
-    struct stat st;
-    int fd;
-    int devnum;
-
-    devnum = xc_find_device_number("gntdev");
-
-    /* Make sure any existing device file links to correct device. */
-    if ( (lstat(GNTTAB_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
-         (st.st_rdev != devnum) )
-        (void)unlink(GNTTAB_DEV_NAME);
-
-reopen:
-    if ( (fd = open(GNTTAB_DEV_NAME, O_RDWR)) == -1 )
-    {
-        if ( (errno == ENOENT) &&
-             ((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
-             (mknod(GNTTAB_DEV_NAME, S_IFCHR|0600, devnum) == 0) )
-            goto reopen;
-
-        PERROR("Could not open grant table interface");
-        return -1;
-    }
-
-    return fd;
+    return xendev_open("gntdev");
 }
 
 int xc_gnttab_close(xc_interface *xch, int xcg_handle)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xc: deal with xen/evtchn and xen/gntdev device names, Xen patchbot-unstable <=