puffs_vnops.c revision 1.213 1 /* $NetBSD: puffs_vnops.c,v 1.213 2018/11/06 02:39:49 manu Exp $ */
2
3 /*
4 * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.213 2018/11/06 02:39:49 manu Exp $");
34
35 #include <sys/param.h>
36 #include <sys/buf.h>
37 #include <sys/lockf.h>
38 #include <sys/malloc.h>
39 #include <sys/mount.h>
40 #include <sys/namei.h>
41 #include <sys/vnode.h>
42 #include <sys/proc.h>
43 #include <sys/kernel.h> /* For hz, hardclock_ticks */
44
45 #include <uvm/uvm.h>
46
47 #include <fs/puffs/puffs_msgif.h>
48 #include <fs/puffs/puffs_sys.h>
49
50 #include <miscfs/fifofs/fifo.h>
51 #include <miscfs/genfs/genfs.h>
52 #include <miscfs/specfs/specdev.h>
53
54 int puffs_vnop_lookup(void *);
55 int puffs_vnop_create(void *);
56 int puffs_vnop_access(void *);
57 int puffs_vnop_mknod(void *);
58 int puffs_vnop_open(void *);
59 int puffs_vnop_close(void *);
60 int puffs_vnop_getattr(void *);
61 int puffs_vnop_setattr(void *);
62 int puffs_vnop_reclaim(void *);
63 int puffs_vnop_readdir(void *);
64 int puffs_vnop_poll(void *);
65 int puffs_vnop_fsync(void *);
66 int puffs_vnop_seek(void *);
67 int puffs_vnop_remove(void *);
68 int puffs_vnop_mkdir(void *);
69 int puffs_vnop_rmdir(void *);
70 int puffs_vnop_link(void *);
71 int puffs_vnop_readlink(void *);
72 int puffs_vnop_symlink(void *);
73 int puffs_vnop_rename(void *);
74 int puffs_vnop_read(void *);
75 int puffs_vnop_write(void *);
76 int puffs_vnop_fallocate(void *);
77 int puffs_vnop_fdiscard(void *);
78 int puffs_vnop_fcntl(void *);
79 int puffs_vnop_ioctl(void *);
80 int puffs_vnop_inactive(void *);
81 int puffs_vnop_print(void *);
82 int puffs_vnop_pathconf(void *);
83 int puffs_vnop_advlock(void *);
84 int puffs_vnop_strategy(void *);
85 int puffs_vnop_bmap(void *);
86 int puffs_vnop_mmap(void *);
87 int puffs_vnop_getpages(void *);
88 int puffs_vnop_abortop(void *);
89 int puffs_vnop_getextattr(void *);
90 int puffs_vnop_setextattr(void *);
91 int puffs_vnop_listextattr(void *);
92 int puffs_vnop_deleteextattr(void *);
93
94 int puffs_vnop_spec_read(void *);
95 int puffs_vnop_spec_write(void *);
96 int puffs_vnop_fifo_read(void *);
97 int puffs_vnop_fifo_write(void *);
98
99 int puffs_vnop_checkop(void *);
100
101 #define puffs_vnop_lock genfs_lock
102 #define puffs_vnop_unlock genfs_unlock
103 #define puffs_vnop_islocked genfs_islocked
104
105 int (**puffs_vnodeop_p)(void *);
106 const struct vnodeopv_entry_desc puffs_vnodeop_entries[] = {
107 { &vop_default_desc, vn_default_error },
108 { &vop_lookup_desc, puffs_vnop_lookup }, /* REAL lookup */
109 { &vop_create_desc, puffs_vnop_checkop }, /* create */
110 { &vop_mknod_desc, puffs_vnop_checkop }, /* mknod */
111 { &vop_open_desc, puffs_vnop_open }, /* REAL open */
112 { &vop_close_desc, puffs_vnop_checkop }, /* close */
113 { &vop_access_desc, puffs_vnop_access }, /* REAL access */
114 { &vop_getattr_desc, puffs_vnop_checkop }, /* getattr */
115 { &vop_setattr_desc, puffs_vnop_checkop }, /* setattr */
116 { &vop_read_desc, puffs_vnop_checkop }, /* read */
117 { &vop_write_desc, puffs_vnop_checkop }, /* write */
118 { &vop_fallocate_desc, puffs_vnop_fallocate }, /* fallocate */
119 { &vop_fdiscard_desc, puffs_vnop_fdiscard }, /* fdiscard */
120 { &vop_fsync_desc, puffs_vnop_fsync }, /* REAL fsync */
121 { &vop_seek_desc, puffs_vnop_checkop }, /* seek */
122 { &vop_remove_desc, puffs_vnop_checkop }, /* remove */
123 { &vop_link_desc, puffs_vnop_checkop }, /* link */
124 { &vop_rename_desc, puffs_vnop_checkop }, /* rename */
125 { &vop_mkdir_desc, puffs_vnop_checkop }, /* mkdir */
126 { &vop_rmdir_desc, puffs_vnop_checkop }, /* rmdir */
127 { &vop_symlink_desc, puffs_vnop_checkop }, /* symlink */
128 { &vop_readdir_desc, puffs_vnop_checkop }, /* readdir */
129 { &vop_readlink_desc, puffs_vnop_checkop }, /* readlink */
130 { &vop_getpages_desc, puffs_vnop_checkop }, /* getpages */
131 { &vop_putpages_desc, genfs_putpages }, /* REAL putpages */
132 { &vop_pathconf_desc, puffs_vnop_checkop }, /* pathconf */
133 { &vop_advlock_desc, puffs_vnop_advlock }, /* advlock */
134 { &vop_strategy_desc, puffs_vnop_strategy }, /* REAL strategy */
135 { &vop_revoke_desc, genfs_revoke }, /* REAL revoke */
136 { &vop_abortop_desc, puffs_vnop_abortop }, /* REAL abortop */
137 { &vop_inactive_desc, puffs_vnop_inactive }, /* REAL inactive */
138 { &vop_reclaim_desc, puffs_vnop_reclaim }, /* REAL reclaim */
139 { &vop_lock_desc, puffs_vnop_lock }, /* REAL lock */
140 { &vop_unlock_desc, puffs_vnop_unlock }, /* REAL unlock */
141 { &vop_bmap_desc, puffs_vnop_bmap }, /* REAL bmap */
142 { &vop_print_desc, puffs_vnop_print }, /* REAL print */
143 { &vop_islocked_desc, puffs_vnop_islocked }, /* REAL islocked */
144 { &vop_bwrite_desc, genfs_nullop }, /* REAL bwrite */
145 { &vop_mmap_desc, puffs_vnop_mmap }, /* REAL mmap */
146 { &vop_poll_desc, puffs_vnop_poll }, /* REAL poll */
147 { &vop_getextattr_desc, puffs_vnop_getextattr }, /* getextattr */
148 { &vop_setextattr_desc, puffs_vnop_setextattr }, /* setextattr */
149 { &vop_listextattr_desc, puffs_vnop_listextattr }, /* listextattr */
150 { &vop_deleteextattr_desc, puffs_vnop_deleteextattr },/* deleteextattr */
151 #if 0
152 { &vop_openextattr_desc, puffs_vnop_checkop }, /* openextattr */
153 { &vop_closeextattr_desc, puffs_vnop_checkop }, /* closeextattr */
154 #endif
155 { &vop_kqfilter_desc, genfs_eopnotsupp }, /* kqfilter XXX */
156 { NULL, NULL }
157 };
158 const struct vnodeopv_desc puffs_vnodeop_opv_desc =
159 { &puffs_vnodeop_p, puffs_vnodeop_entries };
160
161
162 int (**puffs_specop_p)(void *);
163 const struct vnodeopv_entry_desc puffs_specop_entries[] = {
164 { &vop_default_desc, vn_default_error },
165 { &vop_lookup_desc, spec_lookup }, /* lookup, ENOTDIR */
166 { &vop_create_desc, spec_create }, /* genfs_badop */
167 { &vop_mknod_desc, spec_mknod }, /* genfs_badop */
168 { &vop_open_desc, spec_open }, /* spec_open */
169 { &vop_close_desc, spec_close }, /* spec_close */
170 { &vop_access_desc, puffs_vnop_checkop }, /* access */
171 { &vop_getattr_desc, puffs_vnop_checkop }, /* getattr */
172 { &vop_setattr_desc, puffs_vnop_checkop }, /* setattr */
173 { &vop_read_desc, puffs_vnop_spec_read }, /* update, read */
174 { &vop_write_desc, puffs_vnop_spec_write }, /* update, write */
175 { &vop_fallocate_desc, spec_fallocate }, /* fallocate */
176 { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
177 { &vop_ioctl_desc, spec_ioctl }, /* spec_ioctl */
178 { &vop_fcntl_desc, genfs_fcntl }, /* dummy */
179 { &vop_poll_desc, spec_poll }, /* spec_poll */
180 { &vop_kqfilter_desc, spec_kqfilter }, /* spec_kqfilter */
181 { &vop_revoke_desc, spec_revoke }, /* genfs_revoke */
182 { &vop_mmap_desc, spec_mmap }, /* spec_mmap */
183 { &vop_fsync_desc, spec_fsync }, /* vflushbuf */
184 { &vop_seek_desc, spec_seek }, /* genfs_nullop */
185 { &vop_remove_desc, spec_remove }, /* genfs_badop */
186 { &vop_link_desc, spec_link }, /* genfs_badop */
187 { &vop_rename_desc, spec_rename }, /* genfs_badop */
188 { &vop_mkdir_desc, spec_mkdir }, /* genfs_badop */
189 { &vop_rmdir_desc, spec_rmdir }, /* genfs_badop */
190 { &vop_symlink_desc, spec_symlink }, /* genfs_badop */
191 { &vop_readdir_desc, spec_readdir }, /* genfs_badop */
192 { &vop_readlink_desc, spec_readlink }, /* genfs_badop */
193 { &vop_abortop_desc, spec_abortop }, /* genfs_badop */
194 { &vop_inactive_desc, puffs_vnop_inactive }, /* REAL inactive */
195 { &vop_reclaim_desc, puffs_vnop_reclaim }, /* REAL reclaim */
196 { &vop_lock_desc, puffs_vnop_lock }, /* REAL lock */
197 { &vop_unlock_desc, puffs_vnop_unlock }, /* REAL unlock */
198 { &vop_bmap_desc, spec_bmap }, /* dummy */
199 { &vop_strategy_desc, spec_strategy }, /* dev strategy */
200 { &vop_print_desc, puffs_vnop_print }, /* REAL print */
201 { &vop_islocked_desc, puffs_vnop_islocked }, /* REAL islocked */
202 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
203 { &vop_advlock_desc, spec_advlock }, /* lf_advlock */
204 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
205 { &vop_getpages_desc, spec_getpages }, /* genfs_getpages */
206 { &vop_putpages_desc, spec_putpages }, /* genfs_putpages */
207 { &vop_getextattr_desc, puffs_vnop_checkop }, /* getextattr */
208 { &vop_setextattr_desc, puffs_vnop_checkop }, /* setextattr */
209 { &vop_listextattr_desc, puffs_vnop_checkop }, /* listextattr */
210 { &vop_deleteextattr_desc, puffs_vnop_checkop },/* deleteextattr */
211 #if 0
212 { &vop_openextattr_desc, _openextattr }, /* openextattr */
213 { &vop_closeextattr_desc, _closeextattr }, /* closeextattr */
214 #endif
215 { NULL, NULL }
216 };
217 const struct vnodeopv_desc puffs_specop_opv_desc =
218 { &puffs_specop_p, puffs_specop_entries };
219
220
221 int (**puffs_fifoop_p)(void *);
222 const struct vnodeopv_entry_desc puffs_fifoop_entries[] = {
223 { &vop_default_desc, vn_default_error },
224 { &vop_lookup_desc, vn_fifo_bypass }, /* lookup, ENOTDIR */
225 { &vop_create_desc, vn_fifo_bypass }, /* genfs_badop */
226 { &vop_mknod_desc, vn_fifo_bypass }, /* genfs_badop */
227 { &vop_open_desc, vn_fifo_bypass }, /* open */
228 { &vop_close_desc, vn_fifo_bypass }, /* close */
229 { &vop_access_desc, puffs_vnop_checkop }, /* access */
230 { &vop_getattr_desc, puffs_vnop_checkop }, /* getattr */
231 { &vop_setattr_desc, puffs_vnop_checkop }, /* setattr */
232 { &vop_read_desc, puffs_vnop_fifo_read }, /* read, update */
233 { &vop_write_desc, puffs_vnop_fifo_write }, /* write, update */
234 { &vop_fallocate_desc, vn_fifo_bypass }, /* fallocate */
235 { &vop_fdiscard_desc, vn_fifo_bypass }, /* fdiscard */
236 { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */
237 { &vop_fcntl_desc, genfs_fcntl }, /* dummy */
238 { &vop_poll_desc, vn_fifo_bypass }, /* poll */
239 { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */
240 { &vop_revoke_desc, vn_fifo_bypass }, /* genfs_revoke */
241 { &vop_mmap_desc, vn_fifo_bypass }, /* genfs_badop */
242 { &vop_fsync_desc, vn_fifo_bypass }, /* genfs_nullop*/
243 { &vop_seek_desc, vn_fifo_bypass }, /* genfs_badop */
244 { &vop_remove_desc, vn_fifo_bypass }, /* genfs_badop */
245 { &vop_link_desc, vn_fifo_bypass }, /* genfs_badop */
246 { &vop_rename_desc, vn_fifo_bypass }, /* genfs_badop */
247 { &vop_mkdir_desc, vn_fifo_bypass }, /* genfs_badop */
248 { &vop_rmdir_desc, vn_fifo_bypass }, /* genfs_badop */
249 { &vop_symlink_desc, vn_fifo_bypass }, /* genfs_badop */
250 { &vop_readdir_desc, vn_fifo_bypass }, /* genfs_badop */
251 { &vop_readlink_desc, vn_fifo_bypass }, /* genfs_badop */
252 { &vop_abortop_desc, vn_fifo_bypass }, /* genfs_badop */
253 { &vop_inactive_desc, puffs_vnop_inactive }, /* REAL inactive */
254 { &vop_reclaim_desc, puffs_vnop_reclaim }, /* REAL reclaim */
255 { &vop_lock_desc, puffs_vnop_lock }, /* REAL lock */
256 { &vop_unlock_desc, puffs_vnop_unlock }, /* REAL unlock */
257 { &vop_bmap_desc, vn_fifo_bypass }, /* dummy */
258 { &vop_strategy_desc, vn_fifo_bypass }, /* genfs_badop */
259 { &vop_print_desc, puffs_vnop_print }, /* REAL print */
260 { &vop_islocked_desc, puffs_vnop_islocked }, /* REAL islocked */
261 { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */
262 { &vop_advlock_desc, vn_fifo_bypass }, /* genfs_einval */
263 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
264 { &vop_putpages_desc, vn_fifo_bypass }, /* genfs_null_putpages*/
265 #if 0
266 { &vop_openextattr_desc, _openextattr }, /* openextattr */
267 { &vop_closeextattr_desc, _closeextattr }, /* closeextattr */
268 #endif
269 { &vop_getextattr_desc, puffs_vnop_checkop }, /* getextattr */
270 { &vop_setextattr_desc, puffs_vnop_checkop }, /* setextattr */
271 { &vop_listextattr_desc, puffs_vnop_checkop }, /* listextattr */
272 { &vop_deleteextattr_desc, puffs_vnop_checkop }, /* deleteextattr */
273 { NULL, NULL }
274 };
275 const struct vnodeopv_desc puffs_fifoop_opv_desc =
276 { &puffs_fifoop_p, puffs_fifoop_entries };
277
278
279 /* "real" vnode operations */
280 int (**puffs_msgop_p)(void *);
281 const struct vnodeopv_entry_desc puffs_msgop_entries[] = {
282 { &vop_default_desc, vn_default_error },
283 { &vop_create_desc, puffs_vnop_create }, /* create */
284 { &vop_mknod_desc, puffs_vnop_mknod }, /* mknod */
285 { &vop_open_desc, puffs_vnop_open }, /* open */
286 { &vop_close_desc, puffs_vnop_close }, /* close */
287 { &vop_access_desc, puffs_vnop_access }, /* access */
288 { &vop_getattr_desc, puffs_vnop_getattr }, /* getattr */
289 { &vop_setattr_desc, puffs_vnop_setattr }, /* setattr */
290 { &vop_read_desc, puffs_vnop_read }, /* read */
291 { &vop_write_desc, puffs_vnop_write }, /* write */
292 { &vop_seek_desc, puffs_vnop_seek }, /* seek */
293 { &vop_remove_desc, puffs_vnop_remove }, /* remove */
294 { &vop_link_desc, puffs_vnop_link }, /* link */
295 { &vop_rename_desc, puffs_vnop_rename }, /* rename */
296 { &vop_mkdir_desc, puffs_vnop_mkdir }, /* mkdir */
297 { &vop_rmdir_desc, puffs_vnop_rmdir }, /* rmdir */
298 { &vop_symlink_desc, puffs_vnop_symlink }, /* symlink */
299 { &vop_readdir_desc, puffs_vnop_readdir }, /* readdir */
300 { &vop_readlink_desc, puffs_vnop_readlink }, /* readlink */
301 { &vop_print_desc, puffs_vnop_print }, /* print */
302 { &vop_islocked_desc, puffs_vnop_islocked }, /* islocked */
303 { &vop_pathconf_desc, puffs_vnop_pathconf }, /* pathconf */
304 { &vop_getpages_desc, puffs_vnop_getpages }, /* getpages */
305 { NULL, NULL }
306 };
307 const struct vnodeopv_desc puffs_msgop_opv_desc =
308 { &puffs_msgop_p, puffs_msgop_entries };
309
310 /*
311 * for dosetattr / update_va
312 */
313 #define SETATTR_CHSIZE 0x01
314 #define SETATTR_ASYNC 0x02
315
316 #define ERROUT(err) \
317 do { \
318 error = err; \
319 goto out; \
320 } while (/*CONSTCOND*/0)
321
322 /*
323 * This is a generic vnode operation handler. It checks if the necessary
324 * operations for the called vnode operation are implemented by userspace
325 * and either returns a dummy return value or proceeds to call the real
326 * vnode operation from puffs_msgop_v.
327 *
328 * XXX: this should described elsewhere and autogenerated, the complexity
329 * of the vnode operations vectors and their interrelationships is also
330 * getting a bit out of hand. Another problem is that we need this same
331 * information in the fs server code, so keeping the two in sync manually
332 * is not a viable (long term) plan.
333 */
334
335 /* not supported, handle locking protocol */
336 #define CHECKOP_NOTSUPP(op) \
337 case VOP_##op##_DESCOFFSET: \
338 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
339 return genfs_eopnotsupp(v); \
340 break
341
342 /* always succeed, no locking */
343 #define CHECKOP_SUCCESS(op) \
344 case VOP_##op##_DESCOFFSET: \
345 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
346 return 0; \
347 break
348
349 int
350 puffs_vnop_checkop(void *v)
351 {
352 struct vop_generic_args /* {
353 struct vnodeop_desc *a_desc;
354 spooky mystery contents;
355 } */ *ap = v;
356 struct vnodeop_desc *desc = ap->a_desc;
357 struct puffs_mount *pmp;
358 struct vnode *vp;
359 int offset, rv;
360
361 offset = ap->a_desc->vdesc_vp_offsets[0];
362 #ifdef DIAGNOSTIC
363 if (offset == VDESC_NO_OFFSET)
364 panic("puffs_checkop: no vnode, why did you call me?");
365 #endif
366 vp = *VOPARG_OFFSETTO(struct vnode **, offset, ap);
367 pmp = MPTOPUFFSMP(vp->v_mount);
368
369 DPRINTF_VERBOSE(("checkop call %s (%d), vp %p\n",
370 ap->a_desc->vdesc_name, ap->a_desc->vdesc_offset, vp));
371
372 if (!ALLOPS(pmp)) {
373 switch (desc->vdesc_offset) {
374 CHECKOP_NOTSUPP(CREATE);
375 CHECKOP_NOTSUPP(MKNOD);
376 CHECKOP_NOTSUPP(GETATTR);
377 CHECKOP_NOTSUPP(SETATTR);
378 CHECKOP_NOTSUPP(READ);
379 CHECKOP_NOTSUPP(WRITE);
380 CHECKOP_NOTSUPP(FCNTL);
381 CHECKOP_NOTSUPP(IOCTL);
382 CHECKOP_NOTSUPP(REMOVE);
383 CHECKOP_NOTSUPP(LINK);
384 CHECKOP_NOTSUPP(RENAME);
385 CHECKOP_NOTSUPP(MKDIR);
386 CHECKOP_NOTSUPP(RMDIR);
387 CHECKOP_NOTSUPP(SYMLINK);
388 CHECKOP_NOTSUPP(READDIR);
389 CHECKOP_NOTSUPP(READLINK);
390 CHECKOP_NOTSUPP(PRINT);
391 CHECKOP_NOTSUPP(PATHCONF);
392 CHECKOP_NOTSUPP(GETEXTATTR);
393 CHECKOP_NOTSUPP(SETEXTATTR);
394 CHECKOP_NOTSUPP(LISTEXTATTR);
395 CHECKOP_NOTSUPP(DELETEEXTATTR);
396
397 CHECKOP_SUCCESS(ACCESS);
398 CHECKOP_SUCCESS(CLOSE);
399 CHECKOP_SUCCESS(SEEK);
400
401 case VOP_GETPAGES_DESCOFFSET:
402 if (!EXISTSOP(pmp, READ))
403 return genfs_eopnotsupp(v);
404 break;
405
406 default:
407 panic("puffs_checkop: unhandled vnop %d",
408 desc->vdesc_offset);
409 }
410 }
411
412 rv = VOCALL(puffs_msgop_p, ap->a_desc->vdesc_offset, v);
413
414 DPRINTF_VERBOSE(("checkop return %s (%d), vp %p: %d\n",
415 ap->a_desc->vdesc_name, ap->a_desc->vdesc_offset, vp, rv));
416
417 return rv;
418 }
419
420 static int callremove(struct puffs_mount *, puffs_cookie_t, puffs_cookie_t,
421 struct componentname *);
422 static int callrmdir(struct puffs_mount *, puffs_cookie_t, puffs_cookie_t,
423 struct componentname *);
424 static void callinactive(struct puffs_mount *, puffs_cookie_t, int);
425 static void callreclaim(struct puffs_mount *, puffs_cookie_t, int);
426 static int flushvncache(struct vnode *, off_t, off_t, bool);
427 static void update_va(struct vnode *, struct vattr *, struct vattr *,
428 struct timespec *, struct timespec *, int);
429 static void update_parent(struct vnode *, struct vnode *);
430
431
432 #define PUFFS_ABORT_LOOKUP 1
433 #define PUFFS_ABORT_CREATE 2
434 #define PUFFS_ABORT_MKNOD 3
435 #define PUFFS_ABORT_MKDIR 4
436 #define PUFFS_ABORT_SYMLINK 5
437
438 /*
439 * Press the pani^Wabort button! Kernel resource allocation failed.
440 */
441 static void
442 puffs_abortbutton(struct puffs_mount *pmp, int what,
443 puffs_cookie_t dck, puffs_cookie_t ck, struct componentname *cnp)
444 {
445
446 switch (what) {
447 case PUFFS_ABORT_CREATE:
448 case PUFFS_ABORT_MKNOD:
449 case PUFFS_ABORT_SYMLINK:
450 callremove(pmp, dck, ck, cnp);
451 break;
452 case PUFFS_ABORT_MKDIR:
453 callrmdir(pmp, dck, ck, cnp);
454 break;
455 }
456
457 callinactive(pmp, ck, 0);
458 callreclaim(pmp, ck, 1);
459 }
460
461 /*
462 * Begin vnode operations.
463 *
464 * A word from the keymaster about locks: generally we don't want
465 * to use the vnode locks at all: it creates an ugly dependency between
466 * the userlandia file server and the kernel. But we'll play along with
467 * the kernel vnode locks for now. However, even currently we attempt
468 * to release locks as early as possible. This is possible for some
469 * operations which a) don't need a locked vnode after the userspace op
470 * and b) return with the vnode unlocked. Theoretically we could
471 * unlock-do op-lock for others and order the graph in userspace, but I
472 * don't want to think of the consequences for the time being.
473 */
474
475 #define TTL_TO_TIMEOUT(ts) \
476 (hardclock_ticks + (ts->tv_sec * hz) + (ts->tv_nsec * hz / 1000000000))
477 #define TTL_VALID(ts) \
478 ((ts != NULL) && !((ts->tv_sec == 0) && (ts->tv_nsec == 0)))
479 #define TIMED_OUT(expire) \
480 ((int)((unsigned int)hardclock_ticks - (unsigned int)expire) > 0)
481 int
482 puffs_vnop_lookup(void *v)
483 {
484 struct vop_lookup_v2_args /* {
485 const struct vnodeop_desc *a_desc;
486 struct vnode *a_dvp;
487 struct vnode **a_vpp;
488 struct componentname *a_cnp;
489 } */ *ap = v;
490 PUFFS_MSG_VARS(vn, lookup);
491 struct puffs_mount *pmp;
492 struct componentname *cnp;
493 struct vnode *vp, *dvp, *cvp;
494 struct puffs_node *dpn, *cpn;
495 int isdot;
496 int error;
497
498 pmp = MPTOPUFFSMP(ap->a_dvp->v_mount);
499 cnp = ap->a_cnp;
500 dvp = ap->a_dvp;
501 cvp = NULL;
502 cpn = NULL;
503 *ap->a_vpp = NULL;
504
505 /* r/o fs? we check create later to handle EEXIST */
506 if ((cnp->cn_flags & ISLASTCN)
507 && (dvp->v_mount->mnt_flag & MNT_RDONLY)
508 && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
509 return EROFS;
510
511 isdot = cnp->cn_namelen == 1 && *cnp->cn_nameptr == '.';
512
513 DPRINTF(("puffs_lookup: \"%s\", parent vnode %p, op: %x\n",
514 cnp->cn_nameptr, dvp, cnp->cn_nameiop));
515
516 /*
517 * If dotdot cache is enabled, add reference to .. and return.
518 */
519 if (PUFFS_USE_DOTDOTCACHE(pmp) && (cnp->cn_flags & ISDOTDOT)) {
520 vp = VPTOPP(ap->a_dvp)->pn_parent;
521 vref(vp);
522
523 *ap->a_vpp = vp;
524 return 0;
525 }
526
527 /*
528 * Check if someone fed it into the cache
529 */
530 if (!isdot && PUFFS_USE_NAMECACHE(pmp)) {
531 int found, iswhiteout;
532
533 found = cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
534 cnp->cn_nameiop, cnp->cn_flags,
535 &iswhiteout, ap->a_vpp);
536 if (iswhiteout) {
537 cnp->cn_flags |= ISWHITEOUT;
538 }
539
540 if (found && *ap->a_vpp != NULLVP && PUFFS_USE_FS_TTL(pmp)) {
541 cvp = *ap->a_vpp;
542 cpn = VPTOPP(cvp);
543
544 if (TIMED_OUT(cpn->pn_cn_timeout)) {
545 cache_purge(cvp);
546 /*
547 * cached vnode (cvp) is still referenced
548 * so that we can reuse it upon a new
549 * successful lookup.
550 */
551 *ap->a_vpp = NULL;
552 found = 0;
553 }
554 }
555
556 /*
557 * Do not use negative caching, since the filesystem
558 * provides no TTL for it.
559 */
560 if (found && *ap->a_vpp == NULLVP && PUFFS_USE_FS_TTL(pmp))
561 found = 0;
562
563 if (found) {
564 return *ap->a_vpp == NULLVP ? ENOENT : 0;
565 }
566
567 /*
568 * This is what would have been left in ERROR before
569 * the rearrangement of cache_lookup(). What with all
570 * the macros, I am not sure if this is a dead value
571 * below or not.
572 */
573 error = -1;
574 }
575
576 if (isdot) {
577 /* deal with rename lookup semantics */
578 if (cnp->cn_nameiop == RENAME && (cnp->cn_flags & ISLASTCN))
579 return EISDIR;
580
581 vp = ap->a_dvp;
582 vref(vp);
583 *ap->a_vpp = vp;
584 return 0;
585 }
586
587 if (cvp != NULL) {
588 if (vn_lock(cvp, LK_EXCLUSIVE) != 0) {
589 vrele(cvp);
590 cvp = NULL;
591 } else
592 mutex_enter(&cpn->pn_sizemtx);
593 }
594
595 PUFFS_MSG_ALLOC(vn, lookup);
596 puffs_makecn(&lookup_msg->pvnr_cn, &lookup_msg->pvnr_cn_cred,
597 cnp, PUFFS_USE_FULLPNBUF(pmp));
598
599 if (cnp->cn_flags & ISDOTDOT)
600 VOP_UNLOCK(dvp);
601
602 puffs_msg_setinfo(park_lookup, PUFFSOP_VN,
603 PUFFS_VN_LOOKUP, VPTOPNC(dvp));
604 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_lookup, dvp->v_data, NULL, error);
605 DPRINTF(("puffs_lookup: return of the userspace, part %d\n", error));
606
607 /*
608 * In case of error, there is no new vnode to play with, so be
609 * happy with the NULL value given to vpp in the beginning.
610 * Also, check if this really was an error or the target was not
611 * present. Either treat it as a non-error for CREATE/RENAME or
612 * enter the component into the negative name cache (if desired).
613 */
614 if (error) {
615 error = checkerr(pmp, error, __func__);
616 if (error == ENOENT) {
617 /* don't allow to create files on r/o fs */
618 if ((dvp->v_mount->mnt_flag & MNT_RDONLY)
619 && cnp->cn_nameiop == CREATE) {
620 error = EROFS;
621
622 /* adjust values if we are creating */
623 } else if ((cnp->cn_flags & ISLASTCN)
624 && (cnp->cn_nameiop == CREATE
625 || cnp->cn_nameiop == RENAME)) {
626 error = EJUSTRETURN;
627
628 /* save negative cache entry */
629 } else {
630 if (PUFFS_USE_NAMECACHE(pmp) &&
631 !PUFFS_USE_FS_TTL(pmp))
632 cache_enter(dvp, NULL, cnp->cn_nameptr,
633 cnp->cn_namelen, cnp->cn_flags);
634 }
635 }
636 goto out;
637 }
638
639 /*
640 * Check that we don't get our parent node back, that would cause
641 * a pretty obvious deadlock.
642 */
643 dpn = dvp->v_data;
644 if (lookup_msg->pvnr_newnode == dpn->pn_cookie) {
645 puffs_senderr(pmp, PUFFS_ERR_LOOKUP, EINVAL,
646 "lookup produced parent cookie", lookup_msg->pvnr_newnode);
647 error = EPROTO;
648 goto out;
649 }
650
651 /*
652 * Check if we looked up the cached vnode
653 */
654 vp = NULL;
655 if (cvp && (VPTOPP(cvp)->pn_cookie == lookup_msg->pvnr_newnode)) {
656 int grace;
657
658 /*
659 * Bump grace time of this node so that it does not get
660 * reclaimed too fast. We try to increase a bit more the
661 * lifetime of busiest * nodes - with some limits.
662 */
663 grace = 10 * puffs_sopreq_expire_timeout;
664 cpn->pn_cn_grace = hardclock_ticks + grace;
665 vp = cvp;
666 }
667
668 /*
669 * No cached vnode available, or the cached vnode does not
670 * match the userland cookie anymore: is the node known?
671 */
672 if (vp == NULL) {
673 error = puffs_getvnode(dvp->v_mount,
674 lookup_msg->pvnr_newnode, lookup_msg->pvnr_vtype,
675 lookup_msg->pvnr_size, lookup_msg->pvnr_rdev, &vp);
676 if (error) {
677 puffs_abortbutton(pmp, PUFFS_ABORT_LOOKUP,
678 VPTOPNC(dvp), lookup_msg->pvnr_newnode,
679 ap->a_cnp);
680 goto out;
681 }
682
683 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
684 }
685
686 /*
687 * Update cache and TTL
688 */
689 if (PUFFS_USE_FS_TTL(pmp)) {
690 struct timespec *va_ttl = &lookup_msg->pvnr_va_ttl;
691 struct timespec *cn_ttl = &lookup_msg->pvnr_cn_ttl;
692 update_va(vp, NULL, &lookup_msg->pvnr_va,
693 va_ttl, cn_ttl, SETATTR_CHSIZE);
694 }
695
696 KASSERT(lookup_msg->pvnr_newnode == VPTOPP(vp)->pn_cookie);
697 *ap->a_vpp = vp;
698
699 if (PUFFS_USE_NAMECACHE(pmp))
700 cache_enter(dvp, vp, cnp->cn_nameptr, cnp->cn_namelen,
701 cnp->cn_flags);
702
703 /* XXX */
704 if ((lookup_msg->pvnr_cn.pkcn_flags & REQUIREDIR) == 0)
705 cnp->cn_flags &= ~REQUIREDIR;
706 if (lookup_msg->pvnr_cn.pkcn_consume)
707 cnp->cn_consume = MIN(lookup_msg->pvnr_cn.pkcn_consume,
708 strlen(cnp->cn_nameptr) - cnp->cn_namelen);
709
710 VPTOPP(vp)->pn_nlookup++;
711
712 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
713 (VPTOPP(vp)->pn_parent != dvp))
714 update_parent(vp, dvp);
715
716 out:
717 if (cvp != NULL) {
718 mutex_exit(&cpn->pn_sizemtx);
719
720 if (error || (cvp != vp))
721 vput(cvp);
722 }
723 if (error == 0)
724 VOP_UNLOCK(*ap->a_vpp);
725
726 if (cnp->cn_flags & ISDOTDOT)
727 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
728
729 DPRINTF(("puffs_lookup: returning %d %p\n", error, *ap->a_vpp));
730 PUFFS_MSG_RELEASE(lookup);
731 return error;
732 }
733
734 #define REFPN_AND_UNLOCKVP(a, b) \
735 do { \
736 mutex_enter(&b->pn_mtx); \
737 puffs_referencenode(b); \
738 mutex_exit(&b->pn_mtx); \
739 VOP_UNLOCK(a); \
740 } while (/*CONSTCOND*/0)
741
742 #define REFPN(b) \
743 do { \
744 mutex_enter(&b->pn_mtx); \
745 puffs_referencenode(b); \
746 mutex_exit(&b->pn_mtx); \
747 } while (/*CONSTCOND*/0)
748
749 #define RELEPN_AND_VP(a, b) \
750 do { \
751 puffs_releasenode(b); \
752 vrele(a); \
753 } while (/*CONSTCOND*/0)
754
755 int
756 puffs_vnop_create(void *v)
757 {
758 struct vop_create_v3_args /* {
759 const struct vnodeop_desc *a_desc;
760 struct vnode *a_dvp;
761 struct vnode **a_vpp;
762 struct componentname *a_cnp;
763 struct vattr *a_vap;
764 } */ *ap = v;
765 PUFFS_MSG_VARS(vn, create);
766 struct vnode *dvp = ap->a_dvp;
767 struct puffs_node *dpn = VPTOPP(dvp);
768 struct componentname *cnp = ap->a_cnp;
769 struct mount *mp = dvp->v_mount;
770 struct puffs_mount *pmp = MPTOPUFFSMP(mp);
771 int error;
772
773 DPRINTF(("puffs_create: dvp %p, cnp: %s\n",
774 dvp, ap->a_cnp->cn_nameptr));
775
776 PUFFS_MSG_ALLOC(vn, create);
777 puffs_makecn(&create_msg->pvnr_cn, &create_msg->pvnr_cn_cred,
778 cnp, PUFFS_USE_FULLPNBUF(pmp));
779 create_msg->pvnr_va = *ap->a_vap;
780 puffs_msg_setinfo(park_create, PUFFSOP_VN,
781 PUFFS_VN_CREATE, VPTOPNC(dvp));
782 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_create, dvp->v_data, NULL, error);
783
784 error = checkerr(pmp, error, __func__);
785 if (error)
786 goto out;
787
788 error = puffs_newnode(mp, dvp, ap->a_vpp,
789 create_msg->pvnr_newnode, cnp, ap->a_vap->va_type, 0);
790 if (error) {
791 puffs_abortbutton(pmp, PUFFS_ABORT_CREATE, dpn->pn_cookie,
792 create_msg->pvnr_newnode, cnp);
793 goto out;
794 }
795
796 if (PUFFS_USE_FS_TTL(pmp)) {
797 struct timespec *va_ttl = &create_msg->pvnr_va_ttl;
798 struct timespec *cn_ttl = &create_msg->pvnr_cn_ttl;
799 struct vattr *rvap = &create_msg->pvnr_va;
800
801 update_va(*ap->a_vpp, NULL, rvap,
802 va_ttl, cn_ttl, SETATTR_CHSIZE);
803 }
804
805 VPTOPP(*ap->a_vpp)->pn_nlookup++;
806
807 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
808 (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
809 update_parent(*ap->a_vpp, dvp);
810
811 out:
812 DPRINTF(("puffs_create: return %d\n", error));
813 PUFFS_MSG_RELEASE(create);
814 return error;
815 }
816
817 int
818 puffs_vnop_mknod(void *v)
819 {
820 struct vop_mknod_v3_args /* {
821 const struct vnodeop_desc *a_desc;
822 struct vnode *a_dvp;
823 struct vnode **a_vpp;
824 struct componentname *a_cnp;
825 struct vattr *a_vap;
826 } */ *ap = v;
827 PUFFS_MSG_VARS(vn, mknod);
828 struct vnode *dvp = ap->a_dvp;
829 struct puffs_node *dpn = VPTOPP(dvp);
830 struct componentname *cnp = ap->a_cnp;
831 struct mount *mp = dvp->v_mount;
832 struct puffs_mount *pmp = MPTOPUFFSMP(mp);
833 int error;
834
835 PUFFS_MSG_ALLOC(vn, mknod);
836 puffs_makecn(&mknod_msg->pvnr_cn, &mknod_msg->pvnr_cn_cred,
837 cnp, PUFFS_USE_FULLPNBUF(pmp));
838 mknod_msg->pvnr_va = *ap->a_vap;
839 puffs_msg_setinfo(park_mknod, PUFFSOP_VN,
840 PUFFS_VN_MKNOD, VPTOPNC(dvp));
841
842 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mknod, dvp->v_data, NULL, error);
843
844 error = checkerr(pmp, error, __func__);
845 if (error)
846 goto out;
847
848 error = puffs_newnode(mp, dvp, ap->a_vpp,
849 mknod_msg->pvnr_newnode, cnp, ap->a_vap->va_type,
850 ap->a_vap->va_rdev);
851 if (error) {
852 puffs_abortbutton(pmp, PUFFS_ABORT_MKNOD, dpn->pn_cookie,
853 mknod_msg->pvnr_newnode, cnp);
854 goto out;
855 }
856
857 if (PUFFS_USE_FS_TTL(pmp)) {
858 struct timespec *va_ttl = &mknod_msg->pvnr_va_ttl;
859 struct timespec *cn_ttl = &mknod_msg->pvnr_cn_ttl;
860 struct vattr *rvap = &mknod_msg->pvnr_va;
861
862 update_va(*ap->a_vpp, NULL, rvap,
863 va_ttl, cn_ttl, SETATTR_CHSIZE);
864 }
865
866 VPTOPP(*ap->a_vpp)->pn_nlookup++;
867
868 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
869 (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
870 update_parent(*ap->a_vpp, dvp);
871
872 out:
873 PUFFS_MSG_RELEASE(mknod);
874 return error;
875 }
876
877 int
878 puffs_vnop_open(void *v)
879 {
880 struct vop_open_args /* {
881 const struct vnodeop_desc *a_desc;
882 struct vnode *a_vp;
883 int a_mode;
884 kauth_cred_t a_cred;
885 } */ *ap = v;
886 PUFFS_MSG_VARS(vn, open);
887 struct vnode *vp = ap->a_vp;
888 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
889 struct puffs_node *pn = VPTOPP(vp);
890 int mode = ap->a_mode;
891 int error;
892
893 DPRINTF(("puffs_open: vp %p, mode 0x%x\n", vp, mode));
894
895 if (vp->v_type == VREG && mode & FWRITE && !EXISTSOP(pmp, WRITE))
896 ERROUT(EROFS);
897
898 if (!EXISTSOP(pmp, OPEN))
899 ERROUT(0);
900
901 PUFFS_MSG_ALLOC(vn, open);
902 open_msg->pvnr_mode = mode;
903 puffs_credcvt(&open_msg->pvnr_cred, ap->a_cred);
904 puffs_msg_setinfo(park_open, PUFFSOP_VN,
905 PUFFS_VN_OPEN, VPTOPNC(vp));
906
907 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_open, vp->v_data, NULL, error);
908 error = checkerr(pmp, error, __func__);
909
910 if (open_msg->pvnr_oflags & PUFFS_OPEN_IO_DIRECT) {
911 /*
912 * Flush cache:
913 * - we do not want to discard cached write by direct write
914 * - read cache is now useless and should be freed
915 */
916 mutex_enter(&pn->pn_sizemtx);
917 flushvncache(vp, 0, 0, true);
918 mutex_exit(&pn->pn_sizemtx);
919
920 if (mode & FREAD)
921 pn->pn_stat |= PNODE_RDIRECT;
922 if (mode & FWRITE)
923 pn->pn_stat |= PNODE_WDIRECT;
924 }
925 out:
926 DPRINTF(("puffs_open: returning %d\n", error));
927 PUFFS_MSG_RELEASE(open);
928 return error;
929 }
930
931 int
932 puffs_vnop_close(void *v)
933 {
934 struct vop_close_args /* {
935 const struct vnodeop_desc *a_desc;
936 struct vnode *a_vp;
937 int a_fflag;
938 kauth_cred_t a_cred;
939 } */ *ap = v;
940 PUFFS_MSG_VARS(vn, close);
941 struct vnode *vp = ap->a_vp;
942 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
943
944 PUFFS_MSG_ALLOC(vn, close);
945 puffs_msg_setfaf(park_close);
946 close_msg->pvnr_fflag = ap->a_fflag;
947 puffs_credcvt(&close_msg->pvnr_cred, ap->a_cred);
948 puffs_msg_setinfo(park_close, PUFFSOP_VN,
949 PUFFS_VN_CLOSE, VPTOPNC(vp));
950
951 puffs_msg_enqueue(pmp, park_close);
952 PUFFS_MSG_RELEASE(close);
953 return 0;
954 }
955
956 int
957 puffs_vnop_access(void *v)
958 {
959 struct vop_access_args /* {
960 const struct vnodeop_desc *a_desc;
961 struct vnode *a_vp;
962 int a_mode;
963 kauth_cred_t a_cred;
964 } */ *ap = v;
965 PUFFS_MSG_VARS(vn, access);
966 struct vnode *vp = ap->a_vp;
967 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
968 int mode = ap->a_mode;
969 int error;
970
971 if (mode & VWRITE) {
972 switch (vp->v_type) {
973 case VDIR:
974 case VLNK:
975 case VREG:
976 if ((vp->v_mount->mnt_flag & MNT_RDONLY)
977 || !EXISTSOP(pmp, WRITE))
978 return EROFS;
979 break;
980 default:
981 break;
982 }
983 }
984
985 if (!EXISTSOP(pmp, ACCESS))
986 return 0;
987
988 PUFFS_MSG_ALLOC(vn, access);
989 access_msg->pvnr_mode = ap->a_mode;
990 puffs_credcvt(&access_msg->pvnr_cred, ap->a_cred);
991 puffs_msg_setinfo(park_access, PUFFSOP_VN,
992 PUFFS_VN_ACCESS, VPTOPNC(vp));
993
994 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_access, vp->v_data, NULL, error);
995 error = checkerr(pmp, error, __func__);
996 PUFFS_MSG_RELEASE(access);
997
998 return error;
999 }
1000
1001 static void
1002 update_va(struct vnode *vp, struct vattr *vap, struct vattr *rvap,
1003 struct timespec *va_ttl, struct timespec *cn_ttl, int flags)
1004 {
1005 struct puffs_node *pn = VPTOPP(vp);
1006 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1007 int use_metacache;
1008
1009 if (TTL_VALID(cn_ttl)) {
1010 pn->pn_cn_timeout = TTL_TO_TIMEOUT(cn_ttl);
1011 pn->pn_cn_grace = MAX(pn->pn_cn_timeout, pn->pn_cn_grace);
1012 }
1013
1014 /*
1015 * Don't listen to the file server regarding special device
1016 * size info, the file server doesn't know anything about them.
1017 */
1018 if (vp->v_type == VBLK || vp->v_type == VCHR)
1019 rvap->va_size = vp->v_size;
1020
1021 /* Ditto for blocksize (ufs comment: this doesn't belong here) */
1022 if (vp->v_type == VBLK)
1023 rvap->va_blocksize = BLKDEV_IOSIZE;
1024 else if (vp->v_type == VCHR)
1025 rvap->va_blocksize = MAXBSIZE;
1026
1027 if (vap != NULL) {
1028 (void) memcpy(vap, rvap, sizeof(struct vattr));
1029 vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
1030
1031 if (PUFFS_USE_METAFLUSH(pmp)) {
1032 if (pn->pn_stat & PNODE_METACACHE_ATIME)
1033 vap->va_atime = pn->pn_mc_atime;
1034 if (pn->pn_stat & PNODE_METACACHE_CTIME)
1035 vap->va_ctime = pn->pn_mc_ctime;
1036 if (pn->pn_stat & PNODE_METACACHE_MTIME)
1037 vap->va_mtime = pn->pn_mc_mtime;
1038 if (pn->pn_stat & PNODE_METACACHE_SIZE)
1039 vap->va_size = pn->pn_mc_size;
1040 }
1041 }
1042
1043 use_metacache = PUFFS_USE_METAFLUSH(pmp) &&
1044 (pn->pn_stat & PNODE_METACACHE_SIZE);
1045 if (!use_metacache && (flags & SETATTR_CHSIZE)) {
1046 if (rvap->va_size != VNOVAL
1047 && vp->v_type != VBLK && vp->v_type != VCHR) {
1048 uvm_vnp_setsize(vp, rvap->va_size);
1049 pn->pn_serversize = rvap->va_size;
1050 }
1051 }
1052
1053 if ((va_ttl != NULL) && TTL_VALID(va_ttl)) {
1054 if (pn->pn_va_cache == NULL)
1055 pn->pn_va_cache = pool_get(&puffs_vapool, PR_WAITOK);
1056
1057 (void)memcpy(pn->pn_va_cache, rvap, sizeof(*rvap));
1058
1059 pn->pn_va_timeout = TTL_TO_TIMEOUT(va_ttl);
1060 }
1061 }
1062
1063 static void
1064 update_parent(struct vnode *vp, struct vnode *dvp)
1065 {
1066 struct puffs_node *pn = VPTOPP(vp);
1067
1068 if (pn->pn_parent != NULL) {
1069 KASSERT(pn->pn_parent != dvp);
1070 vrele(pn->pn_parent);
1071 }
1072
1073 vref(dvp);
1074 pn->pn_parent = dvp;
1075 }
1076
1077 int
1078 puffs_vnop_getattr(void *v)
1079 {
1080 struct vop_getattr_args /* {
1081 const struct vnodeop_desc *a_desc;
1082 struct vnode *a_vp;
1083 struct vattr *a_vap;
1084 kauth_cred_t a_cred;
1085 } */ *ap = v;
1086 PUFFS_MSG_VARS(vn, getattr);
1087 struct vnode *vp = ap->a_vp;
1088 struct mount *mp = vp->v_mount;
1089 struct puffs_mount *pmp = MPTOPUFFSMP(mp);
1090 struct vattr *vap, *rvap;
1091 struct puffs_node *pn = VPTOPP(vp);
1092 struct timespec *va_ttl = NULL;
1093 int error = 0;
1094
1095 /*
1096 * A lock is required so that we do not race with
1097 * setattr, write and fsync when changing vp->v_size.
1098 * This is critical, since setting a stall smaler value
1099 * triggers a file truncate in uvm_vnp_setsize(), which
1100 * most of the time means data corruption (a chunk of
1101 * data is replaced by zeroes). This can be removed if
1102 * we decide one day that VOP_GETATTR must operate on
1103 * a locked vnode.
1104 *
1105 * XXX Should be useless now that VOP_GETATTR has been
1106 * fixed to always require a shared lock at least.
1107 */
1108 mutex_enter(&pn->pn_sizemtx);
1109
1110 REFPN(pn);
1111 vap = ap->a_vap;
1112
1113 if (PUFFS_USE_FS_TTL(pmp)) {
1114 if (!TIMED_OUT(pn->pn_va_timeout)) {
1115 update_va(vp, vap, pn->pn_va_cache,
1116 NULL, NULL, SETATTR_CHSIZE);
1117 goto out2;
1118 }
1119 }
1120
1121 PUFFS_MSG_ALLOC(vn, getattr);
1122 vattr_null(&getattr_msg->pvnr_va);
1123 puffs_credcvt(&getattr_msg->pvnr_cred, ap->a_cred);
1124 puffs_msg_setinfo(park_getattr, PUFFSOP_VN,
1125 PUFFS_VN_GETATTR, VPTOPNC(vp));
1126
1127 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_getattr, vp->v_data, NULL, error);
1128 error = checkerr(pmp, error, __func__);
1129 if (error)
1130 goto out;
1131
1132 rvap = &getattr_msg->pvnr_va;
1133
1134 if (PUFFS_USE_FS_TTL(pmp))
1135 va_ttl = &getattr_msg->pvnr_va_ttl;
1136
1137 update_va(vp, vap, rvap, va_ttl, NULL, SETATTR_CHSIZE);
1138
1139 out:
1140 PUFFS_MSG_RELEASE(getattr);
1141
1142 out2:
1143 puffs_releasenode(pn);
1144
1145 mutex_exit(&pn->pn_sizemtx);
1146
1147 return error;
1148 }
1149
1150 static void
1151 zerofill_lastpage(struct vnode *vp, voff_t off)
1152 {
1153
1154 if (trunc_page(off) == off)
1155 return;
1156
1157 if (vp->v_writecount == 0)
1158 return;
1159
1160 vsize_t len = round_page(off) - off;
1161 ubc_zerorange(&vp->v_uobj, off, len, UBC_WRITE|UBC_UNMAP_FLAG(vp));
1162 }
1163
1164 static int
1165 dosetattr(struct vnode *vp, struct vattr *vap, kauth_cred_t cred, int flags)
1166 {
1167 PUFFS_MSG_VARS(vn, setattr);
1168 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1169 struct puffs_node *pn = vp->v_data;
1170 vsize_t oldsize = vp->v_size;
1171 int error = 0;
1172
1173 KASSERT(!(flags & SETATTR_CHSIZE) || mutex_owned(&pn->pn_sizemtx));
1174
1175 if ((vp->v_mount->mnt_flag & MNT_RDONLY) &&
1176 (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL
1177 || vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL
1178 || vap->va_mode != (mode_t)VNOVAL))
1179 return EROFS;
1180
1181 if ((vp->v_mount->mnt_flag & MNT_RDONLY)
1182 && vp->v_type == VREG && vap->va_size != VNOVAL)
1183 return EROFS;
1184
1185 /*
1186 * Flush metacache first. If we are called with some explicit
1187 * parameters, treat them as information overriding metacache
1188 * information.
1189 */
1190 if (PUFFS_USE_METAFLUSH(pmp) && pn->pn_stat & PNODE_METACACHE_MASK) {
1191 if ((pn->pn_stat & PNODE_METACACHE_ATIME)
1192 && vap->va_atime.tv_sec == VNOVAL)
1193 vap->va_atime = pn->pn_mc_atime;
1194 if ((pn->pn_stat & PNODE_METACACHE_CTIME)
1195 && vap->va_ctime.tv_sec == VNOVAL)
1196 vap->va_ctime = pn->pn_mc_ctime;
1197 if ((pn->pn_stat & PNODE_METACACHE_MTIME)
1198 && vap->va_mtime.tv_sec == VNOVAL)
1199 vap->va_mtime = pn->pn_mc_mtime;
1200 if ((pn->pn_stat & PNODE_METACACHE_SIZE)
1201 && vap->va_size == VNOVAL)
1202 vap->va_size = pn->pn_mc_size;
1203
1204 pn->pn_stat &= ~PNODE_METACACHE_MASK;
1205 }
1206
1207 /*
1208 * Flush attribute cache so that another thread do
1209 * not get a stale value during the operation.
1210 */
1211 if (PUFFS_USE_FS_TTL(pmp))
1212 pn->pn_va_timeout = 0;
1213
1214 PUFFS_MSG_ALLOC(vn, setattr);
1215 (void)memcpy(&setattr_msg->pvnr_va, vap, sizeof(struct vattr));
1216 puffs_credcvt(&setattr_msg->pvnr_cred, cred);
1217 puffs_msg_setinfo(park_setattr, PUFFSOP_VN,
1218 PUFFS_VN_SETATTR, VPTOPNC(vp));
1219 if (flags & SETATTR_ASYNC)
1220 puffs_msg_setfaf(park_setattr);
1221
1222 puffs_msg_enqueue(pmp, park_setattr);
1223 if ((flags & SETATTR_ASYNC) == 0) {
1224 error = puffs_msg_wait2(pmp, park_setattr, vp->v_data, NULL);
1225
1226 if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
1227 struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl;
1228 struct vattr *rvap = &setattr_msg->pvnr_va;
1229
1230 update_va(vp, NULL, rvap, va_ttl, NULL, flags);
1231 }
1232 }
1233
1234 PUFFS_MSG_RELEASE(setattr);
1235 if ((flags & SETATTR_ASYNC) == 0) {
1236 error = checkerr(pmp, error, __func__);
1237 if (error)
1238 return error;
1239 } else {
1240 error = 0;
1241 }
1242
1243 if (vap->va_size != VNOVAL) {
1244 /*
1245 * If we truncated the file, make sure the data beyond
1246 * EOF in last page does not remain in cache, otherwise
1247 * if the file is later truncated to a larger size (creating
1248 * a hole), that area will not return zeroes as it
1249 * should.
1250 */
1251 if ((flags & SETATTR_CHSIZE) && PUFFS_USE_PAGECACHE(pmp) &&
1252 (vap->va_size < oldsize))
1253 zerofill_lastpage(vp, vap->va_size);
1254
1255 pn->pn_serversize = vap->va_size;
1256 if (flags & SETATTR_CHSIZE)
1257 uvm_vnp_setsize(vp, vap->va_size);
1258 puffs_updatenode(pn, PUFFS_UPDATECTIME | PUFFS_UPDATEMTIME, 0);
1259 }
1260
1261 return 0;
1262 }
1263
1264 int
1265 puffs_vnop_setattr(void *v)
1266 {
1267 struct vop_getattr_args /* {
1268 const struct vnodeop_desc *a_desc;
1269 struct vnode *a_vp;
1270 struct vattr *a_vap;
1271 kauth_cred_t a_cred;
1272 } */ *ap = v;
1273 struct puffs_node *pn = ap->a_vp->v_data;
1274 int error;
1275
1276 mutex_enter(&pn->pn_sizemtx);
1277 error = dosetattr(ap->a_vp, ap->a_vap, ap->a_cred, SETATTR_CHSIZE);
1278 mutex_exit(&pn->pn_sizemtx);
1279
1280 return error;
1281 }
1282
1283 static __inline int
1284 doinact(struct puffs_mount *pmp, int iaflag)
1285 {
1286
1287 if (EXISTSOP(pmp, INACTIVE))
1288 if (pmp->pmp_flags & PUFFS_KFLAG_IAONDEMAND)
1289 if (iaflag || ALLOPS(pmp))
1290 return 1;
1291 else
1292 return 0;
1293 else
1294 return 1;
1295 else
1296 return 0;
1297 }
1298
1299 static void
1300 callinactive(struct puffs_mount *pmp, puffs_cookie_t ck, int iaflag)
1301 {
1302 PUFFS_MSG_VARS(vn, inactive);
1303
1304 if (doinact(pmp, iaflag)) {
1305 PUFFS_MSG_ALLOC(vn, inactive);
1306 puffs_msg_setinfo(park_inactive, PUFFSOP_VN,
1307 PUFFS_VN_INACTIVE, ck);
1308 PUFFS_MSG_ENQUEUEWAIT_NOERROR(pmp, park_inactive);
1309 PUFFS_MSG_RELEASE(inactive);
1310 }
1311 }
1312
1313 /* XXX: callinactive can't setback */
1314 int
1315 puffs_vnop_inactive(void *v)
1316 {
1317 struct vop_inactive_v2_args /* {
1318 const struct vnodeop_desc *a_desc;
1319 struct vnode *a_vp;
1320 } */ *ap = v;
1321 PUFFS_MSG_VARS(vn, inactive);
1322 struct vnode *vp = ap->a_vp;
1323 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1324 struct puffs_node *pnode;
1325 bool recycle = false;
1326
1327 /*
1328 * When puffs_cookie2vnode() misses an entry, vcache_get()
1329 * creates a new node (puffs_vfsop_loadvnode being called to
1330 * initialize the PUFFS part), then it discovers it is VNON,
1331 * and tries to vrele() it. This leads us there, while the
1332 * cookie was stall and the node likely already reclaimed.
1333 */
1334 if (vp->v_type == VNON) {
1335 return 0;
1336 }
1337
1338 pnode = vp->v_data;
1339 mutex_enter(&pnode->pn_sizemtx);
1340
1341 if (doinact(pmp, pnode->pn_stat & PNODE_DOINACT)) {
1342 flushvncache(vp, 0, 0, false);
1343 PUFFS_MSG_ALLOC(vn, inactive);
1344 puffs_msg_setinfo(park_inactive, PUFFSOP_VN,
1345 PUFFS_VN_INACTIVE, VPTOPNC(vp));
1346 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_inactive, vp->v_data,
1347 NULL);
1348 PUFFS_MSG_RELEASE(inactive);
1349 }
1350 pnode->pn_stat &= ~PNODE_DOINACT;
1351
1352 /*
1353 * file server thinks it's gone? then don't be afraid care,
1354 * node's life was already all it would ever be
1355 */
1356 if (pnode->pn_stat & PNODE_NOREFS) {
1357 pnode->pn_stat |= PNODE_DYING;
1358 recycle = true;
1359 }
1360
1361 /*
1362 * Handle node TTL.
1363 * If grace has already timed out, make it reclaimed.
1364 * Otherwise, we queue its expiration by sop thread, so
1365 * that it does not remain for ages in the freelist,
1366 * holding memory in userspace, while we will have
1367 * to look it up again anyway.
1368 */
1369 if (PUFFS_USE_FS_TTL(pmp) && !(vp->v_vflag & VV_ROOT) && !recycle) {
1370 bool incache = !TIMED_OUT(pnode->pn_cn_timeout);
1371 bool ingrace = !TIMED_OUT(pnode->pn_cn_grace);
1372 bool reclaimqueued = pnode->pn_stat & PNODE_SOPEXP;
1373
1374 if (!incache && !ingrace && !reclaimqueued) {
1375 pnode->pn_stat |= PNODE_DYING;
1376 recycle = true;
1377 }
1378
1379 if (!recycle && !reclaimqueued) {
1380 struct puffs_sopreq *psopr;
1381 int at = MAX(pnode->pn_cn_grace, pnode->pn_cn_timeout);
1382
1383 KASSERT(curlwp != uvm.pagedaemon_lwp);
1384 psopr = kmem_alloc(sizeof(*psopr), KM_SLEEP);
1385 psopr->psopr_ck = VPTOPNC(pnode->pn_vp);
1386 psopr->psopr_sopreq = PUFFS_SOPREQ_EXPIRE;
1387 psopr->psopr_at = at;
1388
1389 mutex_enter(&pmp->pmp_sopmtx);
1390
1391 /*
1392 * If thread has disapeared, just give up. The
1393 * fs is being unmounted and the node will be
1394 * be reclaimed anyway.
1395 *
1396 * Otherwise, we queue the request but do not
1397 * immediatly signal the thread, as the node
1398 * has not been expired yet.
1399 */
1400 if (pmp->pmp_sopthrcount == 0) {
1401 kmem_free(psopr, sizeof(*psopr));
1402 } else {
1403 TAILQ_INSERT_TAIL(&pmp->pmp_sopnodereqs,
1404 psopr, psopr_entries);
1405 pnode->pn_stat |= PNODE_SOPEXP;
1406 }
1407
1408 mutex_exit(&pmp->pmp_sopmtx);
1409 }
1410 }
1411
1412 /*
1413 * Wipe direct I/O flags
1414 */
1415 pnode->pn_stat &= ~(PNODE_RDIRECT|PNODE_WDIRECT);
1416
1417 *ap->a_recycle = recycle;
1418
1419 mutex_exit(&pnode->pn_sizemtx);
1420
1421 return 0;
1422 }
1423
1424 static void
1425 callreclaim(struct puffs_mount *pmp, puffs_cookie_t ck, int nlookup)
1426 {
1427 PUFFS_MSG_VARS(vn, reclaim);
1428
1429 if (!EXISTSOP(pmp, RECLAIM))
1430 return;
1431
1432 PUFFS_MSG_ALLOC(vn, reclaim);
1433 reclaim_msg->pvnr_nlookup = nlookup;
1434 puffs_msg_setfaf(park_reclaim);
1435 puffs_msg_setinfo(park_reclaim, PUFFSOP_VN, PUFFS_VN_RECLAIM, ck);
1436
1437 puffs_msg_enqueue(pmp, park_reclaim);
1438 PUFFS_MSG_RELEASE(reclaim);
1439 return;
1440 }
1441
1442 /*
1443 * always FAF, we don't really care if the server wants to fail to
1444 * reclaim the node or not
1445 */
1446 int
1447 puffs_vnop_reclaim(void *v)
1448 {
1449 struct vop_reclaim_v2_args /* {
1450 const struct vnodeop_desc *a_desc;
1451 struct vnode *a_vp;
1452 } */ *ap = v;
1453 struct vnode *vp = ap->a_vp;
1454 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1455 bool notifyserver = true;
1456
1457 VOP_UNLOCK(vp);
1458
1459 /*
1460 * first things first: check if someone is trying to reclaim the
1461 * root vnode. do not allow that to travel to userspace.
1462 * Note that we don't need to take the lock similarly to
1463 * puffs_root(), since there is only one of us.
1464 */
1465 if (vp->v_vflag & VV_ROOT) {
1466 mutex_enter(&pmp->pmp_lock);
1467 KASSERT(pmp->pmp_root != NULL);
1468 pmp->pmp_root = NULL;
1469 mutex_exit(&pmp->pmp_lock);
1470 notifyserver = false;
1471 }
1472
1473 /* See the comment on top of puffs_vnop_inactive(). */
1474 if (vp->v_type == VNON)
1475 notifyserver = false;
1476
1477 /*
1478 * purge info from kernel before issueing FAF, since we
1479 * don't really know when we'll get around to it after
1480 * that and someone might race us into node creation
1481 */
1482 mutex_enter(&pmp->pmp_lock);
1483 if (PUFFS_USE_NAMECACHE(pmp))
1484 cache_purge(vp);
1485 mutex_exit(&pmp->pmp_lock);
1486
1487 if (notifyserver) {
1488 int nlookup = VPTOPP(vp)->pn_nlookup;
1489
1490 callreclaim(MPTOPUFFSMP(vp->v_mount), VPTOPNC(vp), nlookup);
1491 }
1492
1493 if (PUFFS_USE_DOTDOTCACHE(pmp)) {
1494 if (__predict_true(VPTOPP(vp)->pn_parent != NULL))
1495 vrele(VPTOPP(vp)->pn_parent);
1496 else
1497 KASSERT(vp->v_type == VNON || (vp->v_vflag & VV_ROOT));
1498 }
1499
1500 puffs_putvnode(vp);
1501
1502 return 0;
1503 }
1504
1505 #define CSIZE sizeof(**ap->a_cookies)
1506 int
1507 puffs_vnop_readdir(void *v)
1508 {
1509 struct vop_readdir_args /* {
1510 const struct vnodeop_desc *a_desc;
1511 struct vnode *a_vp;
1512 struct uio *a_uio;
1513 kauth_cred_t a_cred;
1514 int *a_eofflag;
1515 off_t **a_cookies;
1516 int *a_ncookies;
1517 } */ *ap = v;
1518 PUFFS_MSG_VARS(vn, readdir);
1519 struct vnode *vp = ap->a_vp;
1520 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1521 size_t argsize, tomove, cookiemem, cookiesmax;
1522 struct uio *uio = ap->a_uio;
1523 size_t howmuch, resid;
1524 int error;
1525
1526 /*
1527 * ok, so we need: resid + cookiemem = maxreq
1528 * => resid + cookiesize * (resid/minsize) = maxreq
1529 * => resid + cookiesize/minsize * resid = maxreq
1530 * => (cookiesize/minsize + 1) * resid = maxreq
1531 * => resid = maxreq / (cookiesize/minsize + 1)
1532 *
1533 * Since cookiesize <= minsize and we're not very big on floats,
1534 * we approximate that to be 1. Therefore:
1535 *
1536 * resid = maxreq / 2;
1537 *
1538 * Well, at least we didn't have to use differential equations
1539 * or the Gram-Schmidt process.
1540 *
1541 * (yes, I'm very afraid of this)
1542 */
1543 KASSERT(CSIZE <= _DIRENT_MINSIZE((struct dirent *)0));
1544
1545 if (ap->a_cookies) {
1546 KASSERT(ap->a_ncookies != NULL);
1547 if (pmp->pmp_args.pa_fhsize == 0)
1548 return EOPNOTSUPP;
1549 resid = PUFFS_TOMOVE(uio->uio_resid, pmp) / 2;
1550 cookiesmax = resid/_DIRENT_MINSIZE((struct dirent *)0);
1551 cookiemem = ALIGN(cookiesmax*CSIZE); /* play safe */
1552 } else {
1553 resid = PUFFS_TOMOVE(uio->uio_resid, pmp);
1554 cookiesmax = 0;
1555 cookiemem = 0;
1556 }
1557
1558 argsize = sizeof(struct puffs_vnmsg_readdir);
1559 tomove = resid + cookiemem;
1560 puffs_msgmem_alloc(argsize + tomove, &park_readdir,
1561 (void *)&readdir_msg, 1);
1562
1563 puffs_credcvt(&readdir_msg->pvnr_cred, ap->a_cred);
1564 readdir_msg->pvnr_offset = uio->uio_offset;
1565 readdir_msg->pvnr_resid = resid;
1566 readdir_msg->pvnr_ncookies = cookiesmax;
1567 readdir_msg->pvnr_eofflag = 0;
1568 readdir_msg->pvnr_dentoff = cookiemem;
1569 puffs_msg_setinfo(park_readdir, PUFFSOP_VN,
1570 PUFFS_VN_READDIR, VPTOPNC(vp));
1571 puffs_msg_setdelta(park_readdir, tomove);
1572
1573 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_readdir, vp->v_data, NULL, error);
1574 error = checkerr(pmp, error, __func__);
1575 if (error)
1576 goto out;
1577
1578 /* userspace is cheating? */
1579 if (readdir_msg->pvnr_resid > resid) {
1580 puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
1581 "resid grew", VPTOPNC(vp));
1582 ERROUT(EPROTO);
1583 }
1584 if (readdir_msg->pvnr_ncookies > cookiesmax) {
1585 puffs_senderr(pmp, PUFFS_ERR_READDIR, E2BIG,
1586 "too many cookies", VPTOPNC(vp));
1587 ERROUT(EPROTO);
1588 }
1589
1590 /* check eof */
1591 if (readdir_msg->pvnr_eofflag)
1592 *ap->a_eofflag = 1;
1593
1594 /* bouncy-wouncy with the directory data */
1595 howmuch = resid - readdir_msg->pvnr_resid;
1596
1597 /* force eof if no data was returned (getcwd() needs this) */
1598 if (howmuch == 0) {
1599 *ap->a_eofflag = 1;
1600 goto out;
1601 }
1602
1603 error = uiomove(readdir_msg->pvnr_data + cookiemem, howmuch, uio);
1604 if (error)
1605 goto out;
1606
1607 /* provide cookies to caller if so desired */
1608 if (ap->a_cookies) {
1609 KASSERT(curlwp != uvm.pagedaemon_lwp);
1610 *ap->a_cookies = malloc(readdir_msg->pvnr_ncookies*CSIZE,
1611 M_TEMP, M_WAITOK);
1612 *ap->a_ncookies = readdir_msg->pvnr_ncookies;
1613 memcpy(*ap->a_cookies, readdir_msg->pvnr_data,
1614 *ap->a_ncookies*CSIZE);
1615 }
1616
1617 /* next readdir starts here */
1618 uio->uio_offset = readdir_msg->pvnr_offset;
1619
1620 out:
1621 puffs_msgmem_release(park_readdir);
1622 return error;
1623 }
1624 #undef CSIZE
1625
1626 /*
1627 * poll works by consuming the bitmask in pn_revents. If there are
1628 * events available, poll returns immediately. If not, it issues a
1629 * poll to userspace, selrecords itself and returns with no available
1630 * events. When the file server returns, it executes puffs_parkdone_poll(),
1631 * where available events are added to the bitmask. selnotify() is
1632 * then also executed by that function causing us to enter here again
1633 * and hopefully find the missing bits (unless someone got them first,
1634 * in which case it starts all over again).
1635 */
1636 int
1637 puffs_vnop_poll(void *v)
1638 {
1639 struct vop_poll_args /* {
1640 const struct vnodeop_desc *a_desc;
1641 struct vnode *a_vp;
1642 int a_events;
1643 } */ *ap = v;
1644 PUFFS_MSG_VARS(vn, poll);
1645 struct vnode *vp = ap->a_vp;
1646 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1647 struct puffs_node *pn = vp->v_data;
1648 int events;
1649
1650 if (EXISTSOP(pmp, POLL)) {
1651 mutex_enter(&pn->pn_mtx);
1652 events = pn->pn_revents & ap->a_events;
1653 if (events & ap->a_events) {
1654 pn->pn_revents &= ~ap->a_events;
1655 mutex_exit(&pn->pn_mtx);
1656
1657 return events;
1658 } else {
1659 puffs_referencenode(pn);
1660 mutex_exit(&pn->pn_mtx);
1661
1662 PUFFS_MSG_ALLOC(vn, poll);
1663 poll_msg->pvnr_events = ap->a_events;
1664 puffs_msg_setinfo(park_poll, PUFFSOP_VN,
1665 PUFFS_VN_POLL, VPTOPNC(vp));
1666 puffs_msg_setcall(park_poll, puffs_parkdone_poll, pn);
1667 selrecord(curlwp, &pn->pn_sel);
1668
1669 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_poll,
1670 vp->v_data, NULL);
1671 PUFFS_MSG_RELEASE(poll);
1672
1673 return 0;
1674 }
1675 } else {
1676 return genfs_poll(v);
1677 }
1678 }
1679
1680 static int
1681 flushvncache(struct vnode *vp, off_t offlo, off_t offhi, bool wait)
1682 {
1683 struct puffs_node *pn = VPTOPP(vp);
1684 struct vattr va;
1685 int pflags, error;
1686
1687 /* flush out information from our metacache, see vop_setattr */
1688 if (pn->pn_stat & PNODE_METACACHE_MASK
1689 && (pn->pn_stat & PNODE_DYING) == 0) {
1690 vattr_null(&va);
1691 error = dosetattr(vp, &va, FSCRED,
1692 SETATTR_CHSIZE | (wait ? 0 : SETATTR_ASYNC));
1693 if (error)
1694 return error;
1695 }
1696
1697 /*
1698 * flush pages to avoid being overly dirty
1699 */
1700 pflags = PGO_CLEANIT;
1701 if (wait)
1702 pflags |= PGO_SYNCIO;
1703
1704 mutex_enter(vp->v_interlock);
1705 return VOP_PUTPAGES(vp, trunc_page(offlo), round_page(offhi), pflags);
1706 }
1707
1708 int
1709 puffs_vnop_fsync(void *v)
1710 {
1711 struct vop_fsync_args /* {
1712 const struct vnodeop_desc *a_desc;
1713 struct vnode *a_vp;
1714 kauth_cred_t a_cred;
1715 int a_flags;
1716 off_t a_offlo;
1717 off_t a_offhi;
1718 } */ *ap = v;
1719 PUFFS_MSG_VARS(vn, fsync);
1720 struct vnode *vp;
1721 struct puffs_node *pn;
1722 struct puffs_mount *pmp;
1723 int error, dofaf;
1724
1725 vp = ap->a_vp;
1726 KASSERT(vp != NULL);
1727 pn = VPTOPP(vp);
1728 KASSERT(pn != NULL);
1729 pmp = MPTOPUFFSMP(vp->v_mount);
1730
1731 /* See the comment on top of puffs_vnop_inactive(). */
1732 if (vp->v_type == VNON)
1733 return 0;
1734
1735 if (ap->a_flags & FSYNC_WAIT) {
1736 mutex_enter(&pn->pn_sizemtx);
1737 } else {
1738 if (mutex_tryenter(&pn->pn_sizemtx) == 0)
1739 return EDEADLK;
1740 }
1741
1742 error = flushvncache(vp, ap->a_offlo, ap->a_offhi,
1743 (ap->a_flags & FSYNC_WAIT) == FSYNC_WAIT);
1744 if (error)
1745 goto out;
1746
1747 /*
1748 * HELLO! We exit already here if the user server does not
1749 * support fsync OR if we should call fsync for a node which
1750 * has references neither in the kernel or the fs server.
1751 * Otherwise we continue to issue fsync() forward.
1752 */
1753 error = 0;
1754 if (!EXISTSOP(pmp, FSYNC) || (pn->pn_stat & PNODE_DYING))
1755 goto out;
1756
1757 dofaf = (ap->a_flags & FSYNC_WAIT) == 0 || ap->a_flags == FSYNC_LAZY;
1758 /*
1759 * We abuse VXLOCK to mean "vnode is going to die", so we issue
1760 * only FAFs for those. Otherwise there's a danger of deadlock,
1761 * since the execution context here might be the user server
1762 * doing some operation on another fs, which in turn caused a
1763 * vnode to be reclaimed from the freelist for this fs.
1764 */
1765 if (dofaf == 0) {
1766 mutex_enter(vp->v_interlock);
1767 if (vdead_check(vp, VDEAD_NOWAIT) != 0)
1768 dofaf = 1;
1769 mutex_exit(vp->v_interlock);
1770 }
1771
1772 PUFFS_MSG_ALLOC(vn, fsync);
1773 if (dofaf)
1774 puffs_msg_setfaf(park_fsync);
1775
1776 puffs_credcvt(&fsync_msg->pvnr_cred, ap->a_cred);
1777 fsync_msg->pvnr_flags = ap->a_flags;
1778 fsync_msg->pvnr_offlo = ap->a_offlo;
1779 fsync_msg->pvnr_offhi = ap->a_offhi;
1780 puffs_msg_setinfo(park_fsync, PUFFSOP_VN,
1781 PUFFS_VN_FSYNC, VPTOPNC(vp));
1782
1783 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fsync, vp->v_data, NULL, error);
1784 PUFFS_MSG_RELEASE(fsync);
1785
1786 error = checkerr(pmp, error, __func__);
1787
1788 out:
1789 mutex_exit(&pn->pn_sizemtx);
1790 return error;
1791 }
1792
1793 int
1794 puffs_vnop_seek(void *v)
1795 {
1796 struct vop_seek_args /* {
1797 const struct vnodeop_desc *a_desc;
1798 struct vnode *a_vp;
1799 off_t a_oldoff;
1800 off_t a_newoff;
1801 kauth_cred_t a_cred;
1802 } */ *ap = v;
1803 PUFFS_MSG_VARS(vn, seek);
1804 struct vnode *vp = ap->a_vp;
1805 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
1806 int error;
1807
1808 PUFFS_MSG_ALLOC(vn, seek);
1809 seek_msg->pvnr_oldoff = ap->a_oldoff;
1810 seek_msg->pvnr_newoff = ap->a_newoff;
1811 puffs_credcvt(&seek_msg->pvnr_cred, ap->a_cred);
1812 puffs_msg_setinfo(park_seek, PUFFSOP_VN,
1813 PUFFS_VN_SEEK, VPTOPNC(vp));
1814
1815 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_seek, vp->v_data, NULL, error);
1816 PUFFS_MSG_RELEASE(seek);
1817 return checkerr(pmp, error, __func__);
1818 }
1819
1820 static int
1821 callremove(struct puffs_mount *pmp, puffs_cookie_t dck, puffs_cookie_t ck,
1822 struct componentname *cnp)
1823 {
1824 PUFFS_MSG_VARS(vn, remove);
1825 int error;
1826
1827 PUFFS_MSG_ALLOC(vn, remove);
1828 remove_msg->pvnr_cookie_targ = ck;
1829 puffs_makecn(&remove_msg->pvnr_cn, &remove_msg->pvnr_cn_cred,
1830 cnp, PUFFS_USE_FULLPNBUF(pmp));
1831 puffs_msg_setinfo(park_remove, PUFFSOP_VN, PUFFS_VN_REMOVE, dck);
1832
1833 PUFFS_MSG_ENQUEUEWAIT(pmp, park_remove, error);
1834 PUFFS_MSG_RELEASE(remove);
1835
1836 return checkerr(pmp, error, __func__);
1837 }
1838
1839 /*
1840 * XXX: can't use callremove now because can't catch setbacks with
1841 * it due to lack of a pnode argument.
1842 */
1843 int
1844 puffs_vnop_remove(void *v)
1845 {
1846 struct vop_remove_v2_args /* {
1847 const struct vnodeop_desc *a_desc;
1848 struct vnode *a_dvp;
1849 struct vnode *a_vp;
1850 struct componentname *a_cnp;
1851 } */ *ap = v;
1852 PUFFS_MSG_VARS(vn, remove);
1853 struct vnode *dvp = ap->a_dvp;
1854 struct vnode *vp = ap->a_vp;
1855 struct puffs_node *dpn = VPTOPP(dvp);
1856 struct puffs_node *pn = VPTOPP(vp);
1857 struct componentname *cnp = ap->a_cnp;
1858 struct mount *mp = dvp->v_mount;
1859 struct puffs_mount *pmp = MPTOPUFFSMP(mp);
1860 int error;
1861
1862 PUFFS_MSG_ALLOC(vn, remove);
1863 remove_msg->pvnr_cookie_targ = VPTOPNC(vp);
1864 puffs_makecn(&remove_msg->pvnr_cn, &remove_msg->pvnr_cn_cred,
1865 cnp, PUFFS_USE_FULLPNBUF(pmp));
1866 puffs_msg_setinfo(park_remove, PUFFSOP_VN,
1867 PUFFS_VN_REMOVE, VPTOPNC(dvp));
1868
1869 puffs_msg_enqueue(pmp, park_remove);
1870 vref(dvp); /* hang onto caller's reference at end */
1871 REFPN(dpn);
1872 if (dvp == vp)
1873 REFPN(pn);
1874 else
1875 REFPN_AND_UNLOCKVP(vp, pn);
1876 error = puffs_msg_wait2(pmp, park_remove, dpn, pn);
1877
1878 PUFFS_MSG_RELEASE(remove);
1879
1880 puffs_updatenode(VPTOPP(dvp), PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
1881
1882 RELEPN_AND_VP(dvp, dpn);
1883 RELEPN_AND_VP(vp, pn);
1884
1885 error = checkerr(pmp, error, __func__);
1886 return error;
1887 }
1888
1889 int
1890 puffs_vnop_mkdir(void *v)
1891 {
1892 struct vop_mkdir_v3_args /* {
1893 const struct vnodeop_desc *a_desc;
1894 struct vnode *a_dvp;
1895 struct vnode **a_vpp;
1896 struct componentname *a_cnp;
1897 struct vattr *a_vap;
1898 } */ *ap = v;
1899 PUFFS_MSG_VARS(vn, mkdir);
1900 struct vnode *dvp = ap->a_dvp;
1901 struct puffs_node *dpn = VPTOPP(dvp);
1902 struct componentname *cnp = ap->a_cnp;
1903 struct mount *mp = dvp->v_mount;
1904 struct puffs_mount *pmp = MPTOPUFFSMP(mp);
1905 int error;
1906
1907 PUFFS_MSG_ALLOC(vn, mkdir);
1908 puffs_makecn(&mkdir_msg->pvnr_cn, &mkdir_msg->pvnr_cn_cred,
1909 cnp, PUFFS_USE_FULLPNBUF(pmp));
1910 mkdir_msg->pvnr_va = *ap->a_vap;
1911 puffs_msg_setinfo(park_mkdir, PUFFSOP_VN,
1912 PUFFS_VN_MKDIR, VPTOPNC(dvp));
1913
1914 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mkdir, dvp->v_data, NULL, error);
1915
1916 error = checkerr(pmp, error, __func__);
1917 if (error)
1918 goto out;
1919
1920 error = puffs_newnode(mp, dvp, ap->a_vpp,
1921 mkdir_msg->pvnr_newnode, cnp, VDIR, 0);
1922 if (error) {
1923 puffs_abortbutton(pmp, PUFFS_ABORT_MKDIR, dpn->pn_cookie,
1924 mkdir_msg->pvnr_newnode, cnp);
1925 goto out;
1926 }
1927
1928 if (PUFFS_USE_FS_TTL(pmp)) {
1929 struct timespec *va_ttl = &mkdir_msg->pvnr_va_ttl;
1930 struct timespec *cn_ttl = &mkdir_msg->pvnr_cn_ttl;
1931 struct vattr *rvap = &mkdir_msg->pvnr_va;
1932
1933 update_va(*ap->a_vpp, NULL, rvap,
1934 va_ttl, cn_ttl, SETATTR_CHSIZE);
1935 }
1936
1937 VPTOPP(*ap->a_vpp)->pn_nlookup++;
1938
1939 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
1940 (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
1941 update_parent(*ap->a_vpp, dvp);
1942
1943 out:
1944 PUFFS_MSG_RELEASE(mkdir);
1945 return error;
1946 }
1947
1948 static int
1949 callrmdir(struct puffs_mount *pmp, puffs_cookie_t dck, puffs_cookie_t ck,
1950 struct componentname *cnp)
1951 {
1952 PUFFS_MSG_VARS(vn, rmdir);
1953 int error;
1954
1955 PUFFS_MSG_ALLOC(vn, rmdir);
1956 rmdir_msg->pvnr_cookie_targ = ck;
1957 puffs_makecn(&rmdir_msg->pvnr_cn, &rmdir_msg->pvnr_cn_cred,
1958 cnp, PUFFS_USE_FULLPNBUF(pmp));
1959 puffs_msg_setinfo(park_rmdir, PUFFSOP_VN, PUFFS_VN_RMDIR, dck);
1960
1961 PUFFS_MSG_ENQUEUEWAIT(pmp, park_rmdir, error);
1962 PUFFS_MSG_RELEASE(rmdir);
1963
1964 return checkerr(pmp, error, __func__);
1965 }
1966
1967 int
1968 puffs_vnop_rmdir(void *v)
1969 {
1970 struct vop_rmdir_v2_args /* {
1971 const struct vnodeop_desc *a_desc;
1972 struct vnode *a_dvp;
1973 struct vnode *a_vp;
1974 struct componentname *a_cnp;
1975 } */ *ap = v;
1976 PUFFS_MSG_VARS(vn, rmdir);
1977 struct vnode *dvp = ap->a_dvp;
1978 struct vnode *vp = ap->a_vp;
1979 struct puffs_node *dpn = VPTOPP(dvp);
1980 struct puffs_node *pn = VPTOPP(vp);
1981 struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
1982 struct componentname *cnp = ap->a_cnp;
1983 int error;
1984
1985 PUFFS_MSG_ALLOC(vn, rmdir);
1986 rmdir_msg->pvnr_cookie_targ = VPTOPNC(vp);
1987 puffs_makecn(&rmdir_msg->pvnr_cn, &rmdir_msg->pvnr_cn_cred,
1988 cnp, PUFFS_USE_FULLPNBUF(pmp));
1989 puffs_msg_setinfo(park_rmdir, PUFFSOP_VN,
1990 PUFFS_VN_RMDIR, VPTOPNC(dvp));
1991
1992 puffs_msg_enqueue(pmp, park_rmdir);
1993 vref(dvp); /* hang onto caller's reference at end */
1994 KASSERTMSG((dvp != vp), "rmdir .");
1995 REFPN(dpn);
1996 REFPN_AND_UNLOCKVP(vp, pn);
1997 error = puffs_msg_wait2(pmp, park_rmdir, dpn, pn);
1998
1999 PUFFS_MSG_RELEASE(rmdir);
2000
2001 puffs_updatenode(VPTOPP(dvp), PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2002
2003 /* XXX: some call cache_purge() *for both vnodes* here, investigate */
2004 RELEPN_AND_VP(dvp, dpn);
2005 RELEPN_AND_VP(vp, pn);
2006
2007 return error;
2008 }
2009
2010 int
2011 puffs_vnop_link(void *v)
2012 {
2013 struct vop_link_v2_args /* {
2014 const struct vnodeop_desc *a_desc;
2015 struct vnode *a_dvp;
2016 struct vnode *a_vp;
2017 struct componentname *a_cnp;
2018 } */ *ap = v;
2019 PUFFS_MSG_VARS(vn, link);
2020 struct vnode *dvp = ap->a_dvp;
2021 struct vnode *vp = ap->a_vp;
2022 struct puffs_node *dpn = VPTOPP(dvp);
2023 struct puffs_node *pn = VPTOPP(vp);
2024 struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
2025 struct componentname *cnp = ap->a_cnp;
2026 int error;
2027
2028 PUFFS_MSG_ALLOC(vn, link);
2029 link_msg->pvnr_cookie_targ = VPTOPNC(vp);
2030 puffs_makecn(&link_msg->pvnr_cn, &link_msg->pvnr_cn_cred,
2031 cnp, PUFFS_USE_FULLPNBUF(pmp));
2032 puffs_msg_setinfo(park_link, PUFFSOP_VN,
2033 PUFFS_VN_LINK, VPTOPNC(dvp));
2034
2035 puffs_msg_enqueue(pmp, park_link);
2036 error = puffs_msg_wait2(pmp, park_link, dpn, pn);
2037
2038 PUFFS_MSG_RELEASE(link);
2039
2040 error = checkerr(pmp, error, __func__);
2041
2042 /*
2043 * XXX: stay in touch with the cache. I don't like this, but
2044 * don't have a better solution either. See also puffs_rename().
2045 */
2046 if (error == 0) {
2047 puffs_updatenode(pn, PUFFS_UPDATECTIME, 0);
2048 puffs_updatenode(VPTOPP(dvp),
2049 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2050 }
2051
2052 return error;
2053 }
2054
2055 int
2056 puffs_vnop_symlink(void *v)
2057 {
2058 struct vop_symlink_v3_args /* {
2059 const struct vnodeop_desc *a_desc;
2060 struct vnode *a_dvp;
2061 struct vnode **a_vpp;
2062 struct componentname *a_cnp;
2063 struct vattr *a_vap;
2064 char *a_target;
2065 } */ *ap = v;
2066 PUFFS_MSG_VARS(vn, symlink);
2067 struct vnode *dvp = ap->a_dvp;
2068 struct puffs_node *dpn = VPTOPP(dvp);
2069 struct mount *mp = dvp->v_mount;
2070 struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
2071 struct componentname *cnp = ap->a_cnp;
2072 int error;
2073
2074 *ap->a_vpp = NULL;
2075
2076 PUFFS_MSG_ALLOC(vn, symlink);
2077 puffs_makecn(&symlink_msg->pvnr_cn, &symlink_msg->pvnr_cn_cred,
2078 cnp, PUFFS_USE_FULLPNBUF(pmp));
2079 symlink_msg->pvnr_va = *ap->a_vap;
2080 (void)strlcpy(symlink_msg->pvnr_link, ap->a_target,
2081 sizeof(symlink_msg->pvnr_link));
2082 puffs_msg_setinfo(park_symlink, PUFFSOP_VN,
2083 PUFFS_VN_SYMLINK, VPTOPNC(dvp));
2084
2085 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_symlink, dvp->v_data, NULL, error);
2086
2087 error = checkerr(pmp, error, __func__);
2088 if (error)
2089 goto out;
2090
2091 error = puffs_newnode(mp, dvp, ap->a_vpp,
2092 symlink_msg->pvnr_newnode, cnp, VLNK, 0);
2093 if (error) {
2094 puffs_abortbutton(pmp, PUFFS_ABORT_SYMLINK, dpn->pn_cookie,
2095 symlink_msg->pvnr_newnode, cnp);
2096 goto out;
2097 }
2098
2099 if (PUFFS_USE_FS_TTL(pmp)) {
2100 struct timespec *va_ttl = &symlink_msg->pvnr_va_ttl;
2101 struct timespec *cn_ttl = &symlink_msg->pvnr_cn_ttl;
2102 struct vattr *rvap = &symlink_msg->pvnr_va;
2103
2104 update_va(*ap->a_vpp, NULL, rvap,
2105 va_ttl, cn_ttl, SETATTR_CHSIZE);
2106 }
2107
2108 VPTOPP(*ap->a_vpp)->pn_nlookup++;
2109
2110 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
2111 (VPTOPP(*ap->a_vpp)->pn_parent != dvp))
2112 update_parent(*ap->a_vpp, dvp);
2113
2114 out:
2115 PUFFS_MSG_RELEASE(symlink);
2116
2117 return error;
2118 }
2119
2120 int
2121 puffs_vnop_readlink(void *v)
2122 {
2123 struct vop_readlink_args /* {
2124 const struct vnodeop_desc *a_desc;
2125 struct vnode *a_vp;
2126 struct uio *a_uio;
2127 kauth_cred_t a_cred;
2128 } */ *ap = v;
2129 PUFFS_MSG_VARS(vn, readlink);
2130 struct vnode *vp = ap->a_vp;
2131 struct puffs_mount *pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
2132 size_t linklen;
2133 int error;
2134
2135 PUFFS_MSG_ALLOC(vn, readlink);
2136 puffs_credcvt(&readlink_msg->pvnr_cred, ap->a_cred);
2137 linklen = sizeof(readlink_msg->pvnr_link);
2138 readlink_msg->pvnr_linklen = linklen;
2139 puffs_msg_setinfo(park_readlink, PUFFSOP_VN,
2140 PUFFS_VN_READLINK, VPTOPNC(vp));
2141
2142 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_readlink, vp->v_data, NULL, error);
2143 error = checkerr(pmp, error, __func__);
2144 if (error)
2145 goto out;
2146
2147 /* bad bad user file server */
2148 if (readlink_msg->pvnr_linklen > linklen) {
2149 puffs_senderr(pmp, PUFFS_ERR_READLINK, E2BIG,
2150 "linklen too big", VPTOPNC(ap->a_vp));
2151 error = EPROTO;
2152 goto out;
2153 }
2154
2155 error = uiomove(&readlink_msg->pvnr_link, readlink_msg->pvnr_linklen,
2156 ap->a_uio);
2157 out:
2158 PUFFS_MSG_RELEASE(readlink);
2159 return error;
2160 }
2161
2162 int
2163 puffs_vnop_rename(void *v)
2164 {
2165 struct vop_rename_args /* {
2166 const struct vnodeop_desc *a_desc;
2167 struct vnode *a_fdvp;
2168 struct vnode *a_fvp;
2169 struct componentname *a_fcnp;
2170 struct vnode *a_tdvp;
2171 struct vnode *a_tvp;
2172 struct componentname *a_tcnp;
2173 } */ *ap = v;
2174 PUFFS_MSG_VARS(vn, rename);
2175 struct vnode *fdvp = ap->a_fdvp, *fvp = ap->a_fvp;
2176 struct vnode *tdvp = ap->a_tdvp, *tvp = ap->a_tvp;
2177 struct puffs_node *fpn = ap->a_fvp->v_data;
2178 struct puffs_mount *pmp = MPTOPUFFSMP(fdvp->v_mount);
2179 int error;
2180 bool doabort = true;
2181
2182 if ((fvp->v_mount != tdvp->v_mount) ||
2183 (tvp && (fvp->v_mount != tvp->v_mount))) {
2184 ERROUT(EXDEV);
2185 }
2186
2187 PUFFS_MSG_ALLOC(vn, rename);
2188 rename_msg->pvnr_cookie_src = VPTOPNC(fvp);
2189 rename_msg->pvnr_cookie_targdir = VPTOPNC(tdvp);
2190 if (tvp)
2191 rename_msg->pvnr_cookie_targ = VPTOPNC(tvp);
2192 else
2193 rename_msg->pvnr_cookie_targ = NULL;
2194 puffs_makecn(&rename_msg->pvnr_cn_src, &rename_msg->pvnr_cn_src_cred,
2195 ap->a_fcnp, PUFFS_USE_FULLPNBUF(pmp));
2196 puffs_makecn(&rename_msg->pvnr_cn_targ, &rename_msg->pvnr_cn_targ_cred,
2197 ap->a_tcnp, PUFFS_USE_FULLPNBUF(pmp));
2198 puffs_msg_setinfo(park_rename, PUFFSOP_VN,
2199 PUFFS_VN_RENAME, VPTOPNC(fdvp));
2200
2201 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rename, fdvp->v_data, NULL, error);
2202 doabort = false;
2203 PUFFS_MSG_RELEASE(rename);
2204 error = checkerr(pmp, error, __func__);
2205
2206 /*
2207 * XXX: stay in touch with the cache. I don't like this, but
2208 * don't have a better solution either. See also puffs_link().
2209 */
2210 if (error == 0) {
2211 puffs_updatenode(fpn, PUFFS_UPDATECTIME, 0);
2212 puffs_updatenode(VPTOPP(fdvp),
2213 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME, 0);
2214 if (fdvp != tdvp)
2215 puffs_updatenode(VPTOPP(tdvp),
2216 PUFFS_UPDATECTIME|PUFFS_UPDATEMTIME,
2217 0);
2218
2219 if (PUFFS_USE_DOTDOTCACHE(pmp) &&
2220 (VPTOPP(fvp)->pn_parent != tdvp))
2221 update_parent(fvp, tdvp);
2222 }
2223
2224
2225 out:
2226 if (doabort)
2227 VOP_ABORTOP(tdvp, ap->a_tcnp);
2228 if (tvp != NULL)
2229 vput(tvp);
2230 if (tdvp == tvp)
2231 vrele(tdvp);
2232 else
2233 vput(tdvp);
2234
2235 if (doabort)
2236 VOP_ABORTOP(fdvp, ap->a_fcnp);
2237 vrele(fdvp);
2238 vrele(fvp);
2239
2240 return error;
2241 }
2242
2243 #define RWARGS(cont, iofl, move, offset, creds) \
2244 (cont)->pvnr_ioflag = (iofl); \
2245 (cont)->pvnr_resid = (move); \
2246 (cont)->pvnr_offset = (offset); \
2247 puffs_credcvt(&(cont)->pvnr_cred, creds)
2248
2249 int
2250 puffs_vnop_read(void *v)
2251 {
2252 struct vop_read_args /* {
2253 const struct vnodeop_desc *a_desc;
2254 struct vnode *a_vp;
2255 struct uio *a_uio;
2256 int a_ioflag;
2257 kauth_cred_t a_cred;
2258 } */ *ap = v;
2259 PUFFS_MSG_VARS(vn, read);
2260 struct vnode *vp = ap->a_vp;
2261 struct puffs_node *pn = VPTOPP(vp);
2262 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2263 struct uio *uio = ap->a_uio;
2264 size_t tomove, argsize;
2265 vsize_t bytelen;
2266 int error;
2267
2268 read_msg = NULL;
2269 error = 0;
2270
2271 /* std sanity */
2272 if (uio->uio_resid == 0)
2273 return 0;
2274 if (uio->uio_offset < 0)
2275 return EFBIG;
2276
2277 /*
2278 * On the case of reading empty files and (vp->v_size != 0) below:
2279 * some filesystems (hint: FUSE and distributed filesystems) still
2280 * expect to get the READ in order to update atime. Reading through
2281 * the case filters empty files, therefore we prefer to bypass the
2282 * cache here.
2283 */
2284 if (vp->v_type == VREG &&
2285 PUFFS_USE_PAGECACHE(pmp) &&
2286 !(pn->pn_stat & PNODE_RDIRECT) &&
2287 (vp->v_size != 0)) {
2288 const int advice = IO_ADV_DECODE(ap->a_ioflag);
2289
2290 while (uio->uio_resid > 0) {
2291 if (vp->v_size <= uio->uio_offset) {
2292 break;
2293 }
2294 bytelen = MIN(uio->uio_resid,
2295 vp->v_size - uio->uio_offset);
2296 if (bytelen == 0)
2297 break;
2298
2299 error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice,
2300 UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
2301 if (error)
2302 break;
2303 }
2304
2305 if ((vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
2306 puffs_updatenode(VPTOPP(vp), PUFFS_UPDATEATIME, 0);
2307 } else {
2308 /*
2309 * in case it's not a regular file or we're operating
2310 * uncached, do read in the old-fashioned style,
2311 * i.e. explicit read operations
2312 */
2313
2314 tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
2315 argsize = sizeof(struct puffs_vnmsg_read);
2316 puffs_msgmem_alloc(argsize + tomove, &park_read,
2317 (void *)&read_msg, 1);
2318
2319 error = 0;
2320 while (uio->uio_resid > 0) {
2321 tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
2322 memset(read_msg, 0, argsize); /* XXX: touser KASSERT */
2323 RWARGS(read_msg, ap->a_ioflag, tomove,
2324 uio->uio_offset, ap->a_cred);
2325 puffs_msg_setinfo(park_read, PUFFSOP_VN,
2326 PUFFS_VN_READ, VPTOPNC(vp));
2327 puffs_msg_setdelta(park_read, tomove);
2328
2329 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_read, vp->v_data,
2330 NULL, error);
2331 error = checkerr(pmp, error, __func__);
2332 if (error)
2333 break;
2334
2335 if (read_msg->pvnr_resid > tomove) {
2336 puffs_senderr(pmp, PUFFS_ERR_READ,
2337 E2BIG, "resid grew", VPTOPNC(ap->a_vp));
2338 error = EPROTO;
2339 break;
2340 }
2341
2342 error = uiomove(read_msg->pvnr_data,
2343 tomove - read_msg->pvnr_resid, uio);
2344
2345 /*
2346 * in case the file is out of juice, resid from
2347 * userspace is != 0. and the error-case is
2348 * quite obvious
2349 */
2350 if (error || read_msg->pvnr_resid)
2351 break;
2352 }
2353
2354 puffs_msgmem_release(park_read);
2355 }
2356
2357 return error;
2358 }
2359
2360 /*
2361 * XXX: in case of a failure, this leaves uio in a bad state.
2362 * We could theoretically copy the uio and iovecs and "replay"
2363 * them the right amount after the userspace trip, but don't
2364 * bother for now.
2365 */
2366 int
2367 puffs_vnop_write(void *v)
2368 {
2369 struct vop_write_args /* {
2370 const struct vnodeop_desc *a_desc;
2371 struct vnode *a_vp;
2372 struct uio *a_uio;
2373 int a_ioflag;
2374 kauth_cred_t a_cred;
2375 } */ *ap = v;
2376 PUFFS_MSG_VARS(vn, write);
2377 struct vnode *vp = ap->a_vp;
2378 struct puffs_node *pn = VPTOPP(vp);
2379 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2380 struct uio *uio = ap->a_uio;
2381 size_t tomove, argsize;
2382 off_t oldoff, newoff, origoff;
2383 vsize_t bytelen;
2384 int error, uflags;
2385 int ubcflags;
2386
2387 error = uflags = 0;
2388 write_msg = NULL;
2389
2390 /* std sanity */
2391 if (uio->uio_resid == 0)
2392 return 0;
2393 if (uio->uio_offset < 0)
2394 return EFBIG;
2395
2396 mutex_enter(&pn->pn_sizemtx);
2397
2398 /*
2399 * userspace *should* be allowed to control this,
2400 * but with UBC it's a bit unclear how to handle it
2401 */
2402 if (ap->a_ioflag & IO_APPEND)
2403 uio->uio_offset = vp->v_size;
2404
2405 origoff = uio->uio_offset;
2406
2407 if (vp->v_type == VREG &&
2408 PUFFS_USE_PAGECACHE(pmp) &&
2409 !(pn->pn_stat & PNODE_WDIRECT)) {
2410 ubcflags = UBC_WRITE | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp);
2411
2412 while (uio->uio_resid > 0) {
2413 oldoff = uio->uio_offset;
2414 bytelen = uio->uio_resid;
2415
2416 newoff = oldoff + bytelen;
2417 if (vp->v_size < newoff) {
2418 uvm_vnp_setwritesize(vp, newoff);
2419 }
2420 error = ubc_uiomove(&vp->v_uobj, uio, bytelen,
2421 UVM_ADV_RANDOM, ubcflags);
2422
2423 /*
2424 * In case of a ubc_uiomove() error,
2425 * opt to not extend the file at all and
2426 * return an error. Otherwise, if we attempt
2427 * to clear the memory we couldn't fault to,
2428 * we might generate a kernel page fault.
2429 */
2430 if (vp->v_size < newoff) {
2431 if (error == 0) {
2432 uflags |= PUFFS_UPDATESIZE;
2433 uvm_vnp_setsize(vp, newoff);
2434 } else {
2435 uvm_vnp_setwritesize(vp, vp->v_size);
2436 }
2437 }
2438 if (error)
2439 break;
2440
2441 /*
2442 * If we're writing large files, flush to file server
2443 * every 64k. Otherwise we can very easily exhaust
2444 * kernel and user memory, as the file server cannot
2445 * really keep up with our writing speed.
2446 *
2447 * Note: this does *NOT* honor MNT_ASYNC, because
2448 * that gives userland too much say in the kernel.
2449 */
2450 if (oldoff >> 16 != uio->uio_offset >> 16) {
2451 mutex_enter(vp->v_interlock);
2452 error = VOP_PUTPAGES(vp, oldoff & ~0xffff,
2453 uio->uio_offset & ~0xffff,
2454 PGO_CLEANIT | PGO_SYNCIO);
2455 if (error)
2456 break;
2457 }
2458 }
2459
2460 /* synchronous I/O? */
2461 if (error == 0 && ap->a_ioflag & IO_SYNC) {
2462 mutex_enter(vp->v_interlock);
2463 error = VOP_PUTPAGES(vp, trunc_page(origoff),
2464 round_page(uio->uio_offset),
2465 PGO_CLEANIT | PGO_SYNCIO);
2466
2467 /* write through page cache? */
2468 } else if (error == 0 && pmp->pmp_flags & PUFFS_KFLAG_WTCACHE) {
2469 mutex_enter(vp->v_interlock);
2470 error = VOP_PUTPAGES(vp, trunc_page(origoff),
2471 round_page(uio->uio_offset), PGO_CLEANIT);
2472 }
2473 } else {
2474 /* tomove is non-increasing */
2475 tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
2476 argsize = sizeof(struct puffs_vnmsg_write) + tomove;
2477 puffs_msgmem_alloc(argsize, &park_write, (void *)&write_msg,1);
2478
2479 while (uio->uio_resid > 0) {
2480 /* move data to buffer */
2481 tomove = PUFFS_TOMOVE(uio->uio_resid, pmp);
2482 memset(write_msg, 0, argsize); /* XXX: touser KASSERT */
2483 RWARGS(write_msg, ap->a_ioflag, tomove,
2484 uio->uio_offset, ap->a_cred);
2485 error = uiomove(write_msg->pvnr_data, tomove, uio);
2486 if (error)
2487 break;
2488
2489 /* move buffer to userspace */
2490 puffs_msg_setinfo(park_write, PUFFSOP_VN,
2491 PUFFS_VN_WRITE, VPTOPNC(vp));
2492 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_write, vp->v_data,
2493 NULL, error);
2494 error = checkerr(pmp, error, __func__);
2495 if (error)
2496 break;
2497
2498 if (write_msg->pvnr_resid > tomove) {
2499 puffs_senderr(pmp, PUFFS_ERR_WRITE,
2500 E2BIG, "resid grew", VPTOPNC(ap->a_vp));
2501 error = EPROTO;
2502 break;
2503 }
2504
2505 /* adjust file size */
2506 if (vp->v_size < uio->uio_offset) {
2507 uflags |= PUFFS_UPDATESIZE;
2508 uvm_vnp_setsize(vp, uio->uio_offset);
2509 }
2510
2511 /* didn't move everything? bad userspace. bail */
2512 if (write_msg->pvnr_resid != 0) {
2513 error = EIO;
2514 break;
2515 }
2516 }
2517 puffs_msgmem_release(park_write);
2518
2519 /*
2520 * Direct I/O on write but not on read: we must
2521 * invlidate the written pages so that we read
2522 * the written data and not the stalled cache.
2523 */
2524 if ((error == 0) &&
2525 (vp->v_type == VREG) && PUFFS_USE_PAGECACHE(pmp) &&
2526 (pn->pn_stat & PNODE_WDIRECT) &&
2527 !(pn->pn_stat & PNODE_RDIRECT)) {
2528 voff_t off_lo = trunc_page(origoff);
2529 voff_t off_hi = round_page(uio->uio_offset);
2530
2531 mutex_enter(vp->v_uobj.vmobjlock);
2532 error = VOP_PUTPAGES(vp, off_lo, off_hi, PGO_FREE);
2533 }
2534 }
2535
2536 if (vp->v_mount->mnt_flag & MNT_RELATIME)
2537 uflags |= PUFFS_UPDATEATIME;
2538 uflags |= PUFFS_UPDATECTIME;
2539 uflags |= PUFFS_UPDATEMTIME;
2540 puffs_updatenode(VPTOPP(vp), uflags, vp->v_size);
2541
2542 /*
2543 * If we do not use meta flush, we need to update the
2544 * filesystem now, otherwise we will get a stale value
2545 * on the next GETATTR
2546 */
2547 if (!PUFFS_USE_METAFLUSH(pmp) && (uflags & PUFFS_UPDATESIZE)) {
2548 struct vattr va;
2549 int ret;
2550
2551 vattr_null(&va);
2552 va.va_size = vp->v_size;
2553 ret = dosetattr(vp, &va, FSCRED, 0);
2554 if (ret) {
2555 DPRINTF(("dosetattr set size to %jd failed: %d\n",
2556 (intmax_t)vp->v_size, ret));
2557 }
2558 }
2559 mutex_exit(&pn->pn_sizemtx);
2560 return error;
2561 }
2562
2563 int
2564 puffs_vnop_fallocate(void *v)
2565 {
2566 struct vop_fallocate_args /* {
2567 const struct vnodeop_desc *a_desc;
2568 struct vnode *a_vp;
2569 off_t a_pos;
2570 off_t a_len;
2571 } */ *ap = v;
2572 struct vnode *vp = ap->a_vp;
2573 struct puffs_node *pn = VPTOPP(vp);
2574 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2575 PUFFS_MSG_VARS(vn, fallocate);
2576 int error;
2577
2578 mutex_enter(&pn->pn_sizemtx);
2579
2580 PUFFS_MSG_ALLOC(vn, fallocate);
2581 fallocate_msg->pvnr_off = ap->a_pos;
2582 fallocate_msg->pvnr_len = ap->a_len;
2583 puffs_msg_setinfo(park_fallocate, PUFFSOP_VN,
2584 PUFFS_VN_FALLOCATE, VPTOPNC(vp));
2585
2586 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fallocate, vp->v_data, NULL, error);
2587 error = checkerr(pmp, error, __func__);
2588 PUFFS_MSG_RELEASE(fallocate);
2589
2590 switch (error) {
2591 case 0:
2592 break;
2593 case EAGAIN:
2594 error = EIO;
2595 /* FALLTHROUGH */
2596 default:
2597 goto out;
2598 }
2599
2600 if (ap->a_pos + ap->a_len > vp->v_size) {
2601 uvm_vnp_setsize(vp, ap->a_pos + ap->a_len);
2602 puffs_updatenode(pn, PUFFS_UPDATESIZE, vp->v_size);
2603 }
2604 out:
2605 mutex_exit(&pn->pn_sizemtx);
2606
2607 return error;
2608 }
2609
2610 int
2611 puffs_vnop_fdiscard(void *v)
2612 {
2613 struct vop_fdiscard_args /* {
2614 const struct vnodeop_desc *a_desc;
2615 struct vnode *a_vp;
2616 off_t a_pos;
2617 off_t a_len;
2618 } */ *ap = v;
2619 struct vnode *vp = ap->a_vp;
2620 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2621 PUFFS_MSG_VARS(vn, fdiscard);
2622 int error;
2623
2624 PUFFS_MSG_ALLOC(vn, fdiscard);
2625 fdiscard_msg->pvnr_off = ap->a_pos;
2626 fdiscard_msg->pvnr_len = ap->a_len;
2627 puffs_msg_setinfo(park_fdiscard, PUFFSOP_VN,
2628 PUFFS_VN_FALLOCATE, VPTOPNC(vp));
2629
2630 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fdiscard, vp->v_data, NULL, error);
2631 error = checkerr(pmp, error, __func__);
2632 PUFFS_MSG_RELEASE(fdiscard);
2633
2634 return error;
2635 }
2636
2637 int
2638 puffs_vnop_print(void *v)
2639 {
2640 struct vop_print_args /* {
2641 struct vnode *a_vp;
2642 } */ *ap = v;
2643 PUFFS_MSG_VARS(vn, print);
2644 struct vnode *vp = ap->a_vp;
2645 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2646 struct puffs_node *pn = vp->v_data;
2647
2648 /* kernel portion */
2649 printf("tag VT_PUFFS, vnode %p, puffs node: %p,\n"
2650 "\tuserspace cookie: %p", vp, pn, pn->pn_cookie);
2651 if (vp->v_type == VFIFO)
2652 VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v);
2653 printf("\n");
2654
2655 /* userspace portion */
2656 if (EXISTSOP(pmp, PRINT)) {
2657 PUFFS_MSG_ALLOC(vn, print);
2658 puffs_msg_setinfo(park_print, PUFFSOP_VN,
2659 PUFFS_VN_PRINT, VPTOPNC(vp));
2660 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp, park_print, vp->v_data,
2661 NULL);
2662 PUFFS_MSG_RELEASE(print);
2663 }
2664
2665 return 0;
2666 }
2667
2668 int
2669 puffs_vnop_pathconf(void *v)
2670 {
2671 struct vop_pathconf_args /* {
2672 const struct vnodeop_desc *a_desc;
2673 struct vnode *a_vp;
2674 int a_name;
2675 register_t *a_retval;
2676 } */ *ap = v;
2677 PUFFS_MSG_VARS(vn, pathconf);
2678 struct vnode *vp = ap->a_vp;
2679 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2680 int error;
2681
2682 PUFFS_MSG_ALLOC(vn, pathconf);
2683 pathconf_msg->pvnr_name = ap->a_name;
2684 puffs_msg_setinfo(park_pathconf, PUFFSOP_VN,
2685 PUFFS_VN_PATHCONF, VPTOPNC(vp));
2686 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_pathconf, vp->v_data, NULL, error);
2687 error = checkerr(pmp, error, __func__);
2688 if (!error)
2689 *ap->a_retval = pathconf_msg->pvnr_retval;
2690 PUFFS_MSG_RELEASE(pathconf);
2691
2692 return error;
2693 }
2694
2695 int
2696 puffs_vnop_advlock(void *v)
2697 {
2698 struct vop_advlock_args /* {
2699 const struct vnodeop_desc *a_desc;
2700 struct vnode *a_vp;
2701 void *a_id;
2702 int a_op;
2703 struct flock *a_fl;
2704 int a_flags;
2705 } */ *ap = v;
2706 PUFFS_MSG_VARS(vn, advlock);
2707 struct vnode *vp = ap->a_vp;
2708 struct puffs_node *pn = VPTOPP(vp);
2709 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2710 int error;
2711
2712 if (!EXISTSOP(pmp, ADVLOCK))
2713 return lf_advlock(ap, &pn->pn_lockf, vp->v_size);
2714
2715 PUFFS_MSG_ALLOC(vn, advlock);
2716 (void)memcpy(&advlock_msg->pvnr_fl, ap->a_fl,
2717 sizeof(advlock_msg->pvnr_fl));
2718 advlock_msg->pvnr_id = ap->a_id;
2719 advlock_msg->pvnr_op = ap->a_op;
2720 advlock_msg->pvnr_flags = ap->a_flags;
2721 puffs_msg_setinfo(park_advlock, PUFFSOP_VN,
2722 PUFFS_VN_ADVLOCK, VPTOPNC(vp));
2723 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_advlock, vp->v_data, NULL, error);
2724 error = checkerr(pmp, error, __func__);
2725 PUFFS_MSG_RELEASE(advlock);
2726
2727 return error;
2728 }
2729
2730 int
2731 puffs_vnop_abortop(void *v)
2732 {
2733 struct vop_abortop_args /* {
2734 struct vnode *a_dvp;
2735 struct componentname *a_cnp;
2736 }; */ *ap = v;
2737 PUFFS_MSG_VARS(vn, abortop);
2738 struct vnode *dvp = ap->a_dvp;
2739 struct puffs_mount *pmp = MPTOPUFFSMP(dvp->v_mount);
2740 struct componentname *cnp = ap->a_cnp;
2741
2742 if (EXISTSOP(pmp, ABORTOP)) {
2743 PUFFS_MSG_ALLOC(vn, abortop);
2744 puffs_makecn(&abortop_msg->pvnr_cn, &abortop_msg->pvnr_cn_cred,
2745 cnp, PUFFS_USE_FULLPNBUF(pmp));
2746 puffs_msg_setfaf(park_abortop);
2747 puffs_msg_setinfo(park_abortop, PUFFSOP_VN,
2748 PUFFS_VN_ABORTOP, VPTOPNC(dvp));
2749
2750 puffs_msg_enqueue(pmp, park_abortop);
2751 PUFFS_MSG_RELEASE(abortop);
2752 }
2753
2754 return genfs_abortop(v);
2755 }
2756
2757 #define BIOASYNC(bp) (bp->b_flags & B_ASYNC)
2758
2759 /*
2760 * This maps itself to PUFFS_VN_READ/WRITE for data transfer.
2761 */
2762 int
2763 puffs_vnop_strategy(void *v)
2764 {
2765 struct vop_strategy_args /* {
2766 const struct vnodeop_desc *a_desc;
2767 struct vnode *a_vp;
2768 struct buf *a_bp;
2769 } */ *ap = v;
2770 PUFFS_MSG_VARS(vn, rw);
2771 struct vnode *vp = ap->a_vp;
2772 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2773 struct puffs_node *pn;
2774 struct buf *bp;
2775 size_t argsize;
2776 size_t tomove, moved;
2777 int error, dofaf, cansleep, dobiodone;
2778
2779 pmp = MPTOPUFFSMP(vp->v_mount);
2780 bp = ap->a_bp;
2781 error = 0;
2782 dofaf = 0;
2783 cansleep = 0;
2784 pn = VPTOPP(vp);
2785 park_rw = NULL; /* explicit */
2786 dobiodone = 1;
2787
2788 if ((BUF_ISREAD(bp) && !EXISTSOP(pmp, READ))
2789 || (BUF_ISWRITE(bp) && !EXISTSOP(pmp, WRITE)))
2790 ERROUT(EOPNOTSUPP);
2791
2792 /*
2793 * Short-circuit optimization: don't flush buffer in between
2794 * VOP_INACTIVE and VOP_RECLAIM in case the node has no references.
2795 */
2796 if (pn->pn_stat & PNODE_DYING) {
2797 KASSERT(BUF_ISWRITE(bp));
2798 bp->b_resid = 0;
2799 goto out;
2800 }
2801
2802 #ifdef DIAGNOSTIC
2803 if (bp->b_bcount > pmp->pmp_msg_maxsize - PUFFS_MSGSTRUCT_MAX)
2804 panic("puffs_strategy: wildly inappropriate buf bcount %d",
2805 bp->b_bcount);
2806 #endif
2807
2808 /*
2809 * See explanation for the necessity of a FAF in puffs_fsync.
2810 *
2811 * Also, do FAF in case we're suspending.
2812 * See puffs_vfsops.c:pageflush()
2813 */
2814 if (BUF_ISWRITE(bp)) {
2815 mutex_enter(vp->v_interlock);
2816 if (vdead_check(vp, VDEAD_NOWAIT) != 0)
2817 dofaf = 1;
2818 if (pn->pn_stat & PNODE_FAF)
2819 dofaf = 1;
2820 mutex_exit(vp->v_interlock);
2821 }
2822
2823 cansleep = (curlwp == uvm.pagedaemon_lwp || dofaf) ? 0 : 1;
2824
2825 KASSERT(curlwp != uvm.pagedaemon_lwp || dofaf || BIOASYNC(bp));
2826
2827 /* allocate transport structure */
2828 tomove = PUFFS_TOMOVE(bp->b_bcount, pmp);
2829 argsize = sizeof(struct puffs_vnmsg_rw);
2830 error = puffs_msgmem_alloc(argsize + tomove, &park_rw,
2831 (void *)&rw_msg, cansleep);
2832 if (error)
2833 goto out;
2834 RWARGS(rw_msg, 0, tomove, bp->b_blkno << DEV_BSHIFT, FSCRED);
2835
2836 /* 2x2 cases: read/write, faf/nofaf */
2837 if (BUF_ISREAD(bp)) {
2838 puffs_msg_setinfo(park_rw, PUFFSOP_VN,
2839 PUFFS_VN_READ, VPTOPNC(vp));
2840 puffs_msg_setdelta(park_rw, tomove);
2841 if (BIOASYNC(bp)) {
2842 puffs_msg_setcall(park_rw,
2843 puffs_parkdone_asyncbioread, bp);
2844 puffs_msg_enqueue(pmp, park_rw);
2845 dobiodone = 0;
2846 } else {
2847 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rw, vp->v_data,
2848 NULL, error);
2849 error = checkerr(pmp, error, __func__);
2850 if (error)
2851 goto out;
2852
2853 if (rw_msg->pvnr_resid > tomove) {
2854 puffs_senderr(pmp, PUFFS_ERR_READ,
2855 E2BIG, "resid grew", VPTOPNC(vp));
2856 ERROUT(EPROTO);
2857 }
2858
2859 moved = tomove - rw_msg->pvnr_resid;
2860
2861 (void)memcpy(bp->b_data, rw_msg->pvnr_data, moved);
2862 bp->b_resid = bp->b_bcount - moved;
2863 }
2864 } else {
2865 puffs_msg_setinfo(park_rw, PUFFSOP_VN,
2866 PUFFS_VN_WRITE, VPTOPNC(vp));
2867 /*
2868 * make pages read-only before we write them if we want
2869 * write caching info
2870 */
2871 if (PUFFS_WCACHEINFO(pmp)) {
2872 struct uvm_object *uobj = &vp->v_uobj;
2873 int npages = (bp->b_bcount + PAGE_SIZE-1) >> PAGE_SHIFT;
2874 struct vm_page *vmp;
2875 int i;
2876
2877 for (i = 0; i < npages; i++) {
2878 vmp= uvm_pageratop((vaddr_t)bp->b_data
2879 + (i << PAGE_SHIFT));
2880 DPRINTF(("puffs_strategy: write-protecting "
2881 "vp %p page %p, offset %" PRId64"\n",
2882 vp, vmp, vmp->offset));
2883 mutex_enter(uobj->vmobjlock);
2884 vmp->flags |= PG_RDONLY;
2885 pmap_page_protect(vmp, VM_PROT_READ);
2886 mutex_exit(uobj->vmobjlock);
2887 }
2888 }
2889
2890 (void)memcpy(&rw_msg->pvnr_data, bp->b_data, tomove);
2891 if (dofaf) {
2892 puffs_msg_setfaf(park_rw);
2893 } else if (BIOASYNC(bp)) {
2894 puffs_msg_setcall(park_rw,
2895 puffs_parkdone_asyncbiowrite, bp);
2896 dobiodone = 0;
2897 }
2898
2899 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_rw, vp->v_data, NULL, error);
2900
2901 if (dobiodone == 0)
2902 goto out;
2903
2904 error = checkerr(pmp, error, __func__);
2905 if (error)
2906 goto out;
2907
2908 if (rw_msg->pvnr_resid > tomove) {
2909 puffs_senderr(pmp, PUFFS_ERR_WRITE,
2910 E2BIG, "resid grew", VPTOPNC(vp));
2911 ERROUT(EPROTO);
2912 }
2913
2914 /*
2915 * FAF moved everything. Frankly, we don't
2916 * really have a choice.
2917 */
2918 if (dofaf && error == 0)
2919 moved = tomove;
2920 else
2921 moved = tomove - rw_msg->pvnr_resid;
2922
2923 bp->b_resid = bp->b_bcount - moved;
2924 if (bp->b_resid != 0) {
2925 ERROUT(EIO);
2926 }
2927 }
2928
2929 out:
2930 if (park_rw)
2931 puffs_msgmem_release(park_rw);
2932
2933 if (error)
2934 bp->b_error = error;
2935
2936 if (error || dobiodone)
2937 biodone(bp);
2938
2939 return error;
2940 }
2941
2942 int
2943 puffs_vnop_mmap(void *v)
2944 {
2945 struct vop_mmap_args /* {
2946 const struct vnodeop_desc *a_desc;
2947 struct vnode *a_vp;
2948 vm_prot_t a_prot;
2949 kauth_cred_t a_cred;
2950 } */ *ap = v;
2951 PUFFS_MSG_VARS(vn, mmap);
2952 struct vnode *vp = ap->a_vp;
2953 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
2954 int error;
2955
2956 if (!PUFFS_USE_PAGECACHE(pmp))
2957 return genfs_eopnotsupp(v);
2958
2959 if (EXISTSOP(pmp, MMAP)) {
2960 PUFFS_MSG_ALLOC(vn, mmap);
2961 mmap_msg->pvnr_prot = ap->a_prot;
2962 puffs_credcvt(&mmap_msg->pvnr_cred, ap->a_cred);
2963 puffs_msg_setinfo(park_mmap, PUFFSOP_VN,
2964 PUFFS_VN_MMAP, VPTOPNC(vp));
2965
2966 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_mmap, vp->v_data, NULL, error);
2967 error = checkerr(pmp, error, __func__);
2968 PUFFS_MSG_RELEASE(mmap);
2969 } else {
2970 error = genfs_mmap(v);
2971 }
2972
2973 return error;
2974 }
2975
2976
2977 /*
2978 * The rest don't get a free trip to userspace and back, they
2979 * have to stay within the kernel.
2980 */
2981
2982 /*
2983 * bmap doesn't really make any sense for puffs, so just 1:1 map it.
2984 * well, maybe somehow, somewhere, some day ....
2985 */
2986 int
2987 puffs_vnop_bmap(void *v)
2988 {
2989 struct vop_bmap_args /* {
2990 const struct vnodeop_desc *a_desc;
2991 struct vnode *a_vp;
2992 daddr_t a_bn;
2993 struct vnode **a_vpp;
2994 daddr_t *a_bnp;
2995 int *a_runp;
2996 } */ *ap = v;
2997 struct puffs_mount *pmp;
2998
2999 pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
3000
3001 if (ap->a_vpp)
3002 *ap->a_vpp = ap->a_vp;
3003 if (ap->a_bnp)
3004 *ap->a_bnp = ap->a_bn;
3005 if (ap->a_runp)
3006 *ap->a_runp
3007 = (PUFFS_TOMOVE(pmp->pmp_msg_maxsize, pmp)>>DEV_BSHIFT) - 1;
3008
3009 return 0;
3010 }
3011
3012 /*
3013 * Handle getpages faults in puffs. We let genfs_getpages() do most
3014 * of the dirty work, but we come in this route to do accounting tasks.
3015 * If the user server has specified functions for cache notifications
3016 * about reads and/or writes, we record which type of operation we got,
3017 * for which page range, and proceed to issue a FAF notification to the
3018 * server about it.
3019 */
3020 int
3021 puffs_vnop_getpages(void *v)
3022 {
3023 struct vop_getpages_args /* {
3024 const struct vnodeop_desc *a_desc;
3025 struct vnode *a_vp;
3026 voff_t a_offset;
3027 struct vm_page **a_m;
3028 int *a_count;
3029 int a_centeridx;
3030 vm_prot_t a_access_type;
3031 int a_advice;
3032 int a_flags;
3033 } */ *ap = v;
3034 struct puffs_mount *pmp;
3035 struct puffs_node *pn;
3036 struct vnode *vp;
3037 struct vm_page **pgs;
3038 struct puffs_cacheinfo *pcinfo = NULL;
3039 struct puffs_cacherun *pcrun;
3040 void *parkmem = NULL;
3041 size_t runsizes;
3042 int i, npages, si, streakon;
3043 int error, locked, write;
3044
3045 pmp = MPTOPUFFSMP(ap->a_vp->v_mount);
3046 npages = *ap->a_count;
3047 pgs = ap->a_m;
3048 vp = ap->a_vp;
3049 pn = vp->v_data;
3050 locked = (ap->a_flags & PGO_LOCKED) != 0;
3051 write = (ap->a_access_type & VM_PROT_WRITE) != 0;
3052
3053 /* ccg xnaht - gets Wuninitialized wrong */
3054 pcrun = NULL;
3055 runsizes = 0;
3056
3057 /*
3058 * Check that we aren't trying to fault in pages which our file
3059 * server doesn't know about. This happens if we extend a file by
3060 * skipping some pages and later try to fault in pages which
3061 * are between pn_serversize and vp_size. This check optimizes
3062 * away the common case where a file is being extended.
3063 */
3064 if (ap->a_offset >= pn->pn_serversize && ap->a_offset < vp->v_size) {
3065 struct vattr va;
3066
3067 /* try again later when we can block */
3068 if (locked)
3069 ERROUT(EBUSY);
3070
3071 mutex_exit(vp->v_interlock);
3072 vattr_null(&va);
3073 va.va_size = vp->v_size;
3074 error = dosetattr(vp, &va, FSCRED, 0);
3075 if (error)
3076 ERROUT(error);
3077 mutex_enter(vp->v_interlock);
3078 }
3079
3080 if (write && PUFFS_WCACHEINFO(pmp)) {
3081 #ifdef notnowjohn
3082 /* allocate worst-case memory */
3083 runsizes = ((npages / 2) + 1) * sizeof(struct puffs_cacherun);
3084 KASSERT(curlwp != uvm.pagedaemon_lwp || locked);
3085 pcinfo = kmem_zalloc(sizeof(struct puffs_cacheinfo) + runsize,
3086 locked ? KM_NOSLEEP : KM_SLEEP);
3087
3088 /*
3089 * can't block if we're locked and can't mess up caching
3090 * information for fs server. so come back later, please
3091 */
3092 if (pcinfo == NULL)
3093 ERROUT(ENOMEM);
3094
3095 parkmem = puffs_park_alloc(locked == 0);
3096 if (parkmem == NULL)
3097 ERROUT(ENOMEM);
3098
3099 pcrun = pcinfo->pcache_runs;
3100 #else
3101 (void)parkmem;
3102 #endif
3103 }
3104
3105 error = genfs_getpages(v);
3106 if (error)
3107 goto out;
3108
3109 if (PUFFS_WCACHEINFO(pmp) == 0)
3110 goto out;
3111
3112 /*
3113 * Let's see whose fault it was and inform the user server of
3114 * possibly read/written pages. Map pages from read faults
3115 * strictly read-only, since otherwise we might miss info on
3116 * when the page is actually write-faulted to.
3117 */
3118 if (!locked)
3119 mutex_enter(vp->v_uobj.vmobjlock);
3120 for (i = 0, si = 0, streakon = 0; i < npages; i++) {
3121 if (pgs[i] == NULL || pgs[i] == PGO_DONTCARE) {
3122 if (streakon && write) {
3123 streakon = 0;
3124 pcrun[si].pcache_runend
3125 = trunc_page(pgs[i]->offset) + PAGE_MASK;
3126 si++;
3127 }
3128 continue;
3129 }
3130 if (streakon == 0 && write) {
3131 streakon = 1;
3132 pcrun[si].pcache_runstart = pgs[i]->offset;
3133 }
3134
3135 if (!write)
3136 pgs[i]->flags |= PG_RDONLY;
3137 }
3138 /* was the last page part of our streak? */
3139 if (streakon) {
3140 pcrun[si].pcache_runend
3141 = trunc_page(pgs[i-1]->offset) + PAGE_MASK;
3142 si++;
3143 }
3144 if (!locked)
3145 mutex_exit(vp->v_uobj.vmobjlock);
3146
3147 KASSERT(si <= (npages / 2) + 1);
3148
3149 #ifdef notnowjohn
3150 /* send results to userspace */
3151 if (write)
3152 puffs_cacheop(pmp, parkmem, pcinfo,
3153 sizeof(struct puffs_cacheinfo) + runsizes, VPTOPNC(vp));
3154 #endif
3155
3156 out:
3157 if (error) {
3158 if (pcinfo != NULL)
3159 kmem_free(pcinfo,
3160 sizeof(struct puffs_cacheinfo) + runsizes);
3161 #ifdef notnowjohn
3162 if (parkmem != NULL)
3163 puffs_park_release(parkmem, 1);
3164 #endif
3165 }
3166
3167 return error;
3168 }
3169
3170 /*
3171 * Extended attribute support.
3172 */
3173
3174 int
3175 puffs_vnop_getextattr(void *v)
3176 {
3177 struct vop_getextattr_args /*
3178 struct vnode *a_vp;
3179 int a_attrnamespace;
3180 const char *a_name;
3181 struct uio *a_uio;
3182 size_t *a_size;
3183 kauth_cred_t a_cred;
3184 }; */ *ap = v;
3185 PUFFS_MSG_VARS(vn, getextattr);
3186 struct vnode *vp = ap->a_vp;
3187 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
3188 int attrnamespace = ap->a_attrnamespace;
3189 const char *name = ap->a_name;
3190 struct uio *uio = ap->a_uio;
3191 size_t *sizep = ap->a_size;
3192 size_t tomove, resid;
3193 int error;
3194
3195 if (uio)
3196 resid = uio->uio_resid;
3197 else
3198 resid = 0;
3199
3200 tomove = PUFFS_TOMOVE(resid, pmp);
3201 if (tomove != resid) {
3202 error = E2BIG;
3203 goto out;
3204 }
3205
3206 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_getextattr) + tomove,
3207 &park_getextattr, (void *)&getextattr_msg, 1);
3208
3209 getextattr_msg->pvnr_attrnamespace = attrnamespace;
3210 strlcpy(getextattr_msg->pvnr_attrname, name,
3211 sizeof(getextattr_msg->pvnr_attrname));
3212 puffs_credcvt(&getextattr_msg->pvnr_cred, ap->a_cred);
3213 if (sizep)
3214 getextattr_msg->pvnr_datasize = 1;
3215 getextattr_msg->pvnr_resid = tomove;
3216
3217 puffs_msg_setinfo(park_getextattr,
3218 PUFFSOP_VN, PUFFS_VN_GETEXTATTR, VPTOPNC(vp));
3219 puffs_msg_setdelta(park_getextattr, tomove);
3220 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_getextattr, vp->v_data, NULL, error);
3221
3222 error = checkerr(pmp, error, __func__);
3223 if (error)
3224 goto out;
3225
3226 resid = getextattr_msg->pvnr_resid;
3227 if (resid > tomove) {
3228 puffs_senderr(pmp, PUFFS_ERR_GETEXTATTR, E2BIG,
3229 "resid grew", VPTOPNC(vp));
3230 error = EPROTO;
3231 goto out;
3232 }
3233
3234 if (sizep)
3235 *sizep = getextattr_msg->pvnr_datasize;
3236 if (uio)
3237 error = uiomove(getextattr_msg->pvnr_data, tomove - resid, uio);
3238
3239 out:
3240 PUFFS_MSG_RELEASE(getextattr);
3241 return error;
3242 }
3243
3244 int
3245 puffs_vnop_setextattr(void *v)
3246 {
3247 struct vop_setextattr_args /* {
3248 struct vnode *a_vp;
3249 int a_attrnamespace;
3250 const char *a_name;
3251 struct uio *a_uio;
3252 kauth_cred_t a_cred;
3253 }; */ *ap = v;
3254 PUFFS_MSG_VARS(vn, setextattr);
3255 struct vnode *vp = ap->a_vp;
3256 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
3257 int attrnamespace = ap->a_attrnamespace;
3258 const char *name = ap->a_name;
3259 struct uio *uio = ap->a_uio;
3260 size_t tomove, resid;
3261 int error;
3262
3263 if (uio)
3264 resid = uio->uio_resid;
3265 else
3266 resid = 0;
3267
3268 tomove = PUFFS_TOMOVE(resid, pmp);
3269 if (tomove != resid) {
3270 error = E2BIG;
3271 goto out;
3272 }
3273
3274 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_setextattr) + tomove,
3275 &park_setextattr, (void *)&setextattr_msg, 1);
3276
3277 setextattr_msg->pvnr_attrnamespace = attrnamespace;
3278 strlcpy(setextattr_msg->pvnr_attrname, name,
3279 sizeof(setextattr_msg->pvnr_attrname));
3280 puffs_credcvt(&setextattr_msg->pvnr_cred, ap->a_cred);
3281 setextattr_msg->pvnr_resid = tomove;
3282
3283 if (uio) {
3284 error = uiomove(setextattr_msg->pvnr_data, tomove, uio);
3285 if (error)
3286 goto out;
3287 }
3288
3289 puffs_msg_setinfo(park_setextattr,
3290 PUFFSOP_VN, PUFFS_VN_SETEXTATTR, VPTOPNC(vp));
3291 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_setextattr, vp->v_data, NULL, error);
3292
3293 error = checkerr(pmp, error, __func__);
3294 if (error)
3295 goto out;
3296
3297 if (setextattr_msg->pvnr_resid != 0)
3298 error = EIO;
3299
3300 out:
3301 PUFFS_MSG_RELEASE(setextattr);
3302
3303 return error;
3304 }
3305
3306 int
3307 puffs_vnop_listextattr(void *v)
3308 {
3309 struct vop_listextattr_args /* {
3310 struct vnode *a_vp;
3311 int a_attrnamespace;
3312 struct uio *a_uio;
3313 size_t *a_size;
3314 int a_flag,
3315 kauth_cred_t a_cred;
3316 }; */ *ap = v;
3317 PUFFS_MSG_VARS(vn, listextattr);
3318 struct vnode *vp = ap->a_vp;
3319 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
3320 int attrnamespace = ap->a_attrnamespace;
3321 struct uio *uio = ap->a_uio;
3322 size_t *sizep = ap->a_size;
3323 int flag = ap->a_flag;
3324 size_t tomove, resid;
3325 int error;
3326
3327 if (uio)
3328 resid = uio->uio_resid;
3329 else
3330 resid = 0;
3331
3332 tomove = PUFFS_TOMOVE(resid, pmp);
3333 if (tomove != resid) {
3334 error = E2BIG;
3335 goto out;
3336 }
3337
3338 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_listextattr) + tomove,
3339 &park_listextattr, (void *)&listextattr_msg, 1);
3340
3341 listextattr_msg->pvnr_attrnamespace = attrnamespace;
3342 listextattr_msg->pvnr_flag = flag;
3343 puffs_credcvt(&listextattr_msg->pvnr_cred, ap->a_cred);
3344 listextattr_msg->pvnr_resid = tomove;
3345 if (sizep)
3346 listextattr_msg->pvnr_datasize = 1;
3347
3348 puffs_msg_setinfo(park_listextattr,
3349 PUFFSOP_VN, PUFFS_VN_LISTEXTATTR, VPTOPNC(vp));
3350 puffs_msg_setdelta(park_listextattr, tomove);
3351 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_listextattr, vp->v_data, NULL, error);
3352
3353 error = checkerr(pmp, error, __func__);
3354 if (error)
3355 goto out;
3356
3357 resid = listextattr_msg->pvnr_resid;
3358 if (resid > tomove) {
3359 puffs_senderr(pmp, PUFFS_ERR_LISTEXTATTR, E2BIG,
3360 "resid grew", VPTOPNC(vp));
3361 error = EPROTO;
3362 goto out;
3363 }
3364
3365 if (sizep)
3366 *sizep = listextattr_msg->pvnr_datasize;
3367 if (uio)
3368 error = uiomove(listextattr_msg->pvnr_data, tomove-resid, uio);
3369
3370 out:
3371 PUFFS_MSG_RELEASE(listextattr);
3372 return error;
3373 }
3374
3375 int
3376 puffs_vnop_deleteextattr(void *v)
3377 {
3378 struct vop_deleteextattr_args /* {
3379 struct vnode *a_vp;
3380 int a_attrnamespace;
3381 const char *a_name;
3382 kauth_cred_t a_cred;
3383 }; */ *ap = v;
3384 PUFFS_MSG_VARS(vn, deleteextattr);
3385 struct vnode *vp = ap->a_vp;
3386 struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
3387 int attrnamespace = ap->a_attrnamespace;
3388 const char *name = ap->a_name;
3389 int error;
3390
3391 PUFFS_MSG_ALLOC(vn, deleteextattr);
3392 deleteextattr_msg->pvnr_attrnamespace = attrnamespace;
3393 strlcpy(deleteextattr_msg->pvnr_attrname, name,
3394 sizeof(deleteextattr_msg->pvnr_attrname));
3395 puffs_credcvt(&deleteextattr_msg->pvnr_cred, ap->a_cred);
3396
3397 puffs_msg_setinfo(park_deleteextattr,
3398 PUFFSOP_VN, PUFFS_VN_DELETEEXTATTR, VPTOPNC(vp));
3399 PUFFS_MSG_ENQUEUEWAIT2(pmp, park_deleteextattr,
3400 vp->v_data, NULL, error);
3401
3402 error = checkerr(pmp, error, __func__);
3403
3404 PUFFS_MSG_RELEASE(deleteextattr);
3405 return error;
3406 }
3407
3408 /*
3409 * spec & fifo. These call the miscfs spec and fifo vectors, but issue
3410 * FAF update information for the puffs node first.
3411 */
3412 int
3413 puffs_vnop_spec_read(void *v)
3414 {
3415 struct vop_read_args /* {
3416 const struct vnodeop_desc *a_desc;
3417 struct vnode *a_vp;
3418 struct uio *a_uio;
3419 int a_ioflag;
3420 kauth_cred_t a_cred;
3421 } */ *ap = v;
3422
3423 puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEATIME, 0);
3424 return VOCALL(spec_vnodeop_p, VOFFSET(vop_read), v);
3425 }
3426
3427 int
3428 puffs_vnop_spec_write(void *v)
3429 {
3430 struct vop_write_args /* {
3431 const struct vnodeop_desc *a_desc;
3432 struct vnode *a_vp;
3433 struct uio *a_uio;
3434 int a_ioflag;
3435 kauth_cred_t a_cred;
3436 } */ *ap = v;
3437
3438 puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEMTIME, 0);
3439 return VOCALL(spec_vnodeop_p, VOFFSET(vop_write), v);
3440 }
3441
3442 int
3443 puffs_vnop_fifo_read(void *v)
3444 {
3445 struct vop_read_args /* {
3446 const struct vnodeop_desc *a_desc;
3447 struct vnode *a_vp;
3448 struct uio *a_uio;
3449 int a_ioflag;
3450 kauth_cred_t a_cred;
3451 } */ *ap = v;
3452
3453 puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEATIME, 0);
3454 return VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), v);
3455 }
3456
3457 int
3458 puffs_vnop_fifo_write(void *v)
3459 {
3460 struct vop_write_args /* {
3461 const struct vnodeop_desc *a_desc;
3462 struct vnode *a_vp;
3463 struct uio *a_uio;
3464 int a_ioflag;
3465 kauth_cred_t a_cred;
3466 } */ *ap = v;
3467
3468 puffs_updatenode(VPTOPP(ap->a_vp), PUFFS_UPDATEMTIME, 0);
3469 return VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), v);
3470 }
3471