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.39 2006/07/18 22:22:15 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/nlookup.h>
61 #include <sys/namei.h>
62 #include <sys/ioccom.h>
63 #include <sys/select.h>
66 #include <vm/vm_object.h>
67 #include <vm/vm_extern.h>
68 #include <vm/vm_zone.h>
72 #include "coda_vnops.h"
73 #include "coda_venus.h"
74 #include "coda_opstats.h"
75 #include "coda_subr.h"
76 #include "coda_namecache.h"
77 #include "coda_pioctl.h"
80 * These flags select various performance enhancements.
82 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
83 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
84 int coda_access_cache = 1; /* Set to handle some access checks directly */
86 /* structure to keep track of vfs calls */
88 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
90 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
91 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
92 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
93 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
95 /* What we are delaying for in printf */
96 int coda_printf_delay = 0; /* in microseconds */
97 int coda_vnop_print_entry = 0;
98 static int coda_lockdebug = 0;
100 /* Definition of the vfs operation vector */
103 * Some NetBSD details:
105 * coda_start is called at the end of the mount syscall.
106 * coda_init is called at boot time.
109 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
111 /* Definition of the vnode operation vector */
113 struct vop_ops coda_vnode_ops = {
114 .vop_default = (void *)coda_vop_error,
115 .vop_old_lookup = (void *)coda_lookup,
116 .vop_old_create = (void *)coda_create,
117 .vop_old_mknod = (void *)coda_vop_error,
118 .vop_open = (void *)coda_open,
119 .vop_close = (void *)coda_close,
120 .vop_access = (void *)coda_access,
121 .vop_getattr = (void *)coda_getattr,
122 .vop_setattr = (void *)coda_setattr,
123 .vop_read = (void *)coda_read,
124 .vop_write = (void *)coda_write,
125 .vop_ioctl = (void *)coda_ioctl,
126 .vop_mmap = (void *)coda_vop_error,
127 .vop_fsync = (void *)coda_fsync,
128 .vop_old_remove = (void *)coda_remove,
129 .vop_old_link = (void *)coda_link,
130 .vop_old_rename = (void *)coda_rename,
131 .vop_old_mkdir = (void *)coda_mkdir,
132 .vop_old_rmdir = (void *)coda_rmdir,
133 .vop_old_symlink = (void *)coda_symlink,
134 .vop_readdir = (void *)coda_readdir,
135 .vop_readlink = (void *)coda_readlink,
136 .vop_inactive = (void *)coda_inactive,
137 .vop_reclaim = (void *)coda_reclaim,
138 .vop_lock = (void *)coda_lock,
139 .vop_unlock = (void *)coda_unlock,
140 .vop_bmap = (void *)coda_bmap,
141 .vop_strategy = (void *)coda_strategy,
142 .vop_print = (void *)coda_vop_error,
143 .vop_islocked = (void *)coda_islocked,
144 .vop_pathconf = (void *)coda_vop_error,
145 .vop_advlock = (void *)coda_vop_nop,
146 .vop_poll = vop_stdpoll,
147 .vop_getpages = (void *)coda_fbsd_getpages,
148 .vop_putpages = (void *)coda_fbsd_putpages
151 /* A generic panic: we were called with something we didn't define yet */
153 coda_vop_error(void *anon)
155 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
157 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
158 (*desc)->vdesc_name));
160 panic("coda_vop_error");
165 /* A generic do-nothing. For lease_check, advlock */
167 coda_vop_nop(void *anon)
169 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
172 myprintf(("Vnode operation %s called, but unsupported\n",
173 (*desc)->vdesc_name));
179 coda_vnodeopstats_init(void)
183 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
184 coda_vnodeopstats[i].opcode = i;
185 coda_vnodeopstats[i].entries = 0;
186 coda_vnodeopstats[i].sat_intrn = 0;
187 coda_vnodeopstats[i].unsat_intrn = 0;
188 coda_vnodeopstats[i].gen_intrn = 0;
194 * coda_open calls Venus to return the device, inode pair of the cache
195 * file holding the data. Using iget, coda_open finds the vnode of the
196 * cache file, and then opens it.
202 * NetBSD can pass the O_EXCL flag in mode, even though the check
203 * has already happened. Venus defensively assumes that if open
204 * is passed the EXCL, it must be a bug. We strip the flag here.
207 struct vop_open_args *ap = v;
208 struct vnode **vpp = &(ap->a_vp);
209 struct cnode *cp = VTOC(*vpp);
210 int flag = ap->a_mode & (~O_EXCL);
211 struct ucred *cred = ap->a_cred;
212 struct thread *td = curthread;
219 MARK_ENTRY(CODA_OPEN_STATS);
221 /* Check for open of control file. */
222 if (IS_CTL_VP(*vpp)) {
224 /* if (WRITEABLE(flag)) */
225 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
226 MARK_INT_FAIL(CODA_OPEN_STATS);
230 MARK_INT_SAT(CODA_OPEN_STATS);
235 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
239 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
240 (u_long)dev2udev(dev), (u_long)inode,
244 /* Translate the <device, inode> pair for the cache file into
246 error = coda_grab_vnode(dev, inode, &vp);
250 /* We get the vnode back locked. Needs unlocked */
252 /* Keep a reference until the close comes in. */
255 /* Save the vnode pointer for the cache file. */
256 if (cp->c_ovp == NULL) {
260 panic("coda_open: cp->c_ovp != ITOV(ip)");
264 /* Flush the attribute cached if writing the file. */
267 cp->c_flags &= ~C_VATTR;
270 /* Save the <device, inode> pair for the cache file to speed
271 up subsequent page_read's. */
275 /* Open the cache file. */
276 error = VOP_OPEN(vp, flag, cred, NULL);
278 printf("coda_open: VOP_OPEN on container failed %d\n", error);
281 /* grab (above) does this when it calls newvnode unless it's in the cache*/
282 if (vp->v_type == VREG) {
283 if (vp->v_object == NULL) {
285 printf("coda_open: cache file vp %p has no VM object!\n", vp);
296 * Close the cache file used for I/O and notify Venus.
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 struct thread *td = curthread;
310 MARK_ENTRY(CODA_CLOSE_STATS);
312 /* Check for close of control file. */
314 MARK_INT_SAT(CODA_CLOSE_STATS);
319 if (IS_UNMOUNTING(cp)) {
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);
328 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
333 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
339 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
343 if (--cp->c_ocount == 0)
346 if (flag & FWRITE) /* file was opened for write */
349 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
352 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
361 struct vop_read_args *ap = v;
364 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
365 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
371 struct vop_write_args *ap = v;
374 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
375 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
379 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
380 struct ucred *cred, struct thread *td)
383 /* NOTE: container file operation!!! */
385 struct cnode *cp = VTOC(vp);
386 struct vnode *cfvp = cp->c_ovp;
387 int igot_internally = 0;
388 int opened_internally = 0;
391 MARK_ENTRY(CODA_RDWR_STATS);
393 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
394 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
395 (long long)uiop->uio_offset, uiop->uio_segflg)); )
397 /* Check for rdwr of control object. */
399 MARK_INT_FAIL(CODA_RDWR_STATS);
404 * If file is not already open this must be a page
405 * {read,write} request. Iget the cache file's inode
406 * pointer if we still have its <device, inode> pair.
407 * Otherwise, we must do an internal open to derive the
412 * If we're dumping core, do the internal open. Otherwise
413 * venus won't have the correct size of the core when
414 * it's completely written.
416 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
418 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
420 MARK_INT_FAIL(CODA_RDWR_STATS);
424 * We get the vnode back locked in both Mach and
425 * NetBSD. Needs unlocked
430 opened_internally = 1;
431 MARK_INT_GEN(CODA_OPEN_STATS);
432 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, NULL);
433 printf("coda_rdwr: Internally Opening %p\n", vp);
435 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
438 if (vp->v_type == VREG) {
439 if (vp->v_object == NULL) {
441 printf("coda_rdwr: vnode %p has no VM object!\n", vp);
446 MARK_INT_FAIL(CODA_RDWR_STATS);
453 /* Have UFS handle the call. */
454 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
455 cp->c_fid.Volume, cp->c_fid.Vnode,
456 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
459 if (rw == UIO_READ) {
460 error = VOP_READ(cfvp, uiop, ioflag, cred);
462 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
463 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
467 if (VOP_GETATTR(cfvp, &attr) == 0) {
468 vnode_pager_setsize(vp, attr.va_size);
474 MARK_INT_FAIL(CODA_RDWR_STATS);
476 MARK_INT_SAT(CODA_RDWR_STATS);
478 /* Do an internal close if necessary. */
479 if (opened_internally) {
480 MARK_INT_GEN(CODA_CLOSE_STATS);
481 VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE));
484 /* Invalidate cached attributes if writing. */
486 cp->c_flags &= ~C_VATTR;
494 struct vop_ioctl_args *ap = v;
495 struct vnode *vp = ap->a_vp;
496 int com = ap->a_command;
497 caddr_t data = ap->a_data;
498 int flag = ap->a_fflag;
499 struct ucred *cred = ap->a_cred;
500 struct thread *td = curthread;
504 struct nlookupdata nd;
505 struct PioctlData *iap = (struct PioctlData *)data;
507 MARK_ENTRY(CODA_IOCTL_STATS);
509 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
511 /* Don't check for operation on a dying object, for ctlvp it
514 /* Must be control object to succeed. */
515 if (!IS_CTL_VP(vp)) {
516 MARK_INT_FAIL(CODA_IOCTL_STATS);
517 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
520 /* Look up the pathname. */
522 /* Should we use the name cache here? It would get it from
523 lookupname sooner or later anyway, right? */
526 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
527 (iap->follow ? NLC_FOLLOW : 0));
529 error = nlookup(&nd);
531 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
535 MARK_INT_FAIL(CODA_IOCTL_STATS);
536 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
542 * Make sure this is a coda style cnode, but it may be a
545 if (tvp->v_tag != VT_CODA) {
547 MARK_INT_FAIL(CODA_IOCTL_STATS);
548 CODADEBUG(CODA_IOCTL,
549 myprintf(("coda_ioctl error: %s not a coda object\n",
554 if (iap->vi.in_size > VC_MAXDATASIZE) {
558 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
561 MARK_INT_FAIL(CODA_IOCTL_STATS);
563 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
570 * To reduce the cost of a user-level venus;we cache attributes in
571 * the kernel. Each cnode has storage allocated for an attribute. If
572 * c_vattr is valid, return a reference to it. Otherwise, get the
573 * attributes from venus and store them in the cnode. There is some
574 * question if this method is a security leak. But I think that in
575 * order to make this call, the user must have done a lookup and
576 * opened the file, and therefore should already have access.
579 coda_getattr(void *v)
582 struct vop_getattr_args *ap = v;
583 struct vnode *vp = ap->a_vp;
584 struct cnode *cp = VTOC(vp);
585 struct vattr *vap = ap->a_vap;
586 struct thread *td = curthread;
590 MARK_ENTRY(CODA_GETATTR_STATS);
592 if (IS_UNMOUNTING(cp))
595 /* Check for getattr of control object. */
597 MARK_INT_FAIL(CODA_GETATTR_STATS);
601 /* Check to see if the attributes have already been cached */
602 if (VALID_VATTR(cp)) {
603 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
606 cp->c_fid.Unique));});
607 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
608 print_vattr(&cp->c_vattr); );
611 MARK_INT_SAT(CODA_GETATTR_STATS);
615 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
618 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
624 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
627 { int size = vap->va_size;
628 struct vnode *convp = cp->c_ovp;
629 if (convp != (struct vnode *)0) {
630 vnode_pager_setsize(convp, size);
633 /* If not open for write, store attributes in cnode */
634 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
636 cp->c_flags |= C_VATTR;
644 coda_setattr(void *v)
647 struct vop_setattr_args *ap = v;
648 struct vnode *vp = ap->a_vp;
649 struct cnode *cp = VTOC(vp);
650 struct vattr *vap = ap->a_vap;
651 struct ucred *cred = ap->a_cred;
652 struct thread *td = curthread;
656 MARK_ENTRY(CODA_SETATTR_STATS);
658 /* Check for setattr of control object. */
660 MARK_INT_FAIL(CODA_SETATTR_STATS);
664 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
667 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
670 cp->c_flags &= ~C_VATTR;
672 { int size = vap->va_size;
673 struct vnode *convp = cp->c_ovp;
674 if (size != VNOVAL && convp != (struct vnode *)0) {
675 vnode_pager_setsize(convp, size);
678 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
686 struct vop_access_args *ap = v;
687 struct vnode *vp = ap->a_vp;
688 struct cnode *cp = VTOC(vp);
689 int mode = ap->a_mode;
690 struct ucred *cred = ap->a_cred;
691 struct thread *td = curthread;
695 MARK_ENTRY(CODA_ACCESS_STATS);
697 /* Check for access of control object. Only read access is
700 /* bogus hack - all will be marked as successes */
701 MARK_INT_SAT(CODA_ACCESS_STATS);
702 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
707 * if the file is a directory, and we are checking exec (eg lookup)
708 * access, and the file is in the namecache, then the user must have
709 * lookup access to it.
711 if (coda_access_cache) {
712 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
713 if (coda_nc_lookup(cp, ".", 1, cred)) {
714 MARK_INT_SAT(CODA_ACCESS_STATS);
715 return(0); /* it was in the cache */
720 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
726 coda_readlink(void *v)
729 struct vop_readlink_args *ap = v;
730 struct vnode *vp = ap->a_vp;
731 struct cnode *cp = VTOC(vp);
732 struct uio *uiop = ap->a_uio;
733 struct ucred *cred = ap->a_cred;
734 struct thread *td = ap->a_uio->uio_td;
740 MARK_ENTRY(CODA_READLINK_STATS);
742 /* Check for readlink of control object. */
744 MARK_INT_FAIL(CODA_READLINK_STATS);
748 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
749 uiop->uio_rw = UIO_READ;
750 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
752 MARK_INT_FAIL(CODA_READLINK_STATS);
754 MARK_INT_SAT(CODA_READLINK_STATS);
758 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
761 uiop->uio_rw = UIO_READ;
762 error = uiomove(str, len, uiop);
764 if (coda_symlink_cache) {
767 cp->c_flags |= C_SYMLINK;
772 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
780 struct vop_fsync_args *ap = v;
781 struct vnode *vp = ap->a_vp;
782 struct cnode *cp = VTOC(vp);
783 struct thread *td = curthread;
785 struct vnode *convp = cp->c_ovp;
788 MARK_ENTRY(CODA_FSYNC_STATS);
790 /* Check for fsync on an unmounting object */
791 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
792 * after an unmount has been initiated. This is a Bad Thing,
793 * which we have to avoid. Not a legitimate failure for stats.
795 if (IS_UNMOUNTING(cp)) {
799 /* Check for fsync of control object. */
801 MARK_INT_SAT(CODA_FSYNC_STATS);
806 VOP_FSYNC(convp, MNT_WAIT);
809 * We see fsyncs with usecount == 1 then usecount == 0.
810 * For now we ignore them.
813 if (!vp->v_usecount) {
814 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
815 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
820 * We can expect fsync on any vnode at all if venus is pruging it.
821 * Venus can't very well answer the fsync request, now can it?
822 * Hopefully, it won't have to, because hopefully, venus preserves
823 * the (possibly untrue) invariant that it never purges an open
826 if (cp->c_flags & C_PURGING) {
832 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
834 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
839 coda_inactive(void *v)
841 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
842 have a proc pointer. Oops. */
844 struct vop_inactive_args *ap = v;
845 struct vnode *vp = ap->a_vp;
846 struct cnode *cp = VTOC(vp);
847 struct ucred *cred __attribute__((unused)) = NULL;
848 /*struct thread *td = curthread;*/
852 /* We don't need to send inactive to venus - DCS */
853 MARK_ENTRY(CODA_INACTIVE_STATS);
856 MARK_INT_SAT(CODA_INACTIVE_STATS);
860 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
861 cp->c_fid.Volume, cp->c_fid.Vnode,
862 cp->c_fid.Unique, vp->v_mount));)
864 /* If an array has been allocated to hold the symlink, deallocate it */
865 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
866 if (cp->c_symlink == NULL)
867 panic("coda_inactive: null symlink pointer in cnode");
869 CODA_FREE(cp->c_symlink, cp->c_symlen);
870 cp->c_flags &= ~C_SYMLINK;
874 /* Remove it from the table so it can't be found. */
876 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
877 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
878 panic("badness in coda_inactive\n");
881 if (IS_UNMOUNTING(cp)) {
883 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
884 if (cp->c_ovp != NULL)
885 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
886 vp->v_usecount, vp, cp);
889 #ifdef OLD_DIAGNOSTIC
890 if (CTOV(cp)->v_usecount) {
891 panic("coda_inactive: nonzero reference count");
893 if (cp->c_ovp != NULL) {
894 panic("coda_inactive: cp->ovp != NULL");
900 MARK_INT_SAT(CODA_INACTIVE_STATS);
905 * Remote file system operations having to do with directory manipulation.
909 * It appears that in NetBSD, lookup is supposed to return the vnode locked
915 struct vop_old_lookup_args *ap = v;
916 struct vnode *dvp = ap->a_dvp;
917 struct cnode *dcp = VTOC(dvp);
918 struct vnode **vpp = ap->a_vpp;
920 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
921 * of the string to xlate, and that we must try to get at least
922 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
925 struct componentname *cnp = ap->a_cnp;
926 struct ucred *cred = cnp->cn_cred;
927 struct thread *td = cnp->cn_td;
930 const char *nm = cnp->cn_nameptr;
931 int len = cnp->cn_namelen;
936 MARK_ENTRY(CODA_LOOKUP_STATS);
938 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
939 nm, dcp->c_fid.Volume,
940 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
942 /* Check for lookup of control object. */
943 if (IS_CTL_NAME(dvp, nm, len)) {
946 MARK_INT_SAT(CODA_LOOKUP_STATS);
950 if (len+1 > CODA_MAXNAMLEN) {
951 MARK_INT_FAIL(CODA_LOOKUP_STATS);
952 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
953 dcp->c_fid.Volume, dcp->c_fid.Vnode,
954 dcp->c_fid.Unique, nm)););
955 *vpp = (struct vnode *)0;
959 /* First try to look the file up in the cfs name cache */
960 /* lock the parent vnode? */
961 cp = coda_nc_lookup(dcp, nm, len, cred);
965 CODADEBUG(CODA_LOOKUP,
966 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
969 /* The name wasn't cached, so we need to contact Venus */
970 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
973 MARK_INT_FAIL(CODA_LOOKUP_STATS);
974 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
975 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
976 *vpp = (struct vnode *)0;
978 MARK_INT_SAT(CODA_LOOKUP_STATS);
979 CODADEBUG(CODA_LOOKUP,
980 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
981 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
984 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
987 /* enter the new vnode in the Name Cache only if the top bit isn't set */
988 /* And don't enter a new vnode for an invalid one! */
989 if (!(vtype & CODA_NOCACHE))
990 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
996 * If we are creating, and this was the last name to be looked up,
997 * and the error was ENOENT, then there really shouldn't be an
998 * error and we can make the leaf NULL and return success. Since
999 * this is supposed to work under Mach as well as NetBSD, we're
1000 * leaving this fn wrapped. We also must tell lookup/namei that
1001 * we need to save the last component of the name. (Create will
1002 * have to free the name buffer later...lucky us...)
1004 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1007 error = EJUSTRETURN;
1012 * If the lookup went well, we need to (potentially?) unlock the
1013 * parent, and lock the child. We are only responsible for
1014 * checking to see if the parent is supposed to be unlocked before
1015 * we return. We must always lock the child (provided there is
1016 * one, and (the parent isn't locked or it isn't the same as the
1017 * parent.) Simple, huh? We can never leave the parent locked unless
1020 if (!error || (error == EJUSTRETURN)) {
1021 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
1022 if ((error = VOP_UNLOCK(dvp, 0))) {
1026 * The parent is unlocked. As long as there is a child,
1027 * lock it without bothering to check anything else.
1030 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1031 printf("coda_lookup: ");
1032 panic("unlocked parent but couldn't lock child");
1036 /* The parent is locked, and may be the same as the child */
1037 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1038 /* Different, go ahead and lock it. */
1039 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1040 printf("coda_lookup: ");
1041 panic("unlocked parent but couldn't lock child");
1046 /* If the lookup failed, we need to ensure that the leaf is NULL */
1047 /* Don't change any locking? */
1055 coda_create(void *v)
1058 struct vop_old_create_args *ap = v;
1059 struct vnode *dvp = ap->a_dvp;
1060 struct cnode *dcp = VTOC(dvp);
1061 struct vattr *va = ap->a_vap;
1063 int mode = ap->a_vap->va_mode;
1064 struct vnode **vpp = ap->a_vpp;
1065 struct componentname *cnp = ap->a_cnp;
1066 struct ucred *cred = cnp->cn_cred;
1067 struct thread *td = cnp->cn_td;
1071 const char *nm = cnp->cn_nameptr;
1072 int len = cnp->cn_namelen;
1076 MARK_ENTRY(CODA_CREATE_STATS);
1078 /* All creates are exclusive XXX */
1079 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1081 /* Check for create of control object. */
1082 if (IS_CTL_NAME(dvp, nm, len)) {
1083 *vpp = (struct vnode *)0;
1084 MARK_INT_FAIL(CODA_CREATE_STATS);
1088 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1092 /* If this is an exclusive create, panic if the file already exists. */
1093 /* Venus should have detected the file and reported EEXIST. */
1095 if ((exclusive == 1) &&
1096 (coda_find(&VFid) != NULL))
1097 panic("cnode existed for newly created file!");
1099 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1102 /* Update va to reflect the new attributes. */
1105 /* Update the attribute cache and mark it as valid */
1106 if (coda_attr_cache) {
1107 VTOC(*vpp)->c_vattr = attr;
1108 VTOC(*vpp)->c_flags |= C_VATTR;
1111 /* Invalidate the parent's attr cache, the modification time has changed */
1112 VTOC(dvp)->c_flags &= ~C_VATTR;
1114 /* enter the new vnode in the Name Cache */
1115 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1117 CODADEBUG(CODA_CREATE,
1118 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1119 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1121 *vpp = (struct vnode *)0;
1122 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1126 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1127 printf("coda_create: ");
1128 panic("unlocked parent but couldn't lock child");
1135 coda_remove(void *v)
1138 struct vop_old_remove_args *ap = v;
1139 struct vnode *dvp = ap->a_dvp;
1140 struct cnode *cp = VTOC(dvp);
1141 struct componentname *cnp = ap->a_cnp;
1142 struct ucred *cred = cnp->cn_cred;
1143 struct thread *td = cnp->cn_td;
1146 const char *nm = cnp->cn_nameptr;
1147 int len = cnp->cn_namelen;
1150 MARK_ENTRY(CODA_REMOVE_STATS);
1152 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1153 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1154 cp->c_fid.Unique)););
1156 /* Remove the file's entry from the CODA Name Cache */
1157 /* We're being conservative here, it might be that this person
1158 * doesn't really have sufficient access to delete the file
1159 * but we feel zapping the entry won't really hurt anyone -- dcs
1161 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1162 * exist, and one is removed, the link count on the other will be
1163 * off by 1. We could either invalidate the attrs if cached, or
1164 * fix them. I'll try to fix them. DCS 11/8/94
1166 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1168 if (VALID_VATTR(tp)) { /* If attrs are cached */
1169 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1170 tp->c_vattr.va_nlink--;
1174 coda_nc_zapfile(VTOC(dvp), nm, len);
1175 /* No need to flush it if it doesn't exist! */
1177 /* Invalidate the parent's attr cache, the modification time has changed */
1178 VTOC(dvp)->c_flags &= ~C_VATTR;
1180 /* Check for remove of control object. */
1181 if (IS_CTL_NAME(dvp, nm, len)) {
1182 MARK_INT_FAIL(CODA_REMOVE_STATS);
1186 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1188 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1197 struct vop_old_link_args *ap = v;
1198 struct vnode *vp = ap->a_vp;
1199 struct cnode *cp = VTOC(vp);
1200 struct vnode *tdvp = ap->a_tdvp;
1201 struct cnode *tdcp = VTOC(tdvp);
1202 struct componentname *cnp = ap->a_cnp;
1203 struct ucred *cred = cnp->cn_cred;
1204 struct thread *td = cnp->cn_td;
1207 const char *nm = cnp->cn_nameptr;
1208 int len = cnp->cn_namelen;
1210 MARK_ENTRY(CODA_LINK_STATS);
1212 if (codadebug & CODADBGMSK(CODA_LINK)) {
1214 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1215 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1216 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1217 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1220 if (codadebug & CODADBGMSK(CODA_LINK)) {
1221 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1222 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1223 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1224 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1228 /* Check for link to/from control object. */
1229 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1230 MARK_INT_FAIL(CODA_LINK_STATS);
1234 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1236 /* Invalidate the parent's attr cache, the modification time has changed */
1237 VTOC(tdvp)->c_flags &= ~C_VATTR;
1238 VTOC(vp)->c_flags &= ~C_VATTR;
1240 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1246 coda_rename(void *v)
1249 struct vop_old_rename_args *ap = v;
1250 struct vnode *odvp = ap->a_fdvp;
1251 struct cnode *odcp = VTOC(odvp);
1252 struct componentname *fcnp = ap->a_fcnp;
1253 struct vnode *ndvp = ap->a_tdvp;
1254 struct cnode *ndcp = VTOC(ndvp);
1255 struct componentname *tcnp = ap->a_tcnp;
1256 struct ucred *cred = fcnp->cn_cred;
1257 struct thread *td = fcnp->cn_td;
1260 const char *fnm = fcnp->cn_nameptr;
1261 int flen = fcnp->cn_namelen;
1262 const char *tnm = tcnp->cn_nameptr;
1263 int tlen = tcnp->cn_namelen;
1265 MARK_ENTRY(CODA_RENAME_STATS);
1267 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1268 This could be Bad. XXX */
1269 #ifdef OLD_DIAGNOSTIC
1270 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1272 panic("coda_rename: component names don't agree");
1276 /* Check for rename involving control object. */
1277 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1278 MARK_INT_FAIL(CODA_RENAME_STATS);
1282 /* Problem with moving directories -- need to flush entry for .. */
1284 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1286 struct vnode *ovp = CTOV(ovcp);
1288 (ovp->v_type == VDIR)) /* If it's a directory */
1289 coda_nc_zapfile(VTOC(ovp),"..", 2);
1293 /* Remove the entries for both source and target files */
1294 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1295 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1297 /* Invalidate the parent's attr cache, the modification time has changed */
1298 VTOC(odvp)->c_flags &= ~C_VATTR;
1299 VTOC(ndvp)->c_flags &= ~C_VATTR;
1301 if (flen+1 > CODA_MAXNAMLEN) {
1302 MARK_INT_FAIL(CODA_RENAME_STATS);
1307 if (tlen+1 > CODA_MAXNAMLEN) {
1308 MARK_INT_FAIL(CODA_RENAME_STATS);
1313 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1316 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1318 /* It seems to be incumbent on us to drop locks on all four vnodes */
1319 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1325 if (ap->a_tvp == ndvp) {
1340 struct vop_old_mkdir_args *ap = v;
1341 struct vnode *dvp = ap->a_dvp;
1342 struct cnode *dcp = VTOC(dvp);
1343 struct componentname *cnp = ap->a_cnp;
1344 struct vattr *va = ap->a_vap;
1345 struct vnode **vpp = ap->a_vpp;
1346 struct ucred *cred = cnp->cn_cred;
1347 struct thread *td = cnp->cn_td;
1350 const char *nm = cnp->cn_nameptr;
1351 int len = cnp->cn_namelen;
1356 MARK_ENTRY(CODA_MKDIR_STATS);
1358 /* Check for mkdir of target object. */
1359 if (IS_CTL_NAME(dvp, nm, len)) {
1360 *vpp = (struct vnode *)0;
1361 MARK_INT_FAIL(CODA_MKDIR_STATS);
1365 if (len+1 > CODA_MAXNAMLEN) {
1366 *vpp = (struct vnode *)0;
1367 MARK_INT_FAIL(CODA_MKDIR_STATS);
1371 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1374 if (coda_find(&VFid) != NULL)
1375 panic("cnode existed for newly created directory!");
1378 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1381 /* enter the new vnode in the Name Cache */
1382 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1384 /* as a side effect, enter "." and ".." for the directory */
1385 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1386 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1388 if (coda_attr_cache) {
1389 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1390 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1393 /* Invalidate the parent's attr cache, the modification time has changed */
1394 VTOC(dvp)->c_flags &= ~C_VATTR;
1396 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1397 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1399 *vpp = (struct vnode *)0;
1400 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1410 struct vop_old_rmdir_args *ap = v;
1411 struct vnode *dvp = ap->a_dvp;
1412 struct cnode *dcp = VTOC(dvp);
1413 struct componentname *cnp = ap->a_cnp;
1414 struct ucred *cred = cnp->cn_cred;
1415 struct thread *td = cnp->cn_td;
1418 const char *nm = cnp->cn_nameptr;
1419 int len = cnp->cn_namelen;
1422 MARK_ENTRY(CODA_RMDIR_STATS);
1424 /* Check for rmdir of control object. */
1425 if (IS_CTL_NAME(dvp, nm, len)) {
1426 MARK_INT_FAIL(CODA_RMDIR_STATS);
1430 /* We're being conservative here, it might be that this person
1431 * doesn't really have sufficient access to delete the file
1432 * but we feel zapping the entry won't really hurt anyone -- dcs
1435 * As a side effect of the rmdir, remove any entries for children of
1436 * the directory, especially "." and "..".
1438 cp = coda_nc_lookup(dcp, nm, len, cred);
1439 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1441 /* Remove the file's entry from the CODA Name Cache */
1442 coda_nc_zapfile(dcp, nm, len);
1444 /* Invalidate the parent's attr cache, the modification time has changed */
1445 dcp->c_flags &= ~C_VATTR;
1447 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1449 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1455 coda_symlink(void *v)
1458 struct vop_old_symlink_args *ap = v;
1459 struct vnode *tdvp = ap->a_dvp;
1460 struct cnode *tdcp = VTOC(tdvp);
1461 struct componentname *cnp = ap->a_cnp;
1462 struct vattr *tva = ap->a_vap;
1463 char *path = ap->a_target;
1464 struct ucred *cred = cnp->cn_cred;
1465 struct thread *td = cnp->cn_td;
1466 struct vnode **vpp = ap->a_vpp;
1470 * XXX I'm assuming the following things about coda_symlink's
1472 * t(foo) is the new name/parent/etc being created.
1473 * lname is the contents of the new symlink.
1475 char *nm = cnp->cn_nameptr;
1476 int len = cnp->cn_namelen;
1477 int plen = strlen(path);
1480 * Here's the strategy for the moment: perform the symlink, then
1481 * do a lookup to grab the resulting vnode. I know this requires
1482 * two communications with Venus for a new sybolic link, but
1483 * that's the way the ball bounces. I don't yet want to change
1484 * the way the Mach symlink works. When Mach support is
1485 * deprecated, we should change symlink so that the common case
1486 * returns the resultant vnode in a vpp argument.
1489 MARK_ENTRY(CODA_SYMLINK_STATS);
1491 /* Check for symlink of control object. */
1492 if (IS_CTL_NAME(tdvp, nm, len)) {
1493 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1497 if (plen+1 > CODA_MAXPATHLEN) {
1498 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1502 if (len+1 > CODA_MAXNAMLEN) {
1503 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1508 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1510 /* Invalidate the parent's attr cache, the modification time has changed */
1511 tdcp->c_flags &= ~C_VATTR;
1514 error = VOP_OLD_LOOKUP(tdvp, vpp, cnp);
1517 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1522 * Read directory entries.
1525 coda_readdir(void *v)
1528 struct vop_readdir_args *ap = v;
1529 struct vnode *vp = ap->a_vp;
1530 struct cnode *cp = VTOC(vp);
1531 struct uio *uiop = ap->a_uio;
1532 struct ucred *cred = ap->a_cred;
1533 int *eofflag = ap->a_eofflag;
1534 u_long **cookies = ap->a_cookies;
1535 int *ncookies = ap->a_ncookies;
1540 MARK_ENTRY(CODA_READDIR_STATS);
1542 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1543 (void *)uiop->uio_iov->iov_base,
1545 (long long)uiop->uio_offset,
1546 uiop->uio_segflg)); )
1548 /* Check for readdir of control object. */
1549 if (IS_CTL_VP(vp)) {
1550 MARK_INT_FAIL(CODA_READDIR_STATS);
1555 /* If directory is not already open do an "internal open" on it. */
1556 int opened_internally = 0;
1557 if (cp->c_ovp == NULL) {
1558 opened_internally = 1;
1559 MARK_INT_GEN(CODA_OPEN_STATS);
1560 error = VOP_OPEN(vp, FREAD, cred, NULL);
1561 printf("coda_readdir: Internally Opening %p\n", vp);
1563 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1566 if (vp->v_type == VREG) {
1567 if (vp->v_object == NULL) {
1569 printf("coda_readdir: vnode %p has no VM object!\n", vp);
1573 if (error) return(error);
1576 /* Have UFS handle the call. */
1577 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)); )
1578 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1582 MARK_INT_FAIL(CODA_READDIR_STATS);
1584 MARK_INT_SAT(CODA_READDIR_STATS);
1586 /* Do an "internal close" if necessary. */
1587 if (opened_internally) {
1588 MARK_INT_GEN(CODA_CLOSE_STATS);
1589 VOP_CLOSE(vp, FREAD);
1597 * Convert from file system blocks to device blocks
1602 /* XXX on the global proc */
1603 struct vop_bmap_args *ap = v;
1607 cp = VTOC(ap->a_vp);
1611 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1612 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1613 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1618 printf("coda_bmap: no container\n");
1625 * I don't think the following two things are used anywhere, so I've
1626 * commented them out
1628 * struct buf *async_bufhead;
1629 * int async_daemon_count;
1632 coda_strategy(struct vop_strategy_args *ap __unused)
1634 printf("coda_strategy: called ???\n");
1639 coda_reclaim(void *v)
1642 struct vop_reclaim_args *ap = v;
1643 struct vnode *vp = ap->a_vp;
1644 struct cnode *cp = VTOC(vp);
1649 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1653 if (IS_UNMOUNTING(cp)) {
1655 if (VTOC(vp)->c_ovp) {
1656 if (IS_UNMOUNTING(cp))
1657 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1661 #ifdef OLD_DIAGNOSTIC
1662 if (vp->v_usecount != 0)
1663 print("coda_reclaim: pushing active %p\n", vp);
1664 if (VTOC(vp)->c_ovp) {
1665 panic("coda_reclaim: c_ovp not void");
1669 coda_free(VTOC(vp));
1678 struct vop_lock_args *ap = v;
1679 struct vnode *vp = ap->a_vp;
1680 struct cnode *cp = VTOC(vp);
1686 if (coda_lockdebug) {
1687 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1688 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1692 return (lockmgr(&vp->v_lock, ap->a_flags));
1694 return (debuglockmgr(&vp->v_lock, ap->a_flags,
1695 "coda_lock", vp->filename, vp->line));
1700 coda_unlock(void *v)
1703 struct vop_unlock_args *ap = v;
1704 struct vnode *vp = ap->a_vp;
1705 struct cnode *cp = VTOC(vp);
1710 if (coda_lockdebug) {
1711 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1712 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1715 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE));
1719 coda_islocked(void *v)
1722 struct vop_islocked_args *ap = v;
1725 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1728 /* How one looks up a vnode given a device/inode pair: */
1730 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1732 /* This is like VFS_VGET() or igetinode()! */
1736 if (!(mp = devtomp(dev))) {
1737 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1738 (u_long)dev2udev(dev)));
1742 /* XXX - ensure that nonzero-return means failure */
1743 error = VFS_VGET(mp,ino,vpp);
1745 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1746 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1753 print_vattr(struct vattr *attr)
1757 switch (attr->va_type) {
1791 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1792 typestr, (int)attr->va_mode, (int)attr->va_uid,
1793 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1795 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1796 (int)attr->va_fileid, (int)attr->va_nlink,
1798 (int)attr->va_blocksize,(int)attr->va_bytes));
1799 myprintf((" gen %ld flags %ld vaflags %d\n",
1800 attr->va_gen, attr->va_flags, attr->va_vaflags));
1801 myprintf((" atime sec %d nsec %d\n",
1802 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1803 myprintf((" mtime sec %d nsec %d\n",
1804 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1805 myprintf((" ctime sec %d nsec %d\n",
1806 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1809 /* How to print a ucred */
1811 print_cred(struct ucred *cred)
1816 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1818 for (i=0; i < cred->cr_ngroups; i++)
1819 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1825 * Return a vnode for the given fid.
1826 * If no cnode exists for this fid create one and put it
1827 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1828 * this fid is already in the table return it (ref count is
1829 * incremented by coda_find. The cnode will be flushed from the
1830 * table when coda_inactive calls coda_unsave.
1833 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1838 if ((cp = coda_find(fid)) == NULL) {
1844 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
1846 panic("coda: getnewvnode returned error %d\n", err);