xref: /minix3/sys/fs/puffs/puffs_vnops.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: puffs_vnops.c,v 1.203 2015/04/20 23:03:08 riastradh Exp $	*/
284d9c625SLionel Sambuc 
384d9c625SLionel Sambuc /*
484d9c625SLionel Sambuc  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
584d9c625SLionel Sambuc  *
684d9c625SLionel Sambuc  * Development of this software was supported by the
784d9c625SLionel Sambuc  * Google Summer of Code program and the Ulla Tuominen Foundation.
884d9c625SLionel Sambuc  * The Google SoC project was mentored by Bill Studenmund.
984d9c625SLionel Sambuc  *
1084d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1184d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
1284d9c625SLionel Sambuc  * are met:
1384d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1484d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1584d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1684d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1784d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1884d9c625SLionel Sambuc  *
1984d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
2084d9c625SLionel Sambuc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2184d9c625SLionel Sambuc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2284d9c625SLionel Sambuc  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2384d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2484d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2584d9c625SLionel Sambuc  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2684d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2784d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2884d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2984d9c625SLionel Sambuc  * SUCH DAMAGE.
3084d9c625SLionel Sambuc  */
3184d9c625SLionel Sambuc 
3284d9c625SLionel Sambuc #include <sys/cdefs.h>
33*0a6a1f1dSLionel Sambuc __KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.203 2015/04/20 23:03:08 riastradh Exp $");
3484d9c625SLionel Sambuc 
3584d9c625SLionel Sambuc #include <sys/param.h>
3684d9c625SLionel Sambuc #include <sys/buf.h>
3784d9c625SLionel Sambuc #include <sys/lockf.h>
3884d9c625SLionel Sambuc #include <sys/malloc.h>
3984d9c625SLionel Sambuc #include <sys/mount.h>
4084d9c625SLionel Sambuc #include <sys/namei.h>
4184d9c625SLionel Sambuc #include <sys/vnode.h>
4284d9c625SLionel Sambuc #include <sys/proc.h>
4384d9c625SLionel Sambuc #include <sys/kernel.h> /* For hz, hardclock_ticks */
4484d9c625SLionel Sambuc 
4584d9c625SLionel Sambuc #include <uvm/uvm.h>
4684d9c625SLionel Sambuc 
4784d9c625SLionel Sambuc #include <fs/puffs/puffs_msgif.h>
4884d9c625SLionel Sambuc #include <fs/puffs/puffs_sys.h>
4984d9c625SLionel Sambuc 
5084d9c625SLionel Sambuc #include <miscfs/fifofs/fifo.h>
5184d9c625SLionel Sambuc #include <miscfs/genfs/genfs.h>
5284d9c625SLionel Sambuc #include <miscfs/specfs/specdev.h>
5384d9c625SLionel Sambuc 
5484d9c625SLionel Sambuc int	puffs_vnop_lookup(void *);
5584d9c625SLionel Sambuc int	puffs_vnop_create(void *);
5684d9c625SLionel Sambuc int	puffs_vnop_access(void *);
5784d9c625SLionel Sambuc int	puffs_vnop_mknod(void *);
5884d9c625SLionel Sambuc int	puffs_vnop_open(void *);
5984d9c625SLionel Sambuc int	puffs_vnop_close(void *);
6084d9c625SLionel Sambuc int	puffs_vnop_getattr(void *);
6184d9c625SLionel Sambuc int	puffs_vnop_setattr(void *);
6284d9c625SLionel Sambuc int	puffs_vnop_reclaim(void *);
6384d9c625SLionel Sambuc int	puffs_vnop_readdir(void *);
6484d9c625SLionel Sambuc int	puffs_vnop_poll(void *);
6584d9c625SLionel Sambuc int	puffs_vnop_fsync(void *);
6684d9c625SLionel Sambuc int	puffs_vnop_seek(void *);
6784d9c625SLionel Sambuc int	puffs_vnop_remove(void *);
6884d9c625SLionel Sambuc int	puffs_vnop_mkdir(void *);
6984d9c625SLionel Sambuc int	puffs_vnop_rmdir(void *);
7084d9c625SLionel Sambuc int	puffs_vnop_link(void *);
7184d9c625SLionel Sambuc int	puffs_vnop_readlink(void *);
7284d9c625SLionel Sambuc int	puffs_vnop_symlink(void *);
7384d9c625SLionel Sambuc int	puffs_vnop_rename(void *);
7484d9c625SLionel Sambuc int	puffs_vnop_read(void *);
7584d9c625SLionel Sambuc int	puffs_vnop_write(void *);
76*0a6a1f1dSLionel Sambuc int	puffs_vnop_fallocate(void *);
77*0a6a1f1dSLionel Sambuc int	puffs_vnop_fdiscard(void *);
7884d9c625SLionel Sambuc int	puffs_vnop_fcntl(void *);
7984d9c625SLionel Sambuc int	puffs_vnop_ioctl(void *);
8084d9c625SLionel Sambuc int	puffs_vnop_inactive(void *);
8184d9c625SLionel Sambuc int	puffs_vnop_print(void *);
8284d9c625SLionel Sambuc int	puffs_vnop_pathconf(void *);
8384d9c625SLionel Sambuc int	puffs_vnop_advlock(void *);
8484d9c625SLionel Sambuc int	puffs_vnop_strategy(void *);
8584d9c625SLionel Sambuc int	puffs_vnop_bmap(void *);
8684d9c625SLionel Sambuc int	puffs_vnop_mmap(void *);
8784d9c625SLionel Sambuc int	puffs_vnop_getpages(void *);
8884d9c625SLionel Sambuc int	puffs_vnop_abortop(void *);
8984d9c625SLionel Sambuc int	puffs_vnop_getextattr(void *);
9084d9c625SLionel Sambuc int	puffs_vnop_setextattr(void *);
9184d9c625SLionel Sambuc int	puffs_vnop_listextattr(void *);
9284d9c625SLionel Sambuc int	puffs_vnop_deleteextattr(void *);
9384d9c625SLionel Sambuc 
9484d9c625SLionel Sambuc int	puffs_vnop_spec_read(void *);
9584d9c625SLionel Sambuc int	puffs_vnop_spec_write(void *);
9684d9c625SLionel Sambuc int	puffs_vnop_fifo_read(void *);
9784d9c625SLionel Sambuc int	puffs_vnop_fifo_write(void *);
9884d9c625SLionel Sambuc 
9984d9c625SLionel Sambuc int	puffs_vnop_checkop(void *);
10084d9c625SLionel Sambuc 
10184d9c625SLionel Sambuc #define puffs_vnop_lock genfs_lock
10284d9c625SLionel Sambuc #define puffs_vnop_unlock genfs_unlock
10384d9c625SLionel Sambuc #define puffs_vnop_islocked genfs_islocked
10484d9c625SLionel Sambuc 
10584d9c625SLionel Sambuc int (**puffs_vnodeop_p)(void *);
10684d9c625SLionel Sambuc const struct vnodeopv_entry_desc puffs_vnodeop_entries[] = {
10784d9c625SLionel Sambuc 	{ &vop_default_desc, vn_default_error },
10884d9c625SLionel Sambuc 	{ &vop_lookup_desc, puffs_vnop_lookup },	/* REAL lookup */
10984d9c625SLionel Sambuc 	{ &vop_create_desc, puffs_vnop_checkop },	/* create */
11084d9c625SLionel Sambuc         { &vop_mknod_desc, puffs_vnop_checkop },	/* mknod */
11184d9c625SLionel Sambuc         { &vop_open_desc, puffs_vnop_open },		/* REAL open */
11284d9c625SLionel Sambuc         { &vop_close_desc, puffs_vnop_checkop },	/* close */
11384d9c625SLionel Sambuc         { &vop_access_desc, puffs_vnop_access },	/* REAL access */
11484d9c625SLionel Sambuc         { &vop_getattr_desc, puffs_vnop_checkop },	/* getattr */
11584d9c625SLionel Sambuc         { &vop_setattr_desc, puffs_vnop_checkop },	/* setattr */
11684d9c625SLionel Sambuc         { &vop_read_desc, puffs_vnop_checkop },		/* read */
11784d9c625SLionel Sambuc         { &vop_write_desc, puffs_vnop_checkop },	/* write */
118*0a6a1f1dSLionel Sambuc 	{ &vop_fallocate_desc, puffs_vnop_fallocate },	/* fallocate */
119*0a6a1f1dSLionel Sambuc 	{ &vop_fdiscard_desc, puffs_vnop_fdiscard },	/* fdiscard */
12084d9c625SLionel Sambuc         { &vop_fsync_desc, puffs_vnop_fsync },		/* REAL fsync */
12184d9c625SLionel Sambuc         { &vop_seek_desc, puffs_vnop_checkop },		/* seek */
12284d9c625SLionel Sambuc         { &vop_remove_desc, puffs_vnop_checkop },	/* remove */
12384d9c625SLionel Sambuc         { &vop_link_desc, puffs_vnop_checkop },		/* link */
12484d9c625SLionel Sambuc         { &vop_rename_desc, puffs_vnop_checkop },	/* rename */
12584d9c625SLionel Sambuc         { &vop_mkdir_desc, puffs_vnop_checkop },	/* mkdir */
12684d9c625SLionel Sambuc         { &vop_rmdir_desc, puffs_vnop_checkop },	/* rmdir */
12784d9c625SLionel Sambuc         { &vop_symlink_desc, puffs_vnop_checkop },	/* symlink */
12884d9c625SLionel Sambuc         { &vop_readdir_desc, puffs_vnop_checkop },	/* readdir */
12984d9c625SLionel Sambuc         { &vop_readlink_desc, puffs_vnop_checkop },	/* readlink */
13084d9c625SLionel Sambuc         { &vop_getpages_desc, puffs_vnop_checkop },	/* getpages */
13184d9c625SLionel Sambuc         { &vop_putpages_desc, genfs_putpages },		/* REAL putpages */
13284d9c625SLionel Sambuc         { &vop_pathconf_desc, puffs_vnop_checkop },	/* pathconf */
13384d9c625SLionel Sambuc         { &vop_advlock_desc, puffs_vnop_advlock },	/* advlock */
13484d9c625SLionel Sambuc         { &vop_strategy_desc, puffs_vnop_strategy },	/* REAL strategy */
13584d9c625SLionel Sambuc         { &vop_revoke_desc, genfs_revoke },		/* REAL revoke */
13684d9c625SLionel Sambuc         { &vop_abortop_desc, puffs_vnop_abortop },	/* REAL abortop */
13784d9c625SLionel Sambuc         { &vop_inactive_desc, puffs_vnop_inactive },	/* REAL inactive */
13884d9c625SLionel Sambuc         { &vop_reclaim_desc, puffs_vnop_reclaim },	/* REAL reclaim */
13984d9c625SLionel Sambuc         { &vop_lock_desc, puffs_vnop_lock },		/* REAL lock */
14084d9c625SLionel Sambuc         { &vop_unlock_desc, puffs_vnop_unlock },	/* REAL unlock */
14184d9c625SLionel Sambuc         { &vop_bmap_desc, puffs_vnop_bmap },		/* REAL bmap */
14284d9c625SLionel Sambuc         { &vop_print_desc, puffs_vnop_print },		/* REAL print */
14384d9c625SLionel Sambuc         { &vop_islocked_desc, puffs_vnop_islocked },	/* REAL islocked */
14484d9c625SLionel Sambuc         { &vop_bwrite_desc, genfs_nullop },		/* REAL bwrite */
14584d9c625SLionel Sambuc         { &vop_mmap_desc, puffs_vnop_mmap },		/* REAL mmap */
14684d9c625SLionel Sambuc         { &vop_poll_desc, puffs_vnop_poll },		/* REAL poll */
14784d9c625SLionel Sambuc 	{ &vop_getextattr_desc, puffs_vnop_getextattr },	/* getextattr */
14884d9c625SLionel Sambuc 	{ &vop_setextattr_desc, puffs_vnop_setextattr },	/* setextattr */
14984d9c625SLionel Sambuc 	{ &vop_listextattr_desc, puffs_vnop_listextattr },	/* listextattr */
15084d9c625SLionel Sambuc 	{ &vop_deleteextattr_desc, puffs_vnop_deleteextattr },/* deleteextattr */
15184d9c625SLionel Sambuc #if 0
15284d9c625SLionel Sambuc 	{ &vop_openextattr_desc, puffs_vnop_checkop },	/* openextattr */
15384d9c625SLionel Sambuc 	{ &vop_closeextattr_desc, puffs_vnop_checkop },	/* closeextattr */
15484d9c625SLionel Sambuc #endif
15584d9c625SLionel Sambuc         { &vop_kqfilter_desc, genfs_eopnotsupp },	/* kqfilter XXX */
15684d9c625SLionel Sambuc 	{ NULL, NULL }
15784d9c625SLionel Sambuc };
15884d9c625SLionel Sambuc const struct vnodeopv_desc puffs_vnodeop_opv_desc =
15984d9c625SLionel Sambuc 	{ &puffs_vnodeop_p, puffs_vnodeop_entries };
16084d9c625SLionel Sambuc 
16184d9c625SLionel Sambuc 
16284d9c625SLionel Sambuc int (**puffs_specop_p)(void *);
16384d9c625SLionel Sambuc const struct vnodeopv_entry_desc puffs_specop_entries[] = {
16484d9c625SLionel Sambuc 	{ &vop_default_desc, vn_default_error },
16584d9c625SLionel Sambuc 	{ &vop_lookup_desc, spec_lookup },		/* lookup, ENOTDIR */
16684d9c625SLionel Sambuc 	{ &vop_create_desc, spec_create },		/* genfs_badop */
16784d9c625SLionel Sambuc 	{ &vop_mknod_desc, spec_mknod },		/* genfs_badop */
16884d9c625SLionel Sambuc 	{ &vop_open_desc, spec_open },			/* spec_open */
16984d9c625SLionel Sambuc 	{ &vop_close_desc, spec_close },		/* spec_close */
17084d9c625SLionel Sambuc 	{ &vop_access_desc, puffs_vnop_checkop },	/* access */
17184d9c625SLionel Sambuc 	{ &vop_getattr_desc, puffs_vnop_checkop },	/* getattr */
17284d9c625SLionel Sambuc 	{ &vop_setattr_desc, puffs_vnop_checkop },	/* setattr */
17384d9c625SLionel Sambuc 	{ &vop_read_desc, puffs_vnop_spec_read },	/* update, read */
17484d9c625SLionel Sambuc 	{ &vop_write_desc, puffs_vnop_spec_write },	/* update, write */
175*0a6a1f1dSLionel Sambuc 	{ &vop_fallocate_desc, spec_fallocate },	/* fallocate */
176*0a6a1f1dSLionel Sambuc 	{ &vop_fdiscard_desc, spec_fdiscard },		/* fdiscard */
17784d9c625SLionel Sambuc 	{ &vop_ioctl_desc, spec_ioctl },		/* spec_ioctl */
17884d9c625SLionel Sambuc 	{ &vop_fcntl_desc, genfs_fcntl },		/* dummy */
17984d9c625SLionel Sambuc 	{ &vop_poll_desc, spec_poll },			/* spec_poll */
18084d9c625SLionel Sambuc 	{ &vop_kqfilter_desc, spec_kqfilter },		/* spec_kqfilter */
18184d9c625SLionel Sambuc 	{ &vop_revoke_desc, spec_revoke },		/* genfs_revoke */
18284d9c625SLionel Sambuc 	{ &vop_mmap_desc, spec_mmap },			/* spec_mmap */
18384d9c625SLionel Sambuc 	{ &vop_fsync_desc, spec_fsync },		/* vflushbuf */
18484d9c625SLionel Sambuc 	{ &vop_seek_desc, spec_seek },			/* genfs_nullop */
18584d9c625SLionel Sambuc 	{ &vop_remove_desc, spec_remove },		/* genfs_badop */
18684d9c625SLionel Sambuc 	{ &vop_link_desc, spec_link },			/* genfs_badop */
18784d9c625SLionel Sambuc 	{ &vop_rename_desc, spec_rename },		/* genfs_badop */
18884d9c625SLionel Sambuc 	{ &vop_mkdir_desc, spec_mkdir },		/* genfs_badop */
18984d9c625SLionel Sambuc 	{ &vop_rmdir_desc, spec_rmdir },		/* genfs_badop */
19084d9c625SLionel Sambuc 	{ &vop_symlink_desc, spec_symlink },		/* genfs_badop */
19184d9c625SLionel Sambuc 	{ &vop_readdir_desc, spec_readdir },		/* genfs_badop */
19284d9c625SLionel Sambuc 	{ &vop_readlink_desc, spec_readlink },		/* genfs_badop */
19384d9c625SLionel Sambuc 	{ &vop_abortop_desc, spec_abortop },		/* genfs_badop */
19484d9c625SLionel Sambuc 	{ &vop_inactive_desc, puffs_vnop_inactive },	/* REAL inactive */
19584d9c625SLionel Sambuc 	{ &vop_reclaim_desc, puffs_vnop_reclaim },	/* REAL reclaim */
19684d9c625SLionel Sambuc 	{ &vop_lock_desc, puffs_vnop_lock },		/* REAL lock */
19784d9c625SLionel Sambuc 	{ &vop_unlock_desc, puffs_vnop_unlock },	/* REAL unlock */
19884d9c625SLionel Sambuc 	{ &vop_bmap_desc, spec_bmap },			/* dummy */
19984d9c625SLionel Sambuc 	{ &vop_strategy_desc, spec_strategy },		/* dev strategy */
20084d9c625SLionel Sambuc 	{ &vop_print_desc, puffs_vnop_print },		/* REAL print */
20184d9c625SLionel Sambuc 	{ &vop_islocked_desc, puffs_vnop_islocked },	/* REAL islocked */
20284d9c625SLionel Sambuc 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
20384d9c625SLionel Sambuc 	{ &vop_advlock_desc, spec_advlock },		/* lf_advlock */
20484d9c625SLionel Sambuc 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
20584d9c625SLionel Sambuc 	{ &vop_getpages_desc, spec_getpages },		/* genfs_getpages */
20684d9c625SLionel Sambuc 	{ &vop_putpages_desc, spec_putpages },		/* genfs_putpages */
20784d9c625SLionel Sambuc 	{ &vop_getextattr_desc, puffs_vnop_checkop },	/* getextattr */
20884d9c625SLionel Sambuc 	{ &vop_setextattr_desc, puffs_vnop_checkop },	/* setextattr */
20984d9c625SLionel Sambuc 	{ &vop_listextattr_desc, puffs_vnop_checkop },	/* listextattr */
21084d9c625SLionel Sambuc 	{ &vop_deleteextattr_desc, puffs_vnop_checkop },/* deleteextattr */
21184d9c625SLionel Sambuc #if 0
21284d9c625SLionel Sambuc 	{ &vop_openextattr_desc, _openextattr },	/* openextattr */
21384d9c625SLionel Sambuc 	{ &vop_closeextattr_desc, _closeextattr },	/* closeextattr */
21484d9c625SLionel Sambuc #endif
21584d9c625SLionel Sambuc 	{ NULL, NULL }
21684d9c625SLionel Sambuc };
21784d9c625SLionel Sambuc const struct vnodeopv_desc puffs_specop_opv_desc =
21884d9c625SLionel Sambuc 	{ &puffs_specop_p, puffs_specop_entries };
21984d9c625SLionel Sambuc 
22084d9c625SLionel Sambuc 
22184d9c625SLionel Sambuc int (**puffs_fifoop_p)(void *);
22284d9c625SLionel Sambuc const struct vnodeopv_entry_desc puffs_fifoop_entries[] = {
22384d9c625SLionel Sambuc 	{ &vop_default_desc, vn_default_error },
22484d9c625SLionel Sambuc 	{ &vop_lookup_desc, vn_fifo_bypass },		/* lookup, ENOTDIR */
22584d9c625SLionel Sambuc 	{ &vop_create_desc, vn_fifo_bypass },		/* genfs_badop */
22684d9c625SLionel Sambuc 	{ &vop_mknod_desc, vn_fifo_bypass },		/* genfs_badop */
22784d9c625SLionel Sambuc 	{ &vop_open_desc, vn_fifo_bypass },		/* open */
22884d9c625SLionel Sambuc 	{ &vop_close_desc, vn_fifo_bypass },		/* close */
22984d9c625SLionel Sambuc 	{ &vop_access_desc, puffs_vnop_checkop },	/* access */
23084d9c625SLionel Sambuc 	{ &vop_getattr_desc, puffs_vnop_checkop },	/* getattr */
23184d9c625SLionel Sambuc 	{ &vop_setattr_desc, puffs_vnop_checkop },	/* setattr */
23284d9c625SLionel Sambuc 	{ &vop_read_desc, puffs_vnop_fifo_read },	/* read, update */
23384d9c625SLionel Sambuc 	{ &vop_write_desc, puffs_vnop_fifo_write },	/* write, update */
234*0a6a1f1dSLionel Sambuc 	{ &vop_fallocate_desc, vn_fifo_bypass },	/* fallocate */
235*0a6a1f1dSLionel Sambuc 	{ &vop_fdiscard_desc, vn_fifo_bypass },		/* fdiscard */
23684d9c625SLionel Sambuc 	{ &vop_ioctl_desc, vn_fifo_bypass },		/* ioctl */
23784d9c625SLionel Sambuc 	{ &vop_fcntl_desc, genfs_fcntl },		/* dummy */
23884d9c625SLionel Sambuc 	{ &vop_poll_desc, vn_fifo_bypass },		/* poll */
23984d9c625SLionel Sambuc 	{ &vop_kqfilter_desc, vn_fifo_bypass },		/* kqfilter */
24084d9c625SLionel Sambuc 	{ &vop_revoke_desc, vn_fifo_bypass },		/* genfs_revoke */
24184d9c625SLionel Sambuc 	{ &vop_mmap_desc, vn_fifo_bypass },		/* genfs_badop */
24284d9c625SLionel Sambuc 	{ &vop_fsync_desc, vn_fifo_bypass },		/* genfs_nullop*/
24384d9c625SLionel Sambuc 	{ &vop_seek_desc, vn_fifo_bypass },		/* genfs_badop */
24484d9c625SLionel Sambuc 	{ &vop_remove_desc, vn_fifo_bypass },		/* genfs_badop */
24584d9c625SLionel Sambuc 	{ &vop_link_desc, vn_fifo_bypass },		/* genfs_badop */
24684d9c625SLionel Sambuc 	{ &vop_rename_desc, vn_fifo_bypass },		/* genfs_badop */
24784d9c625SLionel Sambuc 	{ &vop_mkdir_desc, vn_fifo_bypass },		/* genfs_badop */
24884d9c625SLionel Sambuc 	{ &vop_rmdir_desc, vn_fifo_bypass },		/* genfs_badop */
24984d9c625SLionel Sambuc 	{ &vop_symlink_desc, vn_fifo_bypass },		/* genfs_badop */
25084d9c625SLionel Sambuc 	{ &vop_readdir_desc, vn_fifo_bypass },		/* genfs_badop */
25184d9c625SLionel Sambuc 	{ &vop_readlink_desc, vn_fifo_bypass },		/* genfs_badop */
25284d9c625SLionel Sambuc 	{ &vop_abortop_desc, vn_fifo_bypass },		/* genfs_badop */
25384d9c625SLionel Sambuc 	{ &vop_inactive_desc, puffs_vnop_inactive },	/* REAL inactive */
25484d9c625SLionel Sambuc 	{ &vop_reclaim_desc, puffs_vnop_reclaim },	/* REAL reclaim */
25584d9c625SLionel Sambuc 	{ &vop_lock_desc, puffs_vnop_lock },		/* REAL lock */
25684d9c625SLionel Sambuc 	{ &vop_unlock_desc, puffs_vnop_unlock },	/* REAL unlock */
25784d9c625SLionel Sambuc 	{ &vop_bmap_desc, vn_fifo_bypass },		/* dummy */
25884d9c625SLionel Sambuc 	{ &vop_strategy_desc, vn_fifo_bypass },		/* genfs_badop */
25984d9c625SLionel Sambuc 	{ &vop_print_desc, puffs_vnop_print },		/* REAL print */
26084d9c625SLionel Sambuc 	{ &vop_islocked_desc, puffs_vnop_islocked },	/* REAL islocked */
26184d9c625SLionel Sambuc 	{ &vop_pathconf_desc, vn_fifo_bypass },		/* pathconf */
26284d9c625SLionel Sambuc 	{ &vop_advlock_desc, vn_fifo_bypass },		/* genfs_einval */
26384d9c625SLionel Sambuc 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
26484d9c625SLionel Sambuc 	{ &vop_putpages_desc, vn_fifo_bypass }, 	/* genfs_null_putpages*/
26584d9c625SLionel Sambuc #if 0
26684d9c625SLionel Sambuc 	{ &vop_openextattr_desc, _openextattr },	/* openextattr */
26784d9c625SLionel Sambuc 	{ &vop_closeextattr_desc, _closeextattr },	/* closeextattr */
26884d9c625SLionel Sambuc #endif
26984d9c625SLionel Sambuc 	{ &vop_getextattr_desc, puffs_vnop_checkop },		/* getextattr */
27084d9c625SLionel Sambuc 	{ &vop_setextattr_desc, puffs_vnop_checkop },		/* setextattr */
27184d9c625SLionel Sambuc 	{ &vop_listextattr_desc, puffs_vnop_checkop },	/* listextattr */
27284d9c625SLionel Sambuc 	{ &vop_deleteextattr_desc, puffs_vnop_checkop },	/* deleteextattr */
27384d9c625SLionel Sambuc 	{ NULL, NULL }
27484d9c625SLionel Sambuc };
27584d9c625SLionel Sambuc const struct vnodeopv_desc puffs_fifoop_opv_desc =
27684d9c625SLionel Sambuc 	{ &puffs_fifoop_p, puffs_fifoop_entries };
27784d9c625SLionel Sambuc 
27884d9c625SLionel Sambuc 
27984d9c625SLionel Sambuc /* "real" vnode operations */
28084d9c625SLionel Sambuc int (**puffs_msgop_p)(void *);
28184d9c625SLionel Sambuc const struct vnodeopv_entry_desc puffs_msgop_entries[] = {
28284d9c625SLionel Sambuc 	{ &vop_default_desc, vn_default_error },
28384d9c625SLionel Sambuc 	{ &vop_create_desc, puffs_vnop_create },	/* create */
28484d9c625SLionel Sambuc         { &vop_mknod_desc, puffs_vnop_mknod },		/* mknod */
28584d9c625SLionel Sambuc         { &vop_open_desc, puffs_vnop_open },		/* open */
28684d9c625SLionel Sambuc         { &vop_close_desc, puffs_vnop_close },		/* close */
28784d9c625SLionel Sambuc         { &vop_access_desc, puffs_vnop_access },	/* access */
28884d9c625SLionel Sambuc         { &vop_getattr_desc, puffs_vnop_getattr },	/* getattr */
28984d9c625SLionel Sambuc         { &vop_setattr_desc, puffs_vnop_setattr },	/* setattr */
29084d9c625SLionel Sambuc         { &vop_read_desc, puffs_vnop_read },		/* read */
29184d9c625SLionel Sambuc         { &vop_write_desc, puffs_vnop_write },		/* write */
29284d9c625SLionel Sambuc         { &vop_seek_desc, puffs_vnop_seek },		/* seek */
29384d9c625SLionel Sambuc         { &vop_remove_desc, puffs_vnop_remove },	/* remove */
29484d9c625SLionel Sambuc         { &vop_link_desc, puffs_vnop_link },		/* link */
29584d9c625SLionel Sambuc         { &vop_rename_desc, puffs_vnop_rename },	/* rename */
29684d9c625SLionel Sambuc         { &vop_mkdir_desc, puffs_vnop_mkdir },		/* mkdir */
29784d9c625SLionel Sambuc         { &vop_rmdir_desc, puffs_vnop_rmdir },		/* rmdir */
29884d9c625SLionel Sambuc         { &vop_symlink_desc, puffs_vnop_symlink },	/* symlink */
29984d9c625SLionel Sambuc         { &vop_readdir_desc, puffs_vnop_readdir },	/* readdir */
30084d9c625SLionel Sambuc         { &vop_readlink_desc, puffs_vnop_readlink },	/* readlink */
30184d9c625SLionel Sambuc         { &vop_print_desc, puffs_vnop_print },		/* print */
30284d9c625SLionel Sambuc         { &vop_islocked_desc, puffs_vnop_islocked },	/* islocked */
30384d9c625SLionel Sambuc         { &vop_pathconf_desc, puffs_vnop_pathconf },	/* pathconf */
30484d9c625SLionel Sambuc         { &vop_getpages_desc, puffs_vnop_getpages },	/* getpages */
30584d9c625SLionel Sambuc 	{ NULL, NULL }
30684d9c625SLionel Sambuc };
30784d9c625SLionel Sambuc const struct vnodeopv_desc puffs_msgop_opv_desc =
30884d9c625SLionel Sambuc 	{ &puffs_msgop_p, puffs_msgop_entries };
30984d9c625SLionel Sambuc 
31084d9c625SLionel Sambuc /*
31184d9c625SLionel Sambuc  * for dosetattr / update_va
31284d9c625SLionel Sambuc  */
31384d9c625SLionel Sambuc #define SETATTR_CHSIZE	0x01
31484d9c625SLionel Sambuc #define SETATTR_ASYNC	0x02
31584d9c625SLionel Sambuc 
31684d9c625SLionel Sambuc #define ERROUT(err)							\
31784d9c625SLionel Sambuc do {									\
31884d9c625SLionel Sambuc 	error = err;							\
31984d9c625SLionel Sambuc 	goto out;							\
32084d9c625SLionel Sambuc } while (/*CONSTCOND*/0)
32184d9c625SLionel Sambuc 
32284d9c625SLionel Sambuc /*
32384d9c625SLionel Sambuc  * This is a generic vnode operation handler.  It checks if the necessary
32484d9c625SLionel Sambuc  * operations for the called vnode operation are implemented by userspace
32584d9c625SLionel Sambuc  * and either returns a dummy return value or proceeds to call the real
32684d9c625SLionel Sambuc  * vnode operation from puffs_msgop_v.
32784d9c625SLionel Sambuc  *
32884d9c625SLionel Sambuc  * XXX: this should described elsewhere and autogenerated, the complexity
32984d9c625SLionel Sambuc  * of the vnode operations vectors and their interrelationships is also
33084d9c625SLionel Sambuc  * getting a bit out of hand.  Another problem is that we need this same
33184d9c625SLionel Sambuc  * information in the fs server code, so keeping the two in sync manually
33284d9c625SLionel Sambuc  * is not a viable (long term) plan.
33384d9c625SLionel Sambuc  */
33484d9c625SLionel Sambuc 
33584d9c625SLionel Sambuc /* not supported, handle locking protocol */
33684d9c625SLionel Sambuc #define CHECKOP_NOTSUPP(op)						\
33784d9c625SLionel Sambuc case VOP_##op##_DESCOFFSET:						\
33884d9c625SLionel Sambuc 	if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0)			\
33984d9c625SLionel Sambuc 		return genfs_eopnotsupp(v);				\
34084d9c625SLionel Sambuc 	break
34184d9c625SLionel Sambuc 
34284d9c625SLionel Sambuc /* always succeed, no locking */
34384d9c625SLionel Sambuc #define CHECKOP_SUCCESS(op)						\
34484d9c625SLionel Sambuc case VOP_##op##_DESCOFFSET:						\
34584d9c625SLionel Sambuc 	if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0)			\
34684d9c625SLionel Sambuc 		return 0;						\
34784d9c625SLionel Sambuc 	break
34884d9c625SLionel Sambuc 
34984d9c625SLionel Sambuc int
puffs_vnop_checkop(void * v)35084d9c625SLionel Sambuc puffs_vnop_checkop(void *v)
35184d9c625SLionel Sambuc {
35284d9c625SLionel Sambuc 	struct vop_generic_args /* {
35384d9c625SLionel Sambuc 		struct vnodeop_desc *a_desc;
35484d9c625SLionel Sambuc 		spooky mystery contents;
35584d9c625SLionel Sambuc 	} */ *ap = v;
35684d9c625SLionel Sambuc 	struct vnodeop_desc *desc = ap->a_desc;
35784d9c625SLionel Sambuc 	struct puffs_mount *pmp;
35884d9c625SLionel Sambuc 	struct vnode *vp;
35984d9c625SLionel Sambuc 	int offset, rv;
36084d9c625SLionel Sambuc 
36184d9c625SLionel Sambuc 	offset = ap->a_desc->vdesc_vp_offsets[0];
36284d9c625SLionel Sambuc #ifdef DIAGNOSTIC
36384d9c625SLionel Sambuc 	if (offset == VDESC_NO_OFFSET)
36484d9c625SLionel Sambuc 		panic("puffs_checkop: no vnode, why did you call me?");
36584d9c625SLionel Sambuc #endif
36684d9c625SLionel Sambuc 	vp = *VOPARG_OFFSETTO(struct vnode **, offset, ap);
36784d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(vp->v_mount);
36884d9c625SLionel Sambuc 
36984d9c625SLionel Sambuc 	DPRINTF_VERBOSE(("checkop call %s (%d), vp %p\n",
37084d9c625SLionel Sambuc 	    ap->a_desc->vdesc_name, ap->a_desc->vdesc_offset, vp));
37184d9c625SLionel Sambuc 
37284d9c625SLionel Sambuc 	if (!ALLOPS(pmp)) {
37384d9c625SLionel Sambuc 		switch (desc->vdesc_offset) {
37484d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(CREATE);
37584d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(MKNOD);
37684d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(GETATTR);
37784d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(SETATTR);
37884d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(READ);
37984d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(WRITE);
38084d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(FCNTL);
38184d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(IOCTL);
38284d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(REMOVE);
38384d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(LINK);
38484d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(RENAME);
38584d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(MKDIR);
38684d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(RMDIR);
38784d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(SYMLINK);
38884d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(READDIR);
38984d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(READLINK);
39084d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(PRINT);
39184d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(PATHCONF);
39284d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(GETEXTATTR);
39384d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(SETEXTATTR);
39484d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(LISTEXTATTR);
39584d9c625SLionel Sambuc 			CHECKOP_NOTSUPP(DELETEEXTATTR);
39684d9c625SLionel Sambuc 
39784d9c625SLionel Sambuc 			CHECKOP_SUCCESS(ACCESS);
39884d9c625SLionel Sambuc 			CHECKOP_SUCCESS(CLOSE);
39984d9c625SLionel Sambuc 			CHECKOP_SUCCESS(SEEK);
40084d9c625SLionel Sambuc 
40184d9c625SLionel Sambuc 		case VOP_GETPAGES_DESCOFFSET:
40284d9c625SLionel Sambuc 			if (!EXISTSOP(pmp, READ))
40384d9c625SLionel Sambuc 				return genfs_eopnotsupp(v);
40484d9c625SLionel Sambuc 			break;
40584d9c625SLionel Sambuc 
40684d9c625SLionel Sambuc 		default:
40784d9c625SLionel Sambuc 			panic("puffs_checkop: unhandled vnop %d",
40884d9c625SLionel Sambuc 			    desc->vdesc_offset);
40984d9c625SLionel Sambuc 		}
41084d9c625SLionel Sambuc 	}
41184d9c625SLionel Sambuc 
41284d9c625SLionel Sambuc 	rv = VOCALL(puffs_msgop_p, ap->a_desc->vdesc_offset, v);
41384d9c625SLionel Sambuc 
41484d9c625SLionel Sambuc 	DPRINTF_VERBOSE(("checkop return %s (%d), vp %p: %d\n",
41584d9c625SLionel Sambuc 	    ap->a_desc->vdesc_name, ap->a_desc->vdesc_offset, vp, rv));
41684d9c625SLionel Sambuc 
41784d9c625SLionel Sambuc 	return rv;
41884d9c625SLionel Sambuc }
41984d9c625SLionel Sambuc 
42084d9c625SLionel Sambuc static int callremove(struct puffs_mount *, puffs_cookie_t, puffs_cookie_t,
42184d9c625SLionel Sambuc 			    struct componentname *);
42284d9c625SLionel Sambuc static int callrmdir(struct puffs_mount *, puffs_cookie_t, puffs_cookie_t,
42384d9c625SLionel Sambuc 			   struct componentname *);
42484d9c625SLionel Sambuc static void callinactive(struct puffs_mount *, puffs_cookie_t, int);
42584d9c625SLionel Sambuc static void callreclaim(struct puffs_mount *, puffs_cookie_t, int);
42684d9c625SLionel Sambuc static int  flushvncache(struct vnode *, off_t, off_t, bool);
42784d9c625SLionel Sambuc static void update_va(struct vnode *, struct vattr *, struct vattr *,
42884d9c625SLionel Sambuc 		      struct timespec *, struct timespec *, int);
42984d9c625SLionel Sambuc static void update_parent(struct vnode *, struct vnode *);
43084d9c625SLionel Sambuc 
43184d9c625SLionel Sambuc 
43284d9c625SLionel Sambuc #define PUFFS_ABORT_LOOKUP	1
43384d9c625SLionel Sambuc #define PUFFS_ABORT_CREATE	2
43484d9c625SLionel Sambuc #define PUFFS_ABORT_MKNOD	3
43584d9c625SLionel Sambuc #define PUFFS_ABORT_MKDIR	4
43684d9c625SLionel Sambuc #define PUFFS_ABORT_SYMLINK	5
43784d9c625SLionel Sambuc 
43884d9c625SLionel Sambuc /*
43984d9c625SLionel Sambuc  * Press the pani^Wabort button!  Kernel resource allocation failed.
44084d9c625SLionel Sambuc  */
44184d9c625SLionel Sambuc static void
puffs_abortbutton(struct puffs_mount * pmp,int what,puffs_cookie_t dck,puffs_cookie_t ck,struct componentname * cnp)44284d9c625SLionel Sambuc puffs_abortbutton(struct puffs_mount *pmp, int what,
44384d9c625SLionel Sambuc 	puffs_cookie_t dck, puffs_cookie_t ck, struct componentname *cnp)
44484d9c625SLionel Sambuc {
44584d9c625SLionel Sambuc 
44684d9c625SLionel Sambuc 	switch (what) {
44784d9c625SLionel Sambuc 	case PUFFS_ABORT_CREATE:
44884d9c625SLionel Sambuc 	case PUFFS_ABORT_MKNOD:
44984d9c625SLionel Sambuc 	case PUFFS_ABORT_SYMLINK:
45084d9c625SLionel Sambuc 		callremove(pmp, dck, ck, cnp);
45184d9c625SLionel Sambuc 		break;
45284d9c625SLionel Sambuc 	case PUFFS_ABORT_MKDIR:
45384d9c625SLionel Sambuc 		callrmdir(pmp, dck, ck, cnp);
45484d9c625SLionel Sambuc 		break;
45584d9c625SLionel Sambuc 	}
45684d9c625SLionel Sambuc 
45784d9c625SLionel Sambuc 	callinactive(pmp, ck, 0);
45884d9c625SLionel Sambuc 	callreclaim(pmp, ck, 1);
45984d9c625SLionel Sambuc }
46084d9c625SLionel Sambuc 
46184d9c625SLionel Sambuc /*
46284d9c625SLionel Sambuc  * Begin vnode operations.
46384d9c625SLionel Sambuc  *
46484d9c625SLionel Sambuc  * A word from the keymaster about locks: generally we don't want
46584d9c625SLionel Sambuc  * to use the vnode locks at all: it creates an ugly dependency between
46684d9c625SLionel Sambuc  * the userlandia file server and the kernel.  But we'll play along with
46784d9c625SLionel Sambuc  * the kernel vnode locks for now.  However, even currently we attempt
46884d9c625SLionel Sambuc  * to release locks as early as possible.  This is possible for some
46984d9c625SLionel Sambuc  * operations which a) don't need a locked vnode after the userspace op
47084d9c625SLionel Sambuc  * and b) return with the vnode unlocked.  Theoretically we could
47184d9c625SLionel Sambuc  * unlock-do op-lock for others and order the graph in userspace, but I
47284d9c625SLionel Sambuc  * don't want to think of the consequences for the time being.
47384d9c625SLionel Sambuc  */
47484d9c625SLionel Sambuc 
47584d9c625SLionel Sambuc #define TTL_TO_TIMEOUT(ts) \
47684d9c625SLionel Sambuc     (hardclock_ticks + (ts->tv_sec * hz) + (ts->tv_nsec * hz / 1000000000))
47784d9c625SLionel Sambuc #define TTL_VALID(ts) \
47884d9c625SLionel Sambuc     ((ts != NULL) && !((ts->tv_sec == 0) && (ts->tv_nsec == 0)))
47984d9c625SLionel Sambuc #define TIMED_OUT(expire) \
48084d9c625SLionel Sambuc     ((int)((unsigned int)hardclock_ticks - (unsigned int)expire) > 0)
48184d9c625SLionel Sambuc int
puffs_vnop_lookup(void * v)48284d9c625SLionel Sambuc puffs_vnop_lookup(void *v)
48384d9c625SLionel Sambuc {
484*0a6a1f1dSLionel Sambuc         struct vop_lookup_v2_args /* {
48584d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
48684d9c625SLionel Sambuc 		struct vnode *a_dvp;
48784d9c625SLionel Sambuc 		struct vnode **a_vpp;
48884d9c625SLionel Sambuc 		struct componentname *a_cnp;
48984d9c625SLionel Sambuc         } */ *ap = v;
49084d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, lookup);
49184d9c625SLionel Sambuc 	struct puffs_mount *pmp;
49284d9c625SLionel Sambuc 	struct componentname *cnp;
49384d9c625SLionel Sambuc 	struct vnode *vp, *dvp, *cvp;
49484d9c625SLionel Sambuc 	struct puffs_node *dpn, *cpn;
49584d9c625SLionel Sambuc 	int isdot;
49684d9c625SLionel Sambuc 	int error;
49784d9c625SLionel Sambuc 
49884d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(ap->a_dvp->v_mount);
49984d9c625SLionel Sambuc 	cnp = ap->a_cnp;
50084d9c625SLionel Sambuc 	dvp = ap->a_dvp;
50184d9c625SLionel Sambuc 	cvp = NULL;
50284d9c625SLionel Sambuc 	cpn = NULL;
50384d9c625SLionel Sambuc 	*ap->a_vpp = NULL;
50484d9c625SLionel Sambuc 
50584d9c625SLionel Sambuc 	/* r/o fs?  we check create later to handle EEXIST */
50684d9c625SLionel Sambuc 	if ((cnp->cn_flags & ISLASTCN)
50784d9c625SLionel Sambuc 	    && (dvp->v_mount->mnt_flag & MNT_RDONLY)
50884d9c625SLionel Sambuc 	    && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
50984d9c625SLionel Sambuc 		return EROFS;
51084d9c625SLionel Sambuc 
51184d9c625SLionel Sambuc 	isdot = cnp->cn_namelen == 1 && *cnp->cn_nameptr == '.';
51284d9c625SLionel Sambuc 
51384d9c625SLionel Sambuc 	DPRINTF(("puffs_lookup: \"%s\", parent vnode %p, op: %x\n",
51484d9c625SLionel Sambuc 	    cnp->cn_nameptr, dvp, cnp->cn_nameiop));
51584d9c625SLionel Sambuc 
51684d9c625SLionel Sambuc 	/*
517*0a6a1f1dSLionel Sambuc 	 * If dotdot cache is enabled, add reference to .. and return.
51884d9c625SLionel Sambuc 	 */
51984d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) && (cnp->cn_flags & ISDOTDOT)) {
52084d9c625SLionel Sambuc 		vp = VPTOPP(ap->a_dvp)->pn_parent;
52184d9c625SLionel Sambuc 		vref(vp);
52284d9c625SLionel Sambuc 
52384d9c625SLionel Sambuc 		*ap->a_vpp = vp;
52484d9c625SLionel Sambuc 		return 0;
52584d9c625SLionel Sambuc 	}
52684d9c625SLionel Sambuc 
52784d9c625SLionel Sambuc 	/*
52884d9c625SLionel Sambuc 	 * Check if someone fed it into the cache
52984d9c625SLionel Sambuc 	 */
53084d9c625SLionel Sambuc 	if (!isdot && PUFFS_USE_NAMECACHE(pmp)) {
53184d9c625SLionel Sambuc 		int found, iswhiteout;
53284d9c625SLionel Sambuc 
53384d9c625SLionel Sambuc 		found = cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
53484d9c625SLionel Sambuc 				     cnp->cn_nameiop, cnp->cn_flags,
53584d9c625SLionel Sambuc 				     &iswhiteout, ap->a_vpp);
53684d9c625SLionel Sambuc 		if (iswhiteout) {
53784d9c625SLionel Sambuc 			cnp->cn_flags |= ISWHITEOUT;
53884d9c625SLionel Sambuc 		}
53984d9c625SLionel Sambuc 
54084d9c625SLionel Sambuc 		if (found && *ap->a_vpp != NULLVP && PUFFS_USE_FS_TTL(pmp)) {
54184d9c625SLionel Sambuc 			cvp = *ap->a_vpp;
54284d9c625SLionel Sambuc 			cpn = VPTOPP(cvp);
54384d9c625SLionel Sambuc 
54484d9c625SLionel Sambuc 			if (TIMED_OUT(cpn->pn_cn_timeout)) {
54584d9c625SLionel Sambuc 				cache_purge(cvp);
54684d9c625SLionel Sambuc 				/*
547*0a6a1f1dSLionel Sambuc 				 * cached vnode (cvp) is still referenced
54884d9c625SLionel Sambuc 				 * so that we can reuse it upon a new
54984d9c625SLionel Sambuc 				 * successful lookup.
55084d9c625SLionel Sambuc 				 */
55184d9c625SLionel Sambuc 				*ap->a_vpp = NULL;
55284d9c625SLionel Sambuc 				found = 0;
55384d9c625SLionel Sambuc 			}
55484d9c625SLionel Sambuc 		}
55584d9c625SLionel Sambuc 
55684d9c625SLionel Sambuc 		/*
55784d9c625SLionel Sambuc 		 * Do not use negative caching, since the filesystem
55884d9c625SLionel Sambuc 		 * provides no TTL for it.
55984d9c625SLionel Sambuc 		 */
56084d9c625SLionel Sambuc 		if (found && *ap->a_vpp == NULLVP && PUFFS_USE_FS_TTL(pmp))
56184d9c625SLionel Sambuc 			found = 0;
56284d9c625SLionel Sambuc 
56384d9c625SLionel Sambuc 		if (found) {
56484d9c625SLionel Sambuc 			return *ap->a_vpp == NULLVP ? ENOENT : 0;
56584d9c625SLionel Sambuc 		}
56684d9c625SLionel Sambuc 
56784d9c625SLionel Sambuc 		/*
56884d9c625SLionel Sambuc 		 * This is what would have been left in ERROR before
56984d9c625SLionel Sambuc 		 * the rearrangement of cache_lookup(). What with all
57084d9c625SLionel Sambuc 		 * the macros, I am not sure if this is a dead value
57184d9c625SLionel Sambuc 		 * below or not.
57284d9c625SLionel Sambuc 		 */
57384d9c625SLionel Sambuc 		error = -1;
57484d9c625SLionel Sambuc 	}
57584d9c625SLionel Sambuc 
57684d9c625SLionel Sambuc 	if (isdot) {
57784d9c625SLionel Sambuc 		/* deal with rename lookup semantics */
57884d9c625SLionel Sambuc 		if (cnp->cn_nameiop == RENAME && (cnp->cn_flags & ISLASTCN))
57984d9c625SLionel Sambuc 			return EISDIR;
58084d9c625SLionel Sambuc 
58184d9c625SLionel Sambuc 		vp = ap->a_dvp;
58284d9c625SLionel Sambuc 		vref(vp);
58384d9c625SLionel Sambuc 		*ap->a_vpp = vp;
58484d9c625SLionel Sambuc 		return 0;
58584d9c625SLionel Sambuc 	}
58684d9c625SLionel Sambuc 
587*0a6a1f1dSLionel Sambuc 	if (cvp != NULL) {
588*0a6a1f1dSLionel Sambuc 		if (vn_lock(cvp, LK_EXCLUSIVE) != 0) {
589*0a6a1f1dSLionel Sambuc 			vrele(cvp);
590*0a6a1f1dSLionel Sambuc 			cvp = NULL;
591*0a6a1f1dSLionel Sambuc 		} else
59284d9c625SLionel Sambuc 			mutex_enter(&cpn->pn_sizemtx);
593*0a6a1f1dSLionel Sambuc 	}
59484d9c625SLionel Sambuc 
59584d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, lookup);
59684d9c625SLionel Sambuc 	puffs_makecn(&lookup_msg->pvnr_cn, &lookup_msg->pvnr_cn_cred,
59784d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
59884d9c625SLionel Sambuc 
59984d9c625SLionel Sambuc 	if (cnp->cn_flags & ISDOTDOT)
60084d9c625SLionel Sambuc 		VOP_UNLOCK(dvp);
60184d9c625SLionel Sambuc 
60284d9c625SLionel Sambuc 	puffs_msg_setinfo(park_lookup, PUFFSOP_VN,
60384d9c625SLionel Sambuc 	    PUFFS_VN_LOOKUP, VPTOPNC(dvp));
60484d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_lookup, dvp->v_data, NULL, error);
60584d9c625SLionel Sambuc 	DPRINTF(("puffs_lookup: return of the userspace, part %d\n", error));
60684d9c625SLionel Sambuc 
60784d9c625SLionel Sambuc 	/*
60884d9c625SLionel Sambuc 	 * In case of error, there is no new vnode to play with, so be
60984d9c625SLionel Sambuc 	 * happy with the NULL value given to vpp in the beginning.
61084d9c625SLionel Sambuc 	 * Also, check if this really was an error or the target was not
61184d9c625SLionel Sambuc 	 * present.  Either treat it as a non-error for CREATE/RENAME or
61284d9c625SLionel Sambuc 	 * enter the component into the negative name cache (if desired).
61384d9c625SLionel Sambuc 	 */
61484d9c625SLionel Sambuc 	if (error) {
61584d9c625SLionel Sambuc 		error = checkerr(pmp, error, __func__);
61684d9c625SLionel Sambuc 		if (error == ENOENT) {
61784d9c625SLionel Sambuc 			/* don't allow to create files on r/o fs */
61884d9c625SLionel Sambuc 			if ((dvp->v_mount->mnt_flag & MNT_RDONLY)
61984d9c625SLionel Sambuc 			    && cnp->cn_nameiop == CREATE) {
62084d9c625SLionel Sambuc 				error = EROFS;
62184d9c625SLionel Sambuc 
62284d9c625SLionel Sambuc 			/* adjust values if we are creating */
62384d9c625SLionel Sambuc 			} else if ((cnp->cn_flags & ISLASTCN)
62484d9c625SLionel Sambuc 			    && (cnp->cn_nameiop == CREATE
62584d9c625SLionel Sambuc 			      || cnp->cn_nameiop == RENAME)) {
62684d9c625SLionel Sambuc 				error = EJUSTRETURN;
62784d9c625SLionel Sambuc 
62884d9c625SLionel Sambuc 			/* save negative cache entry */
62984d9c625SLionel Sambuc 			} else {
63084d9c625SLionel Sambuc 				if (PUFFS_USE_NAMECACHE(pmp) &&
63184d9c625SLionel Sambuc 				    !PUFFS_USE_FS_TTL(pmp))
63284d9c625SLionel Sambuc 					cache_enter(dvp, NULL, cnp->cn_nameptr,
63384d9c625SLionel Sambuc 						cnp->cn_namelen, cnp->cn_flags);
63484d9c625SLionel Sambuc 			}
63584d9c625SLionel Sambuc 		}
63684d9c625SLionel Sambuc 		goto out;
63784d9c625SLionel Sambuc 	}
63884d9c625SLionel Sambuc 
63984d9c625SLionel Sambuc 	/*
64084d9c625SLionel Sambuc 	 * Check that we don't get our parent node back, that would cause
64184d9c625SLionel Sambuc 	 * a pretty obvious deadlock.
64284d9c625SLionel Sambuc 	 */
64384d9c625SLionel Sambuc 	dpn = dvp->v_data;
64484d9c625SLionel Sambuc 	if (lookup_msg->pvnr_newnode == dpn->pn_cookie) {
64584d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_LOOKUP, EINVAL,
64684d9c625SLionel Sambuc 		    "lookup produced parent cookie", lookup_msg->pvnr_newnode);
64784d9c625SLionel Sambuc 		error = EPROTO;
64884d9c625SLionel Sambuc 		goto out;
64984d9c625SLionel Sambuc 	}
65084d9c625SLionel Sambuc 
65184d9c625SLionel Sambuc 	/*
65284d9c625SLionel Sambuc 	 * Check if we looked up the cached vnode
65384d9c625SLionel Sambuc 	 */
65484d9c625SLionel Sambuc 	vp = NULL;
65584d9c625SLionel Sambuc 	if (cvp && (VPTOPP(cvp)->pn_cookie == lookup_msg->pvnr_newnode)) {
65684d9c625SLionel Sambuc 		int grace;
65784d9c625SLionel Sambuc 
65884d9c625SLionel Sambuc 		/*
65984d9c625SLionel Sambuc 		 * Bump grace time of this node so that it does not get
66084d9c625SLionel Sambuc 		 * reclaimed too fast. We try to increase a bit more the
66184d9c625SLionel Sambuc 		 * lifetime of busiest * nodes - with some limits.
66284d9c625SLionel Sambuc 		 */
66384d9c625SLionel Sambuc 		grace = 10 * puffs_sopreq_expire_timeout;
66484d9c625SLionel Sambuc 		cpn->pn_cn_grace = hardclock_ticks + grace;
66584d9c625SLionel Sambuc 		vp = cvp;
66684d9c625SLionel Sambuc 	}
66784d9c625SLionel Sambuc 
66884d9c625SLionel Sambuc 	/*
66984d9c625SLionel Sambuc 	 * No cached vnode available, or the cached vnode does not
67084d9c625SLionel Sambuc 	 * match the userland cookie anymore: is the node known?
67184d9c625SLionel Sambuc 	 */
67284d9c625SLionel Sambuc 	if (vp == NULL) {
67384d9c625SLionel Sambuc 		error = puffs_getvnode(dvp->v_mount,
67484d9c625SLionel Sambuc 		    lookup_msg->pvnr_newnode, lookup_msg->pvnr_vtype,
67584d9c625SLionel Sambuc 		    lookup_msg->pvnr_size, lookup_msg->pvnr_rdev, &vp);
67684d9c625SLionel Sambuc 		if (error) {
67784d9c625SLionel Sambuc 			puffs_abortbutton(pmp, PUFFS_ABORT_LOOKUP,
67884d9c625SLionel Sambuc 			    VPTOPNC(dvp), lookup_msg->pvnr_newnode,
67984d9c625SLionel Sambuc 			    ap->a_cnp);
68084d9c625SLionel Sambuc 			goto out;
68184d9c625SLionel Sambuc 		}
68284d9c625SLionel Sambuc 
68384d9c625SLionel Sambuc 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
68484d9c625SLionel Sambuc 	}
68584d9c625SLionel Sambuc 
68684d9c625SLionel Sambuc 	/*
68784d9c625SLionel Sambuc 	 * Update cache and TTL
68884d9c625SLionel Sambuc 	 */
68984d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
69084d9c625SLionel Sambuc 		struct timespec *va_ttl = &lookup_msg->pvnr_va_ttl;
69184d9c625SLionel Sambuc 		struct timespec *cn_ttl = &lookup_msg->pvnr_cn_ttl;
69284d9c625SLionel Sambuc 		update_va(vp, NULL, &lookup_msg->pvnr_va,
69384d9c625SLionel Sambuc 			  va_ttl, cn_ttl, SETATTR_CHSIZE);
69484d9c625SLionel Sambuc 	}
69584d9c625SLionel Sambuc 
69684d9c625SLionel Sambuc 	KASSERT(lookup_msg->pvnr_newnode == VPTOPP(vp)->pn_cookie);
69784d9c625SLionel Sambuc 	*ap->a_vpp = vp;
69884d9c625SLionel Sambuc 
69984d9c625SLionel Sambuc 	if (PUFFS_USE_NAMECACHE(pmp))
70084d9c625SLionel Sambuc 		cache_enter(dvp, vp, cnp->cn_nameptr, cnp->cn_namelen,
70184d9c625SLionel Sambuc 			    cnp->cn_flags);
70284d9c625SLionel Sambuc 
70384d9c625SLionel Sambuc 	/* XXX */
70484d9c625SLionel Sambuc 	if ((lookup_msg->pvnr_cn.pkcn_flags & REQUIREDIR) == 0)
70584d9c625SLionel Sambuc 		cnp->cn_flags &= ~REQUIREDIR;
70684d9c625SLionel Sambuc 	if (lookup_msg->pvnr_cn.pkcn_consume)
70784d9c625SLionel Sambuc 		cnp->cn_consume = MIN(lookup_msg->pvnr_cn.pkcn_consume,
70884d9c625SLionel Sambuc 		    strlen(cnp->cn_nameptr) - cnp->cn_namelen);
70984d9c625SLionel Sambuc 
71084d9c625SLionel Sambuc 	VPTOPP(vp)->pn_nlookup++;
71184d9c625SLionel Sambuc 
71284d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) &&
71384d9c625SLionel Sambuc 	    (VPTOPP(vp)->pn_parent != dvp))
71484d9c625SLionel Sambuc 		update_parent(vp, dvp);
71584d9c625SLionel Sambuc 
71684d9c625SLionel Sambuc  out:
71784d9c625SLionel Sambuc 	if (cvp != NULL) {
71884d9c625SLionel Sambuc 		mutex_exit(&cpn->pn_sizemtx);
71984d9c625SLionel Sambuc 
72084d9c625SLionel Sambuc 		if (error || (cvp != vp))
72184d9c625SLionel Sambuc 			vput(cvp);
72284d9c625SLionel Sambuc 	}
723*0a6a1f1dSLionel Sambuc 	if (error == 0)
724*0a6a1f1dSLionel Sambuc 		VOP_UNLOCK(*ap->a_vpp);
72584d9c625SLionel Sambuc 
72684d9c625SLionel Sambuc 	if (cnp->cn_flags & ISDOTDOT)
72784d9c625SLionel Sambuc 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
72884d9c625SLionel Sambuc 
72984d9c625SLionel Sambuc 	DPRINTF(("puffs_lookup: returning %d %p\n", error, *ap->a_vpp));
73084d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(lookup);
73184d9c625SLionel Sambuc 	return error;
73284d9c625SLionel Sambuc }
73384d9c625SLionel Sambuc 
73484d9c625SLionel Sambuc #define REFPN_AND_UNLOCKVP(a, b)					\
73584d9c625SLionel Sambuc do {									\
73684d9c625SLionel Sambuc 	mutex_enter(&b->pn_mtx);					\
73784d9c625SLionel Sambuc 	puffs_referencenode(b);						\
73884d9c625SLionel Sambuc 	mutex_exit(&b->pn_mtx);						\
73984d9c625SLionel Sambuc 	VOP_UNLOCK(a);						\
74084d9c625SLionel Sambuc } while (/*CONSTCOND*/0)
74184d9c625SLionel Sambuc 
74284d9c625SLionel Sambuc #define REFPN(b)							\
74384d9c625SLionel Sambuc do {									\
74484d9c625SLionel Sambuc 	mutex_enter(&b->pn_mtx);					\
74584d9c625SLionel Sambuc 	puffs_referencenode(b);						\
74684d9c625SLionel Sambuc 	mutex_exit(&b->pn_mtx);						\
74784d9c625SLionel Sambuc } while (/*CONSTCOND*/0)
74884d9c625SLionel Sambuc 
74984d9c625SLionel Sambuc #define RELEPN_AND_VP(a, b)						\
75084d9c625SLionel Sambuc do {									\
75184d9c625SLionel Sambuc 	puffs_releasenode(b);						\
75284d9c625SLionel Sambuc 	vrele(a);							\
75384d9c625SLionel Sambuc } while (/*CONSTCOND*/0)
75484d9c625SLionel Sambuc 
75584d9c625SLionel Sambuc int
puffs_vnop_create(void * v)75684d9c625SLionel Sambuc puffs_vnop_create(void *v)
75784d9c625SLionel Sambuc {
758*0a6a1f1dSLionel Sambuc 	struct vop_create_v3_args /* {
75984d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
76084d9c625SLionel Sambuc 		struct vnode *a_dvp;
76184d9c625SLionel Sambuc 		struct vnode **a_vpp;
76284d9c625SLionel Sambuc 		struct componentname *a_cnp;
76384d9c625SLionel Sambuc 		struct vattr *a_vap;
76484d9c625SLionel Sambuc 	} */ *ap = v;
76584d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, create);
76684d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
76784d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
76884d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
76984d9c625SLionel Sambuc 	struct mount *mp = dvp->v_mount;
77084d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
77184d9c625SLionel Sambuc 	int error;
77284d9c625SLionel Sambuc 
77384d9c625SLionel Sambuc 	DPRINTF(("puffs_create: dvp %p, cnp: %s\n",
77484d9c625SLionel Sambuc 	    dvp, ap->a_cnp->cn_nameptr));
77584d9c625SLionel Sambuc 
77684d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, create);
77784d9c625SLionel Sambuc 	puffs_makecn(&create_msg->pvnr_cn, &create_msg->pvnr_cn_cred,
77884d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
77984d9c625SLionel Sambuc 	create_msg->pvnr_va = *ap->a_vap;
78084d9c625SLionel Sambuc 	puffs_msg_setinfo(park_create, PUFFSOP_VN,
78184d9c625SLionel Sambuc 	    PUFFS_VN_CREATE, VPTOPNC(dvp));
78284d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_create, dvp->v_data, NULL, error);
78384d9c625SLionel Sambuc 
78484d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
78584d9c625SLionel Sambuc 	if (error)
78684d9c625SLionel Sambuc 		goto out;
78784d9c625SLionel Sambuc 
78884d9c625SLionel Sambuc 	error = puffs_newnode(mp, dvp, ap->a_vpp,
78984d9c625SLionel Sambuc 	    create_msg->pvnr_newnode, cnp, ap->a_vap->va_type, 0);
79084d9c625SLionel Sambuc 	if (error) {
79184d9c625SLionel Sambuc 		puffs_abortbutton(pmp, PUFFS_ABORT_CREATE, dpn->pn_cookie,
79284d9c625SLionel Sambuc 		    create_msg->pvnr_newnode, cnp);
79384d9c625SLionel Sambuc 		goto out;
79484d9c625SLionel Sambuc 	}
79584d9c625SLionel Sambuc 
79684d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
79784d9c625SLionel Sambuc 		struct timespec *va_ttl = &create_msg->pvnr_va_ttl;
79884d9c625SLionel Sambuc 		struct timespec *cn_ttl = &create_msg->pvnr_cn_ttl;
79984d9c625SLionel Sambuc 		struct vattr *rvap = &create_msg->pvnr_va;
80084d9c625SLionel Sambuc 
80184d9c625SLionel Sambuc 		update_va(*ap->a_vpp, NULL, rvap,
80284d9c625SLionel Sambuc 			  va_ttl, cn_ttl, SETATTR_CHSIZE);
80384d9c625SLionel Sambuc 	}
80484d9c625SLionel Sambuc 
80584d9c625SLionel Sambuc 	VPTOPP(*ap->a_vpp)->pn_nlookup++;
80684d9c625SLionel Sambuc 
80784d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) &&
80884d9c625SLionel Sambuc 	    (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
80984d9c625SLionel Sambuc 		update_parent(*ap->a_vpp, dvp);
81084d9c625SLionel Sambuc 
81184d9c625SLionel Sambuc  out:
81284d9c625SLionel Sambuc 	DPRINTF(("puffs_create: return %d\n", error));
81384d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(create);
81484d9c625SLionel Sambuc 	return error;
81584d9c625SLionel Sambuc }
81684d9c625SLionel Sambuc 
81784d9c625SLionel Sambuc int
puffs_vnop_mknod(void * v)81884d9c625SLionel Sambuc puffs_vnop_mknod(void *v)
81984d9c625SLionel Sambuc {
820*0a6a1f1dSLionel Sambuc 	struct vop_mknod_v3_args /* {
82184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
82284d9c625SLionel Sambuc 		struct vnode *a_dvp;
82384d9c625SLionel Sambuc 		struct vnode **a_vpp;
82484d9c625SLionel Sambuc 		struct componentname *a_cnp;
82584d9c625SLionel Sambuc 		struct vattr *a_vap;
82684d9c625SLionel Sambuc 	} */ *ap = v;
82784d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, mknod);
82884d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
82984d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
83084d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
83184d9c625SLionel Sambuc 	struct mount *mp = dvp->v_mount;
83284d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
83384d9c625SLionel Sambuc 	int error;
83484d9c625SLionel Sambuc 
83584d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, mknod);
83684d9c625SLionel Sambuc 	puffs_makecn(&mknod_msg->pvnr_cn, &mknod_msg->pvnr_cn_cred,
83784d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
83884d9c625SLionel Sambuc 	mknod_msg->pvnr_va = *ap->a_vap;
83984d9c625SLionel Sambuc 	puffs_msg_setinfo(park_mknod, PUFFSOP_VN,
84084d9c625SLionel Sambuc 	    PUFFS_VN_MKNOD, VPTOPNC(dvp));
84184d9c625SLionel Sambuc 
84284d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mknod, dvp->v_data, NULL, error);
84384d9c625SLionel Sambuc 
84484d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
84584d9c625SLionel Sambuc 	if (error)
84684d9c625SLionel Sambuc 		goto out;
84784d9c625SLionel Sambuc 
84884d9c625SLionel Sambuc 	error = puffs_newnode(mp, dvp, ap->a_vpp,
84984d9c625SLionel Sambuc 	    mknod_msg->pvnr_newnode, cnp, ap->a_vap->va_type,
85084d9c625SLionel Sambuc 	    ap->a_vap->va_rdev);
85184d9c625SLionel Sambuc 	if (error) {
85284d9c625SLionel Sambuc 		puffs_abortbutton(pmp, PUFFS_ABORT_MKNOD, dpn->pn_cookie,
85384d9c625SLionel Sambuc 		    mknod_msg->pvnr_newnode, cnp);
85484d9c625SLionel Sambuc 		goto out;
85584d9c625SLionel Sambuc 	}
85684d9c625SLionel Sambuc 
85784d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
85884d9c625SLionel Sambuc 		struct timespec *va_ttl = &mknod_msg->pvnr_va_ttl;
85984d9c625SLionel Sambuc 		struct timespec *cn_ttl = &mknod_msg->pvnr_cn_ttl;
86084d9c625SLionel Sambuc 		struct vattr *rvap = &mknod_msg->pvnr_va;
86184d9c625SLionel Sambuc 
86284d9c625SLionel Sambuc 		update_va(*ap->a_vpp, NULL, rvap,
86384d9c625SLionel Sambuc 			   va_ttl, cn_ttl, SETATTR_CHSIZE);
86484d9c625SLionel Sambuc 	}
86584d9c625SLionel Sambuc 
86684d9c625SLionel Sambuc 	VPTOPP(*ap->a_vpp)->pn_nlookup++;
86784d9c625SLionel Sambuc 
86884d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) &&
86984d9c625SLionel Sambuc 	    (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
87084d9c625SLionel Sambuc 		update_parent(*ap->a_vpp, dvp);
87184d9c625SLionel Sambuc 
87284d9c625SLionel Sambuc  out:
87384d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(mknod);
87484d9c625SLionel Sambuc 	return error;
87584d9c625SLionel Sambuc }
87684d9c625SLionel Sambuc 
87784d9c625SLionel Sambuc int
puffs_vnop_open(void * v)87884d9c625SLionel Sambuc puffs_vnop_open(void *v)
87984d9c625SLionel Sambuc {
88084d9c625SLionel Sambuc 	struct vop_open_args /* {
88184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
88284d9c625SLionel Sambuc 		struct vnode *a_vp;
88384d9c625SLionel Sambuc 		int a_mode;
88484d9c625SLionel Sambuc 		kauth_cred_t a_cred;
88584d9c625SLionel Sambuc 	} */ *ap = v;
88684d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, open);
88784d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
88884d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
889*0a6a1f1dSLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
89084d9c625SLionel Sambuc 	int mode = ap->a_mode;
89184d9c625SLionel Sambuc 	int error;
89284d9c625SLionel Sambuc 
89384d9c625SLionel Sambuc 	DPRINTF(("puffs_open: vp %p, mode 0x%x\n", vp, mode));
89484d9c625SLionel Sambuc 
89584d9c625SLionel Sambuc 	if (vp->v_type == VREG && mode & FWRITE && !EXISTSOP(pmp, WRITE))
89684d9c625SLionel Sambuc 		ERROUT(EROFS);
89784d9c625SLionel Sambuc 
89884d9c625SLionel Sambuc 	if (!EXISTSOP(pmp, OPEN))
89984d9c625SLionel Sambuc 		ERROUT(0);
90084d9c625SLionel Sambuc 
90184d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, open);
90284d9c625SLionel Sambuc 	open_msg->pvnr_mode = mode;
90384d9c625SLionel Sambuc 	puffs_credcvt(&open_msg->pvnr_cred, ap->a_cred);
90484d9c625SLionel Sambuc 	puffs_msg_setinfo(park_open, PUFFSOP_VN,
90584d9c625SLionel Sambuc 	    PUFFS_VN_OPEN, VPTOPNC(vp));
90684d9c625SLionel Sambuc 
90784d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_open, vp->v_data, NULL, error);
90884d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
90984d9c625SLionel Sambuc 
910*0a6a1f1dSLionel Sambuc 	if (open_msg->pvnr_oflags & PUFFS_OPEN_IO_DIRECT) {
911*0a6a1f1dSLionel Sambuc 		/*
912*0a6a1f1dSLionel Sambuc 		 * Flush cache:
913*0a6a1f1dSLionel Sambuc 		 * - we do not want to discard cached write by direct write
914*0a6a1f1dSLionel Sambuc 		 * - read cache is now useless and should be freed
915*0a6a1f1dSLionel Sambuc 		 */
916*0a6a1f1dSLionel Sambuc 		flushvncache(vp, 0, 0, true);
917*0a6a1f1dSLionel Sambuc 		if (mode & FREAD)
918*0a6a1f1dSLionel Sambuc 			pn->pn_stat |= PNODE_RDIRECT;
919*0a6a1f1dSLionel Sambuc 		if (mode & FWRITE)
920*0a6a1f1dSLionel Sambuc 			pn->pn_stat |= PNODE_WDIRECT;
921*0a6a1f1dSLionel Sambuc 	}
92284d9c625SLionel Sambuc  out:
92384d9c625SLionel Sambuc 	DPRINTF(("puffs_open: returning %d\n", error));
92484d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(open);
92584d9c625SLionel Sambuc 	return error;
92684d9c625SLionel Sambuc }
92784d9c625SLionel Sambuc 
92884d9c625SLionel Sambuc int
puffs_vnop_close(void * v)92984d9c625SLionel Sambuc puffs_vnop_close(void *v)
93084d9c625SLionel Sambuc {
93184d9c625SLionel Sambuc 	struct vop_close_args /* {
93284d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
93384d9c625SLionel Sambuc 		struct vnode *a_vp;
93484d9c625SLionel Sambuc 		int a_fflag;
93584d9c625SLionel Sambuc 		kauth_cred_t a_cred;
93684d9c625SLionel Sambuc 	} */ *ap = v;
93784d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, close);
93884d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
93984d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
94084d9c625SLionel Sambuc 
94184d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, close);
94284d9c625SLionel Sambuc 	puffs_msg_setfaf(park_close);
94384d9c625SLionel Sambuc 	close_msg->pvnr_fflag = ap->a_fflag;
94484d9c625SLionel Sambuc 	puffs_credcvt(&close_msg->pvnr_cred, ap->a_cred);
94584d9c625SLionel Sambuc 	puffs_msg_setinfo(park_close, PUFFSOP_VN,
94684d9c625SLionel Sambuc 	    PUFFS_VN_CLOSE, VPTOPNC(vp));
94784d9c625SLionel Sambuc 
94884d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_close);
94984d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(close);
95084d9c625SLionel Sambuc 	return 0;
95184d9c625SLionel Sambuc }
95284d9c625SLionel Sambuc 
95384d9c625SLionel Sambuc int
puffs_vnop_access(void * v)95484d9c625SLionel Sambuc puffs_vnop_access(void *v)
95584d9c625SLionel Sambuc {
95684d9c625SLionel Sambuc 	struct vop_access_args /* {
95784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
95884d9c625SLionel Sambuc 		struct vnode *a_vp;
95984d9c625SLionel Sambuc 		int a_mode;
96084d9c625SLionel Sambuc 		kauth_cred_t a_cred;
96184d9c625SLionel Sambuc 	} */ *ap = v;
96284d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, access);
96384d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
96484d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
96584d9c625SLionel Sambuc 	int mode = ap->a_mode;
96684d9c625SLionel Sambuc 	int error;
96784d9c625SLionel Sambuc 
96884d9c625SLionel Sambuc 	if (mode & VWRITE) {
96984d9c625SLionel Sambuc 		switch (vp->v_type) {
97084d9c625SLionel Sambuc 		case VDIR:
97184d9c625SLionel Sambuc 		case VLNK:
97284d9c625SLionel Sambuc 		case VREG:
97384d9c625SLionel Sambuc 			if ((vp->v_mount->mnt_flag & MNT_RDONLY)
97484d9c625SLionel Sambuc 			    || !EXISTSOP(pmp, WRITE))
97584d9c625SLionel Sambuc 				return EROFS;
97684d9c625SLionel Sambuc 			break;
97784d9c625SLionel Sambuc 		default:
97884d9c625SLionel Sambuc 			break;
97984d9c625SLionel Sambuc 		}
98084d9c625SLionel Sambuc 	}
98184d9c625SLionel Sambuc 
98284d9c625SLionel Sambuc 	if (!EXISTSOP(pmp, ACCESS))
98384d9c625SLionel Sambuc 		return 0;
98484d9c625SLionel Sambuc 
98584d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, access);
98684d9c625SLionel Sambuc 	access_msg->pvnr_mode = ap->a_mode;
98784d9c625SLionel Sambuc 	puffs_credcvt(&access_msg->pvnr_cred, ap->a_cred);
98884d9c625SLionel Sambuc 	puffs_msg_setinfo(park_access, PUFFSOP_VN,
98984d9c625SLionel Sambuc 	    PUFFS_VN_ACCESS, VPTOPNC(vp));
99084d9c625SLionel Sambuc 
99184d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_access, vp->v_data, NULL, error);
99284d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
99384d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(access);
99484d9c625SLionel Sambuc 
99584d9c625SLionel Sambuc 	return error;
99684d9c625SLionel Sambuc }
99784d9c625SLionel Sambuc 
99884d9c625SLionel Sambuc static void
update_va(struct vnode * vp,struct vattr * vap,struct vattr * rvap,struct timespec * va_ttl,struct timespec * cn_ttl,int flags)99984d9c625SLionel Sambuc update_va(struct vnode *vp, struct vattr *vap, struct vattr *rvap,
100084d9c625SLionel Sambuc 	  struct timespec *va_ttl, struct timespec *cn_ttl, int flags)
100184d9c625SLionel Sambuc {
100284d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
1003*0a6a1f1dSLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1004*0a6a1f1dSLionel Sambuc 	int use_metacache;
100584d9c625SLionel Sambuc 
100684d9c625SLionel Sambuc 	if (TTL_VALID(cn_ttl)) {
100784d9c625SLionel Sambuc 		pn->pn_cn_timeout = TTL_TO_TIMEOUT(cn_ttl);
100884d9c625SLionel Sambuc 		pn->pn_cn_grace = MAX(pn->pn_cn_timeout, pn->pn_cn_grace);
100984d9c625SLionel Sambuc 	}
101084d9c625SLionel Sambuc 
101184d9c625SLionel Sambuc 	/*
101284d9c625SLionel Sambuc 	 * Don't listen to the file server regarding special device
101384d9c625SLionel Sambuc 	 * size info, the file server doesn't know anything about them.
101484d9c625SLionel Sambuc 	 */
101584d9c625SLionel Sambuc 	if (vp->v_type == VBLK || vp->v_type == VCHR)
101684d9c625SLionel Sambuc 		rvap->va_size = vp->v_size;
101784d9c625SLionel Sambuc 
101884d9c625SLionel Sambuc 	/* Ditto for blocksize (ufs comment: this doesn't belong here) */
101984d9c625SLionel Sambuc 	if (vp->v_type == VBLK)
102084d9c625SLionel Sambuc 		rvap->va_blocksize = BLKDEV_IOSIZE;
102184d9c625SLionel Sambuc 	else if (vp->v_type == VCHR)
102284d9c625SLionel Sambuc 		rvap->va_blocksize = MAXBSIZE;
102384d9c625SLionel Sambuc 
102484d9c625SLionel Sambuc 	if (vap != NULL) {
102584d9c625SLionel Sambuc 		(void) memcpy(vap, rvap, sizeof(struct vattr));
102684d9c625SLionel Sambuc 		vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
102784d9c625SLionel Sambuc 
1028*0a6a1f1dSLionel Sambuc 		if (PUFFS_USE_METAFLUSH(pmp)) {
102984d9c625SLionel Sambuc 			if (pn->pn_stat & PNODE_METACACHE_ATIME)
103084d9c625SLionel Sambuc 				vap->va_atime = pn->pn_mc_atime;
103184d9c625SLionel Sambuc 			if (pn->pn_stat & PNODE_METACACHE_CTIME)
103284d9c625SLionel Sambuc 				vap->va_ctime = pn->pn_mc_ctime;
103384d9c625SLionel Sambuc 			if (pn->pn_stat & PNODE_METACACHE_MTIME)
103484d9c625SLionel Sambuc 				vap->va_mtime = pn->pn_mc_mtime;
103584d9c625SLionel Sambuc 			if (pn->pn_stat & PNODE_METACACHE_SIZE)
103684d9c625SLionel Sambuc 				vap->va_size = pn->pn_mc_size;
103784d9c625SLionel Sambuc 		}
1038*0a6a1f1dSLionel Sambuc 	}
103984d9c625SLionel Sambuc 
1040*0a6a1f1dSLionel Sambuc 	use_metacache = PUFFS_USE_METAFLUSH(pmp) &&
1041*0a6a1f1dSLionel Sambuc 			(pn->pn_stat & PNODE_METACACHE_SIZE);
1042*0a6a1f1dSLionel Sambuc 	if (!use_metacache && (flags & SETATTR_CHSIZE)) {
104384d9c625SLionel Sambuc 		if (rvap->va_size != VNOVAL
104484d9c625SLionel Sambuc 		    && vp->v_type != VBLK && vp->v_type != VCHR) {
104584d9c625SLionel Sambuc 			uvm_vnp_setsize(vp, rvap->va_size);
104684d9c625SLionel Sambuc 			pn->pn_serversize = rvap->va_size;
104784d9c625SLionel Sambuc 		}
104884d9c625SLionel Sambuc 	}
104984d9c625SLionel Sambuc 
105084d9c625SLionel Sambuc 	if ((va_ttl != NULL) && TTL_VALID(va_ttl)) {
105184d9c625SLionel Sambuc 		if (pn->pn_va_cache == NULL)
105284d9c625SLionel Sambuc 			pn->pn_va_cache = pool_get(&puffs_vapool, PR_WAITOK);
105384d9c625SLionel Sambuc 
105484d9c625SLionel Sambuc 		(void)memcpy(pn->pn_va_cache, rvap, sizeof(*rvap));
105584d9c625SLionel Sambuc 
105684d9c625SLionel Sambuc 		pn->pn_va_timeout = TTL_TO_TIMEOUT(va_ttl);
105784d9c625SLionel Sambuc 	}
105884d9c625SLionel Sambuc }
105984d9c625SLionel Sambuc 
106084d9c625SLionel Sambuc static void
update_parent(struct vnode * vp,struct vnode * dvp)106184d9c625SLionel Sambuc update_parent(struct vnode *vp, struct vnode *dvp)
106284d9c625SLionel Sambuc {
106384d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
106484d9c625SLionel Sambuc 
106584d9c625SLionel Sambuc 	if (pn->pn_parent != NULL) {
106684d9c625SLionel Sambuc 		KASSERT(pn->pn_parent != dvp);
106784d9c625SLionel Sambuc 		vrele(pn->pn_parent);
106884d9c625SLionel Sambuc 	}
106984d9c625SLionel Sambuc 
107084d9c625SLionel Sambuc 	vref(dvp);
107184d9c625SLionel Sambuc 	pn->pn_parent = dvp;
107284d9c625SLionel Sambuc }
107384d9c625SLionel Sambuc 
107484d9c625SLionel Sambuc int
puffs_vnop_getattr(void * v)107584d9c625SLionel Sambuc puffs_vnop_getattr(void *v)
107684d9c625SLionel Sambuc {
107784d9c625SLionel Sambuc 	struct vop_getattr_args /* {
107884d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
107984d9c625SLionel Sambuc 		struct vnode *a_vp;
108084d9c625SLionel Sambuc 		struct vattr *a_vap;
108184d9c625SLionel Sambuc 		kauth_cred_t a_cred;
108284d9c625SLionel Sambuc 	} */ *ap = v;
108384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, getattr);
108484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
108584d9c625SLionel Sambuc 	struct mount *mp = vp->v_mount;
108684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
108784d9c625SLionel Sambuc 	struct vattr *vap, *rvap;
108884d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
108984d9c625SLionel Sambuc 	struct timespec *va_ttl = NULL;
109084d9c625SLionel Sambuc 	int error = 0;
109184d9c625SLionel Sambuc 
109284d9c625SLionel Sambuc 	/*
109384d9c625SLionel Sambuc 	 * A lock is required so that we do not race with
109484d9c625SLionel Sambuc 	 * setattr, write and fsync when changing vp->v_size.
109584d9c625SLionel Sambuc 	 * This is critical, since setting a stall smaler value
109684d9c625SLionel Sambuc 	 * triggers a file truncate in uvm_vnp_setsize(), which
109784d9c625SLionel Sambuc 	 * most of the time means data corruption (a chunk of
109884d9c625SLionel Sambuc 	 * data is replaced by zeroes). This can be removed if
109984d9c625SLionel Sambuc 	 * we decide one day that VOP_GETATTR must operate on
110084d9c625SLionel Sambuc 	 * a locked vnode.
110184d9c625SLionel Sambuc 	 *
110284d9c625SLionel Sambuc 	 * XXX Should be useless now that VOP_GETATTR has been
110384d9c625SLionel Sambuc 	 *     fixed to always require a shared lock at least.
110484d9c625SLionel Sambuc 	 */
110584d9c625SLionel Sambuc 	mutex_enter(&pn->pn_sizemtx);
110684d9c625SLionel Sambuc 
110784d9c625SLionel Sambuc 	REFPN(pn);
110884d9c625SLionel Sambuc 	vap = ap->a_vap;
110984d9c625SLionel Sambuc 
111084d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
111184d9c625SLionel Sambuc 		if (!TIMED_OUT(pn->pn_va_timeout)) {
111284d9c625SLionel Sambuc 			update_va(vp, vap, pn->pn_va_cache,
111384d9c625SLionel Sambuc 				  NULL, NULL, SETATTR_CHSIZE);
111484d9c625SLionel Sambuc 			goto out2;
111584d9c625SLionel Sambuc 		}
111684d9c625SLionel Sambuc 	}
111784d9c625SLionel Sambuc 
111884d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, getattr);
111984d9c625SLionel Sambuc 	vattr_null(&getattr_msg->pvnr_va);
112084d9c625SLionel Sambuc 	puffs_credcvt(&getattr_msg->pvnr_cred, ap->a_cred);
112184d9c625SLionel Sambuc 	puffs_msg_setinfo(park_getattr, PUFFSOP_VN,
112284d9c625SLionel Sambuc 	    PUFFS_VN_GETATTR, VPTOPNC(vp));
112384d9c625SLionel Sambuc 
112484d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_getattr, vp->v_data, NULL, error);
112584d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
112684d9c625SLionel Sambuc 	if (error)
112784d9c625SLionel Sambuc 		goto out;
112884d9c625SLionel Sambuc 
112984d9c625SLionel Sambuc 	rvap = &getattr_msg->pvnr_va;
113084d9c625SLionel Sambuc 
113184d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp))
113284d9c625SLionel Sambuc 		va_ttl = &getattr_msg->pvnr_va_ttl;
113384d9c625SLionel Sambuc 
113484d9c625SLionel Sambuc 	update_va(vp, vap, rvap, va_ttl, NULL, SETATTR_CHSIZE);
113584d9c625SLionel Sambuc 
113684d9c625SLionel Sambuc  out:
113784d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(getattr);
113884d9c625SLionel Sambuc 
113984d9c625SLionel Sambuc  out2:
114084d9c625SLionel Sambuc 	puffs_releasenode(pn);
114184d9c625SLionel Sambuc 
114284d9c625SLionel Sambuc 	mutex_exit(&pn->pn_sizemtx);
114384d9c625SLionel Sambuc 
114484d9c625SLionel Sambuc 	return error;
114584d9c625SLionel Sambuc }
114684d9c625SLionel Sambuc 
1147*0a6a1f1dSLionel Sambuc static void
zerofill_lastpage(struct vnode * vp,voff_t off)1148*0a6a1f1dSLionel Sambuc zerofill_lastpage(struct vnode *vp, voff_t off)
1149*0a6a1f1dSLionel Sambuc {
1150*0a6a1f1dSLionel Sambuc 	char zbuf[PAGE_SIZE];
1151*0a6a1f1dSLionel Sambuc 	struct iovec iov;
1152*0a6a1f1dSLionel Sambuc 	struct uio uio;
1153*0a6a1f1dSLionel Sambuc 	vsize_t len;
1154*0a6a1f1dSLionel Sambuc 	int error;
1155*0a6a1f1dSLionel Sambuc 
1156*0a6a1f1dSLionel Sambuc 	if (trunc_page(off) == off)
1157*0a6a1f1dSLionel Sambuc 		return;
1158*0a6a1f1dSLionel Sambuc 
1159*0a6a1f1dSLionel Sambuc 	if (vp->v_writecount == 0)
1160*0a6a1f1dSLionel Sambuc 		return;
1161*0a6a1f1dSLionel Sambuc 
1162*0a6a1f1dSLionel Sambuc 	len = round_page(off) - off;
1163*0a6a1f1dSLionel Sambuc 	memset(zbuf, 0, len);
1164*0a6a1f1dSLionel Sambuc 
1165*0a6a1f1dSLionel Sambuc 	iov.iov_base = zbuf;
1166*0a6a1f1dSLionel Sambuc 	iov.iov_len = len;
1167*0a6a1f1dSLionel Sambuc 	UIO_SETUP_SYSSPACE(&uio);
1168*0a6a1f1dSLionel Sambuc 	uio.uio_iov = &iov;
1169*0a6a1f1dSLionel Sambuc 	uio.uio_iovcnt = 1;
1170*0a6a1f1dSLionel Sambuc 	uio.uio_offset = off;
1171*0a6a1f1dSLionel Sambuc 	uio.uio_resid = len;
1172*0a6a1f1dSLionel Sambuc 	uio.uio_rw = UIO_WRITE;
1173*0a6a1f1dSLionel Sambuc 
1174*0a6a1f1dSLionel Sambuc 	error = ubc_uiomove(&vp->v_uobj, &uio, len,
1175*0a6a1f1dSLionel Sambuc 			    UVM_ADV_SEQUENTIAL, UBC_WRITE|UBC_UNMAP_FLAG(vp));
1176*0a6a1f1dSLionel Sambuc 	if (error) {
1177*0a6a1f1dSLionel Sambuc 		DPRINTF(("zero-fill 0x%" PRIxVSIZE "@0x%" PRIx64
1178*0a6a1f1dSLionel Sambuc 			 " failed: error = %d\n", len, off, error));
1179*0a6a1f1dSLionel Sambuc 	}
1180*0a6a1f1dSLionel Sambuc 
1181*0a6a1f1dSLionel Sambuc 	return;
1182*0a6a1f1dSLionel Sambuc }
1183*0a6a1f1dSLionel Sambuc 
118484d9c625SLionel Sambuc static int
dosetattr(struct vnode * vp,struct vattr * vap,kauth_cred_t cred,int flags)118584d9c625SLionel Sambuc dosetattr(struct vnode *vp, struct vattr *vap, kauth_cred_t cred, int flags)
118684d9c625SLionel Sambuc {
118784d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, setattr);
118884d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
118984d9c625SLionel Sambuc 	struct puffs_node *pn = vp->v_data;
1190*0a6a1f1dSLionel Sambuc 	vsize_t oldsize = vp->v_size;
119184d9c625SLionel Sambuc 	int error = 0;
119284d9c625SLionel Sambuc 
119384d9c625SLionel Sambuc 	KASSERT(!(flags & SETATTR_CHSIZE) || mutex_owned(&pn->pn_sizemtx));
119484d9c625SLionel Sambuc 
119584d9c625SLionel Sambuc 	if ((vp->v_mount->mnt_flag & MNT_RDONLY) &&
119684d9c625SLionel Sambuc 	    (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL
119784d9c625SLionel Sambuc 	    || vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL
119884d9c625SLionel Sambuc 	    || vap->va_mode != (mode_t)VNOVAL))
119984d9c625SLionel Sambuc 		return EROFS;
120084d9c625SLionel Sambuc 
120184d9c625SLionel Sambuc 	if ((vp->v_mount->mnt_flag & MNT_RDONLY)
120284d9c625SLionel Sambuc 	    && vp->v_type == VREG && vap->va_size != VNOVAL)
120384d9c625SLionel Sambuc 		return EROFS;
120484d9c625SLionel Sambuc 
120584d9c625SLionel Sambuc 	/*
120684d9c625SLionel Sambuc 	 * Flush metacache first.  If we are called with some explicit
120784d9c625SLionel Sambuc 	 * parameters, treat them as information overriding metacache
120884d9c625SLionel Sambuc 	 * information.
120984d9c625SLionel Sambuc 	 */
1210*0a6a1f1dSLionel Sambuc 	if (PUFFS_USE_METAFLUSH(pmp) && pn->pn_stat & PNODE_METACACHE_MASK) {
121184d9c625SLionel Sambuc 		if ((pn->pn_stat & PNODE_METACACHE_ATIME)
121284d9c625SLionel Sambuc 		    && vap->va_atime.tv_sec == VNOVAL)
121384d9c625SLionel Sambuc 			vap->va_atime = pn->pn_mc_atime;
121484d9c625SLionel Sambuc 		if ((pn->pn_stat & PNODE_METACACHE_CTIME)
121584d9c625SLionel Sambuc 		    && vap->va_ctime.tv_sec == VNOVAL)
121684d9c625SLionel Sambuc 			vap->va_ctime = pn->pn_mc_ctime;
121784d9c625SLionel Sambuc 		if ((pn->pn_stat & PNODE_METACACHE_MTIME)
121884d9c625SLionel Sambuc 		    && vap->va_mtime.tv_sec == VNOVAL)
121984d9c625SLionel Sambuc 			vap->va_mtime = pn->pn_mc_mtime;
122084d9c625SLionel Sambuc 		if ((pn->pn_stat & PNODE_METACACHE_SIZE)
122184d9c625SLionel Sambuc 		    && vap->va_size == VNOVAL)
122284d9c625SLionel Sambuc 			vap->va_size = pn->pn_mc_size;
122384d9c625SLionel Sambuc 
122484d9c625SLionel Sambuc 		pn->pn_stat &= ~PNODE_METACACHE_MASK;
122584d9c625SLionel Sambuc 	}
122684d9c625SLionel Sambuc 
122784d9c625SLionel Sambuc 	/*
122884d9c625SLionel Sambuc 	 * Flush attribute cache so that another thread do
122984d9c625SLionel Sambuc 	 * not get a stale value during the operation.
123084d9c625SLionel Sambuc 	 */
123184d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp))
123284d9c625SLionel Sambuc 		pn->pn_va_timeout = 0;
123384d9c625SLionel Sambuc 
123484d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, setattr);
123584d9c625SLionel Sambuc 	(void)memcpy(&setattr_msg->pvnr_va, vap, sizeof(struct vattr));
123684d9c625SLionel Sambuc 	puffs_credcvt(&setattr_msg->pvnr_cred, cred);
123784d9c625SLionel Sambuc 	puffs_msg_setinfo(park_setattr, PUFFSOP_VN,
123884d9c625SLionel Sambuc 	    PUFFS_VN_SETATTR, VPTOPNC(vp));
123984d9c625SLionel Sambuc 	if (flags & SETATTR_ASYNC)
124084d9c625SLionel Sambuc 		puffs_msg_setfaf(park_setattr);
124184d9c625SLionel Sambuc 
124284d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_setattr);
1243*0a6a1f1dSLionel Sambuc 	if ((flags & SETATTR_ASYNC) == 0) {
124484d9c625SLionel Sambuc 		error = puffs_msg_wait2(pmp, park_setattr, vp->v_data, NULL);
124584d9c625SLionel Sambuc 
124684d9c625SLionel Sambuc 		if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
124784d9c625SLionel Sambuc 			struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl;
124884d9c625SLionel Sambuc 			struct vattr *rvap = &setattr_msg->pvnr_va;
124984d9c625SLionel Sambuc 
125084d9c625SLionel Sambuc 			update_va(vp, NULL, rvap, va_ttl, NULL, flags);
125184d9c625SLionel Sambuc 		}
1252*0a6a1f1dSLionel Sambuc 	}
125384d9c625SLionel Sambuc 
125484d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(setattr);
125584d9c625SLionel Sambuc 	if ((flags & SETATTR_ASYNC) == 0) {
125684d9c625SLionel Sambuc 		error = checkerr(pmp, error, __func__);
125784d9c625SLionel Sambuc 		if (error)
125884d9c625SLionel Sambuc 			return error;
125984d9c625SLionel Sambuc 	} else {
126084d9c625SLionel Sambuc 		error = 0;
126184d9c625SLionel Sambuc 	}
126284d9c625SLionel Sambuc 
126384d9c625SLionel Sambuc 	if (vap->va_size != VNOVAL) {
1264*0a6a1f1dSLionel Sambuc 		/*
1265*0a6a1f1dSLionel Sambuc 		 * If we truncated the file, make sure the data beyond
1266*0a6a1f1dSLionel Sambuc 		 * EOF in last page does not remain in cache, otherwise
1267*0a6a1f1dSLionel Sambuc 		 * if the file is later truncated to a larger size (creating
1268*0a6a1f1dSLionel Sambuc 		 * a hole), that area will not return zeroes as it
1269*0a6a1f1dSLionel Sambuc 		 * should.
1270*0a6a1f1dSLionel Sambuc 		 */
1271*0a6a1f1dSLionel Sambuc 		if ((flags & SETATTR_CHSIZE) && PUFFS_USE_PAGECACHE(pmp) &&
1272*0a6a1f1dSLionel Sambuc 		    (vap->va_size < oldsize))
1273*0a6a1f1dSLionel Sambuc 			zerofill_lastpage(vp, vap->va_size);
1274*0a6a1f1dSLionel Sambuc 
127584d9c625SLionel Sambuc 		pn->pn_serversize = vap->va_size;
127684d9c625SLionel Sambuc 		if (flags & SETATTR_CHSIZE)
127784d9c625SLionel Sambuc 			uvm_vnp_setsize(vp, vap->va_size);
127884d9c625SLionel Sambuc 	}
127984d9c625SLionel Sambuc 
128084d9c625SLionel Sambuc 	return 0;
128184d9c625SLionel Sambuc }
128284d9c625SLionel Sambuc 
128384d9c625SLionel Sambuc int
puffs_vnop_setattr(void * v)128484d9c625SLionel Sambuc puffs_vnop_setattr(void *v)
128584d9c625SLionel Sambuc {
128684d9c625SLionel Sambuc 	struct vop_getattr_args /* {
128784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
128884d9c625SLionel Sambuc 		struct vnode *a_vp;
128984d9c625SLionel Sambuc 		struct vattr *a_vap;
129084d9c625SLionel Sambuc 		kauth_cred_t a_cred;
129184d9c625SLionel Sambuc 	} */ *ap = v;
129284d9c625SLionel Sambuc 	struct puffs_node *pn = ap->a_vp->v_data;
129384d9c625SLionel Sambuc 	int error;
129484d9c625SLionel Sambuc 
129584d9c625SLionel Sambuc 	mutex_enter(&pn->pn_sizemtx);
129684d9c625SLionel Sambuc 	error = dosetattr(ap->a_vp, ap->a_vap, ap->a_cred, SETATTR_CHSIZE);
129784d9c625SLionel Sambuc 	mutex_exit(&pn->pn_sizemtx);
129884d9c625SLionel Sambuc 
129984d9c625SLionel Sambuc 	return error;
130084d9c625SLionel Sambuc }
130184d9c625SLionel Sambuc 
130284d9c625SLionel Sambuc static __inline int
doinact(struct puffs_mount * pmp,int iaflag)130384d9c625SLionel Sambuc doinact(struct puffs_mount *pmp, int iaflag)
130484d9c625SLionel Sambuc {
130584d9c625SLionel Sambuc 
130684d9c625SLionel Sambuc 	if (EXISTSOP(pmp, INACTIVE))
130784d9c625SLionel Sambuc 		if (pmp->pmp_flags & PUFFS_KFLAG_IAONDEMAND)
130884d9c625SLionel Sambuc 			if (iaflag || ALLOPS(pmp))
130984d9c625SLionel Sambuc 				return 1;
131084d9c625SLionel Sambuc 			else
131184d9c625SLionel Sambuc 				return 0;
131284d9c625SLionel Sambuc 		else
131384d9c625SLionel Sambuc 			return 1;
131484d9c625SLionel Sambuc 	else
131584d9c625SLionel Sambuc 		return 0;
131684d9c625SLionel Sambuc }
131784d9c625SLionel Sambuc 
131884d9c625SLionel Sambuc static void
callinactive(struct puffs_mount * pmp,puffs_cookie_t ck,int iaflag)131984d9c625SLionel Sambuc callinactive(struct puffs_mount *pmp, puffs_cookie_t ck, int iaflag)
132084d9c625SLionel Sambuc {
132184d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, inactive);
132284d9c625SLionel Sambuc 
132384d9c625SLionel Sambuc 	if (doinact(pmp, iaflag)) {
132484d9c625SLionel Sambuc 		PUFFS_MSG_ALLOC(vn, inactive);
132584d9c625SLionel Sambuc 		puffs_msg_setinfo(park_inactive, PUFFSOP_VN,
132684d9c625SLionel Sambuc 		    PUFFS_VN_INACTIVE, ck);
132784d9c625SLionel Sambuc 		PUFFS_MSG_ENQUEUEWAIT_NOERROR(pmp, park_inactive);
132884d9c625SLionel Sambuc 		PUFFS_MSG_RELEASE(inactive);
132984d9c625SLionel Sambuc 	}
133084d9c625SLionel Sambuc }
133184d9c625SLionel Sambuc 
133284d9c625SLionel Sambuc /* XXX: callinactive can't setback */
133384d9c625SLionel Sambuc int
puffs_vnop_inactive(void * v)133484d9c625SLionel Sambuc puffs_vnop_inactive(void *v)
133584d9c625SLionel Sambuc {
133684d9c625SLionel Sambuc 	struct vop_inactive_args /* {
133784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
133884d9c625SLionel Sambuc 		struct vnode *a_vp;
133984d9c625SLionel Sambuc 	} */ *ap = v;
134084d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, inactive);
134184d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
134284d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
134384d9c625SLionel Sambuc 	struct puffs_node *pnode;
134484d9c625SLionel Sambuc 	bool recycle = false;
134584d9c625SLionel Sambuc 
1346*0a6a1f1dSLionel Sambuc 	/*
1347*0a6a1f1dSLionel Sambuc 	 * When puffs_cookie2vnode() misses an entry, vcache_get()
1348*0a6a1f1dSLionel Sambuc 	 * creates a new node (puffs_vfsop_loadvnode being called to
1349*0a6a1f1dSLionel Sambuc 	 * initialize the PUFFS part), then it discovers it is VNON,
1350*0a6a1f1dSLionel Sambuc 	 * and tries to vrele() it. This leads us there, while the
1351*0a6a1f1dSLionel Sambuc 	 * cookie was stall and the node likely already reclaimed.
1352*0a6a1f1dSLionel Sambuc 	 */
1353*0a6a1f1dSLionel Sambuc 	if (vp->v_type == VNON) {
1354*0a6a1f1dSLionel Sambuc 		VOP_UNLOCK(vp);
1355*0a6a1f1dSLionel Sambuc 		return 0;
1356*0a6a1f1dSLionel Sambuc 	}
1357*0a6a1f1dSLionel Sambuc 
135884d9c625SLionel Sambuc 	pnode = vp->v_data;
135984d9c625SLionel Sambuc 	mutex_enter(&pnode->pn_sizemtx);
136084d9c625SLionel Sambuc 
136184d9c625SLionel Sambuc 	if (doinact(pmp, pnode->pn_stat & PNODE_DOINACT)) {
136284d9c625SLionel Sambuc 		flushvncache(vp, 0, 0, false);
136384d9c625SLionel Sambuc 		PUFFS_MSG_ALLOC(vn, inactive);
136484d9c625SLionel Sambuc 		puffs_msg_setinfo(park_inactive, PUFFSOP_VN,
136584d9c625SLionel Sambuc 		    PUFFS_VN_INACTIVE, VPTOPNC(vp));
136684d9c625SLionel Sambuc 		PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_inactive, vp->v_data,
136784d9c625SLionel Sambuc 		    NULL);
136884d9c625SLionel Sambuc 		PUFFS_MSG_RELEASE(inactive);
136984d9c625SLionel Sambuc 	}
137084d9c625SLionel Sambuc 	pnode->pn_stat &= ~PNODE_DOINACT;
137184d9c625SLionel Sambuc 
137284d9c625SLionel Sambuc 	/*
137384d9c625SLionel Sambuc 	 * file server thinks it's gone?  then don't be afraid care,
137484d9c625SLionel Sambuc 	 * node's life was already all it would ever be
137584d9c625SLionel Sambuc 	 */
137684d9c625SLionel Sambuc 	if (pnode->pn_stat & PNODE_NOREFS) {
137784d9c625SLionel Sambuc 		pnode->pn_stat |= PNODE_DYING;
137884d9c625SLionel Sambuc 		recycle = true;
137984d9c625SLionel Sambuc 	}
138084d9c625SLionel Sambuc 
138184d9c625SLionel Sambuc 	/*
138284d9c625SLionel Sambuc 	 * Handle node TTL.
138384d9c625SLionel Sambuc 	 * If grace has already timed out, make it reclaimed.
138484d9c625SLionel Sambuc 	 * Otherwise, we queue its expiration by sop thread, so
138584d9c625SLionel Sambuc 	 * that it does not remain for ages in the freelist,
138684d9c625SLionel Sambuc 	 * holding memory in userspace, while we will have
138784d9c625SLionel Sambuc 	 * to look it up again anyway.
138884d9c625SLionel Sambuc 	 */
138984d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp) && !(vp->v_vflag & VV_ROOT) && !recycle) {
139084d9c625SLionel Sambuc 		bool incache = !TIMED_OUT(pnode->pn_cn_timeout);
139184d9c625SLionel Sambuc 		bool ingrace = !TIMED_OUT(pnode->pn_cn_grace);
139284d9c625SLionel Sambuc 		bool reclaimqueued = pnode->pn_stat & PNODE_SOPEXP;
139384d9c625SLionel Sambuc 
139484d9c625SLionel Sambuc 		if (!incache && !ingrace && !reclaimqueued) {
139584d9c625SLionel Sambuc 			pnode->pn_stat |= PNODE_DYING;
139684d9c625SLionel Sambuc 			recycle = true;
139784d9c625SLionel Sambuc 		}
139884d9c625SLionel Sambuc 
139984d9c625SLionel Sambuc 		if (!recycle && !reclaimqueued) {
140084d9c625SLionel Sambuc 			struct puffs_sopreq *psopr;
140184d9c625SLionel Sambuc 			int at = MAX(pnode->pn_cn_grace, pnode->pn_cn_timeout);
140284d9c625SLionel Sambuc 
140384d9c625SLionel Sambuc 			KASSERT(curlwp != uvm.pagedaemon_lwp);
140484d9c625SLionel Sambuc 			psopr = kmem_alloc(sizeof(*psopr), KM_SLEEP);
140584d9c625SLionel Sambuc 			psopr->psopr_ck = VPTOPNC(pnode->pn_vp);
140684d9c625SLionel Sambuc 			psopr->psopr_sopreq = PUFFS_SOPREQ_EXPIRE;
140784d9c625SLionel Sambuc 			psopr->psopr_at = at;
140884d9c625SLionel Sambuc 
140984d9c625SLionel Sambuc 			mutex_enter(&pmp->pmp_sopmtx);
141084d9c625SLionel Sambuc 
141184d9c625SLionel Sambuc 			/*
141284d9c625SLionel Sambuc 			 * If thread has disapeared, just give up. The
141384d9c625SLionel Sambuc 			 * fs is being unmounted and the node will be
141484d9c625SLionel Sambuc 			 * be reclaimed anyway.
141584d9c625SLionel Sambuc 			 *
141684d9c625SLionel Sambuc 			 * Otherwise, we queue the request but do not
141784d9c625SLionel Sambuc 			 * immediatly signal the thread, as the node
141884d9c625SLionel Sambuc 			 * has not been expired yet.
141984d9c625SLionel Sambuc 			 */
142084d9c625SLionel Sambuc 			if (pmp->pmp_sopthrcount == 0) {
142184d9c625SLionel Sambuc 				kmem_free(psopr, sizeof(*psopr));
142284d9c625SLionel Sambuc 			} else {
142384d9c625SLionel Sambuc 				TAILQ_INSERT_TAIL(&pmp->pmp_sopnodereqs,
142484d9c625SLionel Sambuc 				    psopr, psopr_entries);
142584d9c625SLionel Sambuc 				pnode->pn_stat |= PNODE_SOPEXP;
142684d9c625SLionel Sambuc 			}
142784d9c625SLionel Sambuc 
142884d9c625SLionel Sambuc 			mutex_exit(&pmp->pmp_sopmtx);
142984d9c625SLionel Sambuc 		}
143084d9c625SLionel Sambuc 	}
143184d9c625SLionel Sambuc 
1432*0a6a1f1dSLionel Sambuc 	/*
1433*0a6a1f1dSLionel Sambuc 	 * Wipe direct I/O flags
1434*0a6a1f1dSLionel Sambuc 	 */
1435*0a6a1f1dSLionel Sambuc 	pnode->pn_stat &= ~(PNODE_RDIRECT|PNODE_WDIRECT);
1436*0a6a1f1dSLionel Sambuc 
143784d9c625SLionel Sambuc 	*ap->a_recycle = recycle;
143884d9c625SLionel Sambuc 
143984d9c625SLionel Sambuc 	mutex_exit(&pnode->pn_sizemtx);
144084d9c625SLionel Sambuc 	VOP_UNLOCK(vp);
144184d9c625SLionel Sambuc 
144284d9c625SLionel Sambuc 	return 0;
144384d9c625SLionel Sambuc }
144484d9c625SLionel Sambuc 
144584d9c625SLionel Sambuc static void
callreclaim(struct puffs_mount * pmp,puffs_cookie_t ck,int nlookup)144684d9c625SLionel Sambuc callreclaim(struct puffs_mount *pmp, puffs_cookie_t ck, int nlookup)
144784d9c625SLionel Sambuc {
144884d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, reclaim);
144984d9c625SLionel Sambuc 
145084d9c625SLionel Sambuc 	if (!EXISTSOP(pmp, RECLAIM))
145184d9c625SLionel Sambuc 		return;
145284d9c625SLionel Sambuc 
145384d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, reclaim);
145484d9c625SLionel Sambuc 	reclaim_msg->pvnr_nlookup = nlookup;
145584d9c625SLionel Sambuc 	puffs_msg_setfaf(park_reclaim);
145684d9c625SLionel Sambuc 	puffs_msg_setinfo(park_reclaim, PUFFSOP_VN, PUFFS_VN_RECLAIM, ck);
145784d9c625SLionel Sambuc 
145884d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_reclaim);
145984d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(reclaim);
146084d9c625SLionel Sambuc 	return;
146184d9c625SLionel Sambuc }
146284d9c625SLionel Sambuc 
146384d9c625SLionel Sambuc /*
146484d9c625SLionel Sambuc  * always FAF, we don't really care if the server wants to fail to
146584d9c625SLionel Sambuc  * reclaim the node or not
146684d9c625SLionel Sambuc  */
146784d9c625SLionel Sambuc int
puffs_vnop_reclaim(void * v)146884d9c625SLionel Sambuc puffs_vnop_reclaim(void *v)
146984d9c625SLionel Sambuc {
147084d9c625SLionel Sambuc 	struct vop_reclaim_args /* {
147184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
147284d9c625SLionel Sambuc 		struct vnode *a_vp;
147384d9c625SLionel Sambuc 	} */ *ap = v;
147484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
147584d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
147684d9c625SLionel Sambuc 	bool notifyserver = true;
147784d9c625SLionel Sambuc 
147884d9c625SLionel Sambuc 	/*
147984d9c625SLionel Sambuc 	 * first things first: check if someone is trying to reclaim the
148084d9c625SLionel Sambuc 	 * root vnode.  do not allow that to travel to userspace.
148184d9c625SLionel Sambuc 	 * Note that we don't need to take the lock similarly to
148284d9c625SLionel Sambuc 	 * puffs_root(), since there is only one of us.
148384d9c625SLionel Sambuc 	 */
148484d9c625SLionel Sambuc 	if (vp->v_vflag & VV_ROOT) {
148584d9c625SLionel Sambuc 		mutex_enter(&pmp->pmp_lock);
148684d9c625SLionel Sambuc 		KASSERT(pmp->pmp_root != NULL);
148784d9c625SLionel Sambuc 		pmp->pmp_root = NULL;
148884d9c625SLionel Sambuc 		mutex_exit(&pmp->pmp_lock);
148984d9c625SLionel Sambuc 		notifyserver = false;
149084d9c625SLionel Sambuc 	}
149184d9c625SLionel Sambuc 
149284d9c625SLionel Sambuc 	/*
149384d9c625SLionel Sambuc 	 * purge info from kernel before issueing FAF, since we
149484d9c625SLionel Sambuc 	 * don't really know when we'll get around to it after
149584d9c625SLionel Sambuc 	 * that and someone might race us into node creation
149684d9c625SLionel Sambuc 	 */
149784d9c625SLionel Sambuc 	mutex_enter(&pmp->pmp_lock);
149884d9c625SLionel Sambuc 	if (PUFFS_USE_NAMECACHE(pmp))
149984d9c625SLionel Sambuc 		cache_purge(vp);
150084d9c625SLionel Sambuc 	mutex_exit(&pmp->pmp_lock);
150184d9c625SLionel Sambuc 
150284d9c625SLionel Sambuc 	if (notifyserver) {
150384d9c625SLionel Sambuc 		int nlookup = VPTOPP(vp)->pn_nlookup;
150484d9c625SLionel Sambuc 
150584d9c625SLionel Sambuc 		callreclaim(MPTOPUFFSMP(vp->v_mount), VPTOPNC(vp), nlookup);
150684d9c625SLionel Sambuc 	}
150784d9c625SLionel Sambuc 
150884d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp)) {
150984d9c625SLionel Sambuc 		if (__predict_true(VPTOPP(vp)->pn_parent != NULL))
151084d9c625SLionel Sambuc 			vrele(VPTOPP(vp)->pn_parent);
151184d9c625SLionel Sambuc 		else
1512*0a6a1f1dSLionel Sambuc 			KASSERT(vp->v_type == VNON || (vp->v_vflag & VV_ROOT));
151384d9c625SLionel Sambuc 	}
151484d9c625SLionel Sambuc 
151584d9c625SLionel Sambuc 	puffs_putvnode(vp);
151684d9c625SLionel Sambuc 
151784d9c625SLionel Sambuc 	return 0;
151884d9c625SLionel Sambuc }
151984d9c625SLionel Sambuc 
152084d9c625SLionel Sambuc #define CSIZE sizeof(**ap->a_cookies)
152184d9c625SLionel Sambuc int
puffs_vnop_readdir(void * v)152284d9c625SLionel Sambuc puffs_vnop_readdir(void *v)
152384d9c625SLionel Sambuc {
152484d9c625SLionel Sambuc 	struct vop_readdir_args /* {
152584d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
152684d9c625SLionel Sambuc 		struct vnode *a_vp;
152784d9c625SLionel Sambuc 		struct uio *a_uio;
152884d9c625SLionel Sambuc 		kauth_cred_t a_cred;
152984d9c625SLionel Sambuc 		int *a_eofflag;
153084d9c625SLionel Sambuc 		off_t **a_cookies;
153184d9c625SLionel Sambuc 		int *a_ncookies;
153284d9c625SLionel Sambuc 	} */ *ap = v;
153384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, readdir);
153484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
153584d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
153684d9c625SLionel Sambuc 	size_t argsize, tomove, cookiemem, cookiesmax;
153784d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
153884d9c625SLionel Sambuc 	size_t howmuch, resid;
153984d9c625SLionel Sambuc 	int error;
154084d9c625SLionel Sambuc 
154184d9c625SLionel Sambuc 	/*
154284d9c625SLionel Sambuc 	 * ok, so we need: resid + cookiemem = maxreq
154384d9c625SLionel Sambuc 	 * => resid + cookiesize * (resid/minsize) = maxreq
154484d9c625SLionel Sambuc 	 * => resid + cookiesize/minsize * resid = maxreq
154584d9c625SLionel Sambuc 	 * => (cookiesize/minsize + 1) * resid = maxreq
154684d9c625SLionel Sambuc 	 * => resid = maxreq / (cookiesize/minsize + 1)
154784d9c625SLionel Sambuc 	 *
154884d9c625SLionel Sambuc 	 * Since cookiesize <= minsize and we're not very big on floats,
154984d9c625SLionel Sambuc 	 * we approximate that to be 1.  Therefore:
155084d9c625SLionel Sambuc 	 *
155184d9c625SLionel Sambuc 	 * resid = maxreq / 2;
155284d9c625SLionel Sambuc 	 *
155384d9c625SLionel Sambuc 	 * Well, at least we didn't have to use differential equations
155484d9c625SLionel Sambuc 	 * or the Gram-Schmidt process.
155584d9c625SLionel Sambuc 	 *
155684d9c625SLionel Sambuc 	 * (yes, I'm very afraid of this)
155784d9c625SLionel Sambuc 	 */
155884d9c625SLionel Sambuc 	KASSERT(CSIZE <= _DIRENT_MINSIZE((struct dirent *)0));
155984d9c625SLionel Sambuc 
156084d9c625SLionel Sambuc 	if (ap->a_cookies) {
156184d9c625SLionel Sambuc 		KASSERT(ap->a_ncookies != NULL);
156284d9c625SLionel Sambuc 		if (pmp->pmp_args.pa_fhsize == 0)
156384d9c625SLionel Sambuc 			return EOPNOTSUPP;
156484d9c625SLionel Sambuc 		resid = PUFFS_TOMOVE(uio->uio_resid, pmp) / 2;
156584d9c625SLionel Sambuc 		cookiesmax = resid/_DIRENT_MINSIZE((struct dirent *)0);
156684d9c625SLionel Sambuc 		cookiemem = ALIGN(cookiesmax*CSIZE); /* play safe */
156784d9c625SLionel Sambuc 	} else {
156884d9c625SLionel Sambuc 		resid = PUFFS_TOMOVE(uio->uio_resid, pmp);
156984d9c625SLionel Sambuc 		cookiesmax = 0;
157084d9c625SLionel Sambuc 		cookiemem = 0;
157184d9c625SLionel Sambuc 	}
157284d9c625SLionel Sambuc 
157384d9c625SLionel Sambuc 	argsize = sizeof(struct puffs_vnmsg_readdir);
157484d9c625SLionel Sambuc 	tomove = resid + cookiemem;
157584d9c625SLionel Sambuc 	puffs_msgmem_alloc(argsize + tomove, &park_readdir,
157684d9c625SLionel Sambuc 	    (void *)&readdir_msg, 1);
157784d9c625SLionel Sambuc 
157884d9c625SLionel Sambuc 	puffs_credcvt(&readdir_msg->pvnr_cred, ap->a_cred);
157984d9c625SLionel Sambuc 	readdir_msg->pvnr_offset = uio->uio_offset;
158084d9c625SLionel Sambuc 	readdir_msg->pvnr_resid = resid;
158184d9c625SLionel Sambuc 	readdir_msg->pvnr_ncookies = cookiesmax;
158284d9c625SLionel Sambuc 	readdir_msg->pvnr_eofflag = 0;
158384d9c625SLionel Sambuc 	readdir_msg->pvnr_dentoff = cookiemem;
158484d9c625SLionel Sambuc 	puffs_msg_setinfo(park_readdir, PUFFSOP_VN,
158584d9c625SLionel Sambuc 	    PUFFS_VN_READDIR, VPTOPNC(vp));
158684d9c625SLionel Sambuc 	puffs_msg_setdelta(park_readdir, tomove);
158784d9c625SLionel Sambuc 
158884d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_readdir, vp->v_data, NULL, error);
158984d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
159084d9c625SLionel Sambuc 	if (error)
159184d9c625SLionel Sambuc 		goto out;
159284d9c625SLionel Sambuc 
159384d9c625SLionel Sambuc 	/* userspace is cheating? */
159484d9c625SLionel Sambuc 	if (readdir_msg->pvnr_resid > resid) {
159584d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
159684d9c625SLionel Sambuc 		    "resid grew", VPTOPNC(vp));
159784d9c625SLionel Sambuc 		ERROUT(EPROTO);
159884d9c625SLionel Sambuc 	}
159984d9c625SLionel Sambuc 	if (readdir_msg->pvnr_ncookies > cookiesmax) {
160084d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
160184d9c625SLionel Sambuc 		    "too many cookies", VPTOPNC(vp));
160284d9c625SLionel Sambuc 		ERROUT(EPROTO);
160384d9c625SLionel Sambuc 	}
160484d9c625SLionel Sambuc 
160584d9c625SLionel Sambuc 	/* check eof */
160684d9c625SLionel Sambuc 	if (readdir_msg->pvnr_eofflag)
160784d9c625SLionel Sambuc 		*ap->a_eofflag = 1;
160884d9c625SLionel Sambuc 
160984d9c625SLionel Sambuc 	/* bouncy-wouncy with the directory data */
161084d9c625SLionel Sambuc 	howmuch = resid - readdir_msg->pvnr_resid;
161184d9c625SLionel Sambuc 
161284d9c625SLionel Sambuc 	/* force eof if no data was returned (getcwd() needs this) */
161384d9c625SLionel Sambuc 	if (howmuch == 0) {
161484d9c625SLionel Sambuc 		*ap->a_eofflag = 1;
161584d9c625SLionel Sambuc 		goto out;
161684d9c625SLionel Sambuc 	}
161784d9c625SLionel Sambuc 
161884d9c625SLionel Sambuc 	error = uiomove(readdir_msg->pvnr_data + cookiemem, howmuch, uio);
161984d9c625SLionel Sambuc 	if (error)
162084d9c625SLionel Sambuc 		goto out;
162184d9c625SLionel Sambuc 
162284d9c625SLionel Sambuc 	/* provide cookies to caller if so desired */
162384d9c625SLionel Sambuc 	if (ap->a_cookies) {
162484d9c625SLionel Sambuc 		KASSERT(curlwp != uvm.pagedaemon_lwp);
162584d9c625SLionel Sambuc 		*ap->a_cookies = malloc(readdir_msg->pvnr_ncookies*CSIZE,
162684d9c625SLionel Sambuc 		    M_TEMP, M_WAITOK);
162784d9c625SLionel Sambuc 		*ap->a_ncookies = readdir_msg->pvnr_ncookies;
162884d9c625SLionel Sambuc 		memcpy(*ap->a_cookies, readdir_msg->pvnr_data,
162984d9c625SLionel Sambuc 		    *ap->a_ncookies*CSIZE);
163084d9c625SLionel Sambuc 	}
163184d9c625SLionel Sambuc 
163284d9c625SLionel Sambuc 	/* next readdir starts here */
163384d9c625SLionel Sambuc 	uio->uio_offset = readdir_msg->pvnr_offset;
163484d9c625SLionel Sambuc 
163584d9c625SLionel Sambuc  out:
163684d9c625SLionel Sambuc 	puffs_msgmem_release(park_readdir);
163784d9c625SLionel Sambuc 	return error;
163884d9c625SLionel Sambuc }
163984d9c625SLionel Sambuc #undef CSIZE
164084d9c625SLionel Sambuc 
164184d9c625SLionel Sambuc /*
164284d9c625SLionel Sambuc  * poll works by consuming the bitmask in pn_revents.  If there are
164384d9c625SLionel Sambuc  * events available, poll returns immediately.  If not, it issues a
164484d9c625SLionel Sambuc  * poll to userspace, selrecords itself and returns with no available
164584d9c625SLionel Sambuc  * events.  When the file server returns, it executes puffs_parkdone_poll(),
164684d9c625SLionel Sambuc  * where available events are added to the bitmask.  selnotify() is
164784d9c625SLionel Sambuc  * then also executed by that function causing us to enter here again
164884d9c625SLionel Sambuc  * and hopefully find the missing bits (unless someone got them first,
164984d9c625SLionel Sambuc  * in which case it starts all over again).
165084d9c625SLionel Sambuc  */
165184d9c625SLionel Sambuc int
puffs_vnop_poll(void * v)165284d9c625SLionel Sambuc puffs_vnop_poll(void *v)
165384d9c625SLionel Sambuc {
165484d9c625SLionel Sambuc 	struct vop_poll_args /* {
165584d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
165684d9c625SLionel Sambuc 		struct vnode *a_vp;
165784d9c625SLionel Sambuc 		int a_events;
165884d9c625SLionel Sambuc 	} */ *ap = v;
165984d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, poll);
166084d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
166184d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
166284d9c625SLionel Sambuc 	struct puffs_node *pn = vp->v_data;
166384d9c625SLionel Sambuc 	int events;
166484d9c625SLionel Sambuc 
166584d9c625SLionel Sambuc 	if (EXISTSOP(pmp, POLL)) {
166684d9c625SLionel Sambuc 		mutex_enter(&pn->pn_mtx);
166784d9c625SLionel Sambuc 		events = pn->pn_revents & ap->a_events;
166884d9c625SLionel Sambuc 		if (events & ap->a_events) {
166984d9c625SLionel Sambuc 			pn->pn_revents &= ~ap->a_events;
167084d9c625SLionel Sambuc 			mutex_exit(&pn->pn_mtx);
167184d9c625SLionel Sambuc 
167284d9c625SLionel Sambuc 			return events;
167384d9c625SLionel Sambuc 		} else {
167484d9c625SLionel Sambuc 			puffs_referencenode(pn);
167584d9c625SLionel Sambuc 			mutex_exit(&pn->pn_mtx);
167684d9c625SLionel Sambuc 
167784d9c625SLionel Sambuc 			PUFFS_MSG_ALLOC(vn, poll);
167884d9c625SLionel Sambuc 			poll_msg->pvnr_events = ap->a_events;
167984d9c625SLionel Sambuc 			puffs_msg_setinfo(park_poll, PUFFSOP_VN,
168084d9c625SLionel Sambuc 			    PUFFS_VN_POLL, VPTOPNC(vp));
168184d9c625SLionel Sambuc 			puffs_msg_setcall(park_poll, puffs_parkdone_poll, pn);
168284d9c625SLionel Sambuc 			selrecord(curlwp, &pn->pn_sel);
168384d9c625SLionel Sambuc 
168484d9c625SLionel Sambuc 			PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_poll,
168584d9c625SLionel Sambuc 			    vp->v_data, NULL);
168684d9c625SLionel Sambuc 			PUFFS_MSG_RELEASE(poll);
168784d9c625SLionel Sambuc 
168884d9c625SLionel Sambuc 			return 0;
168984d9c625SLionel Sambuc 		}
169084d9c625SLionel Sambuc 	} else {
169184d9c625SLionel Sambuc 		return genfs_poll(v);
169284d9c625SLionel Sambuc 	}
169384d9c625SLionel Sambuc }
169484d9c625SLionel Sambuc 
169584d9c625SLionel Sambuc static int
flushvncache(struct vnode * vp,off_t offlo,off_t offhi,bool wait)169684d9c625SLionel Sambuc flushvncache(struct vnode *vp, off_t offlo, off_t offhi, bool wait)
169784d9c625SLionel Sambuc {
169884d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
169984d9c625SLionel Sambuc 	struct vattr va;
170084d9c625SLionel Sambuc 	int pflags, error;
170184d9c625SLionel Sambuc 
170284d9c625SLionel Sambuc 	/* flush out information from our metacache, see vop_setattr */
170384d9c625SLionel Sambuc 	if (pn->pn_stat & PNODE_METACACHE_MASK
170484d9c625SLionel Sambuc 	    && (pn->pn_stat & PNODE_DYING) == 0) {
170584d9c625SLionel Sambuc 		vattr_null(&va);
170684d9c625SLionel Sambuc 		error = dosetattr(vp, &va, FSCRED,
170784d9c625SLionel Sambuc 		    SETATTR_CHSIZE | (wait ? 0 : SETATTR_ASYNC));
170884d9c625SLionel Sambuc 		if (error)
170984d9c625SLionel Sambuc 			return error;
171084d9c625SLionel Sambuc 	}
171184d9c625SLionel Sambuc 
171284d9c625SLionel Sambuc 	/*
171384d9c625SLionel Sambuc 	 * flush pages to avoid being overly dirty
171484d9c625SLionel Sambuc 	 */
171584d9c625SLionel Sambuc 	pflags = PGO_CLEANIT;
171684d9c625SLionel Sambuc 	if (wait)
171784d9c625SLionel Sambuc 		pflags |= PGO_SYNCIO;
171884d9c625SLionel Sambuc 
171984d9c625SLionel Sambuc 	mutex_enter(vp->v_interlock);
172084d9c625SLionel Sambuc 	return VOP_PUTPAGES(vp, trunc_page(offlo), round_page(offhi), pflags);
172184d9c625SLionel Sambuc }
172284d9c625SLionel Sambuc 
172384d9c625SLionel Sambuc int
puffs_vnop_fsync(void * v)172484d9c625SLionel Sambuc puffs_vnop_fsync(void *v)
172584d9c625SLionel Sambuc {
172684d9c625SLionel Sambuc 	struct vop_fsync_args /* {
172784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
172884d9c625SLionel Sambuc 		struct vnode *a_vp;
172984d9c625SLionel Sambuc 		kauth_cred_t a_cred;
173084d9c625SLionel Sambuc 		int a_flags;
173184d9c625SLionel Sambuc 		off_t a_offlo;
173284d9c625SLionel Sambuc 		off_t a_offhi;
173384d9c625SLionel Sambuc 	} */ *ap = v;
173484d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, fsync);
173584d9c625SLionel Sambuc 	struct vnode *vp;
173684d9c625SLionel Sambuc 	struct puffs_node *pn;
173784d9c625SLionel Sambuc 	struct puffs_mount *pmp;
173884d9c625SLionel Sambuc 	int error, dofaf;
173984d9c625SLionel Sambuc 
174084d9c625SLionel Sambuc 	vp = ap->a_vp;
174184d9c625SLionel Sambuc 	KASSERT(vp != NULL);
174284d9c625SLionel Sambuc 	pn = VPTOPP(vp);
174384d9c625SLionel Sambuc 	KASSERT(pn != NULL);
174484d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(vp->v_mount);
174584d9c625SLionel Sambuc 	if (ap->a_flags & FSYNC_WAIT) {
174684d9c625SLionel Sambuc 		mutex_enter(&pn->pn_sizemtx);
174784d9c625SLionel Sambuc 	} else {
174884d9c625SLionel Sambuc 		if (mutex_tryenter(&pn->pn_sizemtx) == 0)
174984d9c625SLionel Sambuc 			return EDEADLK;
175084d9c625SLionel Sambuc 	}
175184d9c625SLionel Sambuc 
175284d9c625SLionel Sambuc 	error = flushvncache(vp, ap->a_offlo, ap->a_offhi,
175384d9c625SLionel Sambuc 	    (ap->a_flags & FSYNC_WAIT) == FSYNC_WAIT);
175484d9c625SLionel Sambuc 	if (error)
175584d9c625SLionel Sambuc 		goto out;
175684d9c625SLionel Sambuc 
175784d9c625SLionel Sambuc 	/*
175884d9c625SLionel Sambuc 	 * HELLO!  We exit already here if the user server does not
175984d9c625SLionel Sambuc 	 * support fsync OR if we should call fsync for a node which
176084d9c625SLionel Sambuc 	 * has references neither in the kernel or the fs server.
176184d9c625SLionel Sambuc 	 * Otherwise we continue to issue fsync() forward.
176284d9c625SLionel Sambuc 	 */
176384d9c625SLionel Sambuc 	error = 0;
176484d9c625SLionel Sambuc 	if (!EXISTSOP(pmp, FSYNC) || (pn->pn_stat & PNODE_DYING))
176584d9c625SLionel Sambuc 		goto out;
176684d9c625SLionel Sambuc 
176784d9c625SLionel Sambuc 	dofaf = (ap->a_flags & FSYNC_WAIT) == 0 || ap->a_flags == FSYNC_LAZY;
176884d9c625SLionel Sambuc 	/*
176984d9c625SLionel Sambuc 	 * We abuse VXLOCK to mean "vnode is going to die", so we issue
177084d9c625SLionel Sambuc 	 * only FAFs for those.  Otherwise there's a danger of deadlock,
177184d9c625SLionel Sambuc 	 * since the execution context here might be the user server
177284d9c625SLionel Sambuc 	 * doing some operation on another fs, which in turn caused a
177384d9c625SLionel Sambuc 	 * vnode to be reclaimed from the freelist for this fs.
177484d9c625SLionel Sambuc 	 */
177584d9c625SLionel Sambuc 	if (dofaf == 0) {
177684d9c625SLionel Sambuc 		mutex_enter(vp->v_interlock);
1777*0a6a1f1dSLionel Sambuc 		if (vdead_check(vp, VDEAD_NOWAIT) != 0)
177884d9c625SLionel Sambuc 			dofaf = 1;
177984d9c625SLionel Sambuc 		mutex_exit(vp->v_interlock);
178084d9c625SLionel Sambuc 	}
178184d9c625SLionel Sambuc 
178284d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, fsync);
178384d9c625SLionel Sambuc 	if (dofaf)
178484d9c625SLionel Sambuc 		puffs_msg_setfaf(park_fsync);
178584d9c625SLionel Sambuc 
178684d9c625SLionel Sambuc 	puffs_credcvt(&fsync_msg->pvnr_cred, ap->a_cred);
178784d9c625SLionel Sambuc 	fsync_msg->pvnr_flags = ap->a_flags;
178884d9c625SLionel Sambuc 	fsync_msg->pvnr_offlo = ap->a_offlo;
178984d9c625SLionel Sambuc 	fsync_msg->pvnr_offhi = ap->a_offhi;
179084d9c625SLionel Sambuc 	puffs_msg_setinfo(park_fsync, PUFFSOP_VN,
179184d9c625SLionel Sambuc 	    PUFFS_VN_FSYNC, VPTOPNC(vp));
179284d9c625SLionel Sambuc 
179384d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fsync, vp->v_data, NULL, error);
179484d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(fsync);
179584d9c625SLionel Sambuc 
179684d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
179784d9c625SLionel Sambuc 
179884d9c625SLionel Sambuc out:
179984d9c625SLionel Sambuc 	mutex_exit(&pn->pn_sizemtx);
180084d9c625SLionel Sambuc 	return error;
180184d9c625SLionel Sambuc }
180284d9c625SLionel Sambuc 
180384d9c625SLionel Sambuc int
puffs_vnop_seek(void * v)180484d9c625SLionel Sambuc puffs_vnop_seek(void *v)
180584d9c625SLionel Sambuc {
180684d9c625SLionel Sambuc 	struct vop_seek_args /* {
180784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
180884d9c625SLionel Sambuc 		struct vnode *a_vp;
180984d9c625SLionel Sambuc 		off_t a_oldoff;
181084d9c625SLionel Sambuc 		off_t a_newoff;
181184d9c625SLionel Sambuc 		kauth_cred_t a_cred;
181284d9c625SLionel Sambuc 	} */ *ap = v;
181384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, seek);
181484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
181584d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
181684d9c625SLionel Sambuc 	int error;
181784d9c625SLionel Sambuc 
181884d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, seek);
181984d9c625SLionel Sambuc 	seek_msg->pvnr_oldoff = ap->a_oldoff;
182084d9c625SLionel Sambuc 	seek_msg->pvnr_newoff = ap->a_newoff;
182184d9c625SLionel Sambuc 	puffs_credcvt(&seek_msg->pvnr_cred, ap->a_cred);
182284d9c625SLionel Sambuc 	puffs_msg_setinfo(park_seek, PUFFSOP_VN,
182384d9c625SLionel Sambuc 	    PUFFS_VN_SEEK, VPTOPNC(vp));
182484d9c625SLionel Sambuc 
182584d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_seek, vp->v_data, NULL, error);
182684d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(seek);
182784d9c625SLionel Sambuc 	return checkerr(pmp, error, __func__);
182884d9c625SLionel Sambuc }
182984d9c625SLionel Sambuc 
183084d9c625SLionel Sambuc static int
callremove(struct puffs_mount * pmp,puffs_cookie_t dck,puffs_cookie_t ck,struct componentname * cnp)183184d9c625SLionel Sambuc callremove(struct puffs_mount *pmp, puffs_cookie_t dck, puffs_cookie_t ck,
183284d9c625SLionel Sambuc 	struct componentname *cnp)
183384d9c625SLionel Sambuc {
183484d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, remove);
183584d9c625SLionel Sambuc 	int error;
183684d9c625SLionel Sambuc 
183784d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, remove);
183884d9c625SLionel Sambuc 	remove_msg->pvnr_cookie_targ = ck;
183984d9c625SLionel Sambuc 	puffs_makecn(&remove_msg->pvnr_cn, &remove_msg->pvnr_cn_cred,
184084d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
184184d9c625SLionel Sambuc 	puffs_msg_setinfo(park_remove, PUFFSOP_VN, PUFFS_VN_REMOVE, dck);
184284d9c625SLionel Sambuc 
184384d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_remove, error);
184484d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(remove);
184584d9c625SLionel Sambuc 
184684d9c625SLionel Sambuc 	return checkerr(pmp, error, __func__);
184784d9c625SLionel Sambuc }
184884d9c625SLionel Sambuc 
184984d9c625SLionel Sambuc /*
185084d9c625SLionel Sambuc  * XXX: can't use callremove now because can't catch setbacks with
185184d9c625SLionel Sambuc  * it due to lack of a pnode argument.
185284d9c625SLionel Sambuc  */
185384d9c625SLionel Sambuc int
puffs_vnop_remove(void * v)185484d9c625SLionel Sambuc puffs_vnop_remove(void *v)
185584d9c625SLionel Sambuc {
185684d9c625SLionel Sambuc 	struct vop_remove_args /* {
185784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
185884d9c625SLionel Sambuc 		struct vnode *a_dvp;
185984d9c625SLionel Sambuc 		struct vnode *a_vp;
186084d9c625SLionel Sambuc 		struct componentname *a_cnp;
186184d9c625SLionel Sambuc 	} */ *ap = v;
186284d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, remove);
186384d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
186484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
186584d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
186684d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
186784d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
186884d9c625SLionel Sambuc 	struct mount *mp = dvp->v_mount;
186984d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
187084d9c625SLionel Sambuc 	int error;
187184d9c625SLionel Sambuc 
187284d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, remove);
187384d9c625SLionel Sambuc 	remove_msg->pvnr_cookie_targ = VPTOPNC(vp);
187484d9c625SLionel Sambuc 	puffs_makecn(&remove_msg->pvnr_cn, &remove_msg->pvnr_cn_cred,
187584d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
187684d9c625SLionel Sambuc 	puffs_msg_setinfo(park_remove, PUFFSOP_VN,
187784d9c625SLionel Sambuc 	    PUFFS_VN_REMOVE, VPTOPNC(dvp));
187884d9c625SLionel Sambuc 
187984d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_remove);
188084d9c625SLionel Sambuc 	REFPN_AND_UNLOCKVP(dvp, dpn);
188184d9c625SLionel Sambuc 	if (dvp == vp)
188284d9c625SLionel Sambuc 		REFPN(pn);
188384d9c625SLionel Sambuc 	else
188484d9c625SLionel Sambuc 		REFPN_AND_UNLOCKVP(vp, pn);
188584d9c625SLionel Sambuc 	error = puffs_msg_wait2(pmp, park_remove, dpn, pn);
188684d9c625SLionel Sambuc 
188784d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(remove);
188884d9c625SLionel Sambuc 
1889*0a6a1f1dSLionel Sambuc 	puffs_updatenode(VPTOPP(dvp), PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
1890*0a6a1f1dSLionel Sambuc 
189184d9c625SLionel Sambuc 	RELEPN_AND_VP(dvp, dpn);
189284d9c625SLionel Sambuc 	RELEPN_AND_VP(vp, pn);
189384d9c625SLionel Sambuc 
189484d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
189584d9c625SLionel Sambuc 	return error;
189684d9c625SLionel Sambuc }
189784d9c625SLionel Sambuc 
189884d9c625SLionel Sambuc int
puffs_vnop_mkdir(void * v)189984d9c625SLionel Sambuc puffs_vnop_mkdir(void *v)
190084d9c625SLionel Sambuc {
1901*0a6a1f1dSLionel Sambuc 	struct vop_mkdir_v3_args /* {
190284d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
190384d9c625SLionel Sambuc 		struct vnode *a_dvp;
190484d9c625SLionel Sambuc 		struct vnode **a_vpp;
190584d9c625SLionel Sambuc 		struct componentname *a_cnp;
190684d9c625SLionel Sambuc 		struct vattr *a_vap;
190784d9c625SLionel Sambuc 	} */ *ap = v;
190884d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, mkdir);
190984d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
191084d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
191184d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
191284d9c625SLionel Sambuc 	struct mount *mp = dvp->v_mount;
191384d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(mp);
191484d9c625SLionel Sambuc 	int error;
191584d9c625SLionel Sambuc 
191684d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, mkdir);
191784d9c625SLionel Sambuc 	puffs_makecn(&mkdir_msg->pvnr_cn, &mkdir_msg->pvnr_cn_cred,
191884d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
191984d9c625SLionel Sambuc 	mkdir_msg->pvnr_va = *ap->a_vap;
192084d9c625SLionel Sambuc 	puffs_msg_setinfo(park_mkdir, PUFFSOP_VN,
192184d9c625SLionel Sambuc 	    PUFFS_VN_MKDIR, VPTOPNC(dvp));
192284d9c625SLionel Sambuc 
192384d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mkdir, dvp->v_data, NULL, error);
192484d9c625SLionel Sambuc 
192584d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
192684d9c625SLionel Sambuc 	if (error)
192784d9c625SLionel Sambuc 		goto out;
192884d9c625SLionel Sambuc 
192984d9c625SLionel Sambuc 	error = puffs_newnode(mp, dvp, ap->a_vpp,
193084d9c625SLionel Sambuc 	    mkdir_msg->pvnr_newnode, cnp, VDIR, 0);
193184d9c625SLionel Sambuc 	if (error) {
193284d9c625SLionel Sambuc 		puffs_abortbutton(pmp, PUFFS_ABORT_MKDIR, dpn->pn_cookie,
193384d9c625SLionel Sambuc 		    mkdir_msg->pvnr_newnode, cnp);
193484d9c625SLionel Sambuc 		goto out;
193584d9c625SLionel Sambuc 	}
193684d9c625SLionel Sambuc 
193784d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
193884d9c625SLionel Sambuc 		struct timespec *va_ttl = &mkdir_msg->pvnr_va_ttl;
193984d9c625SLionel Sambuc 		struct timespec *cn_ttl = &mkdir_msg->pvnr_cn_ttl;
194084d9c625SLionel Sambuc 		struct vattr *rvap = &mkdir_msg->pvnr_va;
194184d9c625SLionel Sambuc 
194284d9c625SLionel Sambuc 		update_va(*ap->a_vpp, NULL, rvap,
194384d9c625SLionel Sambuc 			  va_ttl, cn_ttl, SETATTR_CHSIZE);
194484d9c625SLionel Sambuc 	}
194584d9c625SLionel Sambuc 
194684d9c625SLionel Sambuc 	VPTOPP(*ap->a_vpp)->pn_nlookup++;
194784d9c625SLionel Sambuc 
194884d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) &&
194984d9c625SLionel Sambuc 	    (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
195084d9c625SLionel Sambuc 		update_parent(*ap->a_vpp, dvp);
195184d9c625SLionel Sambuc 
195284d9c625SLionel Sambuc  out:
195384d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(mkdir);
195484d9c625SLionel Sambuc 	return error;
195584d9c625SLionel Sambuc }
195684d9c625SLionel Sambuc 
195784d9c625SLionel Sambuc static int
callrmdir(struct puffs_mount * pmp,puffs_cookie_t dck,puffs_cookie_t ck,struct componentname * cnp)195884d9c625SLionel Sambuc callrmdir(struct puffs_mount *pmp, puffs_cookie_t dck, puffs_cookie_t ck,
195984d9c625SLionel Sambuc 	struct componentname *cnp)
196084d9c625SLionel Sambuc {
196184d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, rmdir);
196284d9c625SLionel Sambuc 	int error;
196384d9c625SLionel Sambuc 
196484d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, rmdir);
196584d9c625SLionel Sambuc 	rmdir_msg->pvnr_cookie_targ = ck;
196684d9c625SLionel Sambuc 	puffs_makecn(&rmdir_msg->pvnr_cn, &rmdir_msg->pvnr_cn_cred,
196784d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
196884d9c625SLionel Sambuc 	puffs_msg_setinfo(park_rmdir, PUFFSOP_VN, PUFFS_VN_RMDIR, dck);
196984d9c625SLionel Sambuc 
197084d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT(pmp, park_rmdir, error);
197184d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(rmdir);
197284d9c625SLionel Sambuc 
197384d9c625SLionel Sambuc 	return checkerr(pmp, error, __func__);
197484d9c625SLionel Sambuc }
197584d9c625SLionel Sambuc 
197684d9c625SLionel Sambuc int
puffs_vnop_rmdir(void * v)197784d9c625SLionel Sambuc puffs_vnop_rmdir(void *v)
197884d9c625SLionel Sambuc {
197984d9c625SLionel Sambuc 	struct vop_rmdir_args /* {
198084d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
198184d9c625SLionel Sambuc 		struct vnode *a_dvp;
198284d9c625SLionel Sambuc 		struct vnode *a_vp;
198384d9c625SLionel Sambuc 		struct componentname *a_cnp;
198484d9c625SLionel Sambuc 	} */ *ap = v;
198584d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, rmdir);
198684d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
198784d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
198884d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
198984d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
199084d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
199184d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
199284d9c625SLionel Sambuc 	int error;
199384d9c625SLionel Sambuc 
199484d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, rmdir);
199584d9c625SLionel Sambuc 	rmdir_msg->pvnr_cookie_targ = VPTOPNC(vp);
199684d9c625SLionel Sambuc 	puffs_makecn(&rmdir_msg->pvnr_cn, &rmdir_msg->pvnr_cn_cred,
199784d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
199884d9c625SLionel Sambuc 	puffs_msg_setinfo(park_rmdir, PUFFSOP_VN,
199984d9c625SLionel Sambuc 	    PUFFS_VN_RMDIR, VPTOPNC(dvp));
200084d9c625SLionel Sambuc 
200184d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_rmdir);
200284d9c625SLionel Sambuc 	REFPN_AND_UNLOCKVP(dvp, dpn);
200384d9c625SLionel Sambuc 	REFPN_AND_UNLOCKVP(vp, pn);
200484d9c625SLionel Sambuc 	error = puffs_msg_wait2(pmp, park_rmdir, dpn, pn);
200584d9c625SLionel Sambuc 
200684d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(rmdir);
200784d9c625SLionel Sambuc 
2008*0a6a1f1dSLionel Sambuc 	puffs_updatenode(VPTOPP(dvp), PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2009*0a6a1f1dSLionel Sambuc 
201084d9c625SLionel Sambuc 	/* XXX: some call cache_purge() *for both vnodes* here, investigate */
201184d9c625SLionel Sambuc 	RELEPN_AND_VP(dvp, dpn);
201284d9c625SLionel Sambuc 	RELEPN_AND_VP(vp, pn);
201384d9c625SLionel Sambuc 
201484d9c625SLionel Sambuc 	return error;
201584d9c625SLionel Sambuc }
201684d9c625SLionel Sambuc 
201784d9c625SLionel Sambuc int
puffs_vnop_link(void * v)201884d9c625SLionel Sambuc puffs_vnop_link(void *v)
201984d9c625SLionel Sambuc {
2020*0a6a1f1dSLionel Sambuc 	struct vop_link_v2_args /* {
202184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
202284d9c625SLionel Sambuc 		struct vnode *a_dvp;
202384d9c625SLionel Sambuc 		struct vnode *a_vp;
202484d9c625SLionel Sambuc 		struct componentname *a_cnp;
202584d9c625SLionel Sambuc 	} */ *ap = v;
202684d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, link);
202784d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
202884d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
202984d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
203084d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
203184d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
203284d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
203384d9c625SLionel Sambuc 	int error;
203484d9c625SLionel Sambuc 
203584d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, link);
203684d9c625SLionel Sambuc 	link_msg->pvnr_cookie_targ = VPTOPNC(vp);
203784d9c625SLionel Sambuc 	puffs_makecn(&link_msg->pvnr_cn, &link_msg->pvnr_cn_cred,
203884d9c625SLionel Sambuc 	    cnp, PUFFS_USE_FULLPNBUF(pmp));
203984d9c625SLionel Sambuc 	puffs_msg_setinfo(park_link, PUFFSOP_VN,
204084d9c625SLionel Sambuc 	    PUFFS_VN_LINK, VPTOPNC(dvp));
204184d9c625SLionel Sambuc 
204284d9c625SLionel Sambuc 	puffs_msg_enqueue(pmp, park_link);
204384d9c625SLionel Sambuc 	error = puffs_msg_wait2(pmp, park_link, dpn, pn);
204484d9c625SLionel Sambuc 
204584d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(link);
204684d9c625SLionel Sambuc 
204784d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
204884d9c625SLionel Sambuc 
204984d9c625SLionel Sambuc 	/*
205084d9c625SLionel Sambuc 	 * XXX: stay in touch with the cache.  I don't like this, but
205184d9c625SLionel Sambuc 	 * don't have a better solution either.  See also puffs_rename().
205284d9c625SLionel Sambuc 	 */
2053*0a6a1f1dSLionel Sambuc 	if (error == 0) {
205484d9c625SLionel Sambuc 		puffs_updatenode(pn, PUFFS_UPDATECTIME, 0);
2055*0a6a1f1dSLionel Sambuc 		puffs_updatenode(VPTOPP(dvp),
2056*0a6a1f1dSLionel Sambuc 				 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2057*0a6a1f1dSLionel Sambuc 	}
205884d9c625SLionel Sambuc 
205984d9c625SLionel Sambuc 	return error;
206084d9c625SLionel Sambuc }
206184d9c625SLionel Sambuc 
206284d9c625SLionel Sambuc int
puffs_vnop_symlink(void * v)206384d9c625SLionel Sambuc puffs_vnop_symlink(void *v)
206484d9c625SLionel Sambuc {
2065*0a6a1f1dSLionel Sambuc 	struct vop_symlink_v3_args /* {
206684d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
206784d9c625SLionel Sambuc 		struct vnode *a_dvp;
206884d9c625SLionel Sambuc 		struct vnode **a_vpp;
206984d9c625SLionel Sambuc 		struct componentname *a_cnp;
207084d9c625SLionel Sambuc 		struct vattr *a_vap;
207184d9c625SLionel Sambuc 		char *a_target;
207284d9c625SLionel Sambuc 	} */ *ap = v;
207384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, symlink);
207484d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
207584d9c625SLionel Sambuc 	struct puffs_node *dpn = VPTOPP(dvp);
207684d9c625SLionel Sambuc 	struct mount *mp = dvp->v_mount;
207784d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
207884d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
207984d9c625SLionel Sambuc 	int error;
208084d9c625SLionel Sambuc 
208184d9c625SLionel Sambuc 	*ap->a_vpp = NULL;
208284d9c625SLionel Sambuc 
208384d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, symlink);
208484d9c625SLionel Sambuc 	puffs_makecn(&symlink_msg->pvnr_cn, &symlink_msg->pvnr_cn_cred,
208584d9c625SLionel Sambuc 		cnp, PUFFS_USE_FULLPNBUF(pmp));
208684d9c625SLionel Sambuc 	symlink_msg->pvnr_va = *ap->a_vap;
208784d9c625SLionel Sambuc 	(void)strlcpy(symlink_msg->pvnr_link, ap->a_target,
208884d9c625SLionel Sambuc 	    sizeof(symlink_msg->pvnr_link));
208984d9c625SLionel Sambuc 	puffs_msg_setinfo(park_symlink, PUFFSOP_VN,
209084d9c625SLionel Sambuc 	    PUFFS_VN_SYMLINK, VPTOPNC(dvp));
209184d9c625SLionel Sambuc 
209284d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_symlink, dvp->v_data, NULL, error);
209384d9c625SLionel Sambuc 
209484d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
209584d9c625SLionel Sambuc 	if (error)
209684d9c625SLionel Sambuc 		goto out;
209784d9c625SLionel Sambuc 
209884d9c625SLionel Sambuc 	error = puffs_newnode(mp, dvp, ap->a_vpp,
209984d9c625SLionel Sambuc 	    symlink_msg->pvnr_newnode, cnp, VLNK, 0);
210084d9c625SLionel Sambuc 	if (error) {
210184d9c625SLionel Sambuc 		puffs_abortbutton(pmp, PUFFS_ABORT_SYMLINK, dpn->pn_cookie,
210284d9c625SLionel Sambuc 		    symlink_msg->pvnr_newnode, cnp);
210384d9c625SLionel Sambuc 		goto out;
210484d9c625SLionel Sambuc 	}
210584d9c625SLionel Sambuc 
210684d9c625SLionel Sambuc 	if (PUFFS_USE_FS_TTL(pmp)) {
210784d9c625SLionel Sambuc 		struct timespec *va_ttl = &symlink_msg->pvnr_va_ttl;
210884d9c625SLionel Sambuc 		struct timespec *cn_ttl = &symlink_msg->pvnr_cn_ttl;
210984d9c625SLionel Sambuc 		struct vattr *rvap = &symlink_msg->pvnr_va;
211084d9c625SLionel Sambuc 
211184d9c625SLionel Sambuc 		update_va(*ap->a_vpp, NULL, rvap,
211284d9c625SLionel Sambuc 			  va_ttl, cn_ttl, SETATTR_CHSIZE);
211384d9c625SLionel Sambuc 	}
211484d9c625SLionel Sambuc 
211584d9c625SLionel Sambuc 	VPTOPP(*ap->a_vpp)->pn_nlookup++;
211684d9c625SLionel Sambuc 
211784d9c625SLionel Sambuc 	if (PUFFS_USE_DOTDOTCACHE(pmp) &&
211884d9c625SLionel Sambuc 	    (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
211984d9c625SLionel Sambuc 		update_parent(*ap->a_vpp, dvp);
212084d9c625SLionel Sambuc 
212184d9c625SLionel Sambuc  out:
212284d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(symlink);
212384d9c625SLionel Sambuc 
212484d9c625SLionel Sambuc 	return error;
212584d9c625SLionel Sambuc }
212684d9c625SLionel Sambuc 
212784d9c625SLionel Sambuc int
puffs_vnop_readlink(void * v)212884d9c625SLionel Sambuc puffs_vnop_readlink(void *v)
212984d9c625SLionel Sambuc {
213084d9c625SLionel Sambuc 	struct vop_readlink_args /* {
213184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
213284d9c625SLionel Sambuc 		struct vnode *a_vp;
213384d9c625SLionel Sambuc 		struct uio *a_uio;
213484d9c625SLionel Sambuc 		kauth_cred_t a_cred;
213584d9c625SLionel Sambuc 	} */ *ap = v;
213684d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, readlink);
213784d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
213884d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
213984d9c625SLionel Sambuc 	size_t linklen;
214084d9c625SLionel Sambuc 	int error;
214184d9c625SLionel Sambuc 
214284d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, readlink);
214384d9c625SLionel Sambuc 	puffs_credcvt(&readlink_msg->pvnr_cred, ap->a_cred);
214484d9c625SLionel Sambuc 	linklen = sizeof(readlink_msg->pvnr_link);
214584d9c625SLionel Sambuc 	readlink_msg->pvnr_linklen = linklen;
214684d9c625SLionel Sambuc 	puffs_msg_setinfo(park_readlink, PUFFSOP_VN,
214784d9c625SLionel Sambuc 	    PUFFS_VN_READLINK, VPTOPNC(vp));
214884d9c625SLionel Sambuc 
214984d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_readlink, vp->v_data, NULL, error);
215084d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
215184d9c625SLionel Sambuc 	if (error)
215284d9c625SLionel Sambuc 		goto out;
215384d9c625SLionel Sambuc 
215484d9c625SLionel Sambuc 	/* bad bad user file server */
215584d9c625SLionel Sambuc 	if (readlink_msg->pvnr_linklen > linklen) {
215684d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_READLINK, E2BIG,
215784d9c625SLionel Sambuc 		    "linklen too big", VPTOPNC(ap->a_vp));
215884d9c625SLionel Sambuc 		error = EPROTO;
215984d9c625SLionel Sambuc 		goto out;
216084d9c625SLionel Sambuc 	}
216184d9c625SLionel Sambuc 
216284d9c625SLionel Sambuc 	error = uiomove(&readlink_msg->pvnr_link, readlink_msg->pvnr_linklen,
216384d9c625SLionel Sambuc 	    ap->a_uio);
216484d9c625SLionel Sambuc  out:
216584d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(readlink);
216684d9c625SLionel Sambuc 	return error;
216784d9c625SLionel Sambuc }
216884d9c625SLionel Sambuc 
216984d9c625SLionel Sambuc int
puffs_vnop_rename(void * v)217084d9c625SLionel Sambuc puffs_vnop_rename(void *v)
217184d9c625SLionel Sambuc {
217284d9c625SLionel Sambuc 	struct vop_rename_args /* {
217384d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
217484d9c625SLionel Sambuc 		struct vnode *a_fdvp;
217584d9c625SLionel Sambuc 		struct vnode *a_fvp;
217684d9c625SLionel Sambuc 		struct componentname *a_fcnp;
217784d9c625SLionel Sambuc 		struct vnode *a_tdvp;
217884d9c625SLionel Sambuc 		struct vnode *a_tvp;
217984d9c625SLionel Sambuc 		struct componentname *a_tcnp;
218084d9c625SLionel Sambuc 	} */ *ap = v;
218184d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, rename);
218284d9c625SLionel Sambuc 	struct vnode *fdvp = ap->a_fdvp, *fvp = ap->a_fvp;
218384d9c625SLionel Sambuc 	struct vnode *tdvp = ap->a_tdvp, *tvp = ap->a_tvp;
218484d9c625SLionel Sambuc 	struct puffs_node *fpn = ap->a_fvp->v_data;
218584d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(fdvp->v_mount);
218684d9c625SLionel Sambuc 	int error;
218784d9c625SLionel Sambuc 	bool doabort = true;
218884d9c625SLionel Sambuc 
218984d9c625SLionel Sambuc 	if ((fvp->v_mount != tdvp->v_mount) ||
219084d9c625SLionel Sambuc 	    (tvp && (fvp->v_mount != tvp->v_mount))) {
219184d9c625SLionel Sambuc 		ERROUT(EXDEV);
219284d9c625SLionel Sambuc 	}
219384d9c625SLionel Sambuc 
219484d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, rename);
219584d9c625SLionel Sambuc 	rename_msg->pvnr_cookie_src = VPTOPNC(fvp);
219684d9c625SLionel Sambuc 	rename_msg->pvnr_cookie_targdir = VPTOPNC(tdvp);
219784d9c625SLionel Sambuc 	if (tvp)
219884d9c625SLionel Sambuc 		rename_msg->pvnr_cookie_targ = VPTOPNC(tvp);
219984d9c625SLionel Sambuc 	else
220084d9c625SLionel Sambuc 		rename_msg->pvnr_cookie_targ = NULL;
220184d9c625SLionel Sambuc 	puffs_makecn(&rename_msg->pvnr_cn_src, &rename_msg->pvnr_cn_src_cred,
220284d9c625SLionel Sambuc 	    ap->a_fcnp, PUFFS_USE_FULLPNBUF(pmp));
220384d9c625SLionel Sambuc 	puffs_makecn(&rename_msg->pvnr_cn_targ, &rename_msg->pvnr_cn_targ_cred,
220484d9c625SLionel Sambuc 	    ap->a_tcnp, PUFFS_USE_FULLPNBUF(pmp));
220584d9c625SLionel Sambuc 	puffs_msg_setinfo(park_rename, PUFFSOP_VN,
220684d9c625SLionel Sambuc 	    PUFFS_VN_RENAME, VPTOPNC(fdvp));
220784d9c625SLionel Sambuc 
220884d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rename, fdvp->v_data, NULL, error);
220984d9c625SLionel Sambuc 	doabort = false;
221084d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(rename);
221184d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
221284d9c625SLionel Sambuc 
221384d9c625SLionel Sambuc 	/*
221484d9c625SLionel Sambuc 	 * XXX: stay in touch with the cache.  I don't like this, but
221584d9c625SLionel Sambuc 	 * don't have a better solution either.  See also puffs_link().
221684d9c625SLionel Sambuc 	 */
221784d9c625SLionel Sambuc 	if (error == 0) {
221884d9c625SLionel Sambuc 		puffs_updatenode(fpn, PUFFS_UPDATECTIME, 0);
2219*0a6a1f1dSLionel Sambuc 		puffs_updatenode(VPTOPP(fdvp),
2220*0a6a1f1dSLionel Sambuc 				 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2221*0a6a1f1dSLionel Sambuc 		if (fdvp != tdvp)
2222*0a6a1f1dSLionel Sambuc 			puffs_updatenode(VPTOPP(tdvp),
2223*0a6a1f1dSLionel Sambuc 					 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME,
2224*0a6a1f1dSLionel Sambuc 					 0);
222584d9c625SLionel Sambuc 
222684d9c625SLionel Sambuc 		if (PUFFS_USE_DOTDOTCACHE(pmp) &&
222784d9c625SLionel Sambuc 		    (VPTOPP(fvp)->pn_parent != tdvp))
222884d9c625SLionel Sambuc 			update_parent(fvp, tdvp);
222984d9c625SLionel Sambuc 	}
223084d9c625SLionel Sambuc 
223184d9c625SLionel Sambuc 
223284d9c625SLionel Sambuc  out:
223384d9c625SLionel Sambuc 	if (doabort)
223484d9c625SLionel Sambuc 		VOP_ABORTOP(tdvp, ap->a_tcnp);
223584d9c625SLionel Sambuc 	if (tvp != NULL)
223684d9c625SLionel Sambuc 		vput(tvp);
223784d9c625SLionel Sambuc 	if (tdvp == tvp)
223884d9c625SLionel Sambuc 		vrele(tdvp);
223984d9c625SLionel Sambuc 	else
224084d9c625SLionel Sambuc 		vput(tdvp);
224184d9c625SLionel Sambuc 
224284d9c625SLionel Sambuc 	if (doabort)
224384d9c625SLionel Sambuc 		VOP_ABORTOP(fdvp, ap->a_fcnp);
224484d9c625SLionel Sambuc 	vrele(fdvp);
224584d9c625SLionel Sambuc 	vrele(fvp);
224684d9c625SLionel Sambuc 
224784d9c625SLionel Sambuc 	return error;
224884d9c625SLionel Sambuc }
224984d9c625SLionel Sambuc 
225084d9c625SLionel Sambuc #define RWARGS(cont, iofl, move, offset, creds)				\
225184d9c625SLionel Sambuc 	(cont)->pvnr_ioflag = (iofl);					\
225284d9c625SLionel Sambuc 	(cont)->pvnr_resid = (move);					\
225384d9c625SLionel Sambuc 	(cont)->pvnr_offset = (offset);					\
225484d9c625SLionel Sambuc 	puffs_credcvt(&(cont)->pvnr_cred, creds)
225584d9c625SLionel Sambuc 
225684d9c625SLionel Sambuc int
puffs_vnop_read(void * v)225784d9c625SLionel Sambuc puffs_vnop_read(void *v)
225884d9c625SLionel Sambuc {
225984d9c625SLionel Sambuc 	struct vop_read_args /* {
226084d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
226184d9c625SLionel Sambuc 		struct vnode *a_vp;
226284d9c625SLionel Sambuc 		struct uio *a_uio;
226384d9c625SLionel Sambuc 		int a_ioflag;
226484d9c625SLionel Sambuc 		kauth_cred_t a_cred;
226584d9c625SLionel Sambuc 	} */ *ap = v;
226684d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, read);
226784d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
2268*0a6a1f1dSLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
226984d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
227084d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
227184d9c625SLionel Sambuc 	size_t tomove, argsize;
227284d9c625SLionel Sambuc 	vsize_t bytelen;
227384d9c625SLionel Sambuc 	int error;
227484d9c625SLionel Sambuc 
227584d9c625SLionel Sambuc 	read_msg = NULL;
227684d9c625SLionel Sambuc 	error = 0;
227784d9c625SLionel Sambuc 
227884d9c625SLionel Sambuc 	/* std sanity */
227984d9c625SLionel Sambuc 	if (uio->uio_resid == 0)
228084d9c625SLionel Sambuc 		return 0;
228184d9c625SLionel Sambuc 	if (uio->uio_offset < 0)
2282*0a6a1f1dSLionel Sambuc 		return EFBIG;
228384d9c625SLionel Sambuc 
2284*0a6a1f1dSLionel Sambuc 	/*
2285*0a6a1f1dSLionel Sambuc 	 * On the case of reading empty files and (vp->v_size != 0) below:
2286*0a6a1f1dSLionel Sambuc 	 * some filesystems (hint: FUSE and distributed filesystems) still
2287*0a6a1f1dSLionel Sambuc 	 * expect to get the READ in order to update atime. Reading through
2288*0a6a1f1dSLionel Sambuc 	 * the case filters empty files, therefore we prefer to bypass the
2289*0a6a1f1dSLionel Sambuc 	 * cache here.
2290*0a6a1f1dSLionel Sambuc 	 */
2291*0a6a1f1dSLionel Sambuc 	if (vp->v_type == VREG &&
2292*0a6a1f1dSLionel Sambuc 	    PUFFS_USE_PAGECACHE(pmp) &&
2293*0a6a1f1dSLionel Sambuc 	    !(pn->pn_stat & PNODE_RDIRECT) &&
2294*0a6a1f1dSLionel Sambuc 	    (vp->v_size != 0)) {
229584d9c625SLionel Sambuc 		const int advice = IO_ADV_DECODE(ap->a_ioflag);
229684d9c625SLionel Sambuc 
229784d9c625SLionel Sambuc 		while (uio->uio_resid > 0) {
229884d9c625SLionel Sambuc 			if (vp->v_size <= uio->uio_offset) {
229984d9c625SLionel Sambuc 				break;
230084d9c625SLionel Sambuc 			}
230184d9c625SLionel Sambuc 			bytelen = MIN(uio->uio_resid,
230284d9c625SLionel Sambuc 			    vp->v_size - uio->uio_offset);
230384d9c625SLionel Sambuc 			if (bytelen == 0)
230484d9c625SLionel Sambuc 				break;
230584d9c625SLionel Sambuc 
230684d9c625SLionel Sambuc 			error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice,
230784d9c625SLionel Sambuc 			    UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
230884d9c625SLionel Sambuc 			if (error)
230984d9c625SLionel Sambuc 				break;
231084d9c625SLionel Sambuc 		}
231184d9c625SLionel Sambuc 
231284d9c625SLionel Sambuc 		if ((vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
231384d9c625SLionel Sambuc 			puffs_updatenode(VPTOPP(vp), PUFFS_UPDATEATIME, 0);
231484d9c625SLionel Sambuc 	} else {
231584d9c625SLionel Sambuc 		/*
231684d9c625SLionel Sambuc 		 * in case it's not a regular file or we're operating
231784d9c625SLionel Sambuc 		 * uncached, do read in the old-fashioned style,
231884d9c625SLionel Sambuc 		 * i.e. explicit read operations
231984d9c625SLionel Sambuc 		 */
232084d9c625SLionel Sambuc 
232184d9c625SLionel Sambuc 		tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
232284d9c625SLionel Sambuc 		argsize = sizeof(struct puffs_vnmsg_read);
232384d9c625SLionel Sambuc 		puffs_msgmem_alloc(argsize + tomove, &park_read,
232484d9c625SLionel Sambuc 		    (void *)&read_msg, 1);
232584d9c625SLionel Sambuc 
232684d9c625SLionel Sambuc 		error = 0;
232784d9c625SLionel Sambuc 		while (uio->uio_resid > 0) {
232884d9c625SLionel Sambuc 			tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
232984d9c625SLionel Sambuc 			memset(read_msg, 0, argsize); /* XXX: touser KASSERT */
233084d9c625SLionel Sambuc 			RWARGS(read_msg, ap->a_ioflag, tomove,
233184d9c625SLionel Sambuc 			    uio->uio_offset, ap->a_cred);
233284d9c625SLionel Sambuc 			puffs_msg_setinfo(park_read, PUFFSOP_VN,
233384d9c625SLionel Sambuc 			    PUFFS_VN_READ, VPTOPNC(vp));
233484d9c625SLionel Sambuc 			puffs_msg_setdelta(park_read, tomove);
233584d9c625SLionel Sambuc 
233684d9c625SLionel Sambuc 			PUFFS_MSG_ENQUEUEWAIT2(pmp, park_read, vp->v_data,
233784d9c625SLionel Sambuc 			    NULL, error);
233884d9c625SLionel Sambuc 			error = checkerr(pmp, error, __func__);
233984d9c625SLionel Sambuc 			if (error)
234084d9c625SLionel Sambuc 				break;
234184d9c625SLionel Sambuc 
234284d9c625SLionel Sambuc 			if (read_msg->pvnr_resid > tomove) {
234384d9c625SLionel Sambuc 				puffs_senderr(pmp, PUFFS_ERR_READ,
234484d9c625SLionel Sambuc 				    E2BIG, "resid grew", VPTOPNC(ap->a_vp));
234584d9c625SLionel Sambuc 				error = EPROTO;
234684d9c625SLionel Sambuc 				break;
234784d9c625SLionel Sambuc 			}
234884d9c625SLionel Sambuc 
234984d9c625SLionel Sambuc 			error = uiomove(read_msg->pvnr_data,
235084d9c625SLionel Sambuc 			    tomove - read_msg->pvnr_resid, uio);
235184d9c625SLionel Sambuc 
235284d9c625SLionel Sambuc 			/*
235384d9c625SLionel Sambuc 			 * in case the file is out of juice, resid from
235484d9c625SLionel Sambuc 			 * userspace is != 0.  and the error-case is
235584d9c625SLionel Sambuc 			 * quite obvious
235684d9c625SLionel Sambuc 			 */
235784d9c625SLionel Sambuc 			if (error || read_msg->pvnr_resid)
235884d9c625SLionel Sambuc 				break;
235984d9c625SLionel Sambuc 		}
236084d9c625SLionel Sambuc 
236184d9c625SLionel Sambuc 		puffs_msgmem_release(park_read);
236284d9c625SLionel Sambuc 	}
236384d9c625SLionel Sambuc 
236484d9c625SLionel Sambuc 	return error;
236584d9c625SLionel Sambuc }
236684d9c625SLionel Sambuc 
236784d9c625SLionel Sambuc /*
236884d9c625SLionel Sambuc  * XXX: in case of a failure, this leaves uio in a bad state.
236984d9c625SLionel Sambuc  * We could theoretically copy the uio and iovecs and "replay"
237084d9c625SLionel Sambuc  * them the right amount after the userspace trip, but don't
237184d9c625SLionel Sambuc  * bother for now.
237284d9c625SLionel Sambuc  */
237384d9c625SLionel Sambuc int
puffs_vnop_write(void * v)237484d9c625SLionel Sambuc puffs_vnop_write(void *v)
237584d9c625SLionel Sambuc {
237684d9c625SLionel Sambuc 	struct vop_write_args /* {
237784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
237884d9c625SLionel Sambuc 		struct vnode *a_vp;
237984d9c625SLionel Sambuc 		struct uio *a_uio;
238084d9c625SLionel Sambuc 		int a_ioflag;
238184d9c625SLionel Sambuc 		kauth_cred_t a_cred;
238284d9c625SLionel Sambuc 	} */ *ap = v;
238384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, write);
238484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
238584d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
238684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
238784d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
238884d9c625SLionel Sambuc 	size_t tomove, argsize;
238984d9c625SLionel Sambuc 	off_t oldoff, newoff, origoff;
239084d9c625SLionel Sambuc 	vsize_t bytelen;
239184d9c625SLionel Sambuc 	int error, uflags;
239284d9c625SLionel Sambuc 	int ubcflags;
239384d9c625SLionel Sambuc 
239484d9c625SLionel Sambuc 	error = uflags = 0;
239584d9c625SLionel Sambuc 	write_msg = NULL;
239684d9c625SLionel Sambuc 
2397*0a6a1f1dSLionel Sambuc 	/* std sanity */
2398*0a6a1f1dSLionel Sambuc 	if (uio->uio_resid == 0)
2399*0a6a1f1dSLionel Sambuc 		return 0;
2400*0a6a1f1dSLionel Sambuc 	if (uio->uio_offset < 0)
2401*0a6a1f1dSLionel Sambuc 		return EFBIG;
240284d9c625SLionel Sambuc 
2403*0a6a1f1dSLionel Sambuc 	mutex_enter(&pn->pn_sizemtx);
240484d9c625SLionel Sambuc 
240584d9c625SLionel Sambuc 	/*
240684d9c625SLionel Sambuc 	 * userspace *should* be allowed to control this,
240784d9c625SLionel Sambuc 	 * but with UBC it's a bit unclear how to handle it
240884d9c625SLionel Sambuc 	 */
240984d9c625SLionel Sambuc 	if (ap->a_ioflag & IO_APPEND)
241084d9c625SLionel Sambuc 		uio->uio_offset = vp->v_size;
241184d9c625SLionel Sambuc 
241284d9c625SLionel Sambuc 	origoff = uio->uio_offset;
2413*0a6a1f1dSLionel Sambuc 
2414*0a6a1f1dSLionel Sambuc 	if (vp->v_type == VREG &&
2415*0a6a1f1dSLionel Sambuc 	    PUFFS_USE_PAGECACHE(pmp) &&
2416*0a6a1f1dSLionel Sambuc 	    !(pn->pn_stat & PNODE_WDIRECT)) {
2417*0a6a1f1dSLionel Sambuc 		ubcflags = UBC_WRITE | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp);
2418*0a6a1f1dSLionel Sambuc 
241984d9c625SLionel Sambuc 		while (uio->uio_resid > 0) {
242084d9c625SLionel Sambuc 			oldoff = uio->uio_offset;
242184d9c625SLionel Sambuc 			bytelen = uio->uio_resid;
242284d9c625SLionel Sambuc 
242384d9c625SLionel Sambuc 			newoff = oldoff + bytelen;
242484d9c625SLionel Sambuc 			if (vp->v_size < newoff) {
242584d9c625SLionel Sambuc 				uvm_vnp_setwritesize(vp, newoff);
242684d9c625SLionel Sambuc 			}
242784d9c625SLionel Sambuc 			error = ubc_uiomove(&vp->v_uobj, uio, bytelen,
242884d9c625SLionel Sambuc 			    UVM_ADV_RANDOM, ubcflags);
242984d9c625SLionel Sambuc 
243084d9c625SLionel Sambuc 			/*
243184d9c625SLionel Sambuc 			 * In case of a ubc_uiomove() error,
243284d9c625SLionel Sambuc 			 * opt to not extend the file at all and
243384d9c625SLionel Sambuc 			 * return an error.  Otherwise, if we attempt
243484d9c625SLionel Sambuc 			 * to clear the memory we couldn't fault to,
243584d9c625SLionel Sambuc 			 * we might generate a kernel page fault.
243684d9c625SLionel Sambuc 			 */
243784d9c625SLionel Sambuc 			if (vp->v_size < newoff) {
243884d9c625SLionel Sambuc 				if (error == 0) {
243984d9c625SLionel Sambuc 					uflags |= PUFFS_UPDATESIZE;
244084d9c625SLionel Sambuc 					uvm_vnp_setsize(vp, newoff);
244184d9c625SLionel Sambuc 				} else {
244284d9c625SLionel Sambuc 					uvm_vnp_setwritesize(vp, vp->v_size);
244384d9c625SLionel Sambuc 				}
244484d9c625SLionel Sambuc 			}
244584d9c625SLionel Sambuc 			if (error)
244684d9c625SLionel Sambuc 				break;
244784d9c625SLionel Sambuc 
244884d9c625SLionel Sambuc 			/*
244984d9c625SLionel Sambuc 			 * If we're writing large files, flush to file server
245084d9c625SLionel Sambuc 			 * every 64k.  Otherwise we can very easily exhaust
245184d9c625SLionel Sambuc 			 * kernel and user memory, as the file server cannot
245284d9c625SLionel Sambuc 			 * really keep up with our writing speed.
245384d9c625SLionel Sambuc 			 *
245484d9c625SLionel Sambuc 			 * Note: this does *NOT* honor MNT_ASYNC, because
245584d9c625SLionel Sambuc 			 * that gives userland too much say in the kernel.
245684d9c625SLionel Sambuc 			 */
245784d9c625SLionel Sambuc 			if (oldoff >> 16 != uio->uio_offset >> 16) {
245884d9c625SLionel Sambuc 				mutex_enter(vp->v_interlock);
245984d9c625SLionel Sambuc 				error = VOP_PUTPAGES(vp, oldoff & ~0xffff,
246084d9c625SLionel Sambuc 				    uio->uio_offset & ~0xffff,
246184d9c625SLionel Sambuc 				    PGO_CLEANIT | PGO_SYNCIO);
246284d9c625SLionel Sambuc 				if (error)
246384d9c625SLionel Sambuc 					break;
246484d9c625SLionel Sambuc 			}
246584d9c625SLionel Sambuc 		}
246684d9c625SLionel Sambuc 
246784d9c625SLionel Sambuc 		/* synchronous I/O? */
246884d9c625SLionel Sambuc 		if (error == 0 && ap->a_ioflag & IO_SYNC) {
246984d9c625SLionel Sambuc 			mutex_enter(vp->v_interlock);
247084d9c625SLionel Sambuc 			error = VOP_PUTPAGES(vp, trunc_page(origoff),
247184d9c625SLionel Sambuc 			    round_page(uio->uio_offset),
247284d9c625SLionel Sambuc 			    PGO_CLEANIT | PGO_SYNCIO);
247384d9c625SLionel Sambuc 
247484d9c625SLionel Sambuc 		/* write through page cache? */
247584d9c625SLionel Sambuc 		} else if (error == 0 && pmp->pmp_flags & PUFFS_KFLAG_WTCACHE) {
247684d9c625SLionel Sambuc 			mutex_enter(vp->v_interlock);
247784d9c625SLionel Sambuc 			error = VOP_PUTPAGES(vp, trunc_page(origoff),
247884d9c625SLionel Sambuc 			    round_page(uio->uio_offset), PGO_CLEANIT);
247984d9c625SLionel Sambuc 		}
248084d9c625SLionel Sambuc 	} else {
248184d9c625SLionel Sambuc 		/* tomove is non-increasing */
248284d9c625SLionel Sambuc 		tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
248384d9c625SLionel Sambuc 		argsize = sizeof(struct puffs_vnmsg_write) + tomove;
248484d9c625SLionel Sambuc 		puffs_msgmem_alloc(argsize, &park_write, (void *)&write_msg,1);
248584d9c625SLionel Sambuc 
248684d9c625SLionel Sambuc 		while (uio->uio_resid > 0) {
248784d9c625SLionel Sambuc 			/* move data to buffer */
248884d9c625SLionel Sambuc 			tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
248984d9c625SLionel Sambuc 			memset(write_msg, 0, argsize); /* XXX: touser KASSERT */
249084d9c625SLionel Sambuc 			RWARGS(write_msg, ap->a_ioflag, tomove,
249184d9c625SLionel Sambuc 			    uio->uio_offset, ap->a_cred);
249284d9c625SLionel Sambuc 			error = uiomove(write_msg->pvnr_data, tomove, uio);
249384d9c625SLionel Sambuc 			if (error)
249484d9c625SLionel Sambuc 				break;
249584d9c625SLionel Sambuc 
249684d9c625SLionel Sambuc 			/* move buffer to userspace */
249784d9c625SLionel Sambuc 			puffs_msg_setinfo(park_write, PUFFSOP_VN,
249884d9c625SLionel Sambuc 			    PUFFS_VN_WRITE, VPTOPNC(vp));
249984d9c625SLionel Sambuc 			PUFFS_MSG_ENQUEUEWAIT2(pmp, park_write, vp->v_data,
250084d9c625SLionel Sambuc 			    NULL, error);
250184d9c625SLionel Sambuc 			error = checkerr(pmp, error, __func__);
250284d9c625SLionel Sambuc 			if (error)
250384d9c625SLionel Sambuc 				break;
250484d9c625SLionel Sambuc 
250584d9c625SLionel Sambuc 			if (write_msg->pvnr_resid > tomove) {
250684d9c625SLionel Sambuc 				puffs_senderr(pmp, PUFFS_ERR_WRITE,
250784d9c625SLionel Sambuc 				    E2BIG, "resid grew", VPTOPNC(ap->a_vp));
250884d9c625SLionel Sambuc 				error = EPROTO;
250984d9c625SLionel Sambuc 				break;
251084d9c625SLionel Sambuc 			}
251184d9c625SLionel Sambuc 
251284d9c625SLionel Sambuc 			/* adjust file size */
2513*0a6a1f1dSLionel Sambuc 			if (vp->v_size < uio->uio_offset) {
2514*0a6a1f1dSLionel Sambuc 				uflags |= PUFFS_UPDATESIZE;
251584d9c625SLionel Sambuc 				uvm_vnp_setsize(vp, uio->uio_offset);
2516*0a6a1f1dSLionel Sambuc 			}
251784d9c625SLionel Sambuc 
251884d9c625SLionel Sambuc 			/* didn't move everything?  bad userspace.  bail */
251984d9c625SLionel Sambuc 			if (write_msg->pvnr_resid != 0) {
252084d9c625SLionel Sambuc 				error = EIO;
252184d9c625SLionel Sambuc 				break;
252284d9c625SLionel Sambuc 			}
252384d9c625SLionel Sambuc 		}
252484d9c625SLionel Sambuc 		puffs_msgmem_release(park_write);
2525*0a6a1f1dSLionel Sambuc 
2526*0a6a1f1dSLionel Sambuc 		/*
2527*0a6a1f1dSLionel Sambuc 		 * Direct I/O on write but not on read: we must
2528*0a6a1f1dSLionel Sambuc 		 * invlidate the written pages so that we read
2529*0a6a1f1dSLionel Sambuc 		 * the written data and not the stalled cache.
2530*0a6a1f1dSLionel Sambuc 		 */
2531*0a6a1f1dSLionel Sambuc 		if ((error == 0) &&
2532*0a6a1f1dSLionel Sambuc 		    (vp->v_type == VREG) && PUFFS_USE_PAGECACHE(pmp) &&
2533*0a6a1f1dSLionel Sambuc 		    (pn->pn_stat & PNODE_WDIRECT) &&
2534*0a6a1f1dSLionel Sambuc 		    !(pn->pn_stat & PNODE_RDIRECT)) {
2535*0a6a1f1dSLionel Sambuc 			voff_t off_lo = trunc_page(origoff);
2536*0a6a1f1dSLionel Sambuc 			voff_t off_hi = round_page(uio->uio_offset);
2537*0a6a1f1dSLionel Sambuc 
2538*0a6a1f1dSLionel Sambuc 			mutex_enter(vp->v_uobj.vmobjlock);
2539*0a6a1f1dSLionel Sambuc 			error = VOP_PUTPAGES(vp, off_lo, off_hi, PGO_FREE);
2540*0a6a1f1dSLionel Sambuc 		}
254184d9c625SLionel Sambuc 	}
254284d9c625SLionel Sambuc 
2543*0a6a1f1dSLionel Sambuc 	if (vp->v_mount->mnt_flag & MNT_RELATIME)
2544*0a6a1f1dSLionel Sambuc 		uflags |= PUFFS_UPDATEATIME;
2545*0a6a1f1dSLionel Sambuc 	uflags |= PUFFS_UPDATECTIME;
2546*0a6a1f1dSLionel Sambuc 	uflags |= PUFFS_UPDATEMTIME;
2547*0a6a1f1dSLionel Sambuc 	puffs_updatenode(VPTOPP(vp), uflags, vp->v_size);
2548*0a6a1f1dSLionel Sambuc 
2549*0a6a1f1dSLionel Sambuc 	/*
2550*0a6a1f1dSLionel Sambuc 	 * If we do not use meta flush, we need to update the
2551*0a6a1f1dSLionel Sambuc 	 * filesystem now, otherwise we will get a stale value
2552*0a6a1f1dSLionel Sambuc 	 * on the next GETATTR
2553*0a6a1f1dSLionel Sambuc 	 */
2554*0a6a1f1dSLionel Sambuc 	if (!PUFFS_USE_METAFLUSH(pmp) && (uflags & PUFFS_UPDATESIZE)) {
2555*0a6a1f1dSLionel Sambuc 		struct vattr va;
2556*0a6a1f1dSLionel Sambuc 		int ret;
2557*0a6a1f1dSLionel Sambuc 
2558*0a6a1f1dSLionel Sambuc 		vattr_null(&va);
2559*0a6a1f1dSLionel Sambuc 		va.va_size = vp->v_size;
2560*0a6a1f1dSLionel Sambuc 		ret = dosetattr(vp, &va, FSCRED, 0);
2561*0a6a1f1dSLionel Sambuc 		if (ret) {
2562*0a6a1f1dSLionel Sambuc 			DPRINTF(("dosetattr set size to %jd failed: %d\n",
2563*0a6a1f1dSLionel Sambuc 			    (intmax_t)vp->v_size, ret));
2564*0a6a1f1dSLionel Sambuc 		}
2565*0a6a1f1dSLionel Sambuc 	}
256684d9c625SLionel Sambuc 	mutex_exit(&pn->pn_sizemtx);
256784d9c625SLionel Sambuc 	return error;
256884d9c625SLionel Sambuc }
256984d9c625SLionel Sambuc 
257084d9c625SLionel Sambuc int
puffs_vnop_fallocate(void * v)2571*0a6a1f1dSLionel Sambuc puffs_vnop_fallocate(void *v)
2572*0a6a1f1dSLionel Sambuc {
2573*0a6a1f1dSLionel Sambuc 	struct vop_fallocate_args /* {
2574*0a6a1f1dSLionel Sambuc 		const struct vnodeop_desc *a_desc;
2575*0a6a1f1dSLionel Sambuc 		struct vnode *a_vp;
2576*0a6a1f1dSLionel Sambuc 		off_t a_pos;
2577*0a6a1f1dSLionel Sambuc 		off_t a_len;
2578*0a6a1f1dSLionel Sambuc 	} */ *ap = v;
2579*0a6a1f1dSLionel Sambuc 	struct vnode *vp = ap->a_vp;
2580*0a6a1f1dSLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
2581*0a6a1f1dSLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2582*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_VARS(vn, fallocate);
2583*0a6a1f1dSLionel Sambuc 	int error;
2584*0a6a1f1dSLionel Sambuc 
2585*0a6a1f1dSLionel Sambuc 	mutex_enter(&pn->pn_sizemtx);
2586*0a6a1f1dSLionel Sambuc 
2587*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_ALLOC(vn, fallocate);
2588*0a6a1f1dSLionel Sambuc 	fallocate_msg->pvnr_off = ap->a_pos;
2589*0a6a1f1dSLionel Sambuc 	fallocate_msg->pvnr_len = ap->a_len;
2590*0a6a1f1dSLionel Sambuc 	puffs_msg_setinfo(park_fallocate, PUFFSOP_VN,
2591*0a6a1f1dSLionel Sambuc 	    PUFFS_VN_FALLOCATE, VPTOPNC(vp));
2592*0a6a1f1dSLionel Sambuc 
2593*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fallocate, vp->v_data, NULL, error);
2594*0a6a1f1dSLionel Sambuc 	error = checkerr(pmp, error, __func__);
2595*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_RELEASE(fallocate);
2596*0a6a1f1dSLionel Sambuc 
2597*0a6a1f1dSLionel Sambuc 	switch (error) {
2598*0a6a1f1dSLionel Sambuc 	case 0:
2599*0a6a1f1dSLionel Sambuc 		break;
2600*0a6a1f1dSLionel Sambuc 	case EAGAIN:
2601*0a6a1f1dSLionel Sambuc 		error = EIO;
2602*0a6a1f1dSLionel Sambuc 		/* FALLTHROUGH */
2603*0a6a1f1dSLionel Sambuc 	default:
2604*0a6a1f1dSLionel Sambuc 		goto out;
2605*0a6a1f1dSLionel Sambuc 	}
2606*0a6a1f1dSLionel Sambuc 
2607*0a6a1f1dSLionel Sambuc 	if (ap->a_pos + ap->a_len > vp->v_size) {
2608*0a6a1f1dSLionel Sambuc 		uvm_vnp_setsize(vp, ap->a_pos + ap->a_len);
2609*0a6a1f1dSLionel Sambuc 		puffs_updatenode(pn, PUFFS_UPDATESIZE, vp->v_size);
2610*0a6a1f1dSLionel Sambuc 	}
2611*0a6a1f1dSLionel Sambuc out:
2612*0a6a1f1dSLionel Sambuc  	mutex_exit(&pn->pn_sizemtx);
2613*0a6a1f1dSLionel Sambuc 
2614*0a6a1f1dSLionel Sambuc  	return error;
2615*0a6a1f1dSLionel Sambuc }
2616*0a6a1f1dSLionel Sambuc 
2617*0a6a1f1dSLionel Sambuc int
puffs_vnop_fdiscard(void * v)2618*0a6a1f1dSLionel Sambuc puffs_vnop_fdiscard(void *v)
2619*0a6a1f1dSLionel Sambuc {
2620*0a6a1f1dSLionel Sambuc 	struct vop_fdiscard_args /* {
2621*0a6a1f1dSLionel Sambuc 		const struct vnodeop_desc *a_desc;
2622*0a6a1f1dSLionel Sambuc 		struct vnode *a_vp;
2623*0a6a1f1dSLionel Sambuc 		off_t a_pos;
2624*0a6a1f1dSLionel Sambuc 		off_t a_len;
2625*0a6a1f1dSLionel Sambuc 	} */ *ap = v;
2626*0a6a1f1dSLionel Sambuc 	struct vnode *vp = ap->a_vp;
2627*0a6a1f1dSLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2628*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_VARS(vn, fdiscard);
2629*0a6a1f1dSLionel Sambuc 	int error;
2630*0a6a1f1dSLionel Sambuc 
2631*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_ALLOC(vn, fdiscard);
2632*0a6a1f1dSLionel Sambuc 	fdiscard_msg->pvnr_off = ap->a_pos;
2633*0a6a1f1dSLionel Sambuc 	fdiscard_msg->pvnr_len = ap->a_len;
2634*0a6a1f1dSLionel Sambuc 	puffs_msg_setinfo(park_fdiscard, PUFFSOP_VN,
2635*0a6a1f1dSLionel Sambuc 	    PUFFS_VN_FALLOCATE, VPTOPNC(vp));
2636*0a6a1f1dSLionel Sambuc 
2637*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fdiscard, vp->v_data, NULL, error);
2638*0a6a1f1dSLionel Sambuc 	error = checkerr(pmp, error, __func__);
2639*0a6a1f1dSLionel Sambuc 	PUFFS_MSG_RELEASE(fdiscard);
2640*0a6a1f1dSLionel Sambuc 
2641*0a6a1f1dSLionel Sambuc  	return error;
2642*0a6a1f1dSLionel Sambuc }
2643*0a6a1f1dSLionel Sambuc 
2644*0a6a1f1dSLionel Sambuc int
puffs_vnop_print(void * v)264584d9c625SLionel Sambuc puffs_vnop_print(void *v)
264684d9c625SLionel Sambuc {
264784d9c625SLionel Sambuc 	struct vop_print_args /* {
264884d9c625SLionel Sambuc 		struct vnode *a_vp;
264984d9c625SLionel Sambuc 	} */ *ap = v;
265084d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, print);
265184d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
265284d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
265384d9c625SLionel Sambuc 	struct puffs_node *pn = vp->v_data;
265484d9c625SLionel Sambuc 
265584d9c625SLionel Sambuc 	/* kernel portion */
265684d9c625SLionel Sambuc 	printf("tag VT_PUFFS, vnode %p, puffs node: %p,\n"
265784d9c625SLionel Sambuc 	    "\tuserspace cookie: %p", vp, pn, pn->pn_cookie);
265884d9c625SLionel Sambuc 	if (vp->v_type == VFIFO)
265984d9c625SLionel Sambuc 		VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v);
266084d9c625SLionel Sambuc 	printf("\n");
266184d9c625SLionel Sambuc 
266284d9c625SLionel Sambuc 	/* userspace portion */
266384d9c625SLionel Sambuc 	if (EXISTSOP(pmp, PRINT)) {
266484d9c625SLionel Sambuc 		PUFFS_MSG_ALLOC(vn, print);
266584d9c625SLionel Sambuc 		puffs_msg_setinfo(park_print, PUFFSOP_VN,
266684d9c625SLionel Sambuc 		    PUFFS_VN_PRINT, VPTOPNC(vp));
266784d9c625SLionel Sambuc 		PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_print, vp->v_data,
266884d9c625SLionel Sambuc 		    NULL);
266984d9c625SLionel Sambuc 		PUFFS_MSG_RELEASE(print);
267084d9c625SLionel Sambuc 	}
267184d9c625SLionel Sambuc 
267284d9c625SLionel Sambuc 	return 0;
267384d9c625SLionel Sambuc }
267484d9c625SLionel Sambuc 
267584d9c625SLionel Sambuc int
puffs_vnop_pathconf(void * v)267684d9c625SLionel Sambuc puffs_vnop_pathconf(void *v)
267784d9c625SLionel Sambuc {
267884d9c625SLionel Sambuc 	struct vop_pathconf_args /* {
267984d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
268084d9c625SLionel Sambuc 		struct vnode *a_vp;
268184d9c625SLionel Sambuc 		int a_name;
268284d9c625SLionel Sambuc 		register_t *a_retval;
268384d9c625SLionel Sambuc 	} */ *ap = v;
268484d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, pathconf);
268584d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
268684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
268784d9c625SLionel Sambuc 	int error;
268884d9c625SLionel Sambuc 
268984d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, pathconf);
269084d9c625SLionel Sambuc 	pathconf_msg->pvnr_name = ap->a_name;
269184d9c625SLionel Sambuc 	puffs_msg_setinfo(park_pathconf, PUFFSOP_VN,
269284d9c625SLionel Sambuc 	    PUFFS_VN_PATHCONF, VPTOPNC(vp));
269384d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_pathconf, vp->v_data, NULL, error);
269484d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
269584d9c625SLionel Sambuc 	if (!error)
269684d9c625SLionel Sambuc 		*ap->a_retval = pathconf_msg->pvnr_retval;
269784d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(pathconf);
269884d9c625SLionel Sambuc 
269984d9c625SLionel Sambuc 	return error;
270084d9c625SLionel Sambuc }
270184d9c625SLionel Sambuc 
270284d9c625SLionel Sambuc int
puffs_vnop_advlock(void * v)270384d9c625SLionel Sambuc puffs_vnop_advlock(void *v)
270484d9c625SLionel Sambuc {
270584d9c625SLionel Sambuc 	struct vop_advlock_args /* {
270684d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
270784d9c625SLionel Sambuc 		struct vnode *a_vp;
270884d9c625SLionel Sambuc 		void *a_id;
270984d9c625SLionel Sambuc 		int a_op;
271084d9c625SLionel Sambuc 		struct flock *a_fl;
271184d9c625SLionel Sambuc 		int a_flags;
271284d9c625SLionel Sambuc 	} */ *ap = v;
271384d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, advlock);
271484d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
271584d9c625SLionel Sambuc 	struct puffs_node *pn = VPTOPP(vp);
271684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
271784d9c625SLionel Sambuc 	int error;
271884d9c625SLionel Sambuc 
271984d9c625SLionel Sambuc 	if (!EXISTSOP(pmp, ADVLOCK))
272084d9c625SLionel Sambuc 		return lf_advlock(ap, &pn->pn_lockf, vp->v_size);
272184d9c625SLionel Sambuc 
272284d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, advlock);
272384d9c625SLionel Sambuc 	(void)memcpy(&advlock_msg->pvnr_fl, ap->a_fl,
272484d9c625SLionel Sambuc 		     sizeof(advlock_msg->pvnr_fl));
272584d9c625SLionel Sambuc 	advlock_msg->pvnr_id = ap->a_id;
272684d9c625SLionel Sambuc 	advlock_msg->pvnr_op = ap->a_op;
272784d9c625SLionel Sambuc 	advlock_msg->pvnr_flags = ap->a_flags;
272884d9c625SLionel Sambuc 	puffs_msg_setinfo(park_advlock, PUFFSOP_VN,
272984d9c625SLionel Sambuc 	    PUFFS_VN_ADVLOCK, VPTOPNC(vp));
273084d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_advlock, vp->v_data, NULL, error);
273184d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
273284d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(advlock);
273384d9c625SLionel Sambuc 
273484d9c625SLionel Sambuc 	return error;
273584d9c625SLionel Sambuc }
273684d9c625SLionel Sambuc 
273784d9c625SLionel Sambuc int
puffs_vnop_abortop(void * v)273884d9c625SLionel Sambuc puffs_vnop_abortop(void *v)
273984d9c625SLionel Sambuc {
274084d9c625SLionel Sambuc 	struct vop_abortop_args /* {
274184d9c625SLionel Sambuc 		struct vnode *a_dvp;
274284d9c625SLionel Sambuc 		struct componentname *a_cnp;
274384d9c625SLionel Sambuc 	}; */ *ap = v;
274484d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, abortop);
274584d9c625SLionel Sambuc 	struct vnode *dvp = ap->a_dvp;
274684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
274784d9c625SLionel Sambuc 	struct componentname *cnp = ap->a_cnp;
274884d9c625SLionel Sambuc 
274984d9c625SLionel Sambuc 	if (EXISTSOP(pmp, ABORTOP)) {
275084d9c625SLionel Sambuc 		PUFFS_MSG_ALLOC(vn, abortop);
275184d9c625SLionel Sambuc 		puffs_makecn(&abortop_msg->pvnr_cn, &abortop_msg->pvnr_cn_cred,
275284d9c625SLionel Sambuc 		    cnp, PUFFS_USE_FULLPNBUF(pmp));
275384d9c625SLionel Sambuc 		puffs_msg_setfaf(park_abortop);
275484d9c625SLionel Sambuc 		puffs_msg_setinfo(park_abortop, PUFFSOP_VN,
275584d9c625SLionel Sambuc 		    PUFFS_VN_ABORTOP, VPTOPNC(dvp));
275684d9c625SLionel Sambuc 
275784d9c625SLionel Sambuc 		puffs_msg_enqueue(pmp, park_abortop);
275884d9c625SLionel Sambuc 		PUFFS_MSG_RELEASE(abortop);
275984d9c625SLionel Sambuc 	}
276084d9c625SLionel Sambuc 
276184d9c625SLionel Sambuc 	return genfs_abortop(v);
276284d9c625SLionel Sambuc }
276384d9c625SLionel Sambuc 
276484d9c625SLionel Sambuc #define BIOASYNC(bp) (bp->b_flags & B_ASYNC)
276584d9c625SLionel Sambuc 
276684d9c625SLionel Sambuc /*
276784d9c625SLionel Sambuc  * This maps itself to PUFFS_VN_READ/WRITE for data transfer.
276884d9c625SLionel Sambuc  */
276984d9c625SLionel Sambuc int
puffs_vnop_strategy(void * v)277084d9c625SLionel Sambuc puffs_vnop_strategy(void *v)
277184d9c625SLionel Sambuc {
277284d9c625SLionel Sambuc 	struct vop_strategy_args /* {
277384d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
277484d9c625SLionel Sambuc 		struct vnode *a_vp;
277584d9c625SLionel Sambuc 		struct buf *a_bp;
277684d9c625SLionel Sambuc 	} */ *ap = v;
277784d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, rw);
277884d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
277984d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
278084d9c625SLionel Sambuc 	struct puffs_node *pn;
278184d9c625SLionel Sambuc 	struct buf *bp;
278284d9c625SLionel Sambuc 	size_t argsize;
278384d9c625SLionel Sambuc 	size_t tomove, moved;
278484d9c625SLionel Sambuc 	int error, dofaf, cansleep, dobiodone;
278584d9c625SLionel Sambuc 
278684d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(vp->v_mount);
278784d9c625SLionel Sambuc 	bp = ap->a_bp;
278884d9c625SLionel Sambuc 	error = 0;
278984d9c625SLionel Sambuc 	dofaf = 0;
279084d9c625SLionel Sambuc 	cansleep = 0;
279184d9c625SLionel Sambuc 	pn = VPTOPP(vp);
279284d9c625SLionel Sambuc 	park_rw = NULL; /* explicit */
279384d9c625SLionel Sambuc 	dobiodone = 1;
279484d9c625SLionel Sambuc 
279584d9c625SLionel Sambuc 	if ((BUF_ISREAD(bp) && !EXISTSOP(pmp, READ))
279684d9c625SLionel Sambuc 	    || (BUF_ISWRITE(bp) && !EXISTSOP(pmp, WRITE)))
279784d9c625SLionel Sambuc 		ERROUT(EOPNOTSUPP);
279884d9c625SLionel Sambuc 
279984d9c625SLionel Sambuc 	/*
280084d9c625SLionel Sambuc 	 * Short-circuit optimization: don't flush buffer in between
280184d9c625SLionel Sambuc 	 * VOP_INACTIVE and VOP_RECLAIM in case the node has no references.
280284d9c625SLionel Sambuc 	 */
280384d9c625SLionel Sambuc 	if (pn->pn_stat & PNODE_DYING) {
280484d9c625SLionel Sambuc 		KASSERT(BUF_ISWRITE(bp));
280584d9c625SLionel Sambuc 		bp->b_resid = 0;
280684d9c625SLionel Sambuc 		goto out;
280784d9c625SLionel Sambuc 	}
280884d9c625SLionel Sambuc 
280984d9c625SLionel Sambuc #ifdef DIAGNOSTIC
281084d9c625SLionel Sambuc 	if (bp->b_bcount > pmp->pmp_msg_maxsize - PUFFS_MSGSTRUCT_MAX)
281184d9c625SLionel Sambuc 		panic("puffs_strategy: wildly inappropriate buf bcount %d",
281284d9c625SLionel Sambuc 		    bp->b_bcount);
281384d9c625SLionel Sambuc #endif
281484d9c625SLionel Sambuc 
281584d9c625SLionel Sambuc 	/*
281684d9c625SLionel Sambuc 	 * See explanation for the necessity of a FAF in puffs_fsync.
281784d9c625SLionel Sambuc 	 *
281884d9c625SLionel Sambuc 	 * Also, do FAF in case we're suspending.
281984d9c625SLionel Sambuc 	 * See puffs_vfsops.c:pageflush()
282084d9c625SLionel Sambuc 	 */
282184d9c625SLionel Sambuc 	if (BUF_ISWRITE(bp)) {
282284d9c625SLionel Sambuc 		mutex_enter(vp->v_interlock);
2823*0a6a1f1dSLionel Sambuc 		if (vdead_check(vp, VDEAD_NOWAIT) != 0)
282484d9c625SLionel Sambuc 			dofaf = 1;
282584d9c625SLionel Sambuc 		if (pn->pn_stat & PNODE_FAF)
282684d9c625SLionel Sambuc 			dofaf = 1;
282784d9c625SLionel Sambuc 		mutex_exit(vp->v_interlock);
282884d9c625SLionel Sambuc 	}
282984d9c625SLionel Sambuc 
283084d9c625SLionel Sambuc 	cansleep = (curlwp == uvm.pagedaemon_lwp || dofaf) ? 0 : 1;
283184d9c625SLionel Sambuc 
283284d9c625SLionel Sambuc 	KASSERT(curlwp != uvm.pagedaemon_lwp || dofaf || BIOASYNC(bp));
283384d9c625SLionel Sambuc 
283484d9c625SLionel Sambuc 	/* allocate transport structure */
283584d9c625SLionel Sambuc 	tomove = PUFFS_TOMOVE(bp->b_bcount, pmp);
283684d9c625SLionel Sambuc 	argsize = sizeof(struct puffs_vnmsg_rw);
283784d9c625SLionel Sambuc 	error = puffs_msgmem_alloc(argsize + tomove, &park_rw,
283884d9c625SLionel Sambuc 	    (void *)&rw_msg, cansleep);
283984d9c625SLionel Sambuc 	if (error)
284084d9c625SLionel Sambuc 		goto out;
284184d9c625SLionel Sambuc 	RWARGS(rw_msg, 0, tomove, bp->b_blkno << DEV_BSHIFT, FSCRED);
284284d9c625SLionel Sambuc 
284384d9c625SLionel Sambuc 	/* 2x2 cases: read/write, faf/nofaf */
284484d9c625SLionel Sambuc 	if (BUF_ISREAD(bp)) {
284584d9c625SLionel Sambuc 		puffs_msg_setinfo(park_rw, PUFFSOP_VN,
284684d9c625SLionel Sambuc 		    PUFFS_VN_READ, VPTOPNC(vp));
284784d9c625SLionel Sambuc 		puffs_msg_setdelta(park_rw, tomove);
284884d9c625SLionel Sambuc 		if (BIOASYNC(bp)) {
284984d9c625SLionel Sambuc 			puffs_msg_setcall(park_rw,
285084d9c625SLionel Sambuc 			    puffs_parkdone_asyncbioread, bp);
285184d9c625SLionel Sambuc 			puffs_msg_enqueue(pmp, park_rw);
285284d9c625SLionel Sambuc 			dobiodone = 0;
285384d9c625SLionel Sambuc 		} else {
285484d9c625SLionel Sambuc 			PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rw, vp->v_data,
285584d9c625SLionel Sambuc 			    NULL, error);
285684d9c625SLionel Sambuc 			error = checkerr(pmp, error, __func__);
285784d9c625SLionel Sambuc 			if (error)
285884d9c625SLionel Sambuc 				goto out;
285984d9c625SLionel Sambuc 
286084d9c625SLionel Sambuc 			if (rw_msg->pvnr_resid > tomove) {
286184d9c625SLionel Sambuc 				puffs_senderr(pmp, PUFFS_ERR_READ,
286284d9c625SLionel Sambuc 				    E2BIG, "resid grew", VPTOPNC(vp));
286384d9c625SLionel Sambuc 				ERROUT(EPROTO);
286484d9c625SLionel Sambuc 			}
286584d9c625SLionel Sambuc 
286684d9c625SLionel Sambuc 			moved = tomove - rw_msg->pvnr_resid;
286784d9c625SLionel Sambuc 
286884d9c625SLionel Sambuc 			(void)memcpy(bp->b_data, rw_msg->pvnr_data, moved);
286984d9c625SLionel Sambuc 			bp->b_resid = bp->b_bcount - moved;
287084d9c625SLionel Sambuc 		}
287184d9c625SLionel Sambuc 	} else {
287284d9c625SLionel Sambuc 		puffs_msg_setinfo(park_rw, PUFFSOP_VN,
287384d9c625SLionel Sambuc 		    PUFFS_VN_WRITE, VPTOPNC(vp));
287484d9c625SLionel Sambuc 		/*
287584d9c625SLionel Sambuc 		 * make pages read-only before we write them if we want
287684d9c625SLionel Sambuc 		 * write caching info
287784d9c625SLionel Sambuc 		 */
287884d9c625SLionel Sambuc 		if (PUFFS_WCACHEINFO(pmp)) {
287984d9c625SLionel Sambuc 			struct uvm_object *uobj = &vp->v_uobj;
288084d9c625SLionel Sambuc 			int npages = (bp->b_bcount + PAGE_SIZE-1) >> PAGE_SHIFT;
288184d9c625SLionel Sambuc 			struct vm_page *vmp;
288284d9c625SLionel Sambuc 			int i;
288384d9c625SLionel Sambuc 
288484d9c625SLionel Sambuc 			for (i = 0; i < npages; i++) {
288584d9c625SLionel Sambuc 				vmp= uvm_pageratop((vaddr_t)bp->b_data
288684d9c625SLionel Sambuc 				    + (i << PAGE_SHIFT));
288784d9c625SLionel Sambuc 				DPRINTF(("puffs_strategy: write-protecting "
288884d9c625SLionel Sambuc 				    "vp %p page %p, offset %" PRId64"\n",
288984d9c625SLionel Sambuc 				    vp, vmp, vmp->offset));
289084d9c625SLionel Sambuc 				mutex_enter(uobj->vmobjlock);
289184d9c625SLionel Sambuc 				vmp->flags |= PG_RDONLY;
289284d9c625SLionel Sambuc 				pmap_page_protect(vmp, VM_PROT_READ);
289384d9c625SLionel Sambuc 				mutex_exit(uobj->vmobjlock);
289484d9c625SLionel Sambuc 			}
289584d9c625SLionel Sambuc 		}
289684d9c625SLionel Sambuc 
289784d9c625SLionel Sambuc 		(void)memcpy(&rw_msg->pvnr_data, bp->b_data, tomove);
289884d9c625SLionel Sambuc 		if (dofaf) {
289984d9c625SLionel Sambuc 			puffs_msg_setfaf(park_rw);
290084d9c625SLionel Sambuc 		} else if (BIOASYNC(bp)) {
290184d9c625SLionel Sambuc 			puffs_msg_setcall(park_rw,
290284d9c625SLionel Sambuc 			    puffs_parkdone_asyncbiowrite, bp);
290384d9c625SLionel Sambuc 			dobiodone = 0;
290484d9c625SLionel Sambuc 		}
290584d9c625SLionel Sambuc 
290684d9c625SLionel Sambuc 		PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rw, vp->v_data, NULL, error);
290784d9c625SLionel Sambuc 
290884d9c625SLionel Sambuc 		if (dobiodone == 0)
290984d9c625SLionel Sambuc 			goto out;
291084d9c625SLionel Sambuc 
291184d9c625SLionel Sambuc 		error = checkerr(pmp, error, __func__);
291284d9c625SLionel Sambuc 		if (error)
291384d9c625SLionel Sambuc 			goto out;
291484d9c625SLionel Sambuc 
291584d9c625SLionel Sambuc 		if (rw_msg->pvnr_resid > tomove) {
291684d9c625SLionel Sambuc 			puffs_senderr(pmp, PUFFS_ERR_WRITE,
291784d9c625SLionel Sambuc 			    E2BIG, "resid grew", VPTOPNC(vp));
291884d9c625SLionel Sambuc 			ERROUT(EPROTO);
291984d9c625SLionel Sambuc 		}
292084d9c625SLionel Sambuc 
292184d9c625SLionel Sambuc 		/*
292284d9c625SLionel Sambuc 		 * FAF moved everything.  Frankly, we don't
292384d9c625SLionel Sambuc 		 * really have a choice.
292484d9c625SLionel Sambuc 		 */
292584d9c625SLionel Sambuc 		if (dofaf && error == 0)
292684d9c625SLionel Sambuc 			moved = tomove;
292784d9c625SLionel Sambuc 		else
292884d9c625SLionel Sambuc 			moved = tomove - rw_msg->pvnr_resid;
292984d9c625SLionel Sambuc 
293084d9c625SLionel Sambuc 		bp->b_resid = bp->b_bcount - moved;
293184d9c625SLionel Sambuc 		if (bp->b_resid != 0) {
293284d9c625SLionel Sambuc 			ERROUT(EIO);
293384d9c625SLionel Sambuc 		}
293484d9c625SLionel Sambuc 	}
293584d9c625SLionel Sambuc 
293684d9c625SLionel Sambuc  out:
293784d9c625SLionel Sambuc 	if (park_rw)
293884d9c625SLionel Sambuc 		puffs_msgmem_release(park_rw);
293984d9c625SLionel Sambuc 
294084d9c625SLionel Sambuc 	if (error)
294184d9c625SLionel Sambuc 		bp->b_error = error;
294284d9c625SLionel Sambuc 
294384d9c625SLionel Sambuc 	if (error || dobiodone)
294484d9c625SLionel Sambuc 		biodone(bp);
294584d9c625SLionel Sambuc 
294684d9c625SLionel Sambuc 	return error;
294784d9c625SLionel Sambuc }
294884d9c625SLionel Sambuc 
294984d9c625SLionel Sambuc int
puffs_vnop_mmap(void * v)295084d9c625SLionel Sambuc puffs_vnop_mmap(void *v)
295184d9c625SLionel Sambuc {
295284d9c625SLionel Sambuc 	struct vop_mmap_args /* {
295384d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
295484d9c625SLionel Sambuc 		struct vnode *a_vp;
295584d9c625SLionel Sambuc 		vm_prot_t a_prot;
295684d9c625SLionel Sambuc 		kauth_cred_t a_cred;
295784d9c625SLionel Sambuc 	} */ *ap = v;
295884d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, mmap);
295984d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
296084d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
296184d9c625SLionel Sambuc 	int error;
296284d9c625SLionel Sambuc 
296384d9c625SLionel Sambuc 	if (!PUFFS_USE_PAGECACHE(pmp))
296484d9c625SLionel Sambuc 		return genfs_eopnotsupp(v);
296584d9c625SLionel Sambuc 
296684d9c625SLionel Sambuc 	if (EXISTSOP(pmp, MMAP)) {
296784d9c625SLionel Sambuc 		PUFFS_MSG_ALLOC(vn, mmap);
296884d9c625SLionel Sambuc 		mmap_msg->pvnr_prot = ap->a_prot;
296984d9c625SLionel Sambuc 		puffs_credcvt(&mmap_msg->pvnr_cred, ap->a_cred);
297084d9c625SLionel Sambuc 		puffs_msg_setinfo(park_mmap, PUFFSOP_VN,
297184d9c625SLionel Sambuc 		    PUFFS_VN_MMAP, VPTOPNC(vp));
297284d9c625SLionel Sambuc 
297384d9c625SLionel Sambuc 		PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mmap, vp->v_data, NULL, error);
297484d9c625SLionel Sambuc 		error = checkerr(pmp, error, __func__);
297584d9c625SLionel Sambuc 		PUFFS_MSG_RELEASE(mmap);
297684d9c625SLionel Sambuc 	} else {
297784d9c625SLionel Sambuc 		error = genfs_mmap(v);
297884d9c625SLionel Sambuc 	}
297984d9c625SLionel Sambuc 
298084d9c625SLionel Sambuc 	return error;
298184d9c625SLionel Sambuc }
298284d9c625SLionel Sambuc 
298384d9c625SLionel Sambuc 
298484d9c625SLionel Sambuc /*
298584d9c625SLionel Sambuc  * The rest don't get a free trip to userspace and back, they
298684d9c625SLionel Sambuc  * have to stay within the kernel.
298784d9c625SLionel Sambuc  */
298884d9c625SLionel Sambuc 
298984d9c625SLionel Sambuc /*
299084d9c625SLionel Sambuc  * bmap doesn't really make any sense for puffs, so just 1:1 map it.
299184d9c625SLionel Sambuc  * well, maybe somehow, somewhere, some day ....
299284d9c625SLionel Sambuc  */
299384d9c625SLionel Sambuc int
puffs_vnop_bmap(void * v)299484d9c625SLionel Sambuc puffs_vnop_bmap(void *v)
299584d9c625SLionel Sambuc {
299684d9c625SLionel Sambuc 	struct vop_bmap_args /* {
299784d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
299884d9c625SLionel Sambuc 		struct vnode *a_vp;
299984d9c625SLionel Sambuc 		daddr_t a_bn;
300084d9c625SLionel Sambuc 		struct vnode **a_vpp;
300184d9c625SLionel Sambuc 		daddr_t *a_bnp;
300284d9c625SLionel Sambuc 		int *a_runp;
300384d9c625SLionel Sambuc 	} */ *ap = v;
300484d9c625SLionel Sambuc 	struct puffs_mount *pmp;
300584d9c625SLionel Sambuc 
300684d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
300784d9c625SLionel Sambuc 
300884d9c625SLionel Sambuc 	if (ap->a_vpp)
300984d9c625SLionel Sambuc 		*ap->a_vpp = ap->a_vp;
301084d9c625SLionel Sambuc 	if (ap->a_bnp)
301184d9c625SLionel Sambuc 		*ap->a_bnp = ap->a_bn;
301284d9c625SLionel Sambuc 	if (ap->a_runp)
301384d9c625SLionel Sambuc 		*ap->a_runp
301484d9c625SLionel Sambuc 		    = (PUFFS_TOMOVE(pmp->pmp_msg_maxsize, pmp)>>DEV_BSHIFT) - 1;
301584d9c625SLionel Sambuc 
301684d9c625SLionel Sambuc 	return 0;
301784d9c625SLionel Sambuc }
301884d9c625SLionel Sambuc 
301984d9c625SLionel Sambuc /*
302084d9c625SLionel Sambuc  * Handle getpages faults in puffs.  We let genfs_getpages() do most
302184d9c625SLionel Sambuc  * of the dirty work, but we come in this route to do accounting tasks.
302284d9c625SLionel Sambuc  * If the user server has specified functions for cache notifications
302384d9c625SLionel Sambuc  * about reads and/or writes, we record which type of operation we got,
302484d9c625SLionel Sambuc  * for which page range, and proceed to issue a FAF notification to the
302584d9c625SLionel Sambuc  * server about it.
302684d9c625SLionel Sambuc  */
302784d9c625SLionel Sambuc int
puffs_vnop_getpages(void * v)302884d9c625SLionel Sambuc puffs_vnop_getpages(void *v)
302984d9c625SLionel Sambuc {
303084d9c625SLionel Sambuc 	struct vop_getpages_args /* {
303184d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
303284d9c625SLionel Sambuc 		struct vnode *a_vp;
303384d9c625SLionel Sambuc 		voff_t a_offset;
303484d9c625SLionel Sambuc 		struct vm_page **a_m;
303584d9c625SLionel Sambuc 		int *a_count;
303684d9c625SLionel Sambuc 		int a_centeridx;
303784d9c625SLionel Sambuc 		vm_prot_t a_access_type;
303884d9c625SLionel Sambuc 		int a_advice;
303984d9c625SLionel Sambuc 		int a_flags;
304084d9c625SLionel Sambuc 	} */ *ap = v;
304184d9c625SLionel Sambuc 	struct puffs_mount *pmp;
304284d9c625SLionel Sambuc 	struct puffs_node *pn;
304384d9c625SLionel Sambuc 	struct vnode *vp;
304484d9c625SLionel Sambuc 	struct vm_page **pgs;
304584d9c625SLionel Sambuc 	struct puffs_cacheinfo *pcinfo = NULL;
304684d9c625SLionel Sambuc 	struct puffs_cacherun *pcrun;
304784d9c625SLionel Sambuc 	void *parkmem = NULL;
304884d9c625SLionel Sambuc 	size_t runsizes;
304984d9c625SLionel Sambuc 	int i, npages, si, streakon;
305084d9c625SLionel Sambuc 	int error, locked, write;
305184d9c625SLionel Sambuc 
305284d9c625SLionel Sambuc 	pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
305384d9c625SLionel Sambuc 	npages = *ap->a_count;
305484d9c625SLionel Sambuc 	pgs = ap->a_m;
305584d9c625SLionel Sambuc 	vp = ap->a_vp;
305684d9c625SLionel Sambuc 	pn = vp->v_data;
305784d9c625SLionel Sambuc 	locked = (ap->a_flags & PGO_LOCKED) != 0;
305884d9c625SLionel Sambuc 	write = (ap->a_access_type & VM_PROT_WRITE) != 0;
305984d9c625SLionel Sambuc 
306084d9c625SLionel Sambuc 	/* ccg xnaht - gets Wuninitialized wrong */
306184d9c625SLionel Sambuc 	pcrun = NULL;
306284d9c625SLionel Sambuc 	runsizes = 0;
306384d9c625SLionel Sambuc 
306484d9c625SLionel Sambuc 	/*
306584d9c625SLionel Sambuc 	 * Check that we aren't trying to fault in pages which our file
306684d9c625SLionel Sambuc 	 * server doesn't know about.  This happens if we extend a file by
306784d9c625SLionel Sambuc 	 * skipping some pages and later try to fault in pages which
306884d9c625SLionel Sambuc 	 * are between pn_serversize and vp_size.  This check optimizes
306984d9c625SLionel Sambuc 	 * away the common case where a file is being extended.
307084d9c625SLionel Sambuc 	 */
307184d9c625SLionel Sambuc 	if (ap->a_offset >= pn->pn_serversize && ap->a_offset < vp->v_size) {
307284d9c625SLionel Sambuc 		struct vattr va;
307384d9c625SLionel Sambuc 
307484d9c625SLionel Sambuc 		/* try again later when we can block */
307584d9c625SLionel Sambuc 		if (locked)
307684d9c625SLionel Sambuc 			ERROUT(EBUSY);
307784d9c625SLionel Sambuc 
307884d9c625SLionel Sambuc 		mutex_exit(vp->v_interlock);
307984d9c625SLionel Sambuc 		vattr_null(&va);
308084d9c625SLionel Sambuc 		va.va_size = vp->v_size;
308184d9c625SLionel Sambuc 		error = dosetattr(vp, &va, FSCRED, 0);
308284d9c625SLionel Sambuc 		if (error)
308384d9c625SLionel Sambuc 			ERROUT(error);
308484d9c625SLionel Sambuc 		mutex_enter(vp->v_interlock);
308584d9c625SLionel Sambuc 	}
308684d9c625SLionel Sambuc 
308784d9c625SLionel Sambuc 	if (write && PUFFS_WCACHEINFO(pmp)) {
308884d9c625SLionel Sambuc #ifdef notnowjohn
308984d9c625SLionel Sambuc 		/* allocate worst-case memory */
309084d9c625SLionel Sambuc 		runsizes = ((npages / 2) + 1) * sizeof(struct puffs_cacherun);
309184d9c625SLionel Sambuc 		KASSERT(curlwp != uvm.pagedaemon_lwp || locked);
309284d9c625SLionel Sambuc 		pcinfo = kmem_zalloc(sizeof(struct puffs_cacheinfo) + runsize,
309384d9c625SLionel Sambuc 		    locked ? KM_NOSLEEP : KM_SLEEP);
309484d9c625SLionel Sambuc 
309584d9c625SLionel Sambuc 		/*
309684d9c625SLionel Sambuc 		 * can't block if we're locked and can't mess up caching
309784d9c625SLionel Sambuc 		 * information for fs server.  so come back later, please
309884d9c625SLionel Sambuc 		 */
309984d9c625SLionel Sambuc 		if (pcinfo == NULL)
310084d9c625SLionel Sambuc 			ERROUT(ENOMEM);
310184d9c625SLionel Sambuc 
310284d9c625SLionel Sambuc 		parkmem = puffs_park_alloc(locked == 0);
310384d9c625SLionel Sambuc 		if (parkmem == NULL)
310484d9c625SLionel Sambuc 			ERROUT(ENOMEM);
310584d9c625SLionel Sambuc 
310684d9c625SLionel Sambuc 		pcrun = pcinfo->pcache_runs;
310784d9c625SLionel Sambuc #else
310884d9c625SLionel Sambuc 		(void)parkmem;
310984d9c625SLionel Sambuc #endif
311084d9c625SLionel Sambuc 	}
311184d9c625SLionel Sambuc 
311284d9c625SLionel Sambuc 	error = genfs_getpages(v);
311384d9c625SLionel Sambuc 	if (error)
311484d9c625SLionel Sambuc 		goto out;
311584d9c625SLionel Sambuc 
311684d9c625SLionel Sambuc 	if (PUFFS_WCACHEINFO(pmp) == 0)
311784d9c625SLionel Sambuc 		goto out;
311884d9c625SLionel Sambuc 
311984d9c625SLionel Sambuc 	/*
312084d9c625SLionel Sambuc 	 * Let's see whose fault it was and inform the user server of
312184d9c625SLionel Sambuc 	 * possibly read/written pages.  Map pages from read faults
312284d9c625SLionel Sambuc 	 * strictly read-only, since otherwise we might miss info on
312384d9c625SLionel Sambuc 	 * when the page is actually write-faulted to.
312484d9c625SLionel Sambuc 	 */
312584d9c625SLionel Sambuc 	if (!locked)
312684d9c625SLionel Sambuc 		mutex_enter(vp->v_uobj.vmobjlock);
312784d9c625SLionel Sambuc 	for (i = 0, si = 0, streakon = 0; i < npages; i++) {
312884d9c625SLionel Sambuc 		if (pgs[i] == NULL || pgs[i] == PGO_DONTCARE) {
312984d9c625SLionel Sambuc 			if (streakon && write) {
313084d9c625SLionel Sambuc 				streakon = 0;
313184d9c625SLionel Sambuc 				pcrun[si].pcache_runend
313284d9c625SLionel Sambuc 				    = trunc_page(pgs[i]->offset) + PAGE_MASK;
313384d9c625SLionel Sambuc 				si++;
313484d9c625SLionel Sambuc 			}
313584d9c625SLionel Sambuc 			continue;
313684d9c625SLionel Sambuc 		}
313784d9c625SLionel Sambuc 		if (streakon == 0 && write) {
313884d9c625SLionel Sambuc 			streakon = 1;
313984d9c625SLionel Sambuc 			pcrun[si].pcache_runstart = pgs[i]->offset;
314084d9c625SLionel Sambuc 		}
314184d9c625SLionel Sambuc 
314284d9c625SLionel Sambuc 		if (!write)
314384d9c625SLionel Sambuc 			pgs[i]->flags |= PG_RDONLY;
314484d9c625SLionel Sambuc 	}
314584d9c625SLionel Sambuc 	/* was the last page part of our streak? */
314684d9c625SLionel Sambuc 	if (streakon) {
314784d9c625SLionel Sambuc 		pcrun[si].pcache_runend
314884d9c625SLionel Sambuc 		    = trunc_page(pgs[i-1]->offset) + PAGE_MASK;
314984d9c625SLionel Sambuc 		si++;
315084d9c625SLionel Sambuc 	}
315184d9c625SLionel Sambuc 	if (!locked)
315284d9c625SLionel Sambuc 		mutex_exit(vp->v_uobj.vmobjlock);
315384d9c625SLionel Sambuc 
315484d9c625SLionel Sambuc 	KASSERT(si <= (npages / 2) + 1);
315584d9c625SLionel Sambuc 
315684d9c625SLionel Sambuc #ifdef notnowjohn
315784d9c625SLionel Sambuc 	/* send results to userspace */
315884d9c625SLionel Sambuc 	if (write)
315984d9c625SLionel Sambuc 		puffs_cacheop(pmp, parkmem, pcinfo,
316084d9c625SLionel Sambuc 		    sizeof(struct puffs_cacheinfo) + runsizes, VPTOPNC(vp));
316184d9c625SLionel Sambuc #endif
316284d9c625SLionel Sambuc 
316384d9c625SLionel Sambuc  out:
316484d9c625SLionel Sambuc 	if (error) {
316584d9c625SLionel Sambuc 		if (pcinfo != NULL)
316684d9c625SLionel Sambuc 			kmem_free(pcinfo,
316784d9c625SLionel Sambuc 			    sizeof(struct puffs_cacheinfo) + runsizes);
316884d9c625SLionel Sambuc #ifdef notnowjohn
316984d9c625SLionel Sambuc 		if (parkmem != NULL)
317084d9c625SLionel Sambuc 			puffs_park_release(parkmem, 1);
317184d9c625SLionel Sambuc #endif
317284d9c625SLionel Sambuc 	}
317384d9c625SLionel Sambuc 
317484d9c625SLionel Sambuc 	return error;
317584d9c625SLionel Sambuc }
317684d9c625SLionel Sambuc 
317784d9c625SLionel Sambuc /*
317884d9c625SLionel Sambuc  * Extended attribute support.
317984d9c625SLionel Sambuc  */
318084d9c625SLionel Sambuc 
318184d9c625SLionel Sambuc int
puffs_vnop_getextattr(void * v)318284d9c625SLionel Sambuc puffs_vnop_getextattr(void *v)
318384d9c625SLionel Sambuc {
318484d9c625SLionel Sambuc 	struct vop_getextattr_args /*
318584d9c625SLionel Sambuc 		struct vnode *a_vp;
318684d9c625SLionel Sambuc 		int a_attrnamespace;
318784d9c625SLionel Sambuc 		const char *a_name;
318884d9c625SLionel Sambuc 		struct uio *a_uio;
318984d9c625SLionel Sambuc 		size_t *a_size;
319084d9c625SLionel Sambuc 		kauth_cred_t a_cred;
319184d9c625SLionel Sambuc 	}; */ *ap = v;
319284d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, getextattr);
319384d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
319484d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
319584d9c625SLionel Sambuc 	int attrnamespace = ap->a_attrnamespace;
319684d9c625SLionel Sambuc 	const char *name = ap->a_name;
319784d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
319884d9c625SLionel Sambuc 	size_t *sizep = ap->a_size;
319984d9c625SLionel Sambuc 	size_t tomove, resid;
320084d9c625SLionel Sambuc 	int error;
320184d9c625SLionel Sambuc 
320284d9c625SLionel Sambuc 	if (uio)
320384d9c625SLionel Sambuc 		resid = uio->uio_resid;
320484d9c625SLionel Sambuc 	else
320584d9c625SLionel Sambuc 		resid = 0;
320684d9c625SLionel Sambuc 
320784d9c625SLionel Sambuc 	tomove = PUFFS_TOMOVE(resid, pmp);
320884d9c625SLionel Sambuc 	if (tomove != resid) {
320984d9c625SLionel Sambuc 		error = E2BIG;
321084d9c625SLionel Sambuc 		goto out;
321184d9c625SLionel Sambuc 	}
321284d9c625SLionel Sambuc 
321384d9c625SLionel Sambuc 	puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_getextattr) + tomove,
321484d9c625SLionel Sambuc 	    &park_getextattr, (void *)&getextattr_msg, 1);
321584d9c625SLionel Sambuc 
321684d9c625SLionel Sambuc 	getextattr_msg->pvnr_attrnamespace = attrnamespace;
321784d9c625SLionel Sambuc 	strlcpy(getextattr_msg->pvnr_attrname, name,
321884d9c625SLionel Sambuc 	    sizeof(getextattr_msg->pvnr_attrname));
321984d9c625SLionel Sambuc 	puffs_credcvt(&getextattr_msg->pvnr_cred, ap->a_cred);
322084d9c625SLionel Sambuc 	if (sizep)
322184d9c625SLionel Sambuc 		getextattr_msg->pvnr_datasize = 1;
322284d9c625SLionel Sambuc 	getextattr_msg->pvnr_resid = tomove;
322384d9c625SLionel Sambuc 
322484d9c625SLionel Sambuc 	puffs_msg_setinfo(park_getextattr,
322584d9c625SLionel Sambuc 	    PUFFSOP_VN, PUFFS_VN_GETEXTATTR, VPTOPNC(vp));
322684d9c625SLionel Sambuc 	puffs_msg_setdelta(park_getextattr, tomove);
322784d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_getextattr, vp->v_data, NULL, error);
322884d9c625SLionel Sambuc 
322984d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
323084d9c625SLionel Sambuc 	if (error)
323184d9c625SLionel Sambuc 		goto out;
323284d9c625SLionel Sambuc 
323384d9c625SLionel Sambuc 	resid = getextattr_msg->pvnr_resid;
323484d9c625SLionel Sambuc 	if (resid > tomove) {
323584d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_GETEXTATTR, E2BIG,
323684d9c625SLionel Sambuc 		    "resid grew", VPTOPNC(vp));
323784d9c625SLionel Sambuc 		error = EPROTO;
323884d9c625SLionel Sambuc 		goto out;
323984d9c625SLionel Sambuc 	}
324084d9c625SLionel Sambuc 
324184d9c625SLionel Sambuc 	if (sizep)
324284d9c625SLionel Sambuc 		*sizep = getextattr_msg->pvnr_datasize;
324384d9c625SLionel Sambuc 	if (uio)
324484d9c625SLionel Sambuc 		error = uiomove(getextattr_msg->pvnr_data, tomove - resid, uio);
324584d9c625SLionel Sambuc 
324684d9c625SLionel Sambuc  out:
324784d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(getextattr);
324884d9c625SLionel Sambuc 	return error;
324984d9c625SLionel Sambuc }
325084d9c625SLionel Sambuc 
325184d9c625SLionel Sambuc int
puffs_vnop_setextattr(void * v)325284d9c625SLionel Sambuc puffs_vnop_setextattr(void *v)
325384d9c625SLionel Sambuc {
325484d9c625SLionel Sambuc 	struct vop_setextattr_args /* {
325584d9c625SLionel Sambuc 		struct vnode *a_vp;
325684d9c625SLionel Sambuc 		int a_attrnamespace;
325784d9c625SLionel Sambuc 		const char *a_name;
325884d9c625SLionel Sambuc 		struct uio *a_uio;
325984d9c625SLionel Sambuc 		kauth_cred_t a_cred;
326084d9c625SLionel Sambuc 	}; */ *ap = v;
326184d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, setextattr);
326284d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
326384d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
326484d9c625SLionel Sambuc 	int attrnamespace = ap->a_attrnamespace;
326584d9c625SLionel Sambuc 	const char *name = ap->a_name;
326684d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
326784d9c625SLionel Sambuc 	size_t tomove, resid;
326884d9c625SLionel Sambuc 	int error;
326984d9c625SLionel Sambuc 
327084d9c625SLionel Sambuc 	if (uio)
327184d9c625SLionel Sambuc 		resid = uio->uio_resid;
327284d9c625SLionel Sambuc 	else
327384d9c625SLionel Sambuc 		resid = 0;
327484d9c625SLionel Sambuc 
327584d9c625SLionel Sambuc 	tomove = PUFFS_TOMOVE(resid, pmp);
327684d9c625SLionel Sambuc 	if (tomove != resid) {
327784d9c625SLionel Sambuc 		error = E2BIG;
327884d9c625SLionel Sambuc 		goto out;
327984d9c625SLionel Sambuc 	}
328084d9c625SLionel Sambuc 
328184d9c625SLionel Sambuc 	puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_setextattr) + tomove,
328284d9c625SLionel Sambuc 	    &park_setextattr, (void *)&setextattr_msg, 1);
328384d9c625SLionel Sambuc 
328484d9c625SLionel Sambuc 	setextattr_msg->pvnr_attrnamespace = attrnamespace;
328584d9c625SLionel Sambuc 	strlcpy(setextattr_msg->pvnr_attrname, name,
328684d9c625SLionel Sambuc 	    sizeof(setextattr_msg->pvnr_attrname));
328784d9c625SLionel Sambuc 	puffs_credcvt(&setextattr_msg->pvnr_cred, ap->a_cred);
328884d9c625SLionel Sambuc 	setextattr_msg->pvnr_resid = tomove;
328984d9c625SLionel Sambuc 
329084d9c625SLionel Sambuc 	if (uio) {
329184d9c625SLionel Sambuc 		error = uiomove(setextattr_msg->pvnr_data, tomove, uio);
329284d9c625SLionel Sambuc 		if (error)
329384d9c625SLionel Sambuc 			goto out;
329484d9c625SLionel Sambuc 	}
329584d9c625SLionel Sambuc 
329684d9c625SLionel Sambuc 	puffs_msg_setinfo(park_setextattr,
329784d9c625SLionel Sambuc 	    PUFFSOP_VN, PUFFS_VN_SETEXTATTR, VPTOPNC(vp));
329884d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_setextattr, vp->v_data, NULL, error);
329984d9c625SLionel Sambuc 
330084d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
330184d9c625SLionel Sambuc 	if (error)
330284d9c625SLionel Sambuc 		goto out;
330384d9c625SLionel Sambuc 
330484d9c625SLionel Sambuc 	if (setextattr_msg->pvnr_resid != 0)
330584d9c625SLionel Sambuc 		error = EIO;
330684d9c625SLionel Sambuc 
330784d9c625SLionel Sambuc  out:
330884d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(setextattr);
330984d9c625SLionel Sambuc 
331084d9c625SLionel Sambuc 	return error;
331184d9c625SLionel Sambuc }
331284d9c625SLionel Sambuc 
331384d9c625SLionel Sambuc int
puffs_vnop_listextattr(void * v)331484d9c625SLionel Sambuc puffs_vnop_listextattr(void *v)
331584d9c625SLionel Sambuc {
331684d9c625SLionel Sambuc 	struct vop_listextattr_args /* {
331784d9c625SLionel Sambuc 		struct vnode *a_vp;
331884d9c625SLionel Sambuc 		int a_attrnamespace;
331984d9c625SLionel Sambuc 		struct uio *a_uio;
332084d9c625SLionel Sambuc 		size_t *a_size;
332184d9c625SLionel Sambuc 		int a_flag,
332284d9c625SLionel Sambuc 		kauth_cred_t a_cred;
332384d9c625SLionel Sambuc 	}; */ *ap = v;
332484d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, listextattr);
332584d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
332684d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
332784d9c625SLionel Sambuc 	int attrnamespace = ap->a_attrnamespace;
332884d9c625SLionel Sambuc 	struct uio *uio = ap->a_uio;
332984d9c625SLionel Sambuc 	size_t *sizep = ap->a_size;
333084d9c625SLionel Sambuc 	int flag = ap->a_flag;
333184d9c625SLionel Sambuc 	size_t tomove, resid;
333284d9c625SLionel Sambuc 	int error;
333384d9c625SLionel Sambuc 
333484d9c625SLionel Sambuc 	if (uio)
333584d9c625SLionel Sambuc 		resid = uio->uio_resid;
333684d9c625SLionel Sambuc 	else
333784d9c625SLionel Sambuc 		resid = 0;
333884d9c625SLionel Sambuc 
333984d9c625SLionel Sambuc 	tomove = PUFFS_TOMOVE(resid, pmp);
334084d9c625SLionel Sambuc 	if (tomove != resid) {
334184d9c625SLionel Sambuc 		error = E2BIG;
334284d9c625SLionel Sambuc 		goto out;
334384d9c625SLionel Sambuc 	}
334484d9c625SLionel Sambuc 
334584d9c625SLionel Sambuc 	puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_listextattr) + tomove,
334684d9c625SLionel Sambuc 	    &park_listextattr, (void *)&listextattr_msg, 1);
334784d9c625SLionel Sambuc 
334884d9c625SLionel Sambuc 	listextattr_msg->pvnr_attrnamespace = attrnamespace;
334984d9c625SLionel Sambuc 	listextattr_msg->pvnr_flag = flag;
335084d9c625SLionel Sambuc 	puffs_credcvt(&listextattr_msg->pvnr_cred, ap->a_cred);
335184d9c625SLionel Sambuc 	listextattr_msg->pvnr_resid = tomove;
335284d9c625SLionel Sambuc 	if (sizep)
335384d9c625SLionel Sambuc 		listextattr_msg->pvnr_datasize = 1;
335484d9c625SLionel Sambuc 
335584d9c625SLionel Sambuc 	puffs_msg_setinfo(park_listextattr,
335684d9c625SLionel Sambuc 	    PUFFSOP_VN, PUFFS_VN_LISTEXTATTR, VPTOPNC(vp));
335784d9c625SLionel Sambuc 	puffs_msg_setdelta(park_listextattr, tomove);
335884d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_listextattr, vp->v_data, NULL, error);
335984d9c625SLionel Sambuc 
336084d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
336184d9c625SLionel Sambuc 	if (error)
336284d9c625SLionel Sambuc 		goto out;
336384d9c625SLionel Sambuc 
336484d9c625SLionel Sambuc 	resid = listextattr_msg->pvnr_resid;
336584d9c625SLionel Sambuc 	if (resid > tomove) {
336684d9c625SLionel Sambuc 		puffs_senderr(pmp, PUFFS_ERR_LISTEXTATTR, E2BIG,
336784d9c625SLionel Sambuc 		    "resid grew", VPTOPNC(vp));
336884d9c625SLionel Sambuc 		error = EPROTO;
336984d9c625SLionel Sambuc 		goto out;
337084d9c625SLionel Sambuc 	}
337184d9c625SLionel Sambuc 
337284d9c625SLionel Sambuc 	if (sizep)
337384d9c625SLionel Sambuc 		*sizep = listextattr_msg->pvnr_datasize;
337484d9c625SLionel Sambuc 	if (uio)
337584d9c625SLionel Sambuc 		error = uiomove(listextattr_msg->pvnr_data, tomove-resid, uio);
337684d9c625SLionel Sambuc 
337784d9c625SLionel Sambuc  out:
337884d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(listextattr);
337984d9c625SLionel Sambuc 	return error;
338084d9c625SLionel Sambuc }
338184d9c625SLionel Sambuc 
338284d9c625SLionel Sambuc int
puffs_vnop_deleteextattr(void * v)338384d9c625SLionel Sambuc puffs_vnop_deleteextattr(void *v)
338484d9c625SLionel Sambuc {
338584d9c625SLionel Sambuc 	struct vop_deleteextattr_args /* {
338684d9c625SLionel Sambuc 		struct vnode *a_vp;
338784d9c625SLionel Sambuc 		int a_attrnamespace;
338884d9c625SLionel Sambuc 		const char *a_name;
338984d9c625SLionel Sambuc 		kauth_cred_t a_cred;
339084d9c625SLionel Sambuc 	}; */ *ap = v;
339184d9c625SLionel Sambuc 	PUFFS_MSG_VARS(vn, deleteextattr);
339284d9c625SLionel Sambuc 	struct vnode *vp = ap->a_vp;
339384d9c625SLionel Sambuc 	struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
339484d9c625SLionel Sambuc 	int attrnamespace = ap->a_attrnamespace;
339584d9c625SLionel Sambuc 	const char *name = ap->a_name;
339684d9c625SLionel Sambuc 	int error;
339784d9c625SLionel Sambuc 
339884d9c625SLionel Sambuc 	PUFFS_MSG_ALLOC(vn, deleteextattr);
339984d9c625SLionel Sambuc 	deleteextattr_msg->pvnr_attrnamespace = attrnamespace;
340084d9c625SLionel Sambuc 	strlcpy(deleteextattr_msg->pvnr_attrname, name,
340184d9c625SLionel Sambuc 	    sizeof(deleteextattr_msg->pvnr_attrname));
340284d9c625SLionel Sambuc 	puffs_credcvt(&deleteextattr_msg->pvnr_cred, ap->a_cred);
340384d9c625SLionel Sambuc 
340484d9c625SLionel Sambuc 	puffs_msg_setinfo(park_deleteextattr,
340584d9c625SLionel Sambuc 	    PUFFSOP_VN, PUFFS_VN_DELETEEXTATTR, VPTOPNC(vp));
340684d9c625SLionel Sambuc 	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_deleteextattr,
340784d9c625SLionel Sambuc 	    vp->v_data, NULL, error);
340884d9c625SLionel Sambuc 
340984d9c625SLionel Sambuc 	error = checkerr(pmp, error, __func__);
341084d9c625SLionel Sambuc 
341184d9c625SLionel Sambuc 	PUFFS_MSG_RELEASE(deleteextattr);
341284d9c625SLionel Sambuc 	return error;
341384d9c625SLionel Sambuc }
341484d9c625SLionel Sambuc 
341584d9c625SLionel Sambuc /*
341684d9c625SLionel Sambuc  * spec & fifo.  These call the miscfs spec and fifo vectors, but issue
341784d9c625SLionel Sambuc  * FAF update information for the puffs node first.
341884d9c625SLionel Sambuc  */
341984d9c625SLionel Sambuc int
puffs_vnop_spec_read(void * v)342084d9c625SLionel Sambuc puffs_vnop_spec_read(void *v)
342184d9c625SLionel Sambuc {
342284d9c625SLionel Sambuc 	struct vop_read_args /* {
342384d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
342484d9c625SLionel Sambuc 		struct vnode *a_vp;
342584d9c625SLionel Sambuc 		struct uio *a_uio;
342684d9c625SLionel Sambuc 		int a_ioflag;
342784d9c625SLionel Sambuc 		kauth_cred_t a_cred;
342884d9c625SLionel Sambuc 	} */ *ap = v;
342984d9c625SLionel Sambuc 
343084d9c625SLionel Sambuc 	puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEATIME, 0);
343184d9c625SLionel Sambuc 	return VOCALL(spec_vnodeop_p, VOFFSET(vop_read), v);
343284d9c625SLionel Sambuc }
343384d9c625SLionel Sambuc 
343484d9c625SLionel Sambuc int
puffs_vnop_spec_write(void * v)343584d9c625SLionel Sambuc puffs_vnop_spec_write(void *v)
343684d9c625SLionel Sambuc {
343784d9c625SLionel Sambuc 	struct vop_write_args /* {
343884d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
343984d9c625SLionel Sambuc 		struct vnode *a_vp;
344084d9c625SLionel Sambuc 		struct uio *a_uio;
344184d9c625SLionel Sambuc 		int a_ioflag;
344284d9c625SLionel Sambuc 		kauth_cred_t a_cred;
344384d9c625SLionel Sambuc 	} */ *ap = v;
344484d9c625SLionel Sambuc 
344584d9c625SLionel Sambuc 	puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEMTIME, 0);
344684d9c625SLionel Sambuc 	return VOCALL(spec_vnodeop_p, VOFFSET(vop_write), v);
344784d9c625SLionel Sambuc }
344884d9c625SLionel Sambuc 
344984d9c625SLionel Sambuc int
puffs_vnop_fifo_read(void * v)345084d9c625SLionel Sambuc puffs_vnop_fifo_read(void *v)
345184d9c625SLionel Sambuc {
345284d9c625SLionel Sambuc 	struct vop_read_args /* {
345384d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
345484d9c625SLionel Sambuc 		struct vnode *a_vp;
345584d9c625SLionel Sambuc 		struct uio *a_uio;
345684d9c625SLionel Sambuc 		int a_ioflag;
345784d9c625SLionel Sambuc 		kauth_cred_t a_cred;
345884d9c625SLionel Sambuc 	} */ *ap = v;
345984d9c625SLionel Sambuc 
346084d9c625SLionel Sambuc 	puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEATIME, 0);
346184d9c625SLionel Sambuc 	return VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), v);
346284d9c625SLionel Sambuc }
346384d9c625SLionel Sambuc 
346484d9c625SLionel Sambuc int
puffs_vnop_fifo_write(void * v)346584d9c625SLionel Sambuc puffs_vnop_fifo_write(void *v)
346684d9c625SLionel Sambuc {
346784d9c625SLionel Sambuc 	struct vop_write_args /* {
346884d9c625SLionel Sambuc 		const struct vnodeop_desc *a_desc;
346984d9c625SLionel Sambuc 		struct vnode *a_vp;
347084d9c625SLionel Sambuc 		struct uio *a_uio;
347184d9c625SLionel Sambuc 		int a_ioflag;
347284d9c625SLionel Sambuc 		kauth_cred_t a_cred;
347384d9c625SLionel Sambuc 	} */ *ap = v;
347484d9c625SLionel Sambuc 
347584d9c625SLionel Sambuc 	puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEMTIME, 0);
347684d9c625SLionel Sambuc 	return VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), v);
347784d9c625SLionel Sambuc }
3478