[Xenomai-git] Philippe Gerum : cobalt/rtdm/core: enable legacy pathnames for named devices
Module: xenomai-forge Branch: next Commit: 7d7a1936a2968b1f5415651725835e7790afcbbf URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7d7a1936a2968b1f5415651725835e7790afcbbf Author: Philippe Gerum Date: Sun Sep 21 10:16:43 2014 +0200 cobalt/rtdm/core: enable legacy pathnames for named devices --- kernel/cobalt/rtdm/core.c | 48 - kernel/drivers/Kconfig| 21 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index 896f139..f5c82f7 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -96,6 +96,40 @@ static int create_instance(int ufd, struct rtdm_device *dev, return rtdm_fd_enter(&context->fd, ufd, RTDM_FD_MAGIC, &dev->ops); } +#ifdef CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE + +static inline struct file * +open_devnode(struct rtdm_device *dev, const char *path, int oflag) +{ + struct file *filp; + char *filename; + +#ifdef CONFIG_XENO_OPT_DEBUG_USER + if (strncmp(path, "/dev/rtdm/", 10)) + printk(XENO_WARN + "%s[%d] opens obsolete device path: %s\n", + current->comm, current->pid, path); +#endif + filename = kasprintf(GFP_KERNEL, "/dev/rtdm/%s", dev->name); + if (filename == NULL) + return ERR_PTR(-ENOMEM); + + filp = filp_open(filename, oflag, 0); + kfree(filename); + + return filp; +} + +#else /* !CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE */ + +static inline struct file * +open_devnode(struct rtdm_device *dev, const char *path, int oflag) +{ + return filp_open(path, oflag, 0); +} + +#endif /* !CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE */ + int __rtdm_dev_open(const char *path, int oflag) { struct rtdm_dev_context *context; @@ -105,6 +139,18 @@ int __rtdm_dev_open(const char *path, int oflag) secondary_mode_only(); + /* +* CAUTION: we do want a lookup into the registry to happen +* before any attempt is made to open the devnode, so that we +* don't inadvertently open a regular (i.e. non-RTDM) device. +* Reason is that opening, then closing a device - because we +* don't manage it - may incur side-effects we don't want, +* e.g. opening then closing one end of a pipe would cause the +* other side to read the EOF condition. This is basically +* why we keep a RTDM registry for named devices, so that we +* can figure out whether an open() request is going to be +* valid, without having to open the devnode yet. +*/ dev = __rtdm_get_namedev(path); if (dev == NULL) return -ENODEV; @@ -115,7 +161,7 @@ int __rtdm_dev_open(const char *path, int oflag) goto fail_fd; } - filp = filp_open(path, oflag, 0); + filp = open_devnode(dev, path, oflag); if (IS_ERR(filp)) { ret = PTR_ERR(filp); goto fail_fopen; diff --git a/kernel/drivers/Kconfig b/kernel/drivers/Kconfig index 5496f30..a01eb8c 100644 --- a/kernel/drivers/Kconfig +++ b/kernel/drivers/Kconfig @@ -1,5 +1,26 @@ menu "Drivers" +config XENO_OPT_RTDM_COMPAT_DEVNODE +bool "Enable legacy pathnames for named RTDM devices" + default y + help + + This compatibility option allows applications to open named + RTDM devices using the legacy naming scheme, i.e. + + fd = open("devname", ...); + or + fd = open("/dev/devname", ...); + + When such a request is received by RTDM, a warning message is + issued to the kernel log whenever XENO_OPT_DEBUG_USER is + also enabled in the kernel configuration. + + Applications should open named devices via their actual device + nodes instead, i.e. + + fd = open("/dev/rtdm/devname", ...); + source "drivers/xenomai/autotune/Kconfig" source "drivers/xenomai/serial/Kconfig" source "drivers/xenomai/testing/Kconfig" ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/rtdm/core: enable legacy pathnames for named devices
Module: xenomai-forge Branch: next Commit: c04e569927f783e946ed66c9569e9df0441c00b1 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=c04e569927f783e946ed66c9569e9df0441c00b1 Author: Philippe Gerum Date: Sun Sep 21 10:16:43 2014 +0200 cobalt/rtdm/core: enable legacy pathnames for named devices --- kernel/cobalt/rtdm/core.c | 48 - kernel/drivers/Kconfig| 21 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/kernel/cobalt/rtdm/core.c b/kernel/cobalt/rtdm/core.c index 896f139..076af73 100644 --- a/kernel/cobalt/rtdm/core.c +++ b/kernel/cobalt/rtdm/core.c @@ -96,6 +96,40 @@ static int create_instance(int ufd, struct rtdm_device *dev, return rtdm_fd_enter(&context->fd, ufd, RTDM_FD_MAGIC, &dev->ops); } +#ifdef CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE + +static inline struct file * +open_devnode(struct rtdm_device *dev, const char *path, int oflag) +{ + struct file *filp; + char *filename; + +#ifdef CONFIG_XENO_OPT_DEBUG_USER + if (strncmp(path, "/dev/rtdm/", 10)) + printk(XENO_WARN + "%s[%d] opens obsolete device path: %s", + current->comm, current->pid, path); +#endif + filename = kasprintf(GFP_KERNEL, "/dev/rtdm/%s", dev->name); + if (filename == NULL) + return ERR_PTR(-ENOMEM); + + filp = filp_open(filename, oflag, 0); + kfree(filename); + + return filp; +} + +#else /* !CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE */ + +static inline struct file * +open_devnode(struct rtdm_device *dev, const char *path, int oflag) +{ + return filp_open(path, oflag, 0); +} + +#endif /* !CONFIG_XENO_OPT_RTDM_COMPAT_DEVNODE */ + int __rtdm_dev_open(const char *path, int oflag) { struct rtdm_dev_context *context; @@ -105,6 +139,18 @@ int __rtdm_dev_open(const char *path, int oflag) secondary_mode_only(); + /* +* CAUTION: we do want a lookup into the registry to happen +* before any attempt is made to open the devnode, so that we +* don't inadvertently open a regular (i.e. non-RTDM) device. +* Reason is that opening, then closing a device - because we +* don't manage it - may incur side-effects we don't want, +* e.g. opening then closing one end of a pipe would cause the +* other side to read the EOF condition. This is basically +* why we keep a RTDM registry for named devices, so that we +* can figure out whether an open() request is going to be +* valid, without having to open the devnode yet. +*/ dev = __rtdm_get_namedev(path); if (dev == NULL) return -ENODEV; @@ -115,7 +161,7 @@ int __rtdm_dev_open(const char *path, int oflag) goto fail_fd; } - filp = filp_open(path, oflag, 0); + filp = open_devnode(dev, path, oflag); if (IS_ERR(filp)) { ret = PTR_ERR(filp); goto fail_fopen; diff --git a/kernel/drivers/Kconfig b/kernel/drivers/Kconfig index 5496f30..a01eb8c 100644 --- a/kernel/drivers/Kconfig +++ b/kernel/drivers/Kconfig @@ -1,5 +1,26 @@ menu "Drivers" +config XENO_OPT_RTDM_COMPAT_DEVNODE +bool "Enable legacy pathnames for named RTDM devices" + default y + help + + This compatibility option allows applications to open named + RTDM devices using the legacy naming scheme, i.e. + + fd = open("devname", ...); + or + fd = open("/dev/devname", ...); + + When such a request is received by RTDM, a warning message is + issued to the kernel log whenever XENO_OPT_DEBUG_USER is + also enabled in the kernel configuration. + + Applications should open named devices via their actual device + nodes instead, i.e. + + fd = open("/dev/rtdm/devname", ...); + source "drivers/xenomai/autotune/Kconfig" source "drivers/xenomai/serial/Kconfig" source "drivers/xenomai/testing/Kconfig" ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git