3 * Coda: an Experimental Distributed File System
6 * Copyright (c) 1987-1998 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation, and
14 * that credit is given to Carnegie Mellon University in all documents
15 * and publicity pertaining to direct or indirect use of this code or its
18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
23 * ANY DERIVATIVE WORK.
25 * Carnegie Mellon encourages users of this software to return any
26 * improvements or extensions that they make, and to grant Carnegie
27 * Mellon the rights to redistribute these changes without encumbrance.
29 * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $FreeBSD: src/sys/coda/coda_vnops.c,v 1.22.2.1 2001/06/29 16:26:22 shafeeq Exp $
31 * $DragonFly: src/sys/vfs/coda/Attic/coda_vnops.c,v 1.6 2003/06/26 20:27:51 dillon Exp $
36 * Mach Operating System
37 * Copyright (c) 1990 Carnegie-Mellon University
38 * Copyright (c) 1989 Carnegie-Mellon University
39 * All rights reserved. The CMU software License Agreement specifies
40 * the terms and conditions for use and redistribution.
44 * This code was written for the Coda file system at Carnegie Mellon
45 * University. Contributers include David Steere, James Kistler, and
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
53 #include <sys/malloc.h>
54 #include <sys/mount.h>
55 #include <sys/errno.h>
58 #include <sys/fcntl.h>
60 #include <sys/namei.h>
61 #include <sys/ioccom.h>
62 #include <sys/select.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_zone.h>
69 #include <coda/coda.h>
70 #include <coda/cnode.h>
71 #include <coda/coda_vnops.h>
72 #include <coda/coda_venus.h>
73 #include <coda/coda_opstats.h>
74 #include <coda/coda_subr.h>
75 #include <coda/coda_namecache.h>
76 #include <coda/coda_pioctl.h>
79 * These flags select various performance enhancements.
81 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
82 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
83 int coda_access_cache = 1; /* Set to handle some access checks directly */
85 /* structure to keep track of vfs calls */
87 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
89 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
90 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
91 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
92 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
94 /* What we are delaying for in printf */
95 int coda_printf_delay = 0; /* in microseconds */
96 int coda_vnop_print_entry = 0;
97 static int coda_lockdebug = 0;
99 /* Definition of the vfs operation vector */
102 * Some NetBSD details:
104 * coda_start is called at the end of the mount syscall.
105 * coda_init is called at boot time.
108 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
110 /* Definition of the vnode operation vector */
112 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
113 { &vop_default_desc, coda_vop_error },
114 { &vop_lookup_desc, coda_lookup }, /* lookup */
115 { &vop_create_desc, coda_create }, /* create */
116 { &vop_mknod_desc, coda_vop_error }, /* mknod */
117 { &vop_open_desc, coda_open }, /* open */
118 { &vop_close_desc, coda_close }, /* close */
119 { &vop_access_desc, coda_access }, /* access */
120 { &vop_getattr_desc, coda_getattr }, /* getattr */
121 { &vop_setattr_desc, coda_setattr }, /* setattr */
122 { &vop_read_desc, coda_read }, /* read */
123 { &vop_write_desc, coda_write }, /* write */
124 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
125 { &vop_mmap_desc, coda_vop_error }, /* mmap */
126 { &vop_fsync_desc, coda_fsync }, /* fsync */
127 { &vop_remove_desc, coda_remove }, /* remove */
128 { &vop_link_desc, coda_link }, /* link */
129 { &vop_rename_desc, coda_rename }, /* rename */
130 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
131 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
132 { &vop_symlink_desc, coda_symlink }, /* symlink */
133 { &vop_readdir_desc, coda_readdir }, /* readdir */
134 { &vop_readlink_desc, coda_readlink }, /* readlink */
135 { &vop_inactive_desc, coda_inactive }, /* inactive */
136 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
137 { &vop_lock_desc, coda_lock }, /* lock */
138 { &vop_unlock_desc, coda_unlock }, /* unlock */
139 { &vop_bmap_desc, coda_bmap }, /* bmap */
140 { &vop_strategy_desc, coda_strategy }, /* strategy */
141 { &vop_print_desc, coda_vop_error }, /* print */
142 { &vop_islocked_desc, coda_islocked }, /* islocked */
143 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
144 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
145 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
146 { &vop_lease_desc, coda_vop_nop }, /* lease */
147 { &vop_poll_desc, (vop_t *) vop_stdpoll },
148 { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
149 { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
150 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
151 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
152 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
156 we need to define these someday
157 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
158 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
159 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
160 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
161 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
164 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
165 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
166 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
168 { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
171 static struct vnodeopv_desc coda_vnodeop_opv_desc =
172 { &coda_vnodeop_p, coda_vnodeop_entries };
174 VNODEOP_SET(coda_vnodeop_opv_desc);
176 /* A generic panic: we were called with something we didn't define yet */
178 coda_vop_error(void *anon) {
179 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
181 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
182 (*desc)->vdesc_name));
184 panic("coda_vop_error");
189 /* A generic do-nothing. For lease_check, advlock */
191 coda_vop_nop(void *anon) {
192 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
195 myprintf(("Vnode operation %s called, but unsupported\n",
196 (*desc)->vdesc_name));
202 coda_vnodeopstats_init(void)
206 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
207 coda_vnodeopstats[i].opcode = i;
208 coda_vnodeopstats[i].entries = 0;
209 coda_vnodeopstats[i].sat_intrn = 0;
210 coda_vnodeopstats[i].unsat_intrn = 0;
211 coda_vnodeopstats[i].gen_intrn = 0;
217 * coda_open calls Venus to return the device, inode pair of the cache
218 * file holding the data. Using iget, coda_open finds the vnode of the
219 * cache file, and then opens it.
226 * NetBSD can pass the O_EXCL flag in mode, even though the check
227 * has already happened. Venus defensively assumes that if open
228 * is passed the EXCL, it must be a bug. We strip the flag here.
231 struct vop_open_args *ap = v;
232 register struct vnode **vpp = &(ap->a_vp);
233 struct cnode *cp = VTOC(*vpp);
234 int flag = ap->a_mode & (~O_EXCL);
235 struct ucred *cred = ap->a_cred;
236 struct thread *td = ap->a_td;
243 MARK_ENTRY(CODA_OPEN_STATS);
245 /* Check for open of control file. */
246 if (IS_CTL_VP(*vpp)) {
248 /* if (WRITEABLE(flag)) */
249 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
250 MARK_INT_FAIL(CODA_OPEN_STATS);
253 MARK_INT_SAT(CODA_OPEN_STATS);
257 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
261 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
262 (u_long)dev2udev(dev), (u_long)inode,
266 /* Translate the <device, inode> pair for the cache file into
268 error = coda_grab_vnode(dev, inode, &vp);
272 /* We get the vnode back locked. Needs unlocked */
273 VOP_UNLOCK(vp, 0, td);
274 /* Keep a reference until the close comes in. */
277 /* Save the vnode pointer for the cache file. */
278 if (cp->c_ovp == NULL) {
282 panic("coda_open: cp->c_ovp != ITOV(ip)");
286 /* Flush the attribute cached if writing the file. */
289 cp->c_flags &= ~C_VATTR;
292 /* Save the <device, inode> pair for the cache file to speed
293 up subsequent page_read's. */
297 /* Open the cache file. */
298 error = VOP_OPEN(vp, flag, cred, td);
300 printf("coda_open: VOP_OPEN on container failed %d\n", error);
303 /* grab (above) does this when it calls newvnode unless it's in the cache*/
304 if (vp->v_type == VREG) {
305 error = vfs_object_create(vp, td);
307 printf("coda_open: vfs_object_create() returns %d\n", error);
316 * Close the cache file used for I/O and notify Venus.
323 struct vop_close_args *ap = v;
324 struct vnode *vp = ap->a_vp;
325 struct cnode *cp = VTOC(vp);
326 int flag = ap->a_fflag;
327 struct thread *td = ap->a_td;
331 MARK_ENTRY(CODA_CLOSE_STATS);
333 /* Check for close of control file. */
335 MARK_INT_SAT(CODA_CLOSE_STATS);
339 if (IS_UNMOUNTING(cp)) {
342 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
343 vp->v_usecount, cp->c_ovp, vp, cp);
348 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
353 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
358 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
362 if (--cp->c_ocount == 0)
365 if (flag & FWRITE) /* file was opened for write */
368 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
371 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
379 struct vop_read_args *ap = v;
382 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
383 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
390 struct vop_write_args *ap = v;
393 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
394 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
398 coda_rdwr(vp, uiop, rw, ioflag, cred, td)
407 /* NOTE: container file operation!!! */
409 struct cnode *cp = VTOC(vp);
410 struct vnode *cfvp = cp->c_ovp;
411 int igot_internally = 0;
412 int opened_internally = 0;
415 MARK_ENTRY(CODA_RDWR_STATS);
417 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
418 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
419 (long long)uiop->uio_offset, uiop->uio_segflg)); )
421 /* Check for rdwr of control object. */
423 MARK_INT_FAIL(CODA_RDWR_STATS);
428 * If file is not already open this must be a page
429 * {read,write} request. Iget the cache file's inode
430 * pointer if we still have its <device, inode> pair.
431 * Otherwise, we must do an internal open to derive the
436 * If we're dumping core, do the internal open. Otherwise
437 * venus won't have the correct size of the core when
438 * it's completely written.
440 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
442 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
444 MARK_INT_FAIL(CODA_RDWR_STATS);
448 * We get the vnode back locked in both Mach and
449 * NetBSD. Needs unlocked
451 VOP_UNLOCK(cfvp, 0, td);
454 opened_internally = 1;
455 MARK_INT_GEN(CODA_OPEN_STATS);
456 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
458 printf("coda_rdwr: Internally Opening %p\n", vp);
460 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
463 if (vp->v_type == VREG) {
464 error = vfs_object_create(vp, td);
466 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
471 MARK_INT_FAIL(CODA_RDWR_STATS);
478 /* Have UFS handle the call. */
479 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
480 cp->c_fid.Volume, cp->c_fid.Vnode,
481 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
484 if (rw == UIO_READ) {
485 error = VOP_READ(cfvp, uiop, ioflag, cred);
487 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
488 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
492 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
493 vnode_pager_setsize(vp, attr.va_size);
499 MARK_INT_FAIL(CODA_RDWR_STATS);
501 MARK_INT_SAT(CODA_RDWR_STATS);
503 /* Do an internal close if necessary. */
504 if (opened_internally) {
505 MARK_INT_GEN(CODA_CLOSE_STATS);
506 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
509 /* Invalidate cached attributes if writing. */
511 cp->c_flags &= ~C_VATTR;
520 struct vop_ioctl_args *ap = v;
521 struct vnode *vp = ap->a_vp;
522 int com = ap->a_command;
523 caddr_t data = ap->a_data;
524 int flag = ap->a_fflag;
525 struct ucred *cred = ap->a_cred;
526 struct thread *td = ap->a_td;
530 struct nameidata ndp;
531 struct PioctlData *iap = (struct PioctlData *)data;
533 MARK_ENTRY(CODA_IOCTL_STATS);
535 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
537 /* Don't check for operation on a dying object, for ctlvp it
540 /* Must be control object to succeed. */
541 if (!IS_CTL_VP(vp)) {
542 MARK_INT_FAIL(CODA_IOCTL_STATS);
543 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
546 /* Look up the pathname. */
548 /* Should we use the name cache here? It would get it from
549 lookupname sooner or later anyway, right? */
551 NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td);
556 MARK_INT_FAIL(CODA_IOCTL_STATS);
557 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
563 * Make sure this is a coda style cnode, but it may be a
566 if (tvp->v_op != coda_vnodeop_p) {
568 NDFREE(&ndp, NDF_ONLY_PNBUF);
569 MARK_INT_FAIL(CODA_IOCTL_STATS);
570 CODADEBUG(CODA_IOCTL,
571 myprintf(("coda_ioctl error: %s not a coda object\n",
576 if (iap->vi.in_size > VC_MAXDATASIZE) {
580 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
583 MARK_INT_FAIL(CODA_IOCTL_STATS);
585 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
588 NDFREE(&ndp, NDF_ONLY_PNBUF);
593 * To reduce the cost of a user-level venus;we cache attributes in
594 * the kernel. Each cnode has storage allocated for an attribute. If
595 * c_vattr is valid, return a reference to it. Otherwise, get the
596 * attributes from venus and store them in the cnode. There is some
597 * question if this method is a security leak. But I think that in
598 * order to make this call, the user must have done a lookup and
599 * opened the file, and therefore should already have access.
606 struct vop_getattr_args *ap = v;
607 struct vnode *vp = ap->a_vp;
608 struct cnode *cp = VTOC(vp);
609 struct vattr *vap = ap->a_vap;
610 struct thread *td = ap->a_td;
614 MARK_ENTRY(CODA_GETATTR_STATS);
616 if (IS_UNMOUNTING(cp))
619 /* Check for getattr of control object. */
621 MARK_INT_FAIL(CODA_GETATTR_STATS);
625 /* Check to see if the attributes have already been cached */
626 if (VALID_VATTR(cp)) {
627 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
630 cp->c_fid.Unique));});
631 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
632 print_vattr(&cp->c_vattr); );
635 MARK_INT_SAT(CODA_GETATTR_STATS);
639 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
642 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
648 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
651 { int size = vap->va_size;
652 struct vnode *convp = cp->c_ovp;
653 if (convp != (struct vnode *)0) {
654 vnode_pager_setsize(convp, size);
657 /* If not open for write, store attributes in cnode */
658 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
660 cp->c_flags |= C_VATTR;
672 struct vop_setattr_args *ap = v;
673 register struct vnode *vp = ap->a_vp;
674 struct cnode *cp = VTOC(vp);
675 register struct vattr *vap = ap->a_vap;
676 struct ucred *cred = ap->a_cred;
677 struct thread *td = ap->a_td;
681 MARK_ENTRY(CODA_SETATTR_STATS);
683 /* Check for setattr of control object. */
685 MARK_INT_FAIL(CODA_SETATTR_STATS);
689 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
692 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
695 cp->c_flags &= ~C_VATTR;
697 { int size = vap->va_size;
698 struct vnode *convp = cp->c_ovp;
699 if (size != VNOVAL && convp != (struct vnode *)0) {
700 vnode_pager_setsize(convp, size);
703 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
712 struct vop_access_args *ap = v;
713 struct vnode *vp = ap->a_vp;
714 struct cnode *cp = VTOC(vp);
715 int mode = ap->a_mode;
716 struct ucred *cred = ap->a_cred;
717 struct thread *td = ap->a_td;
721 MARK_ENTRY(CODA_ACCESS_STATS);
723 /* Check for access of control object. Only read access is
726 /* bogus hack - all will be marked as successes */
727 MARK_INT_SAT(CODA_ACCESS_STATS);
728 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
733 * if the file is a directory, and we are checking exec (eg lookup)
734 * access, and the file is in the namecache, then the user must have
735 * lookup access to it.
737 if (coda_access_cache) {
738 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
739 if (coda_nc_lookup(cp, ".", 1, cred)) {
740 MARK_INT_SAT(CODA_ACCESS_STATS);
741 return(0); /* it was in the cache */
746 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
756 struct vop_readlink_args *ap = v;
757 struct vnode *vp = ap->a_vp;
758 struct cnode *cp = VTOC(vp);
759 struct uio *uiop = ap->a_uio;
760 struct ucred *cred = ap->a_cred;
761 struct thread *td = ap->a_uio->uio_td;
767 MARK_ENTRY(CODA_READLINK_STATS);
769 /* Check for readlink of control object. */
771 MARK_INT_FAIL(CODA_READLINK_STATS);
775 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
776 uiop->uio_rw = UIO_READ;
777 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
779 MARK_INT_FAIL(CODA_READLINK_STATS);
781 MARK_INT_SAT(CODA_READLINK_STATS);
785 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
788 uiop->uio_rw = UIO_READ;
789 error = uiomove(str, len, uiop);
791 if (coda_symlink_cache) {
794 cp->c_flags |= C_SYMLINK;
799 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
808 struct vop_fsync_args *ap = v;
809 struct vnode *vp = ap->a_vp;
810 struct cnode *cp = VTOC(vp);
811 struct thread *td = ap->a_td;
813 struct vnode *convp = cp->c_ovp;
816 MARK_ENTRY(CODA_FSYNC_STATS);
818 /* Check for fsync on an unmounting object */
819 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
820 * after an unmount has been initiated. This is a Bad Thing,
821 * which we have to avoid. Not a legitimate failure for stats.
823 if (IS_UNMOUNTING(cp)) {
827 /* Check for fsync of control object. */
829 MARK_INT_SAT(CODA_FSYNC_STATS);
834 VOP_FSYNC(convp, MNT_WAIT, td);
837 * We see fsyncs with usecount == 1 then usecount == 0.
838 * For now we ignore them.
841 if (!vp->v_usecount) {
842 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
843 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
848 * We can expect fsync on any vnode at all if venus is pruging it.
849 * Venus can't very well answer the fsync request, now can it?
850 * Hopefully, it won't have to, because hopefully, venus preserves
851 * the (possibly untrue) invariant that it never purges an open
854 if (cp->c_flags & C_PURGING) {
860 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
862 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
870 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
871 have a proc pointer. Oops. */
873 struct vop_inactive_args *ap = v;
874 struct vnode *vp = ap->a_vp;
875 struct cnode *cp = VTOC(vp);
876 struct ucred *cred __attribute__((unused)) = NULL;
877 struct thread *td = curthread;
881 /* We don't need to send inactive to venus - DCS */
882 MARK_ENTRY(CODA_INACTIVE_STATS);
885 MARK_INT_SAT(CODA_INACTIVE_STATS);
889 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
890 cp->c_fid.Volume, cp->c_fid.Vnode,
891 cp->c_fid.Unique, vp->v_mount));)
893 /* If an array has been allocated to hold the symlink, deallocate it */
894 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
895 if (cp->c_symlink == NULL)
896 panic("coda_inactive: null symlink pointer in cnode");
898 CODA_FREE(cp->c_symlink, cp->c_symlen);
899 cp->c_flags &= ~C_SYMLINK;
903 /* Remove it from the table so it can't be found. */
905 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
906 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
907 panic("badness in coda_inactive\n");
910 if (IS_UNMOUNTING(cp)) {
912 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
913 if (cp->c_ovp != NULL)
914 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
915 vp->v_usecount, vp, cp);
917 lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td);
919 #ifdef OLD_DIAGNOSTIC
920 if (CTOV(cp)->v_usecount) {
921 panic("coda_inactive: nonzero reference count");
923 if (cp->c_ovp != NULL) {
924 panic("coda_inactive: cp->ovp != NULL");
927 VOP_UNLOCK(vp, 0, td);
931 MARK_INT_SAT(CODA_INACTIVE_STATS);
936 * Remote file system operations having to do with directory manipulation.
940 * It appears that in NetBSD, lookup is supposed to return the vnode locked
947 struct vop_lookup_args *ap = v;
948 struct vnode *dvp = ap->a_dvp;
949 struct cnode *dcp = VTOC(dvp);
950 struct vnode **vpp = ap->a_vpp;
952 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
953 * of the string to xlate, and that we must try to get at least
954 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
957 struct componentname *cnp = ap->a_cnp;
958 struct ucred *cred = cnp->cn_cred;
959 struct thread *td = cnp->cn_td;
962 const char *nm = cnp->cn_nameptr;
963 int len = cnp->cn_namelen;
968 MARK_ENTRY(CODA_LOOKUP_STATS);
970 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
971 nm, dcp->c_fid.Volume,
972 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
974 /* Check for lookup of control object. */
975 if (IS_CTL_NAME(dvp, nm, len)) {
978 MARK_INT_SAT(CODA_LOOKUP_STATS);
982 if (len+1 > CODA_MAXNAMLEN) {
983 MARK_INT_FAIL(CODA_LOOKUP_STATS);
984 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
985 dcp->c_fid.Volume, dcp->c_fid.Vnode,
986 dcp->c_fid.Unique, nm)););
987 *vpp = (struct vnode *)0;
991 /* First try to look the file up in the cfs name cache */
992 /* lock the parent vnode? */
993 cp = coda_nc_lookup(dcp, nm, len, cred);
997 CODADEBUG(CODA_LOOKUP,
998 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
1001 /* The name wasn't cached, so we need to contact Venus */
1002 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
1005 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1006 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1007 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1008 *vpp = (struct vnode *)0;
1010 MARK_INT_SAT(CODA_LOOKUP_STATS);
1011 CODADEBUG(CODA_LOOKUP,
1012 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1013 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1016 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1019 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1020 /* And don't enter a new vnode for an invalid one! */
1021 if (!(vtype & CODA_NOCACHE))
1022 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1028 * If we are creating, and this was the last name to be looked up,
1029 * and the error was ENOENT, then there really shouldn't be an
1030 * error and we can make the leaf NULL and return success. Since
1031 * this is supposed to work under Mach as well as NetBSD, we're
1032 * leaving this fn wrapped. We also must tell lookup/namei that
1033 * we need to save the last component of the name. (Create will
1034 * have to free the name buffer later...lucky us...)
1036 if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
1037 && (cnp->cn_flags & ISLASTCN)
1038 && (error == ENOENT))
1040 error = EJUSTRETURN;
1041 cnp->cn_flags |= SAVENAME;
1046 * If we are removing, and we are at the last element, and we
1047 * found it, then we need to keep the name around so that the
1048 * removal will go ahead as planned. Unfortunately, this will
1049 * probably also lock the to-be-removed vnode, which may or may
1050 * not be a good idea. I'll have to look at the bits of
1051 * coda_remove to make sure. We'll only save the name if we did in
1052 * fact find the name, otherwise coda_remove won't have a chance
1053 * to free the pathname.
1055 if ((cnp->cn_nameiop == DELETE)
1056 && (cnp->cn_flags & ISLASTCN)
1059 cnp->cn_flags |= SAVENAME;
1063 * If the lookup went well, we need to (potentially?) unlock the
1064 * parent, and lock the child. We are only responsible for
1065 * checking to see if the parent is supposed to be unlocked before
1066 * we return. We must always lock the child (provided there is
1067 * one, and (the parent isn't locked or it isn't the same as the
1068 * parent.) Simple, huh? We can never leave the parent locked unless
1071 if (!error || (error == EJUSTRETURN)) {
1072 if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
1073 if ((error = VOP_UNLOCK(dvp, 0, td))) {
1077 * The parent is unlocked. As long as there is a child,
1078 * lock it without bothering to check anything else.
1081 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1082 printf("coda_lookup: ");
1083 panic("unlocked parent but couldn't lock child");
1087 /* The parent is locked, and may be the same as the child */
1088 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1089 /* Different, go ahead and lock it. */
1090 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1091 printf("coda_lookup: ");
1092 panic("unlocked parent but couldn't lock child");
1097 /* If the lookup failed, we need to ensure that the leaf is NULL */
1098 /* Don't change any locking? */
1110 struct vop_create_args *ap = v;
1111 struct vnode *dvp = ap->a_dvp;
1112 struct cnode *dcp = VTOC(dvp);
1113 struct vattr *va = ap->a_vap;
1115 int mode = ap->a_vap->va_mode;
1116 struct vnode **vpp = ap->a_vpp;
1117 struct componentname *cnp = ap->a_cnp;
1118 struct ucred *cred = cnp->cn_cred;
1119 struct thread *td = cnp->cn_td;
1123 const char *nm = cnp->cn_nameptr;
1124 int len = cnp->cn_namelen;
1128 MARK_ENTRY(CODA_CREATE_STATS);
1130 /* All creates are exclusive XXX */
1131 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1133 /* Check for create of control object. */
1134 if (IS_CTL_NAME(dvp, nm, len)) {
1135 *vpp = (struct vnode *)0;
1136 MARK_INT_FAIL(CODA_CREATE_STATS);
1140 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1144 /* If this is an exclusive create, panic if the file already exists. */
1145 /* Venus should have detected the file and reported EEXIST. */
1147 if ((exclusive == 1) &&
1148 (coda_find(&VFid) != NULL))
1149 panic("cnode existed for newly created file!");
1151 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1154 /* Update va to reflect the new attributes. */
1157 /* Update the attribute cache and mark it as valid */
1158 if (coda_attr_cache) {
1159 VTOC(*vpp)->c_vattr = attr;
1160 VTOC(*vpp)->c_flags |= C_VATTR;
1163 /* Invalidate the parent's attr cache, the modification time has changed */
1164 VTOC(dvp)->c_flags &= ~C_VATTR;
1166 /* enter the new vnode in the Name Cache */
1167 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1169 CODADEBUG(CODA_CREATE,
1170 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1171 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1173 *vpp = (struct vnode *)0;
1174 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1178 if (cnp->cn_flags & LOCKLEAF) {
1179 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1180 printf("coda_create: ");
1181 panic("unlocked parent but couldn't lock child");
1184 #ifdef OLD_DIAGNOSTIC
1186 printf("coda_create: LOCKLEAF not set!\n");
1198 struct vop_remove_args *ap = v;
1199 struct vnode *dvp = ap->a_dvp;
1200 struct cnode *cp = VTOC(dvp);
1201 struct componentname *cnp = ap->a_cnp;
1202 struct ucred *cred = cnp->cn_cred;
1203 struct thread *td = cnp->cn_td;
1206 const char *nm = cnp->cn_nameptr;
1207 int len = cnp->cn_namelen;
1210 MARK_ENTRY(CODA_REMOVE_STATS);
1212 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1213 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1214 cp->c_fid.Unique)););
1216 /* Remove the file's entry from the CODA Name Cache */
1217 /* We're being conservative here, it might be that this person
1218 * doesn't really have sufficient access to delete the file
1219 * but we feel zapping the entry won't really hurt anyone -- dcs
1221 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1222 * exist, and one is removed, the link count on the other will be
1223 * off by 1. We could either invalidate the attrs if cached, or
1224 * fix them. I'll try to fix them. DCS 11/8/94
1226 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1228 if (VALID_VATTR(tp)) { /* If attrs are cached */
1229 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1230 tp->c_vattr.va_nlink--;
1234 coda_nc_zapfile(VTOC(dvp), nm, len);
1235 /* No need to flush it if it doesn't exist! */
1237 /* Invalidate the parent's attr cache, the modification time has changed */
1238 VTOC(dvp)->c_flags &= ~C_VATTR;
1240 /* Check for remove of control object. */
1241 if (IS_CTL_NAME(dvp, nm, len)) {
1242 MARK_INT_FAIL(CODA_REMOVE_STATS);
1246 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1248 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1258 struct vop_link_args *ap = v;
1259 struct vnode *vp = ap->a_vp;
1260 struct cnode *cp = VTOC(vp);
1261 struct vnode *tdvp = ap->a_tdvp;
1262 struct cnode *tdcp = VTOC(tdvp);
1263 struct componentname *cnp = ap->a_cnp;
1264 struct ucred *cred = cnp->cn_cred;
1265 struct thread *td = cnp->cn_td;
1268 const char *nm = cnp->cn_nameptr;
1269 int len = cnp->cn_namelen;
1271 MARK_ENTRY(CODA_LINK_STATS);
1273 if (codadebug & CODADBGMSK(CODA_LINK)) {
1275 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1276 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1277 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1278 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1281 if (codadebug & CODADBGMSK(CODA_LINK)) {
1282 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1283 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1284 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1285 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1289 /* Check for link to/from control object. */
1290 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1291 MARK_INT_FAIL(CODA_LINK_STATS);
1295 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1297 /* Invalidate the parent's attr cache, the modification time has changed */
1298 VTOC(tdvp)->c_flags &= ~C_VATTR;
1299 VTOC(vp)->c_flags &= ~C_VATTR;
1301 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1311 struct vop_rename_args *ap = v;
1312 struct vnode *odvp = ap->a_fdvp;
1313 struct cnode *odcp = VTOC(odvp);
1314 struct componentname *fcnp = ap->a_fcnp;
1315 struct vnode *ndvp = ap->a_tdvp;
1316 struct cnode *ndcp = VTOC(ndvp);
1317 struct componentname *tcnp = ap->a_tcnp;
1318 struct ucred *cred = fcnp->cn_cred;
1319 struct thread *td = fcnp->cn_td;
1322 const char *fnm = fcnp->cn_nameptr;
1323 int flen = fcnp->cn_namelen;
1324 const char *tnm = tcnp->cn_nameptr;
1325 int tlen = tcnp->cn_namelen;
1327 MARK_ENTRY(CODA_RENAME_STATS);
1329 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1330 This could be Bad. XXX */
1331 #ifdef OLD_DIAGNOSTIC
1332 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1334 panic("coda_rename: component names don't agree");
1338 /* Check for rename involving control object. */
1339 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1340 MARK_INT_FAIL(CODA_RENAME_STATS);
1344 /* Problem with moving directories -- need to flush entry for .. */
1346 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1348 struct vnode *ovp = CTOV(ovcp);
1350 (ovp->v_type == VDIR)) /* If it's a directory */
1351 coda_nc_zapfile(VTOC(ovp),"..", 2);
1355 /* Remove the entries for both source and target files */
1356 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1357 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1359 /* Invalidate the parent's attr cache, the modification time has changed */
1360 VTOC(odvp)->c_flags &= ~C_VATTR;
1361 VTOC(ndvp)->c_flags &= ~C_VATTR;
1363 if (flen+1 > CODA_MAXNAMLEN) {
1364 MARK_INT_FAIL(CODA_RENAME_STATS);
1369 if (tlen+1 > CODA_MAXNAMLEN) {
1370 MARK_INT_FAIL(CODA_RENAME_STATS);
1375 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1378 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1379 /* XXX - do we need to call cache pureg on the moved vnode? */
1380 cache_purge(ap->a_fvp);
1382 /* It seems to be incumbent on us to drop locks on all four vnodes */
1383 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1389 if (ap->a_tvp == ndvp) {
1405 struct vop_mkdir_args *ap = v;
1406 struct vnode *dvp = ap->a_dvp;
1407 struct cnode *dcp = VTOC(dvp);
1408 struct componentname *cnp = ap->a_cnp;
1409 register struct vattr *va = ap->a_vap;
1410 struct vnode **vpp = ap->a_vpp;
1411 struct ucred *cred = cnp->cn_cred;
1412 struct thread *td = cnp->cn_td;
1415 const char *nm = cnp->cn_nameptr;
1416 int len = cnp->cn_namelen;
1421 MARK_ENTRY(CODA_MKDIR_STATS);
1423 /* Check for mkdir of target object. */
1424 if (IS_CTL_NAME(dvp, nm, len)) {
1425 *vpp = (struct vnode *)0;
1426 MARK_INT_FAIL(CODA_MKDIR_STATS);
1430 if (len+1 > CODA_MAXNAMLEN) {
1431 *vpp = (struct vnode *)0;
1432 MARK_INT_FAIL(CODA_MKDIR_STATS);
1436 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1439 if (coda_find(&VFid) != NULL)
1440 panic("cnode existed for newly created directory!");
1443 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1446 /* enter the new vnode in the Name Cache */
1447 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1449 /* as a side effect, enter "." and ".." for the directory */
1450 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1451 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1453 if (coda_attr_cache) {
1454 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1455 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1458 /* Invalidate the parent's attr cache, the modification time has changed */
1459 VTOC(dvp)->c_flags &= ~C_VATTR;
1461 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1462 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1464 *vpp = (struct vnode *)0;
1465 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1476 struct vop_rmdir_args *ap = v;
1477 struct vnode *dvp = ap->a_dvp;
1478 struct cnode *dcp = VTOC(dvp);
1479 struct componentname *cnp = ap->a_cnp;
1480 struct ucred *cred = cnp->cn_cred;
1481 struct thread *td = cnp->cn_td;
1484 const char *nm = cnp->cn_nameptr;
1485 int len = cnp->cn_namelen;
1488 MARK_ENTRY(CODA_RMDIR_STATS);
1490 /* Check for rmdir of control object. */
1491 if (IS_CTL_NAME(dvp, nm, len)) {
1492 MARK_INT_FAIL(CODA_RMDIR_STATS);
1496 /* We're being conservative here, it might be that this person
1497 * doesn't really have sufficient access to delete the file
1498 * but we feel zapping the entry won't really hurt anyone -- dcs
1501 * As a side effect of the rmdir, remove any entries for children of
1502 * the directory, especially "." and "..".
1504 cp = coda_nc_lookup(dcp, nm, len, cred);
1505 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1507 /* Remove the file's entry from the CODA Name Cache */
1508 coda_nc_zapfile(dcp, nm, len);
1510 /* Invalidate the parent's attr cache, the modification time has changed */
1511 dcp->c_flags &= ~C_VATTR;
1513 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1515 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1525 struct vop_symlink_args *ap = v;
1526 struct vnode *tdvp = ap->a_dvp;
1527 struct cnode *tdcp = VTOC(tdvp);
1528 struct componentname *cnp = ap->a_cnp;
1529 struct vattr *tva = ap->a_vap;
1530 char *path = ap->a_target;
1531 struct ucred *cred = cnp->cn_cred;
1532 struct thread *td = cnp->cn_td;
1533 struct vnode **vpp = ap->a_vpp;
1537 * XXX I'm assuming the following things about coda_symlink's
1539 * t(foo) is the new name/parent/etc being created.
1540 * lname is the contents of the new symlink.
1542 char *nm = cnp->cn_nameptr;
1543 int len = cnp->cn_namelen;
1544 int plen = strlen(path);
1547 * Here's the strategy for the moment: perform the symlink, then
1548 * do a lookup to grab the resulting vnode. I know this requires
1549 * two communications with Venus for a new sybolic link, but
1550 * that's the way the ball bounces. I don't yet want to change
1551 * the way the Mach symlink works. When Mach support is
1552 * deprecated, we should change symlink so that the common case
1553 * returns the resultant vnode in a vpp argument.
1556 MARK_ENTRY(CODA_SYMLINK_STATS);
1558 /* Check for symlink of control object. */
1559 if (IS_CTL_NAME(tdvp, nm, len)) {
1560 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1564 if (plen+1 > CODA_MAXPATHLEN) {
1565 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1569 if (len+1 > CODA_MAXNAMLEN) {
1570 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1575 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1577 /* Invalidate the parent's attr cache, the modification time has changed */
1578 tdcp->c_flags &= ~C_VATTR;
1581 error = VOP_LOOKUP(tdvp, vpp, cnp);
1584 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1589 * Read directory entries.
1596 struct vop_readdir_args *ap = v;
1597 struct vnode *vp = ap->a_vp;
1598 struct cnode *cp = VTOC(vp);
1599 register struct uio *uiop = ap->a_uio;
1600 struct ucred *cred = ap->a_cred;
1601 int *eofflag = ap->a_eofflag;
1602 u_long **cookies = ap->a_cookies;
1603 int *ncookies = ap->a_ncookies;
1604 struct thread *td = ap->a_uio->uio_td;
1609 MARK_ENTRY(CODA_READDIR_STATS);
1611 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1612 (void *)uiop->uio_iov->iov_base,
1614 (long long)uiop->uio_offset,
1615 uiop->uio_segflg)); )
1617 /* Check for readdir of control object. */
1618 if (IS_CTL_VP(vp)) {
1619 MARK_INT_FAIL(CODA_READDIR_STATS);
1624 /* If directory is not already open do an "internal open" on it. */
1625 int opened_internally = 0;
1626 if (cp->c_ovp == NULL) {
1627 opened_internally = 1;
1628 MARK_INT_GEN(CODA_OPEN_STATS);
1629 error = VOP_OPEN(vp, FREAD, cred, td);
1630 printf("coda_readdir: Internally Opening %p\n", vp);
1632 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1635 if (vp->v_type == VREG) {
1636 error = vfs_object_create(vp, td);
1638 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1642 if (error) return(error);
1645 /* Have UFS handle the call. */
1646 CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vp->v_usecount)); )
1647 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1651 MARK_INT_FAIL(CODA_READDIR_STATS);
1653 MARK_INT_SAT(CODA_READDIR_STATS);
1655 /* Do an "internal close" if necessary. */
1656 if (opened_internally) {
1657 MARK_INT_GEN(CODA_CLOSE_STATS);
1658 (void)VOP_CLOSE(vp, FREAD, td);
1666 * Convert from file system blocks to device blocks
1672 /* XXX on the global proc */
1674 struct vop_bmap_args *ap = v;
1675 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1676 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1677 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1678 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1688 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1690 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1691 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1696 printf("coda_bmap: no container\n");
1703 * I don't think the following two things are used anywhere, so I've
1704 * commented them out
1706 * struct buf *async_bufhead;
1707 * int async_daemon_count;
1714 struct vop_strategy_args *ap = v;
1715 register struct buf *bp __attribute__((unused)) = ap->a_bp;
1719 printf("coda_strategy: called ???\n");
1728 struct vop_reclaim_args *ap = v;
1729 struct vnode *vp = ap->a_vp;
1730 struct cnode *cp = VTOC(vp);
1735 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1739 if (IS_UNMOUNTING(cp)) {
1741 if (VTOC(vp)->c_ovp) {
1742 if (IS_UNMOUNTING(cp))
1743 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1747 #ifdef OLD_DIAGNOSTIC
1748 if (vp->v_usecount != 0)
1749 print("coda_reclaim: pushing active %p\n", vp);
1750 if (VTOC(vp)->c_ovp) {
1751 panic("coda_reclaim: c_ovp not void");
1756 coda_free(VTOC(vp));
1766 struct vop_lock_args *ap = v;
1767 struct vnode *vp = ap->a_vp;
1768 struct cnode *cp = VTOC(vp);
1769 struct thread *td = ap->a_td;
1775 if (coda_lockdebug) {
1776 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1777 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1781 return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td));
1783 return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td,
1784 "coda_lock", vp->filename, vp->line));
1793 struct vop_unlock_args *ap = v;
1794 struct vnode *vp = ap->a_vp;
1795 struct cnode *cp = VTOC(vp);
1796 struct thread *td = ap->a_td;
1801 if (coda_lockdebug) {
1802 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1803 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1806 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td));
1814 struct vop_islocked_args *ap = v;
1815 struct cnode *cp = VTOC(ap->a_vp);
1818 return (lockstatus(&cp->c_lock, ap->a_td));
1821 /* How one looks up a vnode given a device/inode pair: */
1823 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1825 /* This is like VFS_VGET() or igetinode()! */
1829 if (!(mp = devtomp(dev))) {
1830 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1831 (u_long)dev2udev(dev)));
1835 /* XXX - ensure that nonzero-return means failure */
1836 error = VFS_VGET(mp,ino,vpp);
1838 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1839 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1851 switch (attr->va_type) {
1885 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1886 typestr, (int)attr->va_mode, (int)attr->va_uid,
1887 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1889 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1890 (int)attr->va_fileid, (int)attr->va_nlink,
1892 (int)attr->va_blocksize,(int)attr->va_bytes));
1893 myprintf((" gen %ld flags %ld vaflags %d\n",
1894 attr->va_gen, attr->va_flags, attr->va_vaflags));
1895 myprintf((" atime sec %d nsec %d\n",
1896 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1897 myprintf((" mtime sec %d nsec %d\n",
1898 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1899 myprintf((" ctime sec %d nsec %d\n",
1900 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1903 /* How to print a ucred */
1911 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1913 for (i=0; i < cred->cr_ngroups; i++)
1914 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1920 * Return a vnode for the given fid.
1921 * If no cnode exists for this fid create one and put it
1922 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1923 * this fid is already in the table return it (ref count is
1924 * incremented by coda_find. The cnode will be flushed from the
1925 * table when coda_inactive calls coda_unsave.
1928 make_coda_node(fid, vfsp, type)
1929 ViceFid *fid; struct mount *vfsp; short type;
1934 if ((cp = coda_find(fid)) == NULL) {
1938 lockinit(&cp->c_lock, PINOD, "cnode", 0, 0);
1941 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1943 panic("coda: getnewvnode returned error %d\n", err);