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