Module: xenomai-forge Branch: next Commit: 1332b1cc803cef7d269ca6d55d76507ecc580367 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1332b1cc803cef7d269ca6d55d76507ecc580367
Author: Philippe Gerum <[email protected]> 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 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 [email protected] http://www.xenomai.org/mailman/listinfo/xenomai-git
