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