[Xenomai-git] Philippe Gerum : cobalt/rtdm, lib/cobalt: open named device on allocated devnode
Module: xenomai-forge Branch: next Commit: 058ac4537d6e237504ad2df4cc4c22392387ee93 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=058ac4537d6e237504ad2df4cc4c22392387ee93 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);
[Xenomai-git] Philippe Gerum : cobalt/rtdm, lib/cobalt: open named device on allocated devnode
Module: xenomai-forge Branch: next Commit: d7c413c011072e890e96af6ceddcb2400818d8d9 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d7c413c011072e890e96af6ceddcb2400818d8d9 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 | 22 +++--- kernel/cobalt/rtdm/core.c |4 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 +- 9 files changed, 43 insertions(+), 18 deletions(-) diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c index 9810c32..cb57f89 100644 --- a/kernel/cobalt/posix/io.c +++ b/kernel/cobalt/posix/io.c @@ -34,18 +34,34 @@ COBALT_SYSCALL(open, lostage, { char path[RTDM_MAX_DEVNAME_LEN + 1]; 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; 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) + return ufd; + + filp = filp_open(path, oflag, 0); + if (IS_ERR(filp)) { + ret = PTR_ERR(filp); + goto fail; + } + + ppd = cobalt_ppd_get(0); ret = __rt_dev_open(ppd, ufd, path, oflag); if (ret 0) - __close_fd(current-files, ufd); + goto fail; + + fd_install(ufd, filp); + + return ufd; +fail: + put_unused_fd(ufd); return ret; } diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index 56ecbaa..b15505f 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -159,6 +159,10 @@ int __rt_dev_open(struct xnsys_ppd *p, int ufd, const char *path, int oflag) if (strncmp(path, /dev/, 5) == 0) path += 5; + /* skip RTDM devnode root */ + if (strncmp(path, rtdm/, 5) == 0) + path += 5; + device = __rtdm_get_named_device(path, minor); if (device == NULL) return -ENODEV; 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
[Xenomai-git] Philippe Gerum : cobalt/rtdm, lib/cobalt: open named device on allocated devnode
Module: xenomai-forge Branch: next Commit: 1332b1cc803cef7d269ca6d55d76507ecc580367 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1332b1cc803cef7d269ca6d55d76507ecc580367 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 | 22 +++--- kernel/cobalt/rtdm/core.c |4 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 +- 9 files changed, 43 insertions(+), 18 deletions(-) diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c index 9810c32..cb57f89 100644 --- a/kernel/cobalt/posix/io.c +++ b/kernel/cobalt/posix/io.c @@ -34,18 +34,34 @@ COBALT_SYSCALL(open, lostage, { char path[RTDM_MAX_DEVNAME_LEN + 1]; 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; 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) + return ufd; + + filp = filp_open(path, oflag, 0); + if (IS_ERR(filp)) { + ret = PTR_ERR(filp); + goto fail; + } + + ppd = cobalt_ppd_get(0); ret = __rt_dev_open(ppd, ufd, path, oflag); if (ret 0) - __close_fd(current-files, ufd); + goto fail; + + fd_install(ufd, filp); + + return ufd; +fail: + put_unused_fd(ufd); return ret; } diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index 56ecbaa..b15505f 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -159,6 +159,10 @@ int __rt_dev_open(struct xnsys_ppd *p, int ufd, const char *path, int oflag) if (strncmp(path, /dev/, 5) == 0) path += 5; + /* skip RTDM devnode root */ + if (strncmp(path, rtdm/, 5) == 0) + path += 5; + device = __rtdm_get_named_device(path, minor); if (device == NULL) return -ENODEV; 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