Home | History | Annotate | Line # | Download | only in rump_syspuffs
rump_syspuffs.c revision 1.3
      1  1.3  pooka /*	$NetBSD: rump_syspuffs.c,v 1.3 2008/08/11 13:32:55 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*
      4  1.1  pooka  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
      5  1.1  pooka  *
      6  1.1  pooka  * Development of this software was supported by the
      7  1.1  pooka  * Research Foundation of Helsinki University of Technology
      8  1.1  pooka  *
      9  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     10  1.1  pooka  * modification, are permitted provided that the following conditions
     11  1.1  pooka  * are met:
     12  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     13  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     14  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     17  1.1  pooka  *
     18  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19  1.1  pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  1.1  pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  1.1  pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22  1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1  pooka  * SUCH DAMAGE.
     29  1.1  pooka  */
     30  1.1  pooka 
     31  1.1  pooka #include <sys/types.h>
     32  1.1  pooka #include <sys/mount.h>
     33  1.1  pooka #include <sys/socket.h>
     34  1.2  pooka #include <sys/syslimits.h>
     35  1.1  pooka 
     36  1.1  pooka #include <assert.h>
     37  1.1  pooka #include <err.h>
     38  1.1  pooka #include <paths.h>
     39  1.1  pooka #include <puffs.h>
     40  1.1  pooka #include <stdio.h>
     41  1.1  pooka #include <stdlib.h>
     42  1.1  pooka #include <unistd.h>
     43  1.1  pooka 
     44  1.1  pooka #include <rump/p2k.h>
     45  1.1  pooka 
     46  1.1  pooka #include "puffs_rumpglue.h"
     47  1.1  pooka 
     48  1.1  pooka static void
     49  1.1  pooka usage(void)
     50  1.1  pooka {
     51  1.1  pooka 
     52  1.2  pooka 	errx(1, "usage: %s file_server fs_opts", getprogname());
     53  1.1  pooka }
     54  1.1  pooka 
     55  1.3  pooka static void
     56  1.3  pooka trapchild(int sig)
     57  1.3  pooka {
     58  1.3  pooka 
     59  1.3  pooka 	/* XXX: yaya, not reentrant */
     60  1.3  pooka 	errx(1, "child died");
     61  1.3  pooka }
     62  1.3  pooka 
     63  1.1  pooka int
     64  1.1  pooka main(int argc, char *argv[])
     65  1.1  pooka {
     66  1.1  pooka 	struct puffs_kargs kargs;
     67  1.3  pooka 	char *mntpath, *fromname;
     68  1.1  pooka 	size_t len;
     69  1.1  pooka 	char comfd[16];
     70  1.1  pooka 	int sv[2];
     71  1.3  pooka 	int mntflags, pflags, rv;
     72  1.1  pooka 
     73  1.1  pooka #if 1
     74  1.1  pooka 	extern int puffsdebug;
     75  1.1  pooka 	extern int putterdebug;
     76  1.1  pooka 
     77  1.1  pooka 	puffsdebug = putterdebug = 1;
     78  1.1  pooka #endif
     79  1.1  pooka 
     80  1.1  pooka 	setprogname(argv[0]);
     81  1.1  pooka 
     82  1.1  pooka 	if (argc < 2)
     83  1.1  pooka 		usage();
     84  1.1  pooka 
     85  1.1  pooka 	/* Create sucketpair for communication with the real file server */
     86  1.1  pooka 	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) == -1)
     87  1.1  pooka 		err(1, "socketpair");
     88  1.3  pooka 
     89  1.3  pooka 	signal(SIGCHLD, trapchild);
     90  1.1  pooka 
     91  1.1  pooka 	switch (fork()) {
     92  1.1  pooka 	case 0:
     93  1.3  pooka 		snprintf(comfd, sizeof(sv[0]), "%d", sv[0]);
     94  1.3  pooka 		if (setenv("PUFFS_COMFD", comfd, 1) == -1)
     95  1.3  pooka 			err(1, "setenv");
     96  1.3  pooka 
     97  1.3  pooka 		argv++;
     98  1.3  pooka 		if (execvp(argv[0], argv) == -1)
     99  1.1  pooka 			err(1, "execvp");
    100  1.1  pooka 		/*NOTREACHED*/
    101  1.1  pooka 	case -1:
    102  1.1  pooka 		err(1, "fork");
    103  1.1  pooka 		/*NOTREACHED*/
    104  1.1  pooka 	default:
    105  1.1  pooka 		break;
    106  1.1  pooka 	}
    107  1.1  pooka 
    108  1.1  pooka 	/* read args */
    109  1.1  pooka 	if (read(sv[1], &len, sizeof(len)) != sizeof(len))
    110  1.1  pooka 		err(1, "mp 1");
    111  1.1  pooka 	mntpath = malloc(len);
    112  1.1  pooka 	if (mntpath == NULL)
    113  1.1  pooka 		err(1, "malloc %zu", len);
    114  1.1  pooka 	if (read(sv[1], mntpath, len) != len)
    115  1.1  pooka 		err(1, "mp 2");
    116  1.1  pooka 	if (read(sv[1], &len, sizeof(len)) != sizeof(len))
    117  1.1  pooka 		err(1, "fn 1");
    118  1.1  pooka 	fromname = malloc(len);
    119  1.1  pooka 	if (fromname == NULL)
    120  1.1  pooka 		err(1, "malloc %zu", len);
    121  1.1  pooka 	if (read(sv[1], fromname, len) != len)
    122  1.1  pooka 		err(1, "fn 2");
    123  1.1  pooka 	if (read(sv[1], &mntflags, sizeof(mntflags)) != sizeof(mntflags))
    124  1.1  pooka 		err(1, "mntflags");
    125  1.1  pooka 	if (read(sv[1], &kargs, sizeof(kargs)) != sizeof(kargs))
    126  1.1  pooka 		err(1, "puffs_args");
    127  1.2  pooka 	if (read(sv[1], &pflags, sizeof(pflags)) != sizeof(pflags))
    128  1.1  pooka 		err(1, "pflags");
    129  1.1  pooka 
    130  1.3  pooka 	signal(SIGCHLD, SIG_DFL);
    131  1.3  pooka 
    132  1.1  pooka 	/* XXX: some adjustments */
    133  1.1  pooka 	pflags |= PUFFS_KFLAG_NOCACHE;
    134  1.1  pooka 	pflags &= ~PUFFS_FLAG_BUILDPATH;
    135  1.1  pooka 
    136  1.1  pooka 	rv = puffs_rumpglue_init(sv[1], &kargs.pa_fd);
    137  1.1  pooka 	assert(rv == 0);
    138  1.1  pooka 	rv = p2k_run_fs(MOUNT_PUFFS, fromname, mntpath, mntflags,
    139  1.1  pooka 		&kargs, sizeof(kargs), pflags);
    140  1.1  pooka 	if (rv)
    141  1.1  pooka 		err(1, "mount");
    142  1.1  pooka 
    143  1.1  pooka 	return 0;
    144  1.1  pooka }
    145