Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Do not assume that O_FOO flags have matching values in the r...



details:   https://anonhg.NetBSD.org/src/rev/a1a6e2cb4a42
branches:  trunk
changeset: 781554:a1a6e2cb4a42
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Sep 14 16:29:21 2012 +0000

description:
Do not assume that O_FOO flags have matching values in the rump kernel
and hypervisor.

diffstat:

 lib/librumpuser/rumpuser.c              |  30 ++++++++++++++++++++++++++----
 sys/rump/dev/lib/libscsitest/scsitest.c |   6 +++---
 sys/rump/dev/lib/libugenhc/ugenhc.c     |   9 +++++----
 sys/rump/include/rump/rumpuser.h        |  15 ++++++++++++++-
 sys/rump/librump/rumpvfs/rumpblk.c      |  12 ++++++------
 sys/rump/librump/rumpvfs/rumpfs.c       |   8 ++++----
 sys/rump/net/lib/libshmif/if_shmem.c    |  10 ++++++----
 sys/rump/net/lib/libvirtif/if_virt.c    |   6 +++---
 8 files changed, 67 insertions(+), 29 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 8a13168619b6 -r a1a6e2cb4a42 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Fri Sep 14 15:37:03 2012 +0000
+++ b/lib/librumpuser/rumpuser.c        Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.19 2012/08/25 18:00:06 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.20 2012/09/14 16:29:22 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.19 2012/08/25 18:00:06 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.20 2012/09/14 16:29:22 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -317,10 +317,32 @@
 }
 
 int
-rumpuser_open(const char *path, int flags, int *error)
+rumpuser_open(const char *path, int ruflags, int *error)
 {
+       int flags;
 
-       DOCALL(int, (open(path, flags, 0644)));
+       switch (ruflags & RUMPUSER_OPEN_ACCMODE) {
+       case RUMPUSER_OPEN_RDONLY:
+               flags = O_RDONLY;
+               break;
+       case RUMPUSER_OPEN_WRONLY:
+               flags = O_WRONLY;
+               break;
+       case RUMPUSER_OPEN_RDWR:
+               flags = O_RDWR;
+               break;
+       default:
+               *error = EINVAL;
+               return -1;
+       }
+
+#define TESTSET(_ru_, _h_) if (ruflags & _ru_) flags |= _h_;
+       TESTSET(RUMPUSER_OPEN_CREATE, O_CREAT);
+       TESTSET(RUMPUSER_OPEN_EXCL, O_EXCL);
+       TESTSET(RUMPUSER_OPEN_DIRECT, O_DIRECT);
+#undef TESTSET
+
+       DOCALL_KLOCK(int, (open(path, flags, 0644)));
 }
 
 int
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/dev/lib/libscsitest/scsitest.c
--- a/sys/rump/dev/lib/libscsitest/scsitest.c   Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/dev/lib/libscsitest/scsitest.c   Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsitest.c,v 1.3 2012/05/06 16:58:31 martin Exp $      */
+/*     $NetBSD: scsitest.c,v 1.4 2012/09/14 16:29:21 pooka Exp $       */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsitest.c,v 1.3 2012/05/06 16:58:31 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsitest.c,v 1.4 2012/09/14 16:29:21 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -218,7 +218,7 @@
                return 0;
        mycdsize = fsize / CDBLOCKSIZE;
 
-       if ((isofd = rumpuser_open(MYCDISO, O_RDWR, &error)) == -1)
+       if ((isofd = rumpuser_open(MYCDISO, RUMPUSER_OPEN_RDWR, &error)) == -1)
                return 0;
 #else
        /*
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/dev/lib/libugenhc/ugenhc.c
--- a/sys/rump/dev/lib/libugenhc/ugenhc.c       Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/dev/lib/libugenhc/ugenhc.c       Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ugenhc.c,v 1.10 2012/06/10 06:15:55 mrg Exp $  */
+/*     $NetBSD: ugenhc.c,v 1.11 2012/09/14 16:29:21 pooka Exp $        */
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ugenhc.c,v 1.10 2012/06/10 06:15:55 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ugenhc.c,v 1.11 2012/09/14 16:29:21 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -602,7 +602,7 @@
                 */
 
                for (;;) {
-                       fd = rumpuser_open(buf, O_RDWR, &error);
+                       fd = rumpuser_open(buf, RUMPUSER_OPEN_RDWR, &error);
                        if (fd != -1)
                                break;
                        kpause("ugwait", false, hz/4, NULL);
@@ -627,7 +627,7 @@
                 */
 
                for (;;) {
-                       fd = rumpuser_open(buf, O_RDWR, &error);
+                       fd = rumpuser_open(buf, RUMPUSER_OPEN_RDWR, &error);
                        if (fd == -1)
                                break;
 
@@ -971,6 +971,7 @@
                        }
 
                        makeugendevstr(sc->sc_devnum, endpt, buf);
+                       /* XXX: theoretically should convert oflags */
                        fd = rumpuser_open(buf, oflags, &error);
                        if (fd == -1) {
                                return USBD_INVAL; /* XXX: no mapping */
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.h,v 1.72 2012/03/15 02:02:22 joerg Exp $      */
+/*     $NetBSD: rumpuser.h,v 1.73 2012/09/14 16:29:21 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -68,7 +68,20 @@
 void  rumpuser_unmap(void *, size_t);
 int   rumpuser_memsync(void *, size_t, int *);
 
+/*
+ * Open modes.  these "accidentally" happen to match the respective
+ * NetBSD bit representations to preserve NetBSD binary compat for
+ * current users.  If you need to add new ones, just pick any numbers.
+ */
+#define RUMPUSER_OPEN_RDONLY   0x000000
+#define RUMPUSER_OPEN_WRONLY   0x000001
+#define RUMPUSER_OPEN_RDWR     0x000002
+#define RUMPUSER_OPEN_ACCMODE  0x000003 /* "yay" */
+#define RUMPUSER_OPEN_CREATE   0x000200
+#define RUMPUSER_OPEN_EXCL     0x000800
+#define RUMPUSER_OPEN_DIRECT   0x080000
 int rumpuser_open(const char *, int, int *);
+
 int rumpuser_ioctl(int, u_long, void *, int *);
 int rumpuser_close(int, int *);
 int rumpuser_fsync(int, int *);
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/librump/rumpvfs/rumpblk.c
--- a/sys/rump/librump/rumpvfs/rumpblk.c        Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/librump/rumpvfs/rumpblk.c        Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpblk.c,v 1.47 2011/11/19 22:51:31 tls Exp $ */
+/*     $NetBSD: rumpblk.c,v 1.48 2012/09/14 16:29:21 pooka Exp $       */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.47 2011/11/19 22:51:31 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpblk.c,v 1.48 2012/09/14 16:29:21 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -504,16 +504,16 @@
        int error, fd;
 
        KASSERT(rblk->rblk_fd == -1);
-       fd = rumpuser_open(path, O_RDWR, &error);
+       fd = rumpuser_open(path, RUMPUSER_OPEN_RDWR, &error);
        if (error) {
-               fd = rumpuser_open(path, O_RDONLY, &error);
+               fd = rumpuser_open(path, RUMPUSER_OPEN_RDONLY, &error);
                if (error)
                        return error;
                rblk->rblk_mode = FREAD;
 
 #ifdef HAS_ODIRECT
                rblk->rblk_dfd = rumpuser_open(path,
-                   O_RDONLY | O_DIRECT, &error);
+                   RUMPUSER_OPEN_RDONLY | RUMPUSER_OPEN_DIRECT, &error);
                if (error) {
                        close(fd);
                        return error;
@@ -524,7 +524,7 @@
 
 #ifdef HAS_ODIRECT
                rblk->rblk_dfd = rumpuser_open(path,
-                   O_RDWR | O_DIRECT, &error);
+                   RUMPUSER_OPEN_RDWR | RUMPUSER_OPEN_DIRECT, &error);
                if (error) {
                        close(fd);
                        return error;
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/librump/rumpvfs/rumpfs.c
--- a/sys/rump/librump/rumpvfs/rumpfs.c Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/librump/rumpvfs/rumpfs.c Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpfs.c,v 1.110 2012/03/30 18:09:12 njoly Exp $       */
+/*     $NetBSD: rumpfs.c,v 1.111 2012/09/14 16:29:22 pooka Exp $       */
 
 /*
  * Copyright (c) 2009, 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.110 2012/03/30 18:09:12 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.111 2012/09/14 16:29:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -1251,14 +1251,14 @@
                if (rn->rn_readfd != -1)
                        return 0;
                rn->rn_readfd = rumpuser_open(rn->rn_hostpath,
-                   O_RDONLY, &error);
+                   RUMPUSER_OPEN_RDONLY, &error);
        }
 
        if (mode & FWRITE) {
                if (rn->rn_writefd != -1)
                        return 0;
                rn->rn_writefd = rumpuser_open(rn->rn_hostpath,
-                   O_WRONLY, &error);
+                   RUMPUSER_OPEN_WRONLY, &error);
        }
 
        return error;
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/net/lib/libshmif/if_shmem.c
--- a/sys/rump/net/lib/libshmif/if_shmem.c      Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/net/lib/libshmif/if_shmem.c      Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_shmem.c,v 1.44 2011/11/19 22:51:31 tls Exp $        */
+/*     $NetBSD: if_shmem.c,v 1.45 2012/09/14 16:29:22 pooka Exp $      */
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.44 2011/11/19 22:51:31 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.45 2012/09/14 16:29:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -290,7 +290,8 @@
        int memfd = -1; /* XXXgcc */
 
        if (path) {
-               memfd = rumpuser_open(path, O_RDWR | O_CREAT, &error);
+               memfd = rumpuser_open(path,
+                   RUMPUSER_OPEN_RDWR | RUMPUSER_OPEN_CREATE, &error);
                if (memfd == -1)
                        return error;
        }
@@ -470,7 +471,8 @@
                        kmem_free(path, ifd->ifd_len);
                        break;
                }
-               memfd = rumpuser_open(path, O_RDWR | O_CREAT, &rv);
+               memfd = rumpuser_open(path,
+                   RUMPUSER_OPEN_RDWR | RUMPUSER_OPEN_CREATE, &rv);
                if (memfd == -1) {
                        kmem_free(path, ifd->ifd_len);
                        break;
diff -r 8a13168619b6 -r a1a6e2cb4a42 sys/rump/net/lib/libvirtif/if_virt.c
--- a/sys/rump/net/lib/libvirtif/if_virt.c      Fri Sep 14 15:37:03 2012 +0000
+++ b/sys/rump/net/lib/libvirtif/if_virt.c      Fri Sep 14 16:29:21 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_virt.c,v 1.26 2011/11/19 22:51:31 tls Exp $ */
+/*     $NetBSD: if_virt.c,v 1.27 2012/09/14 16:29:22 pooka Exp $       */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.26 2011/11/19 22:51:31 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.27 2012/09/14 16:29:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -97,7 +97,7 @@
                return E2BIG;
 
        snprintf(tapdev, sizeof(tapdev), "/dev/tap%d", num);
-       fd = rumpuser_open(tapdev, O_RDWR, &error);
+       fd = rumpuser_open(tapdev, RUMPUSER_OPEN_RDWR, &error);
        if (fd == -1) {
                printf("virtif_create: can't open /dev/tap%d: %d\n",



Home | Main Index | Thread Index | Old Index