Module: xenomai-forge
Branch: next
Commit: e3f8361d1c6c26f00e17d361550f5f3e8da874f7
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e3f8361d1c6c26f00e17d361550f5f3e8da874f7

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Sep 17 16:40:21 2014 +0200

cobalt/rtdm, lib/cobalt: open named device on allocated devnode

Now that named devices exist in the linux namespace (/dev/rtdm), file
descriptors can be obtained on the associated chrdev, instead of the
anon inode.

With this change, active connections to RTDM named devices are visible
from /proc/<pid>/fd.

---

 kernel/cobalt/posix/io.c           |   51 ++++++++++++++++++++++++++++++------
 kernel/cobalt/rtdm/core.c          |    6 +----
 kernel/cobalt/rtdm/device.c        |   13 +++++++++
 kernel/cobalt/rtdm/internal.h      |    2 ++
 kernel/drivers/testing/rtdmtest.c  |    2 +-
 lib/cobalt/umm.c                   |    4 ++-
 testsuite/latency/latency.c        |    7 ++---
 testsuite/regression/posix/leaks.c |    8 +++---
 testsuite/smokey/rtdm/rtdm.c       |    4 +--
 testsuite/switchtest/switchtest.c  |    8 +++---
 utils/autotune/autotune.c          |    2 +-
 11 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c
index 9810c32..d6d5dc3 100644
--- a/kernel/cobalt/posix/io.c
+++ b/kernel/cobalt/posix/io.c
@@ -32,20 +32,55 @@
 COBALT_SYSCALL(open, lostage,
               int, (const char __user *u_path, int oflag))
 {
-       char path[RTDM_MAX_DEVNAME_LEN + 1];
+       struct rtdm_device *device;
+       struct filename *filename;
        struct xnsys_ppd *ppd;
+       struct file *filp;
        int ufd, ret;
 
-       if (__xn_safe_strncpy_from_user(path, u_path, sizeof(path)-1) < 0)
-               return -EFAULT;
+       filename = getname(u_path);
+       if (IS_ERR(filename))
+               return PTR_ERR(filename);
+
+       /*
+        * Lookup for the device into the RTDM registry: if we don't
+        * own the device, tell userland to forward to the regular
+        * open() service.
+        */
+       device = __rtdm_get_namedev(filename->name);
+       if (device == NULL) {
+               ret = -ENODEV;
+               goto fail_lookup;
+       }
 
-       path[sizeof(path)-1] = '\0';
-       ppd = cobalt_ppd_get(0);
-       ufd = anon_inode_getfd("[rtdm-named]", &rtdm_dumb_fops, ppd, oflag);
+       ufd = get_unused_fd_flags(oflag);
+       if (ufd < 0) {
+               ret = ufd;
+               goto fail_ufd;
+       }
 
-       ret = __rt_dev_open(ppd, ufd, path, oflag);
+       filp = filp_open(filename->name, oflag, 0);
+       if (IS_ERR(filp)) {
+               ret = PTR_ERR(filp);
+               goto fail;
+       }
+
+       ppd = cobalt_ppd_get(0);
+       ret = __rt_dev_open(ppd, ufd, filename->name, oflag);
        if (ret < 0)
-               __close_fd(current->files, ufd);
+               goto fail;
+
+       rtdm_dereference_device(device);
+       fd_install(ufd, filp);
+       putname(filename);
+
+       return ufd;
+fail:
+       put_unused_fd(ufd);
+fail_ufd:
+       rtdm_dereference_device(device);
+fail_lookup:
+       putname(filename);
 
        return ret;
 }
diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c
index 56ecbaa..d46e7a0 100644
--- a/kernel/cobalt/rtdm/core.c
+++ b/kernel/cobalt/rtdm/core.c
@@ -155,11 +155,7 @@ int __rt_dev_open(struct xnsys_ppd *p, int ufd, const char 
*path, int oflag)
        struct rtdm_device *device;
        int ret, minor;
 
-       /* skip common /dev prefix */
-       if (strncmp(path, "/dev/", 5) == 0)
-               path += 5;
-
-       device = __rtdm_get_named_device(path, &minor);
+       device = __rtdm_get_namedev(path);
        if (device == NULL)
                return -ENODEV;
 
diff --git a/kernel/cobalt/rtdm/device.c b/kernel/cobalt/rtdm/device.c
index 4727d67..bbe5be0 100644
--- a/kernel/cobalt/rtdm/device.c
+++ b/kernel/cobalt/rtdm/device.c
@@ -142,6 +142,19 @@ __rtdm_get_protocol_device(int protocol_family, int 
socket_type)
        return device;
 }
 
+struct rtdm_device *__rtdm_get_namedev(const char *path)
+{
+       /* skip common /dev prefix */
+       if (strncmp(path, "/dev/", 5) == 0)
+               path += 5;
+
+       /* skip RTDM devnode root */
+       if (strncmp(path, "rtdm/", 5) == 0)
+               path += 5;
+
+       return __rtdm_get_named_device(path);
+}
+
 /**
  * @ingroup rtdm_driver_interface
  * @defgroup rtdm_device_register Device Registration Services
diff --git a/kernel/cobalt/rtdm/internal.h b/kernel/cobalt/rtdm/internal.h
index 985e01f..f6ab158 100644
--- a/kernel/cobalt/rtdm/internal.h
+++ b/kernel/cobalt/rtdm/internal.h
@@ -77,6 +77,8 @@ void __rt_dev_unref(struct rtdm_fd *fd, unsigned int idx);
 int __rtdm_mmap_from_fdop(struct rtdm_fd *fd, size_t len, off_t offset,
                          int prot, int flags, void *__user *pptr);
 
+struct rtdm_device *__rtdm_get_namedev(const char *path);
+
 int rtdm_init(void);
 
 void rtdm_cleanup(void);
diff --git a/kernel/drivers/testing/rtdmtest.c 
b/kernel/drivers/testing/rtdmtest.c
index 2e671ba..79a174e 100644
--- a/kernel/drivers/testing/rtdmtest.c
+++ b/kernel/drivers/testing/rtdmtest.c
@@ -123,7 +123,7 @@ static struct rtdm_device_class rtdmtest = {
 static struct rtdm_device device[2] = {
        [0 ... 1] = {
                .class = &rtdmtest,
-               .label = "rttest-rtdm%d",
+               .label = "rtdm%d",
        }
 };
 
diff --git a/lib/cobalt/umm.c b/lib/cobalt/umm.c
index 7ae57f2..1ec05ec 100644
--- a/lib/cobalt/umm.c
+++ b/lib/cobalt/umm.c
@@ -44,7 +44,7 @@ static pthread_once_t init_bind_once = PTHREAD_ONCE_INIT;
 
 static uint32_t private_size;
 
-static void *map_umm(const char *name, uint32_t *size_r)
+static void *__map_umm(const char *name, uint32_t *size_r)
 {
        struct cobalt_memdev_stat statbuf;
        int fd, ret;
@@ -73,6 +73,8 @@ static void *map_umm(const char *name, uint32_t *size_r)
        return addr;
 }
 
+#define map_umm(__name, __size_r)  __map_umm("/dev/rtdm/" __name, __size_r)
+
 static void unmap_on_fork(void)
 {
        void *addr;
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index c6097b2..20ccd48 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -745,14 +745,15 @@ int main(int argc, char *const *argv)
        if (test_mode != USER_TASK) {
                char devname[RTDM_MAX_DEVNAME_LEN];
 
-               snprintf(devname, RTDM_MAX_DEVNAME_LEN, "rttest-timerbench%d",
+               snprintf(devname, RTDM_MAX_DEVNAME_LEN,
+                        "/dev/rtdm/timerbench%d",
                         benchdev_no);
                benchdev = open(devname, O_RDWR);
 
                if (benchdev < 0) {
                        fprintf(stderr,
-                               "latency: failed to open benchmark device, code 
%d\n"
-                               "(modprobe xeno_timerbench?)\n", errno);
+                               "latency: cannot open %s: %m\n"
+                               "(modprobe xeno_timerbench?)\n", devname);
                        return 0;
                }
        }
diff --git a/testsuite/regression/posix/leaks.c 
b/testsuite/regression/posix/leaks.c
index db39c8f..c1a727d 100644
--- a/testsuite/regression/posix/leaks.c
+++ b/testsuite/regression/posix/leaks.c
@@ -34,12 +34,14 @@
                        fprintf(stderr, object ": OK\n");               \
        })
 
+#define devnode_root "/dev/rtdm/"
+
 static unsigned long long get_used(void)
 {
        const char *memdev[] = {
-               COBALT_MEMDEV_PRIVATE,
-               COBALT_MEMDEV_SHARED,
-               COBALT_MEMDEV_SYS,
+               devnode_root COBALT_MEMDEV_PRIVATE,
+               devnode_root COBALT_MEMDEV_SHARED,
+               devnode_root COBALT_MEMDEV_SYS,
                NULL,
        };
        struct cobalt_memdev_stat statbuf;
diff --git a/testsuite/smokey/rtdm/rtdm.c b/testsuite/smokey/rtdm/rtdm.c
index b2494b1..f67cc95 100644
--- a/testsuite/smokey/rtdm/rtdm.c
+++ b/testsuite/smokey/rtdm/rtdm.c
@@ -70,8 +70,8 @@ static void check_sleep_inner(const char *fn, int line,
 #define check_sleep(msg, start) \
        check_sleep_inner(__FUNCTION__, __LINE__, msg, start)
 
-static const char *devname = "/dev/rttest-rtdm0";
-static const char *devname2 = "/dev/rttest-rtdm1";
+static const char *devname = "/dev/rtdm/rtdm0";
+static const char *devname2 = "/dev/rtdm/rtdm1";
 
 static int run_rtdm(struct smokey_test *t, int argc, char *const argv[])
 {
diff --git a/testsuite/switchtest/switchtest.c 
b/testsuite/switchtest/switchtest.c
index b8b47a6..8232cb2 100644
--- a/testsuite/switchtest/switchtest.c
+++ b/testsuite/switchtest/switchtest.c
@@ -899,7 +899,7 @@ static int open_rttest(char *buf, size_t size, unsigned 
count)
        int fd, status;
 
        do {
-               snprintf(buf, size, "/dev/rttest-switchtest%d", dev_nr);
+               snprintf(buf, size, "/dev/rtdm/switchtest%d", dev_nr);
 
                status = fd = open(buf, O_RDWR);
 
@@ -912,7 +912,7 @@ static int open_rttest(char *buf, size_t size, unsigned 
count)
                        break;
 
                if (errno != ENOSYS && errno != ENOTTY) {
-                       fprintf(stderr, "switchtest: open: %m\n");
+                       fprintf(stderr, "switchtest: ioctl: %m\n");
                        return -1;
                }
 
@@ -923,8 +923,8 @@ static int open_rttest(char *buf, size_t size, unsigned 
count)
                if (++dev_nr != DEV_NR_MAX)
                        continue;
 
-               fprintf(stderr, "switchtest: Unable to open switchtest 
device.\n"
-                       "(modprobe xeno_switchtest ?)\n");
+               fprintf(stderr, "switchtest: cannot open %s\n"
+                       "(modprobe xeno_switchtest?)\n", buf);
 
                return -1;
        } while (status == -1);
diff --git a/utils/autotune/autotune.c b/utils/autotune/autotune.c
index 3c019f3..b9bccd9 100644
--- a/utils/autotune/autotune.c
+++ b/utils/autotune/autotune.c
@@ -266,7 +266,7 @@ int main(int argc, char *const argv[])
                }
        }
 
-       fd = open("/dev/autotune", O_RDONLY);
+       fd = open("/dev/rtdm/autotune", O_RDONLY);
        if (fd < 0)
                error(1, errno, "cannot open autotune device");
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to