Module Name: src
Committed By: pooka
Date: Sun Apr 28 10:43:46 UTC 2013
Modified Files:
src/lib/librumpuser: rumpuser.c
src/sys/rump/include/rump: rumpuser.h
src/sys/rump/net/lib/libshmif: Makefile if_shmem.c
Added Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c rumpcomp_user.h
Log Message:
make the file monitoring hypercalls private to shmif
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/librumpuser/rumpuser.c
cvs rdiff -u -r1.86 -r1.87 src/sys/rump/include/rump/rumpuser.h
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libshmif/Makefile
cvs rdiff -u -r1.47 -r1.48 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/rumpcomp_user.c \
src/sys/rump/net/lib/libshmif/rumpcomp_user.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/librumpuser/rumpuser.c
diff -u src/lib/librumpuser/rumpuser.c:1.34 src/lib/librumpuser/rumpuser.c:1.35
--- src/lib/librumpuser/rumpuser.c:1.34 Sun Apr 28 09:58:11 2013
+++ src/lib/librumpuser/rumpuser.c Sun Apr 28 10:43:45 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.c,v 1.34 2013/04/28 09:58:11 pooka Exp $ */
+/* $NetBSD: rumpuser.c,v 1.35 2013/04/28 10:43:45 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.34 2013/04/28 09:58:11 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.35 2013/04/28 10:43:45 pooka Exp $");
#endif /* !lint */
#include <sys/ioctl.h>
@@ -601,139 +601,6 @@ rumpuser_seterrno(int error)
}
/*
- * On NetBSD we use kqueue, on Linux we use inotify. The underlying
- * interface requirements aren't quite the same, but we have a very
- * good chance of doing the fd->path mapping on Linux thanks to dcache,
- * so just keep the existing interfaces for now.
- */
-#if defined(__NetBSD__)
-int
-rumpuser_writewatchfile_setup(int kq, int fd, intptr_t opaque, int *error)
-{
- struct kevent kev;
-
- if (kq == -1) {
- kq = kqueue();
- if (kq == -1) {
- seterror(errno);
- return -1;
- }
- }
-
- EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
- NOTE_WRITE, 0, opaque);
- if (kevent(kq, &kev, 1, NULL, 0, NULL) == -1) {
- seterror(errno);
- return -1;
- }
-
- return kq;
-}
-
-int
-rumpuser_writewatchfile_wait(int kq, intptr_t *opaque, int *error)
-{
- struct kevent kev;
- int rv;
-
- again:
- KLOCK_WRAP(rv = kevent(kq, NULL, 0, &kev, 1, NULL));
- if (rv == -1) {
- if (errno == EINTR)
- goto again;
- seterror(errno);
- return -1;
- }
-
- if (opaque)
- *opaque = kev.udata;
- return rv;
-}
-
-#elif defined(__linux__)
-#include <sys/inotify.h>
-
-int
-rumpuser_writewatchfile_setup(int inotify, int fd, intptr_t notused, int *error)
-{
- char procbuf[PATH_MAX], linkbuf[PATH_MAX];
- ssize_t nn;
-
- if (inotify == -1) {
- inotify = inotify_init();
- if (inotify == -1) {
- seterror(errno);
- return -1;
- }
- }
-
- /* ok, need to map fd into path for inotify */
- snprintf(procbuf, sizeof(procbuf), "/proc/self/fd/%d", fd);
- nn = readlink(procbuf, linkbuf, sizeof(linkbuf)-1);
- if (nn >= (ssize_t)sizeof(linkbuf)-1) {
- nn = -1;
- errno = E2BIG; /* pick something */
- }
- if (nn == -1) {
- seterror(errno);
- close(inotify);
- return -1;
- }
-
- linkbuf[nn] = '\0';
- if (inotify_add_watch(inotify, linkbuf, IN_MODIFY) == -1) {
- seterror(errno);
- close(inotify);
- return -1;
- }
-
- return inotify;
-}
-
-int
-rumpuser_writewatchfile_wait(int kq, intptr_t *opaque, int *error)
-{
- struct inotify_event iev;
- ssize_t nn;
-
- do {
- KLOCK_WRAP(nn = read(kq, &iev, sizeof(iev)));
- } while (errno == EINTR);
-
- if (nn == -1) {
- seterror(errno);
- return -1;
- }
- return (nn/sizeof(iev));
-}
-
-#else
-
-/* a polling default implementation */
-int
-rumpuser_writewatchfile_setup(int inotify, int fd, intptr_t notused, int *error)
-{
- static int warned = 0;
-
- if (!warned) {
- fprintf(stderr, "WARNING: rumpuser writewatchfile routines are "
- "polling-only on this platform\n");
- warned = 1;
- }
-
- return 0;
-}
-
-int
-rumpuser_writewatchfile_wait(int kq, intptr_t *opaque, int *error)
-{
-
- KLOCK_WRAP(usleep(10000));
- return 0;
-}
-#endif
-
-/*
* This is meant for safe debugging prints from the kernel.
*/
int
Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.86 src/sys/rump/include/rump/rumpuser.h:1.87
--- src/sys/rump/include/rump/rumpuser.h:1.86 Sun Apr 28 09:58:11 2013
+++ src/sys/rump/include/rump/rumpuser.h Sun Apr 28 10:43:45 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.h,v 1.86 2013/04/28 09:58:11 pooka Exp $ */
+/* $NetBSD: rumpuser.h,v 1.87 2013/04/28 10:43:45 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -113,9 +113,6 @@ int rumpuser_kill(int64_t, int, int *);
void rumpuser_exit(int) __dead;
void rumpuser_seterrno(int);
-int rumpuser_writewatchfile_setup(int, int, intptr_t, int *);
-int rumpuser_writewatchfile_wait(int, intptr_t *, int *);
-
int rumpuser_dprintf(const char *, ...) __printflike(1, 2);
int rumpuser_getnhostcpu(void);
Index: src/sys/rump/net/lib/libshmif/Makefile
diff -u src/sys/rump/net/lib/libshmif/Makefile:1.3 src/sys/rump/net/lib/libshmif/Makefile:1.4
--- src/sys/rump/net/lib/libshmif/Makefile:1.3 Mon Nov 15 22:48:06 2010
+++ src/sys/rump/net/lib/libshmif/Makefile Sun Apr 28 10:43:45 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2010/11/15 22:48:06 pooka Exp $
+# $NetBSD: Makefile,v 1.4 2013/04/28 10:43:45 pooka Exp $
#
LIB= rumpnet_shmif
@@ -8,5 +8,7 @@ SRCS+= component.c
CPPFLAGS+= -I${.CURDIR}/../../../librump/rumpkern
+RUMPCOMP_USER= # filewatch
+
.include <bsd.lib.mk>
.include <bsd.klinks.mk>
Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.47 src/sys/rump/net/lib/libshmif/if_shmem.c:1.48
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.47 Mon Jan 14 20:21:32 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c Sun Apr 28 10:43:45 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: if_shmem.c,v 1.47 2013/01/14 20:21:32 pooka Exp $ */
+/* $NetBSD: if_shmem.c,v 1.48 2013/04/28 10:43:45 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.47 2013/01/14 20:21:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.48 2013/04/28 10:43:45 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v
#include "rump_private.h"
#include "rump_net_private.h"
+#include "rumpcomp_user.h"
static int shmif_clone(struct if_clone *, int);
static int shmif_unclone(struct ifnet *);
@@ -250,7 +251,7 @@ initbackend(struct shmif_sc *sc, int mem
#endif
shmif_unlockbus(sc->sc_busmem);
- sc->sc_kq = rumpuser_writewatchfile_setup(-1, memfd, 0, &error);
+ sc->sc_kq = rumpcomp_shmif_watchsetup(-1, memfd, 0, &error);
if (sc->sc_kq == -1) {
rumpuser_unmap(sc->sc_busmem, BUSMEM_SIZE);
return error;
@@ -668,7 +669,7 @@ shmif_rcv(void *arg)
== sc->sc_nextpacket) {
shmif_unlockbus(busmem);
error = 0;
- rumpuser_writewatchfile_wait(sc->sc_kq, NULL, &error);
+ rumpcomp_shmif_watchwait(sc->sc_kq, NULL, &error);
if (__predict_false(error))
printf("shmif_rcv: wait failed %d\n", error);
membar_consumer();
Added files:
Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u /dev/null src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.1
--- /dev/null Sun Apr 28 10:43:46 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c Sun Apr 28 10:43:45 2013
@@ -0,0 +1,172 @@
+/* $NetBSD: rumpcomp_user.c,v 1.1 2013/04/28 10:43:45 pooka Exp $ */
+
+/*-
+ * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/event.h>
+
+#include <errno.h>
+
+#include <rump/rumpuser_component.h>
+
+#include "rumpcomp_user.h"
+
+/*
+ * On NetBSD we use kqueue, on Linux we use inotify. The underlying
+ * interface requirements aren't quite the same, but we have a very
+ * good chance of doing the fd->path mapping on Linux thanks to dcache,
+ * so just keep the existing interfaces for now.
+ */
+#if defined(__NetBSD__)
+int
+rumpcomp_shmif_watchsetup(int kq, int fd, intptr_t opaque, int *error)
+{
+ struct kevent kev;
+ int rv;
+
+ if (kq == -1) {
+ kq = kqueue();
+ if (kq == -1) {
+ *error = errno;
+ return -1;
+ }
+ }
+
+ EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
+ NOTE_WRITE, 0, opaque);
+ rv = kevent(kq, &kev, 1, NULL, 0, NULL);
+ *error = errno;
+ return rv;
+}
+
+int
+rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+{
+ void *cookie;
+ struct kevent kev;
+ int rv;
+
+ cookie = rumpuser_component_unschedule();
+ do {
+ rv = kevent(kq, NULL, 0, &kev, 1, NULL);
+ } while (rv == -1 && errno == EINTR);
+
+ *error = errno;
+ if (rv != -1 && opaque)
+ *opaque = kev.udata;
+ rumpuser_component_schedule(cookie);
+ return rv;
+}
+
+#elif defined(__linux__)
+#include <sys/inotify.h>
+
+int
+rumpcomp_shmif_watchsetup(int inotify, int fd, intptr_t notused, int *error)
+{
+ char procbuf[PATH_MAX], linkbuf[PATH_MAX];
+ ssize_t nn;
+
+ if (inotify == -1) {
+ inotify = inotify_init();
+ if (inotify == -1) {
+ *error = errno;
+ return -1;
+ }
+ }
+
+ /* ok, need to map fd into path for inotify */
+ snprintf(procbuf, sizeof(procbuf), "/proc/self/fd/%d", fd);
+ nn = readlink(procbuf, linkbuf, sizeof(linkbuf)-1);
+ if (nn >= (ssize_t)sizeof(linkbuf)-1) {
+ nn = -1;
+ errno = E2BIG; /* pick something */
+ }
+ if (nn == -1) {
+ *error = errno;
+ close(inotify);
+ return -1;
+ }
+
+ linkbuf[nn] = '\0';
+ if (inotify_add_watch(inotify, linkbuf, IN_MODIFY) == -1) {
+ *error = errno;
+ close(inotify);
+ return -1;
+ }
+
+ return inotify;
+}
+
+int
+rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+{
+ struct inotify_event iev;
+ void *cookie;
+ ssize_t nn;
+
+ cookie = rumpuser_component_unschedule();
+ do {
+ nn = read(kq, &iev, sizeof(iev));
+ } while (errno == EINTR);
+ *error = errno;
+ rumpuser_component_schedule(cookie);
+
+ if (nn == -1) {
+ return -1;
+ }
+ return (nn/sizeof(iev));
+}
+
+#else
+
+/* a polling default implementation */
+int
+rumpcomp_shmif_watchsetup(int inotify, int fd, intptr_t notused, int *error)
+{
+ static int warned = 0;
+
+ if (!warned) {
+ fprintf(stderr, "WARNING: rumpuser writewatchfile routines are "
+ "polling-only on this platform\n");
+ warned = 1;
+ }
+
+ return 0;
+}
+
+int
+rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+{
+ void *cookie;
+
+ cookie = rumpuser_component_unschedule();
+ usleep(10000);
+ rumpuser_component_schedule(cookie);
+
+ return 0;
+}
+#endif
Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.h
diff -u /dev/null src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.1
--- /dev/null Sun Apr 28 10:43:46 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.h Sun Apr 28 10:43:45 2013
@@ -0,0 +1,29 @@
+/* $NetBSD: rumpcomp_user.h,v 1.1 2013/04/28 10:43:45 pooka Exp $ */
+
+/*
+ * Copyright (c) 2013 Antti Kantee. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+int rumpcomp_shmif_watchsetup(int, int, intptr_t, int *);
+int rumpcomp_shmif_watchwait(int, intptr_t *, int *);