Module: xenomai-3
Branch: master
Commit: 10078a95d180c0bfbc2b1068ba1b46d842e87fe9
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=10078a95d180c0bfbc2b1068ba1b46d842e87fe9

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat Oct 25 21:52:07 2014 +0200

cobalt/mqueue: use rtdm fd flags

---

 include/cobalt/uapi/syscall.h                      |    2 +-
 .../arch/x86/include/asm/xenomai/syscall32-table.h |    1 -
 kernel/cobalt/posix/mqueue.c                       |   79 +++-----------------
 kernel/cobalt/posix/mqueue.h                       |    7 --
 kernel/cobalt/posix/syscall.c                      |    5 +-
 kernel/cobalt/posix/syscall32.c                    |   21 ------
 kernel/cobalt/posix/syscall32.h                    |    4 -
 lib/cobalt/mq.c                                    |   19 ++++-
 8 files changed, 29 insertions(+), 109 deletions(-)

diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index 025d2ff..0f74f37 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -63,7 +63,7 @@
 #define sc_cobalt_mq_close                     40
 #define sc_cobalt_mq_unlink                    41
 #define sc_cobalt_mq_getattr                   42
-#define sc_cobalt_mq_setattr                   43
+/* 43 unimp */
 #define sc_cobalt_mq_timedsend                 44
 #define sc_cobalt_mq_timedreceive              45
 #define sc_cobalt_mq_notify                    46
diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h 
b/kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h
index 1c84ef3..9f2f000 100644
--- a/kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h
+++ b/kernel/cobalt/arch/x86/include/asm/xenomai/syscall32-table.h
@@ -37,7 +37,6 @@ __COBALT_CALL32emu_THUNK(mutex_timedlock)
 __COBALT_CALL32emu_THUNK(cond_wait_prologue)
 __COBALT_CALL32emu_THUNK(mq_open)
 __COBALT_CALL32emu_THUNK(mq_getattr)
-__COBALT_CALL32emu_THUNK(mq_setattr)
 __COBALT_CALL32emu_THUNK(mq_timedsend)
 __COBALT_CALL32emu_THUNK(mq_timedreceive)
 __COBALT_CALL32emu_THUNK(mq_notify)
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 33d8310..b922d5c 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -31,7 +31,7 @@
 
 #define COBALT_MSGMAX          65536
 #define COBALT_MSGSIZEMAX      (16*1024*1024)
-#define COBALT_MSGPRIOMAX      32768
+#define COBALT_MSGPRIOMAX      32768
 
 struct cobalt_mq {
        unsigned magic;
@@ -62,7 +62,6 @@ struct cobalt_mq {
 };
 
 struct cobalt_mqd {
-       long flags;
        struct cobalt_mq *mq;
        struct rtdm_fd fd;
 };
@@ -228,7 +227,7 @@ mqd_select(struct rtdm_fd *fd, struct xnselector *selector,
        switch(type) {
        case XNSELECT_READ:
                err = -EBADF;
-               if ((mqd->flags & COBALT_PERMS_MASK) == O_WRONLY)
+               if ((rtdm_fd_flags(fd) & COBALT_PERMS_MASK) == O_WRONLY)
                        goto unlock_and_error;
 
                err = xnselect_bind(&mq->read_select, binding,
@@ -240,7 +239,7 @@ mqd_select(struct rtdm_fd *fd, struct xnselector *selector,
 
        case XNSELECT_WRITE:
                err = -EBADF;
-               if ((mqd->flags & COBALT_PERMS_MASK) == O_RDONLY)
+               if ((rtdm_fd_flags(fd) & COBALT_PERMS_MASK) == O_RDONLY)
                        goto unlock_and_error;
 
                err = xnselect_bind(&mq->write_select, binding,
@@ -275,7 +274,7 @@ static inline int mqd_create(struct cobalt_mq *mq, unsigned 
long flags, int ufd)
        if (mqd == NULL)
                return -ENOSPC;
 
-       mqd->flags = flags;
+       mqd->fd.oflags = flags;
        mqd->mq = mq;
 
        return rtdm_fd_enter(&mqd->fd, ufd, COBALT_MQD_MAGIC, &mqd_ops);
@@ -416,7 +415,7 @@ mq_trysend(struct cobalt_mqd *mqd, size_t len)
        unsigned flags;
 
        mq = mqd->mq;
-       flags = mqd->flags & COBALT_PERMS_MASK;
+       flags = rtdm_fd_flags(&mqd->fd) & COBALT_PERMS_MASK;
 
        if (flags != O_WRONLY && flags != O_RDWR)
                return ERR_PTR(-EBADF);
@@ -442,7 +441,7 @@ mq_tryrcv(struct cobalt_mqd *mqd, size_t len)
        struct cobalt_mq *mq;
 
        mq = mqd->mq;
-       flags = mqd->flags & COBALT_PERMS_MASK;
+       flags = rtdm_fd_flags(&mqd->fd) & COBALT_PERMS_MASK;
 
        if (flags != O_RDONLY && flags != O_RDWR)
                return ERR_PTR(-EBADF);
@@ -485,7 +484,7 @@ redo:
        if (msg != ERR_PTR(-EAGAIN))
                goto out;
 
-       if (mqd->flags & O_NONBLOCK)
+       if (rtdm_fd_flags(&mqd->fd) & O_NONBLOCK)
                goto out;
 
        if (fetch_timeout) {
@@ -614,7 +613,7 @@ redo:
        if (msg != ERR_PTR(-EAGAIN))
                goto out;
 
-       if (mqd->flags & O_NONBLOCK)
+       if (rtdm_fd_flags(&mqd->fd) & O_NONBLOCK)
                goto out;
 
        if (fetch_timeout) {
@@ -668,36 +667,13 @@ static inline int mq_getattr(struct cobalt_mqd *mqd, 
struct mq_attr *attr)
        mq = mqd->mq;
        *attr = mq->attr;
        xnlock_get_irqsave(&nklock, s);
-       attr->mq_flags = mqd->flags;
+       attr->mq_flags = rtdm_fd_flags(&mqd->fd);
        attr->mq_curmsgs = mq->nrqueued;
        xnlock_put_irqrestore(&nklock, s);
 
        return 0;
 }
 
-static inline int mq_setattr(struct cobalt_mqd *mqd,
-                            const struct mq_attr *__restrict__ attr,
-                            struct mq_attr *__restrict__ oattr)
-{
-       struct cobalt_mq *mq;
-       long flags;
-       spl_t s;
-
-       xnlock_get_irqsave(&nklock, s);
-       mq = mqd->mq;
-       if (oattr) {
-               *oattr = mq->attr;
-               oattr->mq_flags = mqd->flags;
-               oattr->mq_curmsgs = mq->nrqueued;
-       }
-       flags = (mqd->flags & COBALT_PERMS_MASK)
-           | (attr->mq_flags & ~COBALT_PERMS_MASK);
-       mqd->flags = flags;
-       xnlock_put_irqrestore(&nklock, s);
-
-       return 0;
-}
-
 static inline int
 mq_notify(struct cobalt_mqd *mqd, unsigned index, const struct sigevent *evp)
 {
@@ -901,43 +877,6 @@ COBALT_SYSCALL(mq_getattr, current,
        return __xn_safe_copy_to_user(u_attr, &attr, sizeof(attr));
 }
 
-int __cobalt_mq_setattr(mqd_t uqd, const struct mq_attr *attr,
-                       struct mq_attr *oattr)
-{
-       struct cobalt_mqd *mqd;
-       int ret;
-
-       mqd = cobalt_mqd_get(uqd);
-       if (IS_ERR(mqd))
-               return PTR_ERR(mqd);
-
-       trace_cobalt_mq_setattr(uqd, attr);
-       ret = mq_setattr(mqd, attr, oattr);
-       cobalt_mqd_put(mqd);
-
-       return ret;
-}
-
-COBALT_SYSCALL(mq_setattr, current,
-              int, (mqd_t uqd, const struct mq_attr __user *u_attr,
-                    struct mq_attr __user *u_oattr))
-{
-       struct mq_attr attr, oattr;
-       int ret;
-
-       if (__xn_safe_copy_from_user(&attr, u_attr, sizeof(attr)))
-               return -EFAULT;
-
-       ret = __cobalt_mq_setattr(uqd, &attr, &oattr);
-       if (ret)
-               return ret;
-
-       if (u_oattr == NULL)
-               return 0;
-
-       return __xn_safe_copy_to_user(u_oattr, &oattr, sizeof(oattr));
-}
-
 static inline int mq_fetch_timeout(struct timespec *ts,
                                   const void __user *u_ts)
 {
diff --git a/kernel/cobalt/posix/mqueue.h b/kernel/cobalt/posix/mqueue.h
index 8fc42d0..43c862f 100644
--- a/kernel/cobalt/posix/mqueue.h
+++ b/kernel/cobalt/posix/mqueue.h
@@ -35,9 +35,6 @@ int __cobalt_mq_open(const char __user *u_name, int oflags,
 
 int __cobalt_mq_getattr(mqd_t uqd, struct mq_attr *attr);
 
-int __cobalt_mq_setattr(mqd_t uqd, const struct mq_attr *attr,
-                       struct mq_attr *oattr);
-
 int __cobalt_mq_timedsend(mqd_t uqd, const void __user *u_buf, size_t len,
                          unsigned int prio, const void __user *u_ts,
                          int (*fetch_timeout)(struct timespec *ts,
@@ -64,10 +61,6 @@ COBALT_SYSCALL_DECL(mq_unlink,
 COBALT_SYSCALL_DECL(mq_getattr, 
                    int, (mqd_t uqd, struct mq_attr __user *u_attr));
 
-COBALT_SYSCALL_DECL(mq_setattr,
-                   int, (mqd_t uqd, const struct mq_attr __user *u_attr,
-                         struct mq_attr __user *u_oattr));
-
 COBALT_SYSCALL_DECL(mq_timedsend,
                    int, (mqd_t uqd, const void __user *u_buf, size_t len,
                          unsigned int prio,
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 1b128f1..60a385b 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -557,7 +557,6 @@ static const cobalt_syshand cobalt_syscalls[] = {
        __COBALT_CALL_ENTRY(mq_close),
        __COBALT_CALL_ENTRY(mq_unlink),
        __COBALT_CALL_ENTRY(mq_getattr),
-       __COBALT_CALL_ENTRY(mq_setattr),
        __COBALT_CALL_ENTRY(mq_timedsend),
        __COBALT_CALL_ENTRY(mq_timedreceive),
        __COBALT_CALL_ENTRY(mq_notify),
@@ -612,7 +611,8 @@ static const cobalt_syshand cobalt_syscalls[] = {
        __COBALT_CALL_ENTRY(serialdbg),
        __COBALT_CALL_ENTRY(sysconf),
        __COBALT_CALL_ENTRY(sysctl),
-       __COBALT_CALL_ENTRY(fcntl),
+       __COBALT_CALL_ENTRY(fcntl)
+       /* NO COMMA AT END */
 #ifdef CONFIG_XENO_ARCH_SYS3264
 #include <asm/xenomai/syscall32-table.h>
 #endif
@@ -662,7 +662,6 @@ static const int cobalt_sysmodes[] = {
        __COBALT_MODE(mq_close, lostage),
        __COBALT_MODE(mq_unlink, lostage),
        __COBALT_MODE(mq_getattr, current),
-       __COBALT_MODE(mq_setattr, current),
        __COBALT_MODE(mq_timedsend, primary),
        __COBALT_MODE(mq_timedreceive, primary),
        __COBALT_MODE(mq_notify, primary),
diff --git a/kernel/cobalt/posix/syscall32.c b/kernel/cobalt/posix/syscall32.c
index 9bc852e..61c619f 100644
--- a/kernel/cobalt/posix/syscall32.c
+++ b/kernel/cobalt/posix/syscall32.c
@@ -230,27 +230,6 @@ COBALT_SYSCALL32emu(mq_getattr, current,
        return sys32_put_mqattr(u_attr, &attr);
 }
 
-COBALT_SYSCALL32emu(mq_setattr, current,
-                   int, (mqd_t uqd, const struct compat_mq_attr __user *u_attr,
-                         struct compat_mq_attr __user *u_oattr))
-{
-       struct mq_attr attr, oattr;
-       int ret;
-
-       ret = sys32_get_mqattr(&attr, u_attr);
-       if (ret)
-               return ret;
-
-       ret = __cobalt_mq_setattr(uqd, &attr, &oattr);
-       if (ret)
-               return ret;
-
-       if (u_oattr == NULL)
-               return 0;
-
-       return sys32_put_mqattr(u_oattr, &oattr);
-}
-
 COBALT_SYSCALL32emu(mq_timedsend, primary,
                    int, (mqd_t uqd, const void __user *u_buf, size_t len,
                          unsigned int prio,
diff --git a/kernel/cobalt/posix/syscall32.h b/kernel/cobalt/posix/syscall32.h
index 99fe140..7c2be00 100644
--- a/kernel/cobalt/posix/syscall32.h
+++ b/kernel/cobalt/posix/syscall32.h
@@ -80,10 +80,6 @@ COBALT_SYSCALL32emu_DECL(mq_open,
 COBALT_SYSCALL32emu_DECL(mq_getattr,
                         int, (mqd_t uqd, struct compat_mq_attr __user 
*u_attr));
 
-COBALT_SYSCALL32emu_DECL(mq_setattr,
-                        int, (mqd_t uqd, const struct compat_mq_attr __user 
*u_attr,
-                              struct compat_mq_attr __user *u_oattr));
-
 COBALT_SYSCALL32emu_DECL(mq_timedsend,
                         int, (mqd_t uqd, const void __user *u_buf, size_t len,
                               unsigned int prio,
diff --git a/lib/cobalt/mq.c b/lib/cobalt/mq.c
index 49e9db3..a1aed3b 100644
--- a/lib/cobalt/mq.c
+++ b/lib/cobalt/mq.c
@@ -258,12 +258,27 @@ COBALT_IMPL(int, mq_setattr, (mqd_t mqd,
                              const struct mq_attr *__restrict__ attr,
                              struct mq_attr *__restrict__ oattr))
 {
-       int err;
+       int err = 0, flags;
+
+       if (oattr) {
+               err = XENOMAI_SYSCALL2(sc_cobalt_mq_getattr, mqd, oattr);
+               if (err < 0)
+                       goto out_err;
+               flags = oattr->mq_flags;
+       } else {
+               err = __WRAP(fcntl(mqd, F_GETFL));
+               if (err < 0)
+                       goto out_err;
+               flags = err;
+       }
+
+       flags = (flags & ~O_NONBLOCK) | (attr->mq_flags & O_NONBLOCK);
 
-       err = XENOMAI_SYSCALL3(sc_cobalt_mq_setattr, mqd, attr, oattr);
+       err = __WRAP(fcntl(mqd, F_SETFL, flags));
        if (!err)
                return 0;
 
+  out_err:
        errno = -err;
        return -1;
 }


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

Reply via email to