Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/perfused perfused(8) creates a /dev/fuse socket and...



details:   https://anonhg.NetBSD.org/src/rev/01696bdc719a
branches:  trunk
changeset: 757317:01696bdc719a
user:      manu <manu%NetBSD.org@localhost>
date:      Wed Aug 25 07:18:01 2010 +0000

description:
perfused(8) creates a /dev/fuse socket and performs PUFFS to FUSE relaying.
This is still a work in progress.

diffstat:

 usr.sbin/perfused/Makefile   |   13 +
 usr.sbin/perfused/debug.c    |   74 +++++
 usr.sbin/perfused/msg.c      |  599 +++++++++++++++++++++++++++++++++++++++++++
 usr.sbin/perfused/perfused.8 |  121 ++++++++
 usr.sbin/perfused/perfused.c |  384 +++++++++++++++++++++++++++
 usr.sbin/perfused/perfused.h |   68 ++++
 6 files changed, 1259 insertions(+), 0 deletions(-)

diffs (truncated from 1283 to 300 lines):

diff -r 6cbf811739fd -r 01696bdc719a usr.sbin/perfused/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/perfused/Makefile        Wed Aug 25 07:18:01 2010 +0000
@@ -0,0 +1,13 @@
+PROG=            perfused
+
+PERFUSE_OPT_DEBUG_FLAGS=   -g -DPERFUSE_DEBUG
+
+CFLAGS=        ${PERFUSE_OPT_DEBUG_FLAGS}
+SRCS=           perfused.c msg.c debug.c
+MAN=           perfused.8
+WARNS=          4
+
+LDADD+= -lperfuse -lpuffs #-L/usr/pkg/lib -lefence
+DPADD+= ${LIBPUFFS}
+
+.include <bsd.prog.mk>
diff -r 6cbf811739fd -r 01696bdc719a usr.sbin/perfused/debug.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/perfused/debug.c Wed Aug 25 07:18:01 2010 +0000
@@ -0,0 +1,74 @@
+/*  $NetBSD: debug.c,v 1.1 2010/08/25 07:18:01 manu Exp $ */
+
+/*-
+ *  Copyright (c) 2010 Emmanuel Dreyfus. 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ *  ``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 FOUNDATION 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 <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "perfused.h"
+
+#ifdef PERFUSE_DEBUG
+void
+perfuse_hexdump(addr, len)
+       char *addr;
+       size_t len;
+{
+       unsigned int i, j, k;
+
+       for (i = 0; i < len; i += 16) {
+               DPRINTF("%p  ", &addr[i]);
+               for (j = 0; j < 16; j += 4) {
+                       for (k = 0; k < 4; k++) {
+                               if (i + j + k < len) {
+                                       DPRINTF("%02x ", 
+                                              *(addr + i + j + k) & 0xff);
+                               } else {
+                                       DPRINTF("   ");
+                               }
+                       }
+               }
+
+               DPRINTF("  ");
+               for (j = 0; j < 16; j++) {
+                       char c;
+
+                       if (i + j < len) {
+                               c = *(addr + i + j);
+                               DPRINTF("%c", isprint((int)c) ? c : '.');
+                       } else {
+                               DPRINTF(" ");
+                       }
+               }
+               DPRINTF("\n");
+       }
+
+       return;
+}
+
+
+
+#endif /* PERFUSE_DEBUG */
diff -r 6cbf811739fd -r 01696bdc719a usr.sbin/perfused/msg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/perfused/msg.c   Wed Aug 25 07:18:01 2010 +0000
@@ -0,0 +1,599 @@
+/*  $NetBSD: msg.c,v 1.1 2010/08/25 07:18:01 manu Exp $ */
+
+/*-
+ *  Copyright (c) 2010 Emmanuel Dreyfus. 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ *  ``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 FOUNDATION 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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <sysexits.h>
+#include <syslog.h>
+#include <paths.h>
+#include <puffs.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <machine/vmparam.h>
+
+#include "../../lib/libperfuse/perfuse_if.h"
+#include "perfused.h"
+
+static int xchg_pb_inloop(struct puffs_usermount *a, struct puffs_framebuf *,
+       int, enum perfuse_xchg_pb_reply);
+static int xchg_pb_early(struct puffs_usermount *a, struct puffs_framebuf *,
+       int, enum perfuse_xchg_pb_reply);
+
+int
+perfuse_open_sock(void)
+{
+       int s;
+       struct sockaddr_un sun;
+       const struct sockaddr *sa;
+
+       (void)unlink(_PATH_FUSE);
+
+       if ((s = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1)
+               err(EX_OSERR, "socket failed");
+
+       sa = (const struct sockaddr *)(void *)&sun;
+       sun.sun_len = sizeof(sun);
+       sun.sun_family = AF_LOCAL;
+       (void)strcpy(sun.sun_path, _PATH_FUSE); 
+       
+       if (bind(s, sa, (socklen_t )sun.sun_len) == -1)
+               err(EX_OSERR, "cannot open \"%s\" socket", _PATH_FUSE);
+
+       if (listen(s, 1) == -1) 
+               err(EX_OSERR, "listen failed");
+
+       return s;
+}
+
+
+void *
+perfuse_recv_early(fd, len)
+       int fd;
+       size_t len;
+{
+       char *buf;
+
+       if (len == 0)
+               return NULL;
+
+       if ((buf = malloc(len + 1)) == NULL)
+               err(EX_OSERR, "malloc(%d) failed", len);
+
+       if (read(fd, buf, len) != len) {
+               DWARN("short read");
+               return NULL;
+       }
+
+       buf[len] = '\0';
+       return buf;
+}
+
+
+perfuse_msg_t *
+perfuse_new_pb (pu, opc, opcode, payload_len, cred)
+       struct puffs_usermount *pu;
+       puffs_cookie_t opc;
+       int opcode;
+       size_t payload_len;
+       const struct puffs_cred *cred;
+{
+       struct puffs_framebuf *pb;
+       struct fuse_in_header *fih;
+       struct puffs_cc *pcc;
+       uint64_t nodeid;
+       void *data;
+       size_t len;
+
+       if ((pb = puffs_framebuf_make()) == NULL)
+               DERR(EX_OSERR, "puffs_framebuf_make failed");
+
+       len = payload_len + sizeof(*fih);
+       nodeid = (opc != 0) ? perfuse_get_ino(pu, opc) : PERFUSE_UNKNOWN_INO;
+
+       if (puffs_framebuf_reserve_space(pb, len) != 0)
+               DERR(EX_OSERR, "puffs_framebuf_reserve_space failed");
+
+       if (puffs_framebuf_getwindow(pb, 0, &data, &len) != 0)
+               DERR(EX_SOFTWARE, "puffs_framebuf_getwindow failed");
+       if (len != payload_len + sizeof(*fih))
+               DERR(EX_SOFTWARE, "puffs_framebuf_getwindow short len");
+
+       (void)memset(data, 0, len);
+       fih = (struct fuse_in_header *)data;
+       fih->len = len;
+       fih->opcode = opcode;
+       fih->unique = perfuse_next_unique(pu);
+       fih->nodeid = nodeid;
+       fih->uid = (uid_t)-1;
+       fih->gid = (gid_t)-1;
+       fih->pid = 0;
+       if (cred != NULL) {
+               (void)puffs_cred_getuid(cred, &fih->uid);
+               (void)puffs_cred_getuid(cred, &fih->uid);
+       }
+       if ((pcc = puffs_cc_getcc(pu)) != NULL)
+               (void)puffs_cc_getcaller(pcc, (pid_t *)&fih->pid, NULL);
+
+       return (perfuse_msg_t *)(void *)pb;
+}
+
+/*
+ * framebuf send/receive primitives based on pcc are
+ * not available until puffs mainloop is entered.
+ * This xchg_pb_inloop() variant allow early communication.
+ */
+static int
+xchg_pb_early(pu, pb, fd, reply)
+       struct puffs_usermount *pu;
+       struct puffs_framebuf *pb;
+       int fd;
+       enum perfuse_xchg_pb_reply reply;
+{
+       int done;
+       int error;
+
+       done = 0;
+       while (done == 0) {
+               if ((error = perfuse_writeframe(pu, pb, fd, &done)) != 0)
+                       return error;
+       }
+
+       if (reply == no_reply) {
+               puffs_framebuf_destroy(pb);
+               return 0;
+       } else {
+               puffs_framebuf_recycle(pb);
+       }
+
+       done = 0;
+       while (done == 0) {
+               if ((error = perfuse_readframe(pu, pb, fd, &done)) != 0)
+                       return error;
+       }
+
+       return 0;
+}
+
+static int
+xchg_pb_inloop(pu, pb, fd, reply)
+       struct puffs_usermount *pu;
+       struct puffs_framebuf *pb;
+       int fd;
+       enum perfuse_xchg_pb_reply reply;
+{
+       struct puffs_cc *pcc;
+       int error;
+
+       if (reply == no_reply) {
+               error = puffs_framev_enqueue_justsend(pu, fd, pb, 0, 0);
+       } else {
+               pcc = puffs_cc_getcc(pu);
+               error = puffs_framev_enqueue_cc(pcc, fd, pb, 0);
+       }
+



Home | Main Index | Thread Index | Old Index