Home | History | Annotate | Line # | Download | only in puffs
puffs_vfsops.c revision 1.78.10.3
      1  1.78.10.3      yamt /*	$NetBSD: puffs_vfsops.c,v 1.78.10.3 2010/03/11 15:04:14 yamt Exp $	*/
      2        1.1     pooka 
      3        1.1     pooka /*
      4        1.1     pooka  * Copyright (c) 2005, 2006  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  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8        1.1     pooka  * The Google SoC project was mentored by Bill Studenmund.
      9        1.1     pooka  *
     10        1.1     pooka  * Redistribution and use in source and binary forms, with or without
     11        1.1     pooka  * modification, are permitted provided that the following conditions
     12        1.1     pooka  * are met:
     13        1.1     pooka  * 1. Redistributions of source code must retain the above copyright
     14        1.1     pooka  *    notice, this list of conditions and the following disclaimer.
     15        1.1     pooka  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1     pooka  *    notice, this list of conditions and the following disclaimer in the
     17        1.1     pooka  *    documentation and/or other materials provided with the distribution.
     18        1.1     pooka  *
     19        1.1     pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     20        1.1     pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21        1.1     pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22        1.1     pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23        1.1     pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.1     pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25        1.1     pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1     pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1     pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1     pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1     pooka  * SUCH DAMAGE.
     30        1.1     pooka  */
     31        1.1     pooka 
     32        1.1     pooka #include <sys/cdefs.h>
     33  1.78.10.3      yamt __KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.78.10.3 2010/03/11 15:04:14 yamt Exp $");
     34        1.1     pooka 
     35        1.1     pooka #include <sys/param.h>
     36        1.1     pooka #include <sys/mount.h>
     37        1.1     pooka #include <sys/malloc.h>
     38        1.1     pooka #include <sys/extattr.h>
     39        1.1     pooka #include <sys/queue.h>
     40        1.1     pooka #include <sys/vnode.h>
     41        1.1     pooka #include <sys/dirent.h>
     42        1.1     pooka #include <sys/kauth.h>
     43       1.47        ad #include <sys/proc.h>
     44  1.78.10.1      yamt #include <sys/module.h>
     45  1.78.10.3      yamt #include <sys/kthread.h>
     46        1.1     pooka 
     47       1.68     pooka #include <dev/putter/putter_sys.h>
     48        1.1     pooka 
     49       1.78  dholland #include <miscfs/genfs/genfs.h>
     50       1.78  dholland 
     51        1.1     pooka #include <fs/puffs/puffs_msgif.h>
     52        1.1     pooka #include <fs/puffs/puffs_sys.h>
     53        1.1     pooka 
     54       1.66     pooka #include <lib/libkern/libkern.h>
     55       1.66     pooka 
     56       1.38     pooka #include <nfs/nfsproto.h> /* for fh sizes */
     57       1.38     pooka 
     58  1.78.10.2      yamt MODULE(MODULE_CLASS_VFS, puffs, "putter");
     59  1.78.10.1      yamt 
     60       1.73     pooka VFS_PROTOS(puffs_vfsop);
     61        1.1     pooka 
     62       1.22     pooka #ifndef PUFFS_PNODEBUCKETS
     63       1.22     pooka #define PUFFS_PNODEBUCKETS 256
     64       1.22     pooka #endif
     65       1.22     pooka #ifndef PUFFS_MAXPNODEBUCKETS
     66       1.35     pooka #define PUFFS_MAXPNODEBUCKETS 8192
     67       1.22     pooka #endif
     68       1.35     pooka int puffs_pnodebuckets_default = PUFFS_PNODEBUCKETS;
     69       1.35     pooka int puffs_maxpnodebuckets = PUFFS_MAXPNODEBUCKETS;
     70       1.22     pooka 
     71       1.70     pooka #define BUCKETALLOC(a) (sizeof(struct puffs_pnode_hashlist *) * (a))
     72       1.70     pooka 
     73       1.66     pooka static struct putter_ops puffs_putter = {
     74       1.66     pooka 	.pop_getout	= puffs_msgif_getout,
     75       1.66     pooka 	.pop_releaseout	= puffs_msgif_releaseout,
     76       1.66     pooka 	.pop_waitcount	= puffs_msgif_waitcount,
     77       1.66     pooka 	.pop_dispatch	= puffs_msgif_dispatch,
     78       1.66     pooka 	.pop_close	= puffs_msgif_close,
     79       1.66     pooka };
     80       1.66     pooka 
     81        1.1     pooka int
     82       1.73     pooka puffs_vfsop_mount(struct mount *mp, const char *path, void *data,
     83       1.73     pooka 	size_t *data_len)
     84        1.1     pooka {
     85       1.22     pooka 	struct puffs_mount *pmp = NULL;
     86       1.34     pooka 	struct puffs_kargs *args;
     87       1.51     pooka 	char fstype[_VFS_NAMELEN];
     88       1.51     pooka 	char *p;
     89       1.22     pooka 	int error = 0, i;
     90       1.71     pooka 	pid_t mntpid = curlwp->l_proc->p_pid;
     91        1.1     pooka 
     92       1.48       dsl 	if (*data_len < sizeof *args)
     93       1.48       dsl 		return EINVAL;
     94       1.48       dsl 
     95        1.1     pooka 	if (mp->mnt_flag & MNT_GETARGS) {
     96        1.1     pooka 		pmp = MPTOPUFFSMP(mp);
     97       1.48       dsl 		*(struct puffs_kargs *)data = pmp->pmp_args;
     98       1.48       dsl 		*data_len = sizeof *args;
     99       1.48       dsl 		return 0;
    100        1.1     pooka 	}
    101        1.1     pooka 
    102        1.1     pooka 	/* update is not supported currently */
    103        1.1     pooka 	if (mp->mnt_flag & MNT_UPDATE)
    104        1.1     pooka 		return EOPNOTSUPP;
    105        1.1     pooka 
    106        1.1     pooka 	/*
    107        1.1     pooka 	 * We need the file system name
    108        1.1     pooka 	 */
    109        1.1     pooka 	if (!data)
    110        1.1     pooka 		return EINVAL;
    111        1.1     pooka 
    112       1.70     pooka 	args = (struct puffs_kargs *)data;
    113       1.17     pooka 
    114       1.17     pooka 	/* devel phase */
    115       1.17     pooka 	if (args->pa_vers != (PUFFSVERSION | PUFFSDEVELVERS)) {
    116       1.64     pooka 		printf("puffs_mount: development version mismatch: "
    117       1.64     pooka 		    "kernel %d, lib %d\n",
    118       1.64     pooka 		    PUFFSVERSION, args->pa_vers & ~PUFFSDEVELVERS);
    119       1.17     pooka 		error = EINVAL;
    120       1.17     pooka 		goto out;
    121       1.17     pooka 	}
    122        1.1     pooka 
    123       1.54     pooka 	if ((args->pa_flags & ~PUFFS_KFLAG_MASK) != 0) {
    124       1.54     pooka 		printf("puffs_mount: invalid KFLAGs 0x%x\n", args->pa_flags);
    125       1.54     pooka 		error = EINVAL;
    126       1.54     pooka 		goto out;
    127       1.54     pooka 	}
    128       1.54     pooka 	if ((args->pa_fhflags & ~PUFFS_FHFLAG_MASK) != 0) {
    129       1.54     pooka 		printf("puffs_mount: invalid FHFLAGs 0x%x\n", args->pa_fhflags);
    130       1.54     pooka 		error = EINVAL;
    131       1.54     pooka 		goto out;
    132       1.54     pooka 	}
    133       1.54     pooka 
    134       1.54     pooka 	/* use dummy value for passthrough */
    135       1.54     pooka 	if (args->pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    136       1.54     pooka 		args->pa_fhsize = sizeof(struct fid);
    137        1.8     pooka 
    138       1.38     pooka 	/* sanitize file handle length */
    139       1.38     pooka 	if (PUFFS_TOFHSIZE(args->pa_fhsize) > FHANDLE_SIZE_MAX) {
    140       1.38     pooka 		printf("puffs_mount: handle size %zu too large\n",
    141       1.38     pooka 		    args->pa_fhsize);
    142       1.38     pooka 		error = EINVAL;
    143       1.38     pooka 		goto out;
    144       1.38     pooka 	}
    145       1.38     pooka 	/* sanity check file handle max sizes */
    146       1.38     pooka 	if (args->pa_fhsize && args->pa_fhflags & PUFFS_FHFLAG_PROTOMASK) {
    147       1.38     pooka 		size_t kfhsize = PUFFS_TOFHSIZE(args->pa_fhsize);
    148       1.38     pooka 
    149       1.38     pooka 		if (args->pa_fhflags & PUFFS_FHFLAG_NFSV2) {
    150       1.38     pooka 			if (NFSX_FHTOOBIG_P(kfhsize, 0)) {
    151       1.38     pooka 				printf("puffs_mount: fhsize larger than "
    152       1.38     pooka 				    "NFSv2 max %d\n",
    153       1.38     pooka 				    PUFFS_FROMFHSIZE(NFSX_V2FH));
    154       1.38     pooka 				error = EINVAL;
    155       1.38     pooka 				goto out;
    156       1.38     pooka 			}
    157       1.38     pooka 		}
    158       1.38     pooka 
    159       1.38     pooka 		if (args->pa_fhflags & PUFFS_FHFLAG_NFSV3) {
    160       1.38     pooka 			if (NFSX_FHTOOBIG_P(kfhsize, 1)) {
    161       1.38     pooka 				printf("puffs_mount: fhsize larger than "
    162       1.38     pooka 				    "NFSv3 max %d\n",
    163       1.38     pooka 				    PUFFS_FROMFHSIZE(NFSX_V3FHMAX));
    164       1.38     pooka 				error = EINVAL;
    165       1.38     pooka 				goto out;
    166       1.38     pooka 			}
    167       1.38     pooka 		}
    168       1.38     pooka 	}
    169       1.38     pooka 
    170       1.51     pooka 	/* don't allow non-printing characters (like my sweet umlauts.. snif) */
    171       1.51     pooka 	args->pa_typename[sizeof(args->pa_typename)-1] = '\0';
    172       1.51     pooka 	for (p = args->pa_typename; *p; p++)
    173       1.51     pooka 		if (*p < ' ' || *p > '~')
    174       1.51     pooka 			*p = '.';
    175       1.51     pooka 
    176       1.51     pooka 	args->pa_mntfromname[sizeof(args->pa_mntfromname)-1] = '\0';
    177       1.51     pooka 	for (p = args->pa_mntfromname; *p; p++)
    178       1.51     pooka 		if (*p < ' ' || *p > '~')
    179       1.51     pooka 			*p = '.';
    180       1.51     pooka 
    181        1.1     pooka 	/* build real name */
    182       1.51     pooka 	(void)strlcpy(fstype, PUFFS_TYPEPREFIX, sizeof(fstype));
    183       1.51     pooka 	(void)strlcat(fstype, args->pa_typename, sizeof(fstype));
    184        1.1     pooka 
    185        1.1     pooka 	/* inform user server if it got the max request size it wanted */
    186       1.63     pooka 	if (args->pa_maxmsglen == 0 || args->pa_maxmsglen > PUFFS_MSG_MAXSIZE)
    187       1.63     pooka 		args->pa_maxmsglen = PUFFS_MSG_MAXSIZE;
    188       1.63     pooka 	else if (args->pa_maxmsglen < 2*PUFFS_MSGSTRUCT_MAX)
    189       1.63     pooka 		args->pa_maxmsglen = 2*PUFFS_MSGSTRUCT_MAX;
    190       1.63     pooka 
    191       1.51     pooka 	(void)strlcpy(args->pa_typename, fstype, sizeof(args->pa_typename));
    192        1.1     pooka 
    193       1.40     pooka 	if (args->pa_nhashbuckets == 0)
    194       1.40     pooka 		args->pa_nhashbuckets = puffs_pnodebuckets_default;
    195       1.40     pooka 	if (args->pa_nhashbuckets < 1)
    196       1.40     pooka 		args->pa_nhashbuckets = 1;
    197       1.40     pooka 	if (args->pa_nhashbuckets > PUFFS_MAXPNODEBUCKETS) {
    198       1.40     pooka 		args->pa_nhashbuckets = puffs_maxpnodebuckets;
    199       1.40     pooka 		printf("puffs_mount: using %d hash buckets. "
    200       1.40     pooka 		    "adjust puffs_maxpnodebuckets for more\n",
    201       1.40     pooka 		    puffs_maxpnodebuckets);
    202       1.40     pooka 	}
    203       1.40     pooka 
    204       1.51     pooka 	error = set_statvfs_info(path, UIO_USERSPACE, args->pa_mntfromname,
    205       1.71     pooka 	    UIO_SYSSPACE, fstype, mp, curlwp);
    206        1.1     pooka 	if (error)
    207       1.17     pooka 		goto out;
    208       1.10     pooka 	mp->mnt_stat.f_iosize = DEV_BSIZE;
    209        1.1     pooka 
    210       1.42     pooka 	/*
    211       1.42     pooka 	 * We can't handle the VFS_STATVFS() mount_domount() does
    212       1.42     pooka 	 * after VFS_MOUNT() because we'd deadlock, so handle it
    213       1.42     pooka 	 * here already.
    214       1.42     pooka 	 */
    215       1.42     pooka 	copy_statvfs_info(&args->pa_svfsb, mp);
    216       1.42     pooka 	(void)memcpy(&mp->mnt_stat, &args->pa_svfsb, sizeof(mp->mnt_stat));
    217       1.42     pooka 
    218       1.70     pooka 	pmp = kmem_zalloc(sizeof(struct puffs_mount), KM_SLEEP);
    219        1.1     pooka 
    220        1.6     pooka 	mp->mnt_fs_bshift = DEV_BSHIFT;
    221        1.6     pooka 	mp->mnt_dev_bshift = DEV_BSHIFT;
    222        1.6     pooka 	mp->mnt_flag &= ~MNT_LOCAL; /* we don't really know, so ... */
    223        1.1     pooka 	mp->mnt_data = pmp;
    224  1.78.10.3      yamt 
    225  1.78.10.3      yamt #if 0
    226  1.78.10.3      yamt 	/*
    227  1.78.10.3      yamt 	 * XXX: puffs code is MPSAFE.  However, VFS really isn't.
    228  1.78.10.3      yamt 	 * Currently, there is nothing which protects an inode from
    229  1.78.10.3      yamt 	 * reclaim while there are threads inside the file system.
    230  1.78.10.3      yamt 	 * This means that in the event of a server crash, an MPSAFE
    231  1.78.10.3      yamt 	 * mount is likely to end up accessing invalid memory.  For the
    232  1.78.10.3      yamt 	 * non-mpsafe case, the kernel lock, general structure of
    233  1.78.10.3      yamt 	 * puffs and pmp_refcount protect the threads during escape.
    234  1.78.10.3      yamt 	 *
    235  1.78.10.3      yamt 	 * Fixing this will require:
    236  1.78.10.3      yamt 	 *  a) fixing vfs
    237  1.78.10.3      yamt 	 * OR
    238  1.78.10.3      yamt 	 *  b) adding a small sleep to puffs_msgif_close() between
    239  1.78.10.3      yamt 	 *     userdead() and dounmount().
    240  1.78.10.3      yamt 	 *     (well, this isn't really a fix, but would solve
    241  1.78.10.3      yamt 	 *     99.999% of the race conditions).
    242  1.78.10.3      yamt 	 *
    243  1.78.10.3      yamt 	 * Also, in the event of "b", unmount -f should be used,
    244  1.78.10.3      yamt 	 * like with any other file system, sparingly and only when
    245  1.78.10.3      yamt 	 * it is "known" to be safe.
    246  1.78.10.3      yamt 	 */
    247  1.78.10.3      yamt 	mp->mnt_iflags |= IMNT_MPSAFE;
    248  1.78.10.3      yamt #endif
    249        1.6     pooka 
    250        1.1     pooka 	pmp->pmp_status = PUFFSTAT_MOUNTING;
    251        1.1     pooka 	pmp->pmp_mp = mp;
    252       1.63     pooka 	pmp->pmp_msg_maxsize = args->pa_maxmsglen;
    253       1.17     pooka 	pmp->pmp_args = *args;
    254        1.1     pooka 
    255       1.40     pooka 	pmp->pmp_npnodehash = args->pa_nhashbuckets;
    256  1.78.10.3      yamt 	pmp->pmp_pnodehash = kmem_alloc(BUCKETALLOC(pmp->pmp_npnodehash),
    257  1.78.10.3      yamt 	    KM_SLEEP);
    258       1.22     pooka 	for (i = 0; i < pmp->pmp_npnodehash; i++)
    259       1.22     pooka 		LIST_INIT(&pmp->pmp_pnodehash[i]);
    260       1.57     pooka 	LIST_INIT(&pmp->pmp_newcookie);
    261       1.22     pooka 
    262        1.1     pooka 	/*
    263        1.1     pooka 	 * Inform the fileops processing code that we have a mountpoint.
    264        1.1     pooka 	 * If it doesn't know about anyone with our pid/fd having the
    265        1.1     pooka 	 * device open, punt
    266        1.1     pooka 	 */
    267       1.66     pooka 	if ((pmp->pmp_pi
    268       1.66     pooka 	    = putter_attach(mntpid, args->pa_fd, pmp, &puffs_putter)) == NULL) {
    269       1.17     pooka 		error = ENOENT;
    270       1.17     pooka 		goto out;
    271        1.1     pooka 	}
    272        1.1     pooka 
    273       1.42     pooka 	/* XXX: check parameters */
    274       1.42     pooka 	pmp->pmp_root_cookie = args->pa_root_cookie;
    275       1.42     pooka 	pmp->pmp_root_vtype = args->pa_root_vtype;
    276       1.42     pooka 	pmp->pmp_root_vsize = args->pa_root_vsize;
    277       1.42     pooka 	pmp->pmp_root_rdev = args->pa_root_rdev;
    278       1.42     pooka 
    279       1.31     pooka 	mutex_init(&pmp->pmp_lock, MUTEX_DEFAULT, IPL_NONE);
    280  1.78.10.3      yamt 	mutex_init(&pmp->pmp_sopmtx, MUTEX_DEFAULT, IPL_NONE);
    281       1.63     pooka 	cv_init(&pmp->pmp_msg_waiter_cv, "puffsget");
    282       1.41     pooka 	cv_init(&pmp->pmp_refcount_cv, "puffsref");
    283       1.31     pooka 	cv_init(&pmp->pmp_unmounting_cv, "puffsum");
    284  1.78.10.3      yamt 	cv_init(&pmp->pmp_sopcv, "puffsop");
    285       1.63     pooka 	TAILQ_INIT(&pmp->pmp_msg_touser);
    286       1.63     pooka 	TAILQ_INIT(&pmp->pmp_msg_replywait);
    287  1.78.10.3      yamt 	TAILQ_INIT(&pmp->pmp_sopreqs);
    288  1.78.10.3      yamt 
    289  1.78.10.3      yamt 	if ((error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL,
    290  1.78.10.3      yamt 	    puffs_sop_thread, pmp, NULL, "puffsop")) != 0)
    291  1.78.10.3      yamt 		goto out;
    292  1.78.10.3      yamt 	pmp->pmp_sopthrcount = 1;
    293        1.1     pooka 
    294        1.1     pooka 	DPRINTF(("puffs_mount: mount point at %p, puffs specific at %p\n",
    295        1.1     pooka 	    mp, MPTOPUFFSMP(mp)));
    296        1.1     pooka 
    297        1.1     pooka 	vfs_getnewfsid(mp);
    298        1.1     pooka 
    299       1.17     pooka  out:
    300  1.78.10.3      yamt 	if (error && pmp && pmp->pmp_pi)
    301  1.78.10.3      yamt 		putter_detach(pmp->pmp_pi);
    302       1.22     pooka 	if (error && pmp && pmp->pmp_pnodehash)
    303       1.70     pooka 		kmem_free(pmp->pmp_pnodehash, BUCKETALLOC(pmp->pmp_npnodehash));
    304       1.22     pooka 	if (error && pmp)
    305       1.70     pooka 		kmem_free(pmp, sizeof(struct puffs_mount));
    306       1.17     pooka 	return error;
    307        1.1     pooka }
    308        1.1     pooka 
    309        1.1     pooka int
    310       1.73     pooka puffs_vfsop_start(struct mount *mp, int flags)
    311        1.1     pooka {
    312       1.42     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    313        1.1     pooka 
    314       1.42     pooka 	KASSERT(pmp->pmp_status == PUFFSTAT_MOUNTING);
    315        1.1     pooka 	pmp->pmp_status = PUFFSTAT_RUNNING;
    316        1.1     pooka 
    317        1.1     pooka 	return 0;
    318        1.1     pooka }
    319        1.1     pooka 
    320        1.1     pooka int
    321       1.73     pooka puffs_vfsop_unmount(struct mount *mp, int mntflags)
    322        1.1     pooka {
    323       1.63     pooka 	PUFFS_MSG_VARS(vfs, unmount);
    324        1.1     pooka 	struct puffs_mount *pmp;
    325        1.1     pooka 	int error, force;
    326        1.1     pooka 
    327        1.1     pooka 	error = 0;
    328        1.1     pooka 	force = mntflags & MNT_FORCE;
    329        1.1     pooka 	pmp = MPTOPUFFSMP(mp);
    330        1.1     pooka 
    331        1.1     pooka 	DPRINTF(("puffs_unmount: detach filesystem from vfs, current "
    332        1.1     pooka 	    "status 0x%x\n", pmp->pmp_status));
    333        1.1     pooka 
    334        1.1     pooka 	/*
    335        1.1     pooka 	 * flush all the vnodes.  VOP_RECLAIM() takes care that the
    336        1.1     pooka 	 * root vnode does not get flushed until unmount.  The
    337        1.1     pooka 	 * userspace root node cookie is stored in the mount
    338        1.1     pooka 	 * structure, so we can always re-instantiate a root vnode,
    339        1.1     pooka 	 * should userspace unmount decide it doesn't want to
    340        1.1     pooka 	 * cooperate.
    341        1.1     pooka 	 */
    342        1.1     pooka 	error = vflush(mp, NULLVP, force ? FORCECLOSE : 0);
    343        1.1     pooka 	if (error)
    344        1.1     pooka 		goto out;
    345        1.1     pooka 
    346        1.1     pooka 	/*
    347        1.1     pooka 	 * If we are not DYING, we should ask userspace's opinion
    348        1.1     pooka 	 * about the situation
    349        1.1     pooka 	 */
    350       1.31     pooka 	mutex_enter(&pmp->pmp_lock);
    351        1.1     pooka 	if (pmp->pmp_status != PUFFSTAT_DYING) {
    352       1.16     pooka 		pmp->pmp_unmounting = 1;
    353       1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    354       1.16     pooka 
    355       1.63     pooka 		PUFFS_MSG_ALLOC(vfs, unmount);
    356       1.69     pooka 		puffs_msg_setinfo(park_unmount,
    357       1.69     pooka 		    PUFFSOP_VFS, PUFFS_VFS_UNMOUNT, NULL);
    358       1.63     pooka 		unmount_msg->pvfsr_flags = mntflags;
    359       1.63     pooka 
    360       1.69     pooka 		PUFFS_MSG_ENQUEUEWAIT(pmp, park_unmount, error);
    361       1.63     pooka 		PUFFS_MSG_RELEASE(unmount);
    362       1.16     pooka 
    363       1.60     pooka 		error = checkerr(pmp, error, __func__);
    364       1.16     pooka 		DPRINTF(("puffs_unmount: error %d force %d\n", error, force));
    365       1.16     pooka 
    366       1.31     pooka 		mutex_enter(&pmp->pmp_lock);
    367       1.16     pooka 		pmp->pmp_unmounting = 0;
    368       1.31     pooka 		cv_broadcast(&pmp->pmp_unmounting_cv);
    369        1.1     pooka 	}
    370        1.1     pooka 
    371        1.1     pooka 	/*
    372        1.1     pooka 	 * if userspace cooperated or we really need to die,
    373        1.1     pooka 	 * screw what userland thinks and just die.
    374        1.1     pooka 	 */
    375        1.1     pooka 	if (error == 0 || force) {
    376  1.78.10.3      yamt 		struct puffs_sopreq *psopr;
    377  1.78.10.3      yamt 
    378       1.26     pooka 		/* tell waiters & other resources to go unwait themselves */
    379       1.26     pooka 		puffs_userdead(pmp);
    380       1.66     pooka 		putter_detach(pmp->pmp_pi);
    381       1.26     pooka 
    382       1.26     pooka 		/*
    383       1.41     pooka 		 * Wait until there are no more users for the mount resource.
    384       1.41     pooka 		 * Notice that this is hooked against transport_close
    385       1.41     pooka 		 * and return from touser.  In an ideal world, it would
    386       1.41     pooka 		 * be hooked against final return from all operations.
    387       1.41     pooka 		 * But currently it works well enough, since nobody
    388       1.41     pooka 		 * does weird blocking voodoo after return from touser().
    389       1.26     pooka 		 */
    390       1.41     pooka 		while (pmp->pmp_refcount != 0)
    391       1.41     pooka 			cv_wait(&pmp->pmp_refcount_cv, &pmp->pmp_lock);
    392       1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    393       1.26     pooka 
    394  1.78.10.3      yamt 		/*
    395  1.78.10.3      yamt 		 * Release kernel thread now that there is nothing
    396  1.78.10.3      yamt 		 * it would be wanting to lock.
    397  1.78.10.3      yamt 		 */
    398  1.78.10.3      yamt 		psopr = kmem_alloc(sizeof(*psopr), KM_SLEEP);
    399  1.78.10.3      yamt 		psopr->psopr_sopreq = PUFFS_SOPREQSYS_EXIT;
    400  1.78.10.3      yamt 		mutex_enter(&pmp->pmp_sopmtx);
    401  1.78.10.3      yamt 		if (pmp->pmp_sopthrcount == 0) {
    402  1.78.10.3      yamt 			mutex_exit(&pmp->pmp_sopmtx);
    403  1.78.10.3      yamt 			kmem_free(psopr, sizeof(*psopr));
    404  1.78.10.3      yamt 			mutex_enter(&pmp->pmp_sopmtx);
    405  1.78.10.3      yamt 			KASSERT(pmp->pmp_sopthrcount == 0);
    406  1.78.10.3      yamt 		} else {
    407  1.78.10.3      yamt 			TAILQ_INSERT_TAIL(&pmp->pmp_sopreqs,
    408  1.78.10.3      yamt 			    psopr, psopr_entries);
    409  1.78.10.3      yamt 			cv_signal(&pmp->pmp_sopcv);
    410  1.78.10.3      yamt 		}
    411  1.78.10.3      yamt 		while (pmp->pmp_sopthrcount > 0)
    412  1.78.10.3      yamt 			cv_wait(&pmp->pmp_sopcv, &pmp->pmp_sopmtx);
    413  1.78.10.3      yamt 		mutex_exit(&pmp->pmp_sopmtx);
    414  1.78.10.3      yamt 
    415       1.26     pooka 		/* free resources now that we hopefully have no waiters left */
    416       1.41     pooka 		cv_destroy(&pmp->pmp_unmounting_cv);
    417       1.41     pooka 		cv_destroy(&pmp->pmp_refcount_cv);
    418       1.63     pooka 		cv_destroy(&pmp->pmp_msg_waiter_cv);
    419  1.78.10.3      yamt 		cv_destroy(&pmp->pmp_sopcv);
    420       1.31     pooka 		mutex_destroy(&pmp->pmp_lock);
    421  1.78.10.3      yamt 		mutex_destroy(&pmp->pmp_sopmtx);
    422       1.31     pooka 
    423       1.70     pooka 		kmem_free(pmp->pmp_pnodehash, BUCKETALLOC(pmp->pmp_npnodehash));
    424       1.70     pooka 		kmem_free(pmp, sizeof(struct puffs_mount));
    425        1.1     pooka 		error = 0;
    426       1.16     pooka 	} else {
    427       1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    428        1.1     pooka 	}
    429        1.1     pooka 
    430        1.1     pooka  out:
    431        1.2     pooka 	DPRINTF(("puffs_unmount: return %d\n", error));
    432        1.1     pooka 	return error;
    433        1.1     pooka }
    434        1.1     pooka 
    435        1.1     pooka /*
    436        1.1     pooka  * This doesn't need to travel to userspace
    437        1.1     pooka  */
    438        1.1     pooka int
    439       1.73     pooka puffs_vfsop_root(struct mount *mp, struct vnode **vpp)
    440        1.1     pooka {
    441       1.45     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    442       1.59     pooka 	int rv;
    443        1.1     pooka 
    444       1.59     pooka 	rv = puffs_cookie2vnode(pmp, pmp->pmp_root_cookie, 1, 1, vpp);
    445       1.59     pooka 	KASSERT(rv != PUFFS_NOSUCHCOOKIE);
    446       1.59     pooka 	return rv;
    447        1.1     pooka }
    448        1.1     pooka 
    449        1.1     pooka int
    450       1.73     pooka puffs_vfsop_statvfs(struct mount *mp, struct statvfs *sbp)
    451        1.1     pooka {
    452       1.63     pooka 	PUFFS_MSG_VARS(vfs, statvfs);
    453        1.1     pooka 	struct puffs_mount *pmp;
    454        1.1     pooka 	int error = 0;
    455        1.1     pooka 
    456        1.1     pooka 	pmp = MPTOPUFFSMP(mp);
    457        1.1     pooka 
    458        1.1     pooka 	/*
    459        1.1     pooka 	 * If we are mounting, it means that the userspace counterpart
    460        1.1     pooka 	 * is calling mount(2), but mount(2) also calls statvfs.  So
    461        1.1     pooka 	 * requesting statvfs from userspace would mean a deadlock.
    462        1.1     pooka 	 * Compensate.
    463        1.1     pooka 	 */
    464  1.78.10.3      yamt 	if (__predict_false(pmp->pmp_status == PUFFSTAT_MOUNTING))
    465        1.1     pooka 		return EINPROGRESS;
    466        1.1     pooka 
    467       1.63     pooka 	PUFFS_MSG_ALLOC(vfs, statvfs);
    468       1.69     pooka 	puffs_msg_setinfo(park_statvfs, PUFFSOP_VFS, PUFFS_VFS_STATVFS, NULL);
    469        1.1     pooka 
    470       1.69     pooka 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_statvfs, error);
    471       1.60     pooka 	error = checkerr(pmp, error, __func__);
    472       1.63     pooka 	statvfs_msg->pvfsr_sb.f_iosize = DEV_BSIZE;
    473       1.10     pooka 
    474        1.1     pooka 	/*
    475        1.1     pooka 	 * Try to produce a sensible result even in the event
    476        1.1     pooka 	 * of userspace error.
    477        1.1     pooka 	 *
    478        1.1     pooka 	 * XXX: cache the copy in non-error case
    479        1.1     pooka 	 */
    480        1.1     pooka 	if (!error) {
    481       1.63     pooka 		copy_statvfs_info(&statvfs_msg->pvfsr_sb, mp);
    482       1.63     pooka 		(void)memcpy(sbp, &statvfs_msg->pvfsr_sb,
    483        1.1     pooka 		    sizeof(struct statvfs));
    484        1.1     pooka 	} else {
    485        1.1     pooka 		copy_statvfs_info(sbp, mp);
    486        1.1     pooka 	}
    487        1.1     pooka 
    488       1.63     pooka 	PUFFS_MSG_RELEASE(statvfs);
    489       1.14     pooka 	return error;
    490        1.1     pooka }
    491        1.1     pooka 
    492       1.26     pooka static int
    493  1.78.10.3      yamt pageflush(struct mount *mp, kauth_cred_t cred, int waitfor)
    494        1.1     pooka {
    495       1.26     pooka 	struct puffs_node *pn;
    496       1.74        ad 	struct vnode *vp, *mvp;
    497       1.30     pooka 	int error, rv;
    498        1.1     pooka 
    499       1.18     pooka 	error = 0;
    500       1.18     pooka 
    501       1.74        ad 	/* Allocate a marker vnode. */
    502       1.76     pooka 	if ((mvp = vnalloc(mp)) == NULL)
    503       1.74        ad 		return ENOMEM;
    504       1.74        ad 
    505       1.18     pooka 	/*
    506       1.24     pooka 	 * Sync all cached data from regular vnodes (which are not
    507       1.24     pooka 	 * currently locked, see below).  After this we call VFS_SYNC
    508       1.24     pooka 	 * for the fs server, which should handle data and metadata for
    509       1.24     pooka 	 * all the nodes it knows to exist.
    510       1.18     pooka 	 */
    511       1.74        ad 	mutex_enter(&mntvnode_lock);
    512       1.18     pooka  loop:
    513       1.74        ad 	for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = vunmark(mvp)) {
    514       1.74        ad 		vmark(mvp, vp);
    515       1.74        ad 		if (vp->v_mount != mp || vismarker(vp))
    516       1.74        ad 			continue;
    517       1.18     pooka 
    518       1.74        ad 		mutex_enter(&vp->v_interlock);
    519       1.26     pooka 		pn = VPTOPP(vp);
    520       1.19     pooka 		if (vp->v_type != VREG || UVM_OBJ_IS_CLEAN(&vp->v_uobj)) {
    521       1.74        ad 			mutex_exit(&vp->v_interlock);
    522       1.18     pooka 			continue;
    523       1.18     pooka 		}
    524       1.18     pooka 
    525       1.74        ad 		mutex_exit(&mntvnode_lock);
    526       1.21     pooka 
    527       1.21     pooka 		/*
    528       1.21     pooka 		 * Here we try to get a reference to the vnode and to
    529       1.21     pooka 		 * lock it.  This is mostly cargo-culted, but I will
    530       1.21     pooka 		 * offer an explanation to why I believe this might
    531       1.21     pooka 		 * actually do the right thing.
    532       1.21     pooka 		 *
    533       1.21     pooka 		 * If the vnode is a goner, we quite obviously don't need
    534       1.21     pooka 		 * to sync it.
    535       1.21     pooka 		 *
    536       1.21     pooka 		 * If the vnode was busy, we don't need to sync it because
    537       1.21     pooka 		 * this is never called with MNT_WAIT except from
    538       1.21     pooka 		 * dounmount(), when we are wait-flushing all the dirty
    539       1.21     pooka 		 * vnodes through other routes in any case.  So there,
    540       1.21     pooka 		 * sync() doesn't actually sync.  Happy now?
    541       1.21     pooka 		 */
    542       1.18     pooka 		rv = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
    543       1.18     pooka 		if (rv) {
    544       1.74        ad 			mutex_enter(&mntvnode_lock);
    545       1.74        ad 			if (rv == ENOENT) {
    546       1.74        ad 				(void)vunmark(mvp);
    547       1.18     pooka 				goto loop;
    548       1.74        ad 			}
    549       1.18     pooka 			continue;
    550       1.18     pooka 		}
    551       1.18     pooka 
    552  1.78.10.3      yamt 		/* hmm.. is the FAF thing entirely sensible? */
    553  1.78.10.3      yamt 		if (waitfor == MNT_LAZY) {
    554       1.74        ad 			mutex_enter(&vp->v_interlock);
    555  1.78.10.3      yamt 			pn->pn_stat |= PNODE_FAF;
    556       1.74        ad 			mutex_exit(&vp->v_interlock);
    557       1.30     pooka 		}
    558       1.71     pooka 		rv = VOP_FSYNC(vp, cred, waitfor, 0, 0);
    559  1.78.10.3      yamt 		if (waitfor == MNT_LAZY) {
    560       1.74        ad 			mutex_enter(&vp->v_interlock);
    561  1.78.10.3      yamt 			pn->pn_stat &= ~PNODE_FAF;
    562       1.74        ad 			mutex_exit(&vp->v_interlock);
    563       1.26     pooka 		}
    564       1.21     pooka 		if (rv)
    565       1.18     pooka 			error = rv;
    566       1.18     pooka 		vput(vp);
    567       1.74        ad 		mutex_enter(&mntvnode_lock);
    568       1.18     pooka 	}
    569       1.74        ad 	mutex_exit(&mntvnode_lock);
    570       1.76     pooka 	vnfree(mvp);
    571       1.18     pooka 
    572       1.26     pooka 	return error;
    573       1.26     pooka }
    574       1.26     pooka 
    575       1.26     pooka int
    576       1.73     pooka puffs_vfsop_sync(struct mount *mp, int waitfor, struct kauth_cred *cred)
    577       1.26     pooka {
    578       1.63     pooka 	PUFFS_MSG_VARS(vfs, sync);
    579       1.62     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    580       1.26     pooka 	int error, rv;
    581       1.26     pooka 
    582  1.78.10.3      yamt 	error = pageflush(mp, cred, waitfor);
    583       1.26     pooka 
    584       1.18     pooka 	/* sync fs */
    585       1.63     pooka 	PUFFS_MSG_ALLOC(vfs, sync);
    586       1.63     pooka 	sync_msg->pvfsr_waitfor = waitfor;
    587       1.63     pooka 	puffs_credcvt(&sync_msg->pvfsr_cred, cred);
    588       1.69     pooka 	puffs_msg_setinfo(park_sync, PUFFSOP_VFS, PUFFS_VFS_SYNC, NULL);
    589        1.1     pooka 
    590       1.69     pooka 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_sync, rv);
    591       1.62     pooka 	rv = checkerr(pmp, rv, __func__);
    592       1.18     pooka 	if (rv)
    593       1.18     pooka 		error = rv;
    594        1.1     pooka 
    595       1.63     pooka 	PUFFS_MSG_RELEASE(sync);
    596        1.1     pooka 	return error;
    597        1.1     pooka }
    598        1.1     pooka 
    599        1.1     pooka int
    600       1.73     pooka puffs_vfsop_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    601        1.1     pooka {
    602       1.63     pooka 	PUFFS_MSG_VARS(vfs, fhtonode);
    603       1.33     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    604       1.33     pooka 	struct vnode *vp;
    605       1.54     pooka 	void *fhdata;
    606       1.54     pooka 	size_t argsize, fhlen;
    607       1.33     pooka 	int error;
    608       1.33     pooka 
    609       1.38     pooka 	if (pmp->pmp_args.pa_fhsize == 0)
    610       1.33     pooka 		return EOPNOTSUPP;
    611       1.33     pooka 
    612       1.54     pooka 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
    613       1.54     pooka 		fhlen = fhp->fid_len;
    614       1.54     pooka 		fhdata = fhp;
    615       1.39     pooka 	} else {
    616       1.54     pooka 		fhlen = PUFFS_FROMFHSIZE(fhp->fid_len);
    617       1.54     pooka 		fhdata = fhp->fid_data;
    618       1.54     pooka 
    619       1.54     pooka 		if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) {
    620       1.54     pooka 			if (pmp->pmp_args.pa_fhsize < fhlen)
    621       1.54     pooka 				return EINVAL;
    622       1.54     pooka 		} else {
    623       1.54     pooka 			if (pmp->pmp_args.pa_fhsize != fhlen)
    624       1.54     pooka 				return EINVAL;
    625       1.54     pooka 		}
    626       1.39     pooka 	}
    627       1.33     pooka 
    628       1.63     pooka 	argsize = sizeof(struct puffs_vfsmsg_fhtonode) + fhlen;
    629       1.75     pooka 	puffs_msgmem_alloc(argsize, &park_fhtonode, (void *)&fhtonode_msg, 1);
    630       1.63     pooka 	fhtonode_msg->pvfsr_dsize = fhlen;
    631       1.63     pooka 	memcpy(fhtonode_msg->pvfsr_data, fhdata, fhlen);
    632       1.69     pooka 	puffs_msg_setinfo(park_fhtonode, PUFFSOP_VFS, PUFFS_VFS_FHTOVP, NULL);
    633       1.33     pooka 
    634       1.69     pooka 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_fhtonode, error);
    635       1.60     pooka 	error = checkerr(pmp, error, __func__);
    636       1.33     pooka 	if (error)
    637       1.38     pooka 		goto out;
    638       1.33     pooka 
    639       1.63     pooka 	error = puffs_cookie2vnode(pmp, fhtonode_msg->pvfsr_fhcookie, 1,1,&vp);
    640       1.33     pooka 	DPRINTF(("puffs_fhtovp: got cookie %p, existing vnode %p\n",
    641       1.63     pooka 	    fhtonode_msg->pvfsr_fhcookie, vp));
    642       1.59     pooka 	if (error == PUFFS_NOSUCHCOOKIE) {
    643       1.63     pooka 		error = puffs_getvnode(mp, fhtonode_msg->pvfsr_fhcookie,
    644       1.63     pooka 		    fhtonode_msg->pvfsr_vtype, fhtonode_msg->pvfsr_size,
    645       1.63     pooka 		    fhtonode_msg->pvfsr_rdev, &vp);
    646       1.33     pooka 		if (error)
    647       1.38     pooka 			goto out;
    648       1.33     pooka 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    649       1.59     pooka 	} else if (error) {
    650       1.59     pooka 		goto out;
    651       1.33     pooka 	}
    652        1.1     pooka 
    653       1.33     pooka 	*vpp = vp;
    654       1.38     pooka  out:
    655       1.63     pooka 	puffs_msgmem_release(park_fhtonode);
    656       1.38     pooka 	return error;
    657        1.1     pooka }
    658        1.1     pooka 
    659        1.1     pooka int
    660       1.73     pooka puffs_vfsop_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    661        1.1     pooka {
    662       1.63     pooka 	PUFFS_MSG_VARS(vfs, nodetofh);
    663       1.33     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
    664       1.54     pooka 	size_t argsize, fhlen;
    665       1.33     pooka 	int error;
    666       1.33     pooka 
    667       1.38     pooka 	if (pmp->pmp_args.pa_fhsize == 0)
    668       1.33     pooka 		return EOPNOTSUPP;
    669       1.33     pooka 
    670       1.54     pooka 	/* if file handles are static len, we can test len immediately */
    671       1.38     pooka 	if (((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) == 0)
    672       1.54     pooka 	    && ((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) == 0)
    673       1.38     pooka 	    && (PUFFS_FROMFHSIZE(*fh_size) < pmp->pmp_args.pa_fhsize)) {
    674       1.38     pooka 		*fh_size = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
    675       1.33     pooka 		return E2BIG;
    676       1.33     pooka 	}
    677        1.1     pooka 
    678       1.54     pooka 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    679       1.54     pooka 		fhlen = *fh_size;
    680       1.54     pooka 	else
    681       1.54     pooka 		fhlen = PUFFS_FROMFHSIZE(*fh_size);
    682       1.54     pooka 
    683       1.63     pooka 	argsize = sizeof(struct puffs_vfsmsg_nodetofh) + fhlen;
    684       1.75     pooka 	puffs_msgmem_alloc(argsize, &park_nodetofh, (void *)&nodetofh_msg, 1);
    685       1.63     pooka 	nodetofh_msg->pvfsr_fhcookie = VPTOPNC(vp);
    686       1.63     pooka 	nodetofh_msg->pvfsr_dsize = fhlen;
    687       1.69     pooka 	puffs_msg_setinfo(park_nodetofh, PUFFSOP_VFS, PUFFS_VFS_VPTOFH, NULL);
    688       1.38     pooka 
    689       1.69     pooka 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_nodetofh, error);
    690       1.60     pooka 	error = checkerr(pmp, error, __func__);
    691       1.54     pooka 
    692       1.54     pooka 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    693       1.63     pooka 		fhlen = nodetofh_msg->pvfsr_dsize;
    694       1.54     pooka 	else if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC)
    695       1.63     pooka 		fhlen = PUFFS_TOFHSIZE(nodetofh_msg->pvfsr_dsize);
    696       1.54     pooka 	else
    697       1.54     pooka 		fhlen = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
    698       1.54     pooka 
    699       1.38     pooka 	if (error) {
    700       1.38     pooka 		if (error == E2BIG)
    701       1.54     pooka 			*fh_size = fhlen;
    702       1.38     pooka 		goto out;
    703       1.38     pooka 	}
    704       1.38     pooka 
    705       1.54     pooka 	if (fhlen > FHANDLE_SIZE_MAX) {
    706       1.69     pooka 		puffs_senderr(pmp, PUFFS_ERR_VPTOFH, E2BIG,
    707       1.60     pooka 		    "file handle too big", VPTOPNC(vp));
    708       1.58     pooka 		error = EPROTO;
    709       1.38     pooka 		goto out;
    710       1.38     pooka 	}
    711       1.33     pooka 
    712       1.54     pooka 	if (*fh_size < fhlen) {
    713       1.54     pooka 		*fh_size = fhlen;
    714       1.38     pooka 		error = E2BIG;
    715       1.38     pooka 		goto out;
    716       1.38     pooka 	}
    717       1.54     pooka 	*fh_size = fhlen;
    718        1.1     pooka 
    719       1.38     pooka 	if (fhp) {
    720       1.54     pooka 		if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
    721       1.63     pooka 			memcpy(fhp, nodetofh_msg->pvfsr_data, fhlen);
    722       1.54     pooka 		} else {
    723       1.54     pooka 			fhp->fid_len = *fh_size;
    724       1.63     pooka 			memcpy(fhp->fid_data, nodetofh_msg->pvfsr_data,
    725       1.63     pooka 			    nodetofh_msg->pvfsr_dsize);
    726       1.54     pooka 		}
    727       1.38     pooka 	}
    728        1.1     pooka 
    729       1.38     pooka  out:
    730       1.63     pooka 	puffs_msgmem_release(park_nodetofh);
    731       1.38     pooka 	return error;
    732        1.1     pooka }
    733        1.1     pooka 
    734        1.1     pooka void
    735  1.78.10.2      yamt puffs_vfsop_init(void)
    736        1.1     pooka {
    737        1.1     pooka 
    738       1.56     pooka 	/* some checks depend on this */
    739       1.56     pooka 	KASSERT(VNOVAL == VSIZENOTSET);
    740       1.56     pooka 
    741       1.31     pooka 	pool_init(&puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0,
    742       1.31     pooka 	    "puffpnpl", &pool_allocator_nointr, IPL_NONE);
    743       1.31     pooka 	puffs_msgif_init();
    744        1.1     pooka }
    745        1.1     pooka 
    746        1.1     pooka void
    747  1.78.10.2      yamt puffs_vfsop_done(void)
    748        1.1     pooka {
    749        1.1     pooka 
    750       1.31     pooka 	puffs_msgif_destroy();
    751       1.31     pooka 	pool_destroy(&puffs_pnpool);
    752        1.1     pooka }
    753        1.1     pooka 
    754        1.1     pooka int
    755       1.73     pooka puffs_vfsop_snapshot(struct mount *mp, struct vnode *vp, struct timespec *ts)
    756        1.1     pooka {
    757        1.1     pooka 
    758        1.1     pooka 	return EOPNOTSUPP;
    759        1.1     pooka }
    760        1.1     pooka 
    761        1.1     pooka const struct vnodeopv_desc * const puffs_vnodeopv_descs[] = {
    762        1.1     pooka 	&puffs_vnodeop_opv_desc,
    763        1.3     pooka 	&puffs_specop_opv_desc,
    764        1.4     pooka 	&puffs_fifoop_opv_desc,
    765       1.12     pooka 	&puffs_msgop_opv_desc,
    766        1.1     pooka 	NULL,
    767        1.1     pooka };
    768        1.1     pooka 
    769        1.1     pooka struct vfsops puffs_vfsops = {
    770        1.1     pooka 	MOUNT_PUFFS,
    771       1.48       dsl 	sizeof (struct puffs_kargs),
    772       1.73     pooka 	puffs_vfsop_mount,		/* mount	*/
    773       1.73     pooka 	puffs_vfsop_start,		/* start	*/
    774       1.73     pooka 	puffs_vfsop_unmount,		/* unmount	*/
    775       1.73     pooka 	puffs_vfsop_root,		/* root		*/
    776       1.73     pooka 	(void *)eopnotsupp,		/* quotactl	*/
    777       1.73     pooka 	puffs_vfsop_statvfs,		/* statvfs	*/
    778       1.73     pooka 	puffs_vfsop_sync,		/* sync		*/
    779       1.73     pooka 	(void *)eopnotsupp,		/* vget		*/
    780       1.73     pooka 	puffs_vfsop_fhtovp,		/* fhtovp	*/
    781       1.73     pooka 	puffs_vfsop_vptofh,		/* vptofh	*/
    782       1.73     pooka 	puffs_vfsop_init,		/* init		*/
    783       1.73     pooka 	NULL,				/* reinit	*/
    784       1.73     pooka 	puffs_vfsop_done,		/* done		*/
    785       1.73     pooka 	NULL,				/* mountroot	*/
    786       1.73     pooka 	puffs_vfsop_snapshot,		/* snapshot	*/
    787       1.73     pooka 	vfs_stdextattrctl,		/* extattrctl	*/
    788  1.78.10.3      yamt 	(void *)eopnotsupp,		/* suspendctl	*/
    789       1.78  dholland 	genfs_renamelock_enter,
    790       1.78  dholland 	genfs_renamelock_exit,
    791  1.78.10.1      yamt 	(void *)eopnotsupp,
    792       1.73     pooka 	puffs_vnodeopv_descs,		/* vnodeops	*/
    793       1.73     pooka 	0,				/* refcount	*/
    794        1.1     pooka 	{ NULL, NULL }
    795        1.1     pooka };
    796  1.78.10.1      yamt 
    797  1.78.10.1      yamt static int
    798  1.78.10.1      yamt puffs_modcmd(modcmd_t cmd, void *arg)
    799  1.78.10.1      yamt {
    800  1.78.10.1      yamt 
    801  1.78.10.1      yamt 	switch (cmd) {
    802  1.78.10.1      yamt 	case MODULE_CMD_INIT:
    803  1.78.10.1      yamt 		return vfs_attach(&puffs_vfsops);
    804  1.78.10.1      yamt 	case MODULE_CMD_FINI:
    805  1.78.10.1      yamt 		return vfs_detach(&puffs_vfsops);
    806  1.78.10.1      yamt 	default:
    807  1.78.10.1      yamt 		return ENOTTY;
    808  1.78.10.1      yamt 	}
    809  1.78.10.1      yamt }
    810