Home | History | Annotate | Line # | Download | only in puffs
puffs_vfsops.c revision 1.53.2.7
      1  1.53.2.7     joerg /*	$NetBSD: puffs_vfsops.c,v 1.53.2.7 2007/11/27 19:37:49 joerg 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.53.2.7     joerg __KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.53.2.7 2007/11/27 19:37:49 joerg 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.26     pooka #include <sys/fstrans.h>
     44      1.47        ad #include <sys/proc.h>
     45       1.1     pooka 
     46  1.53.2.5     joerg #include <dev/putter/putter_sys.h>
     47       1.1     pooka 
     48       1.1     pooka #include <fs/puffs/puffs_msgif.h>
     49       1.1     pooka #include <fs/puffs/puffs_sys.h>
     50       1.1     pooka 
     51  1.53.2.4     joerg #include <lib/libkern/libkern.h>
     52  1.53.2.4     joerg 
     53      1.38     pooka #include <nfs/nfsproto.h> /* for fh sizes */
     54      1.38     pooka 
     55       1.1     pooka VFS_PROTOS(puffs);
     56       1.1     pooka 
     57      1.22     pooka #ifndef PUFFS_PNODEBUCKETS
     58      1.22     pooka #define PUFFS_PNODEBUCKETS 256
     59      1.22     pooka #endif
     60      1.22     pooka #ifndef PUFFS_MAXPNODEBUCKETS
     61      1.35     pooka #define PUFFS_MAXPNODEBUCKETS 8192
     62      1.22     pooka #endif
     63      1.35     pooka int puffs_pnodebuckets_default = PUFFS_PNODEBUCKETS;
     64      1.35     pooka int puffs_maxpnodebuckets = PUFFS_MAXPNODEBUCKETS;
     65      1.22     pooka 
     66  1.53.2.6     joerg #define BUCKETALLOC(a) (sizeof(struct puffs_pnode_hashlist *) * (a))
     67  1.53.2.6     joerg 
     68  1.53.2.4     joerg static struct putter_ops puffs_putter = {
     69  1.53.2.4     joerg 	.pop_getout	= puffs_msgif_getout,
     70  1.53.2.4     joerg 	.pop_releaseout	= puffs_msgif_releaseout,
     71  1.53.2.4     joerg 	.pop_waitcount	= puffs_msgif_waitcount,
     72  1.53.2.4     joerg 	.pop_dispatch	= puffs_msgif_dispatch,
     73  1.53.2.4     joerg 	.pop_close	= puffs_msgif_close,
     74  1.53.2.4     joerg };
     75  1.53.2.4     joerg 
     76       1.1     pooka int
     77  1.53.2.7     joerg puffs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
     78       1.1     pooka {
     79      1.22     pooka 	struct puffs_mount *pmp = NULL;
     80      1.34     pooka 	struct puffs_kargs *args;
     81      1.51     pooka 	char fstype[_VFS_NAMELEN];
     82      1.51     pooka 	char *p;
     83      1.22     pooka 	int error = 0, i;
     84  1.53.2.7     joerg 	pid_t mntpid = curlwp->l_proc->p_pid;
     85       1.1     pooka 
     86      1.48       dsl 	if (*data_len < sizeof *args)
     87      1.48       dsl 		return EINVAL;
     88      1.48       dsl 
     89       1.1     pooka 	if (mp->mnt_flag & MNT_GETARGS) {
     90       1.1     pooka 		pmp = MPTOPUFFSMP(mp);
     91      1.48       dsl 		*(struct puffs_kargs *)data = pmp->pmp_args;
     92      1.48       dsl 		*data_len = sizeof *args;
     93      1.48       dsl 		return 0;
     94       1.1     pooka 	}
     95       1.1     pooka 
     96       1.1     pooka 	/* update is not supported currently */
     97       1.1     pooka 	if (mp->mnt_flag & MNT_UPDATE)
     98       1.1     pooka 		return EOPNOTSUPP;
     99       1.1     pooka 
    100       1.1     pooka 	/*
    101       1.1     pooka 	 * We need the file system name
    102       1.1     pooka 	 */
    103       1.1     pooka 	if (!data)
    104       1.1     pooka 		return EINVAL;
    105       1.1     pooka 
    106  1.53.2.6     joerg 	args = (struct puffs_kargs *)data;
    107      1.17     pooka 
    108      1.17     pooka 	/* devel phase */
    109      1.17     pooka 	if (args->pa_vers != (PUFFSVERSION | PUFFSDEVELVERS)) {
    110  1.53.2.3     joerg 		printf("puffs_mount: development version mismatch: "
    111  1.53.2.3     joerg 		    "kernel %d, lib %d\n",
    112  1.53.2.3     joerg 		    PUFFSVERSION, args->pa_vers & ~PUFFSDEVELVERS);
    113      1.17     pooka 		error = EINVAL;
    114      1.17     pooka 		goto out;
    115      1.17     pooka 	}
    116       1.1     pooka 
    117  1.53.2.1  jmcneill 	if ((args->pa_flags & ~PUFFS_KFLAG_MASK) != 0) {
    118  1.53.2.1  jmcneill 		printf("puffs_mount: invalid KFLAGs 0x%x\n", args->pa_flags);
    119  1.53.2.1  jmcneill 		error = EINVAL;
    120  1.53.2.1  jmcneill 		goto out;
    121  1.53.2.1  jmcneill 	}
    122  1.53.2.1  jmcneill 	if ((args->pa_fhflags & ~PUFFS_FHFLAG_MASK) != 0) {
    123  1.53.2.1  jmcneill 		printf("puffs_mount: invalid FHFLAGs 0x%x\n", args->pa_fhflags);
    124  1.53.2.1  jmcneill 		error = EINVAL;
    125  1.53.2.1  jmcneill 		goto out;
    126  1.53.2.1  jmcneill 	}
    127  1.53.2.1  jmcneill 
    128  1.53.2.1  jmcneill 	/* use dummy value for passthrough */
    129  1.53.2.1  jmcneill 	if (args->pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    130  1.53.2.1  jmcneill 		args->pa_fhsize = sizeof(struct fid);
    131       1.8     pooka 
    132      1.38     pooka 	/* sanitize file handle length */
    133      1.38     pooka 	if (PUFFS_TOFHSIZE(args->pa_fhsize) > FHANDLE_SIZE_MAX) {
    134      1.38     pooka 		printf("puffs_mount: handle size %zu too large\n",
    135      1.38     pooka 		    args->pa_fhsize);
    136      1.38     pooka 		error = EINVAL;
    137      1.38     pooka 		goto out;
    138      1.38     pooka 	}
    139      1.38     pooka 	/* sanity check file handle max sizes */
    140      1.38     pooka 	if (args->pa_fhsize && args->pa_fhflags & PUFFS_FHFLAG_PROTOMASK) {
    141      1.38     pooka 		size_t kfhsize = PUFFS_TOFHSIZE(args->pa_fhsize);
    142      1.38     pooka 
    143      1.38     pooka 		if (args->pa_fhflags & PUFFS_FHFLAG_NFSV2) {
    144      1.38     pooka 			if (NFSX_FHTOOBIG_P(kfhsize, 0)) {
    145      1.38     pooka 				printf("puffs_mount: fhsize larger than "
    146      1.38     pooka 				    "NFSv2 max %d\n",
    147      1.38     pooka 				    PUFFS_FROMFHSIZE(NFSX_V2FH));
    148      1.38     pooka 				error = EINVAL;
    149      1.38     pooka 				goto out;
    150      1.38     pooka 			}
    151      1.38     pooka 		}
    152      1.38     pooka 
    153      1.38     pooka 		if (args->pa_fhflags & PUFFS_FHFLAG_NFSV3) {
    154      1.38     pooka 			if (NFSX_FHTOOBIG_P(kfhsize, 1)) {
    155      1.38     pooka 				printf("puffs_mount: fhsize larger than "
    156      1.38     pooka 				    "NFSv3 max %d\n",
    157      1.38     pooka 				    PUFFS_FROMFHSIZE(NFSX_V3FHMAX));
    158      1.38     pooka 				error = EINVAL;
    159      1.38     pooka 				goto out;
    160      1.38     pooka 			}
    161      1.38     pooka 		}
    162      1.38     pooka 	}
    163      1.38     pooka 
    164      1.51     pooka 	/* don't allow non-printing characters (like my sweet umlauts.. snif) */
    165      1.51     pooka 	args->pa_typename[sizeof(args->pa_typename)-1] = '\0';
    166      1.51     pooka 	for (p = args->pa_typename; *p; p++)
    167      1.51     pooka 		if (*p < ' ' || *p > '~')
    168      1.51     pooka 			*p = '.';
    169      1.51     pooka 
    170      1.51     pooka 	args->pa_mntfromname[sizeof(args->pa_mntfromname)-1] = '\0';
    171      1.51     pooka 	for (p = args->pa_mntfromname; *p; p++)
    172      1.51     pooka 		if (*p < ' ' || *p > '~')
    173      1.51     pooka 			*p = '.';
    174      1.51     pooka 
    175       1.1     pooka 	/* build real name */
    176      1.51     pooka 	(void)strlcpy(fstype, PUFFS_TYPEPREFIX, sizeof(fstype));
    177      1.51     pooka 	(void)strlcat(fstype, args->pa_typename, sizeof(fstype));
    178       1.1     pooka 
    179       1.1     pooka 	/* inform user server if it got the max request size it wanted */
    180  1.53.2.3     joerg 	if (args->pa_maxmsglen == 0 || args->pa_maxmsglen > PUFFS_MSG_MAXSIZE)
    181  1.53.2.3     joerg 		args->pa_maxmsglen = PUFFS_MSG_MAXSIZE;
    182  1.53.2.3     joerg 	else if (args->pa_maxmsglen < 2*PUFFS_MSGSTRUCT_MAX)
    183  1.53.2.3     joerg 		args->pa_maxmsglen = 2*PUFFS_MSGSTRUCT_MAX;
    184  1.53.2.3     joerg 
    185      1.51     pooka 	(void)strlcpy(args->pa_typename, fstype, sizeof(args->pa_typename));
    186       1.1     pooka 
    187      1.40     pooka 	if (args->pa_nhashbuckets == 0)
    188      1.40     pooka 		args->pa_nhashbuckets = puffs_pnodebuckets_default;
    189      1.40     pooka 	if (args->pa_nhashbuckets < 1)
    190      1.40     pooka 		args->pa_nhashbuckets = 1;
    191      1.40     pooka 	if (args->pa_nhashbuckets > PUFFS_MAXPNODEBUCKETS) {
    192      1.40     pooka 		args->pa_nhashbuckets = puffs_maxpnodebuckets;
    193      1.40     pooka 		printf("puffs_mount: using %d hash buckets. "
    194      1.40     pooka 		    "adjust puffs_maxpnodebuckets for more\n",
    195      1.40     pooka 		    puffs_maxpnodebuckets);
    196      1.40     pooka 	}
    197      1.40     pooka 
    198      1.51     pooka 	error = set_statvfs_info(path, UIO_USERSPACE, args->pa_mntfromname,
    199  1.53.2.7     joerg 	    UIO_SYSSPACE, fstype, mp, curlwp);
    200       1.1     pooka 	if (error)
    201      1.17     pooka 		goto out;
    202      1.10     pooka 	mp->mnt_stat.f_iosize = DEV_BSIZE;
    203       1.1     pooka 
    204      1.42     pooka 	/*
    205      1.42     pooka 	 * We can't handle the VFS_STATVFS() mount_domount() does
    206      1.42     pooka 	 * after VFS_MOUNT() because we'd deadlock, so handle it
    207      1.42     pooka 	 * here already.
    208      1.42     pooka 	 */
    209      1.42     pooka 	copy_statvfs_info(&args->pa_svfsb, mp);
    210      1.42     pooka 	(void)memcpy(&mp->mnt_stat, &args->pa_svfsb, sizeof(mp->mnt_stat));
    211      1.42     pooka 
    212  1.53.2.6     joerg 	pmp = kmem_zalloc(sizeof(struct puffs_mount), KM_SLEEP);
    213       1.1     pooka 
    214       1.6     pooka 	mp->mnt_fs_bshift = DEV_BSHIFT;
    215       1.6     pooka 	mp->mnt_dev_bshift = DEV_BSHIFT;
    216       1.6     pooka 	mp->mnt_flag &= ~MNT_LOCAL; /* we don't really know, so ... */
    217       1.1     pooka 	mp->mnt_data = pmp;
    218      1.26     pooka 	mp->mnt_iflag |= IMNT_HAS_TRANS;
    219       1.6     pooka 
    220       1.1     pooka 	pmp->pmp_status = PUFFSTAT_MOUNTING;
    221       1.1     pooka 	pmp->pmp_mp = mp;
    222  1.53.2.3     joerg 	pmp->pmp_msg_maxsize = args->pa_maxmsglen;
    223      1.17     pooka 	pmp->pmp_args = *args;
    224       1.1     pooka 
    225      1.40     pooka 	pmp->pmp_npnodehash = args->pa_nhashbuckets;
    226  1.53.2.6     joerg 	pmp->pmp_pnodehash = kmem_alloc(BUCKETALLOC(pmp->pmp_npnodehash), KM_SLEEP);
    227      1.22     pooka 	for (i = 0; i < pmp->pmp_npnodehash; i++)
    228      1.22     pooka 		LIST_INIT(&pmp->pmp_pnodehash[i]);
    229  1.53.2.2     joerg 	LIST_INIT(&pmp->pmp_newcookie);
    230      1.22     pooka 
    231       1.1     pooka 	/*
    232       1.1     pooka 	 * Inform the fileops processing code that we have a mountpoint.
    233       1.1     pooka 	 * If it doesn't know about anyone with our pid/fd having the
    234       1.1     pooka 	 * device open, punt
    235       1.1     pooka 	 */
    236  1.53.2.4     joerg 	if ((pmp->pmp_pi
    237  1.53.2.4     joerg 	    = putter_attach(mntpid, args->pa_fd, pmp, &puffs_putter)) == NULL) {
    238      1.17     pooka 		error = ENOENT;
    239      1.17     pooka 		goto out;
    240       1.1     pooka 	}
    241       1.1     pooka 
    242      1.42     pooka 	/* XXX: check parameters */
    243      1.42     pooka 	pmp->pmp_root_cookie = args->pa_root_cookie;
    244      1.42     pooka 	pmp->pmp_root_vtype = args->pa_root_vtype;
    245      1.42     pooka 	pmp->pmp_root_vsize = args->pa_root_vsize;
    246      1.42     pooka 	pmp->pmp_root_rdev = args->pa_root_rdev;
    247      1.42     pooka 
    248      1.31     pooka 	mutex_init(&pmp->pmp_lock, MUTEX_DEFAULT, IPL_NONE);
    249  1.53.2.3     joerg 	cv_init(&pmp->pmp_msg_waiter_cv, "puffsget");
    250      1.41     pooka 	cv_init(&pmp->pmp_refcount_cv, "puffsref");
    251      1.31     pooka 	cv_init(&pmp->pmp_unmounting_cv, "puffsum");
    252  1.53.2.3     joerg 	TAILQ_INIT(&pmp->pmp_msg_touser);
    253  1.53.2.3     joerg 	TAILQ_INIT(&pmp->pmp_msg_replywait);
    254       1.1     pooka 
    255       1.1     pooka 	DPRINTF(("puffs_mount: mount point at %p, puffs specific at %p\n",
    256       1.1     pooka 	    mp, MPTOPUFFSMP(mp)));
    257       1.1     pooka 
    258       1.1     pooka 	vfs_getnewfsid(mp);
    259       1.1     pooka 
    260      1.17     pooka  out:
    261      1.22     pooka 	if (error && pmp && pmp->pmp_pnodehash)
    262  1.53.2.6     joerg 		kmem_free(pmp->pmp_pnodehash, BUCKETALLOC(pmp->pmp_npnodehash));
    263      1.22     pooka 	if (error && pmp)
    264  1.53.2.6     joerg 		kmem_free(pmp, sizeof(struct puffs_mount));
    265      1.17     pooka 	return error;
    266       1.1     pooka }
    267       1.1     pooka 
    268       1.1     pooka int
    269  1.53.2.7     joerg puffs_start(struct mount *mp, int flags)
    270       1.1     pooka {
    271      1.42     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    272       1.1     pooka 
    273      1.42     pooka 	KASSERT(pmp->pmp_status == PUFFSTAT_MOUNTING);
    274       1.1     pooka 	pmp->pmp_status = PUFFSTAT_RUNNING;
    275       1.1     pooka 
    276       1.1     pooka 	return 0;
    277       1.1     pooka }
    278       1.1     pooka 
    279       1.1     pooka int
    280  1.53.2.7     joerg puffs_unmount(struct mount *mp, int mntflags)
    281       1.1     pooka {
    282  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, unmount);
    283       1.1     pooka 	struct puffs_mount *pmp;
    284       1.1     pooka 	int error, force;
    285       1.1     pooka 
    286       1.1     pooka 	error = 0;
    287       1.1     pooka 	force = mntflags & MNT_FORCE;
    288       1.1     pooka 	pmp = MPTOPUFFSMP(mp);
    289       1.1     pooka 
    290       1.1     pooka 	DPRINTF(("puffs_unmount: detach filesystem from vfs, current "
    291       1.1     pooka 	    "status 0x%x\n", pmp->pmp_status));
    292       1.1     pooka 
    293       1.1     pooka 	/*
    294       1.1     pooka 	 * flush all the vnodes.  VOP_RECLAIM() takes care that the
    295       1.1     pooka 	 * root vnode does not get flushed until unmount.  The
    296       1.1     pooka 	 * userspace root node cookie is stored in the mount
    297       1.1     pooka 	 * structure, so we can always re-instantiate a root vnode,
    298       1.1     pooka 	 * should userspace unmount decide it doesn't want to
    299       1.1     pooka 	 * cooperate.
    300       1.1     pooka 	 */
    301       1.1     pooka 	error = vflush(mp, NULLVP, force ? FORCECLOSE : 0);
    302       1.1     pooka 	if (error)
    303       1.1     pooka 		goto out;
    304       1.1     pooka 
    305       1.1     pooka 	/*
    306       1.1     pooka 	 * If we are not DYING, we should ask userspace's opinion
    307       1.1     pooka 	 * about the situation
    308       1.1     pooka 	 */
    309      1.31     pooka 	mutex_enter(&pmp->pmp_lock);
    310       1.1     pooka 	if (pmp->pmp_status != PUFFSTAT_DYING) {
    311      1.16     pooka 		pmp->pmp_unmounting = 1;
    312      1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    313      1.16     pooka 
    314  1.53.2.3     joerg 		PUFFS_MSG_ALLOC(vfs, unmount);
    315  1.53.2.6     joerg 		puffs_msg_setinfo(park_unmount,
    316  1.53.2.6     joerg 		    PUFFSOP_VFS, PUFFS_VFS_UNMOUNT, NULL);
    317  1.53.2.3     joerg 		unmount_msg->pvfsr_flags = mntflags;
    318  1.53.2.3     joerg 
    319  1.53.2.6     joerg 		PUFFS_MSG_ENQUEUEWAIT(pmp, park_unmount, error);
    320  1.53.2.3     joerg 		PUFFS_MSG_RELEASE(unmount);
    321      1.16     pooka 
    322  1.53.2.2     joerg 		error = checkerr(pmp, error, __func__);
    323      1.16     pooka 		DPRINTF(("puffs_unmount: error %d force %d\n", error, force));
    324      1.16     pooka 
    325      1.31     pooka 		mutex_enter(&pmp->pmp_lock);
    326      1.16     pooka 		pmp->pmp_unmounting = 0;
    327      1.31     pooka 		cv_broadcast(&pmp->pmp_unmounting_cv);
    328       1.1     pooka 	}
    329       1.1     pooka 
    330       1.1     pooka 	/*
    331       1.1     pooka 	 * if userspace cooperated or we really need to die,
    332       1.1     pooka 	 * screw what userland thinks and just die.
    333       1.1     pooka 	 */
    334       1.1     pooka 	if (error == 0 || force) {
    335      1.26     pooka 		/* tell waiters & other resources to go unwait themselves */
    336      1.26     pooka 		puffs_userdead(pmp);
    337  1.53.2.4     joerg 		putter_detach(pmp->pmp_pi);
    338      1.26     pooka 
    339      1.26     pooka 		/*
    340      1.41     pooka 		 * Wait until there are no more users for the mount resource.
    341      1.41     pooka 		 * Notice that this is hooked against transport_close
    342      1.41     pooka 		 * and return from touser.  In an ideal world, it would
    343      1.41     pooka 		 * be hooked against final return from all operations.
    344      1.41     pooka 		 * But currently it works well enough, since nobody
    345      1.41     pooka 		 * does weird blocking voodoo after return from touser().
    346      1.26     pooka 		 */
    347      1.41     pooka 		while (pmp->pmp_refcount != 0)
    348      1.41     pooka 			cv_wait(&pmp->pmp_refcount_cv, &pmp->pmp_lock);
    349      1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    350      1.26     pooka 
    351      1.26     pooka 		/* free resources now that we hopefully have no waiters left */
    352      1.41     pooka 		cv_destroy(&pmp->pmp_unmounting_cv);
    353      1.41     pooka 		cv_destroy(&pmp->pmp_refcount_cv);
    354  1.53.2.3     joerg 		cv_destroy(&pmp->pmp_msg_waiter_cv);
    355      1.31     pooka 		mutex_destroy(&pmp->pmp_lock);
    356      1.31     pooka 
    357  1.53.2.6     joerg 		kmem_free(pmp->pmp_pnodehash, BUCKETALLOC(pmp->pmp_npnodehash));
    358  1.53.2.6     joerg 		kmem_free(pmp, sizeof(struct puffs_mount));
    359       1.1     pooka 		error = 0;
    360      1.16     pooka 	} else {
    361      1.31     pooka 		mutex_exit(&pmp->pmp_lock);
    362       1.1     pooka 	}
    363       1.1     pooka 
    364       1.1     pooka  out:
    365       1.2     pooka 	DPRINTF(("puffs_unmount: return %d\n", error));
    366       1.1     pooka 	return error;
    367       1.1     pooka }
    368       1.1     pooka 
    369       1.1     pooka /*
    370       1.1     pooka  * This doesn't need to travel to userspace
    371       1.1     pooka  */
    372       1.1     pooka int
    373       1.1     pooka puffs_root(struct mount *mp, struct vnode **vpp)
    374       1.1     pooka {
    375      1.45     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    376  1.53.2.2     joerg 	int rv;
    377       1.1     pooka 
    378  1.53.2.2     joerg 	rv = puffs_cookie2vnode(pmp, pmp->pmp_root_cookie, 1, 1, vpp);
    379  1.53.2.2     joerg 	KASSERT(rv != PUFFS_NOSUCHCOOKIE);
    380  1.53.2.2     joerg 	return rv;
    381       1.1     pooka }
    382       1.1     pooka 
    383       1.1     pooka int
    384  1.53.2.7     joerg puffs_statvfs(struct mount *mp, struct statvfs *sbp)
    385       1.1     pooka {
    386  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, statvfs);
    387       1.1     pooka 	struct puffs_mount *pmp;
    388       1.1     pooka 	int error = 0;
    389       1.1     pooka 
    390       1.1     pooka 	pmp = MPTOPUFFSMP(mp);
    391       1.1     pooka 
    392       1.1     pooka 	/*
    393       1.1     pooka 	 * If we are mounting, it means that the userspace counterpart
    394       1.1     pooka 	 * is calling mount(2), but mount(2) also calls statvfs.  So
    395       1.1     pooka 	 * requesting statvfs from userspace would mean a deadlock.
    396       1.1     pooka 	 * Compensate.
    397       1.1     pooka 	 */
    398       1.1     pooka 	if (pmp->pmp_status == PUFFSTAT_MOUNTING)
    399       1.1     pooka 		return EINPROGRESS;
    400       1.1     pooka 
    401  1.53.2.3     joerg 	PUFFS_MSG_ALLOC(vfs, statvfs);
    402  1.53.2.6     joerg 	puffs_msg_setinfo(park_statvfs, PUFFSOP_VFS, PUFFS_VFS_STATVFS, NULL);
    403       1.1     pooka 
    404  1.53.2.6     joerg 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_statvfs, error);
    405  1.53.2.2     joerg 	error = checkerr(pmp, error, __func__);
    406  1.53.2.3     joerg 	statvfs_msg->pvfsr_sb.f_iosize = DEV_BSIZE;
    407      1.10     pooka 
    408       1.1     pooka 	/*
    409       1.1     pooka 	 * Try to produce a sensible result even in the event
    410       1.1     pooka 	 * of userspace error.
    411       1.1     pooka 	 *
    412       1.1     pooka 	 * XXX: cache the copy in non-error case
    413       1.1     pooka 	 */
    414       1.1     pooka 	if (!error) {
    415  1.53.2.3     joerg 		copy_statvfs_info(&statvfs_msg->pvfsr_sb, mp);
    416  1.53.2.3     joerg 		(void)memcpy(sbp, &statvfs_msg->pvfsr_sb,
    417       1.1     pooka 		    sizeof(struct statvfs));
    418       1.1     pooka 	} else {
    419       1.1     pooka 		copy_statvfs_info(sbp, mp);
    420       1.1     pooka 	}
    421       1.1     pooka 
    422  1.53.2.3     joerg 	PUFFS_MSG_RELEASE(statvfs);
    423      1.14     pooka 	return error;
    424       1.1     pooka }
    425       1.1     pooka 
    426      1.26     pooka static int
    427  1.53.2.7     joerg pageflush(struct mount *mp, kauth_cred_t cred, int waitfor, int suspending)
    428       1.1     pooka {
    429      1.26     pooka 	struct puffs_node *pn;
    430      1.18     pooka 	struct vnode *vp, *nvp;
    431      1.30     pooka 	int error, rv;
    432       1.1     pooka 
    433      1.26     pooka 	KASSERT(((waitfor == MNT_WAIT) && suspending) == 0);
    434      1.26     pooka 	KASSERT((suspending == 0)
    435      1.26     pooka 	    || (fstrans_is_owner(mp)
    436      1.27   hannken 	      && fstrans_getstate(mp) == FSTRANS_SUSPENDING));
    437       1.1     pooka 
    438      1.18     pooka 	error = 0;
    439      1.18     pooka 
    440      1.18     pooka 	/*
    441      1.24     pooka 	 * Sync all cached data from regular vnodes (which are not
    442      1.24     pooka 	 * currently locked, see below).  After this we call VFS_SYNC
    443      1.24     pooka 	 * for the fs server, which should handle data and metadata for
    444      1.24     pooka 	 * all the nodes it knows to exist.
    445      1.18     pooka 	 */
    446      1.18     pooka 	simple_lock(&mntvnode_slock);
    447      1.18     pooka  loop:
    448      1.18     pooka 	for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
    449      1.18     pooka 		/* check if we're on the right list */
    450      1.18     pooka 		if (vp->v_mount != mp)
    451      1.18     pooka 			goto loop;
    452      1.18     pooka 
    453      1.18     pooka 		simple_lock(&vp->v_interlock);
    454      1.26     pooka 		pn = VPTOPP(vp);
    455      1.18     pooka 		nvp = TAILQ_NEXT(vp, v_mntvnodes);
    456      1.18     pooka 
    457      1.19     pooka 		if (vp->v_type != VREG || UVM_OBJ_IS_CLEAN(&vp->v_uobj)) {
    458      1.18     pooka 			simple_unlock(&vp->v_interlock);
    459      1.18     pooka 			continue;
    460      1.18     pooka 		}
    461      1.18     pooka 
    462      1.18     pooka 		simple_unlock(&mntvnode_slock);
    463      1.21     pooka 
    464      1.21     pooka 		/*
    465      1.21     pooka 		 * Here we try to get a reference to the vnode and to
    466      1.21     pooka 		 * lock it.  This is mostly cargo-culted, but I will
    467      1.21     pooka 		 * offer an explanation to why I believe this might
    468      1.21     pooka 		 * actually do the right thing.
    469      1.21     pooka 		 *
    470      1.21     pooka 		 * If the vnode is a goner, we quite obviously don't need
    471      1.21     pooka 		 * to sync it.
    472      1.21     pooka 		 *
    473      1.21     pooka 		 * If the vnode was busy, we don't need to sync it because
    474      1.21     pooka 		 * this is never called with MNT_WAIT except from
    475      1.21     pooka 		 * dounmount(), when we are wait-flushing all the dirty
    476      1.21     pooka 		 * vnodes through other routes in any case.  So there,
    477      1.21     pooka 		 * sync() doesn't actually sync.  Happy now?
    478      1.26     pooka 		 *
    479      1.26     pooka 		 * NOTE: if we're suspending, vget() does NOT lock.
    480      1.26     pooka 		 * See puffs_lock() for details.
    481      1.21     pooka 		 */
    482      1.18     pooka 		rv = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
    483      1.18     pooka 		if (rv) {
    484      1.18     pooka 			simple_lock(&mntvnode_slock);
    485      1.18     pooka 			if (rv == ENOENT)
    486      1.18     pooka 				goto loop;
    487      1.18     pooka 			continue;
    488      1.18     pooka 		}
    489      1.18     pooka 
    490      1.26     pooka 		/*
    491      1.26     pooka 		 * Thread information to puffs_strategy() through the
    492      1.26     pooka 		 * pnode flags: we want to issue the putpages operations
    493      1.26     pooka 		 * as FAF if we're suspending, since it's very probable
    494      1.26     pooka 		 * that our execution context is that of the userspace
    495      1.26     pooka 		 * daemon.  We can do this because:
    496      1.26     pooka 		 *   + we send the "going to suspend" prior to this part
    497      1.26     pooka 		 *   + if any of the writes fails in userspace, it's the
    498      1.26     pooka 		 *     file system server's problem to decide if this was a
    499      1.26     pooka 		 *     failed snapshot when it gets the "snapshot complete"
    500      1.26     pooka 		 *     notification.
    501      1.26     pooka 		 *   + if any of the writes fail in the kernel already, we
    502      1.26     pooka 		 *     immediately fail *and* notify the user server of
    503      1.26     pooka 		 *     failure.
    504      1.26     pooka 		 *
    505      1.26     pooka 		 * We also do FAFs if we're called from the syncer.  This
    506      1.26     pooka 		 * is just general optimization for trickle sync: no need
    507      1.26     pooka 		 * to really guarantee that the stuff ended on backing
    508      1.26     pooka 		 * storage.
    509      1.26     pooka 		 * TODO: Maybe also hint the user server of this twist?
    510      1.26     pooka 		 */
    511      1.30     pooka 		if (suspending || waitfor == MNT_LAZY) {
    512      1.30     pooka 			simple_lock(&vp->v_interlock);
    513      1.26     pooka 			pn->pn_stat |= PNODE_SUSPEND;
    514      1.30     pooka 			simple_unlock(&vp->v_interlock);
    515      1.30     pooka 		}
    516  1.53.2.7     joerg 		rv = VOP_FSYNC(vp, cred, waitfor, 0, 0);
    517      1.26     pooka 		if (suspending || waitfor == MNT_LAZY) {
    518      1.26     pooka 			simple_lock(&vp->v_interlock);
    519      1.26     pooka 			pn->pn_stat &= ~PNODE_SUSPEND;
    520      1.26     pooka 			simple_unlock(&vp->v_interlock);
    521      1.26     pooka 		}
    522      1.21     pooka 		if (rv)
    523      1.18     pooka 			error = rv;
    524      1.18     pooka 		vput(vp);
    525      1.18     pooka 		simple_lock(&mntvnode_slock);
    526      1.18     pooka 	}
    527      1.18     pooka 	simple_unlock(&mntvnode_slock);
    528      1.18     pooka 
    529      1.26     pooka 	return error;
    530      1.26     pooka }
    531      1.26     pooka 
    532      1.26     pooka int
    533  1.53.2.7     joerg puffs_sync(struct mount *mp, int waitfor, struct kauth_cred *cred)
    534      1.26     pooka {
    535  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, sync);
    536  1.53.2.3     joerg 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    537      1.26     pooka 	int error, rv;
    538      1.26     pooka 
    539  1.53.2.7     joerg 	error = pageflush(mp, cred, waitfor, 0);
    540      1.26     pooka 
    541      1.18     pooka 	/* sync fs */
    542  1.53.2.3     joerg 	PUFFS_MSG_ALLOC(vfs, sync);
    543  1.53.2.3     joerg 	sync_msg->pvfsr_waitfor = waitfor;
    544  1.53.2.3     joerg 	puffs_credcvt(&sync_msg->pvfsr_cred, cred);
    545  1.53.2.6     joerg 	puffs_msg_setinfo(park_sync, PUFFSOP_VFS, PUFFS_VFS_SYNC, NULL);
    546  1.53.2.3     joerg 
    547  1.53.2.6     joerg 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_sync, rv);
    548  1.53.2.3     joerg 	rv = checkerr(pmp, rv, __func__);
    549      1.18     pooka 	if (rv)
    550      1.18     pooka 		error = rv;
    551       1.1     pooka 
    552  1.53.2.3     joerg 	PUFFS_MSG_RELEASE(sync);
    553       1.1     pooka 	return error;
    554       1.1     pooka }
    555       1.1     pooka 
    556       1.1     pooka int
    557      1.33     pooka puffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    558       1.1     pooka {
    559  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, fhtonode);
    560      1.33     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
    561      1.33     pooka 	struct vnode *vp;
    562  1.53.2.1  jmcneill 	void *fhdata;
    563  1.53.2.1  jmcneill 	size_t argsize, fhlen;
    564      1.33     pooka 	int error;
    565      1.33     pooka 
    566      1.38     pooka 	if (pmp->pmp_args.pa_fhsize == 0)
    567      1.33     pooka 		return EOPNOTSUPP;
    568      1.33     pooka 
    569  1.53.2.1  jmcneill 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
    570  1.53.2.1  jmcneill 		fhlen = fhp->fid_len;
    571  1.53.2.1  jmcneill 		fhdata = fhp;
    572      1.39     pooka 	} else {
    573  1.53.2.1  jmcneill 		fhlen = PUFFS_FROMFHSIZE(fhp->fid_len);
    574  1.53.2.1  jmcneill 		fhdata = fhp->fid_data;
    575  1.53.2.1  jmcneill 
    576  1.53.2.1  jmcneill 		if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) {
    577  1.53.2.1  jmcneill 			if (pmp->pmp_args.pa_fhsize < fhlen)
    578  1.53.2.1  jmcneill 				return EINVAL;
    579  1.53.2.1  jmcneill 		} else {
    580  1.53.2.1  jmcneill 			if (pmp->pmp_args.pa_fhsize != fhlen)
    581  1.53.2.1  jmcneill 				return EINVAL;
    582  1.53.2.1  jmcneill 		}
    583      1.39     pooka 	}
    584      1.33     pooka 
    585  1.53.2.3     joerg 	argsize = sizeof(struct puffs_vfsmsg_fhtonode) + fhlen;
    586  1.53.2.3     joerg 	puffs_msgmem_alloc(argsize, &park_fhtonode, (void **)&fhtonode_msg, 1);
    587  1.53.2.3     joerg 	fhtonode_msg->pvfsr_dsize = fhlen;
    588  1.53.2.3     joerg 	memcpy(fhtonode_msg->pvfsr_data, fhdata, fhlen);
    589  1.53.2.6     joerg 	puffs_msg_setinfo(park_fhtonode, PUFFSOP_VFS, PUFFS_VFS_FHTOVP, NULL);
    590      1.33     pooka 
    591  1.53.2.6     joerg 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_fhtonode, error);
    592  1.53.2.2     joerg 	error = checkerr(pmp, error, __func__);
    593      1.33     pooka 	if (error)
    594      1.38     pooka 		goto out;
    595      1.33     pooka 
    596  1.53.2.3     joerg 	error = puffs_cookie2vnode(pmp, fhtonode_msg->pvfsr_fhcookie, 1,1,&vp);
    597      1.33     pooka 	DPRINTF(("puffs_fhtovp: got cookie %p, existing vnode %p\n",
    598  1.53.2.3     joerg 	    fhtonode_msg->pvfsr_fhcookie, vp));
    599  1.53.2.2     joerg 	if (error == PUFFS_NOSUCHCOOKIE) {
    600  1.53.2.3     joerg 		error = puffs_getvnode(mp, fhtonode_msg->pvfsr_fhcookie,
    601  1.53.2.3     joerg 		    fhtonode_msg->pvfsr_vtype, fhtonode_msg->pvfsr_size,
    602  1.53.2.3     joerg 		    fhtonode_msg->pvfsr_rdev, &vp);
    603      1.33     pooka 		if (error)
    604      1.38     pooka 			goto out;
    605      1.33     pooka 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    606  1.53.2.2     joerg 	} else if (error) {
    607  1.53.2.2     joerg 		goto out;
    608      1.33     pooka 	}
    609       1.1     pooka 
    610      1.33     pooka 	*vpp = vp;
    611      1.38     pooka  out:
    612  1.53.2.3     joerg 	puffs_msgmem_release(park_fhtonode);
    613      1.38     pooka 	return error;
    614       1.1     pooka }
    615       1.1     pooka 
    616       1.1     pooka int
    617      1.33     pooka puffs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
    618       1.1     pooka {
    619  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, nodetofh);
    620      1.33     pooka 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
    621  1.53.2.1  jmcneill 	size_t argsize, fhlen;
    622      1.33     pooka 	int error;
    623      1.33     pooka 
    624      1.38     pooka 	if (pmp->pmp_args.pa_fhsize == 0)
    625      1.33     pooka 		return EOPNOTSUPP;
    626      1.33     pooka 
    627  1.53.2.1  jmcneill 	/* if file handles are static len, we can test len immediately */
    628      1.38     pooka 	if (((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC) == 0)
    629  1.53.2.1  jmcneill 	    && ((pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) == 0)
    630      1.38     pooka 	    && (PUFFS_FROMFHSIZE(*fh_size) < pmp->pmp_args.pa_fhsize)) {
    631      1.38     pooka 		*fh_size = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
    632      1.33     pooka 		return E2BIG;
    633      1.33     pooka 	}
    634       1.1     pooka 
    635  1.53.2.1  jmcneill 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    636  1.53.2.1  jmcneill 		fhlen = *fh_size;
    637  1.53.2.1  jmcneill 	else
    638  1.53.2.1  jmcneill 		fhlen = PUFFS_FROMFHSIZE(*fh_size);
    639  1.53.2.1  jmcneill 
    640  1.53.2.3     joerg 	argsize = sizeof(struct puffs_vfsmsg_nodetofh) + fhlen;
    641  1.53.2.3     joerg 	puffs_msgmem_alloc(argsize, &park_nodetofh, (void **)&nodetofh_msg, 1);
    642  1.53.2.3     joerg 	nodetofh_msg->pvfsr_fhcookie = VPTOPNC(vp);
    643  1.53.2.3     joerg 	nodetofh_msg->pvfsr_dsize = fhlen;
    644  1.53.2.6     joerg 	puffs_msg_setinfo(park_nodetofh, PUFFSOP_VFS, PUFFS_VFS_VPTOFH, NULL);
    645      1.38     pooka 
    646  1.53.2.6     joerg 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_nodetofh, error);
    647  1.53.2.2     joerg 	error = checkerr(pmp, error, __func__);
    648  1.53.2.1  jmcneill 
    649  1.53.2.1  jmcneill 	if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH)
    650  1.53.2.3     joerg 		fhlen = nodetofh_msg->pvfsr_dsize;
    651  1.53.2.1  jmcneill 	else if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_DYNAMIC)
    652  1.53.2.3     joerg 		fhlen = PUFFS_TOFHSIZE(nodetofh_msg->pvfsr_dsize);
    653  1.53.2.1  jmcneill 	else
    654  1.53.2.1  jmcneill 		fhlen = PUFFS_TOFHSIZE(pmp->pmp_args.pa_fhsize);
    655  1.53.2.1  jmcneill 
    656      1.38     pooka 	if (error) {
    657      1.38     pooka 		if (error == E2BIG)
    658  1.53.2.1  jmcneill 			*fh_size = fhlen;
    659      1.38     pooka 		goto out;
    660      1.38     pooka 	}
    661      1.38     pooka 
    662  1.53.2.1  jmcneill 	if (fhlen > FHANDLE_SIZE_MAX) {
    663  1.53.2.6     joerg 		puffs_senderr(pmp, PUFFS_ERR_VPTOFH, E2BIG,
    664  1.53.2.2     joerg 		    "file handle too big", VPTOPNC(vp));
    665  1.53.2.2     joerg 		error = EPROTO;
    666      1.38     pooka 		goto out;
    667      1.38     pooka 	}
    668      1.33     pooka 
    669  1.53.2.1  jmcneill 	if (*fh_size < fhlen) {
    670  1.53.2.1  jmcneill 		*fh_size = fhlen;
    671      1.38     pooka 		error = E2BIG;
    672      1.38     pooka 		goto out;
    673      1.38     pooka 	}
    674  1.53.2.1  jmcneill 	*fh_size = fhlen;
    675       1.1     pooka 
    676      1.38     pooka 	if (fhp) {
    677  1.53.2.1  jmcneill 		if (pmp->pmp_args.pa_fhflags & PUFFS_FHFLAG_PASSTHROUGH) {
    678  1.53.2.3     joerg 			memcpy(fhp, nodetofh_msg->pvfsr_data, fhlen);
    679  1.53.2.1  jmcneill 		} else {
    680  1.53.2.1  jmcneill 			fhp->fid_len = *fh_size;
    681  1.53.2.3     joerg 			memcpy(fhp->fid_data, nodetofh_msg->pvfsr_data,
    682  1.53.2.3     joerg 			    nodetofh_msg->pvfsr_dsize);
    683  1.53.2.1  jmcneill 		}
    684      1.38     pooka 	}
    685       1.1     pooka 
    686      1.38     pooka  out:
    687  1.53.2.3     joerg 	puffs_msgmem_release(park_nodetofh);
    688      1.38     pooka 	return error;
    689       1.1     pooka }
    690       1.1     pooka 
    691       1.1     pooka void
    692       1.1     pooka puffs_init()
    693       1.1     pooka {
    694       1.1     pooka 
    695  1.53.2.2     joerg 	/* some checks depend on this */
    696  1.53.2.2     joerg 	KASSERT(VNOVAL == VSIZENOTSET);
    697  1.53.2.2     joerg 
    698      1.31     pooka 	pool_init(&puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0,
    699      1.31     pooka 	    "puffpnpl", &pool_allocator_nointr, IPL_NONE);
    700      1.31     pooka 	puffs_msgif_init();
    701       1.1     pooka }
    702       1.1     pooka 
    703       1.1     pooka void
    704       1.1     pooka puffs_done()
    705       1.1     pooka {
    706       1.1     pooka 
    707      1.31     pooka 	puffs_msgif_destroy();
    708      1.31     pooka 	pool_destroy(&puffs_pnpool);
    709       1.1     pooka }
    710       1.1     pooka 
    711       1.1     pooka int
    712       1.1     pooka puffs_snapshot(struct mount *mp, struct vnode *vp, struct timespec *ts)
    713       1.1     pooka {
    714       1.1     pooka 
    715       1.1     pooka 	return EOPNOTSUPP;
    716       1.1     pooka }
    717       1.1     pooka 
    718      1.26     pooka int
    719      1.26     pooka puffs_suspendctl(struct mount *mp, int cmd)
    720      1.26     pooka {
    721  1.53.2.3     joerg 	PUFFS_MSG_VARS(vfs, suspend);
    722      1.26     pooka 	struct puffs_mount *pmp;
    723      1.26     pooka 	int error;
    724      1.26     pooka 
    725      1.26     pooka 	pmp = MPTOPUFFSMP(mp);
    726      1.26     pooka 	switch (cmd) {
    727      1.26     pooka 	case SUSPEND_SUSPEND:
    728      1.26     pooka 		DPRINTF(("puffs_suspendctl: suspending\n"));
    729      1.27   hannken 		if ((error = fstrans_setstate(mp, FSTRANS_SUSPENDING)) != 0)
    730      1.26     pooka 			break;
    731  1.53.2.3     joerg 		PUFFS_MSG_ALLOC(vfs, suspend);
    732  1.53.2.3     joerg 		puffs_msg_setfaf(park_suspend);
    733  1.53.2.3     joerg 		suspend_msg->pvfsr_status = PUFFS_SUSPEND_START;
    734  1.53.2.6     joerg 		puffs_msg_setinfo(park_suspend, PUFFSOP_VFS,
    735  1.53.2.6     joerg 		    PUFFS_VFS_SUSPEND, NULL);
    736  1.53.2.6     joerg 
    737  1.53.2.6     joerg 		puffs_msg_enqueue(pmp, park_suspend);
    738  1.53.2.3     joerg 		PUFFS_MSG_RELEASE(suspend);
    739      1.26     pooka 
    740  1.53.2.7     joerg 		error = pageflush(mp, FSCRED, 0, 1);
    741      1.26     pooka 		if (error == 0)
    742      1.27   hannken 			error = fstrans_setstate(mp, FSTRANS_SUSPENDED);
    743      1.26     pooka 
    744      1.26     pooka 		if (error != 0) {
    745  1.53.2.3     joerg 			PUFFS_MSG_ALLOC(vfs, suspend);
    746  1.53.2.3     joerg 			puffs_msg_setfaf(park_suspend);
    747  1.53.2.3     joerg 			suspend_msg->pvfsr_status = PUFFS_SUSPEND_ERROR;
    748  1.53.2.6     joerg 			puffs_msg_setinfo(park_suspend, PUFFSOP_VFS,
    749  1.53.2.6     joerg 			    PUFFS_VFS_SUSPEND, NULL);
    750  1.53.2.6     joerg 
    751  1.53.2.6     joerg 			puffs_msg_enqueue(pmp, park_suspend);
    752  1.53.2.3     joerg 			PUFFS_MSG_RELEASE(suspend);
    753      1.27   hannken 			(void) fstrans_setstate(mp, FSTRANS_NORMAL);
    754      1.26     pooka 			break;
    755      1.26     pooka 		}
    756      1.26     pooka 
    757  1.53.2.3     joerg 		PUFFS_MSG_ALLOC(vfs, suspend);
    758  1.53.2.3     joerg 		puffs_msg_setfaf(park_suspend);
    759  1.53.2.3     joerg 		suspend_msg->pvfsr_status = PUFFS_SUSPEND_SUSPENDED;
    760  1.53.2.6     joerg 		puffs_msg_setinfo(park_suspend, PUFFSOP_VFS,
    761  1.53.2.6     joerg 		    PUFFS_VFS_SUSPEND, NULL);
    762  1.53.2.6     joerg 
    763  1.53.2.6     joerg 		puffs_msg_enqueue(pmp, park_suspend);
    764  1.53.2.3     joerg 		PUFFS_MSG_RELEASE(suspend);
    765      1.26     pooka 
    766      1.26     pooka 		break;
    767      1.26     pooka 
    768      1.26     pooka 	case SUSPEND_RESUME:
    769      1.26     pooka 		DPRINTF(("puffs_suspendctl: resume\n"));
    770      1.26     pooka 		error = 0;
    771      1.27   hannken 		(void) fstrans_setstate(mp, FSTRANS_NORMAL);
    772  1.53.2.3     joerg 		PUFFS_MSG_ALLOC(vfs, suspend);
    773  1.53.2.3     joerg 		puffs_msg_setfaf(park_suspend);
    774  1.53.2.3     joerg 		suspend_msg->pvfsr_status = PUFFS_SUSPEND_RESUME;
    775  1.53.2.6     joerg 		puffs_msg_setinfo(park_suspend, PUFFSOP_VFS,
    776  1.53.2.6     joerg 		    PUFFS_VFS_SUSPEND, NULL);
    777  1.53.2.6     joerg 
    778  1.53.2.6     joerg 		puffs_msg_enqueue(pmp, park_suspend);
    779  1.53.2.3     joerg 		PUFFS_MSG_RELEASE(suspend);
    780      1.26     pooka 		break;
    781      1.26     pooka 
    782      1.26     pooka 	default:
    783      1.26     pooka 		error = EINVAL;
    784      1.26     pooka 		break;
    785      1.26     pooka 	}
    786      1.26     pooka 
    787      1.26     pooka 	DPRINTF(("puffs_suspendctl: return %d\n", error));
    788      1.26     pooka 	return error;
    789      1.26     pooka }
    790      1.26     pooka 
    791       1.1     pooka const struct vnodeopv_desc * const puffs_vnodeopv_descs[] = {
    792       1.1     pooka 	&puffs_vnodeop_opv_desc,
    793       1.3     pooka 	&puffs_specop_opv_desc,
    794       1.4     pooka 	&puffs_fifoop_opv_desc,
    795      1.12     pooka 	&puffs_msgop_opv_desc,
    796       1.1     pooka 	NULL,
    797       1.1     pooka };
    798       1.1     pooka 
    799       1.1     pooka struct vfsops puffs_vfsops = {
    800       1.1     pooka 	MOUNT_PUFFS,
    801      1.48       dsl 	sizeof (struct puffs_kargs),
    802       1.1     pooka 	puffs_mount,		/* mount	*/
    803       1.1     pooka 	puffs_start,		/* start	*/
    804       1.1     pooka 	puffs_unmount,		/* unmount	*/
    805       1.1     pooka 	puffs_root,		/* root		*/
    806      1.33     pooka 	(void *)eopnotsupp,	/* quotactl	*/
    807       1.1     pooka 	puffs_statvfs,		/* statvfs	*/
    808       1.1     pooka 	puffs_sync,		/* sync		*/
    809      1.33     pooka 	(void *)eopnotsupp,	/* vget		*/
    810      1.33     pooka 	puffs_fhtovp,		/* fhtovp	*/
    811      1.33     pooka 	puffs_vptofh,		/* vptofh	*/
    812       1.1     pooka 	puffs_init,		/* init		*/
    813       1.1     pooka 	NULL,			/* reinit	*/
    814       1.1     pooka 	puffs_done,		/* done		*/
    815       1.1     pooka 	NULL,			/* mountroot	*/
    816       1.1     pooka 	puffs_snapshot,		/* snapshot	*/
    817       1.1     pooka 	vfs_stdextattrctl,	/* extattrctl	*/
    818      1.26     pooka 	puffs_suspendctl,	/* suspendctl	*/
    819       1.1     pooka 	puffs_vnodeopv_descs,	/* vnodeops	*/
    820       1.1     pooka 	0,			/* refcount	*/
    821       1.1     pooka 	{ NULL, NULL }
    822       1.1     pooka };
    823       1.1     pooka VFS_ATTACH(puffs_vfsops);
    824