Home | History | Annotate | Line # | Download | only in puffs
puffs_vfsops.c revision 1.28.6.4
      1 /*	$NetBSD: puffs_vfsops.c,v 1.28.6.4 2007/04/10 13:26:36 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by the
      7  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8  * The Google SoC project was mentored by Bill Studenmund.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.28.6.4 2007/04/10 13:26:36 ad Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/mount.h>
     40 #include <sys/malloc.h>
     41 #include <sys/extattr.h>
     42 #include <sys/queue.h>
     43 #include <sys/vnode.h>
     44 #include <sys/dirent.h>
     45 #include <sys/kauth.h>
     46 #include <sys/fstrans.h>
     47 #include <sys/proc.h>
     48 
     49 #include <lib/libkern/libkern.h>
     50 
     51 #include <fs/puffs/puffs_msgif.h>
     52 #include <fs/puffs/puffs_sys.h>
     53 
     54 VFS_PROTOS(puffs);
     55 
     56 MALLOC_JUSTDEFINE(M_PUFFS, "puffs", "Pass-to-Userspace Framework File System");
     57 
     58 #ifndef PUFFS_PNODEBUCKETS
     59 #define PUFFS_PNODEBUCKETS 256
     60 #endif
     61 #ifndef PUFFS_MAXPNODEBUCKETS
     62 #define PUFFS_MAXPNODEBUCKETS 65536
     63 #endif
     64 int puffs_pnodebuckets = PUFFS_PNODEBUCKETS;
     65 
     66 int
     67 puffs_mount(struct mount *mp, const char *path, void *data,
     68 	    struct nameidata *ndp, struct lwp *l)
     69 {
     70 	struct puffs_mount *pmp = NULL;
     71 	struct puffs_args *args;
     72 	char namebuf[PUFFSNAMESIZE+sizeof(PUFFS_NAMEPREFIX)+1]; /* spooky */
     73 	int error = 0, i;
     74 
     75 	if (mp->mnt_flag & MNT_GETARGS) {
     76 		pmp = MPTOPUFFSMP(mp);
     77 		return copyout(&pmp->pmp_args, data, sizeof(struct puffs_args));
     78 	}
     79 
     80 	/* update is not supported currently */
     81 	if (mp->mnt_flag & MNT_UPDATE)
     82 		return EOPNOTSUPP;
     83 
     84 	/*
     85 	 * We need the file system name
     86 	 */
     87 	if (!data)
     88 		return EINVAL;
     89 
     90 	MALLOC(args, struct puffs_args *, sizeof(struct puffs_args),
     91 	    M_PUFFS, M_WAITOK);
     92 
     93 	error = copyin(data, args, sizeof(struct puffs_args));
     94 	if (error)
     95 		goto out;
     96 
     97 	/* devel phase */
     98 	if (args->pa_vers != (PUFFSVERSION | PUFFSDEVELVERS)) {
     99 		printf("puffs_mount: development version mismatch\n");
    100 		error = EINVAL;
    101 		goto out;
    102 	}
    103 
    104 	/* nuke spy bits */
    105 	args->pa_flags &= PUFFS_KFLAG_MASK;
    106 
    107 	/* build real name */
    108 	(void)strlcpy(namebuf, PUFFS_NAMEPREFIX, sizeof(namebuf));
    109 	(void)strlcat(namebuf, args->pa_name, sizeof(namebuf));
    110 
    111 	/* inform user server if it got the max request size it wanted */
    112 	if (args->pa_maxreqlen == 0 || args->pa_maxreqlen > PUFFS_REQ_MAXSIZE)
    113 		args->pa_maxreqlen = PUFFS_REQ_MAXSIZE;
    114 	else if (args->pa_maxreqlen < PUFFS_REQSTRUCT_MAX)
    115 		args->pa_maxreqlen = PUFFS_REQSTRUCT_MAX;
    116 	(void)strlcpy(args->pa_name, namebuf, sizeof(args->pa_name));
    117 
    118 	error = copyout(args, data, sizeof(struct puffs_args));
    119 	if (error)
    120 		goto out;
    121 
    122 	error = set_statvfs_info(path, UIO_USERSPACE, namebuf,
    123 	    UIO_SYSSPACE, mp, l);
    124 	if (error)
    125 		goto out;
    126 	mp->mnt_stat.f_iosize = DEV_BSIZE;
    127 
    128 	MALLOC(pmp, struct puffs_mount *, sizeof(struct puffs_mount),
    129 	    M_PUFFS, M_WAITOK | M_ZERO);
    130 
    131 	mp->mnt_fs_bshift = DEV_BSHIFT;
    132 	mp->mnt_dev_bshift = DEV_BSHIFT;
    133 	mp->mnt_flag &= ~MNT_LOCAL; /* we don't really know, so ... */
    134 	mp->mnt_data = pmp;
    135 	mp->mnt_iflag |= IMNT_HAS_TRANS;
    136 
    137 	pmp->pmp_status = PUFFSTAT_MOUNTING;
    138 	pmp->pmp_nextreq = 0;
    139 	pmp->pmp_mp = mp;
    140 	pmp->pmp_req_maxsize = args->pa_maxreqlen;
    141 	pmp->pmp_args = *args;
    142 
    143 	/* puffs_node hash buckets */
    144 	pmp->pmp_npnodehash = puffs_pnodebuckets;
    145 	if (pmp->pmp_npnodehash < 1)
    146 		pmp->pmp_npnodehash = 1;
    147 	if (pmp->pmp_npnodehash > PUFFS_MAXPNODEBUCKETS)
    148 		pmp->pmp_npnodehash = PUFFS_MAXPNODEBUCKETS;
    149 	pmp->pmp_pnodehash = malloc
    150 	    (sizeof(struct puffs_pnode_hashlist *) * pmp->pmp_npnodehash,
    151 	    M_PUFFS, M_WAITOK);
    152 	for (i = 0; i < pmp->pmp_npnodehash; i++)
    153 		LIST_INIT(&pmp->pmp_pnodehash[i]);
    154 
    155 	/*
    156 	 * Inform the fileops processing code that we have a mountpoint.
    157 	 * If it doesn't know about anyone with our pid/fd having the
    158 	 * device open, punt
    159 	 */
    160 	if (puffs_setpmp(l->l_proc->p_pid, args->pa_fd, pmp)) {
    161 		error = ENOENT;
    162 		goto out;
    163 	}
    164 
    165 	mutex_init(&pmp->pmp_lock, MUTEX_DEFAULT, IPL_NONE);
    166 	cv_init(&pmp->pmp_req_waiter_cv, "puffsget");
    167 	cv_init(&pmp->pmp_req_waitersink_cv, "puffsink");
    168 	cv_init(&pmp->pmp_unmounting_cv, "puffsum");
    169 	cv_init(&pmp->pmp_suspend_cv, "pufsusum");
    170 	TAILQ_INIT(&pmp->pmp_req_touser);
    171 	TAILQ_INIT(&pmp->pmp_req_replywait);
    172 	TAILQ_INIT(&pmp->pmp_req_sizepark);
    173 
    174 	DPRINTF(("puffs_mount: mount point at %p, puffs specific at %p\n",
    175 	    mp, MPTOPUFFSMP(mp)));
    176 
    177 	vfs_getnewfsid(mp);
    178 
    179  out:
    180 	if (error && pmp && pmp->pmp_pnodehash)
    181 		free(pmp->pmp_pnodehash, M_PUFFS);
    182 	if (error && pmp)
    183 		FREE(pmp, M_PUFFS);
    184 	FREE(args, M_PUFFS);
    185 	return error;
    186 }
    187 
    188 /*
    189  * This is called from the first "Hello, I'm alive" ioctl
    190  * from userspace.
    191  */
    192 int
    193 puffs_start2(struct puffs_mount *pmp, struct puffs_startreq *sreq)
    194 {
    195 	struct puffs_node *pn;
    196 	struct mount *mp;
    197 
    198 	mp = PMPTOMP(pmp);
    199 
    200 	mutex_enter(&pmp->pmp_lock);
    201 
    202 	/*
    203 	 * if someone has issued a VFS_ROOT() already, fill in the
    204 	 * vnode cookie.
    205 	 */
    206 	pn = NULL;
    207 	if (pmp->pmp_root) {
    208 		pn = VPTOPP(pmp->pmp_root);
    209 		pn->pn_cookie = sreq->psr_cookie;
    210 	}
    211 
    212 	/* We're good to fly */
    213 	pmp->pmp_rootcookie = sreq->psr_cookie;
    214 	pmp->pmp_status = PUFFSTAT_RUNNING;
    215 	mutex_exit(&pmp->pmp_lock);
    216 
    217 	/* do the VFS_STATVFS() we missed out on in sys_mount() */
    218 	copy_statvfs_info(&sreq->psr_sb, mp);
    219 	(void)memcpy(&mp->mnt_stat, &sreq->psr_sb, sizeof(mp->mnt_stat));
    220 	mp->mnt_stat.f_iosize = DEV_BSIZE;
    221 
    222 	DPRINTF(("puffs_start2: root vp %p, cur root pnode %p, cookie %p\n",
    223 	    pmp->pmp_root, pn, sreq->psr_cookie));
    224 
    225 	return 0;
    226 }
    227 
    228 int
    229 puffs_start(struct mount *mp, int flags, struct lwp *l)
    230 {
    231 
    232 	/*
    233 	 * This cannot travel to userspace, as this is called from
    234 	 * the kernel context of the process doing mount(2).  But
    235 	 * it's probably a safe bet that the process doing mount(2)
    236 	 * realizes it needs to start the filesystem also...
    237 	 */
    238 	return 0;
    239 }
    240 
    241 int
    242 puffs_unmount(struct mount *mp, int mntflags, struct lwp *l)
    243 {
    244 	struct puffs_mount *pmp;
    245 	int error, force;
    246 
    247 	PUFFS_VFSREQ(unmount);
    248 
    249 	error = 0;
    250 	force = mntflags & MNT_FORCE;
    251 	pmp = MPTOPUFFSMP(mp);
    252 
    253 	DPRINTF(("puffs_unmount: detach filesystem from vfs, current "
    254 	    "status 0x%x\n", pmp->pmp_status));
    255 
    256 	/*
    257 	 * flush all the vnodes.  VOP_RECLAIM() takes care that the
    258 	 * root vnode does not get flushed until unmount.  The
    259 	 * userspace root node cookie is stored in the mount
    260 	 * structure, so we can always re-instantiate a root vnode,
    261 	 * should userspace unmount decide it doesn't want to
    262 	 * cooperate.
    263 	 */
    264 	error = vflush(mp, NULLVP, force ? FORCECLOSE : 0);
    265 	if (error)
    266 		goto out;
    267 
    268 	/*
    269 	 * If we are not DYING, we should ask userspace's opinion
    270 	 * about the situation
    271 	 */
    272 	mutex_enter(&pmp->pmp_lock);
    273 	if (pmp->pmp_status != PUFFSTAT_DYING) {
    274 		pmp->pmp_unmounting = 1;
    275 		mutex_exit(&pmp->pmp_lock);
    276 
    277 		unmount_arg.pvfsr_flags = mntflags;
    278 		unmount_arg.pvfsr_pid = puffs_lwp2pid(l);
    279 
    280 		error = puffs_vfstouser(pmp, PUFFS_VFS_UNMOUNT,
    281 		     &unmount_arg, sizeof(unmount_arg));
    282 		DPRINTF(("puffs_unmount: error %d force %d\n", error, force));
    283 
    284 		mutex_enter(&pmp->pmp_lock);
    285 		pmp->pmp_unmounting = 0;
    286 		cv_broadcast(&pmp->pmp_unmounting_cv);
    287 	}
    288 
    289 	/*
    290 	 * if userspace cooperated or we really need to die,
    291 	 * screw what userland thinks and just die.
    292 	 */
    293 	if (error == 0 || force) {
    294 		/* tell waiters & other resources to go unwait themselves */
    295 		puffs_userdead(pmp);
    296 		puffs_nukebypmp(pmp);
    297 
    298 		/*
    299 		 * Sink waiters.  This is still not perfect, since the
    300 		 * draining is done after userret, not when they really
    301 		 * exit the file system.  It will probably work as almost
    302 		 * no call will block and therefore cause a context switch
    303 		 * and therefore will protected by the biglock after
    304 		 * exiting userspace.  But ... it's an imperfect world.
    305 		 */
    306 		while (pmp->pmp_req_waiters != 0)
    307 			cv_wait(&pmp->pmp_req_waitersink_cv, &pmp->pmp_lock);
    308 		mutex_exit(&pmp->pmp_lock);
    309 
    310 		/* free resources now that we hopefully have no waiters left */
    311 		cv_destroy(&pmp->pmp_req_waiter_cv);
    312 		cv_destroy(&pmp->pmp_req_waitersink_cv);
    313 		cv_destroy(&pmp->pmp_unmounting_cv);
    314 		cv_destroy(&pmp->pmp_suspend_cv);
    315 		mutex_destroy(&pmp->pmp_lock);
    316 
    317 		free(pmp->pmp_pnodehash, M_PUFFS);
    318 		FREE(pmp, M_PUFFS);
    319 		error = 0;
    320 	} else {
    321 		mutex_exit(&pmp->pmp_lock);
    322 	}
    323 
    324  out:
    325 	DPRINTF(("puffs_unmount: return %d\n", error));
    326 	return error;
    327 }
    328 
    329 /*
    330  * This doesn't need to travel to userspace
    331  */
    332 int
    333 puffs_root(struct mount *mp, struct vnode **vpp)
    334 {
    335 	struct puffs_mount *pmp;
    336 	struct puffs_node *pn;
    337 	struct vnode *vp;
    338 
    339 	pmp = MPTOPUFFSMP(mp);
    340 
    341 	/*
    342 	 * pmp_lock must be held if vref()'ing or vrele()'ing the
    343 	 * root vnode.  the latter is controlled by puffs_inactive().
    344 	 */
    345 	mutex_enter(&pmp->pmp_lock);
    346 	vp = pmp->pmp_root;
    347 	if (vp) {
    348 		mutex_enter(&vp->v_interlock);
    349 		mutex_exit(&pmp->pmp_lock);
    350 		pn = VPTOPP(vp);
    351 		if (vget(vp, LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK))
    352 			goto grabnew;
    353 		*vpp = vp;
    354 		return 0;
    355 	} else
    356 		mutex_exit(&pmp->pmp_lock);
    357 
    358 	/* XXX: this is wrong, so FIXME */
    359  grabnew:
    360 
    361 	/*
    362 	 * So, didn't have the magic root vnode available.
    363 	 * No matter, grab another an stuff it with the cookie.
    364 	 */
    365 	if (puffs_getvnode(mp, pmp->pmp_rootcookie, VDIR, 0, 0, &vp))
    366 		panic("sloppy programming");
    367 
    368 	mutex_enter(&pmp->pmp_lock);
    369 	/*
    370 	 * check if by mysterious force someone else created a root
    371 	 * vnode while we were executing.
    372 	 */
    373 	if (pmp->pmp_root) {
    374 		vref(pmp->pmp_root);
    375 		mutex_exit(&pmp->pmp_lock);
    376 		puffs_putvnode(vp);
    377 		vn_lock(pmp->pmp_root, LK_EXCLUSIVE | LK_RETRY);
    378 		*vpp = pmp->pmp_root;
    379 		return 0;
    380 	}
    381 
    382 	/* store cache */
    383 	vp->v_flag = VROOT;
    384 	pmp->pmp_root = vp;
    385 	mutex_exit(&pmp->pmp_lock);
    386 
    387 	vn_lock(pmp->pmp_root, LK_EXCLUSIVE | LK_RETRY);
    388 
    389 	*vpp = vp;
    390 	return 0;
    391 }
    392 
    393 int
    394 puffs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct lwp *l)
    395 {
    396 
    397 	return EOPNOTSUPP;
    398 }
    399 
    400 int
    401 puffs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    402 {
    403 	struct puffs_vfsreq_statvfs *statvfs_arg; /* too big for stack */
    404 	struct puffs_mount *pmp;
    405 	int error = 0;
    406 
    407 	pmp = MPTOPUFFSMP(mp);
    408 
    409 	/*
    410 	 * If we are mounting, it means that the userspace counterpart
    411 	 * is calling mount(2), but mount(2) also calls statvfs.  So
    412 	 * requesting statvfs from userspace would mean a deadlock.
    413 	 * Compensate.
    414 	 */
    415 	if (pmp->pmp_status == PUFFSTAT_MOUNTING)
    416 		return EINPROGRESS;
    417 
    418 	/* too big for stack */
    419 	MALLOC(statvfs_arg, struct puffs_vfsreq_statvfs *,
    420 	    sizeof(struct puffs_vfsreq_statvfs), M_PUFFS, M_WAITOK | M_ZERO);
    421 	statvfs_arg->pvfsr_pid = puffs_lwp2pid(l);
    422 
    423 	error = puffs_vfstouser(pmp, PUFFS_VFS_STATVFS,
    424 	    statvfs_arg, sizeof(*statvfs_arg));
    425 	statvfs_arg->pvfsr_sb.f_iosize = DEV_BSIZE;
    426 
    427 	/*
    428 	 * Try to produce a sensible result even in the event
    429 	 * of userspace error.
    430 	 *
    431 	 * XXX: cache the copy in non-error case
    432 	 */
    433 	if (!error) {
    434 		copy_statvfs_info(&statvfs_arg->pvfsr_sb, mp);
    435 		(void)memcpy(sbp, &statvfs_arg->pvfsr_sb,
    436 		    sizeof(struct statvfs));
    437 	} else {
    438 		copy_statvfs_info(sbp, mp);
    439 	}
    440 
    441 	FREE(statvfs_arg, M_PUFFS);
    442 	return error;
    443 }
    444 
    445 static int
    446 pageflush(struct mount *mp, kauth_cred_t cred,
    447 	int waitfor, int suspending, struct lwp *l)
    448 {
    449 	struct puffs_node *pn;
    450 	struct vnode *vp, *nvp;
    451 	int error, rv;
    452 
    453 	KASSERT(((waitfor == MNT_WAIT) && suspending) == 0);
    454 	KASSERT((suspending == 0)
    455 	    || (fstrans_is_owner(mp)
    456 	      && fstrans_getstate(mp) == FSTRANS_SUSPENDING));
    457 
    458 	error = 0;
    459 
    460 	/*
    461 	 * Sync all cached data from regular vnodes (which are not
    462 	 * currently locked, see below).  After this we call VFS_SYNC
    463 	 * for the fs server, which should handle data and metadata for
    464 	 * all the nodes it knows to exist.
    465 	 */
    466 	mutex_enter(&mntvnode_lock);
    467  loop:
    468 	for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
    469 		/* check if we're on the right list */
    470 		if (vp->v_mount != mp)
    471 			goto loop;
    472 
    473 		mutex_enter(&vp->v_interlock);
    474 		pn = VPTOPP(vp);
    475 		nvp = TAILQ_NEXT(vp, v_mntvnodes);
    476 
    477 		if (vp->v_type != VREG || UVM_OBJ_IS_CLEAN(&vp->v_uobj)) {
    478 			mutex_exit(&vp->v_interlock);
    479 			continue;
    480 		}
    481 
    482 		mutex_exit(&mntvnode_lock);
    483 
    484 		/*
    485 		 * Here we try to get a reference to the vnode and to
    486 		 * lock it.  This is mostly cargo-culted, but I will
    487 		 * offer an explanation to why I believe this might
    488 		 * actually do the right thing.
    489 		 *
    490 		 * If the vnode is a goner, we quite obviously don't need
    491 		 * to sync it.
    492 		 *
    493 		 * If the vnode was busy, we don't need to sync it because
    494 		 * this is never called with MNT_WAIT except from
    495 		 * dounmount(), when we are wait-flushing all the dirty
    496 		 * vnodes through other routes in any case.  So there,
    497 		 * sync() doesn't actually sync.  Happy now?
    498 		 *
    499 		 * NOTE: if we're suspending, vget() does NOT lock.
    500 		 * See puffs_lock() for details.
    501 		 */
    502 		rv = vget(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_INTERLOCK);
    503 		if (rv) {
    504 			mutex_enter(&mntvnode_lock);
    505 			if (rv == ENOENT)
    506 				goto loop;
    507 			continue;
    508 		}
    509 
    510 		/*
    511 		 * Thread information to puffs_strategy() through the
    512 		 * pnode flags: we want to issue the putpages operations
    513 		 * as FAF if we're suspending, since it's very probable
    514 		 * that our execution context is that of the userspace
    515 		 * daemon.  We can do this because:
    516 		 *   + we send the "going to suspend" prior to this part
    517 		 *   + if any of the writes fails in userspace, it's the
    518 		 *     file system server's problem to decide if this was a
    519 		 *     failed snapshot when it gets the "snapshot complete"
    520 		 *     notification.
    521 		 *   + if any of the writes fail in the kernel already, we
    522 		 *     immediately fail *and* notify the user server of
    523 		 *     failure.
    524 		 *
    525 		 * We also do FAFs if we're called from the syncer.  This
    526 		 * is just general optimization for trickle sync: no need
    527 		 * to really guarantee that the stuff ended on backing
    528 		 * storage.
    529 		 * TODO: Maybe also hint the user server of this twist?
    530 		 */
    531 		if (suspending || waitfor == MNT_LAZY) {
    532 			mutex_enter(&vp->v_interlock);
    533 			pn->pn_stat |= PNODE_SUSPEND;
    534 			mutex_exit(&vp->v_interlock);
    535 		}
    536 		rv = VOP_FSYNC(vp, cred, waitfor, 0, 0, l);
    537 		if (suspending || waitfor == MNT_LAZY) {
    538 			mutex_enter(&vp->v_interlock);
    539 			pn->pn_stat &= ~PNODE_SUSPEND;
    540 			mutex_exit(&vp->v_interlock);
    541 		}
    542 		if (rv)
    543 			error = rv;
    544 		vput(vp);
    545 		mutex_enter(&mntvnode_lock);
    546 	}
    547 	mutex_exit(&mntvnode_lock);
    548 
    549 	return error;
    550 }
    551 
    552 int
    553 puffs_sync(struct mount *mp, int waitfor, struct kauth_cred *cred,
    554 	struct lwp *l)
    555 {
    556 	int error, rv;
    557 
    558 	PUFFS_VFSREQ(sync);
    559 
    560 	error = pageflush(mp, cred, waitfor, 0, l);
    561 
    562 	/* sync fs */
    563 	sync_arg.pvfsr_waitfor = waitfor;
    564 	puffs_credcvt(&sync_arg.pvfsr_cred, cred);
    565 	sync_arg.pvfsr_pid = puffs_lwp2pid(l);
    566 
    567 	rv = puffs_vfstouser(MPTOPUFFSMP(mp), PUFFS_VFS_SYNC,
    568 	    &sync_arg, sizeof(sync_arg));
    569 	if (rv)
    570 		error = rv;
    571 
    572 	return error;
    573 }
    574 
    575 int
    576 puffs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
    577 {
    578 
    579 	return EOPNOTSUPP;
    580 }
    581 
    582 #if 0
    583 /*ARGSUSED*/
    584 int
    585 puffs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
    586 {
    587 
    588 	return EOPNOTSUPP;
    589 }
    590 
    591 /*ARGSUSED*/
    592 int
    593 puffs_vptofh(struct vnode *vp, struct fid *fhp)
    594 {
    595 
    596 	return EOPNOTSUPP;
    597 }
    598 #endif
    599 
    600 void
    601 puffs_init()
    602 {
    603 
    604 	malloc_type_attach(M_PUFFS);
    605 
    606 	pool_init(&puffs_pnpool, sizeof(struct puffs_node), 0, 0, 0,
    607 	    "puffpnpl", &pool_allocator_nointr, IPL_NONE);
    608 	puffs_transport_init();
    609 	puffs_msgif_init();
    610 }
    611 
    612 void
    613 puffs_done()
    614 {
    615 
    616 	puffs_msgif_destroy();
    617 	puffs_transport_destroy();
    618 	pool_destroy(&puffs_pnpool);
    619 
    620 	malloc_type_detach(M_PUFFS);
    621 }
    622 
    623 int
    624 puffs_snapshot(struct mount *mp, struct vnode *vp, struct timespec *ts)
    625 {
    626 
    627 	return EOPNOTSUPP;
    628 }
    629 
    630 int
    631 puffs_suspendctl(struct mount *mp, int cmd)
    632 {
    633 	struct puffs_mount *pmp;
    634 	int error;
    635 
    636 	pmp = MPTOPUFFSMP(mp);
    637 	switch (cmd) {
    638 	case SUSPEND_SUSPEND:
    639 		DPRINTF(("puffs_suspendctl: suspending\n"));
    640 		if ((error = fstrans_setstate(mp, FSTRANS_SUSPENDING)) != 0)
    641 			break;
    642 		puffs_suspendtouser(pmp, PUFFS_SUSPEND_START);
    643 
    644 		error = pageflush(mp, FSCRED, 0, 1, curlwp);
    645 		if (error == 0)
    646 			error = fstrans_setstate(mp, FSTRANS_SUSPENDED);
    647 
    648 		if (error != 0) {
    649 			puffs_suspendtouser(pmp, PUFFS_SUSPEND_ERROR);
    650 			(void) fstrans_setstate(mp, FSTRANS_NORMAL);
    651 			break;
    652 		}
    653 
    654 		puffs_suspendtouser(pmp, PUFFS_SUSPEND_SUSPENDED);
    655 
    656 		break;
    657 
    658 	case SUSPEND_RESUME:
    659 		DPRINTF(("puffs_suspendctl: resume\n"));
    660 		error = 0;
    661 		(void) fstrans_setstate(mp, FSTRANS_NORMAL);
    662 		puffs_suspendtouser(pmp, PUFFS_SUSPEND_RESUME);
    663 		break;
    664 
    665 	default:
    666 		error = EINVAL;
    667 		break;
    668 	}
    669 
    670 	DPRINTF(("puffs_suspendctl: return %d\n", error));
    671 	return error;
    672 }
    673 
    674 const struct vnodeopv_desc * const puffs_vnodeopv_descs[] = {
    675 	&puffs_vnodeop_opv_desc,
    676 	&puffs_specop_opv_desc,
    677 	&puffs_fifoop_opv_desc,
    678 	&puffs_msgop_opv_desc,
    679 	NULL,
    680 };
    681 
    682 struct vfsops puffs_vfsops = {
    683 	MOUNT_PUFFS,
    684 	puffs_mount,		/* mount	*/
    685 	puffs_start,		/* start	*/
    686 	puffs_unmount,		/* unmount	*/
    687 	puffs_root,		/* root		*/
    688 	puffs_quotactl,		/* quotactl	*/
    689 	puffs_statvfs,		/* statvfs	*/
    690 	puffs_sync,		/* sync		*/
    691 	puffs_vget,		/* vget		*/
    692 	(void *)eopnotsupp,	/* fhtovp	*/
    693 	(void *)eopnotsupp,	/* vptofh	*/
    694 	puffs_init,		/* init		*/
    695 	NULL,			/* reinit	*/
    696 	puffs_done,		/* done		*/
    697 	NULL,			/* mountroot	*/
    698 	puffs_snapshot,		/* snapshot	*/
    699 	vfs_stdextattrctl,	/* extattrctl	*/
    700 	puffs_suspendctl,	/* suspendctl	*/
    701 	puffs_vnodeopv_descs,	/* vnodeops	*/
    702 	0,			/* refcount	*/
    703 	{ NULL, NULL }
    704 };
    705 VFS_ATTACH(puffs_vfsops);
    706