1 /* $NetBSD: puffs_vnops.c,v 1.140 2009/11/19 16:21:04 pooka Exp $ */
4 * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.140 2009/11/19 16:21:04 pooka Exp $");
35 #include <sys/param.h>
37 #include <sys/malloc.h>
38 #include <sys/mount.h>
39 #include <sys/namei.h>
40 #include <sys/vnode.h>
45 #include <fs/puffs/puffs_msgif.h>
46 #include <fs/puffs/puffs_sys.h>
48 #include <miscfs/fifofs/fifo.h>
49 #include <miscfs/genfs/genfs.h>
50 #include <miscfs/specfs/specdev.h>
52 int puffs_vnop_lookup(void *);
53 int puffs_vnop_create(void *);
54 int puffs_vnop_access(void *);
55 int puffs_vnop_mknod(void *);
56 int puffs_vnop_open(void *);
57 int puffs_vnop_close(void *);
58 int puffs_vnop_getattr(void *);
59 int puffs_vnop_setattr(void *);
60 int puffs_vnop_reclaim(void *);
61 int puffs_vnop_readdir(void *);
62 int puffs_vnop_poll(void *);
63 int puffs_vnop_fsync(void *);
64 int puffs_vnop_seek(void *);
65 int puffs_vnop_remove(void *);
66 int puffs_vnop_mkdir(void *);
67 int puffs_vnop_rmdir(void *);
68 int puffs_vnop_link(void *);
69 int puffs_vnop_readlink(void *);
70 int puffs_vnop_symlink(void *);
71 int puffs_vnop_rename(void *);
72 int puffs_vnop_read(void *);
73 int puffs_vnop_write(void *);
74 int puffs_vnop_fcntl(void *);
75 int puffs_vnop_ioctl(void *);
76 int puffs_vnop_inactive(void *);
77 int puffs_vnop_print(void *);
78 int puffs_vnop_pathconf(void *);
79 int puffs_vnop_advlock(void *);
80 int puffs_vnop_strategy(void *);
81 int puffs_vnop_bmap(void *);
82 int puffs_vnop_mmap(void *);
83 int puffs_vnop_getpages(void *);
84 int puffs_vnop_abortop(void *);
86 int puffs_vnop_spec_read(void *);
87 int puffs_vnop_spec_write(void *);
88 int puffs_vnop_fifo_read(void *);
89 int puffs_vnop_fifo_write(void *);
91 int puffs_vnop_checkop(void *);
93 #define puffs_vnop_lock genfs_lock
94 #define puffs_vnop_unlock genfs_unlock
95 #define puffs_vnop_islocked genfs_islocked
97 int (**puffs_vnodeop_p
)(void *);
98 const struct vnodeopv_entry_desc puffs_vnodeop_entries
[] = {
99 { &vop_default_desc
, vn_default_error
},
100 { &vop_lookup_desc
, puffs_vnop_lookup
}, /* REAL lookup */
101 { &vop_create_desc
, puffs_vnop_checkop
}, /* create */
102 { &vop_mknod_desc
, puffs_vnop_checkop
}, /* mknod */
103 { &vop_open_desc
, puffs_vnop_open
}, /* REAL open */
104 { &vop_close_desc
, puffs_vnop_checkop
}, /* close */
105 { &vop_access_desc
, puffs_vnop_access
}, /* REAL access */
106 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
107 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
108 { &vop_read_desc
, puffs_vnop_checkop
}, /* read */
109 { &vop_write_desc
, puffs_vnop_checkop
}, /* write */
110 { &vop_fsync_desc
, puffs_vnop_fsync
}, /* REAL fsync */
111 { &vop_seek_desc
, puffs_vnop_checkop
}, /* seek */
112 { &vop_remove_desc
, puffs_vnop_checkop
}, /* remove */
113 { &vop_link_desc
, puffs_vnop_checkop
}, /* link */
114 { &vop_rename_desc
, puffs_vnop_checkop
}, /* rename */
115 { &vop_mkdir_desc
, puffs_vnop_checkop
}, /* mkdir */
116 { &vop_rmdir_desc
, puffs_vnop_checkop
}, /* rmdir */
117 { &vop_symlink_desc
, puffs_vnop_checkop
}, /* symlink */
118 { &vop_readdir_desc
, puffs_vnop_checkop
}, /* readdir */
119 { &vop_readlink_desc
, puffs_vnop_checkop
}, /* readlink */
120 { &vop_getpages_desc
, puffs_vnop_checkop
}, /* getpages */
121 { &vop_putpages_desc
, genfs_putpages
}, /* REAL putpages */
122 { &vop_pathconf_desc
, puffs_vnop_checkop
}, /* pathconf */
123 { &vop_advlock_desc
, puffs_vnop_checkop
}, /* advlock */
124 { &vop_strategy_desc
, puffs_vnop_strategy
}, /* REAL strategy */
125 { &vop_revoke_desc
, genfs_revoke
}, /* REAL revoke */
126 { &vop_abortop_desc
, puffs_vnop_abortop
}, /* REAL abortop */
127 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
128 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
129 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
130 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
131 { &vop_bmap_desc
, puffs_vnop_bmap
}, /* REAL bmap */
132 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
133 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
134 { &vop_bwrite_desc
, genfs_nullop
}, /* REAL bwrite */
135 { &vop_mmap_desc
, puffs_vnop_mmap
}, /* REAL mmap */
136 { &vop_poll_desc
, puffs_vnop_poll
}, /* REAL poll */
138 { &vop_kqfilter_desc
, genfs_eopnotsupp
}, /* kqfilter XXX */
141 const struct vnodeopv_desc puffs_vnodeop_opv_desc
=
142 { &puffs_vnodeop_p
, puffs_vnodeop_entries
};
145 int (**puffs_specop_p
)(void *);
146 const struct vnodeopv_entry_desc puffs_specop_entries
[] = {
147 { &vop_default_desc
, vn_default_error
},
148 { &vop_lookup_desc
, spec_lookup
}, /* lookup, ENOTDIR */
149 { &vop_create_desc
, spec_create
}, /* genfs_badop */
150 { &vop_mknod_desc
, spec_mknod
}, /* genfs_badop */
151 { &vop_open_desc
, spec_open
}, /* spec_open */
152 { &vop_close_desc
, spec_close
}, /* spec_close */
153 { &vop_access_desc
, puffs_vnop_checkop
}, /* access */
154 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
155 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
156 { &vop_read_desc
, puffs_vnop_spec_read
}, /* update, read */
157 { &vop_write_desc
, puffs_vnop_spec_write
}, /* update, write */
158 { &vop_ioctl_desc
, spec_ioctl
}, /* spec_ioctl */
159 { &vop_fcntl_desc
, genfs_fcntl
}, /* dummy */
160 { &vop_poll_desc
, spec_poll
}, /* spec_poll */
161 { &vop_kqfilter_desc
, spec_kqfilter
}, /* spec_kqfilter */
162 { &vop_revoke_desc
, spec_revoke
}, /* genfs_revoke */
163 { &vop_mmap_desc
, spec_mmap
}, /* spec_mmap */
164 { &vop_fsync_desc
, spec_fsync
}, /* vflushbuf */
165 { &vop_seek_desc
, spec_seek
}, /* genfs_nullop */
166 { &vop_remove_desc
, spec_remove
}, /* genfs_badop */
167 { &vop_link_desc
, spec_link
}, /* genfs_badop */
168 { &vop_rename_desc
, spec_rename
}, /* genfs_badop */
169 { &vop_mkdir_desc
, spec_mkdir
}, /* genfs_badop */
170 { &vop_rmdir_desc
, spec_rmdir
}, /* genfs_badop */
171 { &vop_symlink_desc
, spec_symlink
}, /* genfs_badop */
172 { &vop_readdir_desc
, spec_readdir
}, /* genfs_badop */
173 { &vop_readlink_desc
, spec_readlink
}, /* genfs_badop */
174 { &vop_abortop_desc
, spec_abortop
}, /* genfs_badop */
175 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
176 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
177 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
178 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
179 { &vop_bmap_desc
, spec_bmap
}, /* dummy */
180 { &vop_strategy_desc
, spec_strategy
}, /* dev strategy */
181 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
182 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
183 { &vop_pathconf_desc
, spec_pathconf
}, /* pathconf */
184 { &vop_advlock_desc
, spec_advlock
}, /* lf_advlock */
185 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
186 { &vop_getpages_desc
, spec_getpages
}, /* genfs_getpages */
187 { &vop_putpages_desc
, spec_putpages
}, /* genfs_putpages */
189 { &vop_openextattr_desc
, _openextattr
}, /* openextattr */
190 { &vop_closeextattr_desc
, _closeextattr
}, /* closeextattr */
191 { &vop_getextattr_desc
, _getextattr
}, /* getextattr */
192 { &vop_setextattr_desc
, _setextattr
}, /* setextattr */
193 { &vop_listextattr_desc
, _listextattr
}, /* listextattr */
194 { &vop_deleteextattr_desc
, _deleteextattr
}, /* deleteextattr */
198 const struct vnodeopv_desc puffs_specop_opv_desc
=
199 { &puffs_specop_p
, puffs_specop_entries
};
202 int (**puffs_fifoop_p
)(void *);
203 const struct vnodeopv_entry_desc puffs_fifoop_entries
[] = {
204 { &vop_default_desc
, vn_default_error
},
205 { &vop_lookup_desc
, fifo_lookup
}, /* lookup, ENOTDIR */
206 { &vop_create_desc
, fifo_create
}, /* genfs_badop */
207 { &vop_mknod_desc
, fifo_mknod
}, /* genfs_badop */
208 { &vop_open_desc
, fifo_open
}, /* open */
209 { &vop_close_desc
, fifo_close
}, /* close */
210 { &vop_access_desc
, puffs_vnop_checkop
}, /* access */
211 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
212 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
213 { &vop_read_desc
, puffs_vnop_fifo_read
}, /* read, update */
214 { &vop_write_desc
, puffs_vnop_fifo_write
}, /* write, update */
215 { &vop_ioctl_desc
, fifo_ioctl
}, /* ioctl */
216 { &vop_fcntl_desc
, genfs_fcntl
}, /* dummy */
217 { &vop_poll_desc
, fifo_poll
}, /* poll */
218 { &vop_kqfilter_desc
, fifo_kqfilter
}, /* kqfilter */
219 { &vop_revoke_desc
, fifo_revoke
}, /* genfs_revoke */
220 { &vop_mmap_desc
, fifo_mmap
}, /* genfs_badop */
221 { &vop_fsync_desc
, fifo_fsync
}, /* genfs_nullop*/
222 { &vop_seek_desc
, fifo_seek
}, /* genfs_badop */
223 { &vop_remove_desc
, fifo_remove
}, /* genfs_badop */
224 { &vop_link_desc
, fifo_link
}, /* genfs_badop */
225 { &vop_rename_desc
, fifo_rename
}, /* genfs_badop */
226 { &vop_mkdir_desc
, fifo_mkdir
}, /* genfs_badop */
227 { &vop_rmdir_desc
, fifo_rmdir
}, /* genfs_badop */
228 { &vop_symlink_desc
, fifo_symlink
}, /* genfs_badop */
229 { &vop_readdir_desc
, fifo_readdir
}, /* genfs_badop */
230 { &vop_readlink_desc
, fifo_readlink
}, /* genfs_badop */
231 { &vop_abortop_desc
, fifo_abortop
}, /* genfs_badop */
232 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
233 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
234 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
235 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
236 { &vop_bmap_desc
, fifo_bmap
}, /* dummy */
237 { &vop_strategy_desc
, fifo_strategy
}, /* genfs_badop */
238 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
239 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
240 { &vop_pathconf_desc
, fifo_pathconf
}, /* pathconf */
241 { &vop_advlock_desc
, fifo_advlock
}, /* genfs_einval */
242 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
243 { &vop_putpages_desc
, fifo_putpages
}, /* genfs_null_putpages*/
245 { &vop_openextattr_desc
, _openextattr
}, /* openextattr */
246 { &vop_closeextattr_desc
, _closeextattr
}, /* closeextattr */
247 { &vop_getextattr_desc
, _getextattr
}, /* getextattr */
248 { &vop_setextattr_desc
, _setextattr
}, /* setextattr */
249 { &vop_listextattr_desc
, _listextattr
}, /* listextattr */
250 { &vop_deleteextattr_desc
, _deleteextattr
}, /* deleteextattr */
254 const struct vnodeopv_desc puffs_fifoop_opv_desc
=
255 { &puffs_fifoop_p
, puffs_fifoop_entries
};
258 /* "real" vnode operations */
259 int (**puffs_msgop_p
)(void *);
260 const struct vnodeopv_entry_desc puffs_msgop_entries
[] = {
261 { &vop_default_desc
, vn_default_error
},
262 { &vop_create_desc
, puffs_vnop_create
}, /* create */
263 { &vop_mknod_desc
, puffs_vnop_mknod
}, /* mknod */
264 { &vop_open_desc
, puffs_vnop_open
}, /* open */
265 { &vop_close_desc
, puffs_vnop_close
}, /* close */
266 { &vop_access_desc
, puffs_vnop_access
}, /* access */
267 { &vop_getattr_desc
, puffs_vnop_getattr
}, /* getattr */
268 { &vop_setattr_desc
, puffs_vnop_setattr
}, /* setattr */
269 { &vop_read_desc
, puffs_vnop_read
}, /* read */
270 { &vop_write_desc
, puffs_vnop_write
}, /* write */
271 { &vop_seek_desc
, puffs_vnop_seek
}, /* seek */
272 { &vop_remove_desc
, puffs_vnop_remove
}, /* remove */
273 { &vop_link_desc
, puffs_vnop_link
}, /* link */
274 { &vop_rename_desc
, puffs_vnop_rename
}, /* rename */
275 { &vop_mkdir_desc
, puffs_vnop_mkdir
}, /* mkdir */
276 { &vop_rmdir_desc
, puffs_vnop_rmdir
}, /* rmdir */
277 { &vop_symlink_desc
, puffs_vnop_symlink
}, /* symlink */
278 { &vop_readdir_desc
, puffs_vnop_readdir
}, /* readdir */
279 { &vop_readlink_desc
, puffs_vnop_readlink
}, /* readlink */
280 { &vop_print_desc
, puffs_vnop_print
}, /* print */
281 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* islocked */
282 { &vop_pathconf_desc
, puffs_vnop_pathconf
}, /* pathconf */
283 { &vop_advlock_desc
, puffs_vnop_advlock
}, /* advlock */
284 { &vop_getpages_desc
, puffs_vnop_getpages
}, /* getpages */
287 const struct vnodeopv_desc puffs_msgop_opv_desc
=
288 { &puffs_msgop_p
, puffs_msgop_entries
};
291 #define ERROUT(err) \
295 } while (/*CONSTCOND*/0)
298 * This is a generic vnode operation handler. It checks if the necessary
299 * operations for the called vnode operation are implemented by userspace
300 * and either returns a dummy return value or proceeds to call the real
301 * vnode operation from puffs_msgop_v.
303 * XXX: this should described elsewhere and autogenerated, the complexity
304 * of the vnode operations vectors and their interrelationships is also
305 * getting a bit out of hand. Another problem is that we need this same
306 * information in the fs server code, so keeping the two in sync manually
307 * is not a viable (long term) plan.
310 /* not supported, handle locking protocol */
311 #define CHECKOP_NOTSUPP(op) \
312 case VOP_##op##_DESCOFFSET: \
313 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
314 return genfs_eopnotsupp(v); \
317 /* always succeed, no locking */
318 #define CHECKOP_SUCCESS(op) \
319 case VOP_##op##_DESCOFFSET: \
320 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
325 puffs_vnop_checkop(void *v
)
327 struct vop_generic_args
/* {
328 struct vnodeop_desc *a_desc;
329 spooky mystery contents;
331 struct vnodeop_desc
*desc
= ap
->a_desc
;
332 struct puffs_mount
*pmp
;
336 offset
= ap
->a_desc
->vdesc_vp_offsets
[0];
338 if (offset
== VDESC_NO_OFFSET
)
339 panic("puffs_checkop: no vnode, why did you call me?");
341 vp
= *VOPARG_OFFSETTO(struct vnode
**, offset
, ap
);
342 pmp
= MPTOPUFFSMP(vp
->v_mount
);
344 DPRINTF_VERBOSE(("checkop call %s (%d), vp %p\n",
345 ap
->a_desc
->vdesc_name
, ap
->a_desc
->vdesc_offset
, vp
));
348 switch (desc
->vdesc_offset
) {
349 CHECKOP_NOTSUPP(CREATE
);
350 CHECKOP_NOTSUPP(MKNOD
);
351 CHECKOP_NOTSUPP(GETATTR
);
352 CHECKOP_NOTSUPP(SETATTR
);
353 CHECKOP_NOTSUPP(READ
);
354 CHECKOP_NOTSUPP(WRITE
);
355 CHECKOP_NOTSUPP(FCNTL
);
356 CHECKOP_NOTSUPP(IOCTL
);
357 CHECKOP_NOTSUPP(REMOVE
);
358 CHECKOP_NOTSUPP(LINK
);
359 CHECKOP_NOTSUPP(RENAME
);
360 CHECKOP_NOTSUPP(MKDIR
);
361 CHECKOP_NOTSUPP(RMDIR
);
362 CHECKOP_NOTSUPP(SYMLINK
);
363 CHECKOP_NOTSUPP(READDIR
);
364 CHECKOP_NOTSUPP(READLINK
);
365 CHECKOP_NOTSUPP(PRINT
);
366 CHECKOP_NOTSUPP(PATHCONF
);
367 CHECKOP_NOTSUPP(ADVLOCK
);
369 CHECKOP_SUCCESS(ACCESS
);
370 CHECKOP_SUCCESS(CLOSE
);
371 CHECKOP_SUCCESS(SEEK
);
373 case VOP_GETPAGES_DESCOFFSET
:
374 if (!EXISTSOP(pmp
, READ
))
375 return genfs_eopnotsupp(v
);
379 panic("puffs_checkop: unhandled vnop %d",
384 rv
= VOCALL(puffs_msgop_p
, ap
->a_desc
->vdesc_offset
, v
);
386 DPRINTF_VERBOSE(("checkop return %s (%d), vp %p: %d\n",
387 ap
->a_desc
->vdesc_name
, ap
->a_desc
->vdesc_offset
, vp
, rv
));
392 static int callremove(struct puffs_mount
*, puffs_cookie_t
, puffs_cookie_t
,
393 struct componentname
*);
394 static int callrmdir(struct puffs_mount
*, puffs_cookie_t
, puffs_cookie_t
,
395 struct componentname
*);
396 static void callinactive(struct puffs_mount
*, puffs_cookie_t
, int);
397 static void callreclaim(struct puffs_mount
*, puffs_cookie_t
);
398 static int flushvncache(struct vnode
*, off_t
, off_t
, bool);
401 #define PUFFS_ABORT_LOOKUP 1
402 #define PUFFS_ABORT_CREATE 2
403 #define PUFFS_ABORT_MKNOD 3
404 #define PUFFS_ABORT_MKDIR 4
405 #define PUFFS_ABORT_SYMLINK 5
408 * Press the pani^Wabort button! Kernel resource allocation failed.
411 puffs_abortbutton(struct puffs_mount
*pmp
, int what
,
412 puffs_cookie_t dck
, puffs_cookie_t ck
, struct componentname
*cnp
)
416 case PUFFS_ABORT_CREATE
:
417 case PUFFS_ABORT_MKNOD
:
418 case PUFFS_ABORT_SYMLINK
:
419 callremove(pmp
, dck
, ck
, cnp
);
421 case PUFFS_ABORT_MKDIR
:
422 callrmdir(pmp
, dck
, ck
, cnp
);
426 callinactive(pmp
, ck
, 0);
427 callreclaim(pmp
, ck
);
431 * Begin vnode operations.
433 * A word from the keymaster about locks: generally we don't want
434 * to use the vnode locks at all: it creates an ugly dependency between
435 * the userlandia file server and the kernel. But we'll play along with
436 * the kernel vnode locks for now. However, even currently we attempt
437 * to release locks as early as possible. This is possible for some
438 * operations which a) don't need a locked vnode after the userspace op
439 * and b) return with the vnode unlocked. Theoretically we could
440 * unlock-do op-lock for others and order the graph in userspace, but I
441 * don't want to think of the consequences for the time being.
445 puffs_vnop_lookup(void *v
)
447 struct vop_lookup_args
/* {
448 const struct vnodeop_desc *a_desc;
450 struct vnode **a_vpp;
451 struct componentname *a_cnp;
453 PUFFS_MSG_VARS(vn
, lookup
);
454 struct puffs_mount
*pmp
;
455 struct componentname
*cnp
;
456 struct vnode
*vp
, *dvp
;
457 struct puffs_node
*dpn
;
461 pmp
= MPTOPUFFSMP(ap
->a_dvp
->v_mount
);
466 /* r/o fs? we check create later to handle EEXIST */
467 if ((cnp
->cn_flags
& ISLASTCN
)
468 && (dvp
->v_mount
->mnt_flag
& MNT_RDONLY
)
469 && (cnp
->cn_nameiop
== DELETE
|| cnp
->cn_nameiop
== RENAME
))
472 isdot
= cnp
->cn_namelen
== 1 && *cnp
->cn_nameptr
== '.';
474 DPRINTF(("puffs_lookup: \"%s\", parent vnode %p, op: %x\n",
475 cnp
->cn_nameptr
, dvp
, cnp
->cn_nameiop
));
478 * Check if someone fed it into the cache
480 if (PUFFS_USE_NAMECACHE(pmp
)) {
481 error
= cache_lookup(dvp
, ap
->a_vpp
, cnp
);
494 PUFFS_MSG_ALLOC(vn
, lookup
);
495 puffs_makecn(&lookup_msg
->pvnr_cn
, &lookup_msg
->pvnr_cn_cred
,
496 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
498 if (cnp
->cn_flags
& ISDOTDOT
)
501 puffs_msg_setinfo(park_lookup
, PUFFSOP_VN
,
502 PUFFS_VN_LOOKUP
, VPTOPNC(dvp
));
503 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_lookup
, dvp
->v_data
, NULL
, error
);
504 DPRINTF(("puffs_lookup: return of the userspace, part %d\n", error
));
507 * In case of error, there is no new vnode to play with, so be
508 * happy with the NULL value given to vpp in the beginning.
509 * Also, check if this really was an error or the target was not
510 * present. Either treat it as a non-error for CREATE/RENAME or
511 * enter the component into the negative name cache (if desired).
514 error
= checkerr(pmp
, error
, __func__
);
515 if (error
== ENOENT
) {
516 /* don't allow to create files on r/o fs */
517 if ((dvp
->v_mount
->mnt_flag
& MNT_RDONLY
)
518 && cnp
->cn_nameiop
== CREATE
) {
521 /* adjust values if we are creating */
522 } else if ((cnp
->cn_flags
& ISLASTCN
)
523 && (cnp
->cn_nameiop
== CREATE
524 || cnp
->cn_nameiop
== RENAME
)) {
525 cnp
->cn_flags
|= SAVENAME
;
528 /* save negative cache entry */
530 if ((cnp
->cn_flags
& MAKEENTRY
)
531 && PUFFS_USE_NAMECACHE(pmp
))
532 cache_enter(dvp
, NULL
, cnp
);
539 * Check that we don't get our parent node back, that would cause
540 * a pretty obvious deadlock.
543 if (lookup_msg
->pvnr_newnode
== dpn
->pn_cookie
) {
544 puffs_senderr(pmp
, PUFFS_ERR_LOOKUP
, EINVAL
,
545 "lookup produced parent cookie", lookup_msg
->pvnr_newnode
);
550 error
= puffs_cookie2vnode(pmp
, lookup_msg
->pvnr_newnode
, 1, 1, &vp
);
551 if (error
== PUFFS_NOSUCHCOOKIE
) {
552 error
= puffs_getvnode(dvp
->v_mount
,
553 lookup_msg
->pvnr_newnode
, lookup_msg
->pvnr_vtype
,
554 lookup_msg
->pvnr_size
, lookup_msg
->pvnr_rdev
, &vp
);
556 puffs_abortbutton(pmp
, PUFFS_ABORT_LOOKUP
, VPTOPNC(dvp
),
557 lookup_msg
->pvnr_newnode
, ap
->a_cnp
);
560 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
562 puffs_abortbutton(pmp
, PUFFS_ABORT_LOOKUP
, VPTOPNC(dvp
),
563 lookup_msg
->pvnr_newnode
, ap
->a_cnp
);
569 if ((cnp
->cn_flags
& MAKEENTRY
) != 0 && PUFFS_USE_NAMECACHE(pmp
))
570 cache_enter(dvp
, vp
, cnp
);
573 if ((lookup_msg
->pvnr_cn
.pkcn_flags
& REQUIREDIR
) == 0)
574 cnp
->cn_flags
&= ~REQUIREDIR
;
575 if (lookup_msg
->pvnr_cn
.pkcn_consume
)
576 cnp
->cn_consume
= MIN(lookup_msg
->pvnr_cn
.pkcn_consume
,
577 strlen(cnp
->cn_nameptr
) - cnp
->cn_namelen
);
580 * We need the name in remove and rmdir (well, rename too, but
581 * SAVESTART takes care of that)
583 if (cnp
->cn_nameiop
== DELETE
)
584 cnp
->cn_flags
|= SAVENAME
;
587 if (cnp
->cn_flags
& ISDOTDOT
)
588 vn_lock(dvp
, LK_EXCLUSIVE
| LK_RETRY
);
590 DPRINTF(("puffs_lookup: returning %d %p\n", error
, *ap
->a_vpp
));
591 PUFFS_MSG_RELEASE(lookup
);
595 #define REFPN_AND_UNLOCKVP(a, b) \
597 mutex_enter(&b->pn_mtx); \
598 puffs_referencenode(b); \
599 mutex_exit(&b->pn_mtx); \
601 } while (/*CONSTCOND*/0)
605 mutex_enter(&b->pn_mtx); \
606 puffs_referencenode(b); \
607 mutex_exit(&b->pn_mtx); \
608 } while (/*CONSTCOND*/0)
610 #define RELEPN_AND_VP(a, b) \
612 puffs_releasenode(b); \
614 } while (/*CONSTCOND*/0)
617 puffs_vnop_create(void *v
)
619 struct vop_create_args
/* {
620 const struct vnodeop_desc *a_desc;
622 struct vnode **a_vpp;
623 struct componentname *a_cnp;
626 PUFFS_MSG_VARS(vn
, create
);
627 struct vnode
*dvp
= ap
->a_dvp
;
628 struct puffs_node
*dpn
= VPTOPP(dvp
);
629 struct componentname
*cnp
= ap
->a_cnp
;
630 struct mount
*mp
= dvp
->v_mount
;
631 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
634 DPRINTF(("puffs_create: dvp %p, cnp: %s\n",
635 dvp
, ap
->a_cnp
->cn_nameptr
));
637 PUFFS_MSG_ALLOC(vn
, create
);
638 puffs_makecn(&create_msg
->pvnr_cn
, &create_msg
->pvnr_cn_cred
,
639 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
640 create_msg
->pvnr_va
= *ap
->a_vap
;
641 puffs_msg_setinfo(park_create
, PUFFSOP_VN
,
642 PUFFS_VN_CREATE
, VPTOPNC(dvp
));
643 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_create
, dvp
->v_data
, NULL
, error
);
645 error
= checkerr(pmp
, error
, __func__
);
649 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
650 create_msg
->pvnr_newnode
, cnp
, ap
->a_vap
->va_type
, 0);
652 puffs_abortbutton(pmp
, PUFFS_ABORT_CREATE
, dpn
->pn_cookie
,
653 create_msg
->pvnr_newnode
, cnp
);
657 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
658 PNBUF_PUT(cnp
->cn_pnbuf
);
660 DPRINTF(("puffs_create: return %d\n", error
));
661 PUFFS_MSG_RELEASE(create
);
666 puffs_vnop_mknod(void *v
)
668 struct vop_mknod_args
/* {
669 const struct vnodeop_desc *a_desc;
671 struct vnode **a_vpp;
672 struct componentname *a_cnp;
675 PUFFS_MSG_VARS(vn
, mknod
);
676 struct vnode
*dvp
= ap
->a_dvp
;
677 struct puffs_node
*dpn
= VPTOPP(dvp
);
678 struct componentname
*cnp
= ap
->a_cnp
;
679 struct mount
*mp
= dvp
->v_mount
;
680 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
683 PUFFS_MSG_ALLOC(vn
, mknod
);
684 puffs_makecn(&mknod_msg
->pvnr_cn
, &mknod_msg
->pvnr_cn_cred
,
685 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
686 mknod_msg
->pvnr_va
= *ap
->a_vap
;
687 puffs_msg_setinfo(park_mknod
, PUFFSOP_VN
,
688 PUFFS_VN_MKNOD
, VPTOPNC(dvp
));
690 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mknod
, dvp
->v_data
, NULL
, error
);
692 error
= checkerr(pmp
, error
, __func__
);
696 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
697 mknod_msg
->pvnr_newnode
, cnp
, ap
->a_vap
->va_type
,
700 puffs_abortbutton(pmp
, PUFFS_ABORT_MKNOD
, dpn
->pn_cookie
,
701 mknod_msg
->pvnr_newnode
, cnp
);
705 PUFFS_MSG_RELEASE(mknod
);
706 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
707 PNBUF_PUT(cnp
->cn_pnbuf
);
712 puffs_vnop_open(void *v
)
714 struct vop_open_args
/* {
715 const struct vnodeop_desc *a_desc;
720 PUFFS_MSG_VARS(vn
, open
);
721 struct vnode
*vp
= ap
->a_vp
;
722 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
723 int mode
= ap
->a_mode
;
726 DPRINTF(("puffs_open: vp %p, mode 0x%x\n", vp
, mode
));
728 if (vp
->v_type
== VREG
&& mode
& FWRITE
&& !EXISTSOP(pmp
, WRITE
))
731 if (!EXISTSOP(pmp
, OPEN
))
734 PUFFS_MSG_ALLOC(vn
, open
);
735 open_msg
->pvnr_mode
= mode
;
736 puffs_credcvt(&open_msg
->pvnr_cred
, ap
->a_cred
);
737 puffs_msg_setinfo(park_open
, PUFFSOP_VN
,
738 PUFFS_VN_OPEN
, VPTOPNC(vp
));
740 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_open
, vp
->v_data
, NULL
, error
);
741 error
= checkerr(pmp
, error
, __func__
);
744 DPRINTF(("puffs_open: returning %d\n", error
));
745 PUFFS_MSG_RELEASE(open
);
750 puffs_vnop_close(void *v
)
752 struct vop_close_args
/* {
753 const struct vnodeop_desc *a_desc;
758 PUFFS_MSG_VARS(vn
, close
);
759 struct vnode
*vp
= ap
->a_vp
;
760 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
762 PUFFS_MSG_ALLOC(vn
, close
);
763 puffs_msg_setfaf(park_close
);
764 close_msg
->pvnr_fflag
= ap
->a_fflag
;
765 puffs_credcvt(&close_msg
->pvnr_cred
, ap
->a_cred
);
766 puffs_msg_setinfo(park_close
, PUFFSOP_VN
,
767 PUFFS_VN_CLOSE
, VPTOPNC(vp
));
769 puffs_msg_enqueue(pmp
, park_close
);
770 PUFFS_MSG_RELEASE(close
);
775 puffs_vnop_access(void *v
)
777 struct vop_access_args
/* {
778 const struct vnodeop_desc *a_desc;
783 PUFFS_MSG_VARS(vn
, access
);
784 struct vnode
*vp
= ap
->a_vp
;
785 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
786 int mode
= ap
->a_mode
;
790 switch (vp
->v_type
) {
794 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
795 || !EXISTSOP(pmp
, WRITE
))
803 if (!EXISTSOP(pmp
, ACCESS
))
806 PUFFS_MSG_ALLOC(vn
, access
);
807 access_msg
->pvnr_mode
= ap
->a_mode
;
808 puffs_credcvt(&access_msg
->pvnr_cred
, ap
->a_cred
);
809 puffs_msg_setinfo(park_access
, PUFFSOP_VN
,
810 PUFFS_VN_ACCESS
, VPTOPNC(vp
));
812 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_access
, vp
->v_data
, NULL
, error
);
813 error
= checkerr(pmp
, error
, __func__
);
814 PUFFS_MSG_RELEASE(access
);
820 puffs_vnop_getattr(void *v
)
822 struct vop_getattr_args
/* {
823 const struct vnodeop_desc *a_desc;
828 PUFFS_MSG_VARS(vn
, getattr
);
829 struct vnode
*vp
= ap
->a_vp
;
830 struct mount
*mp
= vp
->v_mount
;
831 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
832 struct vattr
*vap
, *rvap
;
833 struct puffs_node
*pn
;
838 PUFFS_MSG_ALLOC(vn
, getattr
);
839 vattr_null(&getattr_msg
->pvnr_va
);
840 puffs_credcvt(&getattr_msg
->pvnr_cred
, ap
->a_cred
);
841 puffs_msg_setinfo(park_getattr
, PUFFSOP_VN
,
842 PUFFS_VN_GETATTR
, VPTOPNC(vp
));
844 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_getattr
, vp
->v_data
, NULL
, error
);
845 error
= checkerr(pmp
, error
, __func__
);
849 rvap
= &getattr_msg
->pvnr_va
;
851 * Don't listen to the file server regarding special device
852 * size info, the file server doesn't know anything about them.
854 if (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
)
855 rvap
->va_size
= vp
->v_size
;
857 /* Ditto for blocksize (ufs comment: this doesn't belong here) */
858 if (vp
->v_type
== VBLK
)
859 rvap
->va_blocksize
= BLKDEV_IOSIZE
;
860 else if (vp
->v_type
== VCHR
)
861 rvap
->va_blocksize
= MAXBSIZE
;
863 (void) memcpy(vap
, rvap
, sizeof(struct vattr
));
864 vap
->va_fsid
= mp
->mnt_stat
.f_fsidx
.__fsid_val
[0];
867 if (pn
->pn_stat
& PNODE_METACACHE_ATIME
)
868 vap
->va_atime
= pn
->pn_mc_atime
;
869 if (pn
->pn_stat
& PNODE_METACACHE_CTIME
)
870 vap
->va_ctime
= pn
->pn_mc_ctime
;
871 if (pn
->pn_stat
& PNODE_METACACHE_MTIME
)
872 vap
->va_mtime
= pn
->pn_mc_mtime
;
873 if (pn
->pn_stat
& PNODE_METACACHE_SIZE
) {
874 vap
->va_size
= pn
->pn_mc_size
;
876 if (rvap
->va_size
!= VNOVAL
877 && vp
->v_type
!= VBLK
&& vp
->v_type
!= VCHR
) {
878 uvm_vnp_setsize(vp
, rvap
->va_size
);
879 pn
->pn_serversize
= rvap
->va_size
;
884 PUFFS_MSG_RELEASE(getattr
);
888 #define SETATTR_CHSIZE 0x01
889 #define SETATTR_ASYNC 0x02
891 dosetattr(struct vnode
*vp
, struct vattr
*vap
, kauth_cred_t cred
, int flags
)
893 PUFFS_MSG_VARS(vn
, setattr
);
894 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
895 struct puffs_node
*pn
= vp
->v_data
;
898 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
) &&
899 (vap
->va_uid
!= (uid_t
)VNOVAL
|| vap
->va_gid
!= (gid_t
)VNOVAL
900 || vap
->va_atime
.tv_sec
!= VNOVAL
|| vap
->va_mtime
.tv_sec
!= VNOVAL
901 || vap
->va_mode
!= (mode_t
)VNOVAL
))
904 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
905 && vp
->v_type
== VREG
&& vap
->va_size
!= VNOVAL
)
909 * Flush metacache first. If we are called with some explicit
910 * parameters, treat them as information overriding metacache
913 if (pn
->pn_stat
& PNODE_METACACHE_MASK
) {
914 if ((pn
->pn_stat
& PNODE_METACACHE_ATIME
)
915 && vap
->va_atime
.tv_sec
== VNOVAL
)
916 vap
->va_atime
= pn
->pn_mc_atime
;
917 if ((pn
->pn_stat
& PNODE_METACACHE_CTIME
)
918 && vap
->va_ctime
.tv_sec
== VNOVAL
)
919 vap
->va_ctime
= pn
->pn_mc_ctime
;
920 if ((pn
->pn_stat
& PNODE_METACACHE_MTIME
)
921 && vap
->va_mtime
.tv_sec
== VNOVAL
)
922 vap
->va_mtime
= pn
->pn_mc_mtime
;
923 if ((pn
->pn_stat
& PNODE_METACACHE_SIZE
)
924 && vap
->va_size
== VNOVAL
)
925 vap
->va_size
= pn
->pn_mc_size
;
927 pn
->pn_stat
&= ~PNODE_METACACHE_MASK
;
930 PUFFS_MSG_ALLOC(vn
, setattr
);
931 (void)memcpy(&setattr_msg
->pvnr_va
, vap
, sizeof(struct vattr
));
932 puffs_credcvt(&setattr_msg
->pvnr_cred
, cred
);
933 puffs_msg_setinfo(park_setattr
, PUFFSOP_VN
,
934 PUFFS_VN_SETATTR
, VPTOPNC(vp
));
935 if (flags
& SETATTR_ASYNC
)
936 puffs_msg_setfaf(park_setattr
);
938 puffs_msg_enqueue(pmp
, park_setattr
);
939 if ((flags
& SETATTR_ASYNC
) == 0)
940 error
= puffs_msg_wait2(pmp
, park_setattr
, vp
->v_data
, NULL
);
941 PUFFS_MSG_RELEASE(setattr
);
942 if ((flags
& SETATTR_ASYNC
) == 0) {
943 error
= checkerr(pmp
, error
, __func__
);
950 if (vap
->va_size
!= VNOVAL
) {
951 pn
->pn_serversize
= vap
->va_size
;
952 if (flags
& SETATTR_CHSIZE
)
953 uvm_vnp_setsize(vp
, vap
->va_size
);
960 puffs_vnop_setattr(void *v
)
962 struct vop_getattr_args
/* {
963 const struct vnodeop_desc *a_desc;
969 return dosetattr(ap
->a_vp
, ap
->a_vap
, ap
->a_cred
, SETATTR_CHSIZE
);
973 doinact(struct puffs_mount
*pmp
, int iaflag
)
976 if (EXISTSOP(pmp
, INACTIVE
))
977 if (pmp
->pmp_flags
& PUFFS_KFLAG_IAONDEMAND
)
978 if (iaflag
|| ALLOPS(pmp
))
989 callinactive(struct puffs_mount
*pmp
, puffs_cookie_t ck
, int iaflag
)
992 PUFFS_MSG_VARS(vn
, inactive
);
994 if (doinact(pmp
, iaflag
)) {
995 PUFFS_MSG_ALLOC(vn
, inactive
);
996 puffs_msg_setinfo(park_inactive
, PUFFSOP_VN
,
997 PUFFS_VN_INACTIVE
, ck
);
999 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_inactive
, error
);
1000 PUFFS_MSG_RELEASE(inactive
);
1004 /* XXX: callinactive can't setback */
1006 puffs_vnop_inactive(void *v
)
1008 struct vop_inactive_args
/* {
1009 const struct vnodeop_desc *a_desc;
1012 PUFFS_MSG_VARS(vn
, inactive
);
1013 struct vnode
*vp
= ap
->a_vp
;
1014 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1015 struct puffs_node
*pnode
;
1020 if (doinact(pmp
, pnode
->pn_stat
& PNODE_DOINACT
)) {
1021 flushvncache(vp
, 0, 0, false);
1022 PUFFS_MSG_ALLOC(vn
, inactive
);
1023 puffs_msg_setinfo(park_inactive
, PUFFSOP_VN
,
1024 PUFFS_VN_INACTIVE
, VPTOPNC(vp
));
1026 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_inactive
, vp
->v_data
,
1028 PUFFS_MSG_RELEASE(inactive
);
1030 pnode
->pn_stat
&= ~PNODE_DOINACT
;
1033 * file server thinks it's gone? then don't be afraid care,
1034 * node's life was already all it would ever be
1036 if (pnode
->pn_stat
& PNODE_NOREFS
) {
1037 pnode
->pn_stat
|= PNODE_DYING
;
1038 *ap
->a_recycle
= true;
1047 callreclaim(struct puffs_mount
*pmp
, puffs_cookie_t ck
)
1049 PUFFS_MSG_VARS(vn
, reclaim
);
1051 if (!EXISTSOP(pmp
, RECLAIM
))
1054 PUFFS_MSG_ALLOC(vn
, reclaim
);
1055 puffs_msg_setfaf(park_reclaim
);
1056 puffs_msg_setinfo(park_reclaim
, PUFFSOP_VN
, PUFFS_VN_RECLAIM
, ck
);
1058 puffs_msg_enqueue(pmp
, park_reclaim
);
1059 PUFFS_MSG_RELEASE(reclaim
);
1063 * always FAF, we don't really care if the server wants to fail to
1064 * reclaim the node or not
1067 puffs_vnop_reclaim(void *v
)
1069 struct vop_reclaim_args
/* {
1070 const struct vnodeop_desc *a_desc;
1073 struct vnode
*vp
= ap
->a_vp
;
1074 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1075 struct puffs_node
*pnode
= vp
->v_data
;
1076 bool notifyserver
= true;
1079 * first things first: check if someone is trying to reclaim the
1080 * root vnode. do not allow that to travel to userspace.
1081 * Note that we don't need to take the lock similarly to
1082 * puffs_root(), since there is only one of us.
1084 if (vp
->v_vflag
& VV_ROOT
) {
1085 mutex_enter(&pmp
->pmp_lock
);
1086 KASSERT(pmp
->pmp_root
!= NULL
);
1087 pmp
->pmp_root
= NULL
;
1088 mutex_exit(&pmp
->pmp_lock
);
1089 notifyserver
= false;
1093 * purge info from kernel before issueing FAF, since we
1094 * don't really know when we'll get around to it after
1095 * that and someone might race us into node creation
1097 mutex_enter(&pmp
->pmp_lock
);
1098 LIST_REMOVE(pnode
, pn_hashent
);
1099 mutex_exit(&pmp
->pmp_lock
);
1100 if (PUFFS_USE_NAMECACHE(pmp
))
1104 callreclaim(MPTOPUFFSMP(vp
->v_mount
), VPTOPNC(vp
));
1111 #define CSIZE sizeof(**ap->a_cookies)
1113 puffs_vnop_readdir(void *v
)
1115 struct vop_readdir_args
/* {
1116 const struct vnodeop_desc *a_desc;
1119 kauth_cred_t a_cred;
1124 PUFFS_MSG_VARS(vn
, readdir
);
1125 struct vnode
*vp
= ap
->a_vp
;
1126 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1127 size_t argsize
, tomove
, cookiemem
, cookiesmax
;
1128 struct uio
*uio
= ap
->a_uio
;
1129 size_t howmuch
, resid
;
1133 * ok, so we need: resid + cookiemem = maxreq
1134 * => resid + cookiesize * (resid/minsize) = maxreq
1135 * => resid + cookiesize/minsize * resid = maxreq
1136 * => (cookiesize/minsize + 1) * resid = maxreq
1137 * => resid = maxreq / (cookiesize/minsize + 1)
1139 * Since cookiesize <= minsize and we're not very big on floats,
1140 * we approximate that to be 1. Therefore:
1142 * resid = maxreq / 2;
1144 * Well, at least we didn't have to use differential equations
1145 * or the Gram-Schmidt process.
1147 * (yes, I'm very afraid of this)
1149 KASSERT(CSIZE
<= _DIRENT_MINSIZE((struct dirent
*)0));
1151 if (ap
->a_cookies
) {
1152 KASSERT(ap
->a_ncookies
!= NULL
);
1153 if (pmp
->pmp_args
.pa_fhsize
== 0)
1155 resid
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
) / 2;
1156 cookiesmax
= resid
/_DIRENT_MINSIZE((struct dirent
*)0);
1157 cookiemem
= ALIGN(cookiesmax
*CSIZE
); /* play safe */
1159 resid
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
1164 argsize
= sizeof(struct puffs_vnmsg_readdir
);
1165 tomove
= resid
+ cookiemem
;
1166 puffs_msgmem_alloc(argsize
+ tomove
, &park_readdir
,
1167 (void *)&readdir_msg
, 1);
1169 puffs_credcvt(&readdir_msg
->pvnr_cred
, ap
->a_cred
);
1170 readdir_msg
->pvnr_offset
= uio
->uio_offset
;
1171 readdir_msg
->pvnr_resid
= resid
;
1172 readdir_msg
->pvnr_ncookies
= cookiesmax
;
1173 readdir_msg
->pvnr_eofflag
= 0;
1174 readdir_msg
->pvnr_dentoff
= cookiemem
;
1175 puffs_msg_setinfo(park_readdir
, PUFFSOP_VN
,
1176 PUFFS_VN_READDIR
, VPTOPNC(vp
));
1177 puffs_msg_setdelta(park_readdir
, tomove
);
1179 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_readdir
, vp
->v_data
, NULL
, error
);
1180 error
= checkerr(pmp
, error
, __func__
);
1184 /* userspace is cheating? */
1185 if (readdir_msg
->pvnr_resid
> resid
) {
1186 puffs_senderr(pmp
, PUFFS_ERR_READDIR
, E2BIG
,
1187 "resid grew", VPTOPNC(vp
));
1190 if (readdir_msg
->pvnr_ncookies
> cookiesmax
) {
1191 puffs_senderr(pmp
, PUFFS_ERR_READDIR
, E2BIG
,
1192 "too many cookies", VPTOPNC(vp
));
1197 if (readdir_msg
->pvnr_eofflag
)
1200 /* bouncy-wouncy with the directory data */
1201 howmuch
= resid
- readdir_msg
->pvnr_resid
;
1203 /* force eof if no data was returned (getcwd() needs this) */
1209 error
= uiomove(readdir_msg
->pvnr_data
+ cookiemem
, howmuch
, uio
);
1213 /* provide cookies to caller if so desired */
1214 if (ap
->a_cookies
) {
1215 *ap
->a_cookies
= malloc(readdir_msg
->pvnr_ncookies
*CSIZE
,
1217 *ap
->a_ncookies
= readdir_msg
->pvnr_ncookies
;
1218 memcpy(*ap
->a_cookies
, readdir_msg
->pvnr_data
,
1219 *ap
->a_ncookies
*CSIZE
);
1222 /* next readdir starts here */
1223 uio
->uio_offset
= readdir_msg
->pvnr_offset
;
1226 puffs_msgmem_release(park_readdir
);
1232 * poll works by consuming the bitmask in pn_revents. If there are
1233 * events available, poll returns immediately. If not, it issues a
1234 * poll to userspace, selrecords itself and returns with no available
1235 * events. When the file server returns, it executes puffs_parkdone_poll(),
1236 * where available events are added to the bitmask. selnotify() is
1237 * then also executed by that function causing us to enter here again
1238 * and hopefully find the missing bits (unless someone got them first,
1239 * in which case it starts all over again).
1242 puffs_vnop_poll(void *v
)
1244 struct vop_poll_args
/* {
1245 const struct vnodeop_desc *a_desc;
1249 PUFFS_MSG_VARS(vn
, poll
);
1250 struct vnode
*vp
= ap
->a_vp
;
1251 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1252 struct puffs_node
*pn
= vp
->v_data
;
1255 if (EXISTSOP(pmp
, POLL
)) {
1256 mutex_enter(&pn
->pn_mtx
);
1257 events
= pn
->pn_revents
& ap
->a_events
;
1258 if (events
& ap
->a_events
) {
1259 pn
->pn_revents
&= ~ap
->a_events
;
1260 mutex_exit(&pn
->pn_mtx
);
1264 puffs_referencenode(pn
);
1265 mutex_exit(&pn
->pn_mtx
);
1267 PUFFS_MSG_ALLOC(vn
, poll
);
1268 poll_msg
->pvnr_events
= ap
->a_events
;
1269 puffs_msg_setinfo(park_poll
, PUFFSOP_VN
,
1270 PUFFS_VN_POLL
, VPTOPNC(vp
));
1271 puffs_msg_setcall(park_poll
, puffs_parkdone_poll
, pn
);
1272 selrecord(curlwp
, &pn
->pn_sel
);
1274 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_poll
, vp
->v_data
,
1276 PUFFS_MSG_RELEASE(poll
);
1281 return genfs_poll(v
);
1286 flushvncache(struct vnode
*vp
, off_t offlo
, off_t offhi
, bool wait
)
1288 struct puffs_node
*pn
= VPTOPP(vp
);
1292 /* flush out information from our metacache, see vop_setattr */
1293 if (pn
->pn_stat
& PNODE_METACACHE_MASK
1294 && (pn
->pn_stat
& PNODE_DYING
) == 0) {
1296 error
= dosetattr(vp
, &va
, FSCRED
,
1297 SETATTR_CHSIZE
| (wait
? 0 : SETATTR_ASYNC
));
1303 * flush pages to avoid being overly dirty
1305 pflags
= PGO_CLEANIT
;
1307 pflags
|= PGO_SYNCIO
;
1308 mutex_enter(&vp
->v_interlock
);
1309 return VOP_PUTPAGES(vp
, trunc_page(offlo
), round_page(offhi
), pflags
);
1313 puffs_vnop_fsync(void *v
)
1315 struct vop_fsync_args
/* {
1316 const struct vnodeop_desc *a_desc;
1318 kauth_cred_t a_cred;
1323 PUFFS_MSG_VARS(vn
, fsync
);
1324 struct vnode
*vp
= ap
->a_vp
;
1325 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1326 struct puffs_node
*pn
= VPTOPP(vp
);
1329 error
= flushvncache(vp
, ap
->a_offlo
, ap
->a_offhi
,
1330 (ap
->a_flags
& FSYNC_WAIT
) == FSYNC_WAIT
);
1335 * HELLO! We exit already here if the user server does not
1336 * support fsync OR if we should call fsync for a node which
1337 * has references neither in the kernel or the fs server.
1338 * Otherwise we continue to issue fsync() forward.
1340 if (!EXISTSOP(pmp
, FSYNC
) || (pn
->pn_stat
& PNODE_DYING
))
1343 dofaf
= (ap
->a_flags
& FSYNC_WAIT
) == 0 || ap
->a_flags
== FSYNC_LAZY
;
1345 * We abuse VXLOCK to mean "vnode is going to die", so we issue
1346 * only FAFs for those. Otherwise there's a danger of deadlock,
1347 * since the execution context here might be the user server
1348 * doing some operation on another fs, which in turn caused a
1349 * vnode to be reclaimed from the freelist for this fs.
1352 mutex_enter(&vp
->v_interlock
);
1353 if (vp
->v_iflag
& VI_XLOCK
)
1355 mutex_exit(&vp
->v_interlock
);
1358 PUFFS_MSG_ALLOC(vn
, fsync
);
1360 puffs_msg_setfaf(park_fsync
);
1362 puffs_credcvt(&fsync_msg
->pvnr_cred
, ap
->a_cred
);
1363 fsync_msg
->pvnr_flags
= ap
->a_flags
;
1364 fsync_msg
->pvnr_offlo
= ap
->a_offlo
;
1365 fsync_msg
->pvnr_offhi
= ap
->a_offhi
;
1366 puffs_msg_setinfo(park_fsync
, PUFFSOP_VN
,
1367 PUFFS_VN_FSYNC
, VPTOPNC(vp
));
1369 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_fsync
, vp
->v_data
, NULL
, error
);
1370 PUFFS_MSG_RELEASE(fsync
);
1372 error
= checkerr(pmp
, error
, __func__
);
1378 puffs_vnop_seek(void *v
)
1380 struct vop_seek_args
/* {
1381 const struct vnodeop_desc *a_desc;
1385 kauth_cred_t a_cred;
1387 PUFFS_MSG_VARS(vn
, seek
);
1388 struct vnode
*vp
= ap
->a_vp
;
1389 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1392 PUFFS_MSG_ALLOC(vn
, seek
);
1393 seek_msg
->pvnr_oldoff
= ap
->a_oldoff
;
1394 seek_msg
->pvnr_newoff
= ap
->a_newoff
;
1395 puffs_credcvt(&seek_msg
->pvnr_cred
, ap
->a_cred
);
1396 puffs_msg_setinfo(park_seek
, PUFFSOP_VN
,
1397 PUFFS_VN_SEEK
, VPTOPNC(vp
));
1399 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_seek
, vp
->v_data
, NULL
, error
);
1400 PUFFS_MSG_RELEASE(seek
);
1401 return checkerr(pmp
, error
, __func__
);
1405 callremove(struct puffs_mount
*pmp
, puffs_cookie_t dck
, puffs_cookie_t ck
,
1406 struct componentname
*cnp
)
1408 PUFFS_MSG_VARS(vn
, remove
);
1411 PUFFS_MSG_ALLOC(vn
, remove
);
1412 remove_msg
->pvnr_cookie_targ
= ck
;
1413 puffs_makecn(&remove_msg
->pvnr_cn
, &remove_msg
->pvnr_cn_cred
,
1414 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1415 puffs_msg_setinfo(park_remove
, PUFFSOP_VN
, PUFFS_VN_REMOVE
, dck
);
1417 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_remove
, error
);
1418 PUFFS_MSG_RELEASE(remove
);
1420 return checkerr(pmp
, error
, __func__
);
1424 * XXX: can't use callremove now because can't catch setbacks with
1425 * it due to lack of a pnode argument.
1428 puffs_vnop_remove(void *v
)
1430 struct vop_remove_args
/* {
1431 const struct vnodeop_desc *a_desc;
1432 struct vnode *a_dvp;
1434 struct componentname *a_cnp;
1436 PUFFS_MSG_VARS(vn
, remove
);
1437 struct vnode
*dvp
= ap
->a_dvp
;
1438 struct vnode
*vp
= ap
->a_vp
;
1439 struct puffs_node
*dpn
= VPTOPP(dvp
);
1440 struct puffs_node
*pn
= VPTOPP(vp
);
1441 struct componentname
*cnp
= ap
->a_cnp
;
1442 struct mount
*mp
= dvp
->v_mount
;
1443 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
1446 PUFFS_MSG_ALLOC(vn
, remove
);
1447 remove_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1448 puffs_makecn(&remove_msg
->pvnr_cn
, &remove_msg
->pvnr_cn_cred
,
1449 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1450 puffs_msg_setinfo(park_remove
, PUFFSOP_VN
,
1451 PUFFS_VN_REMOVE
, VPTOPNC(dvp
));
1453 puffs_msg_enqueue(pmp
, park_remove
);
1454 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1458 REFPN_AND_UNLOCKVP(vp
, pn
);
1459 error
= puffs_msg_wait2(pmp
, park_remove
, dpn
, pn
);
1461 PUFFS_MSG_RELEASE(remove
);
1463 RELEPN_AND_VP(dvp
, dpn
);
1464 RELEPN_AND_VP(vp
, pn
);
1466 error
= checkerr(pmp
, error
, __func__
);
1467 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
1468 PNBUF_PUT(cnp
->cn_pnbuf
);
1473 puffs_vnop_mkdir(void *v
)
1475 struct vop_mkdir_args
/* {
1476 const struct vnodeop_desc *a_desc;
1477 struct vnode *a_dvp;
1478 struct vnode **a_vpp;
1479 struct componentname *a_cnp;
1480 struct vattr *a_vap;
1482 PUFFS_MSG_VARS(vn
, mkdir
);
1483 struct vnode
*dvp
= ap
->a_dvp
;
1484 struct puffs_node
*dpn
= VPTOPP(dvp
);
1485 struct componentname
*cnp
= ap
->a_cnp
;
1486 struct mount
*mp
= dvp
->v_mount
;
1487 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
1490 PUFFS_MSG_ALLOC(vn
, mkdir
);
1491 puffs_makecn(&mkdir_msg
->pvnr_cn
, &mkdir_msg
->pvnr_cn_cred
,
1492 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1493 mkdir_msg
->pvnr_va
= *ap
->a_vap
;
1494 puffs_msg_setinfo(park_mkdir
, PUFFSOP_VN
,
1495 PUFFS_VN_MKDIR
, VPTOPNC(dvp
));
1497 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mkdir
, dvp
->v_data
, NULL
, error
);
1499 error
= checkerr(pmp
, error
, __func__
);
1503 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
1504 mkdir_msg
->pvnr_newnode
, cnp
, VDIR
, 0);
1506 puffs_abortbutton(pmp
, PUFFS_ABORT_MKDIR
, dpn
->pn_cookie
,
1507 mkdir_msg
->pvnr_newnode
, cnp
);
1511 PUFFS_MSG_RELEASE(mkdir
);
1512 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
1513 PNBUF_PUT(cnp
->cn_pnbuf
);
1518 callrmdir(struct puffs_mount
*pmp
, puffs_cookie_t dck
, puffs_cookie_t ck
,
1519 struct componentname
*cnp
)
1521 PUFFS_MSG_VARS(vn
, rmdir
);
1524 PUFFS_MSG_ALLOC(vn
, rmdir
);
1525 rmdir_msg
->pvnr_cookie_targ
= ck
;
1526 puffs_makecn(&rmdir_msg
->pvnr_cn
, &rmdir_msg
->pvnr_cn_cred
,
1527 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1528 puffs_msg_setinfo(park_rmdir
, PUFFSOP_VN
, PUFFS_VN_RMDIR
, dck
);
1530 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_rmdir
, error
);
1531 PUFFS_MSG_RELEASE(rmdir
);
1533 return checkerr(pmp
, error
, __func__
);
1537 puffs_vnop_rmdir(void *v
)
1539 struct vop_rmdir_args
/* {
1540 const struct vnodeop_desc *a_desc;
1541 struct vnode *a_dvp;
1543 struct componentname *a_cnp;
1545 PUFFS_MSG_VARS(vn
, rmdir
);
1546 struct vnode
*dvp
= ap
->a_dvp
;
1547 struct vnode
*vp
= ap
->a_vp
;
1548 struct puffs_node
*dpn
= VPTOPP(dvp
);
1549 struct puffs_node
*pn
= VPTOPP(vp
);
1550 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1551 struct componentname
*cnp
= ap
->a_cnp
;
1554 PUFFS_MSG_ALLOC(vn
, rmdir
);
1555 rmdir_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1556 puffs_makecn(&rmdir_msg
->pvnr_cn
, &rmdir_msg
->pvnr_cn_cred
,
1557 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1558 puffs_msg_setinfo(park_rmdir
, PUFFSOP_VN
,
1559 PUFFS_VN_RMDIR
, VPTOPNC(dvp
));
1561 puffs_msg_enqueue(pmp
, park_rmdir
);
1562 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1563 REFPN_AND_UNLOCKVP(vp
, pn
);
1564 error
= puffs_msg_wait2(pmp
, park_rmdir
, dpn
, pn
);
1566 PUFFS_MSG_RELEASE(rmdir
);
1568 /* XXX: some call cache_purge() *for both vnodes* here, investigate */
1569 RELEPN_AND_VP(dvp
, dpn
);
1570 RELEPN_AND_VP(vp
, pn
);
1572 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
1573 PNBUF_PUT(cnp
->cn_pnbuf
);
1579 puffs_vnop_link(void *v
)
1581 struct vop_link_args
/* {
1582 const struct vnodeop_desc *a_desc;
1583 struct vnode *a_dvp;
1585 struct componentname *a_cnp;
1587 PUFFS_MSG_VARS(vn
, link
);
1588 struct vnode
*dvp
= ap
->a_dvp
;
1589 struct vnode
*vp
= ap
->a_vp
;
1590 struct puffs_node
*dpn
= VPTOPP(dvp
);
1591 struct puffs_node
*pn
= VPTOPP(vp
);
1592 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1593 struct componentname
*cnp
= ap
->a_cnp
;
1596 PUFFS_MSG_ALLOC(vn
, link
);
1597 link_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1598 puffs_makecn(&link_msg
->pvnr_cn
, &link_msg
->pvnr_cn_cred
,
1599 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1600 puffs_msg_setinfo(park_link
, PUFFSOP_VN
,
1601 PUFFS_VN_LINK
, VPTOPNC(dvp
));
1603 puffs_msg_enqueue(pmp
, park_link
);
1604 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1606 error
= puffs_msg_wait2(pmp
, park_link
, dpn
, pn
);
1608 PUFFS_MSG_RELEASE(link
);
1610 error
= checkerr(pmp
, error
, __func__
);
1613 * XXX: stay in touch with the cache. I don't like this, but
1614 * don't have a better solution either. See also puffs_rename().
1617 puffs_updatenode(pn
, PUFFS_UPDATECTIME
, 0);
1619 PNBUF_PUT(cnp
->cn_pnbuf
);
1620 RELEPN_AND_VP(dvp
, dpn
);
1621 puffs_releasenode(pn
);
1627 puffs_vnop_symlink(void *v
)
1629 struct vop_symlink_args
/* {
1630 const struct vnodeop_desc *a_desc;
1631 struct vnode *a_dvp;
1632 struct vnode **a_vpp;
1633 struct componentname *a_cnp;
1634 struct vattr *a_vap;
1637 PUFFS_MSG_VARS(vn
, symlink
);
1638 struct vnode
*dvp
= ap
->a_dvp
;
1639 struct puffs_node
*dpn
= VPTOPP(dvp
);
1640 struct mount
*mp
= dvp
->v_mount
;
1641 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1642 struct componentname
*cnp
= ap
->a_cnp
;
1647 PUFFS_MSG_ALLOC(vn
, symlink
);
1648 puffs_makecn(&symlink_msg
->pvnr_cn
, &symlink_msg
->pvnr_cn_cred
,
1649 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1650 symlink_msg
->pvnr_va
= *ap
->a_vap
;
1651 (void)strlcpy(symlink_msg
->pvnr_link
, ap
->a_target
,
1652 sizeof(symlink_msg
->pvnr_link
));
1653 puffs_msg_setinfo(park_symlink
, PUFFSOP_VN
,
1654 PUFFS_VN_SYMLINK
, VPTOPNC(dvp
));
1656 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_symlink
, dvp
->v_data
, NULL
, error
);
1658 error
= checkerr(pmp
, error
, __func__
);
1662 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
1663 symlink_msg
->pvnr_newnode
, cnp
, VLNK
, 0);
1665 puffs_abortbutton(pmp
, PUFFS_ABORT_SYMLINK
, dpn
->pn_cookie
,
1666 symlink_msg
->pvnr_newnode
, cnp
);
1670 PUFFS_MSG_RELEASE(symlink
);
1671 if (error
|| (cnp
->cn_flags
& SAVESTART
) == 0)
1672 PNBUF_PUT(cnp
->cn_pnbuf
);
1678 puffs_vnop_readlink(void *v
)
1680 struct vop_readlink_args
/* {
1681 const struct vnodeop_desc *a_desc;
1684 kauth_cred_t a_cred;
1686 PUFFS_MSG_VARS(vn
, readlink
);
1687 struct vnode
*vp
= ap
->a_vp
;
1688 struct puffs_mount
*pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
1692 PUFFS_MSG_ALLOC(vn
, readlink
);
1693 puffs_credcvt(&readlink_msg
->pvnr_cred
, ap
->a_cred
);
1694 linklen
= sizeof(readlink_msg
->pvnr_link
);
1695 readlink_msg
->pvnr_linklen
= linklen
;
1696 puffs_msg_setinfo(park_readlink
, PUFFSOP_VN
,
1697 PUFFS_VN_READLINK
, VPTOPNC(vp
));
1699 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_readlink
, vp
->v_data
, NULL
, error
);
1700 error
= checkerr(pmp
, error
, __func__
);
1704 /* bad bad user file server */
1705 if (readlink_msg
->pvnr_linklen
> linklen
) {
1706 puffs_senderr(pmp
, PUFFS_ERR_READLINK
, E2BIG
,
1707 "linklen too big", VPTOPNC(ap
->a_vp
));
1712 error
= uiomove(&readlink_msg
->pvnr_link
, readlink_msg
->pvnr_linklen
,
1715 PUFFS_MSG_RELEASE(readlink
);
1720 puffs_vnop_rename(void *v
)
1722 struct vop_rename_args
/* {
1723 const struct vnodeop_desc *a_desc;
1724 struct vnode *a_fdvp;
1725 struct vnode *a_fvp;
1726 struct componentname *a_fcnp;
1727 struct vnode *a_tdvp;
1728 struct vnode *a_tvp;
1729 struct componentname *a_tcnp;
1731 PUFFS_MSG_VARS(vn
, rename
);
1732 struct vnode
*fdvp
= ap
->a_fdvp
, *fvp
= ap
->a_fvp
;
1733 struct vnode
*tdvp
= ap
->a_tdvp
, *tvp
= ap
->a_tvp
;
1734 struct puffs_node
*fpn
= ap
->a_fvp
->v_data
;
1735 struct puffs_mount
*pmp
= MPTOPUFFSMP(fdvp
->v_mount
);
1737 bool doabort
= true;
1739 if ((fvp
->v_mount
!= tdvp
->v_mount
) ||
1740 (tvp
&& (fvp
->v_mount
!= tvp
->v_mount
))) {
1744 PUFFS_MSG_ALLOC(vn
, rename
);
1745 rename_msg
->pvnr_cookie_src
= VPTOPNC(fvp
);
1746 rename_msg
->pvnr_cookie_targdir
= VPTOPNC(tdvp
);
1748 rename_msg
->pvnr_cookie_targ
= VPTOPNC(tvp
);
1750 rename_msg
->pvnr_cookie_targ
= NULL
;
1751 puffs_makecn(&rename_msg
->pvnr_cn_src
, &rename_msg
->pvnr_cn_src_cred
,
1752 ap
->a_fcnp
, PUFFS_USE_FULLPNBUF(pmp
));
1753 puffs_makecn(&rename_msg
->pvnr_cn_targ
, &rename_msg
->pvnr_cn_targ_cred
,
1754 ap
->a_tcnp
, PUFFS_USE_FULLPNBUF(pmp
));
1755 puffs_msg_setinfo(park_rename
, PUFFSOP_VN
,
1756 PUFFS_VN_RENAME
, VPTOPNC(fdvp
));
1758 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rename
, fdvp
->v_data
, NULL
, error
);
1760 PUFFS_MSG_RELEASE(rename
);
1761 error
= checkerr(pmp
, error
, __func__
);
1764 * XXX: stay in touch with the cache. I don't like this, but
1765 * don't have a better solution either. See also puffs_link().
1768 puffs_updatenode(fpn
, PUFFS_UPDATECTIME
, 0);
1772 VOP_ABORTOP(tdvp
, ap
->a_tcnp
);
1781 VOP_ABORTOP(fdvp
, ap
->a_fcnp
);
1788 #define RWARGS(cont, iofl, move, offset, creds) \
1789 (cont)->pvnr_ioflag = (iofl); \
1790 (cont)->pvnr_resid = (move); \
1791 (cont)->pvnr_offset = (offset); \
1792 puffs_credcvt(&(cont)->pvnr_cred, creds)
1795 puffs_vnop_read(void *v
)
1797 struct vop_read_args
/* {
1798 const struct vnodeop_desc *a_desc;
1802 kauth_cred_t a_cred;
1804 PUFFS_MSG_VARS(vn
, read
);
1805 struct vnode
*vp
= ap
->a_vp
;
1806 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1807 struct uio
*uio
= ap
->a_uio
;
1808 size_t tomove
, argsize
;
1816 if (uio
->uio_resid
== 0)
1818 if (uio
->uio_offset
< 0)
1821 if (vp
->v_type
== VREG
&& PUFFS_USE_PAGECACHE(pmp
)) {
1822 const int advice
= IO_ADV_DECODE(ap
->a_ioflag
);
1824 while (uio
->uio_resid
> 0) {
1825 bytelen
= MIN(uio
->uio_resid
,
1826 vp
->v_size
- uio
->uio_offset
);
1830 error
= ubc_uiomove(&vp
->v_uobj
, uio
, bytelen
, advice
,
1831 UBC_READ
| UBC_PARTIALOK
| UBC_UNMAP_FLAG(vp
));
1836 if ((vp
->v_mount
->mnt_flag
& MNT_NOATIME
) == 0)
1837 puffs_updatenode(VPTOPP(vp
), PUFFS_UPDATEATIME
, 0);
1840 * in case it's not a regular file or we're operating
1841 * uncached, do read in the old-fashioned style,
1842 * i.e. explicit read operations
1845 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
1846 argsize
= sizeof(struct puffs_vnmsg_read
);
1847 puffs_msgmem_alloc(argsize
+ tomove
, &park_read
,
1848 (void *)&read_msg
, 1);
1851 while (uio
->uio_resid
> 0) {
1852 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
1853 memset(read_msg
, 0, argsize
); /* XXX: touser KASSERT */
1854 RWARGS(read_msg
, ap
->a_ioflag
, tomove
,
1855 uio
->uio_offset
, ap
->a_cred
);
1856 puffs_msg_setinfo(park_read
, PUFFSOP_VN
,
1857 PUFFS_VN_READ
, VPTOPNC(vp
));
1858 puffs_msg_setdelta(park_read
, tomove
);
1860 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_read
, vp
->v_data
,
1862 error
= checkerr(pmp
, error
, __func__
);
1866 if (read_msg
->pvnr_resid
> tomove
) {
1867 puffs_senderr(pmp
, PUFFS_ERR_READ
,
1868 E2BIG
, "resid grew", VPTOPNC(ap
->a_vp
));
1873 error
= uiomove(read_msg
->pvnr_data
,
1874 tomove
- read_msg
->pvnr_resid
, uio
);
1877 * in case the file is out of juice, resid from
1878 * userspace is != 0. and the error-case is
1881 if (error
|| read_msg
->pvnr_resid
)
1885 puffs_msgmem_release(park_read
);
1892 * XXX: in case of a failure, this leaves uio in a bad state.
1893 * We could theoretically copy the uio and iovecs and "replay"
1894 * them the right amount after the userspace trip, but don't
1898 puffs_vnop_write(void *v
)
1900 struct vop_write_args
/* {
1901 const struct vnodeop_desc *a_desc;
1905 kauth_cred_t a_cred;
1907 PUFFS_MSG_VARS(vn
, write
);
1908 struct vnode
*vp
= ap
->a_vp
;
1909 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1910 struct uio
*uio
= ap
->a_uio
;
1911 size_t tomove
, argsize
;
1912 off_t oldoff
, newoff
, origoff
;
1920 if (vp
->v_type
== VREG
&& PUFFS_USE_PAGECACHE(pmp
)) {
1921 ubcflags
= UBC_WRITE
| UBC_PARTIALOK
| UBC_UNMAP_FLAG(vp
);
1924 * userspace *should* be allowed to control this,
1925 * but with UBC it's a bit unclear how to handle it
1927 if (ap
->a_ioflag
& IO_APPEND
)
1928 uio
->uio_offset
= vp
->v_size
;
1930 origoff
= uio
->uio_offset
;
1931 while (uio
->uio_resid
> 0) {
1932 uflags
|= PUFFS_UPDATECTIME
;
1933 uflags
|= PUFFS_UPDATEMTIME
;
1934 oldoff
= uio
->uio_offset
;
1935 bytelen
= uio
->uio_resid
;
1937 newoff
= oldoff
+ bytelen
;
1938 if (vp
->v_size
< newoff
) {
1939 uvm_vnp_setwritesize(vp
, newoff
);
1941 error
= ubc_uiomove(&vp
->v_uobj
, uio
, bytelen
,
1942 UVM_ADV_RANDOM
, ubcflags
);
1945 * In case of a ubc_uiomove() error,
1946 * opt to not extend the file at all and
1947 * return an error. Otherwise, if we attempt
1948 * to clear the memory we couldn't fault to,
1949 * we might generate a kernel page fault.
1951 if (vp
->v_size
< newoff
) {
1953 uflags
|= PUFFS_UPDATESIZE
;
1954 uvm_vnp_setsize(vp
, newoff
);
1956 uvm_vnp_setwritesize(vp
, vp
->v_size
);
1963 * If we're writing large files, flush to file server
1964 * every 64k. Otherwise we can very easily exhaust
1965 * kernel and user memory, as the file server cannot
1966 * really keep up with our writing speed.
1968 * Note: this does *NOT* honor MNT_ASYNC, because
1969 * that gives userland too much say in the kernel.
1971 if (oldoff
>> 16 != uio
->uio_offset
>> 16) {
1972 mutex_enter(&vp
->v_interlock
);
1973 error
= VOP_PUTPAGES(vp
, oldoff
& ~0xffff,
1974 uio
->uio_offset
& ~0xffff,
1975 PGO_CLEANIT
| PGO_SYNCIO
);
1981 /* synchronous I/O? */
1982 if (error
== 0 && ap
->a_ioflag
& IO_SYNC
) {
1983 mutex_enter(&vp
->v_interlock
);
1984 error
= VOP_PUTPAGES(vp
, trunc_page(origoff
),
1985 round_page(uio
->uio_offset
),
1986 PGO_CLEANIT
| PGO_SYNCIO
);
1988 /* write through page cache? */
1989 } else if (error
== 0 && pmp
->pmp_flags
& PUFFS_KFLAG_WTCACHE
) {
1990 mutex_enter(&vp
->v_interlock
);
1991 error
= VOP_PUTPAGES(vp
, trunc_page(origoff
),
1992 round_page(uio
->uio_offset
), PGO_CLEANIT
);
1995 puffs_updatenode(VPTOPP(vp
), uflags
, vp
->v_size
);
1997 /* tomove is non-increasing */
1998 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
1999 argsize
= sizeof(struct puffs_vnmsg_write
) + tomove
;
2000 puffs_msgmem_alloc(argsize
, &park_write
, (void *)&write_msg
,1);
2002 while (uio
->uio_resid
> 0) {
2003 /* move data to buffer */
2004 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
2005 memset(write_msg
, 0, argsize
); /* XXX: touser KASSERT */
2006 RWARGS(write_msg
, ap
->a_ioflag
, tomove
,
2007 uio
->uio_offset
, ap
->a_cred
);
2008 error
= uiomove(write_msg
->pvnr_data
, tomove
, uio
);
2012 /* move buffer to userspace */
2013 puffs_msg_setinfo(park_write
, PUFFSOP_VN
,
2014 PUFFS_VN_WRITE
, VPTOPNC(vp
));
2015 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_write
, vp
->v_data
,
2017 error
= checkerr(pmp
, error
, __func__
);
2021 if (write_msg
->pvnr_resid
> tomove
) {
2022 puffs_senderr(pmp
, PUFFS_ERR_WRITE
,
2023 E2BIG
, "resid grew", VPTOPNC(ap
->a_vp
));
2028 /* adjust file size */
2029 if (vp
->v_size
< uio
->uio_offset
)
2030 uvm_vnp_setsize(vp
, uio
->uio_offset
);
2032 /* didn't move everything? bad userspace. bail */
2033 if (write_msg
->pvnr_resid
!= 0) {
2038 puffs_msgmem_release(park_write
);
2045 puffs_vnop_print(void *v
)
2047 struct vop_print_args
/* {
2050 PUFFS_MSG_VARS(vn
, print
);
2051 struct vnode
*vp
= ap
->a_vp
;
2052 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2053 struct puffs_node
*pn
= vp
->v_data
;
2056 /* kernel portion */
2057 printf("tag VT_PUFFS, vnode %p, puffs node: %p,\n"
2058 " userspace cookie: %p\n", vp
, pn
, pn
->pn_cookie
);
2059 if (vp
->v_type
== VFIFO
)
2062 /* userspace portion */
2063 if (EXISTSOP(pmp
, PRINT
)) {
2064 PUFFS_MSG_ALLOC(vn
, print
);
2065 puffs_msg_setinfo(park_print
, PUFFSOP_VN
,
2066 PUFFS_VN_PRINT
, VPTOPNC(vp
));
2067 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_print
, vp
->v_data
,
2069 PUFFS_MSG_RELEASE(print
);
2076 puffs_vnop_pathconf(void *v
)
2078 struct vop_pathconf_args
/* {
2079 const struct vnodeop_desc *a_desc;
2082 register_t *a_retval;
2084 PUFFS_MSG_VARS(vn
, pathconf
);
2085 struct vnode
*vp
= ap
->a_vp
;
2086 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2089 PUFFS_MSG_ALLOC(vn
, pathconf
);
2090 pathconf_msg
->pvnr_name
= ap
->a_name
;
2091 puffs_msg_setinfo(park_pathconf
, PUFFSOP_VN
,
2092 PUFFS_VN_PATHCONF
, VPTOPNC(vp
));
2093 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_pathconf
, vp
->v_data
, NULL
, error
);
2094 error
= checkerr(pmp
, error
, __func__
);
2096 *ap
->a_retval
= pathconf_msg
->pvnr_retval
;
2097 PUFFS_MSG_RELEASE(pathconf
);
2103 puffs_vnop_advlock(void *v
)
2105 struct vop_advlock_args
/* {
2106 const struct vnodeop_desc *a_desc;
2113 PUFFS_MSG_VARS(vn
, advlock
);
2114 struct vnode
*vp
= ap
->a_vp
;
2115 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2118 PUFFS_MSG_ALLOC(vn
, advlock
);
2119 error
= copyin(ap
->a_fl
, &advlock_msg
->pvnr_fl
, sizeof(struct flock
));
2122 advlock_msg
->pvnr_id
= ap
->a_id
;
2123 advlock_msg
->pvnr_op
= ap
->a_op
;
2124 advlock_msg
->pvnr_flags
= ap
->a_flags
;
2125 puffs_msg_setinfo(park_advlock
, PUFFSOP_VN
,
2126 PUFFS_VN_ADVLOCK
, VPTOPNC(vp
));
2128 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_advlock
, vp
->v_data
, NULL
, error
);
2129 error
= checkerr(pmp
, error
, __func__
);
2132 PUFFS_MSG_RELEASE(advlock
);
2137 puffs_vnop_abortop(void *v
)
2139 struct vop_abortop_args
/* {
2140 struct vnode *a_dvp;
2141 struct componentname *a_cnp;
2143 PUFFS_MSG_VARS(vn
, abortop
);
2144 struct vnode
*dvp
= ap
->a_dvp
;
2145 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
2146 struct componentname
*cnp
= ap
->a_cnp
;
2148 if (EXISTSOP(pmp
, ABORTOP
)) {
2149 PUFFS_MSG_ALLOC(vn
, abortop
);
2150 puffs_makecn(&abortop_msg
->pvnr_cn
, &abortop_msg
->pvnr_cn_cred
,
2151 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
2152 puffs_msg_setfaf(park_abortop
);
2153 puffs_msg_setinfo(park_abortop
, PUFFSOP_VN
,
2154 PUFFS_VN_ABORTOP
, VPTOPNC(dvp
));
2156 puffs_msg_enqueue(pmp
, park_abortop
);
2157 PUFFS_MSG_RELEASE(abortop
);
2160 return genfs_abortop(v
);
2163 #define BIOASYNC(bp) (bp->b_flags & B_ASYNC)
2166 * This maps itself to PUFFS_VN_READ/WRITE for data transfer.
2169 puffs_vnop_strategy(void *v
)
2171 struct vop_strategy_args
/* {
2172 const struct vnodeop_desc *a_desc;
2176 PUFFS_MSG_VARS(vn
, rw
);
2177 struct vnode
*vp
= ap
->a_vp
;
2178 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2179 struct puffs_node
*pn
;
2182 size_t tomove
, moved
;
2183 int error
, dofaf
, dobiodone
;
2185 pmp
= MPTOPUFFSMP(vp
->v_mount
);
2190 park_rw
= NULL
; /* explicit */
2193 if ((BUF_ISREAD(bp
) && !EXISTSOP(pmp
, READ
))
2194 || (BUF_ISWRITE(bp
) && !EXISTSOP(pmp
, WRITE
)))
2198 * Short-circuit optimization: don't flush buffer in between
2199 * VOP_INACTIVE and VOP_RECLAIM in case the node has no references.
2201 if (pn
->pn_stat
& PNODE_DYING
) {
2202 KASSERT(BUF_ISWRITE(bp
));
2208 if (bp
->b_bcount
> pmp
->pmp_msg_maxsize
- PUFFS_MSGSTRUCT_MAX
)
2209 panic("puffs_strategy: wildly inappropriate buf bcount %d",
2214 * See explanation for the necessity of a FAF in puffs_fsync.
2216 * Also, do FAF in case we're suspending.
2217 * See puffs_vfsops.c:pageflush()
2219 if (BUF_ISWRITE(bp
)) {
2220 mutex_enter(&vp
->v_interlock
);
2221 if (vp
->v_iflag
& VI_XLOCK
)
2223 if (pn
->pn_stat
& PNODE_FAF
)
2225 mutex_exit(&vp
->v_interlock
);
2229 if (curlwp
== uvm
.pagedaemon_lwp
)
2230 KASSERT(dofaf
|| BIOASYNC(bp
));
2233 /* allocate transport structure */
2234 tomove
= PUFFS_TOMOVE(bp
->b_bcount
, pmp
);
2235 argsize
= sizeof(struct puffs_vnmsg_rw
);
2236 error
= puffs_msgmem_alloc(argsize
+ tomove
, &park_rw
,
2237 (void *)&rw_msg
, dofaf
? 0 : 1);
2240 RWARGS(rw_msg
, 0, tomove
, bp
->b_blkno
<< DEV_BSHIFT
, FSCRED
);
2242 /* 2x2 cases: read/write, faf/nofaf */
2243 if (BUF_ISREAD(bp
)) {
2244 puffs_msg_setinfo(park_rw
, PUFFSOP_VN
,
2245 PUFFS_VN_READ
, VPTOPNC(vp
));
2246 puffs_msg_setdelta(park_rw
, tomove
);
2248 puffs_msg_setcall(park_rw
,
2249 puffs_parkdone_asyncbioread
, bp
);
2250 puffs_msg_enqueue(pmp
, park_rw
);
2253 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rw
, vp
->v_data
,
2255 error
= checkerr(pmp
, error
, __func__
);
2259 if (rw_msg
->pvnr_resid
> tomove
) {
2260 puffs_senderr(pmp
, PUFFS_ERR_READ
,
2261 E2BIG
, "resid grew", VPTOPNC(vp
));
2265 moved
= tomove
- rw_msg
->pvnr_resid
;
2267 (void)memcpy(bp
->b_data
, rw_msg
->pvnr_data
, moved
);
2268 bp
->b_resid
= bp
->b_bcount
- moved
;
2271 puffs_msg_setinfo(park_rw
, PUFFSOP_VN
,
2272 PUFFS_VN_WRITE
, VPTOPNC(vp
));
2274 * make pages read-only before we write them if we want
2275 * write caching info
2277 if (PUFFS_WCACHEINFO(pmp
)) {
2278 struct uvm_object
*uobj
= &vp
->v_uobj
;
2279 int npages
= (bp
->b_bcount
+ PAGE_SIZE
-1) >> PAGE_SHIFT
;
2280 struct vm_page
*vmp
;
2283 for (i
= 0; i
< npages
; i
++) {
2284 vmp
= uvm_pageratop((vaddr_t
)bp
->b_data
2285 + (i
<< PAGE_SHIFT
));
2286 DPRINTF(("puffs_strategy: write-protecting "
2287 "vp %p page %p, offset %" PRId64
"\n",
2288 vp
, vmp
, vmp
->offset
));
2289 mutex_enter(&uobj
->vmobjlock
);
2290 vmp
->flags
|= PG_RDONLY
;
2291 pmap_page_protect(vmp
, VM_PROT_READ
);
2292 mutex_exit(&uobj
->vmobjlock
);
2296 (void)memcpy(&rw_msg
->pvnr_data
, bp
->b_data
, tomove
);
2298 puffs_msg_setfaf(park_rw
);
2299 } else if (BIOASYNC(bp
)) {
2300 puffs_msg_setcall(park_rw
,
2301 puffs_parkdone_asyncbiowrite
, bp
);
2305 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rw
, vp
->v_data
, NULL
, error
);
2311 * XXXXXXXX: wrong, but kernel can't survive strategy
2312 * failure currently. Here, have one more X: X.
2314 if (error
!= ENOMEM
)
2317 error
= checkerr(pmp
, error
, __func__
);
2321 if (rw_msg
->pvnr_resid
> tomove
) {
2322 puffs_senderr(pmp
, PUFFS_ERR_WRITE
,
2323 E2BIG
, "resid grew", VPTOPNC(vp
));
2328 * FAF moved everything. Frankly, we don't
2329 * really have a choice.
2331 if (dofaf
&& error
== 0)
2334 moved
= tomove
- rw_msg
->pvnr_resid
;
2336 bp
->b_resid
= bp
->b_bcount
- moved
;
2337 if (bp
->b_resid
!= 0) {
2344 puffs_msgmem_release(park_rw
);
2347 bp
->b_error
= error
;
2349 if (error
|| dobiodone
)
2356 puffs_vnop_mmap(void *v
)
2358 struct vop_mmap_args
/* {
2359 const struct vnodeop_desc *a_desc;
2362 kauth_cred_t a_cred;
2364 PUFFS_MSG_VARS(vn
, mmap
);
2365 struct vnode
*vp
= ap
->a_vp
;
2366 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2369 if (!PUFFS_USE_PAGECACHE(pmp
))
2370 return genfs_eopnotsupp(v
);
2372 if (EXISTSOP(pmp
, MMAP
)) {
2373 PUFFS_MSG_ALLOC(vn
, mmap
);
2374 mmap_msg
->pvnr_prot
= ap
->a_prot
;
2375 puffs_credcvt(&mmap_msg
->pvnr_cred
, ap
->a_cred
);
2376 puffs_msg_setinfo(park_mmap
, PUFFSOP_VN
,
2377 PUFFS_VN_MMAP
, VPTOPNC(vp
));
2379 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mmap
, vp
->v_data
, NULL
, error
);
2380 error
= checkerr(pmp
, error
, __func__
);
2381 PUFFS_MSG_RELEASE(mmap
);
2383 error
= genfs_mmap(v
);
2391 * The rest don't get a free trip to userspace and back, they
2392 * have to stay within the kernel.
2396 * bmap doesn't really make any sense for puffs, so just 1:1 map it.
2397 * well, maybe somehow, somewhere, some day ....
2400 puffs_vnop_bmap(void *v
)
2402 struct vop_bmap_args
/* {
2403 const struct vnodeop_desc *a_desc;
2406 struct vnode **a_vpp;
2410 struct puffs_mount
*pmp
;
2412 pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
2415 *ap
->a_vpp
= ap
->a_vp
;
2417 *ap
->a_bnp
= ap
->a_bn
;
2420 = (PUFFS_TOMOVE(pmp
->pmp_msg_maxsize
, pmp
)>>DEV_BSHIFT
) - 1;
2426 * Handle getpages faults in puffs. We let genfs_getpages() do most
2427 * of the dirty work, but we come in this route to do accounting tasks.
2428 * If the user server has specified functions for cache notifications
2429 * about reads and/or writes, we record which type of operation we got,
2430 * for which page range, and proceed to issue a FAF notification to the
2434 puffs_vnop_getpages(void *v
)
2436 struct vop_getpages_args
/* {
2437 const struct vnodeop_desc *a_desc;
2440 struct vm_page **a_m;
2443 vm_prot_t a_access_type;
2447 struct puffs_mount
*pmp
;
2448 struct puffs_node
*pn
;
2450 struct vm_page
**pgs
;
2451 struct puffs_cacheinfo
*pcinfo
= NULL
;
2452 struct puffs_cacherun
*pcrun
;
2453 void *parkmem
= NULL
;
2455 int i
, npages
, si
, streakon
;
2456 int error
, locked
, write
;
2458 pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
2459 npages
= *ap
->a_count
;
2463 locked
= (ap
->a_flags
& PGO_LOCKED
) != 0;
2464 write
= (ap
->a_access_type
& VM_PROT_WRITE
) != 0;
2466 /* ccg xnaht - gets Wuninitialized wrong */
2471 * Check that we aren't trying to fault in pages which our file
2472 * server doesn't know about. This happens if we extend a file by
2473 * skipping some pages and later try to fault in pages which
2474 * are between pn_serversize and vp_size. This check optimizes
2475 * away the common case where a file is being extended.
2477 if (ap
->a_offset
>= pn
->pn_serversize
&& ap
->a_offset
< vp
->v_size
) {
2480 /* try again later when we can block */
2484 mutex_exit(&vp
->v_interlock
);
2486 va
.va_size
= vp
->v_size
;
2487 error
= dosetattr(vp
, &va
, FSCRED
, 0);
2490 mutex_enter(&vp
->v_interlock
);
2493 if (write
&& PUFFS_WCACHEINFO(pmp
)) {
2495 /* allocate worst-case memory */
2496 runsizes
= ((npages
/ 2) + 1) * sizeof(struct puffs_cacherun
);
2497 pcinfo
= kmem_zalloc(sizeof(struct puffs_cacheinfo
) + runsize
,
2498 locked
? KM_NOSLEEP
: KM_SLEEP
);
2501 * can't block if we're locked and can't mess up caching
2502 * information for fs server. so come back later, please
2507 parkmem
= puffs_park_alloc(locked
== 0);
2508 if (parkmem
== NULL
)
2511 pcrun
= pcinfo
->pcache_runs
;
2517 error
= genfs_getpages(v
);
2521 if (PUFFS_WCACHEINFO(pmp
) == 0)
2525 * Let's see whose fault it was and inform the user server of
2526 * possibly read/written pages. Map pages from read faults
2527 * strictly read-only, since otherwise we might miss info on
2528 * when the page is actually write-faulted to.
2531 mutex_enter(&vp
->v_uobj
.vmobjlock
);
2532 for (i
= 0, si
= 0, streakon
= 0; i
< npages
; i
++) {
2533 if (pgs
[i
] == NULL
|| pgs
[i
] == PGO_DONTCARE
) {
2534 if (streakon
&& write
) {
2536 pcrun
[si
].pcache_runend
2537 = trunc_page(pgs
[i
]->offset
) + PAGE_MASK
;
2542 if (streakon
== 0 && write
) {
2544 pcrun
[si
].pcache_runstart
= pgs
[i
]->offset
;
2548 pgs
[i
]->flags
|= PG_RDONLY
;
2550 /* was the last page part of our streak? */
2552 pcrun
[si
].pcache_runend
2553 = trunc_page(pgs
[i
-1]->offset
) + PAGE_MASK
;
2557 mutex_exit(&vp
->v_uobj
.vmobjlock
);
2559 KASSERT(si
<= (npages
/ 2) + 1);
2562 /* send results to userspace */
2564 puffs_cacheop(pmp
, parkmem
, pcinfo
,
2565 sizeof(struct puffs_cacheinfo
) + runsizes
, VPTOPNC(vp
));
2572 sizeof(struct puffs_cacheinfo
) + runsizes
);
2574 if (parkmem
!= NULL
)
2575 puffs_park_release(parkmem
, 1);
2583 * spec & fifo. These call the miscfs spec and fifo vectors, but issue
2584 * FAF update information for the puffs node first.
2587 puffs_vnop_spec_read(void *v
)
2589 struct vop_read_args
/* {
2590 const struct vnodeop_desc *a_desc;
2594 kauth_cred_t a_cred;
2597 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEATIME
, 0);
2598 return VOCALL(spec_vnodeop_p
, VOFFSET(vop_read
), v
);
2602 puffs_vnop_spec_write(void *v
)
2604 struct vop_write_args
/* {
2605 const struct vnodeop_desc *a_desc;
2609 kauth_cred_t a_cred;
2612 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEMTIME
, 0);
2613 return VOCALL(spec_vnodeop_p
, VOFFSET(vop_write
), v
);
2617 puffs_vnop_fifo_read(void *v
)
2619 struct vop_read_args
/* {
2620 const struct vnodeop_desc *a_desc;
2624 kauth_cred_t a_cred;
2627 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEATIME
, 0);
2628 return VOCALL(fifo_vnodeop_p
, VOFFSET(vop_read
), v
);
2632 puffs_vnop_fifo_write(void *v
)
2634 struct vop_write_args
/* {
2635 const struct vnodeop_desc *a_desc;
2639 kauth_cred_t a_cred;
2642 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEMTIME
, 0);
2643 return VOCALL(fifo_vnodeop_p
, VOFFSET(vop_write
), v
);