Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src make the file monitoring hypercalls private to shmif
details: https://anonhg.NetBSD.org/src/rev/c7f8cb718fb4
branches: trunk
changeset: 786426:c7f8cb718fb4
user: pooka <pooka%NetBSD.org@localhost>
date: Sun Apr 28 10:43:45 2013 +0000
description:
make the file monitoring hypercalls private to shmif
diffstat:
lib/librumpuser/rumpuser.c | 137 +-----------------------
sys/rump/include/rump/rumpuser.h | 5 +-
sys/rump/net/lib/libshmif/Makefile | 4 +-
sys/rump/net/lib/libshmif/if_shmem.c | 9 +-
sys/rump/net/lib/libshmif/rumpcomp_user.c | 172 ++++++++++++++++++++++++++++++
sys/rump/net/lib/libshmif/rumpcomp_user.h | 29 +++++
6 files changed, 212 insertions(+), 144 deletions(-)
diffs (truncated from 447 to 300 lines):
diff -r 935494f21221 -r c7f8cb718fb4 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c Sun Apr 28 10:25:41 2013 +0000
+++ b/lib/librumpuser/rumpuser.c Sun Apr 28 10:43:45 2013 +0000
@@ -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 @@
}
/*
- * 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
diff -r 935494f21221 -r c7f8cb718fb4 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h Sun Apr 28 10:25:41 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h Sun Apr 28 10:43:45 2013 +0000
@@ -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 @@
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);
diff -r 935494f21221 -r c7f8cb718fb4 sys/rump/net/lib/libshmif/Makefile
--- a/sys/rump/net/lib/libshmif/Makefile Sun Apr 28 10:25:41 2013 +0000
+++ b/sys/rump/net/lib/libshmif/Makefile Sun Apr 28 10:43:45 2013 +0000
@@ -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 @@
CPPFLAGS+= -I${.CURDIR}/../../../librump/rumpkern
+RUMPCOMP_USER= # filewatch
+
.include <bsd.lib.mk>
.include <bsd.klinks.mk>
diff -r 935494f21221 -r c7f8cb718fb4 sys/rump/net/lib/libshmif/if_shmem.c
--- a/sys/rump/net/lib/libshmif/if_shmem.c Sun Apr 28 10:25:41 2013 +0000
+++ b/sys/rump/net/lib/libshmif/if_shmem.c Sun Apr 28 10:43:45 2013 +0000
@@ -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 @@
#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 @@
#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 @@
== 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();
diff -r 935494f21221 -r c7f8cb718fb4 sys/rump/net/lib/libshmif/rumpcomp_user.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/net/lib/libshmif/rumpcomp_user.c Sun Apr 28 10:43:45 2013 +0000
@@ -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,
Home |
Main Index |
Thread Index |
Old Index