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.13 2004/02/16 19:56:26 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>
71 #include "coda_vnops.h"
72 #include "coda_venus.h"
73 #include "coda_opstats.h"
74 #include "coda_subr.h"
75 #include "coda_namecache.h"
76 #include "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 int (**coda_vnodeop_p)(void *);
87 /* structure to keep track of vfs calls */
89 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
91 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
92 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
93 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
94 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
96 /* What we are delaying for in printf */
97 int coda_printf_delay = 0; /* in microseconds */
98 int coda_vnop_print_entry = 0;
99 static int coda_lockdebug = 0;
101 /* Definition of the vfs operation vector */
104 * Some NetBSD details:
106 * coda_start is called at the end of the mount syscall.
107 * coda_init is called at boot time.
110 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
112 /* Definition of the vnode operation vector */
114 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
115 { &vop_default_desc, coda_vop_error },
116 { &vop_lookup_desc, coda_lookup }, /* lookup */
117 { &vop_create_desc, coda_create }, /* create */
118 { &vop_mknod_desc, coda_vop_error }, /* mknod */
119 { &vop_open_desc, coda_open }, /* open */
120 { &vop_close_desc, coda_close }, /* close */
121 { &vop_access_desc, coda_access }, /* access */
122 { &vop_getattr_desc, coda_getattr }, /* getattr */
123 { &vop_setattr_desc, coda_setattr }, /* setattr */
124 { &vop_read_desc, coda_read }, /* read */
125 { &vop_write_desc, coda_write }, /* write */
126 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
127 { &vop_mmap_desc, coda_vop_error }, /* mmap */
128 { &vop_fsync_desc, coda_fsync }, /* fsync */
129 { &vop_remove_desc, coda_remove }, /* remove */
130 { &vop_link_desc, coda_link }, /* link */
131 { &vop_rename_desc, coda_rename }, /* rename */
132 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
133 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
134 { &vop_symlink_desc, coda_symlink }, /* symlink */
135 { &vop_readdir_desc, coda_readdir }, /* readdir */
136 { &vop_readlink_desc, coda_readlink }, /* readlink */
137 { &vop_inactive_desc, coda_inactive }, /* inactive */
138 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
139 { &vop_lock_desc, coda_lock }, /* lock */
140 { &vop_unlock_desc, coda_unlock }, /* unlock */
141 { &vop_bmap_desc, coda_bmap }, /* bmap */
142 { &vop_strategy_desc, coda_strategy }, /* strategy */
143 { &vop_print_desc, coda_vop_error }, /* print */
144 { &vop_islocked_desc, coda_islocked }, /* islocked */
145 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
146 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
147 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
148 { &vop_lease_desc, coda_vop_nop }, /* lease */
149 { &vop_poll_desc, (vop_t *) vop_stdpoll },
150 { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
151 { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
152 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
153 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
154 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
158 we need to define these someday
159 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
160 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
161 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
162 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
163 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
166 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
167 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
168 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
170 { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
173 static struct vnodeopv_desc coda_vnodeop_opv_desc =
174 { &coda_vnodeop_p, coda_vnodeop_entries };
176 VNODEOP_SET(coda_vnodeop_opv_desc);
178 /* A generic panic: we were called with something we didn't define yet */
180 coda_vop_error(void *anon) {
181 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
183 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
184 (*desc)->vdesc_name));
186 panic("coda_vop_error");
191 /* A generic do-nothing. For lease_check, advlock */
193 coda_vop_nop(void *anon) {
194 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
197 myprintf(("Vnode operation %s called, but unsupported\n",
198 (*desc)->vdesc_name));
204 coda_vnodeopstats_init(void)
208 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
209 coda_vnodeopstats[i].opcode = i;
210 coda_vnodeopstats[i].entries = 0;
211 coda_vnodeopstats[i].sat_intrn = 0;
212 coda_vnodeopstats[i].unsat_intrn = 0;
213 coda_vnodeopstats[i].gen_intrn = 0;
219 * coda_open calls Venus to return the device, inode pair of the cache
220 * file holding the data. Using iget, coda_open finds the vnode of the
221 * cache file, and then opens it.
228 * NetBSD can pass the O_EXCL flag in mode, even though the check
229 * has already happened. Venus defensively assumes that if open
230 * is passed the EXCL, it must be a bug. We strip the flag here.
233 struct vop_open_args *ap = v;
234 struct vnode **vpp = &(ap->a_vp);
235 struct cnode *cp = VTOC(*vpp);
236 int flag = ap->a_mode & (~O_EXCL);
237 struct ucred *cred = ap->a_cred;
238 struct thread *td = ap->a_td;
245 MARK_ENTRY(CODA_OPEN_STATS);
247 /* Check for open of control file. */
248 if (IS_CTL_VP(*vpp)) {
250 /* if (WRITEABLE(flag)) */
251 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
252 MARK_INT_FAIL(CODA_OPEN_STATS);
255 MARK_INT_SAT(CODA_OPEN_STATS);
259 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
263 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
264 (u_long)dev2udev(dev), (u_long)inode,
268 /* Translate the <device, inode> pair for the cache file into
270 error = coda_grab_vnode(dev, inode, &vp);
274 /* We get the vnode back locked. Needs unlocked */
275 VOP_UNLOCK(vp, 0, td);
276 /* Keep a reference until the close comes in. */
279 /* Save the vnode pointer for the cache file. */
280 if (cp->c_ovp == NULL) {
284 panic("coda_open: cp->c_ovp != ITOV(ip)");
288 /* Flush the attribute cached if writing the file. */
291 cp->c_flags &= ~C_VATTR;
294 /* Save the <device, inode> pair for the cache file to speed
295 up subsequent page_read's. */
299 /* Open the cache file. */
300 error = VOP_OPEN(vp, flag, cred, td);
302 printf("coda_open: VOP_OPEN on container failed %d\n", error);
305 /* grab (above) does this when it calls newvnode unless it's in the cache*/
306 if (vp->v_type == VREG) {
307 error = vfs_object_create(vp, td);
309 printf("coda_open: vfs_object_create() returns %d\n", error);
318 * Close the cache file used for I/O and notify Venus.
325 struct vop_close_args *ap = v;
326 struct vnode *vp = ap->a_vp;
327 struct cnode *cp = VTOC(vp);
328 int flag = ap->a_fflag;
329 struct thread *td = ap->a_td;
333 MARK_ENTRY(CODA_CLOSE_STATS);
335 /* Check for close of control file. */
337 MARK_INT_SAT(CODA_CLOSE_STATS);
341 if (IS_UNMOUNTING(cp)) {
344 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
345 vp->v_usecount, cp->c_ovp, vp, cp);
350 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
355 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
360 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
364 if (--cp->c_ocount == 0)
367 if (flag & FWRITE) /* file was opened for write */
370 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
373 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
381 struct vop_read_args *ap = v;
384 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
385 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
392 struct vop_write_args *ap = v;
395 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
396 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
400 coda_rdwr(vp, uiop, rw, ioflag, cred, td)
409 /* NOTE: container file operation!!! */
411 struct cnode *cp = VTOC(vp);
412 struct vnode *cfvp = cp->c_ovp;
413 int igot_internally = 0;
414 int opened_internally = 0;
417 MARK_ENTRY(CODA_RDWR_STATS);
419 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
420 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
421 (long long)uiop->uio_offset, uiop->uio_segflg)); )
423 /* Check for rdwr of control object. */
425 MARK_INT_FAIL(CODA_RDWR_STATS);
430 * If file is not already open this must be a page
431 * {read,write} request. Iget the cache file's inode
432 * pointer if we still have its <device, inode> pair.
433 * Otherwise, we must do an internal open to derive the
438 * If we're dumping core, do the internal open. Otherwise
439 * venus won't have the correct size of the core when
440 * it's completely written.
442 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
444 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
446 MARK_INT_FAIL(CODA_RDWR_STATS);
450 * We get the vnode back locked in both Mach and
451 * NetBSD. Needs unlocked
453 VOP_UNLOCK(cfvp, 0, td);
456 opened_internally = 1;
457 MARK_INT_GEN(CODA_OPEN_STATS);
458 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
460 printf("coda_rdwr: Internally Opening %p\n", vp);
462 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
465 if (vp->v_type == VREG) {
466 error = vfs_object_create(vp, td);
468 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
473 MARK_INT_FAIL(CODA_RDWR_STATS);
480 /* Have UFS handle the call. */
481 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
482 cp->c_fid.Volume, cp->c_fid.Vnode,
483 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
486 if (rw == UIO_READ) {
487 error = VOP_READ(cfvp, uiop, ioflag, cred);
489 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
490 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
494 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
495 vnode_pager_setsize(vp, attr.va_size);
501 MARK_INT_FAIL(CODA_RDWR_STATS);
503 MARK_INT_SAT(CODA_RDWR_STATS);
505 /* Do an internal close if necessary. */
506 if (opened_internally) {
507 MARK_INT_GEN(CODA_CLOSE_STATS);
508 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
511 /* Invalidate cached attributes if writing. */
513 cp->c_flags &= ~C_VATTR;
522 struct vop_ioctl_args *ap = v;
523 struct vnode *vp = ap->a_vp;
524 int com = ap->a_command;
525 caddr_t data = ap->a_data;
526 int flag = ap->a_fflag;
527 struct ucred *cred = ap->a_cred;
528 struct thread *td = ap->a_td;
532 struct nameidata ndp;
533 struct PioctlData *iap = (struct PioctlData *)data;
535 MARK_ENTRY(CODA_IOCTL_STATS);
537 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
539 /* Don't check for operation on a dying object, for ctlvp it
542 /* Must be control object to succeed. */
543 if (!IS_CTL_VP(vp)) {
544 MARK_INT_FAIL(CODA_IOCTL_STATS);
545 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
548 /* Look up the pathname. */
550 /* Should we use the name cache here? It would get it from
551 lookupname sooner or later anyway, right? */
553 NDINIT(&ndp, NAMEI_LOOKUP, (iap->follow ? CNP_FOLLOW : 0), UIO_USERSPACE, iap->path, td);
558 MARK_INT_FAIL(CODA_IOCTL_STATS);
559 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
565 * Make sure this is a coda style cnode, but it may be a
568 if (tvp->v_op != coda_vnodeop_p) {
570 NDFREE(&ndp, NDF_ONLY_PNBUF);
571 MARK_INT_FAIL(CODA_IOCTL_STATS);
572 CODADEBUG(CODA_IOCTL,
573 myprintf(("coda_ioctl error: %s not a coda object\n",
578 if (iap->vi.in_size > VC_MAXDATASIZE) {
582 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
585 MARK_INT_FAIL(CODA_IOCTL_STATS);
587 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
590 NDFREE(&ndp, NDF_ONLY_PNBUF);
595 * To reduce the cost of a user-level venus;we cache attributes in
596 * the kernel. Each cnode has storage allocated for an attribute. If
597 * c_vattr is valid, return a reference to it. Otherwise, get the
598 * attributes from venus and store them in the cnode. There is some
599 * question if this method is a security leak. But I think that in
600 * order to make this call, the user must have done a lookup and
601 * opened the file, and therefore should already have access.
608 struct vop_getattr_args *ap = v;
609 struct vnode *vp = ap->a_vp;
610 struct cnode *cp = VTOC(vp);
611 struct vattr *vap = ap->a_vap;
612 struct thread *td = ap->a_td;
616 MARK_ENTRY(CODA_GETATTR_STATS);
618 if (IS_UNMOUNTING(cp))
621 /* Check for getattr of control object. */
623 MARK_INT_FAIL(CODA_GETATTR_STATS);
627 /* Check to see if the attributes have already been cached */
628 if (VALID_VATTR(cp)) {
629 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
632 cp->c_fid.Unique));});
633 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
634 print_vattr(&cp->c_vattr); );
637 MARK_INT_SAT(CODA_GETATTR_STATS);
641 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
644 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
650 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
653 { int size = vap->va_size;
654 struct vnode *convp = cp->c_ovp;
655 if (convp != (struct vnode *)0) {
656 vnode_pager_setsize(convp, size);
659 /* If not open for write, store attributes in cnode */
660 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
662 cp->c_flags |= C_VATTR;
674 struct vop_setattr_args *ap = v;
675 struct vnode *vp = ap->a_vp;
676 struct cnode *cp = VTOC(vp);
677 struct vattr *vap = ap->a_vap;
678 struct ucred *cred = ap->a_cred;
679 struct thread *td = ap->a_td;
683 MARK_ENTRY(CODA_SETATTR_STATS);
685 /* Check for setattr of control object. */
687 MARK_INT_FAIL(CODA_SETATTR_STATS);
691 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
694 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
697 cp->c_flags &= ~C_VATTR;
699 { int size = vap->va_size;
700 struct vnode *convp = cp->c_ovp;
701 if (size != VNOVAL && convp != (struct vnode *)0) {
702 vnode_pager_setsize(convp, size);
705 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
714 struct vop_access_args *ap = v;
715 struct vnode *vp = ap->a_vp;
716 struct cnode *cp = VTOC(vp);
717 int mode = ap->a_mode;
718 struct ucred *cred = ap->a_cred;
719 struct thread *td = ap->a_td;
723 MARK_ENTRY(CODA_ACCESS_STATS);
725 /* Check for access of control object. Only read access is
728 /* bogus hack - all will be marked as successes */
729 MARK_INT_SAT(CODA_ACCESS_STATS);
730 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
735 * if the file is a directory, and we are checking exec (eg lookup)
736 * access, and the file is in the namecache, then the user must have
737 * lookup access to it.
739 if (coda_access_cache) {
740 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
741 if (coda_nc_lookup(cp, ".", 1, cred)) {
742 MARK_INT_SAT(CODA_ACCESS_STATS);
743 return(0); /* it was in the cache */
748 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
758 struct vop_readlink_args *ap = v;
759 struct vnode *vp = ap->a_vp;
760 struct cnode *cp = VTOC(vp);
761 struct uio *uiop = ap->a_uio;
762 struct ucred *cred = ap->a_cred;
763 struct thread *td = ap->a_uio->uio_td;
769 MARK_ENTRY(CODA_READLINK_STATS);
771 /* Check for readlink of control object. */
773 MARK_INT_FAIL(CODA_READLINK_STATS);
777 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
778 uiop->uio_rw = UIO_READ;
779 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
781 MARK_INT_FAIL(CODA_READLINK_STATS);
783 MARK_INT_SAT(CODA_READLINK_STATS);
787 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
790 uiop->uio_rw = UIO_READ;
791 error = uiomove(str, len, uiop);
793 if (coda_symlink_cache) {
796 cp->c_flags |= C_SYMLINK;
801 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
810 struct vop_fsync_args *ap = v;
811 struct vnode *vp = ap->a_vp;
812 struct cnode *cp = VTOC(vp);
813 struct thread *td = ap->a_td;
815 struct vnode *convp = cp->c_ovp;
818 MARK_ENTRY(CODA_FSYNC_STATS);
820 /* Check for fsync on an unmounting object */
821 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
822 * after an unmount has been initiated. This is a Bad Thing,
823 * which we have to avoid. Not a legitimate failure for stats.
825 if (IS_UNMOUNTING(cp)) {
829 /* Check for fsync of control object. */
831 MARK_INT_SAT(CODA_FSYNC_STATS);
836 VOP_FSYNC(convp, MNT_WAIT, td);
839 * We see fsyncs with usecount == 1 then usecount == 0.
840 * For now we ignore them.
843 if (!vp->v_usecount) {
844 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
845 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
850 * We can expect fsync on any vnode at all if venus is pruging it.
851 * Venus can't very well answer the fsync request, now can it?
852 * Hopefully, it won't have to, because hopefully, venus preserves
853 * the (possibly untrue) invariant that it never purges an open
856 if (cp->c_flags & C_PURGING) {
862 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
864 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
872 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
873 have a proc pointer. Oops. */
875 struct vop_inactive_args *ap = v;
876 struct vnode *vp = ap->a_vp;
877 struct cnode *cp = VTOC(vp);
878 struct ucred *cred __attribute__((unused)) = NULL;
879 struct thread *td = curthread;
883 /* We don't need to send inactive to venus - DCS */
884 MARK_ENTRY(CODA_INACTIVE_STATS);
887 MARK_INT_SAT(CODA_INACTIVE_STATS);
891 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
892 cp->c_fid.Volume, cp->c_fid.Vnode,
893 cp->c_fid.Unique, vp->v_mount));)
895 /* If an array has been allocated to hold the symlink, deallocate it */
896 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
897 if (cp->c_symlink == NULL)
898 panic("coda_inactive: null symlink pointer in cnode");
900 CODA_FREE(cp->c_symlink, cp->c_symlen);
901 cp->c_flags &= ~C_SYMLINK;
905 /* Remove it from the table so it can't be found. */
907 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
908 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
909 panic("badness in coda_inactive\n");
912 if (IS_UNMOUNTING(cp)) {
914 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
915 if (cp->c_ovp != NULL)
916 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
917 vp->v_usecount, vp, cp);
919 lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td);
921 #ifdef OLD_DIAGNOSTIC
922 if (CTOV(cp)->v_usecount) {
923 panic("coda_inactive: nonzero reference count");
925 if (cp->c_ovp != NULL) {
926 panic("coda_inactive: cp->ovp != NULL");
929 VOP_UNLOCK(vp, 0, td);
933 MARK_INT_SAT(CODA_INACTIVE_STATS);
938 * Remote file system operations having to do with directory manipulation.
942 * It appears that in NetBSD, lookup is supposed to return the vnode locked
949 struct vop_lookup_args *ap = v;
950 struct vnode *dvp = ap->a_dvp;
951 struct cnode *dcp = VTOC(dvp);
952 struct vnode **vpp = ap->a_vpp;
954 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
955 * of the string to xlate, and that we must try to get at least
956 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
959 struct componentname *cnp = ap->a_cnp;
960 struct ucred *cred = cnp->cn_cred;
961 struct thread *td = cnp->cn_td;
964 const char *nm = cnp->cn_nameptr;
965 int len = cnp->cn_namelen;
970 MARK_ENTRY(CODA_LOOKUP_STATS);
972 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
973 nm, dcp->c_fid.Volume,
974 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
976 /* Check for lookup of control object. */
977 if (IS_CTL_NAME(dvp, nm, len)) {
980 MARK_INT_SAT(CODA_LOOKUP_STATS);
984 if (len+1 > CODA_MAXNAMLEN) {
985 MARK_INT_FAIL(CODA_LOOKUP_STATS);
986 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
987 dcp->c_fid.Volume, dcp->c_fid.Vnode,
988 dcp->c_fid.Unique, nm)););
989 *vpp = (struct vnode *)0;
993 /* First try to look the file up in the cfs name cache */
994 /* lock the parent vnode? */
995 cp = coda_nc_lookup(dcp, nm, len, cred);
999 CODADEBUG(CODA_LOOKUP,
1000 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
1003 /* The name wasn't cached, so we need to contact Venus */
1004 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
1007 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1008 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1009 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1010 *vpp = (struct vnode *)0;
1012 MARK_INT_SAT(CODA_LOOKUP_STATS);
1013 CODADEBUG(CODA_LOOKUP,
1014 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1015 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1018 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1021 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1022 /* And don't enter a new vnode for an invalid one! */
1023 if (!(vtype & CODA_NOCACHE))
1024 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1030 * If we are creating, and this was the last name to be looked up,
1031 * and the error was ENOENT, then there really shouldn't be an
1032 * error and we can make the leaf NULL and return success. Since
1033 * this is supposed to work under Mach as well as NetBSD, we're
1034 * leaving this fn wrapped. We also must tell lookup/namei that
1035 * we need to save the last component of the name. (Create will
1036 * have to free the name buffer later...lucky us...)
1038 if (((cnp->cn_nameiop == NAMEI_CREATE) || (cnp->cn_nameiop == NAMEI_RENAME))
1039 && (cnp->cn_flags & CNP_ISLASTCN)
1040 && (error == ENOENT))
1042 error = EJUSTRETURN;
1043 cnp->cn_flags |= CNP_SAVENAME;
1048 * If we are removing, and we are at the last element, and we
1049 * found it, then we need to keep the name around so that the
1050 * removal will go ahead as planned. Unfortunately, this will
1051 * probably also lock the to-be-removed vnode, which may or may
1052 * not be a good idea. I'll have to look at the bits of
1053 * coda_remove to make sure. We'll only save the name if we did in
1054 * fact find the name, otherwise coda_remove won't have a chance
1055 * to free the pathname.
1057 if ((cnp->cn_nameiop == NAMEI_DELETE)
1058 && (cnp->cn_flags & CNP_ISLASTCN)
1061 cnp->cn_flags |= CNP_SAVENAME;
1065 * If the lookup went well, we need to (potentially?) unlock the
1066 * parent, and lock the child. We are only responsible for
1067 * checking to see if the parent is supposed to be unlocked before
1068 * we return. We must always lock the child (provided there is
1069 * one, and (the parent isn't locked or it isn't the same as the
1070 * parent.) Simple, huh? We can never leave the parent locked unless
1073 if (!error || (error == EJUSTRETURN)) {
1074 if (!(cnp->cn_flags & CNP_LOCKPARENT) || !(cnp->cn_flags & CNP_ISLASTCN)) {
1075 if ((error = VOP_UNLOCK(dvp, 0, td))) {
1079 * The parent is unlocked. As long as there is a child,
1080 * lock it without bothering to check anything else.
1083 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1084 printf("coda_lookup: ");
1085 panic("unlocked parent but couldn't lock child");
1089 /* The parent is locked, and may be the same as the child */
1090 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1091 /* Different, go ahead and lock it. */
1092 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1093 printf("coda_lookup: ");
1094 panic("unlocked parent but couldn't lock child");
1099 /* If the lookup failed, we need to ensure that the leaf is NULL */
1100 /* Don't change any locking? */
1112 struct vop_create_args *ap = v;
1113 struct vnode *dvp = ap->a_dvp;
1114 struct cnode *dcp = VTOC(dvp);
1115 struct vattr *va = ap->a_vap;
1117 int mode = ap->a_vap->va_mode;
1118 struct vnode **vpp = ap->a_vpp;
1119 struct componentname *cnp = ap->a_cnp;
1120 struct ucred *cred = cnp->cn_cred;
1121 struct thread *td = cnp->cn_td;
1125 const char *nm = cnp->cn_nameptr;
1126 int len = cnp->cn_namelen;
1130 MARK_ENTRY(CODA_CREATE_STATS);
1132 /* All creates are exclusive XXX */
1133 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1135 /* Check for create of control object. */
1136 if (IS_CTL_NAME(dvp, nm, len)) {
1137 *vpp = (struct vnode *)0;
1138 MARK_INT_FAIL(CODA_CREATE_STATS);
1142 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1146 /* If this is an exclusive create, panic if the file already exists. */
1147 /* Venus should have detected the file and reported EEXIST. */
1149 if ((exclusive == 1) &&
1150 (coda_find(&VFid) != NULL))
1151 panic("cnode existed for newly created file!");
1153 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1156 /* Update va to reflect the new attributes. */
1159 /* Update the attribute cache and mark it as valid */
1160 if (coda_attr_cache) {
1161 VTOC(*vpp)->c_vattr = attr;
1162 VTOC(*vpp)->c_flags |= C_VATTR;
1165 /* Invalidate the parent's attr cache, the modification time has changed */
1166 VTOC(dvp)->c_flags &= ~C_VATTR;
1168 /* enter the new vnode in the Name Cache */
1169 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1171 CODADEBUG(CODA_CREATE,
1172 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1173 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1175 *vpp = (struct vnode *)0;
1176 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1180 if (cnp->cn_flags & CNP_LOCKLEAF) {
1181 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1182 printf("coda_create: ");
1183 panic("unlocked parent but couldn't lock child");
1186 #ifdef OLD_DIAGNOSTIC
1188 printf("coda_create: LOCKLEAF not set!\n");
1200 struct vop_remove_args *ap = v;
1201 struct vnode *dvp = ap->a_dvp;
1202 struct cnode *cp = VTOC(dvp);
1203 struct componentname *cnp = ap->a_cnp;
1204 struct ucred *cred = cnp->cn_cred;
1205 struct thread *td = cnp->cn_td;
1208 const char *nm = cnp->cn_nameptr;
1209 int len = cnp->cn_namelen;
1212 MARK_ENTRY(CODA_REMOVE_STATS);
1214 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1215 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1216 cp->c_fid.Unique)););
1218 /* Remove the file's entry from the CODA Name Cache */
1219 /* We're being conservative here, it might be that this person
1220 * doesn't really have sufficient access to delete the file
1221 * but we feel zapping the entry won't really hurt anyone -- dcs
1223 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1224 * exist, and one is removed, the link count on the other will be
1225 * off by 1. We could either invalidate the attrs if cached, or
1226 * fix them. I'll try to fix them. DCS 11/8/94
1228 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1230 if (VALID_VATTR(tp)) { /* If attrs are cached */
1231 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1232 tp->c_vattr.va_nlink--;
1236 coda_nc_zapfile(VTOC(dvp), nm, len);
1237 /* No need to flush it if it doesn't exist! */
1239 /* Invalidate the parent's attr cache, the modification time has changed */
1240 VTOC(dvp)->c_flags &= ~C_VATTR;
1242 /* Check for remove of control object. */
1243 if (IS_CTL_NAME(dvp, nm, len)) {
1244 MARK_INT_FAIL(CODA_REMOVE_STATS);
1248 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1250 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1260 struct vop_link_args *ap = v;
1261 struct vnode *vp = ap->a_vp;
1262 struct cnode *cp = VTOC(vp);
1263 struct vnode *tdvp = ap->a_tdvp;
1264 struct cnode *tdcp = VTOC(tdvp);
1265 struct componentname *cnp = ap->a_cnp;
1266 struct ucred *cred = cnp->cn_cred;
1267 struct thread *td = cnp->cn_td;
1270 const char *nm = cnp->cn_nameptr;
1271 int len = cnp->cn_namelen;
1273 MARK_ENTRY(CODA_LINK_STATS);
1275 if (codadebug & CODADBGMSK(CODA_LINK)) {
1277 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1278 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1279 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1280 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1283 if (codadebug & CODADBGMSK(CODA_LINK)) {
1284 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1285 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1286 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1287 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1291 /* Check for link to/from control object. */
1292 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1293 MARK_INT_FAIL(CODA_LINK_STATS);
1297 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1299 /* Invalidate the parent's attr cache, the modification time has changed */
1300 VTOC(tdvp)->c_flags &= ~C_VATTR;
1301 VTOC(vp)->c_flags &= ~C_VATTR;
1303 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1313 struct vop_rename_args *ap = v;
1314 struct vnode *odvp = ap->a_fdvp;
1315 struct cnode *odcp = VTOC(odvp);
1316 struct componentname *fcnp = ap->a_fcnp;
1317 struct vnode *ndvp = ap->a_tdvp;
1318 struct cnode *ndcp = VTOC(ndvp);
1319 struct componentname *tcnp = ap->a_tcnp;
1320 struct ucred *cred = fcnp->cn_cred;
1321 struct thread *td = fcnp->cn_td;
1324 const char *fnm = fcnp->cn_nameptr;
1325 int flen = fcnp->cn_namelen;
1326 const char *tnm = tcnp->cn_nameptr;
1327 int tlen = tcnp->cn_namelen;
1329 MARK_ENTRY(CODA_RENAME_STATS);
1331 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1332 This could be Bad. XXX */
1333 #ifdef OLD_DIAGNOSTIC
1334 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1336 panic("coda_rename: component names don't agree");
1340 /* Check for rename involving control object. */
1341 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1342 MARK_INT_FAIL(CODA_RENAME_STATS);
1346 /* Problem with moving directories -- need to flush entry for .. */
1348 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1350 struct vnode *ovp = CTOV(ovcp);
1352 (ovp->v_type == VDIR)) /* If it's a directory */
1353 coda_nc_zapfile(VTOC(ovp),"..", 2);
1357 /* Remove the entries for both source and target files */
1358 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1359 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1361 /* Invalidate the parent's attr cache, the modification time has changed */
1362 VTOC(odvp)->c_flags &= ~C_VATTR;
1363 VTOC(ndvp)->c_flags &= ~C_VATTR;
1365 if (flen+1 > CODA_MAXNAMLEN) {
1366 MARK_INT_FAIL(CODA_RENAME_STATS);
1371 if (tlen+1 > CODA_MAXNAMLEN) {
1372 MARK_INT_FAIL(CODA_RENAME_STATS);
1377 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1380 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1381 /* XXX - do we need to call cache pureg on the moved vnode? */
1382 cache_purge(ap->a_fvp);
1384 /* It seems to be incumbent on us to drop locks on all four vnodes */
1385 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1391 if (ap->a_tvp == ndvp) {
1407 struct vop_mkdir_args *ap = v;
1408 struct vnode *dvp = ap->a_dvp;
1409 struct cnode *dcp = VTOC(dvp);
1410 struct componentname *cnp = ap->a_cnp;
1411 struct vattr *va = ap->a_vap;
1412 struct vnode **vpp = ap->a_vpp;
1413 struct ucred *cred = cnp->cn_cred;
1414 struct thread *td = cnp->cn_td;
1417 const char *nm = cnp->cn_nameptr;
1418 int len = cnp->cn_namelen;
1423 MARK_ENTRY(CODA_MKDIR_STATS);
1425 /* Check for mkdir of target object. */
1426 if (IS_CTL_NAME(dvp, nm, len)) {
1427 *vpp = (struct vnode *)0;
1428 MARK_INT_FAIL(CODA_MKDIR_STATS);
1432 if (len+1 > CODA_MAXNAMLEN) {
1433 *vpp = (struct vnode *)0;
1434 MARK_INT_FAIL(CODA_MKDIR_STATS);
1438 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1441 if (coda_find(&VFid) != NULL)
1442 panic("cnode existed for newly created directory!");
1445 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1448 /* enter the new vnode in the Name Cache */
1449 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1451 /* as a side effect, enter "." and ".." for the directory */
1452 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1453 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1455 if (coda_attr_cache) {
1456 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1457 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1460 /* Invalidate the parent's attr cache, the modification time has changed */
1461 VTOC(dvp)->c_flags &= ~C_VATTR;
1463 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1464 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1466 *vpp = (struct vnode *)0;
1467 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1478 struct vop_rmdir_args *ap = v;
1479 struct vnode *dvp = ap->a_dvp;
1480 struct cnode *dcp = VTOC(dvp);
1481 struct componentname *cnp = ap->a_cnp;
1482 struct ucred *cred = cnp->cn_cred;
1483 struct thread *td = cnp->cn_td;
1486 const char *nm = cnp->cn_nameptr;
1487 int len = cnp->cn_namelen;
1490 MARK_ENTRY(CODA_RMDIR_STATS);
1492 /* Check for rmdir of control object. */
1493 if (IS_CTL_NAME(dvp, nm, len)) {
1494 MARK_INT_FAIL(CODA_RMDIR_STATS);
1498 /* We're being conservative here, it might be that this person
1499 * doesn't really have sufficient access to delete the file
1500 * but we feel zapping the entry won't really hurt anyone -- dcs
1503 * As a side effect of the rmdir, remove any entries for children of
1504 * the directory, especially "." and "..".
1506 cp = coda_nc_lookup(dcp, nm, len, cred);
1507 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1509 /* Remove the file's entry from the CODA Name Cache */
1510 coda_nc_zapfile(dcp, nm, len);
1512 /* Invalidate the parent's attr cache, the modification time has changed */
1513 dcp->c_flags &= ~C_VATTR;
1515 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1517 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1527 struct vop_symlink_args *ap = v;
1528 struct vnode *tdvp = ap->a_dvp;
1529 struct cnode *tdcp = VTOC(tdvp);
1530 struct componentname *cnp = ap->a_cnp;
1531 struct vattr *tva = ap->a_vap;
1532 char *path = ap->a_target;
1533 struct ucred *cred = cnp->cn_cred;
1534 struct thread *td = cnp->cn_td;
1535 struct vnode **vpp = ap->a_vpp;
1539 * XXX I'm assuming the following things about coda_symlink's
1541 * t(foo) is the new name/parent/etc being created.
1542 * lname is the contents of the new symlink.
1544 char *nm = cnp->cn_nameptr;
1545 int len = cnp->cn_namelen;
1546 int plen = strlen(path);
1549 * Here's the strategy for the moment: perform the symlink, then
1550 * do a lookup to grab the resulting vnode. I know this requires
1551 * two communications with Venus for a new sybolic link, but
1552 * that's the way the ball bounces. I don't yet want to change
1553 * the way the Mach symlink works. When Mach support is
1554 * deprecated, we should change symlink so that the common case
1555 * returns the resultant vnode in a vpp argument.
1558 MARK_ENTRY(CODA_SYMLINK_STATS);
1560 /* Check for symlink of control object. */
1561 if (IS_CTL_NAME(tdvp, nm, len)) {
1562 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1566 if (plen+1 > CODA_MAXPATHLEN) {
1567 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1571 if (len+1 > CODA_MAXNAMLEN) {
1572 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1577 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1579 /* Invalidate the parent's attr cache, the modification time has changed */
1580 tdcp->c_flags &= ~C_VATTR;
1583 error = VOP_LOOKUP(tdvp, NCPNULL, vpp, NCPPNULL, cnp);
1586 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1591 * Read directory entries.
1598 struct vop_readdir_args *ap = v;
1599 struct vnode *vp = ap->a_vp;
1600 struct cnode *cp = VTOC(vp);
1601 struct uio *uiop = ap->a_uio;
1602 struct ucred *cred = ap->a_cred;
1603 int *eofflag = ap->a_eofflag;
1604 u_long **cookies = ap->a_cookies;
1605 int *ncookies = ap->a_ncookies;
1606 struct thread *td = ap->a_uio->uio_td;
1611 MARK_ENTRY(CODA_READDIR_STATS);
1613 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1614 (void *)uiop->uio_iov->iov_base,
1616 (long long)uiop->uio_offset,
1617 uiop->uio_segflg)); )
1619 /* Check for readdir of control object. */
1620 if (IS_CTL_VP(vp)) {
1621 MARK_INT_FAIL(CODA_READDIR_STATS);
1626 /* If directory is not already open do an "internal open" on it. */
1627 int opened_internally = 0;
1628 if (cp->c_ovp == NULL) {
1629 opened_internally = 1;
1630 MARK_INT_GEN(CODA_OPEN_STATS);
1631 error = VOP_OPEN(vp, FREAD, cred, td);
1632 printf("coda_readdir: Internally Opening %p\n", vp);
1634 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1637 if (vp->v_type == VREG) {
1638 error = vfs_object_create(vp, td);
1640 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1644 if (error) return(error);
1647 /* Have UFS handle the call. */
1648 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)); )
1649 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1653 MARK_INT_FAIL(CODA_READDIR_STATS);
1655 MARK_INT_SAT(CODA_READDIR_STATS);
1657 /* Do an "internal close" if necessary. */
1658 if (opened_internally) {
1659 MARK_INT_GEN(CODA_CLOSE_STATS);
1660 (void)VOP_CLOSE(vp, FREAD, td);
1668 * Convert from file system blocks to device blocks
1674 /* XXX on the global proc */
1676 struct vop_bmap_args *ap = v;
1677 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1678 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1679 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1680 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1690 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1692 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1693 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1698 printf("coda_bmap: no container\n");
1705 * I don't think the following two things are used anywhere, so I've
1706 * commented them out
1708 * struct buf *async_bufhead;
1709 * int async_daemon_count;
1716 struct vop_strategy_args *ap = v;
1717 struct buf *bp __attribute__((unused)) = ap->a_bp;
1721 printf("coda_strategy: called ???\n");
1730 struct vop_reclaim_args *ap = v;
1731 struct vnode *vp = ap->a_vp;
1732 struct cnode *cp = VTOC(vp);
1737 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1741 if (IS_UNMOUNTING(cp)) {
1743 if (VTOC(vp)->c_ovp) {
1744 if (IS_UNMOUNTING(cp))
1745 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1749 #ifdef OLD_DIAGNOSTIC
1750 if (vp->v_usecount != 0)
1751 print("coda_reclaim: pushing active %p\n", vp);
1752 if (VTOC(vp)->c_ovp) {
1753 panic("coda_reclaim: c_ovp not void");
1758 coda_free(VTOC(vp));
1768 struct vop_lock_args *ap = v;
1769 struct vnode *vp = ap->a_vp;
1770 struct cnode *cp = VTOC(vp);
1771 struct thread *td = ap->a_td;
1777 if (coda_lockdebug) {
1778 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1779 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1783 return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td));
1785 return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td,
1786 "coda_lock", vp->filename, vp->line));
1795 struct vop_unlock_args *ap = v;
1796 struct vnode *vp = ap->a_vp;
1797 struct cnode *cp = VTOC(vp);
1798 struct thread *td = ap->a_td;
1803 if (coda_lockdebug) {
1804 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1805 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1808 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td));
1816 struct vop_islocked_args *ap = v;
1817 struct cnode *cp = VTOC(ap->a_vp);
1820 return (lockstatus(&cp->c_lock, ap->a_td));
1823 /* How one looks up a vnode given a device/inode pair: */
1825 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1827 /* This is like VFS_VGET() or igetinode()! */
1831 if (!(mp = devtomp(dev))) {
1832 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1833 (u_long)dev2udev(dev)));
1837 /* XXX - ensure that nonzero-return means failure */
1838 error = VFS_VGET(mp,ino,vpp);
1840 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1841 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1853 switch (attr->va_type) {
1887 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1888 typestr, (int)attr->va_mode, (int)attr->va_uid,
1889 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1891 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1892 (int)attr->va_fileid, (int)attr->va_nlink,
1894 (int)attr->va_blocksize,(int)attr->va_bytes));
1895 myprintf((" gen %ld flags %ld vaflags %d\n",
1896 attr->va_gen, attr->va_flags, attr->va_vaflags));
1897 myprintf((" atime sec %d nsec %d\n",
1898 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1899 myprintf((" mtime sec %d nsec %d\n",
1900 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1901 myprintf((" ctime sec %d nsec %d\n",
1902 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1905 /* How to print a ucred */
1913 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1915 for (i=0; i < cred->cr_ngroups; i++)
1916 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1922 * Return a vnode for the given fid.
1923 * If no cnode exists for this fid create one and put it
1924 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1925 * this fid is already in the table return it (ref count is
1926 * incremented by coda_find. The cnode will be flushed from the
1927 * table when coda_inactive calls coda_unsave.
1930 make_coda_node(fid, vfsp, type)
1931 ViceFid *fid; struct mount *vfsp; short type;
1936 if ((cp = coda_find(fid)) == NULL) {
1940 lockinit(&cp->c_lock, 0, "cnode", 0, 0);
1943 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1945 panic("coda: getnewvnode returned error %d\n", err);