1 /* $NetBSD: puffs_vnops.c,v 1.177 2013/10/17 21:03:27 christos 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.177 2013/10/17 21:03:27 christos Exp $");
35 #include <sys/param.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>
43 #include <sys/kernel.h> /* For hz, hardclock_ticks */
47 #include <fs/puffs/puffs_msgif.h>
48 #include <fs/puffs/puffs_sys.h>
50 #include <miscfs/fifofs/fifo.h>
51 #include <miscfs/genfs/genfs.h>
52 #include <miscfs/specfs/specdev.h>
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_fcntl(void *);
77 int puffs_vnop_ioctl(void *);
78 int puffs_vnop_inactive(void *);
79 int puffs_vnop_print(void *);
80 int puffs_vnop_pathconf(void *);
81 int puffs_vnop_advlock(void *);
82 int puffs_vnop_strategy(void *);
83 int puffs_vnop_bmap(void *);
84 int puffs_vnop_mmap(void *);
85 int puffs_vnop_getpages(void *);
86 int puffs_vnop_abortop(void *);
87 int puffs_vnop_getextattr(void *);
88 int puffs_vnop_setextattr(void *);
89 int puffs_vnop_listextattr(void *);
90 int puffs_vnop_deleteextattr(void *);
92 int puffs_vnop_spec_read(void *);
93 int puffs_vnop_spec_write(void *);
94 int puffs_vnop_fifo_read(void *);
95 int puffs_vnop_fifo_write(void *);
97 int puffs_vnop_checkop(void *);
99 #define puffs_vnop_lock genfs_lock
100 #define puffs_vnop_unlock genfs_unlock
101 #define puffs_vnop_islocked genfs_islocked
103 int (**puffs_vnodeop_p
)(void *);
104 const struct vnodeopv_entry_desc puffs_vnodeop_entries
[] = {
105 { &vop_default_desc
, vn_default_error
},
106 { &vop_lookup_desc
, puffs_vnop_lookup
}, /* REAL lookup */
107 { &vop_create_desc
, puffs_vnop_checkop
}, /* create */
108 { &vop_mknod_desc
, puffs_vnop_checkop
}, /* mknod */
109 { &vop_open_desc
, puffs_vnop_open
}, /* REAL open */
110 { &vop_close_desc
, puffs_vnop_checkop
}, /* close */
111 { &vop_access_desc
, puffs_vnop_access
}, /* REAL access */
112 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
113 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
114 { &vop_read_desc
, puffs_vnop_checkop
}, /* read */
115 { &vop_write_desc
, puffs_vnop_checkop
}, /* write */
116 { &vop_fsync_desc
, puffs_vnop_fsync
}, /* REAL fsync */
117 { &vop_seek_desc
, puffs_vnop_checkop
}, /* seek */
118 { &vop_remove_desc
, puffs_vnop_checkop
}, /* remove */
119 { &vop_link_desc
, puffs_vnop_checkop
}, /* link */
120 { &vop_rename_desc
, puffs_vnop_checkop
}, /* rename */
121 { &vop_mkdir_desc
, puffs_vnop_checkop
}, /* mkdir */
122 { &vop_rmdir_desc
, puffs_vnop_checkop
}, /* rmdir */
123 { &vop_symlink_desc
, puffs_vnop_checkop
}, /* symlink */
124 { &vop_readdir_desc
, puffs_vnop_checkop
}, /* readdir */
125 { &vop_readlink_desc
, puffs_vnop_checkop
}, /* readlink */
126 { &vop_getpages_desc
, puffs_vnop_checkop
}, /* getpages */
127 { &vop_putpages_desc
, genfs_putpages
}, /* REAL putpages */
128 { &vop_pathconf_desc
, puffs_vnop_checkop
}, /* pathconf */
129 { &vop_advlock_desc
, puffs_vnop_advlock
}, /* advlock */
130 { &vop_strategy_desc
, puffs_vnop_strategy
}, /* REAL strategy */
131 { &vop_revoke_desc
, genfs_revoke
}, /* REAL revoke */
132 { &vop_abortop_desc
, puffs_vnop_abortop
}, /* REAL abortop */
133 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
134 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
135 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
136 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
137 { &vop_bmap_desc
, puffs_vnop_bmap
}, /* REAL bmap */
138 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
139 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
140 { &vop_bwrite_desc
, genfs_nullop
}, /* REAL bwrite */
141 { &vop_mmap_desc
, puffs_vnop_mmap
}, /* REAL mmap */
142 { &vop_poll_desc
, puffs_vnop_poll
}, /* REAL poll */
143 { &vop_getextattr_desc
, puffs_vnop_getextattr
}, /* getextattr */
144 { &vop_setextattr_desc
, puffs_vnop_setextattr
}, /* setextattr */
145 { &vop_listextattr_desc
, puffs_vnop_listextattr
}, /* listextattr */
146 { &vop_deleteextattr_desc
, puffs_vnop_deleteextattr
},/* deleteextattr */
148 { &vop_openextattr_desc
, puffs_vnop_checkop
}, /* openextattr */
149 { &vop_closeextattr_desc
, puffs_vnop_checkop
}, /* closeextattr */
151 { &vop_kqfilter_desc
, genfs_eopnotsupp
}, /* kqfilter XXX */
154 const struct vnodeopv_desc puffs_vnodeop_opv_desc
=
155 { &puffs_vnodeop_p
, puffs_vnodeop_entries
};
158 int (**puffs_specop_p
)(void *);
159 const struct vnodeopv_entry_desc puffs_specop_entries
[] = {
160 { &vop_default_desc
, vn_default_error
},
161 { &vop_lookup_desc
, spec_lookup
}, /* lookup, ENOTDIR */
162 { &vop_create_desc
, spec_create
}, /* genfs_badop */
163 { &vop_mknod_desc
, spec_mknod
}, /* genfs_badop */
164 { &vop_open_desc
, spec_open
}, /* spec_open */
165 { &vop_close_desc
, spec_close
}, /* spec_close */
166 { &vop_access_desc
, puffs_vnop_checkop
}, /* access */
167 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
168 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
169 { &vop_read_desc
, puffs_vnop_spec_read
}, /* update, read */
170 { &vop_write_desc
, puffs_vnop_spec_write
}, /* update, write */
171 { &vop_ioctl_desc
, spec_ioctl
}, /* spec_ioctl */
172 { &vop_fcntl_desc
, genfs_fcntl
}, /* dummy */
173 { &vop_poll_desc
, spec_poll
}, /* spec_poll */
174 { &vop_kqfilter_desc
, spec_kqfilter
}, /* spec_kqfilter */
175 { &vop_revoke_desc
, spec_revoke
}, /* genfs_revoke */
176 { &vop_mmap_desc
, spec_mmap
}, /* spec_mmap */
177 { &vop_fsync_desc
, spec_fsync
}, /* vflushbuf */
178 { &vop_seek_desc
, spec_seek
}, /* genfs_nullop */
179 { &vop_remove_desc
, spec_remove
}, /* genfs_badop */
180 { &vop_link_desc
, spec_link
}, /* genfs_badop */
181 { &vop_rename_desc
, spec_rename
}, /* genfs_badop */
182 { &vop_mkdir_desc
, spec_mkdir
}, /* genfs_badop */
183 { &vop_rmdir_desc
, spec_rmdir
}, /* genfs_badop */
184 { &vop_symlink_desc
, spec_symlink
}, /* genfs_badop */
185 { &vop_readdir_desc
, spec_readdir
}, /* genfs_badop */
186 { &vop_readlink_desc
, spec_readlink
}, /* genfs_badop */
187 { &vop_abortop_desc
, spec_abortop
}, /* genfs_badop */
188 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
189 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
190 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
191 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
192 { &vop_bmap_desc
, spec_bmap
}, /* dummy */
193 { &vop_strategy_desc
, spec_strategy
}, /* dev strategy */
194 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
195 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
196 { &vop_pathconf_desc
, spec_pathconf
}, /* pathconf */
197 { &vop_advlock_desc
, spec_advlock
}, /* lf_advlock */
198 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
199 { &vop_getpages_desc
, spec_getpages
}, /* genfs_getpages */
200 { &vop_putpages_desc
, spec_putpages
}, /* genfs_putpages */
201 { &vop_getextattr_desc
, puffs_vnop_checkop
}, /* getextattr */
202 { &vop_setextattr_desc
, puffs_vnop_checkop
}, /* setextattr */
203 { &vop_listextattr_desc
, puffs_vnop_checkop
}, /* listextattr */
204 { &vop_deleteextattr_desc
, puffs_vnop_checkop
},/* deleteextattr */
206 { &vop_openextattr_desc
, _openextattr
}, /* openextattr */
207 { &vop_closeextattr_desc
, _closeextattr
}, /* closeextattr */
211 const struct vnodeopv_desc puffs_specop_opv_desc
=
212 { &puffs_specop_p
, puffs_specop_entries
};
215 int (**puffs_fifoop_p
)(void *);
216 const struct vnodeopv_entry_desc puffs_fifoop_entries
[] = {
217 { &vop_default_desc
, vn_default_error
},
218 { &vop_lookup_desc
, vn_fifo_bypass
}, /* lookup, ENOTDIR */
219 { &vop_create_desc
, vn_fifo_bypass
}, /* genfs_badop */
220 { &vop_mknod_desc
, vn_fifo_bypass
}, /* genfs_badop */
221 { &vop_open_desc
, vn_fifo_bypass
}, /* open */
222 { &vop_close_desc
, vn_fifo_bypass
}, /* close */
223 { &vop_access_desc
, puffs_vnop_checkop
}, /* access */
224 { &vop_getattr_desc
, puffs_vnop_checkop
}, /* getattr */
225 { &vop_setattr_desc
, puffs_vnop_checkop
}, /* setattr */
226 { &vop_read_desc
, puffs_vnop_fifo_read
}, /* read, update */
227 { &vop_write_desc
, puffs_vnop_fifo_write
}, /* write, update */
228 { &vop_ioctl_desc
, vn_fifo_bypass
}, /* ioctl */
229 { &vop_fcntl_desc
, genfs_fcntl
}, /* dummy */
230 { &vop_poll_desc
, vn_fifo_bypass
}, /* poll */
231 { &vop_kqfilter_desc
, vn_fifo_bypass
}, /* kqfilter */
232 { &vop_revoke_desc
, vn_fifo_bypass
}, /* genfs_revoke */
233 { &vop_mmap_desc
, vn_fifo_bypass
}, /* genfs_badop */
234 { &vop_fsync_desc
, vn_fifo_bypass
}, /* genfs_nullop*/
235 { &vop_seek_desc
, vn_fifo_bypass
}, /* genfs_badop */
236 { &vop_remove_desc
, vn_fifo_bypass
}, /* genfs_badop */
237 { &vop_link_desc
, vn_fifo_bypass
}, /* genfs_badop */
238 { &vop_rename_desc
, vn_fifo_bypass
}, /* genfs_badop */
239 { &vop_mkdir_desc
, vn_fifo_bypass
}, /* genfs_badop */
240 { &vop_rmdir_desc
, vn_fifo_bypass
}, /* genfs_badop */
241 { &vop_symlink_desc
, vn_fifo_bypass
}, /* genfs_badop */
242 { &vop_readdir_desc
, vn_fifo_bypass
}, /* genfs_badop */
243 { &vop_readlink_desc
, vn_fifo_bypass
}, /* genfs_badop */
244 { &vop_abortop_desc
, vn_fifo_bypass
}, /* genfs_badop */
245 { &vop_inactive_desc
, puffs_vnop_inactive
}, /* REAL inactive */
246 { &vop_reclaim_desc
, puffs_vnop_reclaim
}, /* REAL reclaim */
247 { &vop_lock_desc
, puffs_vnop_lock
}, /* REAL lock */
248 { &vop_unlock_desc
, puffs_vnop_unlock
}, /* REAL unlock */
249 { &vop_bmap_desc
, vn_fifo_bypass
}, /* dummy */
250 { &vop_strategy_desc
, vn_fifo_bypass
}, /* genfs_badop */
251 { &vop_print_desc
, puffs_vnop_print
}, /* REAL print */
252 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* REAL islocked */
253 { &vop_pathconf_desc
, vn_fifo_bypass
}, /* pathconf */
254 { &vop_advlock_desc
, vn_fifo_bypass
}, /* genfs_einval */
255 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
256 { &vop_putpages_desc
, vn_fifo_bypass
}, /* genfs_null_putpages*/
258 { &vop_openextattr_desc
, _openextattr
}, /* openextattr */
259 { &vop_closeextattr_desc
, _closeextattr
}, /* closeextattr */
261 { &vop_getextattr_desc
, puffs_vnop_checkop
}, /* getextattr */
262 { &vop_setextattr_desc
, puffs_vnop_checkop
}, /* setextattr */
263 { &vop_listextattr_desc
, puffs_vnop_checkop
}, /* listextattr */
264 { &vop_deleteextattr_desc
, puffs_vnop_checkop
}, /* deleteextattr */
267 const struct vnodeopv_desc puffs_fifoop_opv_desc
=
268 { &puffs_fifoop_p
, puffs_fifoop_entries
};
271 /* "real" vnode operations */
272 int (**puffs_msgop_p
)(void *);
273 const struct vnodeopv_entry_desc puffs_msgop_entries
[] = {
274 { &vop_default_desc
, vn_default_error
},
275 { &vop_create_desc
, puffs_vnop_create
}, /* create */
276 { &vop_mknod_desc
, puffs_vnop_mknod
}, /* mknod */
277 { &vop_open_desc
, puffs_vnop_open
}, /* open */
278 { &vop_close_desc
, puffs_vnop_close
}, /* close */
279 { &vop_access_desc
, puffs_vnop_access
}, /* access */
280 { &vop_getattr_desc
, puffs_vnop_getattr
}, /* getattr */
281 { &vop_setattr_desc
, puffs_vnop_setattr
}, /* setattr */
282 { &vop_read_desc
, puffs_vnop_read
}, /* read */
283 { &vop_write_desc
, puffs_vnop_write
}, /* write */
284 { &vop_seek_desc
, puffs_vnop_seek
}, /* seek */
285 { &vop_remove_desc
, puffs_vnop_remove
}, /* remove */
286 { &vop_link_desc
, puffs_vnop_link
}, /* link */
287 { &vop_rename_desc
, puffs_vnop_rename
}, /* rename */
288 { &vop_mkdir_desc
, puffs_vnop_mkdir
}, /* mkdir */
289 { &vop_rmdir_desc
, puffs_vnop_rmdir
}, /* rmdir */
290 { &vop_symlink_desc
, puffs_vnop_symlink
}, /* symlink */
291 { &vop_readdir_desc
, puffs_vnop_readdir
}, /* readdir */
292 { &vop_readlink_desc
, puffs_vnop_readlink
}, /* readlink */
293 { &vop_print_desc
, puffs_vnop_print
}, /* print */
294 { &vop_islocked_desc
, puffs_vnop_islocked
}, /* islocked */
295 { &vop_pathconf_desc
, puffs_vnop_pathconf
}, /* pathconf */
296 { &vop_getpages_desc
, puffs_vnop_getpages
}, /* getpages */
299 const struct vnodeopv_desc puffs_msgop_opv_desc
=
300 { &puffs_msgop_p
, puffs_msgop_entries
};
303 * for dosetattr / update_va
305 #define SETATTR_CHSIZE 0x01
306 #define SETATTR_ASYNC 0x02
308 #define ERROUT(err) \
312 } while (/*CONSTCOND*/0)
315 * This is a generic vnode operation handler. It checks if the necessary
316 * operations for the called vnode operation are implemented by userspace
317 * and either returns a dummy return value or proceeds to call the real
318 * vnode operation from puffs_msgop_v.
320 * XXX: this should described elsewhere and autogenerated, the complexity
321 * of the vnode operations vectors and their interrelationships is also
322 * getting a bit out of hand. Another problem is that we need this same
323 * information in the fs server code, so keeping the two in sync manually
324 * is not a viable (long term) plan.
327 /* not supported, handle locking protocol */
328 #define CHECKOP_NOTSUPP(op) \
329 case VOP_##op##_DESCOFFSET: \
330 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
331 return genfs_eopnotsupp(v); \
334 /* always succeed, no locking */
335 #define CHECKOP_SUCCESS(op) \
336 case VOP_##op##_DESCOFFSET: \
337 if (pmp->pmp_vnopmask[PUFFS_VN_##op] == 0) \
342 puffs_vnop_checkop(void *v
)
344 struct vop_generic_args
/* {
345 struct vnodeop_desc *a_desc;
346 spooky mystery contents;
348 struct vnodeop_desc
*desc
= ap
->a_desc
;
349 struct puffs_mount
*pmp
;
353 offset
= ap
->a_desc
->vdesc_vp_offsets
[0];
355 if (offset
== VDESC_NO_OFFSET
)
356 panic("puffs_checkop: no vnode, why did you call me?");
358 vp
= *VOPARG_OFFSETTO(struct vnode
**, offset
, ap
);
359 pmp
= MPTOPUFFSMP(vp
->v_mount
);
361 DPRINTF_VERBOSE(("checkop call %s (%d), vp %p\n",
362 ap
->a_desc
->vdesc_name
, ap
->a_desc
->vdesc_offset
, vp
));
365 switch (desc
->vdesc_offset
) {
366 CHECKOP_NOTSUPP(CREATE
);
367 CHECKOP_NOTSUPP(MKNOD
);
368 CHECKOP_NOTSUPP(GETATTR
);
369 CHECKOP_NOTSUPP(SETATTR
);
370 CHECKOP_NOTSUPP(READ
);
371 CHECKOP_NOTSUPP(WRITE
);
372 CHECKOP_NOTSUPP(FCNTL
);
373 CHECKOP_NOTSUPP(IOCTL
);
374 CHECKOP_NOTSUPP(REMOVE
);
375 CHECKOP_NOTSUPP(LINK
);
376 CHECKOP_NOTSUPP(RENAME
);
377 CHECKOP_NOTSUPP(MKDIR
);
378 CHECKOP_NOTSUPP(RMDIR
);
379 CHECKOP_NOTSUPP(SYMLINK
);
380 CHECKOP_NOTSUPP(READDIR
);
381 CHECKOP_NOTSUPP(READLINK
);
382 CHECKOP_NOTSUPP(PRINT
);
383 CHECKOP_NOTSUPP(PATHCONF
);
384 CHECKOP_NOTSUPP(GETEXTATTR
);
385 CHECKOP_NOTSUPP(SETEXTATTR
);
386 CHECKOP_NOTSUPP(LISTEXTATTR
);
387 CHECKOP_NOTSUPP(DELETEEXTATTR
);
389 CHECKOP_SUCCESS(ACCESS
);
390 CHECKOP_SUCCESS(CLOSE
);
391 CHECKOP_SUCCESS(SEEK
);
393 case VOP_GETPAGES_DESCOFFSET
:
394 if (!EXISTSOP(pmp
, READ
))
395 return genfs_eopnotsupp(v
);
399 panic("puffs_checkop: unhandled vnop %d",
404 rv
= VOCALL(puffs_msgop_p
, ap
->a_desc
->vdesc_offset
, v
);
406 DPRINTF_VERBOSE(("checkop return %s (%d), vp %p: %d\n",
407 ap
->a_desc
->vdesc_name
, ap
->a_desc
->vdesc_offset
, vp
, rv
));
412 static int callremove(struct puffs_mount
*, puffs_cookie_t
, puffs_cookie_t
,
413 struct componentname
*);
414 static int callrmdir(struct puffs_mount
*, puffs_cookie_t
, puffs_cookie_t
,
415 struct componentname
*);
416 static void callinactive(struct puffs_mount
*, puffs_cookie_t
, int);
417 static void callreclaim(struct puffs_mount
*, puffs_cookie_t
, int);
418 static int flushvncache(struct vnode
*, off_t
, off_t
, bool);
419 static void update_va(struct vnode
*, struct vattr
*, struct vattr
*,
420 struct timespec
*, struct timespec
*, int);
421 static void update_parent(struct vnode
*, struct vnode
*);
424 #define PUFFS_ABORT_LOOKUP 1
425 #define PUFFS_ABORT_CREATE 2
426 #define PUFFS_ABORT_MKNOD 3
427 #define PUFFS_ABORT_MKDIR 4
428 #define PUFFS_ABORT_SYMLINK 5
431 * Press the pani^Wabort button! Kernel resource allocation failed.
434 puffs_abortbutton(struct puffs_mount
*pmp
, int what
,
435 puffs_cookie_t dck
, puffs_cookie_t ck
, struct componentname
*cnp
)
439 case PUFFS_ABORT_CREATE
:
440 case PUFFS_ABORT_MKNOD
:
441 case PUFFS_ABORT_SYMLINK
:
442 callremove(pmp
, dck
, ck
, cnp
);
444 case PUFFS_ABORT_MKDIR
:
445 callrmdir(pmp
, dck
, ck
, cnp
);
449 callinactive(pmp
, ck
, 0);
450 callreclaim(pmp
, ck
, 1);
454 * Begin vnode operations.
456 * A word from the keymaster about locks: generally we don't want
457 * to use the vnode locks at all: it creates an ugly dependency between
458 * the userlandia file server and the kernel. But we'll play along with
459 * the kernel vnode locks for now. However, even currently we attempt
460 * to release locks as early as possible. This is possible for some
461 * operations which a) don't need a locked vnode after the userspace op
462 * and b) return with the vnode unlocked. Theoretically we could
463 * unlock-do op-lock for others and order the graph in userspace, but I
464 * don't want to think of the consequences for the time being.
467 #define TTL_TO_TIMEOUT(ts) \
468 (hardclock_ticks + (ts->tv_sec * hz) + (ts->tv_nsec * hz / 1000000000))
469 #define TTL_VALID(ts) \
470 ((ts != NULL) && !((ts->tv_sec == 0) && (ts->tv_nsec == 0)))
471 #define TIMED_OUT(expire) \
472 ((int)((unsigned int)hardclock_ticks - (unsigned int)expire) > 0)
474 puffs_vnop_lookup(void *v
)
476 struct vop_lookup_args
/* {
477 const struct vnodeop_desc *a_desc;
479 struct vnode **a_vpp;
480 struct componentname *a_cnp;
482 PUFFS_MSG_VARS(vn
, lookup
);
483 struct puffs_mount
*pmp
;
484 struct componentname
*cnp
;
485 struct vnode
*vp
, *dvp
, *cvp
;
486 struct puffs_node
*dpn
, *cpn
;
490 pmp
= MPTOPUFFSMP(ap
->a_dvp
->v_mount
);
497 /* r/o fs? we check create later to handle EEXIST */
498 if ((cnp
->cn_flags
& ISLASTCN
)
499 && (dvp
->v_mount
->mnt_flag
& MNT_RDONLY
)
500 && (cnp
->cn_nameiop
== DELETE
|| cnp
->cn_nameiop
== RENAME
))
503 isdot
= cnp
->cn_namelen
== 1 && *cnp
->cn_nameptr
== '.';
505 DPRINTF(("puffs_lookup: \"%s\", parent vnode %p, op: %x\n",
506 cnp
->cn_nameptr
, dvp
, cnp
->cn_nameiop
));
509 * If dotdot cache is enabled, unlock parent, lock ..
510 * (grand-parent) and relock parent.
512 if (PUFFS_USE_DOTDOTCACHE(pmp
) && (cnp
->cn_flags
& ISDOTDOT
)) {
515 vp
= VPTOPP(ap
->a_dvp
)->pn_parent
;
518 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
519 vn_lock(dvp
, LK_EXCLUSIVE
| LK_RETRY
);
526 * Check if someone fed it into the cache
528 if (!isdot
&& PUFFS_USE_NAMECACHE(pmp
)) {
529 int found
, iswhiteout
;
531 found
= cache_lookup(dvp
, cnp
->cn_nameptr
, cnp
->cn_namelen
,
532 cnp
->cn_nameiop
, cnp
->cn_flags
,
533 &iswhiteout
, ap
->a_vpp
);
535 cnp
->cn_flags
|= ISWHITEOUT
;
538 if (found
&& *ap
->a_vpp
!= NULLVP
&& PUFFS_USE_FS_TTL(pmp
)) {
542 if (TIMED_OUT(cpn
->pn_cn_timeout
)) {
545 * cached vnode (cvp) is still locked
546 * so that we can reuse it upon a new
555 * Do not use negative caching, since the filesystem
556 * provides no TTL for it.
558 if (found
&& *ap
->a_vpp
== NULLVP
&& PUFFS_USE_FS_TTL(pmp
))
562 return *ap
->a_vpp
== NULLVP
? ENOENT
: 0;
566 * This is what would have been left in ERROR before
567 * the rearrangement of cache_lookup(). What with all
568 * the macros, I am not sure if this is a dead value
575 /* deal with rename lookup semantics */
576 if (cnp
->cn_nameiop
== RENAME
&& (cnp
->cn_flags
& ISLASTCN
))
586 mutex_enter(&cpn
->pn_sizemtx
);
588 PUFFS_MSG_ALLOC(vn
, lookup
);
589 puffs_makecn(&lookup_msg
->pvnr_cn
, &lookup_msg
->pvnr_cn_cred
,
590 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
592 if (cnp
->cn_flags
& ISDOTDOT
)
595 puffs_msg_setinfo(park_lookup
, PUFFSOP_VN
,
596 PUFFS_VN_LOOKUP
, VPTOPNC(dvp
));
597 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_lookup
, dvp
->v_data
, NULL
, error
);
598 DPRINTF(("puffs_lookup: return of the userspace, part %d\n", error
));
601 * In case of error, there is no new vnode to play with, so be
602 * happy with the NULL value given to vpp in the beginning.
603 * Also, check if this really was an error or the target was not
604 * present. Either treat it as a non-error for CREATE/RENAME or
605 * enter the component into the negative name cache (if desired).
608 error
= checkerr(pmp
, error
, __func__
);
609 if (error
== ENOENT
) {
610 /* don't allow to create files on r/o fs */
611 if ((dvp
->v_mount
->mnt_flag
& MNT_RDONLY
)
612 && cnp
->cn_nameiop
== CREATE
) {
615 /* adjust values if we are creating */
616 } else if ((cnp
->cn_flags
& ISLASTCN
)
617 && (cnp
->cn_nameiop
== CREATE
618 || cnp
->cn_nameiop
== RENAME
)) {
621 /* save negative cache entry */
623 if (PUFFS_USE_NAMECACHE(pmp
) &&
624 !PUFFS_USE_FS_TTL(pmp
))
625 cache_enter(dvp
, NULL
, cnp
->cn_nameptr
,
626 cnp
->cn_namelen
, cnp
->cn_flags
);
633 * Check that we don't get our parent node back, that would cause
634 * a pretty obvious deadlock.
637 if (lookup_msg
->pvnr_newnode
== dpn
->pn_cookie
) {
638 puffs_senderr(pmp
, PUFFS_ERR_LOOKUP
, EINVAL
,
639 "lookup produced parent cookie", lookup_msg
->pvnr_newnode
);
645 * Check if we looked up the cached vnode
648 if (cvp
&& (VPTOPP(cvp
)->pn_cookie
== lookup_msg
->pvnr_newnode
)) {
652 * Bump grace time of this node so that it does not get
653 * reclaimed too fast. We try to increase a bit more the
654 * lifetime of busiest * nodes - with some limits.
656 grace
= 10 * puffs_sopreq_expire_timeout
;
657 cpn
->pn_cn_grace
= hardclock_ticks
+ grace
;
662 * No cached vnode available, or the cached vnode does not
663 * match the userland cookie anymore: is the node known?
666 error
= puffs_cookie2vnode(pmp
, lookup_msg
->pvnr_newnode
,
670 if (error
== PUFFS_NOSUCHCOOKIE
) {
671 error
= puffs_getvnode(dvp
->v_mount
,
672 lookup_msg
->pvnr_newnode
, lookup_msg
->pvnr_vtype
,
673 lookup_msg
->pvnr_size
, lookup_msg
->pvnr_rdev
, &vp
);
675 puffs_abortbutton(pmp
, PUFFS_ABORT_LOOKUP
,
676 VPTOPNC(dvp
), lookup_msg
->pvnr_newnode
,
681 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
683 puffs_abortbutton(pmp
, PUFFS_ABORT_LOOKUP
, VPTOPNC(dvp
),
684 lookup_msg
->pvnr_newnode
, ap
->a_cnp
);
689 * Update cache and TTL
691 if (PUFFS_USE_FS_TTL(pmp
)) {
692 struct timespec
*va_ttl
= &lookup_msg
->pvnr_va_ttl
;
693 struct timespec
*cn_ttl
= &lookup_msg
->pvnr_cn_ttl
;
694 update_va(vp
, NULL
, &lookup_msg
->pvnr_va
,
695 va_ttl
, cn_ttl
, SETATTR_CHSIZE
);
698 KASSERT(lookup_msg
->pvnr_newnode
== VPTOPP(vp
)->pn_cookie
);
701 if (PUFFS_USE_NAMECACHE(pmp
))
702 cache_enter(dvp
, vp
, cnp
->cn_nameptr
, cnp
->cn_namelen
,
706 if ((lookup_msg
->pvnr_cn
.pkcn_flags
& REQUIREDIR
) == 0)
707 cnp
->cn_flags
&= ~REQUIREDIR
;
708 if (lookup_msg
->pvnr_cn
.pkcn_consume
)
709 cnp
->cn_consume
= MIN(lookup_msg
->pvnr_cn
.pkcn_consume
,
710 strlen(cnp
->cn_nameptr
) - cnp
->cn_namelen
);
712 VPTOPP(vp
)->pn_nlookup
++;
714 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
715 (VPTOPP(vp
)->pn_parent
!= dvp
))
716 update_parent(vp
, dvp
);
720 mutex_exit(&cpn
->pn_sizemtx
);
722 if (error
|| (cvp
!= vp
))
726 if (cnp
->cn_flags
& ISDOTDOT
)
727 vn_lock(dvp
, LK_EXCLUSIVE
| LK_RETRY
);
729 DPRINTF(("puffs_lookup: returning %d %p\n", error
, *ap
->a_vpp
));
730 PUFFS_MSG_RELEASE(lookup
);
734 #define REFPN_AND_UNLOCKVP(a, b) \
736 mutex_enter(&b->pn_mtx); \
737 puffs_referencenode(b); \
738 mutex_exit(&b->pn_mtx); \
740 } while (/*CONSTCOND*/0)
744 mutex_enter(&b->pn_mtx); \
745 puffs_referencenode(b); \
746 mutex_exit(&b->pn_mtx); \
747 } while (/*CONSTCOND*/0)
749 #define RELEPN_AND_VP(a, b) \
751 puffs_releasenode(b); \
753 } while (/*CONSTCOND*/0)
756 puffs_vnop_create(void *v
)
758 struct vop_create_args
/* {
759 const struct vnodeop_desc *a_desc;
761 struct vnode **a_vpp;
762 struct componentname *a_cnp;
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
);
773 DPRINTF(("puffs_create: dvp %p, cnp: %s\n",
774 dvp
, ap
->a_cnp
->cn_nameptr
));
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
);
784 error
= checkerr(pmp
, error
, __func__
);
788 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
789 create_msg
->pvnr_newnode
, cnp
, ap
->a_vap
->va_type
, 0);
791 puffs_abortbutton(pmp
, PUFFS_ABORT_CREATE
, dpn
->pn_cookie
,
792 create_msg
->pvnr_newnode
, cnp
);
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
;
801 update_va(*ap
->a_vpp
, NULL
, rvap
,
802 va_ttl
, cn_ttl
, SETATTR_CHSIZE
);
805 VPTOPP(*ap
->a_vpp
)->pn_nlookup
++;
807 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
808 (VPTOPP(*ap
->a_vpp
)->pn_parent
!= dvp
))
809 update_parent(*ap
->a_vpp
, dvp
);
814 DPRINTF(("puffs_create: return %d\n", error
));
815 PUFFS_MSG_RELEASE(create
);
820 puffs_vnop_mknod(void *v
)
822 struct vop_mknod_args
/* {
823 const struct vnodeop_desc *a_desc;
825 struct vnode **a_vpp;
826 struct componentname *a_cnp;
829 PUFFS_MSG_VARS(vn
, mknod
);
830 struct vnode
*dvp
= ap
->a_dvp
;
831 struct puffs_node
*dpn
= VPTOPP(dvp
);
832 struct componentname
*cnp
= ap
->a_cnp
;
833 struct mount
*mp
= dvp
->v_mount
;
834 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
837 PUFFS_MSG_ALLOC(vn
, mknod
);
838 puffs_makecn(&mknod_msg
->pvnr_cn
, &mknod_msg
->pvnr_cn_cred
,
839 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
840 mknod_msg
->pvnr_va
= *ap
->a_vap
;
841 puffs_msg_setinfo(park_mknod
, PUFFSOP_VN
,
842 PUFFS_VN_MKNOD
, VPTOPNC(dvp
));
844 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mknod
, dvp
->v_data
, NULL
, error
);
846 error
= checkerr(pmp
, error
, __func__
);
850 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
851 mknod_msg
->pvnr_newnode
, cnp
, ap
->a_vap
->va_type
,
854 puffs_abortbutton(pmp
, PUFFS_ABORT_MKNOD
, dpn
->pn_cookie
,
855 mknod_msg
->pvnr_newnode
, cnp
);
859 if (PUFFS_USE_FS_TTL(pmp
)) {
860 struct timespec
*va_ttl
= &mknod_msg
->pvnr_va_ttl
;
861 struct timespec
*cn_ttl
= &mknod_msg
->pvnr_cn_ttl
;
862 struct vattr
*rvap
= &mknod_msg
->pvnr_va
;
864 update_va(*ap
->a_vpp
, NULL
, rvap
,
865 va_ttl
, cn_ttl
, SETATTR_CHSIZE
);
868 VPTOPP(*ap
->a_vpp
)->pn_nlookup
++;
870 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
871 (VPTOPP(*ap
->a_vpp
)->pn_parent
!= dvp
))
872 update_parent(*ap
->a_vpp
, dvp
);
876 PUFFS_MSG_RELEASE(mknod
);
881 puffs_vnop_open(void *v
)
883 struct vop_open_args
/* {
884 const struct vnodeop_desc *a_desc;
889 PUFFS_MSG_VARS(vn
, open
);
890 struct vnode
*vp
= ap
->a_vp
;
891 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
892 int mode
= ap
->a_mode
;
895 DPRINTF(("puffs_open: vp %p, mode 0x%x\n", vp
, mode
));
897 if (vp
->v_type
== VREG
&& mode
& FWRITE
&& !EXISTSOP(pmp
, WRITE
))
900 if (!EXISTSOP(pmp
, OPEN
))
903 PUFFS_MSG_ALLOC(vn
, open
);
904 open_msg
->pvnr_mode
= mode
;
905 puffs_credcvt(&open_msg
->pvnr_cred
, ap
->a_cred
);
906 puffs_msg_setinfo(park_open
, PUFFSOP_VN
,
907 PUFFS_VN_OPEN
, VPTOPNC(vp
));
909 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_open
, vp
->v_data
, NULL
, error
);
910 error
= checkerr(pmp
, error
, __func__
);
913 DPRINTF(("puffs_open: returning %d\n", error
));
914 PUFFS_MSG_RELEASE(open
);
919 puffs_vnop_close(void *v
)
921 struct vop_close_args
/* {
922 const struct vnodeop_desc *a_desc;
927 PUFFS_MSG_VARS(vn
, close
);
928 struct vnode
*vp
= ap
->a_vp
;
929 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
931 PUFFS_MSG_ALLOC(vn
, close
);
932 puffs_msg_setfaf(park_close
);
933 close_msg
->pvnr_fflag
= ap
->a_fflag
;
934 puffs_credcvt(&close_msg
->pvnr_cred
, ap
->a_cred
);
935 puffs_msg_setinfo(park_close
, PUFFSOP_VN
,
936 PUFFS_VN_CLOSE
, VPTOPNC(vp
));
938 puffs_msg_enqueue(pmp
, park_close
);
939 PUFFS_MSG_RELEASE(close
);
944 puffs_vnop_access(void *v
)
946 struct vop_access_args
/* {
947 const struct vnodeop_desc *a_desc;
952 PUFFS_MSG_VARS(vn
, access
);
953 struct vnode
*vp
= ap
->a_vp
;
954 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
955 int mode
= ap
->a_mode
;
959 switch (vp
->v_type
) {
963 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
964 || !EXISTSOP(pmp
, WRITE
))
972 if (!EXISTSOP(pmp
, ACCESS
))
975 PUFFS_MSG_ALLOC(vn
, access
);
976 access_msg
->pvnr_mode
= ap
->a_mode
;
977 puffs_credcvt(&access_msg
->pvnr_cred
, ap
->a_cred
);
978 puffs_msg_setinfo(park_access
, PUFFSOP_VN
,
979 PUFFS_VN_ACCESS
, VPTOPNC(vp
));
981 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_access
, vp
->v_data
, NULL
, error
);
982 error
= checkerr(pmp
, error
, __func__
);
983 PUFFS_MSG_RELEASE(access
);
989 update_va(struct vnode
*vp
, struct vattr
*vap
, struct vattr
*rvap
,
990 struct timespec
*va_ttl
, struct timespec
*cn_ttl
, int flags
)
992 struct puffs_node
*pn
= VPTOPP(vp
);
994 if (TTL_VALID(cn_ttl
)) {
995 pn
->pn_cn_timeout
= TTL_TO_TIMEOUT(cn_ttl
);
996 pn
->pn_cn_grace
= MAX(pn
->pn_cn_timeout
, pn
->pn_cn_grace
);
1000 * Don't listen to the file server regarding special device
1001 * size info, the file server doesn't know anything about them.
1003 if (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
)
1004 rvap
->va_size
= vp
->v_size
;
1006 /* Ditto for blocksize (ufs comment: this doesn't belong here) */
1007 if (vp
->v_type
== VBLK
)
1008 rvap
->va_blocksize
= BLKDEV_IOSIZE
;
1009 else if (vp
->v_type
== VCHR
)
1010 rvap
->va_blocksize
= MAXBSIZE
;
1013 (void) memcpy(vap
, rvap
, sizeof(struct vattr
));
1014 vap
->va_fsid
= vp
->v_mount
->mnt_stat
.f_fsidx
.__fsid_val
[0];
1016 if (pn
->pn_stat
& PNODE_METACACHE_ATIME
)
1017 vap
->va_atime
= pn
->pn_mc_atime
;
1018 if (pn
->pn_stat
& PNODE_METACACHE_CTIME
)
1019 vap
->va_ctime
= pn
->pn_mc_ctime
;
1020 if (pn
->pn_stat
& PNODE_METACACHE_MTIME
)
1021 vap
->va_mtime
= pn
->pn_mc_mtime
;
1022 if (pn
->pn_stat
& PNODE_METACACHE_SIZE
)
1023 vap
->va_size
= pn
->pn_mc_size
;
1026 if (!(pn
->pn_stat
& PNODE_METACACHE_SIZE
) && (flags
& SETATTR_CHSIZE
)) {
1027 if (rvap
->va_size
!= VNOVAL
1028 && vp
->v_type
!= VBLK
&& vp
->v_type
!= VCHR
) {
1029 uvm_vnp_setsize(vp
, rvap
->va_size
);
1030 pn
->pn_serversize
= rvap
->va_size
;
1034 if ((va_ttl
!= NULL
) && TTL_VALID(va_ttl
)) {
1035 if (pn
->pn_va_cache
== NULL
)
1036 pn
->pn_va_cache
= pool_get(&puffs_vapool
, PR_WAITOK
);
1038 (void)memcpy(pn
->pn_va_cache
, rvap
, sizeof(*rvap
));
1040 pn
->pn_va_timeout
= TTL_TO_TIMEOUT(va_ttl
);
1045 update_parent(struct vnode
*vp
, struct vnode
*dvp
)
1047 struct puffs_node
*pn
= VPTOPP(vp
);
1049 if (pn
->pn_parent
!= NULL
) {
1050 KASSERT(pn
->pn_parent
!= dvp
);
1051 vrele(pn
->pn_parent
);
1055 pn
->pn_parent
= dvp
;
1059 puffs_vnop_getattr(void *v
)
1061 struct vop_getattr_args
/* {
1062 const struct vnodeop_desc *a_desc;
1064 struct vattr *a_vap;
1065 kauth_cred_t a_cred;
1067 PUFFS_MSG_VARS(vn
, getattr
);
1068 struct vnode
*vp
= ap
->a_vp
;
1069 struct mount
*mp
= vp
->v_mount
;
1070 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
1071 struct vattr
*vap
, *rvap
;
1072 struct puffs_node
*pn
= VPTOPP(vp
);
1073 struct timespec
*va_ttl
= NULL
;
1077 * A lock is required so that we do not race with
1078 * setattr, write and fsync when changing vp->v_size.
1079 * This is critical, since setting a stall smaler value
1080 * triggers a file truncate in uvm_vnp_setsize(), which
1081 * most of the time means data corruption (a chunk of
1082 * data is replaced by zeroes). This can be removed if
1083 * we decide one day that VOP_GETATTR must operate on
1086 * XXX Should be useless now that VOP_GETATTR has been
1087 * fixed to always require a shared lock at least.
1089 mutex_enter(&pn
->pn_sizemtx
);
1094 if (PUFFS_USE_FS_TTL(pmp
)) {
1095 if (!TIMED_OUT(pn
->pn_va_timeout
)) {
1096 update_va(vp
, vap
, pn
->pn_va_cache
,
1097 NULL
, NULL
, SETATTR_CHSIZE
);
1102 PUFFS_MSG_ALLOC(vn
, getattr
);
1103 vattr_null(&getattr_msg
->pvnr_va
);
1104 puffs_credcvt(&getattr_msg
->pvnr_cred
, ap
->a_cred
);
1105 puffs_msg_setinfo(park_getattr
, PUFFSOP_VN
,
1106 PUFFS_VN_GETATTR
, VPTOPNC(vp
));
1108 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_getattr
, vp
->v_data
, NULL
, error
);
1109 error
= checkerr(pmp
, error
, __func__
);
1113 rvap
= &getattr_msg
->pvnr_va
;
1115 if (PUFFS_USE_FS_TTL(pmp
))
1116 va_ttl
= &getattr_msg
->pvnr_va_ttl
;
1118 update_va(vp
, vap
, rvap
, va_ttl
, NULL
, SETATTR_CHSIZE
);
1121 PUFFS_MSG_RELEASE(getattr
);
1124 puffs_releasenode(pn
);
1126 mutex_exit(&pn
->pn_sizemtx
);
1132 dosetattr(struct vnode
*vp
, struct vattr
*vap
, kauth_cred_t cred
, int flags
)
1134 PUFFS_MSG_VARS(vn
, setattr
);
1135 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1136 struct puffs_node
*pn
= vp
->v_data
;
1139 KASSERT(!(flags
& SETATTR_CHSIZE
) || mutex_owned(&pn
->pn_sizemtx
));
1141 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
) &&
1142 (vap
->va_uid
!= (uid_t
)VNOVAL
|| vap
->va_gid
!= (gid_t
)VNOVAL
1143 || vap
->va_atime
.tv_sec
!= VNOVAL
|| vap
->va_mtime
.tv_sec
!= VNOVAL
1144 || vap
->va_mode
!= (mode_t
)VNOVAL
))
1147 if ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
1148 && vp
->v_type
== VREG
&& vap
->va_size
!= VNOVAL
)
1152 * Flush metacache first. If we are called with some explicit
1153 * parameters, treat them as information overriding metacache
1156 if (pn
->pn_stat
& PNODE_METACACHE_MASK
) {
1157 if ((pn
->pn_stat
& PNODE_METACACHE_ATIME
)
1158 && vap
->va_atime
.tv_sec
== VNOVAL
)
1159 vap
->va_atime
= pn
->pn_mc_atime
;
1160 if ((pn
->pn_stat
& PNODE_METACACHE_CTIME
)
1161 && vap
->va_ctime
.tv_sec
== VNOVAL
)
1162 vap
->va_ctime
= pn
->pn_mc_ctime
;
1163 if ((pn
->pn_stat
& PNODE_METACACHE_MTIME
)
1164 && vap
->va_mtime
.tv_sec
== VNOVAL
)
1165 vap
->va_mtime
= pn
->pn_mc_mtime
;
1166 if ((pn
->pn_stat
& PNODE_METACACHE_SIZE
)
1167 && vap
->va_size
== VNOVAL
)
1168 vap
->va_size
= pn
->pn_mc_size
;
1170 pn
->pn_stat
&= ~PNODE_METACACHE_MASK
;
1174 * Flush attribute cache so that another thread do
1175 * not get a stale value during the operation.
1177 if (PUFFS_USE_FS_TTL(pmp
))
1178 pn
->pn_va_timeout
= 0;
1180 PUFFS_MSG_ALLOC(vn
, setattr
);
1181 (void)memcpy(&setattr_msg
->pvnr_va
, vap
, sizeof(struct vattr
));
1182 puffs_credcvt(&setattr_msg
->pvnr_cred
, cred
);
1183 puffs_msg_setinfo(park_setattr
, PUFFSOP_VN
,
1184 PUFFS_VN_SETATTR
, VPTOPNC(vp
));
1185 if (flags
& SETATTR_ASYNC
)
1186 puffs_msg_setfaf(park_setattr
);
1188 puffs_msg_enqueue(pmp
, park_setattr
);
1189 if ((flags
& SETATTR_ASYNC
) == 0)
1190 error
= puffs_msg_wait2(pmp
, park_setattr
, vp
->v_data
, NULL
);
1192 if ((error
== 0) && PUFFS_USE_FS_TTL(pmp
)) {
1193 struct timespec
*va_ttl
= &setattr_msg
->pvnr_va_ttl
;
1194 struct vattr
*rvap
= &setattr_msg
->pvnr_va
;
1196 update_va(vp
, NULL
, rvap
, va_ttl
, NULL
, flags
);
1199 PUFFS_MSG_RELEASE(setattr
);
1200 if ((flags
& SETATTR_ASYNC
) == 0) {
1201 error
= checkerr(pmp
, error
, __func__
);
1208 if (vap
->va_size
!= VNOVAL
) {
1209 pn
->pn_serversize
= vap
->va_size
;
1210 if (flags
& SETATTR_CHSIZE
)
1211 uvm_vnp_setsize(vp
, vap
->va_size
);
1218 puffs_vnop_setattr(void *v
)
1220 struct vop_getattr_args
/* {
1221 const struct vnodeop_desc *a_desc;
1223 struct vattr *a_vap;
1224 kauth_cred_t a_cred;
1226 struct puffs_node
*pn
= ap
->a_vp
->v_data
;
1229 mutex_enter(&pn
->pn_sizemtx
);
1230 error
= dosetattr(ap
->a_vp
, ap
->a_vap
, ap
->a_cred
, SETATTR_CHSIZE
);
1231 mutex_exit(&pn
->pn_sizemtx
);
1237 doinact(struct puffs_mount
*pmp
, int iaflag
)
1240 if (EXISTSOP(pmp
, INACTIVE
))
1241 if (pmp
->pmp_flags
& PUFFS_KFLAG_IAONDEMAND
)
1242 if (iaflag
|| ALLOPS(pmp
))
1253 callinactive(struct puffs_mount
*pmp
, puffs_cookie_t ck
, int iaflag
)
1255 PUFFS_MSG_VARS(vn
, inactive
);
1257 if (doinact(pmp
, iaflag
)) {
1258 PUFFS_MSG_ALLOC(vn
, inactive
);
1259 puffs_msg_setinfo(park_inactive
, PUFFSOP_VN
,
1260 PUFFS_VN_INACTIVE
, ck
);
1261 PUFFS_MSG_ENQUEUEWAIT_NOERROR(pmp
, park_inactive
);
1262 PUFFS_MSG_RELEASE(inactive
);
1266 /* XXX: callinactive can't setback */
1268 puffs_vnop_inactive(void *v
)
1270 struct vop_inactive_args
/* {
1271 const struct vnodeop_desc *a_desc;
1274 PUFFS_MSG_VARS(vn
, inactive
);
1275 struct vnode
*vp
= ap
->a_vp
;
1276 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1277 struct puffs_node
*pnode
;
1278 bool recycle
= false;
1281 mutex_enter(&pnode
->pn_sizemtx
);
1283 if (doinact(pmp
, pnode
->pn_stat
& PNODE_DOINACT
)) {
1284 flushvncache(vp
, 0, 0, false);
1285 PUFFS_MSG_ALLOC(vn
, inactive
);
1286 puffs_msg_setinfo(park_inactive
, PUFFSOP_VN
,
1287 PUFFS_VN_INACTIVE
, VPTOPNC(vp
));
1288 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp
, park_inactive
, vp
->v_data
,
1290 PUFFS_MSG_RELEASE(inactive
);
1292 pnode
->pn_stat
&= ~PNODE_DOINACT
;
1295 * file server thinks it's gone? then don't be afraid care,
1296 * node's life was already all it would ever be
1298 if (pnode
->pn_stat
& PNODE_NOREFS
) {
1299 pnode
->pn_stat
|= PNODE_DYING
;
1305 * If grace has already timed out, make it reclaimed.
1306 * Otherwise, we queue its expiration by sop thread, so
1307 * that it does not remain for ages in the freelist,
1308 * holding memory in userspace, while we will have
1309 * to look it up again anyway.
1311 if (PUFFS_USE_FS_TTL(pmp
) && !(vp
->v_vflag
& VV_ROOT
) && !recycle
) {
1312 bool incache
= !TIMED_OUT(pnode
->pn_cn_timeout
);
1313 bool ingrace
= !TIMED_OUT(pnode
->pn_cn_grace
);
1314 bool reclaimqueued
= pnode
->pn_stat
& PNODE_SOPEXP
;
1316 if (!incache
&& !ingrace
&& !reclaimqueued
) {
1317 pnode
->pn_stat
|= PNODE_DYING
;
1321 if (!recycle
&& !reclaimqueued
) {
1322 struct puffs_sopreq
*psopr
;
1323 int at
= MAX(pnode
->pn_cn_grace
, pnode
->pn_cn_timeout
);
1325 KASSERT(curlwp
!= uvm
.pagedaemon_lwp
);
1326 psopr
= kmem_alloc(sizeof(*psopr
), KM_SLEEP
);
1327 psopr
->psopr_ck
= VPTOPNC(pnode
->pn_vp
);
1328 psopr
->psopr_sopreq
= PUFFS_SOPREQ_EXPIRE
;
1329 psopr
->psopr_at
= at
;
1331 mutex_enter(&pmp
->pmp_sopmtx
);
1334 * If thread has disapeared, just give up. The
1335 * fs is being unmounted and the node will be
1336 * be reclaimed anyway.
1338 * Otherwise, we queue the request but do not
1339 * immediatly signal the thread, as the node
1340 * has not been expired yet.
1342 if (pmp
->pmp_sopthrcount
== 0) {
1343 kmem_free(psopr
, sizeof(*psopr
));
1345 TAILQ_INSERT_TAIL(&pmp
->pmp_sopnodereqs
,
1346 psopr
, psopr_entries
);
1347 pnode
->pn_stat
|= PNODE_SOPEXP
;
1350 mutex_exit(&pmp
->pmp_sopmtx
);
1354 *ap
->a_recycle
= recycle
;
1356 mutex_exit(&pnode
->pn_sizemtx
);
1363 callreclaim(struct puffs_mount
*pmp
, puffs_cookie_t ck
, int nlookup
)
1365 PUFFS_MSG_VARS(vn
, reclaim
);
1367 if (!EXISTSOP(pmp
, RECLAIM
))
1370 PUFFS_MSG_ALLOC(vn
, reclaim
);
1371 reclaim_msg
->pvnr_nlookup
= nlookup
;
1372 puffs_msg_setfaf(park_reclaim
);
1373 puffs_msg_setinfo(park_reclaim
, PUFFSOP_VN
, PUFFS_VN_RECLAIM
, ck
);
1375 puffs_msg_enqueue(pmp
, park_reclaim
);
1376 PUFFS_MSG_RELEASE(reclaim
);
1381 * always FAF, we don't really care if the server wants to fail to
1382 * reclaim the node or not
1385 puffs_vnop_reclaim(void *v
)
1387 struct vop_reclaim_args
/* {
1388 const struct vnodeop_desc *a_desc;
1391 struct vnode
*vp
= ap
->a_vp
;
1392 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1393 struct puffs_node
*pnode
= vp
->v_data
;
1394 bool notifyserver
= true;
1397 * first things first: check if someone is trying to reclaim the
1398 * root vnode. do not allow that to travel to userspace.
1399 * Note that we don't need to take the lock similarly to
1400 * puffs_root(), since there is only one of us.
1402 if (vp
->v_vflag
& VV_ROOT
) {
1403 mutex_enter(&pmp
->pmp_lock
);
1404 KASSERT(pmp
->pmp_root
!= NULL
);
1405 pmp
->pmp_root
= NULL
;
1406 mutex_exit(&pmp
->pmp_lock
);
1407 notifyserver
= false;
1411 * purge info from kernel before issueing FAF, since we
1412 * don't really know when we'll get around to it after
1413 * that and someone might race us into node creation
1415 mutex_enter(&pmp
->pmp_lock
);
1416 LIST_REMOVE(pnode
, pn_hashent
);
1417 if (PUFFS_USE_NAMECACHE(pmp
))
1419 mutex_exit(&pmp
->pmp_lock
);
1422 int nlookup
= VPTOPP(vp
)->pn_nlookup
;
1424 callreclaim(MPTOPUFFSMP(vp
->v_mount
), VPTOPNC(vp
), nlookup
);
1427 if (PUFFS_USE_DOTDOTCACHE(pmp
)) {
1428 if (__predict_true(VPTOPP(vp
)->pn_parent
!= NULL
))
1429 vrele(VPTOPP(vp
)->pn_parent
);
1431 KASSERT(vp
->v_vflag
& VV_ROOT
);
1440 #define CSIZE sizeof(**ap->a_cookies)
1442 puffs_vnop_readdir(void *v
)
1444 struct vop_readdir_args
/* {
1445 const struct vnodeop_desc *a_desc;
1448 kauth_cred_t a_cred;
1453 PUFFS_MSG_VARS(vn
, readdir
);
1454 struct vnode
*vp
= ap
->a_vp
;
1455 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1456 size_t argsize
, tomove
, cookiemem
, cookiesmax
;
1457 struct uio
*uio
= ap
->a_uio
;
1458 size_t howmuch
, resid
;
1462 * ok, so we need: resid + cookiemem = maxreq
1463 * => resid + cookiesize * (resid/minsize) = maxreq
1464 * => resid + cookiesize/minsize * resid = maxreq
1465 * => (cookiesize/minsize + 1) * resid = maxreq
1466 * => resid = maxreq / (cookiesize/minsize + 1)
1468 * Since cookiesize <= minsize and we're not very big on floats,
1469 * we approximate that to be 1. Therefore:
1471 * resid = maxreq / 2;
1473 * Well, at least we didn't have to use differential equations
1474 * or the Gram-Schmidt process.
1476 * (yes, I'm very afraid of this)
1478 KASSERT(CSIZE
<= _DIRENT_MINSIZE((struct dirent
*)0));
1480 if (ap
->a_cookies
) {
1481 KASSERT(ap
->a_ncookies
!= NULL
);
1482 if (pmp
->pmp_args
.pa_fhsize
== 0)
1484 resid
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
) / 2;
1485 cookiesmax
= resid
/_DIRENT_MINSIZE((struct dirent
*)0);
1486 cookiemem
= ALIGN(cookiesmax
*CSIZE
); /* play safe */
1488 resid
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
1493 argsize
= sizeof(struct puffs_vnmsg_readdir
);
1494 tomove
= resid
+ cookiemem
;
1495 puffs_msgmem_alloc(argsize
+ tomove
, &park_readdir
,
1496 (void *)&readdir_msg
, 1);
1498 puffs_credcvt(&readdir_msg
->pvnr_cred
, ap
->a_cred
);
1499 readdir_msg
->pvnr_offset
= uio
->uio_offset
;
1500 readdir_msg
->pvnr_resid
= resid
;
1501 readdir_msg
->pvnr_ncookies
= cookiesmax
;
1502 readdir_msg
->pvnr_eofflag
= 0;
1503 readdir_msg
->pvnr_dentoff
= cookiemem
;
1504 puffs_msg_setinfo(park_readdir
, PUFFSOP_VN
,
1505 PUFFS_VN_READDIR
, VPTOPNC(vp
));
1506 puffs_msg_setdelta(park_readdir
, tomove
);
1508 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_readdir
, vp
->v_data
, NULL
, error
);
1509 error
= checkerr(pmp
, error
, __func__
);
1513 /* userspace is cheating? */
1514 if (readdir_msg
->pvnr_resid
> resid
) {
1515 puffs_senderr(pmp
, PUFFS_ERR_READDIR
, E2BIG
,
1516 "resid grew", VPTOPNC(vp
));
1519 if (readdir_msg
->pvnr_ncookies
> cookiesmax
) {
1520 puffs_senderr(pmp
, PUFFS_ERR_READDIR
, E2BIG
,
1521 "too many cookies", VPTOPNC(vp
));
1526 if (readdir_msg
->pvnr_eofflag
)
1529 /* bouncy-wouncy with the directory data */
1530 howmuch
= resid
- readdir_msg
->pvnr_resid
;
1532 /* force eof if no data was returned (getcwd() needs this) */
1538 error
= uiomove(readdir_msg
->pvnr_data
+ cookiemem
, howmuch
, uio
);
1542 /* provide cookies to caller if so desired */
1543 if (ap
->a_cookies
) {
1544 KASSERT(curlwp
!= uvm
.pagedaemon_lwp
);
1545 *ap
->a_cookies
= malloc(readdir_msg
->pvnr_ncookies
*CSIZE
,
1547 *ap
->a_ncookies
= readdir_msg
->pvnr_ncookies
;
1548 memcpy(*ap
->a_cookies
, readdir_msg
->pvnr_data
,
1549 *ap
->a_ncookies
*CSIZE
);
1552 /* next readdir starts here */
1553 uio
->uio_offset
= readdir_msg
->pvnr_offset
;
1556 puffs_msgmem_release(park_readdir
);
1562 * poll works by consuming the bitmask in pn_revents. If there are
1563 * events available, poll returns immediately. If not, it issues a
1564 * poll to userspace, selrecords itself and returns with no available
1565 * events. When the file server returns, it executes puffs_parkdone_poll(),
1566 * where available events are added to the bitmask. selnotify() is
1567 * then also executed by that function causing us to enter here again
1568 * and hopefully find the missing bits (unless someone got them first,
1569 * in which case it starts all over again).
1572 puffs_vnop_poll(void *v
)
1574 struct vop_poll_args
/* {
1575 const struct vnodeop_desc *a_desc;
1579 PUFFS_MSG_VARS(vn
, poll
);
1580 struct vnode
*vp
= ap
->a_vp
;
1581 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1582 struct puffs_node
*pn
= vp
->v_data
;
1585 if (EXISTSOP(pmp
, POLL
)) {
1586 mutex_enter(&pn
->pn_mtx
);
1587 events
= pn
->pn_revents
& ap
->a_events
;
1588 if (events
& ap
->a_events
) {
1589 pn
->pn_revents
&= ~ap
->a_events
;
1590 mutex_exit(&pn
->pn_mtx
);
1594 puffs_referencenode(pn
);
1595 mutex_exit(&pn
->pn_mtx
);
1597 PUFFS_MSG_ALLOC(vn
, poll
);
1598 poll_msg
->pvnr_events
= ap
->a_events
;
1599 puffs_msg_setinfo(park_poll
, PUFFSOP_VN
,
1600 PUFFS_VN_POLL
, VPTOPNC(vp
));
1601 puffs_msg_setcall(park_poll
, puffs_parkdone_poll
, pn
);
1602 selrecord(curlwp
, &pn
->pn_sel
);
1604 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp
, park_poll
,
1606 PUFFS_MSG_RELEASE(poll
);
1611 return genfs_poll(v
);
1616 flushvncache(struct vnode
*vp
, off_t offlo
, off_t offhi
, bool wait
)
1618 struct puffs_node
*pn
= VPTOPP(vp
);
1622 /* flush out information from our metacache, see vop_setattr */
1623 if (pn
->pn_stat
& PNODE_METACACHE_MASK
1624 && (pn
->pn_stat
& PNODE_DYING
) == 0) {
1626 error
= dosetattr(vp
, &va
, FSCRED
,
1627 SETATTR_CHSIZE
| (wait
? 0 : SETATTR_ASYNC
));
1633 * flush pages to avoid being overly dirty
1635 pflags
= PGO_CLEANIT
;
1637 pflags
|= PGO_SYNCIO
;
1639 mutex_enter(vp
->v_interlock
);
1640 return VOP_PUTPAGES(vp
, trunc_page(offlo
), round_page(offhi
), pflags
);
1644 puffs_vnop_fsync(void *v
)
1646 struct vop_fsync_args
/* {
1647 const struct vnodeop_desc *a_desc;
1649 kauth_cred_t a_cred;
1654 PUFFS_MSG_VARS(vn
, fsync
);
1656 struct puffs_node
*pn
;
1657 struct puffs_mount
*pmp
;
1661 KASSERT(vp
!= NULL
);
1663 KASSERT(pn
!= NULL
);
1664 pmp
= MPTOPUFFSMP(vp
->v_mount
);
1665 if (ap
->a_flags
& FSYNC_WAIT
) {
1666 mutex_enter(&pn
->pn_sizemtx
);
1668 if (mutex_tryenter(&pn
->pn_sizemtx
) == 0)
1672 error
= flushvncache(vp
, ap
->a_offlo
, ap
->a_offhi
,
1673 (ap
->a_flags
& FSYNC_WAIT
) == FSYNC_WAIT
);
1678 * HELLO! We exit already here if the user server does not
1679 * support fsync OR if we should call fsync for a node which
1680 * has references neither in the kernel or the fs server.
1681 * Otherwise we continue to issue fsync() forward.
1684 if (!EXISTSOP(pmp
, FSYNC
) || (pn
->pn_stat
& PNODE_DYING
))
1687 dofaf
= (ap
->a_flags
& FSYNC_WAIT
) == 0 || ap
->a_flags
== FSYNC_LAZY
;
1689 * We abuse VXLOCK to mean "vnode is going to die", so we issue
1690 * only FAFs for those. Otherwise there's a danger of deadlock,
1691 * since the execution context here might be the user server
1692 * doing some operation on another fs, which in turn caused a
1693 * vnode to be reclaimed from the freelist for this fs.
1696 mutex_enter(vp
->v_interlock
);
1697 if (vp
->v_iflag
& VI_XLOCK
)
1699 mutex_exit(vp
->v_interlock
);
1702 PUFFS_MSG_ALLOC(vn
, fsync
);
1704 puffs_msg_setfaf(park_fsync
);
1706 puffs_credcvt(&fsync_msg
->pvnr_cred
, ap
->a_cred
);
1707 fsync_msg
->pvnr_flags
= ap
->a_flags
;
1708 fsync_msg
->pvnr_offlo
= ap
->a_offlo
;
1709 fsync_msg
->pvnr_offhi
= ap
->a_offhi
;
1710 puffs_msg_setinfo(park_fsync
, PUFFSOP_VN
,
1711 PUFFS_VN_FSYNC
, VPTOPNC(vp
));
1713 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_fsync
, vp
->v_data
, NULL
, error
);
1714 PUFFS_MSG_RELEASE(fsync
);
1716 error
= checkerr(pmp
, error
, __func__
);
1719 mutex_exit(&pn
->pn_sizemtx
);
1724 puffs_vnop_seek(void *v
)
1726 struct vop_seek_args
/* {
1727 const struct vnodeop_desc *a_desc;
1731 kauth_cred_t a_cred;
1733 PUFFS_MSG_VARS(vn
, seek
);
1734 struct vnode
*vp
= ap
->a_vp
;
1735 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
1738 PUFFS_MSG_ALLOC(vn
, seek
);
1739 seek_msg
->pvnr_oldoff
= ap
->a_oldoff
;
1740 seek_msg
->pvnr_newoff
= ap
->a_newoff
;
1741 puffs_credcvt(&seek_msg
->pvnr_cred
, ap
->a_cred
);
1742 puffs_msg_setinfo(park_seek
, PUFFSOP_VN
,
1743 PUFFS_VN_SEEK
, VPTOPNC(vp
));
1745 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_seek
, vp
->v_data
, NULL
, error
);
1746 PUFFS_MSG_RELEASE(seek
);
1747 return checkerr(pmp
, error
, __func__
);
1751 callremove(struct puffs_mount
*pmp
, puffs_cookie_t dck
, puffs_cookie_t ck
,
1752 struct componentname
*cnp
)
1754 PUFFS_MSG_VARS(vn
, remove
);
1757 PUFFS_MSG_ALLOC(vn
, remove
);
1758 remove_msg
->pvnr_cookie_targ
= ck
;
1759 puffs_makecn(&remove_msg
->pvnr_cn
, &remove_msg
->pvnr_cn_cred
,
1760 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1761 puffs_msg_setinfo(park_remove
, PUFFSOP_VN
, PUFFS_VN_REMOVE
, dck
);
1763 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_remove
, error
);
1764 PUFFS_MSG_RELEASE(remove
);
1766 return checkerr(pmp
, error
, __func__
);
1770 * XXX: can't use callremove now because can't catch setbacks with
1771 * it due to lack of a pnode argument.
1774 puffs_vnop_remove(void *v
)
1776 struct vop_remove_args
/* {
1777 const struct vnodeop_desc *a_desc;
1778 struct vnode *a_dvp;
1780 struct componentname *a_cnp;
1782 PUFFS_MSG_VARS(vn
, remove
);
1783 struct vnode
*dvp
= ap
->a_dvp
;
1784 struct vnode
*vp
= ap
->a_vp
;
1785 struct puffs_node
*dpn
= VPTOPP(dvp
);
1786 struct puffs_node
*pn
= VPTOPP(vp
);
1787 struct componentname
*cnp
= ap
->a_cnp
;
1788 struct mount
*mp
= dvp
->v_mount
;
1789 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
1792 PUFFS_MSG_ALLOC(vn
, remove
);
1793 remove_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1794 puffs_makecn(&remove_msg
->pvnr_cn
, &remove_msg
->pvnr_cn_cred
,
1795 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1796 puffs_msg_setinfo(park_remove
, PUFFSOP_VN
,
1797 PUFFS_VN_REMOVE
, VPTOPNC(dvp
));
1799 puffs_msg_enqueue(pmp
, park_remove
);
1800 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1804 REFPN_AND_UNLOCKVP(vp
, pn
);
1805 error
= puffs_msg_wait2(pmp
, park_remove
, dpn
, pn
);
1807 PUFFS_MSG_RELEASE(remove
);
1809 RELEPN_AND_VP(dvp
, dpn
);
1810 RELEPN_AND_VP(vp
, pn
);
1812 error
= checkerr(pmp
, error
, __func__
);
1817 puffs_vnop_mkdir(void *v
)
1819 struct vop_mkdir_args
/* {
1820 const struct vnodeop_desc *a_desc;
1821 struct vnode *a_dvp;
1822 struct vnode **a_vpp;
1823 struct componentname *a_cnp;
1824 struct vattr *a_vap;
1826 PUFFS_MSG_VARS(vn
, mkdir
);
1827 struct vnode
*dvp
= ap
->a_dvp
;
1828 struct puffs_node
*dpn
= VPTOPP(dvp
);
1829 struct componentname
*cnp
= ap
->a_cnp
;
1830 struct mount
*mp
= dvp
->v_mount
;
1831 struct puffs_mount
*pmp
= MPTOPUFFSMP(mp
);
1834 PUFFS_MSG_ALLOC(vn
, mkdir
);
1835 puffs_makecn(&mkdir_msg
->pvnr_cn
, &mkdir_msg
->pvnr_cn_cred
,
1836 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1837 mkdir_msg
->pvnr_va
= *ap
->a_vap
;
1838 puffs_msg_setinfo(park_mkdir
, PUFFSOP_VN
,
1839 PUFFS_VN_MKDIR
, VPTOPNC(dvp
));
1841 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mkdir
, dvp
->v_data
, NULL
, error
);
1843 error
= checkerr(pmp
, error
, __func__
);
1847 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
1848 mkdir_msg
->pvnr_newnode
, cnp
, VDIR
, 0);
1850 puffs_abortbutton(pmp
, PUFFS_ABORT_MKDIR
, dpn
->pn_cookie
,
1851 mkdir_msg
->pvnr_newnode
, cnp
);
1855 if (PUFFS_USE_FS_TTL(pmp
)) {
1856 struct timespec
*va_ttl
= &mkdir_msg
->pvnr_va_ttl
;
1857 struct timespec
*cn_ttl
= &mkdir_msg
->pvnr_cn_ttl
;
1858 struct vattr
*rvap
= &mkdir_msg
->pvnr_va
;
1860 update_va(*ap
->a_vpp
, NULL
, rvap
,
1861 va_ttl
, cn_ttl
, SETATTR_CHSIZE
);
1864 VPTOPP(*ap
->a_vpp
)->pn_nlookup
++;
1866 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
1867 (VPTOPP(*ap
->a_vpp
)->pn_parent
!= dvp
))
1868 update_parent(*ap
->a_vpp
, dvp
);
1872 PUFFS_MSG_RELEASE(mkdir
);
1877 callrmdir(struct puffs_mount
*pmp
, puffs_cookie_t dck
, puffs_cookie_t ck
,
1878 struct componentname
*cnp
)
1880 PUFFS_MSG_VARS(vn
, rmdir
);
1883 PUFFS_MSG_ALLOC(vn
, rmdir
);
1884 rmdir_msg
->pvnr_cookie_targ
= ck
;
1885 puffs_makecn(&rmdir_msg
->pvnr_cn
, &rmdir_msg
->pvnr_cn_cred
,
1886 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1887 puffs_msg_setinfo(park_rmdir
, PUFFSOP_VN
, PUFFS_VN_RMDIR
, dck
);
1889 PUFFS_MSG_ENQUEUEWAIT(pmp
, park_rmdir
, error
);
1890 PUFFS_MSG_RELEASE(rmdir
);
1892 return checkerr(pmp
, error
, __func__
);
1896 puffs_vnop_rmdir(void *v
)
1898 struct vop_rmdir_args
/* {
1899 const struct vnodeop_desc *a_desc;
1900 struct vnode *a_dvp;
1902 struct componentname *a_cnp;
1904 PUFFS_MSG_VARS(vn
, rmdir
);
1905 struct vnode
*dvp
= ap
->a_dvp
;
1906 struct vnode
*vp
= ap
->a_vp
;
1907 struct puffs_node
*dpn
= VPTOPP(dvp
);
1908 struct puffs_node
*pn
= VPTOPP(vp
);
1909 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1910 struct componentname
*cnp
= ap
->a_cnp
;
1913 PUFFS_MSG_ALLOC(vn
, rmdir
);
1914 rmdir_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1915 puffs_makecn(&rmdir_msg
->pvnr_cn
, &rmdir_msg
->pvnr_cn_cred
,
1916 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1917 puffs_msg_setinfo(park_rmdir
, PUFFSOP_VN
,
1918 PUFFS_VN_RMDIR
, VPTOPNC(dvp
));
1920 puffs_msg_enqueue(pmp
, park_rmdir
);
1921 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1922 REFPN_AND_UNLOCKVP(vp
, pn
);
1923 error
= puffs_msg_wait2(pmp
, park_rmdir
, dpn
, pn
);
1925 PUFFS_MSG_RELEASE(rmdir
);
1927 /* XXX: some call cache_purge() *for both vnodes* here, investigate */
1928 RELEPN_AND_VP(dvp
, dpn
);
1929 RELEPN_AND_VP(vp
, pn
);
1935 puffs_vnop_link(void *v
)
1937 struct vop_link_args
/* {
1938 const struct vnodeop_desc *a_desc;
1939 struct vnode *a_dvp;
1941 struct componentname *a_cnp;
1943 PUFFS_MSG_VARS(vn
, link
);
1944 struct vnode
*dvp
= ap
->a_dvp
;
1945 struct vnode
*vp
= ap
->a_vp
;
1946 struct puffs_node
*dpn
= VPTOPP(dvp
);
1947 struct puffs_node
*pn
= VPTOPP(vp
);
1948 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1949 struct componentname
*cnp
= ap
->a_cnp
;
1952 PUFFS_MSG_ALLOC(vn
, link
);
1953 link_msg
->pvnr_cookie_targ
= VPTOPNC(vp
);
1954 puffs_makecn(&link_msg
->pvnr_cn
, &link_msg
->pvnr_cn_cred
,
1955 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
1956 puffs_msg_setinfo(park_link
, PUFFSOP_VN
,
1957 PUFFS_VN_LINK
, VPTOPNC(dvp
));
1959 puffs_msg_enqueue(pmp
, park_link
);
1960 REFPN_AND_UNLOCKVP(dvp
, dpn
);
1962 error
= puffs_msg_wait2(pmp
, park_link
, dpn
, pn
);
1964 PUFFS_MSG_RELEASE(link
);
1966 error
= checkerr(pmp
, error
, __func__
);
1969 * XXX: stay in touch with the cache. I don't like this, but
1970 * don't have a better solution either. See also puffs_rename().
1973 puffs_updatenode(pn
, PUFFS_UPDATECTIME
, 0);
1975 RELEPN_AND_VP(dvp
, dpn
);
1976 puffs_releasenode(pn
);
1982 puffs_vnop_symlink(void *v
)
1984 struct vop_symlink_args
/* {
1985 const struct vnodeop_desc *a_desc;
1986 struct vnode *a_dvp;
1987 struct vnode **a_vpp;
1988 struct componentname *a_cnp;
1989 struct vattr *a_vap;
1992 PUFFS_MSG_VARS(vn
, symlink
);
1993 struct vnode
*dvp
= ap
->a_dvp
;
1994 struct puffs_node
*dpn
= VPTOPP(dvp
);
1995 struct mount
*mp
= dvp
->v_mount
;
1996 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
1997 struct componentname
*cnp
= ap
->a_cnp
;
2002 PUFFS_MSG_ALLOC(vn
, symlink
);
2003 puffs_makecn(&symlink_msg
->pvnr_cn
, &symlink_msg
->pvnr_cn_cred
,
2004 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
2005 symlink_msg
->pvnr_va
= *ap
->a_vap
;
2006 (void)strlcpy(symlink_msg
->pvnr_link
, ap
->a_target
,
2007 sizeof(symlink_msg
->pvnr_link
));
2008 puffs_msg_setinfo(park_symlink
, PUFFSOP_VN
,
2009 PUFFS_VN_SYMLINK
, VPTOPNC(dvp
));
2011 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_symlink
, dvp
->v_data
, NULL
, error
);
2013 error
= checkerr(pmp
, error
, __func__
);
2017 error
= puffs_newnode(mp
, dvp
, ap
->a_vpp
,
2018 symlink_msg
->pvnr_newnode
, cnp
, VLNK
, 0);
2020 puffs_abortbutton(pmp
, PUFFS_ABORT_SYMLINK
, dpn
->pn_cookie
,
2021 symlink_msg
->pvnr_newnode
, cnp
);
2025 if (PUFFS_USE_FS_TTL(pmp
)) {
2026 struct timespec
*va_ttl
= &symlink_msg
->pvnr_va_ttl
;
2027 struct timespec
*cn_ttl
= &symlink_msg
->pvnr_cn_ttl
;
2028 struct vattr
*rvap
= &symlink_msg
->pvnr_va
;
2030 update_va(*ap
->a_vpp
, NULL
, rvap
,
2031 va_ttl
, cn_ttl
, SETATTR_CHSIZE
);
2034 VPTOPP(*ap
->a_vpp
)->pn_nlookup
++;
2036 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
2037 (VPTOPP(*ap
->a_vpp
)->pn_parent
!= dvp
))
2038 update_parent(*ap
->a_vpp
, dvp
);
2042 PUFFS_MSG_RELEASE(symlink
);
2048 puffs_vnop_readlink(void *v
)
2050 struct vop_readlink_args
/* {
2051 const struct vnodeop_desc *a_desc;
2054 kauth_cred_t a_cred;
2056 PUFFS_MSG_VARS(vn
, readlink
);
2057 struct vnode
*vp
= ap
->a_vp
;
2058 struct puffs_mount
*pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
2062 PUFFS_MSG_ALLOC(vn
, readlink
);
2063 puffs_credcvt(&readlink_msg
->pvnr_cred
, ap
->a_cred
);
2064 linklen
= sizeof(readlink_msg
->pvnr_link
);
2065 readlink_msg
->pvnr_linklen
= linklen
;
2066 puffs_msg_setinfo(park_readlink
, PUFFSOP_VN
,
2067 PUFFS_VN_READLINK
, VPTOPNC(vp
));
2069 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_readlink
, vp
->v_data
, NULL
, error
);
2070 error
= checkerr(pmp
, error
, __func__
);
2074 /* bad bad user file server */
2075 if (readlink_msg
->pvnr_linklen
> linklen
) {
2076 puffs_senderr(pmp
, PUFFS_ERR_READLINK
, E2BIG
,
2077 "linklen too big", VPTOPNC(ap
->a_vp
));
2082 error
= uiomove(&readlink_msg
->pvnr_link
, readlink_msg
->pvnr_linklen
,
2085 PUFFS_MSG_RELEASE(readlink
);
2090 puffs_vnop_rename(void *v
)
2092 struct vop_rename_args
/* {
2093 const struct vnodeop_desc *a_desc;
2094 struct vnode *a_fdvp;
2095 struct vnode *a_fvp;
2096 struct componentname *a_fcnp;
2097 struct vnode *a_tdvp;
2098 struct vnode *a_tvp;
2099 struct componentname *a_tcnp;
2101 PUFFS_MSG_VARS(vn
, rename
);
2102 struct vnode
*fdvp
= ap
->a_fdvp
, *fvp
= ap
->a_fvp
;
2103 struct vnode
*tdvp
= ap
->a_tdvp
, *tvp
= ap
->a_tvp
;
2104 struct puffs_node
*fpn
= ap
->a_fvp
->v_data
;
2105 struct puffs_mount
*pmp
= MPTOPUFFSMP(fdvp
->v_mount
);
2107 bool doabort
= true;
2109 if ((fvp
->v_mount
!= tdvp
->v_mount
) ||
2110 (tvp
&& (fvp
->v_mount
!= tvp
->v_mount
))) {
2114 PUFFS_MSG_ALLOC(vn
, rename
);
2115 rename_msg
->pvnr_cookie_src
= VPTOPNC(fvp
);
2116 rename_msg
->pvnr_cookie_targdir
= VPTOPNC(tdvp
);
2118 rename_msg
->pvnr_cookie_targ
= VPTOPNC(tvp
);
2120 rename_msg
->pvnr_cookie_targ
= NULL
;
2121 puffs_makecn(&rename_msg
->pvnr_cn_src
, &rename_msg
->pvnr_cn_src_cred
,
2122 ap
->a_fcnp
, PUFFS_USE_FULLPNBUF(pmp
));
2123 puffs_makecn(&rename_msg
->pvnr_cn_targ
, &rename_msg
->pvnr_cn_targ_cred
,
2124 ap
->a_tcnp
, PUFFS_USE_FULLPNBUF(pmp
));
2125 puffs_msg_setinfo(park_rename
, PUFFSOP_VN
,
2126 PUFFS_VN_RENAME
, VPTOPNC(fdvp
));
2128 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rename
, fdvp
->v_data
, NULL
, error
);
2130 PUFFS_MSG_RELEASE(rename
);
2131 error
= checkerr(pmp
, error
, __func__
);
2134 * XXX: stay in touch with the cache. I don't like this, but
2135 * don't have a better solution either. See also puffs_link().
2138 puffs_updatenode(fpn
, PUFFS_UPDATECTIME
, 0);
2140 if (PUFFS_USE_DOTDOTCACHE(pmp
) &&
2141 (VPTOPP(fvp
)->pn_parent
!= tdvp
))
2142 update_parent(fvp
, tdvp
);
2148 VOP_ABORTOP(tdvp
, ap
->a_tcnp
);
2157 VOP_ABORTOP(fdvp
, ap
->a_fcnp
);
2164 #define RWARGS(cont, iofl, move, offset, creds) \
2165 (cont)->pvnr_ioflag = (iofl); \
2166 (cont)->pvnr_resid = (move); \
2167 (cont)->pvnr_offset = (offset); \
2168 puffs_credcvt(&(cont)->pvnr_cred, creds)
2171 puffs_vnop_read(void *v
)
2173 struct vop_read_args
/* {
2174 const struct vnodeop_desc *a_desc;
2178 kauth_cred_t a_cred;
2180 PUFFS_MSG_VARS(vn
, read
);
2181 struct vnode
*vp
= ap
->a_vp
;
2182 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2183 struct uio
*uio
= ap
->a_uio
;
2184 size_t tomove
, argsize
;
2192 if (uio
->uio_resid
== 0)
2194 if (uio
->uio_offset
< 0)
2197 if (vp
->v_type
== VREG
&& PUFFS_USE_PAGECACHE(pmp
)) {
2198 const int advice
= IO_ADV_DECODE(ap
->a_ioflag
);
2200 while (uio
->uio_resid
> 0) {
2201 if (vp
->v_size
<= uio
->uio_offset
) {
2204 bytelen
= MIN(uio
->uio_resid
,
2205 vp
->v_size
- uio
->uio_offset
);
2209 error
= ubc_uiomove(&vp
->v_uobj
, uio
, bytelen
, advice
,
2210 UBC_READ
| UBC_PARTIALOK
| UBC_UNMAP_FLAG(vp
));
2215 if ((vp
->v_mount
->mnt_flag
& MNT_NOATIME
) == 0)
2216 puffs_updatenode(VPTOPP(vp
), PUFFS_UPDATEATIME
, 0);
2219 * in case it's not a regular file or we're operating
2220 * uncached, do read in the old-fashioned style,
2221 * i.e. explicit read operations
2224 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
2225 argsize
= sizeof(struct puffs_vnmsg_read
);
2226 puffs_msgmem_alloc(argsize
+ tomove
, &park_read
,
2227 (void *)&read_msg
, 1);
2230 while (uio
->uio_resid
> 0) {
2231 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
2232 memset(read_msg
, 0, argsize
); /* XXX: touser KASSERT */
2233 RWARGS(read_msg
, ap
->a_ioflag
, tomove
,
2234 uio
->uio_offset
, ap
->a_cred
);
2235 puffs_msg_setinfo(park_read
, PUFFSOP_VN
,
2236 PUFFS_VN_READ
, VPTOPNC(vp
));
2237 puffs_msg_setdelta(park_read
, tomove
);
2239 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_read
, vp
->v_data
,
2241 error
= checkerr(pmp
, error
, __func__
);
2245 if (read_msg
->pvnr_resid
> tomove
) {
2246 puffs_senderr(pmp
, PUFFS_ERR_READ
,
2247 E2BIG
, "resid grew", VPTOPNC(ap
->a_vp
));
2252 error
= uiomove(read_msg
->pvnr_data
,
2253 tomove
- read_msg
->pvnr_resid
, uio
);
2256 * in case the file is out of juice, resid from
2257 * userspace is != 0. and the error-case is
2260 if (error
|| read_msg
->pvnr_resid
)
2264 puffs_msgmem_release(park_read
);
2271 * XXX: in case of a failure, this leaves uio in a bad state.
2272 * We could theoretically copy the uio and iovecs and "replay"
2273 * them the right amount after the userspace trip, but don't
2277 puffs_vnop_write(void *v
)
2279 struct vop_write_args
/* {
2280 const struct vnodeop_desc *a_desc;
2284 kauth_cred_t a_cred;
2286 PUFFS_MSG_VARS(vn
, write
);
2287 struct vnode
*vp
= ap
->a_vp
;
2288 struct puffs_node
*pn
= VPTOPP(vp
);
2289 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2290 struct uio
*uio
= ap
->a_uio
;
2291 size_t tomove
, argsize
;
2292 off_t oldoff
, newoff
, origoff
;
2300 mutex_enter(&pn
->pn_sizemtx
);
2302 if (vp
->v_type
== VREG
&& PUFFS_USE_PAGECACHE(pmp
)) {
2303 ubcflags
= UBC_WRITE
| UBC_PARTIALOK
| UBC_UNMAP_FLAG(vp
);
2306 * userspace *should* be allowed to control this,
2307 * but with UBC it's a bit unclear how to handle it
2309 if (ap
->a_ioflag
& IO_APPEND
)
2310 uio
->uio_offset
= vp
->v_size
;
2312 origoff
= uio
->uio_offset
;
2313 while (uio
->uio_resid
> 0) {
2314 if (vp
->v_mount
->mnt_flag
& MNT_RELATIME
)
2315 uflags
|= PUFFS_UPDATEATIME
;
2316 uflags
|= PUFFS_UPDATECTIME
;
2317 uflags
|= PUFFS_UPDATEMTIME
;
2318 oldoff
= uio
->uio_offset
;
2319 bytelen
= uio
->uio_resid
;
2321 newoff
= oldoff
+ bytelen
;
2322 if (vp
->v_size
< newoff
) {
2323 uvm_vnp_setwritesize(vp
, newoff
);
2325 error
= ubc_uiomove(&vp
->v_uobj
, uio
, bytelen
,
2326 UVM_ADV_RANDOM
, ubcflags
);
2329 * In case of a ubc_uiomove() error,
2330 * opt to not extend the file at all and
2331 * return an error. Otherwise, if we attempt
2332 * to clear the memory we couldn't fault to,
2333 * we might generate a kernel page fault.
2335 if (vp
->v_size
< newoff
) {
2337 uflags
|= PUFFS_UPDATESIZE
;
2338 uvm_vnp_setsize(vp
, newoff
);
2340 uvm_vnp_setwritesize(vp
, vp
->v_size
);
2347 * If we're writing large files, flush to file server
2348 * every 64k. Otherwise we can very easily exhaust
2349 * kernel and user memory, as the file server cannot
2350 * really keep up with our writing speed.
2352 * Note: this does *NOT* honor MNT_ASYNC, because
2353 * that gives userland too much say in the kernel.
2355 if (oldoff
>> 16 != uio
->uio_offset
>> 16) {
2356 mutex_enter(vp
->v_interlock
);
2357 error
= VOP_PUTPAGES(vp
, oldoff
& ~0xffff,
2358 uio
->uio_offset
& ~0xffff,
2359 PGO_CLEANIT
| PGO_SYNCIO
);
2365 /* synchronous I/O? */
2366 if (error
== 0 && ap
->a_ioflag
& IO_SYNC
) {
2367 mutex_enter(vp
->v_interlock
);
2368 error
= VOP_PUTPAGES(vp
, trunc_page(origoff
),
2369 round_page(uio
->uio_offset
),
2370 PGO_CLEANIT
| PGO_SYNCIO
);
2372 /* write through page cache? */
2373 } else if (error
== 0 && pmp
->pmp_flags
& PUFFS_KFLAG_WTCACHE
) {
2374 mutex_enter(vp
->v_interlock
);
2375 error
= VOP_PUTPAGES(vp
, trunc_page(origoff
),
2376 round_page(uio
->uio_offset
), PGO_CLEANIT
);
2379 puffs_updatenode(VPTOPP(vp
), uflags
, vp
->v_size
);
2381 /* tomove is non-increasing */
2382 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
2383 argsize
= sizeof(struct puffs_vnmsg_write
) + tomove
;
2384 puffs_msgmem_alloc(argsize
, &park_write
, (void *)&write_msg
,1);
2386 while (uio
->uio_resid
> 0) {
2387 /* move data to buffer */
2388 tomove
= PUFFS_TOMOVE(uio
->uio_resid
, pmp
);
2389 memset(write_msg
, 0, argsize
); /* XXX: touser KASSERT */
2390 RWARGS(write_msg
, ap
->a_ioflag
, tomove
,
2391 uio
->uio_offset
, ap
->a_cred
);
2392 error
= uiomove(write_msg
->pvnr_data
, tomove
, uio
);
2396 /* move buffer to userspace */
2397 puffs_msg_setinfo(park_write
, PUFFSOP_VN
,
2398 PUFFS_VN_WRITE
, VPTOPNC(vp
));
2399 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_write
, vp
->v_data
,
2401 error
= checkerr(pmp
, error
, __func__
);
2405 if (write_msg
->pvnr_resid
> tomove
) {
2406 puffs_senderr(pmp
, PUFFS_ERR_WRITE
,
2407 E2BIG
, "resid grew", VPTOPNC(ap
->a_vp
));
2412 /* adjust file size */
2413 if (vp
->v_size
< uio
->uio_offset
)
2414 uvm_vnp_setsize(vp
, uio
->uio_offset
);
2416 /* didn't move everything? bad userspace. bail */
2417 if (write_msg
->pvnr_resid
!= 0) {
2422 puffs_msgmem_release(park_write
);
2425 mutex_exit(&pn
->pn_sizemtx
);
2430 puffs_vnop_print(void *v
)
2432 struct vop_print_args
/* {
2435 PUFFS_MSG_VARS(vn
, print
);
2436 struct vnode
*vp
= ap
->a_vp
;
2437 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2438 struct puffs_node
*pn
= vp
->v_data
;
2440 /* kernel portion */
2441 printf("tag VT_PUFFS, vnode %p, puffs node: %p,\n"
2442 "\tuserspace cookie: %p", vp
, pn
, pn
->pn_cookie
);
2443 if (vp
->v_type
== VFIFO
)
2444 VOCALL(fifo_vnodeop_p
, VOFFSET(vop_print
), v
);
2447 /* userspace portion */
2448 if (EXISTSOP(pmp
, PRINT
)) {
2449 PUFFS_MSG_ALLOC(vn
, print
);
2450 puffs_msg_setinfo(park_print
, PUFFSOP_VN
,
2451 PUFFS_VN_PRINT
, VPTOPNC(vp
));
2452 PUFFS_MSG_ENQUEUEWAIT2_NOERROR(pmp
, park_print
, vp
->v_data
,
2454 PUFFS_MSG_RELEASE(print
);
2461 puffs_vnop_pathconf(void *v
)
2463 struct vop_pathconf_args
/* {
2464 const struct vnodeop_desc *a_desc;
2467 register_t *a_retval;
2469 PUFFS_MSG_VARS(vn
, pathconf
);
2470 struct vnode
*vp
= ap
->a_vp
;
2471 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2474 PUFFS_MSG_ALLOC(vn
, pathconf
);
2475 pathconf_msg
->pvnr_name
= ap
->a_name
;
2476 puffs_msg_setinfo(park_pathconf
, PUFFSOP_VN
,
2477 PUFFS_VN_PATHCONF
, VPTOPNC(vp
));
2478 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_pathconf
, vp
->v_data
, NULL
, error
);
2479 error
= checkerr(pmp
, error
, __func__
);
2481 *ap
->a_retval
= pathconf_msg
->pvnr_retval
;
2482 PUFFS_MSG_RELEASE(pathconf
);
2488 puffs_vnop_advlock(void *v
)
2490 struct vop_advlock_args
/* {
2491 const struct vnodeop_desc *a_desc;
2498 PUFFS_MSG_VARS(vn
, advlock
);
2499 struct vnode
*vp
= ap
->a_vp
;
2500 struct puffs_node
*pn
= VPTOPP(vp
);
2501 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2504 if (!EXISTSOP(pmp
, ADVLOCK
))
2505 return lf_advlock(ap
, &pn
->pn_lockf
, vp
->v_size
);
2507 PUFFS_MSG_ALLOC(vn
, advlock
);
2508 (void)memcpy(&advlock_msg
->pvnr_fl
, ap
->a_fl
,
2509 sizeof(advlock_msg
->pvnr_fl
));
2510 advlock_msg
->pvnr_id
= ap
->a_id
;
2511 advlock_msg
->pvnr_op
= ap
->a_op
;
2512 advlock_msg
->pvnr_flags
= ap
->a_flags
;
2513 puffs_msg_setinfo(park_advlock
, PUFFSOP_VN
,
2514 PUFFS_VN_ADVLOCK
, VPTOPNC(vp
));
2515 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_advlock
, vp
->v_data
, NULL
, error
);
2516 error
= checkerr(pmp
, error
, __func__
);
2517 PUFFS_MSG_RELEASE(advlock
);
2523 puffs_vnop_abortop(void *v
)
2525 struct vop_abortop_args
/* {
2526 struct vnode *a_dvp;
2527 struct componentname *a_cnp;
2529 PUFFS_MSG_VARS(vn
, abortop
);
2530 struct vnode
*dvp
= ap
->a_dvp
;
2531 struct puffs_mount
*pmp
= MPTOPUFFSMP(dvp
->v_mount
);
2532 struct componentname
*cnp
= ap
->a_cnp
;
2534 if (EXISTSOP(pmp
, ABORTOP
)) {
2535 PUFFS_MSG_ALLOC(vn
, abortop
);
2536 puffs_makecn(&abortop_msg
->pvnr_cn
, &abortop_msg
->pvnr_cn_cred
,
2537 cnp
, PUFFS_USE_FULLPNBUF(pmp
));
2538 puffs_msg_setfaf(park_abortop
);
2539 puffs_msg_setinfo(park_abortop
, PUFFSOP_VN
,
2540 PUFFS_VN_ABORTOP
, VPTOPNC(dvp
));
2542 puffs_msg_enqueue(pmp
, park_abortop
);
2543 PUFFS_MSG_RELEASE(abortop
);
2546 return genfs_abortop(v
);
2549 #define BIOASYNC(bp) (bp->b_flags & B_ASYNC)
2552 * This maps itself to PUFFS_VN_READ/WRITE for data transfer.
2555 puffs_vnop_strategy(void *v
)
2557 struct vop_strategy_args
/* {
2558 const struct vnodeop_desc *a_desc;
2562 PUFFS_MSG_VARS(vn
, rw
);
2563 struct vnode
*vp
= ap
->a_vp
;
2564 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2565 struct puffs_node
*pn
;
2568 size_t tomove
, moved
;
2569 int error
, dofaf
, cansleep
, dobiodone
;
2571 pmp
= MPTOPUFFSMP(vp
->v_mount
);
2577 park_rw
= NULL
; /* explicit */
2580 if ((BUF_ISREAD(bp
) && !EXISTSOP(pmp
, READ
))
2581 || (BUF_ISWRITE(bp
) && !EXISTSOP(pmp
, WRITE
)))
2585 * Short-circuit optimization: don't flush buffer in between
2586 * VOP_INACTIVE and VOP_RECLAIM in case the node has no references.
2588 if (pn
->pn_stat
& PNODE_DYING
) {
2589 KASSERT(BUF_ISWRITE(bp
));
2595 if (bp
->b_bcount
> pmp
->pmp_msg_maxsize
- PUFFS_MSGSTRUCT_MAX
)
2596 panic("puffs_strategy: wildly inappropriate buf bcount %d",
2601 * See explanation for the necessity of a FAF in puffs_fsync.
2603 * Also, do FAF in case we're suspending.
2604 * See puffs_vfsops.c:pageflush()
2606 if (BUF_ISWRITE(bp
)) {
2607 mutex_enter(vp
->v_interlock
);
2608 if (vp
->v_iflag
& VI_XLOCK
)
2610 if (pn
->pn_stat
& PNODE_FAF
)
2612 mutex_exit(vp
->v_interlock
);
2615 cansleep
= (curlwp
== uvm
.pagedaemon_lwp
|| dofaf
) ? 0 : 1;
2617 KASSERT(curlwp
!= uvm
.pagedaemon_lwp
|| dofaf
|| BIOASYNC(bp
));
2619 /* allocate transport structure */
2620 tomove
= PUFFS_TOMOVE(bp
->b_bcount
, pmp
);
2621 argsize
= sizeof(struct puffs_vnmsg_rw
);
2622 error
= puffs_msgmem_alloc(argsize
+ tomove
, &park_rw
,
2623 (void *)&rw_msg
, cansleep
);
2626 RWARGS(rw_msg
, 0, tomove
, bp
->b_blkno
<< DEV_BSHIFT
, FSCRED
);
2628 /* 2x2 cases: read/write, faf/nofaf */
2629 if (BUF_ISREAD(bp
)) {
2630 puffs_msg_setinfo(park_rw
, PUFFSOP_VN
,
2631 PUFFS_VN_READ
, VPTOPNC(vp
));
2632 puffs_msg_setdelta(park_rw
, tomove
);
2634 puffs_msg_setcall(park_rw
,
2635 puffs_parkdone_asyncbioread
, bp
);
2636 puffs_msg_enqueue(pmp
, park_rw
);
2639 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rw
, vp
->v_data
,
2641 error
= checkerr(pmp
, error
, __func__
);
2645 if (rw_msg
->pvnr_resid
> tomove
) {
2646 puffs_senderr(pmp
, PUFFS_ERR_READ
,
2647 E2BIG
, "resid grew", VPTOPNC(vp
));
2651 moved
= tomove
- rw_msg
->pvnr_resid
;
2653 (void)memcpy(bp
->b_data
, rw_msg
->pvnr_data
, moved
);
2654 bp
->b_resid
= bp
->b_bcount
- moved
;
2657 puffs_msg_setinfo(park_rw
, PUFFSOP_VN
,
2658 PUFFS_VN_WRITE
, VPTOPNC(vp
));
2660 * make pages read-only before we write them if we want
2661 * write caching info
2663 if (PUFFS_WCACHEINFO(pmp
)) {
2664 struct uvm_object
*uobj
= &vp
->v_uobj
;
2665 int npages
= (bp
->b_bcount
+ PAGE_SIZE
-1) >> PAGE_SHIFT
;
2666 struct vm_page
*vmp
;
2669 for (i
= 0; i
< npages
; i
++) {
2670 vmp
= uvm_pageratop((vaddr_t
)bp
->b_data
2671 + (i
<< PAGE_SHIFT
));
2672 DPRINTF(("puffs_strategy: write-protecting "
2673 "vp %p page %p, offset %" PRId64
"\n",
2674 vp
, vmp
, vmp
->offset
));
2675 mutex_enter(uobj
->vmobjlock
);
2676 vmp
->flags
|= PG_RDONLY
;
2677 pmap_page_protect(vmp
, VM_PROT_READ
);
2678 mutex_exit(uobj
->vmobjlock
);
2682 (void)memcpy(&rw_msg
->pvnr_data
, bp
->b_data
, tomove
);
2684 puffs_msg_setfaf(park_rw
);
2685 } else if (BIOASYNC(bp
)) {
2686 puffs_msg_setcall(park_rw
,
2687 puffs_parkdone_asyncbiowrite
, bp
);
2691 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_rw
, vp
->v_data
, NULL
, error
);
2697 * XXXXXXXX: wrong, but kernel can't survive strategy
2698 * failure currently. Here, have one more X: X.
2700 if (error
!= ENOMEM
)
2703 error
= checkerr(pmp
, error
, __func__
);
2707 if (rw_msg
->pvnr_resid
> tomove
) {
2708 puffs_senderr(pmp
, PUFFS_ERR_WRITE
,
2709 E2BIG
, "resid grew", VPTOPNC(vp
));
2714 * FAF moved everything. Frankly, we don't
2715 * really have a choice.
2717 if (dofaf
&& error
== 0)
2720 moved
= tomove
- rw_msg
->pvnr_resid
;
2722 bp
->b_resid
= bp
->b_bcount
- moved
;
2723 if (bp
->b_resid
!= 0) {
2730 puffs_msgmem_release(park_rw
);
2733 bp
->b_error
= error
;
2735 if (error
|| dobiodone
)
2742 puffs_vnop_mmap(void *v
)
2744 struct vop_mmap_args
/* {
2745 const struct vnodeop_desc *a_desc;
2748 kauth_cred_t a_cred;
2750 PUFFS_MSG_VARS(vn
, mmap
);
2751 struct vnode
*vp
= ap
->a_vp
;
2752 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2755 if (!PUFFS_USE_PAGECACHE(pmp
))
2756 return genfs_eopnotsupp(v
);
2758 if (EXISTSOP(pmp
, MMAP
)) {
2759 PUFFS_MSG_ALLOC(vn
, mmap
);
2760 mmap_msg
->pvnr_prot
= ap
->a_prot
;
2761 puffs_credcvt(&mmap_msg
->pvnr_cred
, ap
->a_cred
);
2762 puffs_msg_setinfo(park_mmap
, PUFFSOP_VN
,
2763 PUFFS_VN_MMAP
, VPTOPNC(vp
));
2765 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_mmap
, vp
->v_data
, NULL
, error
);
2766 error
= checkerr(pmp
, error
, __func__
);
2767 PUFFS_MSG_RELEASE(mmap
);
2769 error
= genfs_mmap(v
);
2777 * The rest don't get a free trip to userspace and back, they
2778 * have to stay within the kernel.
2782 * bmap doesn't really make any sense for puffs, so just 1:1 map it.
2783 * well, maybe somehow, somewhere, some day ....
2786 puffs_vnop_bmap(void *v
)
2788 struct vop_bmap_args
/* {
2789 const struct vnodeop_desc *a_desc;
2792 struct vnode **a_vpp;
2796 struct puffs_mount
*pmp
;
2798 pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
2801 *ap
->a_vpp
= ap
->a_vp
;
2803 *ap
->a_bnp
= ap
->a_bn
;
2806 = (PUFFS_TOMOVE(pmp
->pmp_msg_maxsize
, pmp
)>>DEV_BSHIFT
) - 1;
2812 * Handle getpages faults in puffs. We let genfs_getpages() do most
2813 * of the dirty work, but we come in this route to do accounting tasks.
2814 * If the user server has specified functions for cache notifications
2815 * about reads and/or writes, we record which type of operation we got,
2816 * for which page range, and proceed to issue a FAF notification to the
2820 puffs_vnop_getpages(void *v
)
2822 struct vop_getpages_args
/* {
2823 const struct vnodeop_desc *a_desc;
2826 struct vm_page **a_m;
2829 vm_prot_t a_access_type;
2833 struct puffs_mount
*pmp
;
2834 struct puffs_node
*pn
;
2836 struct vm_page
**pgs
;
2837 struct puffs_cacheinfo
*pcinfo
= NULL
;
2838 struct puffs_cacherun
*pcrun
;
2839 void *parkmem
= NULL
;
2841 int i
, npages
, si
, streakon
;
2842 int error
, locked
, write
;
2844 pmp
= MPTOPUFFSMP(ap
->a_vp
->v_mount
);
2845 npages
= *ap
->a_count
;
2849 locked
= (ap
->a_flags
& PGO_LOCKED
) != 0;
2850 write
= (ap
->a_access_type
& VM_PROT_WRITE
) != 0;
2852 /* ccg xnaht - gets Wuninitialized wrong */
2857 * Check that we aren't trying to fault in pages which our file
2858 * server doesn't know about. This happens if we extend a file by
2859 * skipping some pages and later try to fault in pages which
2860 * are between pn_serversize and vp_size. This check optimizes
2861 * away the common case where a file is being extended.
2863 if (ap
->a_offset
>= pn
->pn_serversize
&& ap
->a_offset
< vp
->v_size
) {
2866 /* try again later when we can block */
2870 mutex_exit(vp
->v_interlock
);
2872 va
.va_size
= vp
->v_size
;
2873 error
= dosetattr(vp
, &va
, FSCRED
, 0);
2876 mutex_enter(vp
->v_interlock
);
2879 if (write
&& PUFFS_WCACHEINFO(pmp
)) {
2881 /* allocate worst-case memory */
2882 runsizes
= ((npages
/ 2) + 1) * sizeof(struct puffs_cacherun
);
2883 KASSERT(curlwp
!= uvm
.pagedaemon_lwp
|| locked
);
2884 pcinfo
= kmem_zalloc(sizeof(struct puffs_cacheinfo
) + runsize
,
2885 locked
? KM_NOSLEEP
: KM_SLEEP
);
2888 * can't block if we're locked and can't mess up caching
2889 * information for fs server. so come back later, please
2894 parkmem
= puffs_park_alloc(locked
== 0);
2895 if (parkmem
== NULL
)
2898 pcrun
= pcinfo
->pcache_runs
;
2904 error
= genfs_getpages(v
);
2908 if (PUFFS_WCACHEINFO(pmp
) == 0)
2912 * Let's see whose fault it was and inform the user server of
2913 * possibly read/written pages. Map pages from read faults
2914 * strictly read-only, since otherwise we might miss info on
2915 * when the page is actually write-faulted to.
2918 mutex_enter(vp
->v_uobj
.vmobjlock
);
2919 for (i
= 0, si
= 0, streakon
= 0; i
< npages
; i
++) {
2920 if (pgs
[i
] == NULL
|| pgs
[i
] == PGO_DONTCARE
) {
2921 if (streakon
&& write
) {
2923 pcrun
[si
].pcache_runend
2924 = trunc_page(pgs
[i
]->offset
) + PAGE_MASK
;
2929 if (streakon
== 0 && write
) {
2931 pcrun
[si
].pcache_runstart
= pgs
[i
]->offset
;
2935 pgs
[i
]->flags
|= PG_RDONLY
;
2937 /* was the last page part of our streak? */
2939 pcrun
[si
].pcache_runend
2940 = trunc_page(pgs
[i
-1]->offset
) + PAGE_MASK
;
2944 mutex_exit(vp
->v_uobj
.vmobjlock
);
2946 KASSERT(si
<= (npages
/ 2) + 1);
2949 /* send results to userspace */
2951 puffs_cacheop(pmp
, parkmem
, pcinfo
,
2952 sizeof(struct puffs_cacheinfo
) + runsizes
, VPTOPNC(vp
));
2959 sizeof(struct puffs_cacheinfo
) + runsizes
);
2961 if (parkmem
!= NULL
)
2962 puffs_park_release(parkmem
, 1);
2970 * Extended attribute support.
2974 puffs_vnop_getextattr(void *v
)
2976 struct vop_getextattr_args
/*
2978 int a_attrnamespace;
2982 kauth_cred_t a_cred;
2984 PUFFS_MSG_VARS(vn
, getextattr
);
2985 struct vnode
*vp
= ap
->a_vp
;
2986 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
2987 int attrnamespace
= ap
->a_attrnamespace
;
2988 const char *name
= ap
->a_name
;
2989 struct uio
*uio
= ap
->a_uio
;
2990 size_t *sizep
= ap
->a_size
;
2991 size_t tomove
, resid
;
2995 resid
= uio
->uio_resid
;
2999 tomove
= PUFFS_TOMOVE(resid
, pmp
);
3000 if (tomove
!= resid
) {
3005 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_getextattr
) + tomove
,
3006 &park_getextattr
, (void *)&getextattr_msg
, 1);
3008 getextattr_msg
->pvnr_attrnamespace
= attrnamespace
;
3009 strlcpy(getextattr_msg
->pvnr_attrname
, name
,
3010 sizeof(getextattr_msg
->pvnr_attrname
));
3011 puffs_credcvt(&getextattr_msg
->pvnr_cred
, ap
->a_cred
);
3013 getextattr_msg
->pvnr_datasize
= 1;
3014 getextattr_msg
->pvnr_resid
= tomove
;
3016 puffs_msg_setinfo(park_getextattr
,
3017 PUFFSOP_VN
, PUFFS_VN_GETEXTATTR
, VPTOPNC(vp
));
3018 puffs_msg_setdelta(park_getextattr
, tomove
);
3019 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_getextattr
, vp
->v_data
, NULL
, error
);
3021 error
= checkerr(pmp
, error
, __func__
);
3025 resid
= getextattr_msg
->pvnr_resid
;
3026 if (resid
> tomove
) {
3027 puffs_senderr(pmp
, PUFFS_ERR_GETEXTATTR
, E2BIG
,
3028 "resid grew", VPTOPNC(vp
));
3034 *sizep
= getextattr_msg
->pvnr_datasize
;
3036 error
= uiomove(getextattr_msg
->pvnr_data
, tomove
- resid
, uio
);
3039 PUFFS_MSG_RELEASE(getextattr
);
3044 puffs_vnop_setextattr(void *v
)
3046 struct vop_setextattr_args
/* {
3048 int a_attrnamespace;
3051 kauth_cred_t a_cred;
3053 PUFFS_MSG_VARS(vn
, setextattr
);
3054 struct vnode
*vp
= ap
->a_vp
;
3055 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
3056 int attrnamespace
= ap
->a_attrnamespace
;
3057 const char *name
= ap
->a_name
;
3058 struct uio
*uio
= ap
->a_uio
;
3059 size_t tomove
, resid
;
3063 resid
= uio
->uio_resid
;
3067 tomove
= PUFFS_TOMOVE(resid
, pmp
);
3068 if (tomove
!= resid
) {
3073 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_setextattr
) + tomove
,
3074 &park_setextattr
, (void *)&setextattr_msg
, 1);
3076 setextattr_msg
->pvnr_attrnamespace
= attrnamespace
;
3077 strlcpy(setextattr_msg
->pvnr_attrname
, name
,
3078 sizeof(setextattr_msg
->pvnr_attrname
));
3079 puffs_credcvt(&setextattr_msg
->pvnr_cred
, ap
->a_cred
);
3080 setextattr_msg
->pvnr_resid
= tomove
;
3083 error
= uiomove(setextattr_msg
->pvnr_data
, tomove
, uio
);
3088 puffs_msg_setinfo(park_setextattr
,
3089 PUFFSOP_VN
, PUFFS_VN_SETEXTATTR
, VPTOPNC(vp
));
3090 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_setextattr
, vp
->v_data
, NULL
, error
);
3092 error
= checkerr(pmp
, error
, __func__
);
3096 if (setextattr_msg
->pvnr_resid
!= 0)
3100 PUFFS_MSG_RELEASE(setextattr
);
3106 puffs_vnop_listextattr(void *v
)
3108 struct vop_listextattr_args
/* {
3110 int a_attrnamespace;
3114 kauth_cred_t a_cred;
3116 PUFFS_MSG_VARS(vn
, listextattr
);
3117 struct vnode
*vp
= ap
->a_vp
;
3118 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
3119 int attrnamespace
= ap
->a_attrnamespace
;
3120 struct uio
*uio
= ap
->a_uio
;
3121 size_t *sizep
= ap
->a_size
;
3122 int flag
= ap
->a_flag
;
3123 size_t tomove
, resid
;
3127 resid
= uio
->uio_resid
;
3131 tomove
= PUFFS_TOMOVE(resid
, pmp
);
3132 if (tomove
!= resid
) {
3137 puffs_msgmem_alloc(sizeof(struct puffs_vnmsg_listextattr
) + tomove
,
3138 &park_listextattr
, (void *)&listextattr_msg
, 1);
3140 listextattr_msg
->pvnr_attrnamespace
= attrnamespace
;
3141 listextattr_msg
->pvnr_flag
= flag
;
3142 puffs_credcvt(&listextattr_msg
->pvnr_cred
, ap
->a_cred
);
3143 listextattr_msg
->pvnr_resid
= tomove
;
3145 listextattr_msg
->pvnr_datasize
= 1;
3147 puffs_msg_setinfo(park_listextattr
,
3148 PUFFSOP_VN
, PUFFS_VN_LISTEXTATTR
, VPTOPNC(vp
));
3149 puffs_msg_setdelta(park_listextattr
, tomove
);
3150 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_listextattr
, vp
->v_data
, NULL
, error
);
3152 error
= checkerr(pmp
, error
, __func__
);
3156 resid
= listextattr_msg
->pvnr_resid
;
3157 if (resid
> tomove
) {
3158 puffs_senderr(pmp
, PUFFS_ERR_LISTEXTATTR
, E2BIG
,
3159 "resid grew", VPTOPNC(vp
));
3165 *sizep
= listextattr_msg
->pvnr_datasize
;
3167 error
= uiomove(listextattr_msg
->pvnr_data
, tomove
-resid
, uio
);
3170 PUFFS_MSG_RELEASE(listextattr
);
3175 puffs_vnop_deleteextattr(void *v
)
3177 struct vop_deleteextattr_args
/* {
3179 int a_attrnamespace;
3181 kauth_cred_t a_cred;
3183 PUFFS_MSG_VARS(vn
, deleteextattr
);
3184 struct vnode
*vp
= ap
->a_vp
;
3185 struct puffs_mount
*pmp
= MPTOPUFFSMP(vp
->v_mount
);
3186 int attrnamespace
= ap
->a_attrnamespace
;
3187 const char *name
= ap
->a_name
;
3190 PUFFS_MSG_ALLOC(vn
, deleteextattr
);
3191 deleteextattr_msg
->pvnr_attrnamespace
= attrnamespace
;
3192 strlcpy(deleteextattr_msg
->pvnr_attrname
, name
,
3193 sizeof(deleteextattr_msg
->pvnr_attrname
));
3194 puffs_credcvt(&deleteextattr_msg
->pvnr_cred
, ap
->a_cred
);
3196 puffs_msg_setinfo(park_deleteextattr
,
3197 PUFFSOP_VN
, PUFFS_VN_DELETEEXTATTR
, VPTOPNC(vp
));
3198 PUFFS_MSG_ENQUEUEWAIT2(pmp
, park_deleteextattr
,
3199 vp
->v_data
, NULL
, error
);
3201 error
= checkerr(pmp
, error
, __func__
);
3203 PUFFS_MSG_RELEASE(deleteextattr
);
3208 * spec & fifo. These call the miscfs spec and fifo vectors, but issue
3209 * FAF update information for the puffs node first.
3212 puffs_vnop_spec_read(void *v
)
3214 struct vop_read_args
/* {
3215 const struct vnodeop_desc *a_desc;
3219 kauth_cred_t a_cred;
3222 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEATIME
, 0);
3223 return VOCALL(spec_vnodeop_p
, VOFFSET(vop_read
), v
);
3227 puffs_vnop_spec_write(void *v
)
3229 struct vop_write_args
/* {
3230 const struct vnodeop_desc *a_desc;
3234 kauth_cred_t a_cred;
3237 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEMTIME
, 0);
3238 return VOCALL(spec_vnodeop_p
, VOFFSET(vop_write
), v
);
3242 puffs_vnop_fifo_read(void *v
)
3244 struct vop_read_args
/* {
3245 const struct vnodeop_desc *a_desc;
3249 kauth_cred_t a_cred;
3252 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEATIME
, 0);
3253 return VOCALL(fifo_vnodeop_p
, VOFFSET(vop_read
), v
);
3257 puffs_vnop_fifo_write(void *v
)
3259 struct vop_write_args
/* {
3260 const struct vnodeop_desc *a_desc;
3264 kauth_cred_t a_cred;
3267 puffs_updatenode(VPTOPP(ap
->a_vp
), PUFFS_UPDATEMTIME
, 0);
3268 return VOCALL(fifo_vnodeop_p
, VOFFSET(vop_write
), v
);