Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/mount_portal Remove the portalfs kernel file system dri...
details: https://anonhg.NetBSD.org/src/rev/447ad6163566
branches: trunk
changeset: 749680:447ad6163566
user: pooka <pooka%NetBSD.org@localhost>
date: Sat Dec 05 20:25:32 2009 +0000
description:
Remove the portalfs kernel file system driver. Replace mount_portal(8)
with a version based on puffs. User functionality remains the same.
(missed new file in change batch)
diffstat:
sbin/mount_portal/puffs_portal.c | 783 +++++++++++++++++++++++++++++++++++++++
1 files changed, 783 insertions(+), 0 deletions(-)
diffs (truncated from 787 to 300 lines):
diff -r 5fc602d7abc7 -r 447ad6163566 sbin/mount_portal/puffs_portal.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/mount_portal/puffs_portal.c Sat Dec 05 20:25:32 2009 +0000
@@ -0,0 +1,783 @@
+/* $NetBSD: puffs_portal.c,v 1.1 2009/12/05 20:25:32 pooka Exp $ */
+
+/*
+ * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
+ * Development was supported by the Finnish Cultural Foundation.
+ *
+ * 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/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: puffs_portal.c,v 1.1 2009/12/05 20:25:32 pooka Exp $");
+#endif /* !lint */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <mntopts.h>
+#include <paths.h>
+#include <poll.h>
+#include <puffs.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util.h>
+
+#include "portald.h"
+
+struct portal_node {
+ char *path;
+ int fd;
+};
+
+static void usage(void);
+
+PUFFSOP_PROTOS(portal);
+
+#define PORTAL_ROOT NULL
+#define METADATASIZE (sizeof(int) + sizeof(size_t))
+
+qelem q;
+int readcfg, sigchild;
+const char *cfg;
+
+static void
+usage()
+{
+
+ errx(1, "usage: %s [-o options] /path/portal.conf mount_point",
+ getprogname());
+}
+
+static void
+sighup(int sig)
+{
+
+ readcfg = 1;
+}
+
+static void
+sigcry(int sig)
+{
+
+ sigchild = 1;
+}
+
+static void
+portal_loopfn(struct puffs_usermount *pu)
+{
+
+ if (readcfg)
+ conf_read(&q, cfg);
+ readcfg = 0;
+
+ if (sigchild) {
+ sigchild = 0;
+ while (waitpid(-1, NULL, WNOHANG) != -1)
+ continue;
+ }
+}
+
+#define PUFBUF_FD 1
+#define PUFBUF_DATA 2
+
+#define CMSIZE (sizeof(struct cmsghdr) + sizeof(int))
+
+/* receive file descriptor produced by our child process */
+static int
+readfd(struct puffs_framebuf *pufbuf, int fd, int *done)
+{
+ struct cmsghdr *cmp;
+ struct msghdr msg;
+ struct iovec iov;
+ ssize_t n;
+ int error, rv;
+
+ rv = 0;
+ cmp = emalloc(CMSG_LEN(sizeof(int)));
+
+ iov.iov_base = &error;
+ iov.iov_len = sizeof(int);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_control = cmp;
+ msg.msg_controllen = CMSG_LEN(sizeof(int));
+
+ n = recvmsg(fd, &msg, 0);
+ if (n == -1) {
+ rv = errno;
+ goto out;
+ }
+ if (n == 0) {
+ rv = ECONNRESET;
+ goto out;
+ }
+
+ /* the data for the server */
+ puffs_framebuf_putdata_atoff(pufbuf, 0, &error, sizeof(int));
+ if (error) {
+ rv = error;
+ goto out;
+ }
+ puffs_framebuf_putdata_atoff(pufbuf, sizeof(int),
+ CMSG_DATA(cmp), sizeof(int));
+ *done = 1;
+
+ out:
+ free(cmp);
+ return rv;
+}
+
+/*
+ * receive data from provider
+ *
+ * XXX: should read directly into the buffer and adjust offsets
+ * instead of doing memcpy
+ */
+static int
+readdata(struct puffs_framebuf *pufbuf, int fd, int *done)
+{
+ char buf[1024];
+ size_t max;
+ ssize_t n;
+ size_t moved;
+
+ /* don't override metadata */
+ if (puffs_framebuf_telloff(pufbuf) == 0)
+ puffs_framebuf_seekset(pufbuf, METADATASIZE);
+ puffs_framebuf_getdata_atoff(pufbuf, sizeof(int), &max, sizeof(size_t));
+ moved = puffs_framebuf_tellsize(pufbuf) - METADATASIZE;
+ assert(max >= moved);
+ max -= moved;
+
+ do {
+ n = read(fd, buf, MIN(sizeof(buf), max));
+ if (n == 0) {
+ if (moved)
+ break;
+ else
+ return -1; /* caught by read */
+ }
+ if (n < 0) {
+ if (moved)
+ return 0;
+
+ if (errno != EAGAIN)
+ return errno;
+ else
+ return 0;
+ }
+
+ puffs_framebuf_putdata(pufbuf, buf, n);
+ moved += n;
+ max -= n;
+ } while (max > 0);
+
+ *done = 1;
+
+ return 0;
+}
+
+static int
+portal_frame_rf(struct puffs_usermount *pu, struct puffs_framebuf *pufbuf,
+ int fd, int *done)
+{
+ int type;
+
+ if (puffs_framebuf_getdata_atoff(pufbuf, 0, &type, sizeof(int)) == -1)
+ return EINVAL;
+
+ if (type == PUFBUF_FD)
+ return readfd(pufbuf, fd, done);
+ else if (type == PUFBUF_DATA)
+ return readdata(pufbuf, fd, done);
+ else
+ abort();
+}
+
+static int
+portal_frame_wf(struct puffs_usermount *pu, struct puffs_framebuf *pufbuf,
+ int fd, int *done)
+{
+ void *win;
+ size_t pbsize, pboff, winlen;
+ ssize_t n;
+ int error;
+
+ pboff = puffs_framebuf_telloff(pufbuf);
+ pbsize = puffs_framebuf_tellsize(pufbuf);
+ error = 0;
+
+ do {
+ assert(pbsize > pboff);
+ winlen = pbsize - pboff;
+ if (puffs_framebuf_getwindow(pufbuf, pboff, &win, &winlen)==-1)
+ return errno;
+ n = write(fd, win, winlen);
+ if (n == 0) {
+ if (pboff != 0)
+ break;
+ else
+ return -1; /* caught by node_write */
+ }
+ if (n < 0) {
+ if (pboff != 0)
+ break;
+
+ if (errno != EAGAIN)
+ return errno;
+ return 0;
+ }
+
+ pboff += n;
+ puffs_framebuf_seekset(pufbuf, pboff);
+ } while (pboff != pbsize);
+
+ *done = 1;
+ puffs_framebuf_putdata_atoff(pufbuf, 0, &pboff, sizeof(size_t));
+ return error;
+}
+
+/* transfer file descriptor to master file server */
+static int
+sendfd(int s, int fd, int error)
+{
+ struct cmsghdr *cmp;
+ struct msghdr msg;
+ struct iovec iov;
+ ssize_t n;
+ int rv;
+
+ rv = 0;
+ cmp = emalloc(CMSG_LEN(sizeof(int)));
+
+ iov.iov_base = &error;
+ iov.iov_len = sizeof(int);
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ if (error == 0) {
+ cmp->cmsg_level = SOL_SOCKET;
+ cmp->cmsg_type = SCM_RIGHTS;
+ cmp->cmsg_len = CMSG_LEN(sizeof(int));
+
+ msg.msg_control = cmp;
+ msg.msg_controllen = CMSG_LEN(sizeof(int));
+ *(int *)CMSG_DATA(cmp) = fd;
+ } else {
+ msg.msg_control = NULL;
Home |
Main Index |
Thread Index |
Old Index