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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep  9 16:11:54 2014 +0200

cobalt/posix/mq, lib/cobalt: alloc file descriptors on the anon inode

---

 kernel/cobalt/posix/mqueue.c       |   35 ++++++++++++++++++++++-------------
 kernel/cobalt/posix/mqueue.h       |    3 +--
 kernel/cobalt/trace/cobalt-posix.h |   11 ++++-------
 lib/cobalt/mq.c                    |   18 +++++++-----------
 4 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 689c755..4d6a697 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -18,6 +18,8 @@
 
 #include <stdarg.h>
 #include <linux/fs.h>
+#include <linux/fdtable.h>
+#include <linux/anon_inodes.h>
 #include <linux/slab.h>
 #include <linux/mm.h>
 #include <cobalt/kernel/select.h>
@@ -284,13 +286,11 @@ static inline int mqd_create(struct cobalt_mq *mq, 
unsigned long flags, int ufd)
        return rtdm_fd_enter(p, &mqd->fd, ufd, COBALT_MQD_MAGIC, &mqd_ops);
 }
 
-static int mq_open(int uqd, const char *name, int oflags, ...)
+static int mq_open(int uqd, const char *name, int oflags,
+                  int mode, struct mq_attr *attr)
 {
        struct cobalt_mq *mq;
-       struct mq_attr *attr;
        xnhandle_t handle;
-       mode_t mode;
-       va_list ap;
        spl_t s;
        int err;
 
@@ -337,11 +337,6 @@ static int mq_open(int uqd, const char *name, int oflags, 
...)
                if (mq == NULL)
                        return -ENOSPC;
 
-               va_start(ap, oflags);
-               mode = va_arg(ap, int); /* unused */
-               attr = va_arg(ap, struct mq_attr *);
-               va_end(ap);
-
                err = mq_init(mq, attr);
                if (err) {
                        xnfree(mq);
@@ -792,11 +787,14 @@ COBALT_SYSCALL(mq_notify, primary,
 
 COBALT_SYSCALL(mq_open, lostage,
               int, (const char __user *u_name, int oflags,
-                    mode_t mode, struct mq_attr __user *u_attr, mqd_t uqd))
+                    mode_t mode, struct mq_attr __user *u_attr))
 {
        struct mq_attr locattr, *attr;
        char name[COBALT_MAXNAME];
-       unsigned len;
+       struct xnsys_ppd *ppd;
+       unsigned int len;
+       mqd_t uqd;
+       int ret;
 
        len = __xn_safe_strncpy_from_user(name, u_name, sizeof(name));
        if (len < 0)
@@ -816,9 +814,20 @@ COBALT_SYSCALL(mq_open, lostage,
        } else
                attr = NULL;
 
-       trace_cobalt_mq_open(name, oflags, mode, uqd);
+       trace_cobalt_mq_open(name, oflags, mode);
+
+       ppd = cobalt_ppd_get(0);
+       uqd = anon_inode_getfd("[cobalt-mq]", &rtdm_dumb_fops, ppd, oflags);
+       if (uqd < 0)
+               return uqd;
+
+       ret = mq_open(uqd, name, oflags, mode, attr);
+       if (ret < 0) {
+               __close_fd(current->files, uqd);
+               return ret;
+       }
 
-       return mq_open(uqd, name, oflags, mode, attr);
+       return uqd;
 }
 
 COBALT_SYSCALL(mq_close, lostage, int, (mqd_t uqd))
diff --git a/kernel/cobalt/posix/mqueue.h b/kernel/cobalt/posix/mqueue.h
index 5097b78..9b48333 100644
--- a/kernel/cobalt/posix/mqueue.h
+++ b/kernel/cobalt/posix/mqueue.h
@@ -32,8 +32,7 @@ struct mq_attr {
 
 COBALT_SYSCALL_DECL(mq_open,
                    int, (const char __user *u_name, int oflags,
-                         mode_t mode, struct mq_attr __user *u_attr,
-                         mqd_t uqd));
+                         mode_t mode, struct mq_attr __user *u_attr));
 
 COBALT_SYSCALL_DECL(mq_close, int, (mqd_t uqd));
 
diff --git a/kernel/cobalt/trace/cobalt-posix.h 
b/kernel/cobalt/trace/cobalt-posix.h
index c2dfe34..f0d4e3e 100644
--- a/kernel/cobalt/trace/cobalt-posix.h
+++ b/kernel/cobalt/trace/cobalt-posix.h
@@ -739,28 +739,25 @@ TRACE_EVENT(cobalt_cond_wait,
 );
 
 TRACE_EVENT(cobalt_mq_open,
-       TP_PROTO(const char *name, int oflags, mode_t mode, mqd_t mqd),
-       TP_ARGS(name, oflags, mode, mqd),
+       TP_PROTO(const char *name, int oflags, mode_t mode),
+       TP_ARGS(name, oflags, mode),
 
        TP_STRUCT__entry(
                __string(name, name)
                __field(int, oflags)
                __field(mode_t, mode)
-               __field(mqd_t, mqd)
        ),
 
        TP_fast_assign(
                __assign_str(name, name);
                __entry->oflags = oflags;
                __entry->mode = (oflags & O_CREAT) ? mode : 0;
-               __entry->mqd = mqd;
        ),
 
-       TP_printk("name=%s oflags=%#x(%s) mode=%o mqd=%d",
+       TP_printk("name=%s oflags=%#x(%s) mode=%o",
                  __get_str(name),
                  __entry->oflags, cobalt_print_oflags(__entry->oflags),
-                 __entry->mode,
-                 __entry->mqd)
+                 __entry->mode)
 );
 
 TRACE_EVENT(cobalt_mq_notify,
diff --git a/lib/cobalt/mq.c b/lib/cobalt/mq.c
index a0726f8..5b904b5 100644
--- a/lib/cobalt/mq.c
+++ b/lib/cobalt/mq.c
@@ -104,7 +104,7 @@ COBALT_IMPL(mqd_t, mq_open, (const char *name, int oflags, 
...))
        struct mq_attr *attr = NULL;
        mode_t mode = 0;
        va_list ap;
-       int q, err;
+       int fd;
 
        if ((oflags & O_CREAT) != 0) {
                va_start(ap, oflags);
@@ -113,17 +113,13 @@ COBALT_IMPL(mqd_t, mq_open, (const char *name, int 
oflags, ...))
                va_end(ap);
        }
 
-       q = __STD(open("/dev/null", O_RDWR, 0));
-       if (q == -1)
-               return (mqd_t) - 1;
-
-       err = -XENOMAI_SYSCALL5(sc_cobalt_mq_open, name, oflags, mode, attr, q);
-
-       if (!err)
-               return (mqd_t) q;
+       fd = XENOMAI_SYSCALL4(sc_cobalt_mq_open, name, oflags, mode, attr);
+       if (fd < 0) {
+               errno = -fd;
+               return (mqd_t)-1;
+       }
 
-       errno = err;
-       return (mqd_t) - 1;
+       return (mqd_t)fd;
 }
 
 /**


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

Reply via email to