coda_vnops.c revision 1.53 1 /*
2 coda_create/vn_open
3 remove/unlink
4 link
5 mkdir
6 rmdir
7 symlink
8 */
9 /* $NetBSD: coda_vnops.c,v 1.53 2007/04/05 12:48:51 gdt Exp $ */
10
11 /*
12 *
13 * Coda: an Experimental Distributed File System
14 * Release 3.1
15 *
16 * Copyright (c) 1987-1998 Carnegie Mellon University
17 * All Rights Reserved
18 *
19 * Permission to use, copy, modify and distribute this software and its
20 * documentation is hereby granted, provided that both the copyright
21 * notice and this permission notice appear in all copies of the
22 * software, derivative works or modified versions, and any portions
23 * thereof, and that both notices appear in supporting documentation, and
24 * that credit is given to Carnegie Mellon University in all documents
25 * and publicity pertaining to direct or indirect use of this code or its
26 * derivatives.
27 *
28 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
29 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
30 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
31 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
32 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
33 * ANY DERIVATIVE WORK.
34 *
35 * Carnegie Mellon encourages users of this software to return any
36 * improvements or extensions that they make, and to grant Carnegie
37 * Mellon the rights to redistribute these changes without encumbrance.
38 *
39 * @(#) coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
40 */
41
42 /*
43 * Mach Operating System
44 * Copyright (c) 1990 Carnegie-Mellon University
45 * Copyright (c) 1989 Carnegie-Mellon University
46 * All rights reserved. The CMU software License Agreement specifies
47 * the terms and conditions for use and redistribution.
48 */
49
50 /*
51 * This code was written for the Coda file system at Carnegie Mellon
52 * University. Contributers include David Steere, James Kistler, and
53 * M. Satyanarayanan.
54 */
55
56 #include <sys/cdefs.h>
57 __KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.53 2007/04/05 12:48:51 gdt Exp $");
58
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/malloc.h>
62 #include <sys/errno.h>
63 #include <sys/acct.h>
64 #include <sys/file.h>
65 #include <sys/uio.h>
66 #include <sys/namei.h>
67 #include <sys/ioctl.h>
68 #include <sys/mount.h>
69 #include <sys/proc.h>
70 #include <sys/select.h>
71 #include <sys/user.h>
72 #include <sys/kauth.h>
73
74 #include <miscfs/genfs/genfs.h>
75
76 #include <coda/coda.h>
77 #include <coda/cnode.h>
78 #include <coda/coda_vnops.h>
79 #include <coda/coda_venus.h>
80 #include <coda/coda_opstats.h>
81 #include <coda/coda_subr.h>
82 #include <coda/coda_namecache.h>
83 #include <coda/coda_pioctl.h>
84
85 /*
86 * These flags select various performance enhancements.
87 */
88 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
89 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
90 int coda_access_cache = 1; /* Set to handle some access checks directly */
91
92 /* structure to keep track of vfs calls */
93
94 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
95
96 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
97 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
98 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
99 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
100
101 /* What we are delaying for in printf */
102 int coda_printf_delay = 0; /* in microseconds */
103 int coda_vnop_print_entry = 0;
104 static int coda_lockdebug = 0;
105
106 /* Definition of the vfs operation vector */
107
108 /*
109 * Some NetBSD details:
110 *
111 * coda_start is called at the end of the mount syscall.
112 * coda_init is called at boot time.
113 */
114
115 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
116
117 /* Definition of the vnode operation vector */
118
119 const struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
120 { &vop_default_desc, coda_vop_error },
121 { &vop_lookup_desc, coda_lookup }, /* lookup */
122 { &vop_create_desc, coda_create }, /* create */
123 { &vop_mknod_desc, coda_vop_error }, /* mknod */
124 { &vop_open_desc, coda_open }, /* open */
125 { &vop_close_desc, coda_close }, /* close */
126 { &vop_access_desc, coda_access }, /* access */
127 { &vop_getattr_desc, coda_getattr }, /* getattr */
128 { &vop_setattr_desc, coda_setattr }, /* setattr */
129 { &vop_read_desc, coda_read }, /* read */
130 { &vop_write_desc, coda_write }, /* write */
131 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
132 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
133 /* 1.3 { &vop_select_desc, coda_select }, select */
134 { &vop_mmap_desc, genfs_mmap }, /* mmap */
135 { &vop_fsync_desc, coda_fsync }, /* fsync */
136 { &vop_remove_desc, coda_remove }, /* remove */
137 { &vop_link_desc, coda_link }, /* link */
138 { &vop_rename_desc, coda_rename }, /* rename */
139 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
140 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
141 { &vop_symlink_desc, coda_symlink }, /* symlink */
142 { &vop_readdir_desc, coda_readdir }, /* readdir */
143 { &vop_readlink_desc, coda_readlink }, /* readlink */
144 { &vop_abortop_desc, coda_abortop }, /* abortop */
145 { &vop_inactive_desc, coda_inactive }, /* inactive */
146 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
147 { &vop_lock_desc, coda_lock }, /* lock */
148 { &vop_unlock_desc, coda_unlock }, /* unlock */
149 { &vop_bmap_desc, coda_bmap }, /* bmap */
150 { &vop_strategy_desc, coda_strategy }, /* strategy */
151 { &vop_print_desc, coda_vop_error }, /* print */
152 { &vop_islocked_desc, coda_islocked }, /* islocked */
153 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
154 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
155 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
156 { &vop_lease_desc, coda_vop_nop }, /* lease */
157 { &vop_seek_desc, genfs_seek }, /* seek */
158 { &vop_poll_desc, genfs_poll }, /* poll */
159 { &vop_getpages_desc, coda_getpages }, /* getpages */
160 { &vop_putpages_desc, coda_putpages }, /* putpages */
161 { NULL, NULL }
162 };
163
164 const struct vnodeopv_desc coda_vnodeop_opv_desc =
165 { &coda_vnodeop_p, coda_vnodeop_entries };
166
167 /* Definitions of NetBSD vnodeop interfaces */
168
169 /* A generic panic: we were called with something we didn't define yet */
170 int
171 coda_vop_error(void *anon) {
172 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
173
174 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
175 (*desc)->vdesc_name));
176 /*
177 panic("coda_nbsd_vop_error");
178 return 0;
179 */
180 return EIO;
181 }
182
183 /* A generic do-nothing. For lease_check, advlock */
184 int
185 coda_vop_nop(void *anon) {
186 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
187
188 if (codadebug) {
189 myprintf(("Vnode operation %s called, but unsupported\n",
190 (*desc)->vdesc_name));
191 }
192 return (0);
193 }
194
195 int
196 coda_vnodeopstats_init(void)
197 {
198 int i;
199
200 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
201 coda_vnodeopstats[i].opcode = i;
202 coda_vnodeopstats[i].entries = 0;
203 coda_vnodeopstats[i].sat_intrn = 0;
204 coda_vnodeopstats[i].unsat_intrn = 0;
205 coda_vnodeopstats[i].gen_intrn = 0;
206 }
207
208 return 0;
209 }
210
211 /*
212 * coda_open calls Venus to return the device, inode pair of the cache
213 * file holding the data. Using iget, coda_open finds the vnode of the
214 * cache file, and then opens it.
215 */
216 int
217 coda_open(void *v)
218 {
219 /*
220 * NetBSD can pass the O_EXCL flag in mode, even though the check
221 * has already happened. Venus defensively assumes that if open
222 * is passed the EXCL, it must be a bug. We strip the flag here.
223 */
224 /* true args */
225 struct vop_open_args *ap = v;
226 struct vnode **vpp = &(ap->a_vp);
227 struct cnode *cp = VTOC(*vpp);
228 int flag = ap->a_mode & (~O_EXCL);
229 kauth_cred_t cred = ap->a_cred;
230 struct lwp *l = ap->a_l;
231 /* locals */
232 int error;
233 struct vnode *vp;
234 dev_t dev;
235 ino_t inode;
236
237 MARK_ENTRY(CODA_OPEN_STATS);
238
239 /* Check for open of control file. */
240 if (IS_CTL_VP(*vpp)) {
241 /* XXX */
242 /* if (WRITABLE(flag)) */
243 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
244 MARK_INT_FAIL(CODA_OPEN_STATS);
245 return(EACCES);
246 }
247 MARK_INT_SAT(CODA_OPEN_STATS);
248 return(0);
249 }
250
251 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, l, &dev, &inode);
252 if (error)
253 return (error);
254 if (!error) {
255 CODADEBUG( CODA_OPEN,myprintf(("open: dev %d inode %llu result %d\n",
256 dev, (unsigned long long)inode, error)); )
257 }
258
259 /* Translate the <device, inode> pair for the cache file into
260 an inode pointer. */
261 error = coda_grab_vnode(dev, inode, &vp);
262 if (error)
263 return (error);
264
265 /* We get the vnode back locked in both Mach and NetBSD. Needs unlocked */
266 VOP_UNLOCK(vp, 0);
267 /* Keep a reference until the close comes in. */
268 vref(*vpp);
269
270 /* Save the vnode pointer for the cache file. */
271 if (cp->c_ovp == NULL) {
272 cp->c_ovp = vp;
273 } else {
274 if (cp->c_ovp != vp)
275 panic("coda_open: cp->c_ovp != ITOV(ip)");
276 }
277 cp->c_ocount++;
278
279 /* Flush the attribute cached if writing the file. */
280 if (flag & FWRITE) {
281 cp->c_owrite++;
282 cp->c_flags &= ~C_VATTR;
283 }
284
285 /* Save the <device, inode> pair for the cache file to speed
286 up subsequent page_read's. */
287 cp->c_device = dev;
288 cp->c_inode = inode;
289
290 /* Open the cache file. */
291 error = VOP_OPEN(vp, flag, cred, l);
292 return(error);
293 }
294
295 /*
296 * Close the cache file used for I/O and notify Venus.
297 */
298 int
299 coda_close(void *v)
300 {
301 /* true args */
302 struct vop_close_args *ap = v;
303 struct vnode *vp = ap->a_vp;
304 struct cnode *cp = VTOC(vp);
305 int flag = ap->a_fflag;
306 kauth_cred_t cred = ap->a_cred;
307 struct lwp *l = ap->a_l;
308 /* locals */
309 int error;
310
311 MARK_ENTRY(CODA_CLOSE_STATS);
312
313 /* Check for close of control file. */
314 if (IS_CTL_VP(vp)) {
315 MARK_INT_SAT(CODA_CLOSE_STATS);
316 return(0);
317 }
318
319 if (IS_UNMOUNTING(cp)) {
320 if (cp->c_ovp) {
321 #ifdef CODA_VERBOSE
322 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
323 vp->v_usecount, cp->c_ovp, vp, cp);
324 #endif
325 #ifdef hmm
326 vgone(cp->c_ovp);
327 #else
328 vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
329 VOP_CLOSE(cp->c_ovp, flag, cred, l); /* Do errors matter here? */
330 vput(cp->c_ovp);
331 #endif
332 } else {
333 #ifdef CODA_VERBOSE
334 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
335 #endif
336 }
337 return ENODEV;
338 } else {
339 vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
340 VOP_CLOSE(cp->c_ovp, flag, cred, l); /* Do errors matter here? */
341 vput(cp->c_ovp);
342 }
343
344 if (--cp->c_ocount == 0)
345 cp->c_ovp = NULL;
346
347 if (flag & FWRITE) /* file was opened for write */
348 --cp->c_owrite;
349
350 error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, l);
351 vrele(CTOV(cp));
352
353 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
354 return(error);
355 }
356
357 int
358 coda_read(void *v)
359 {
360 struct vop_read_args *ap = v;
361
362 ENTRY;
363 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
364 ap->a_ioflag, ap->a_cred, curlwp));
365 }
366
367 int
368 coda_write(void *v)
369 {
370 struct vop_write_args *ap = v;
371
372 ENTRY;
373 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
374 ap->a_ioflag, ap->a_cred, curlwp));
375 }
376
377 int
378 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
379 kauth_cred_t cred, struct lwp *l)
380 {
381 /* upcall decl */
382 /* NOTE: container file operation!!! */
383 /* locals */
384 struct cnode *cp = VTOC(vp);
385 struct vnode *cfvp = cp->c_ovp;
386 struct proc *p = l->l_proc;
387 int opened_internally = 0;
388 int error = 0;
389
390 MARK_ENTRY(CODA_RDWR_STATS);
391
392 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %lu, %lld)\n", rw,
393 uiop->uio_iov->iov_base,
394 (unsigned long) uiop->uio_resid,
395 (long long) uiop->uio_offset)); )
396
397 /* Check for rdwr of control object. */
398 if (IS_CTL_VP(vp)) {
399 MARK_INT_FAIL(CODA_RDWR_STATS);
400 return(EINVAL);
401 }
402
403 /* Redirect the request to UFS. */
404
405 /*
406 * If file is not already open this must be a page
407 * {read,write} request. Iget the cache file's inode
408 * pointer if we still have its <device, inode> pair.
409 * Otherwise, we must do an internal open to derive the
410 * pair.
411 */
412 if (cfvp == NULL) {
413 /*
414 * If we're dumping core, do the internal open. Otherwise
415 * venus won't have the correct size of the core when
416 * it's completely written.
417 */
418 if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) {
419 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
420 if (error) {
421 MARK_INT_FAIL(CODA_RDWR_STATS);
422 return(error);
423 }
424 /*
425 * We get the vnode back locked in both Mach and
426 * NetBSD. Needs unlocked
427 */
428 VOP_UNLOCK(cfvp, 0);
429 }
430 else {
431 opened_internally = 1;
432 MARK_INT_GEN(CODA_OPEN_STATS);
433 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
434 cred, l);
435 #ifdef CODA_VERBOSE
436 printf("coda_rdwr: Internally Opening %p\n", vp);
437 #endif
438 if (error) {
439 MARK_INT_FAIL(CODA_RDWR_STATS);
440 return(error);
441 }
442 cfvp = cp->c_ovp;
443 }
444 }
445
446 /* Have UFS handle the call. */
447 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = %s, refcnt = %d\n",
448 coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); )
449
450 if (rw == UIO_READ) {
451 error = VOP_READ(cfvp, uiop, ioflag, cred);
452 } else {
453 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
454 }
455
456 if (error)
457 MARK_INT_FAIL(CODA_RDWR_STATS);
458 else
459 MARK_INT_SAT(CODA_RDWR_STATS);
460
461 /* Do an internal close if necessary. */
462 if (opened_internally) {
463 MARK_INT_GEN(CODA_CLOSE_STATS);
464 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, l);
465 }
466
467 /* Invalidate cached attributes if writing. */
468 if (rw == UIO_WRITE)
469 cp->c_flags &= ~C_VATTR;
470 return(error);
471 }
472
473 int
474 coda_ioctl(void *v)
475 {
476 /* true args */
477 struct vop_ioctl_args *ap = v;
478 struct vnode *vp = ap->a_vp;
479 int com = ap->a_command;
480 void *data = ap->a_data;
481 int flag = ap->a_fflag;
482 kauth_cred_t cred = ap->a_cred;
483 struct lwp *l = ap->a_l;
484 /* locals */
485 int error;
486 struct vnode *tvp;
487 struct nameidata ndp;
488 struct PioctlData *iap = (struct PioctlData *)data;
489
490 MARK_ENTRY(CODA_IOCTL_STATS);
491
492 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
493
494 /* Don't check for operation on a dying object, for ctlvp it
495 shouldn't matter */
496
497 /* Must be control object to succeed. */
498 if (!IS_CTL_VP(vp)) {
499 MARK_INT_FAIL(CODA_IOCTL_STATS);
500 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
501 return (EOPNOTSUPP);
502 }
503 /* Look up the pathname. */
504
505 /* Should we use the name cache here? It would get it from
506 lookupname sooner or later anyway, right? */
507
508 NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE,
509 iap->path, l);
510 error = namei(&ndp);
511 tvp = ndp.ni_vp;
512
513 if (error) {
514 MARK_INT_FAIL(CODA_IOCTL_STATS);
515 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
516 error));)
517 return(error);
518 }
519
520 /*
521 * Make sure this is a coda style cnode, but it may be a
522 * different vfsp
523 */
524 /* XXX: this totally violates the comment about vtagtype in vnode.h */
525 if (tvp->v_tag != VT_CODA) {
526 vrele(tvp);
527 MARK_INT_FAIL(CODA_IOCTL_STATS);
528 CODADEBUG(CODA_IOCTL,
529 myprintf(("coda_ioctl error: %s not a coda object\n",
530 iap->path));)
531 return(EINVAL);
532 }
533
534 if (iap->vi.in_size > VC_MAXDATASIZE) {
535 vrele(tvp);
536 return(EINVAL);
537 }
538 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, l);
539
540 if (error)
541 MARK_INT_FAIL(CODA_IOCTL_STATS);
542 else
543 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
544
545 vrele(tvp);
546 return(error);
547 }
548
549 /*
550 * To reduce the cost of a user-level venus;we cache attributes in
551 * the kernel. Each cnode has storage allocated for an attribute. If
552 * c_vattr is valid, return a reference to it. Otherwise, get the
553 * attributes from venus and store them in the cnode. There is some
554 * question if this method is a security leak. But I think that in
555 * order to make this call, the user must have done a lookup and
556 * opened the file, and therefore should already have access.
557 */
558 int
559 coda_getattr(void *v)
560 {
561 /* true args */
562 struct vop_getattr_args *ap = v;
563 struct vnode *vp = ap->a_vp;
564 struct cnode *cp = VTOC(vp);
565 struct vattr *vap = ap->a_vap;
566 kauth_cred_t cred = ap->a_cred;
567 struct lwp *l = ap->a_l;
568 /* locals */
569 int error;
570
571 MARK_ENTRY(CODA_GETATTR_STATS);
572
573 /* Check for getattr of control object. */
574 if (IS_CTL_VP(vp)) {
575 MARK_INT_FAIL(CODA_GETATTR_STATS);
576 return(ENOENT);
577 }
578
579 /* Check to see if the attributes have already been cached */
580 if (VALID_VATTR(cp)) {
581 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: %s\n",
582 coda_f2s(&cp->c_fid)));});
583 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
584 print_vattr(&cp->c_vattr); );
585
586 *vap = cp->c_vattr;
587 MARK_INT_SAT(CODA_GETATTR_STATS);
588 return(0);
589 }
590
591 error = venus_getattr(vtomi(vp), &cp->c_fid, cred, l, vap);
592
593 if (!error) {
594 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss %s: result %d\n",
595 coda_f2s(&cp->c_fid), error)); )
596
597 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
598 print_vattr(vap); );
599
600 /* If not open for write, store attributes in cnode */
601 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
602 cp->c_vattr = *vap;
603 cp->c_flags |= C_VATTR;
604 }
605
606 }
607 return(error);
608 }
609
610 int
611 coda_setattr(void *v)
612 {
613 /* true args */
614 struct vop_setattr_args *ap = v;
615 struct vnode *vp = ap->a_vp;
616 struct cnode *cp = VTOC(vp);
617 struct vattr *vap = ap->a_vap;
618 kauth_cred_t cred = ap->a_cred;
619 struct lwp *l = ap->a_l;
620 /* locals */
621 int error;
622
623 MARK_ENTRY(CODA_SETATTR_STATS);
624
625 /* Check for setattr of control object. */
626 if (IS_CTL_VP(vp)) {
627 MARK_INT_FAIL(CODA_SETATTR_STATS);
628 return(ENOENT);
629 }
630
631 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
632 print_vattr(vap);
633 }
634 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, l);
635
636 if (!error)
637 cp->c_flags &= ~C_VATTR;
638
639 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
640 return(error);
641 }
642
643 int
644 coda_access(void *v)
645 {
646 /* true args */
647 struct vop_access_args *ap = v;
648 struct vnode *vp = ap->a_vp;
649 struct cnode *cp = VTOC(vp);
650 int mode = ap->a_mode;
651 kauth_cred_t cred = ap->a_cred;
652 struct lwp *l = ap->a_l;
653 /* locals */
654 int error;
655
656 MARK_ENTRY(CODA_ACCESS_STATS);
657
658 /* Check for access of control object. Only read access is
659 allowed on it. */
660 if (IS_CTL_VP(vp)) {
661 /* bogus hack - all will be marked as successes */
662 MARK_INT_SAT(CODA_ACCESS_STATS);
663 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
664 ? 0 : EACCES);
665 }
666
667 /*
668 * if the file is a directory, and we are checking exec (eg lookup)
669 * access, and the file is in the namecache, then the user must have
670 * lookup access to it.
671 */
672 if (coda_access_cache) {
673 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
674 if (coda_nc_lookup(cp, ".", 1, cred)) {
675 MARK_INT_SAT(CODA_ACCESS_STATS);
676 return(0); /* it was in the cache */
677 }
678 }
679 }
680
681 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, l);
682
683 return(error);
684 }
685
686 /*
687 * CODA abort op, called after namei() when a CREATE/DELETE isn't actually
688 * done. If a buffer has been saved in anticipation of a coda_create or
689 * a coda_remove, delete it.
690 */
691 /* ARGSUSED */
692 int
693 coda_abortop(void *v)
694 {
695 /* true args */
696 struct vop_abortop_args /* {
697 struct vnode *a_dvp;
698 struct componentname *a_cnp;
699 } */ *ap = v;
700 /* upcall decl */
701 /* locals */
702
703 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
704 PNBUF_PUT(ap->a_cnp->cn_pnbuf);
705 return (0);
706 }
707
708 int
709 coda_readlink(void *v)
710 {
711 /* true args */
712 struct vop_readlink_args *ap = v;
713 struct vnode *vp = ap->a_vp;
714 struct cnode *cp = VTOC(vp);
715 struct uio *uiop = ap->a_uio;
716 kauth_cred_t cred = ap->a_cred;
717 /* locals */
718 struct lwp *l = curlwp;
719 int error;
720 char *str;
721 int len;
722
723 MARK_ENTRY(CODA_READLINK_STATS);
724
725 /* Check for readlink of control object. */
726 if (IS_CTL_VP(vp)) {
727 MARK_INT_FAIL(CODA_READLINK_STATS);
728 return(ENOENT);
729 }
730
731 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
732 uiop->uio_rw = UIO_READ;
733 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
734 if (error)
735 MARK_INT_FAIL(CODA_READLINK_STATS);
736 else
737 MARK_INT_SAT(CODA_READLINK_STATS);
738 return(error);
739 }
740
741 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, l, &str, &len);
742
743 if (!error) {
744 uiop->uio_rw = UIO_READ;
745 error = uiomove(str, len, uiop);
746
747 if (coda_symlink_cache) {
748 cp->c_symlink = str;
749 cp->c_symlen = len;
750 cp->c_flags |= C_SYMLINK;
751 } else
752 CODA_FREE(str, len);
753 }
754
755 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
756 return(error);
757 }
758
759 int
760 coda_fsync(void *v)
761 {
762 /* true args */
763 struct vop_fsync_args *ap = v;
764 struct vnode *vp = ap->a_vp;
765 struct cnode *cp = VTOC(vp);
766 kauth_cred_t cred = ap->a_cred;
767 struct lwp *l = ap->a_l;
768 /* locals */
769 struct vnode *convp = cp->c_ovp;
770 int error;
771
772 MARK_ENTRY(CODA_FSYNC_STATS);
773
774 /* Check for fsync on an unmounting object */
775 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
776 * after an unmount has been initiated. This is a Bad Thing,
777 * which we have to avoid. Not a legitimate failure for stats.
778 */
779 if (IS_UNMOUNTING(cp)) {
780 return(ENODEV);
781 }
782
783 /* Check for fsync of control object. */
784 if (IS_CTL_VP(vp)) {
785 MARK_INT_SAT(CODA_FSYNC_STATS);
786 return(0);
787 }
788
789 if (convp)
790 VOP_FSYNC(convp, cred, MNT_WAIT, 0, 0, l);
791
792 /*
793 * We can expect fsync on any vnode at all if venus is pruging it.
794 * Venus can't very well answer the fsync request, now can it?
795 * Hopefully, it won't have to, because hopefully, venus preserves
796 * the (possibly untrue) invariant that it never purges an open
797 * vnode. Hopefully.
798 */
799 if (cp->c_flags & C_PURGING) {
800 return(0);
801 }
802
803 error = venus_fsync(vtomi(vp), &cp->c_fid, cred, l);
804
805 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
806 return(error);
807 }
808
809 int
810 coda_inactive(void *v)
811 {
812 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
813 have a proc pointer. Oops. */
814 /* true args */
815 struct vop_inactive_args *ap = v;
816 struct vnode *vp = ap->a_vp;
817 struct cnode *cp = VTOC(vp);
818 kauth_cred_t cred __attribute__((unused)) = NULL;
819 struct lwp *l __attribute__((unused)) = curlwp;
820 /* upcall decl */
821 /* locals */
822
823 /* We don't need to send inactive to venus - DCS */
824 MARK_ENTRY(CODA_INACTIVE_STATS);
825
826 if (IS_CTL_VP(vp)) {
827 MARK_INT_SAT(CODA_INACTIVE_STATS);
828 return 0;
829 }
830
831 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %s, vfsp %p\n",
832 coda_f2s(&cp->c_fid), vp->v_mount));)
833
834 /* If an array has been allocated to hold the symlink, deallocate it */
835 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
836 if (cp->c_symlink == NULL)
837 panic("coda_inactive: null symlink pointer in cnode");
838
839 CODA_FREE(cp->c_symlink, cp->c_symlen);
840 cp->c_flags &= ~C_SYMLINK;
841 cp->c_symlen = 0;
842 }
843
844 /* Remove it from the table so it can't be found. */
845 coda_unsave(cp);
846 if (vp->v_mount->mnt_data == NULL) {
847 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
848 panic("badness in coda_inactive");
849 }
850
851 if (IS_UNMOUNTING(cp)) {
852 #ifdef DEBUG
853 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
854 if (cp->c_ovp != NULL)
855 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
856 vp->v_usecount, vp, cp);
857 #endif
858 lockmgr(&vp->v_lock, LK_RELEASE, &vp->v_interlock);
859 } else {
860 #ifdef OLD_DIAGNOSTIC
861 if (CTOV(cp)->v_usecount) {
862 panic("coda_inactive: nonzero reference count");
863 }
864 if (cp->c_ovp != NULL) {
865 panic("coda_inactive: cp->ovp != NULL");
866 }
867 #endif
868 VOP_UNLOCK(vp, 0);
869 vgone(vp);
870 }
871
872 MARK_INT_SAT(CODA_INACTIVE_STATS);
873 return(0);
874 }
875
876 /*
877 * Remote file system operations having to do with directory manipulation.
878 */
879
880 /*
881 * It appears that in NetBSD, lookup is supposed to return the vnode locked
882 */
883 int
884 coda_lookup(void *v)
885 {
886 /* true args */
887 struct vop_lookup_args *ap = v;
888 /* (locked) vnode of dir in which to do lookup */
889 struct vnode *dvp = ap->a_dvp;
890 struct cnode *dcp = VTOC(dvp);
891 /* output variable for result */
892 struct vnode **vpp = ap->a_vpp;
893 /* name to lookup */
894 struct componentname *cnp = ap->a_cnp;
895 kauth_cred_t cred = cnp->cn_cred;
896 struct lwp *l = cnp->cn_lwp;
897 /* locals */
898 struct cnode *cp;
899 const char *nm = cnp->cn_nameptr;
900 int len = cnp->cn_namelen;
901 int flags = cnp->cn_flags;
902 CodaFid VFid;
903 int vtype;
904 int error = 0;
905
906 MARK_ENTRY(CODA_LOOKUP_STATS);
907
908 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %s\n",
909 nm, coda_f2s(&dcp->c_fid))););
910
911 /*
912 * XXX componentname flags in MODMASK are not handled at all
913 */
914
915 /*
916 * The overall strategy is to switch on the lookup type and get a
917 * result vnode that is vref'd but not locked. Then, the code at
918 * exit: switches on ., .., and regular lookups and does the right
919 * locking.
920 */
921
922 /* Check for lookup of control object. */
923 if (IS_CTL_NAME(dvp, nm, len)) {
924 *vpp = coda_ctlvp;
925 vref(*vpp);
926 MARK_INT_SAT(CODA_LOOKUP_STATS);
927 goto exit;
928 }
929
930 /* Avoid trying to hand venus an unreasonably long name. */
931 if (len+1 > CODA_MAXNAMLEN) {
932 MARK_INT_FAIL(CODA_LOOKUP_STATS);
933 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %s (%s)\n",
934 coda_f2s(&dcp->c_fid), nm)););
935 *vpp = (struct vnode *)0;
936 error = EINVAL;
937 goto exit;
938 }
939
940 /*
941 * Try to resolve the lookup in the minicache. If that fails, ask
942 * venus to do the lookup. XXX The interaction between vnode
943 * locking and any locking that coda does is not clear.
944 */
945 cp = coda_nc_lookup(dcp, nm, len, cred);
946 if (cp) {
947 *vpp = CTOV(cp);
948 vref(*vpp);
949 CODADEBUG(CODA_LOOKUP,
950 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
951 } else {
952 /* The name wasn't cached, so ask Venus. */
953 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, l, &VFid, &vtype);
954
955 if (error) {
956 MARK_INT_FAIL(CODA_LOOKUP_STATS);
957 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %s (%s)%d\n",
958 coda_f2s(&dcp->c_fid), nm, error));)
959 *vpp = (struct vnode *)0;
960 } else {
961 MARK_INT_SAT(CODA_LOOKUP_STATS);
962 CODADEBUG(CODA_LOOKUP,
963 myprintf(("lookup: %s type %o result %d\n",
964 coda_f2s(&VFid), vtype, error)); )
965
966 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
967 *vpp = CTOV(cp);
968 /* vpp is now vrefed. */
969
970 /*
971 * Unless this vnode is marked CODA_NOCACHE, enter it into
972 * the coda name cache to avoid a future venus round-trip.
973 * XXX Interaction with componentname NOCACHE is unclear.
974 */
975 if (!(vtype & CODA_NOCACHE))
976 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
977 }
978 }
979
980 exit:
981 /*
982 * If we are creating, and this was the last name to be looked up,
983 * and the error was ENOENT, then make the leaf NULL and return
984 * success.
985 * XXX Check against new lookup rules.
986 */
987 if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
988 && (cnp->cn_flags & ISLASTCN)
989 && (error == ENOENT))
990 {
991 error = EJUSTRETURN;
992 cnp->cn_flags |= SAVENAME;
993 *ap->a_vpp = NULL;
994 }
995
996 /*
997 * If we are removing, and we are at the last element, and we
998 * found it, then we need to keep the name around so that the
999 * removal will go ahead as planned.
1000 * XXX Check against new lookup rules.
1001 */
1002 if ((cnp->cn_nameiop == DELETE)
1003 && (cnp->cn_flags & ISLASTCN)
1004 && !error)
1005 {
1006 cnp->cn_flags |= SAVENAME;
1007 }
1008
1009 /*
1010 * If the lookup succeeded, we must generally lock the returned
1011 * vnode. This could be a ., .., or normal lookup. See
1012 * vnodeops(9) for the details.
1013 */
1014 /*
1015 * XXX LK_RETRY is likely incorrect. Handle vn_lock failure
1016 * somehow, and remove LK_RETRY.
1017 */
1018 if (!error || (error == EJUSTRETURN)) {
1019 /* Lookup has a value and it isn't "."? */
1020 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1021 if (flags & ISDOTDOT)
1022 /* ..: unlock parent */
1023 VOP_UNLOCK(dvp, 0);
1024 /* all but .: lock child */
1025 vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY);
1026 if (flags & ISDOTDOT)
1027 /* ..: relock parent */
1028 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1029 }
1030 /* else .: leave dvp locked */
1031 } else {
1032 /* The lookup failed, so return NULL. Leave dvp locked. */
1033 *ap->a_vpp = NULL;
1034 }
1035 return(error);
1036 }
1037
1038 /*ARGSUSED*/
1039 int
1040 coda_create(void *v)
1041 {
1042 /* true args */
1043 struct vop_create_args *ap = v;
1044 struct vnode *dvp = ap->a_dvp;
1045 struct cnode *dcp = VTOC(dvp);
1046 struct vattr *va = ap->a_vap;
1047 int exclusive = 1;
1048 int mode = ap->a_vap->va_mode;
1049 struct vnode **vpp = ap->a_vpp;
1050 struct componentname *cnp = ap->a_cnp;
1051 kauth_cred_t cred = cnp->cn_cred;
1052 struct lwp *l = cnp->cn_lwp;
1053 /* locals */
1054 int error;
1055 struct cnode *cp;
1056 const char *nm = cnp->cn_nameptr;
1057 int len = cnp->cn_namelen;
1058 CodaFid VFid;
1059 struct vattr attr;
1060
1061 MARK_ENTRY(CODA_CREATE_STATS);
1062
1063 /* All creates are exclusive XXX */
1064 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1065
1066 /* Check for create of control object. */
1067 if (IS_CTL_NAME(dvp, nm, len)) {
1068 *vpp = (struct vnode *)0;
1069 MARK_INT_FAIL(CODA_CREATE_STATS);
1070 return(EACCES);
1071 }
1072
1073 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, l, &VFid, &attr);
1074
1075 if (!error) {
1076
1077 /* If this is an exclusive create, panic if the file already exists. */
1078 /* Venus should have detected the file and reported EEXIST. */
1079
1080 if ((exclusive == 1) &&
1081 (coda_find(&VFid) != NULL))
1082 panic("cnode existed for newly created file!");
1083
1084 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1085 *vpp = CTOV(cp);
1086
1087 /* Update va to reflect the new attributes. */
1088 (*va) = attr;
1089
1090 /* Update the attribute cache and mark it as valid */
1091 if (coda_attr_cache) {
1092 VTOC(*vpp)->c_vattr = attr;
1093 VTOC(*vpp)->c_flags |= C_VATTR;
1094 }
1095
1096 /* Invalidate the parent's attr cache, the modification time has changed */
1097 VTOC(dvp)->c_flags &= ~C_VATTR;
1098
1099 /* enter the new vnode in the Name Cache */
1100 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1101
1102 CODADEBUG(CODA_CREATE,
1103 myprintf(("create: %s, result %d\n",
1104 coda_f2s(&VFid), error)); )
1105 } else {
1106 *vpp = (struct vnode *)0;
1107 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1108 }
1109
1110 /* Locking strategy. */
1111 /*
1112 * In NetBSD, all creates must explicitly vput their dvp's. We'll
1113 * go ahead and use the LOCKLEAF flag of the cnp argument.
1114 * However, I'm pretty sure that create must return the leaf
1115 * locked; so there is a DIAGNOSTIC check to ensure that this is
1116 * true.
1117 */
1118 vput(dvp);
1119 if (!error) {
1120 if (cnp->cn_flags & LOCKLEAF) {
1121 if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1122 printf("coda_create: ");
1123 panic("unlocked parent but couldn't lock child");
1124 }
1125 }
1126 #ifdef OLD_DIAGNOSTIC
1127 else {
1128 printf("coda_create: LOCKLEAF not set!\n");
1129 }
1130 #endif
1131 }
1132 /* Have to free the previously saved name */
1133 /*
1134 * This condition is stolen from ufs_makeinode. I have no idea
1135 * why it's here, but what the hey...
1136 */
1137 if ((cnp->cn_flags & SAVESTART) == 0) {
1138 PNBUF_PUT(cnp->cn_pnbuf);
1139 }
1140 return(error);
1141 }
1142
1143 int
1144 coda_remove(void *v)
1145 {
1146 /* true args */
1147 struct vop_remove_args *ap = v;
1148 struct vnode *dvp = ap->a_dvp;
1149 struct cnode *cp = VTOC(dvp);
1150 struct componentname *cnp = ap->a_cnp;
1151 kauth_cred_t cred = cnp->cn_cred;
1152 struct lwp *l = cnp->cn_lwp;
1153 /* locals */
1154 int error;
1155 const char *nm = cnp->cn_nameptr;
1156 int len = cnp->cn_namelen;
1157 struct cnode *tp;
1158
1159 MARK_ENTRY(CODA_REMOVE_STATS);
1160
1161 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %s\n",
1162 nm, coda_f2s(&cp->c_fid))););
1163
1164 /* Remove the file's entry from the CODA Name Cache */
1165 /* We're being conservative here, it might be that this person
1166 * doesn't really have sufficient access to delete the file
1167 * but we feel zapping the entry won't really hurt anyone -- dcs
1168 */
1169 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1170 * exist, and one is removed, the link count on the other will be
1171 * off by 1. We could either invalidate the attrs if cached, or
1172 * fix them. I'll try to fix them. DCS 11/8/94
1173 */
1174 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1175 if (tp) {
1176 if (VALID_VATTR(tp)) { /* If attrs are cached */
1177 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1178 tp->c_vattr.va_nlink--;
1179 }
1180 }
1181
1182 coda_nc_zapfile(VTOC(dvp), nm, len);
1183 /* No need to flush it if it doesn't exist! */
1184 }
1185 /* Invalidate the parent's attr cache, the modification time has changed */
1186 VTOC(dvp)->c_flags &= ~C_VATTR;
1187
1188 /* Check for remove of control object. */
1189 if (IS_CTL_NAME(dvp, nm, len)) {
1190 MARK_INT_FAIL(CODA_REMOVE_STATS);
1191 return(ENOENT);
1192 }
1193
1194 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, l);
1195
1196 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1197
1198 /*
1199 * Regardless of what happens, we have to unconditionally drop
1200 * locks/refs on parent and child. (I hope). This is based on
1201 * what ufs_remove seems to be doing.
1202 */
1203 if (dvp == ap->a_vp) {
1204 vrele(ap->a_vp);
1205 } else {
1206 vput(ap->a_vp);
1207 }
1208 vput(dvp);
1209
1210 if ((cnp->cn_flags & SAVESTART) == 0) {
1211 PNBUF_PUT(cnp->cn_pnbuf);
1212 }
1213 return(error);
1214 }
1215
1216 int
1217 coda_link(void *v)
1218 {
1219 /* true args */
1220 struct vop_link_args *ap = v;
1221 struct vnode *vp = ap->a_vp;
1222 struct cnode *cp = VTOC(vp);
1223 struct vnode *tdvp = ap->a_dvp;
1224 struct cnode *tdcp = VTOC(tdvp);
1225 struct componentname *cnp = ap->a_cnp;
1226 kauth_cred_t cred = cnp->cn_cred;
1227 struct lwp *l = cnp->cn_lwp;
1228 /* locals */
1229 int error;
1230 const char *nm = cnp->cn_nameptr;
1231 int len = cnp->cn_namelen;
1232
1233 MARK_ENTRY(CODA_LINK_STATS);
1234
1235 if (codadebug & CODADBGMSK(CODA_LINK)) {
1236
1237 myprintf(("nb_link: vp fid: %s\n",
1238 coda_f2s(&cp->c_fid)));
1239 myprintf(("nb_link: tdvp fid: %s)\n",
1240 coda_f2s(&tdcp->c_fid)));
1241
1242 }
1243 if (codadebug & CODADBGMSK(CODA_LINK)) {
1244 myprintf(("link: vp fid: %s\n",
1245 coda_f2s(&cp->c_fid)));
1246 myprintf(("link: tdvp fid: %s\n",
1247 coda_f2s(&tdcp->c_fid)));
1248
1249 }
1250
1251 /* Check for link to/from control object. */
1252 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1253 MARK_INT_FAIL(CODA_LINK_STATS);
1254 return(EACCES);
1255 }
1256
1257 /*
1258 * According to the ufs_link operation here's the locking situation:
1259 * We enter with the thing called "dvp" (the directory) locked.
1260 * We must unconditionally drop locks on "dvp"
1261 *
1262 * We enter with the thing called "vp" (the linked-to) unlocked,
1263 * but ref'd (?)
1264 * We seem to need to lock it before calling coda_link, and
1265 * unconditionally unlock it after.
1266 */
1267
1268 if ((ap->a_vp != tdvp) && (error = vn_lock(ap->a_vp, LK_EXCLUSIVE))) {
1269 goto exit;
1270 }
1271
1272 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, l);
1273
1274 /* Invalidate the parent's attr cache, the modification time has changed */
1275 VTOC(tdvp)->c_flags &= ~C_VATTR;
1276 VTOC(vp)->c_flags &= ~C_VATTR;
1277
1278 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1279
1280 exit:
1281
1282 if (ap->a_vp != tdvp) {
1283 VOP_UNLOCK(ap->a_vp, 0);
1284 }
1285 vput(tdvp);
1286
1287 /* Drop the name buffer if we don't need to SAVESTART */
1288 if ((cnp->cn_flags & SAVESTART) == 0) {
1289 PNBUF_PUT(cnp->cn_pnbuf);
1290 }
1291 return(error);
1292 }
1293
1294 int
1295 coda_rename(void *v)
1296 {
1297 /* true args */
1298 struct vop_rename_args *ap = v;
1299 struct vnode *odvp = ap->a_fdvp;
1300 struct cnode *odcp = VTOC(odvp);
1301 struct componentname *fcnp = ap->a_fcnp;
1302 struct vnode *ndvp = ap->a_tdvp;
1303 struct cnode *ndcp = VTOC(ndvp);
1304 struct componentname *tcnp = ap->a_tcnp;
1305 kauth_cred_t cred = fcnp->cn_cred;
1306 struct lwp *l = fcnp->cn_lwp;
1307 /* true args */
1308 int error;
1309 const char *fnm = fcnp->cn_nameptr;
1310 int flen = fcnp->cn_namelen;
1311 const char *tnm = tcnp->cn_nameptr;
1312 int tlen = tcnp->cn_namelen;
1313
1314 MARK_ENTRY(CODA_RENAME_STATS);
1315
1316 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1317 This could be Bad. XXX */
1318 #ifdef OLD_DIAGNOSTIC
1319 if ((fcnp->cn_cred != tcnp->cn_cred)
1320 || (fcnp->cn_lwp != tcnp->cn_lwp))
1321 {
1322 panic("coda_rename: component names don't agree");
1323 }
1324 #endif
1325
1326 /* Check for rename involving control object. */
1327 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1328 MARK_INT_FAIL(CODA_RENAME_STATS);
1329 return(EACCES);
1330 }
1331
1332 /* Problem with moving directories -- need to flush entry for .. */
1333 if (odvp != ndvp) {
1334 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1335 if (ovcp) {
1336 struct vnode *ovp = CTOV(ovcp);
1337 if ((ovp) &&
1338 (ovp->v_type == VDIR)) /* If it's a directory */
1339 coda_nc_zapfile(VTOC(ovp),"..", 2);
1340 }
1341 }
1342
1343 /* Remove the entries for both source and target files */
1344 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1345 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1346
1347 /* Invalidate the parent's attr cache, the modification time has changed */
1348 VTOC(odvp)->c_flags &= ~C_VATTR;
1349 VTOC(ndvp)->c_flags &= ~C_VATTR;
1350
1351 if (flen+1 > CODA_MAXNAMLEN) {
1352 MARK_INT_FAIL(CODA_RENAME_STATS);
1353 error = EINVAL;
1354 goto exit;
1355 }
1356
1357 if (tlen+1 > CODA_MAXNAMLEN) {
1358 MARK_INT_FAIL(CODA_RENAME_STATS);
1359 error = EINVAL;
1360 goto exit;
1361 }
1362
1363 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, l);
1364
1365 exit:
1366 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1367 /* XXX - do we need to call cache pureg on the moved vnode? */
1368 cache_purge(ap->a_fvp);
1369
1370 /* It seems to be incumbent on us to drop locks on all four vnodes */
1371 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1372
1373 vrele(ap->a_fvp);
1374 vrele(odvp);
1375
1376 if (ap->a_tvp) {
1377 if (ap->a_tvp == ndvp) {
1378 vrele(ap->a_tvp);
1379 } else {
1380 vput(ap->a_tvp);
1381 }
1382 }
1383
1384 vput(ndvp);
1385 return(error);
1386 }
1387
1388 int
1389 coda_mkdir(void *v)
1390 {
1391 /* true args */
1392 struct vop_mkdir_args *ap = v;
1393 struct vnode *dvp = ap->a_dvp;
1394 struct cnode *dcp = VTOC(dvp);
1395 struct componentname *cnp = ap->a_cnp;
1396 struct vattr *va = ap->a_vap;
1397 struct vnode **vpp = ap->a_vpp;
1398 kauth_cred_t cred = cnp->cn_cred;
1399 struct lwp *l = cnp->cn_lwp;
1400 /* locals */
1401 int error;
1402 const char *nm = cnp->cn_nameptr;
1403 int len = cnp->cn_namelen;
1404 struct cnode *cp;
1405 CodaFid VFid;
1406 struct vattr ova;
1407
1408 MARK_ENTRY(CODA_MKDIR_STATS);
1409
1410 /* Check for mkdir of target object. */
1411 if (IS_CTL_NAME(dvp, nm, len)) {
1412 *vpp = (struct vnode *)0;
1413 MARK_INT_FAIL(CODA_MKDIR_STATS);
1414 return(EACCES);
1415 }
1416
1417 if (len+1 > CODA_MAXNAMLEN) {
1418 *vpp = (struct vnode *)0;
1419 MARK_INT_FAIL(CODA_MKDIR_STATS);
1420 return(EACCES);
1421 }
1422
1423 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, l, &VFid, &ova);
1424
1425 if (!error) {
1426 if (coda_find(&VFid) != NULL)
1427 panic("cnode existed for newly created directory!");
1428
1429
1430 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1431 *vpp = CTOV(cp);
1432
1433 /* enter the new vnode in the Name Cache */
1434 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1435
1436 /* as a side effect, enter "." and ".." for the directory */
1437 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1438 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1439
1440 if (coda_attr_cache) {
1441 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1442 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1443 }
1444
1445 /* Invalidate the parent's attr cache, the modification time has changed */
1446 VTOC(dvp)->c_flags &= ~C_VATTR;
1447
1448 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: %s result %d\n",
1449 coda_f2s(&VFid), error)); )
1450 } else {
1451 *vpp = (struct vnode *)0;
1452 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1453 }
1454
1455 /*
1456 * Currently, all mkdirs explicitly vput their dvp's.
1457 * It also appears that we *must* lock the vpp, since
1458 * lockleaf isn't set, but someone down the road is going
1459 * to try to unlock the new directory.
1460 */
1461 vput(dvp);
1462 if (!error) {
1463 if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1464 panic("coda_mkdir: couldn't lock child");
1465 }
1466 }
1467
1468 /* Have to free the previously saved name */
1469 /*
1470 * ufs_mkdir doesn't check for SAVESTART before freeing the
1471 * pathname buffer, but ufs_create does. For the moment, I'll
1472 * follow their lead, but this seems like it is probably
1473 * incorrect.
1474 */
1475 PNBUF_PUT(cnp->cn_pnbuf);
1476 return(error);
1477 }
1478
1479 int
1480 coda_rmdir(void *v)
1481 {
1482 /* true args */
1483 struct vop_rmdir_args *ap = v;
1484 struct vnode *dvp = ap->a_dvp;
1485 struct cnode *dcp = VTOC(dvp);
1486 struct componentname *cnp = ap->a_cnp;
1487 kauth_cred_t cred = cnp->cn_cred;
1488 struct lwp *l = cnp->cn_lwp;
1489 /* true args */
1490 int error;
1491 const char *nm = cnp->cn_nameptr;
1492 int len = cnp->cn_namelen;
1493 struct cnode *cp;
1494
1495 MARK_ENTRY(CODA_RMDIR_STATS);
1496
1497 /* Check for rmdir of control object. */
1498 if (IS_CTL_NAME(dvp, nm, len)) {
1499 MARK_INT_FAIL(CODA_RMDIR_STATS);
1500 return(ENOENT);
1501 }
1502
1503 /* We're being conservative here, it might be that this person
1504 * doesn't really have sufficient access to delete the file
1505 * but we feel zapping the entry won't really hurt anyone -- dcs
1506 */
1507 /*
1508 * As a side effect of the rmdir, remove any entries for children of
1509 * the directory, especially "." and "..".
1510 */
1511 cp = coda_nc_lookup(dcp, nm, len, cred);
1512 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1513
1514 /* Remove the file's entry from the CODA Name Cache */
1515 coda_nc_zapfile(dcp, nm, len);
1516
1517 /* Invalidate the parent's attr cache, the modification time has changed */
1518 dcp->c_flags &= ~C_VATTR;
1519
1520 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, l);
1521
1522 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1523
1524 /*
1525 * regardless of what happens, we need to drop locks/refs on the
1526 * parent and child. I think.
1527 */
1528 if (dvp == ap->a_vp) {
1529 vrele(ap->a_vp);
1530 } else {
1531 vput(ap->a_vp);
1532 }
1533 vput(dvp);
1534
1535 if ((cnp->cn_flags & SAVESTART) == 0) {
1536 PNBUF_PUT(cnp->cn_pnbuf);
1537 }
1538 return(error);
1539 }
1540
1541 int
1542 coda_symlink(void *v)
1543 {
1544 /* true args */
1545 struct vop_symlink_args *ap = v;
1546 struct vnode *tdvp = ap->a_dvp;
1547 struct cnode *tdcp = VTOC(tdvp);
1548 struct componentname *cnp = ap->a_cnp;
1549 struct vattr *tva = ap->a_vap;
1550 char *path = ap->a_target;
1551 kauth_cred_t cred = cnp->cn_cred;
1552 struct lwp *l = cnp->cn_lwp;
1553 /* locals */
1554 int error;
1555 u_long saved_cn_flags;
1556 /*
1557 * XXX I'm assuming the following things about coda_symlink's
1558 * arguments:
1559 * t(foo) is the new name/parent/etc being created.
1560 * lname is the contents of the new symlink.
1561 */
1562 const char *nm = cnp->cn_nameptr;
1563 int len = cnp->cn_namelen;
1564 int plen = strlen(path);
1565
1566 /* XXX What about the vpp argument? Do we need it? */
1567 /*
1568 * Here's the strategy for the moment: perform the symlink, then
1569 * do a lookup to grab the resulting vnode. I know this requires
1570 * two communications with Venus for a new sybolic link, but
1571 * that's the way the ball bounces. I don't yet want to change
1572 * the way the Mach symlink works. When Mach support is
1573 * deprecated, we should change symlink so that the common case
1574 * returns the resultant vnode in a vpp argument.
1575 */
1576
1577 MARK_ENTRY(CODA_SYMLINK_STATS);
1578
1579 /* Check for symlink of control object. */
1580 if (IS_CTL_NAME(tdvp, nm, len)) {
1581 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1582 return(EACCES);
1583 }
1584
1585 if (plen+1 > CODA_MAXPATHLEN) {
1586 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1587 return(EINVAL);
1588 }
1589
1590 if (len+1 > CODA_MAXNAMLEN) {
1591 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1592 error = EINVAL;
1593 goto exit;
1594 }
1595
1596 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, l);
1597
1598 /* Invalidate the parent's attr cache, the modification time has changed */
1599 tdcp->c_flags &= ~C_VATTR;
1600
1601 if (!error) {
1602 /*
1603 * VOP_SYMLINK is not defined to pay attention to cnp->cn_flags;
1604 * these are defined only for VOP_LOOKUP. We desire to reuse
1605 * cnp for a VOP_LOOKUP operation, and must be sure to not pass
1606 * stray flags passed to us. Such stray flags can occur because
1607 * sys_symlink makes a namei call and then reuses the
1608 * componentname structure.
1609 */
1610 /*
1611 * XXX Arguably we should create our own componentname structure
1612 * and not reuse the one that was passed in.
1613 */
1614 saved_cn_flags = cnp->cn_flags;
1615 cnp->cn_flags &= ~(MODMASK | OPMASK);
1616 cnp->cn_flags |= LOOKUP;
1617 error = VOP_LOOKUP(tdvp, ap->a_vpp, cnp);
1618 cnp->cn_flags = saved_cn_flags;
1619 /* Either an error occurs, or ap->a_vpp is locked. */
1620 }
1621 /* unlock and deference parent */
1622 vput(tdvp);
1623
1624 exit:
1625 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1626 return(error);
1627 }
1628
1629 /*
1630 * Read directory entries.
1631 */
1632 int
1633 coda_readdir(void *v)
1634 {
1635 /* true args */
1636 struct vop_readdir_args *ap = v;
1637 struct vnode *vp = ap->a_vp;
1638 struct cnode *cp = VTOC(vp);
1639 struct uio *uiop = ap->a_uio;
1640 kauth_cred_t cred = ap->a_cred;
1641 int *eofflag = ap->a_eofflag;
1642 off_t **cookies = ap->a_cookies;
1643 int *ncookies = ap->a_ncookies;
1644 /* upcall decl */
1645 /* locals */
1646 struct lwp *l = curlwp;
1647 int error = 0;
1648
1649 MARK_ENTRY(CODA_READDIR_STATS);
1650
1651 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %lu, %lld)\n", uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid, (long long) uiop->uio_offset)); )
1652
1653 /* Check for readdir of control object. */
1654 if (IS_CTL_VP(vp)) {
1655 MARK_INT_FAIL(CODA_READDIR_STATS);
1656 return(ENOENT);
1657 }
1658
1659 {
1660 /* Redirect the request to UFS. */
1661
1662 /* If directory is not already open do an "internal open" on it. */
1663 int opened_internally = 0;
1664 if (cp->c_ovp == NULL) {
1665 opened_internally = 1;
1666 MARK_INT_GEN(CODA_OPEN_STATS);
1667 error = VOP_OPEN(vp, FREAD, cred, l);
1668 #ifdef CODA_VERBOSE
1669 printf("coda_readdir: Internally Opening %p\n", vp);
1670 #endif
1671 if (error) return(error);
1672 } else
1673 vp = cp->c_ovp;
1674
1675 /* Have UFS handle the call. */
1676 CODADEBUG(CODA_READDIR, myprintf((
1677 "indirect readdir: fid = %s, refcnt = %d\n",
1678 coda_f2s(&cp->c_fid), vp->v_usecount)); )
1679 error = VOP_READDIR(vp, uiop, cred, eofflag, cookies, ncookies);
1680 if (error)
1681 MARK_INT_FAIL(CODA_READDIR_STATS);
1682 else
1683 MARK_INT_SAT(CODA_READDIR_STATS);
1684
1685 /* Do an "internal close" if necessary. */
1686 if (opened_internally) {
1687 MARK_INT_GEN(CODA_CLOSE_STATS);
1688 (void)VOP_CLOSE(vp, FREAD, cred, l);
1689 }
1690 }
1691
1692 return(error);
1693 }
1694
1695 /*
1696 * Convert from file system blocks to device blocks
1697 */
1698 int
1699 coda_bmap(void *v)
1700 {
1701 /* XXX on the global proc */
1702 /* true args */
1703 struct vop_bmap_args *ap = v;
1704 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1705 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1706 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1707 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1708 struct lwp *l __attribute__((unused)) = curlwp;
1709 /* upcall decl */
1710 /* locals */
1711
1712 *vpp = (struct vnode *)0;
1713 myprintf(("coda_bmap called!\n"));
1714 return(EINVAL);
1715 }
1716
1717 /*
1718 * I don't think the following two things are used anywhere, so I've
1719 * commented them out
1720 *
1721 * struct buf *async_bufhead;
1722 * int async_daemon_count;
1723 */
1724 int
1725 coda_strategy(void *v)
1726 {
1727 /* true args */
1728 struct vop_strategy_args *ap = v;
1729 struct buf *bp __attribute__((unused)) = ap->a_bp;
1730 struct lwp *l __attribute__((unused)) = curlwp;
1731 /* upcall decl */
1732 /* locals */
1733
1734 myprintf(("coda_strategy called! "));
1735 return(EINVAL);
1736 }
1737
1738 int
1739 coda_reclaim(void *v)
1740 {
1741 /* true args */
1742 struct vop_reclaim_args *ap = v;
1743 struct vnode *vp = ap->a_vp;
1744 struct cnode *cp = VTOC(vp);
1745 /* upcall decl */
1746 /* locals */
1747
1748 /*
1749 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1750 */
1751 ENTRY;
1752
1753 if (IS_UNMOUNTING(cp)) {
1754 #ifdef DEBUG
1755 if (VTOC(vp)->c_ovp) {
1756 if (IS_UNMOUNTING(cp))
1757 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1758 }
1759 #endif
1760 } else {
1761 #ifdef OLD_DIAGNOSTIC
1762 if (vp->v_usecount != 0)
1763 print("coda_reclaim: pushing active %p\n", vp);
1764 if (VTOC(vp)->c_ovp) {
1765 panic("coda_reclaim: c_ovp not void");
1766 }
1767 #endif
1768 }
1769 cache_purge(vp);
1770 coda_free(VTOC(vp));
1771 SET_VTOC(vp) = NULL;
1772 return (0);
1773 }
1774
1775 int
1776 coda_lock(void *v)
1777 {
1778 /* true args */
1779 struct vop_lock_args *ap = v;
1780 struct vnode *vp = ap->a_vp;
1781 struct cnode *cp = VTOC(vp);
1782 /* upcall decl */
1783 /* locals */
1784
1785 ENTRY;
1786
1787 if (coda_lockdebug) {
1788 myprintf(("Attempting lock on %s\n",
1789 coda_f2s(&cp->c_fid)));
1790 }
1791
1792 return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
1793 }
1794
1795 int
1796 coda_unlock(void *v)
1797 {
1798 /* true args */
1799 struct vop_unlock_args *ap = v;
1800 struct vnode *vp = ap->a_vp;
1801 struct cnode *cp = VTOC(vp);
1802 /* upcall decl */
1803 /* locals */
1804
1805 ENTRY;
1806 if (coda_lockdebug) {
1807 myprintf(("Attempting unlock on %s\n",
1808 coda_f2s(&cp->c_fid)));
1809 }
1810
1811 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock));
1812 }
1813
1814 int
1815 coda_islocked(void *v)
1816 {
1817 /* true args */
1818 struct vop_islocked_args *ap = v;
1819 ENTRY;
1820
1821 return (lockstatus(&ap->a_vp->v_lock));
1822 }
1823
1824 /* How one looks up a vnode given a device/inode pair: */
1825 int
1826 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1827 {
1828 /* This is like VFS_VGET() or igetinode()! */
1829 int error;
1830 struct mount *mp;
1831
1832 if (!(mp = devtomp(dev))) {
1833 myprintf(("coda_grab_vnode: devtomp(%d) returns NULL\n", dev));
1834 return(ENXIO);
1835 }
1836
1837 /* XXX - ensure that nonzero-return means failure */
1838 error = VFS_VGET(mp, ino, vpp);
1839 if (error) {
1840 myprintf(("coda_grab_vnode: iget/vget(%d, %llu) returns %p, err %d\n",
1841 dev, (unsigned long long)ino, *vpp, error));
1842 return(ENOENT);
1843 }
1844 return(0);
1845 }
1846
1847 void
1848 print_vattr(struct vattr *attr)
1849 {
1850 const char *typestr;
1851
1852 switch (attr->va_type) {
1853 case VNON:
1854 typestr = "VNON";
1855 break;
1856 case VREG:
1857 typestr = "VREG";
1858 break;
1859 case VDIR:
1860 typestr = "VDIR";
1861 break;
1862 case VBLK:
1863 typestr = "VBLK";
1864 break;
1865 case VCHR:
1866 typestr = "VCHR";
1867 break;
1868 case VLNK:
1869 typestr = "VLNK";
1870 break;
1871 case VSOCK:
1872 typestr = "VSCK";
1873 break;
1874 case VFIFO:
1875 typestr = "VFFO";
1876 break;
1877 case VBAD:
1878 typestr = "VBAD";
1879 break;
1880 default:
1881 typestr = "????";
1882 break;
1883 }
1884
1885
1886 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1887 typestr, (int)attr->va_mode, (int)attr->va_uid,
1888 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1889
1890 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1891 (int)attr->va_fileid, (int)attr->va_nlink,
1892 (int)attr->va_size,
1893 (int)attr->va_blocksize,(int)attr->va_bytes));
1894 myprintf((" gen %ld flags %ld vaflags %d\n",
1895 attr->va_gen, attr->va_flags, attr->va_vaflags));
1896 myprintf((" atime sec %d nsec %d\n",
1897 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1898 myprintf((" mtime sec %d nsec %d\n",
1899 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1900 myprintf((" ctime sec %d nsec %d\n",
1901 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1902 }
1903
1904 /* How to print a ucred */
1905 void
1906 print_cred(kauth_cred_t cred)
1907 {
1908
1909 uint16_t ngroups;
1910 int i;
1911
1912 myprintf(("ref %d\tuid %d\n", kauth_cred_getrefcnt(cred),
1913 kauth_cred_geteuid(cred)));
1914
1915 ngroups = kauth_cred_ngroups(cred);
1916 for (i=0; i < ngroups; i++)
1917 myprintf(("\tgroup %d: (%d)\n", i, kauth_cred_group(cred, i)));
1918 myprintf(("\n"));
1919
1920 }
1921
1922 /*
1923 * Return a vnode for the given fid.
1924 * If no cnode exists for this fid create one and put it
1925 * in a table hashed by coda_f2i(). If the cnode for
1926 * this fid is already in the table return it (ref count is
1927 * incremented by coda_find. The cnode will be flushed from the
1928 * table when coda_inactive calls coda_unsave.
1929 */
1930 struct cnode *
1931 make_coda_node(CodaFid *fid, struct mount *vfsp, short type)
1932 {
1933 struct cnode *cp;
1934 int err;
1935
1936 if ((cp = coda_find(fid)) == NULL) {
1937 struct vnode *vp;
1938
1939 cp = coda_alloc();
1940 cp->c_fid = *fid;
1941
1942 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1943 if (err) {
1944 panic("coda: getnewvnode returned error %d", err);
1945 }
1946 vp->v_data = cp;
1947 vp->v_type = type;
1948 cp->c_vnode = vp;
1949 coda_save(cp);
1950
1951 } else {
1952 vref(CTOV(cp));
1953 }
1954
1955 return cp;
1956 }
1957
1958 int
1959 coda_getpages(void *v)
1960 {
1961 struct vop_getpages_args /* {
1962 struct vnode *a_vp;
1963 voff_t a_offset;
1964 struct vm_page **a_m;
1965 int *a_count;
1966 int a_centeridx;
1967 vm_prot_t a_access_type;
1968 int a_advice;
1969 int a_flags;
1970 } */ *ap = v;
1971 struct vnode *vp = ap->a_vp;
1972 struct cnode *cp = VTOC(vp);
1973 struct lwp *l = curlwp;
1974 kauth_cred_t cred = l->l_cred;
1975 int error;
1976
1977 /* Check for control object. */
1978 if (IS_CTL_VP(vp)) {
1979 return(EINVAL);
1980 }
1981
1982 error = VOP_OPEN(vp, FREAD, cred, l);
1983 if (error) {
1984 return error;
1985 }
1986 ap->a_vp = cp->c_ovp;
1987 error = VOCALL(ap->a_vp->v_op, VOFFSET(vop_getpages), ap);
1988 (void) VOP_CLOSE(vp, FREAD, cred, l);
1989 return error;
1990 }
1991
1992 int
1993 coda_putpages(void *v)
1994 {
1995 struct vop_putpages_args /* {
1996 struct vnode *a_vp;
1997 voff_t a_offlo;
1998 voff_t a_offhi;
1999 int a_flags;
2000 } */ *ap = v;
2001 struct vnode *vp = ap->a_vp;
2002
2003 simple_unlock(&vp->v_interlock);
2004
2005 /* Check for control object. */
2006 if (IS_CTL_VP(vp)) {
2007 return(EINVAL);
2008 }
2009
2010 /*
2011 * XXX
2012 * we'd like to do something useful here for msync(),
2013 * but that turns out to be hard.
2014 */
2015
2016 return 0;
2017 }
2018