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.43 2006/08/12 00:26:20 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 static int coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw,
114 int ioflag, struct ucred *cred, struct thread *p);
116 static int coda_vop_error(struct vop_generic_args *ap);
117 static int coda_vop_nop(struct vop_generic_args *ap);
119 static int coda_lookup(struct vop_old_lookup_args *ap);
120 static int coda_create(struct vop_old_create_args *ap);
121 static int coda_open(struct vop_open_args *ap);
122 static int coda_close(struct vop_close_args *ap);
123 static int coda_access(struct vop_access_args *ap);
124 static int coda_getattr(struct vop_getattr_args *ap);
125 static int coda_setattr(struct vop_setattr_args *ap);
126 static int coda_read(struct vop_read_args *ap);
127 static int coda_write(struct vop_write_args *ap);
128 static int coda_ioctl(struct vop_ioctl_args *ap);
129 static int coda_fsync(struct vop_fsync_args *ap);
130 static int coda_remove(struct vop_old_remove_args *ap);
131 static int coda_link(struct vop_old_link_args *ap);
132 static int coda_rename(struct vop_old_rename_args *ap);
133 static int coda_mkdir(struct vop_old_mkdir_args *ap);
134 static int coda_rmdir(struct vop_old_rmdir_args *ap);
135 static int coda_symlink(struct vop_old_symlink_args *ap);
136 static int coda_readdir(struct vop_readdir_args *ap);
137 static int coda_readlink(struct vop_readlink_args *ap);
138 static int coda_inactive(struct vop_inactive_args *ap);
139 static int coda_reclaim(struct vop_reclaim_args *ap);
140 static int coda_bmap(struct vop_bmap_args *ap);
141 static int coda_strategy(struct vop_strategy_args *ap);
143 struct vop_ops coda_vnode_ops = {
144 .vop_default = (void *)coda_vop_error,
145 .vop_old_lookup = coda_lookup,
146 .vop_old_create = coda_create,
147 .vop_old_mknod = (void *)coda_vop_error,
148 .vop_open = coda_open,
149 .vop_close = coda_close,
150 .vop_access = coda_access,
151 .vop_getattr = coda_getattr,
152 .vop_setattr = coda_setattr,
153 .vop_read = coda_read,
154 .vop_write = coda_write,
155 .vop_ioctl = coda_ioctl,
156 .vop_mmap = (void *)coda_vop_error,
157 .vop_fsync = coda_fsync,
158 .vop_old_remove = coda_remove,
159 .vop_old_link = coda_link,
160 .vop_old_rename = coda_rename,
161 .vop_old_mkdir = coda_mkdir,
162 .vop_old_rmdir = coda_rmdir,
163 .vop_old_symlink = coda_symlink,
164 .vop_readdir = coda_readdir,
165 .vop_readlink = coda_readlink,
166 .vop_inactive = coda_inactive,
167 .vop_reclaim = coda_reclaim,
168 .vop_bmap = coda_bmap,
169 .vop_strategy = coda_strategy,
170 .vop_print = (void *)coda_vop_error,
171 .vop_pathconf = (void *)coda_vop_error,
172 .vop_advlock = (void *)coda_vop_nop,
173 .vop_poll = vop_stdpoll,
174 .vop_getpages = coda_fbsd_getpages,
175 .vop_putpages = coda_fbsd_putpages
178 /* A generic panic: we were called with something we didn't define yet */
180 coda_vop_error(struct vop_generic_args *ap)
182 struct syslink_desc *desc = ap->a_desc;
184 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
187 panic("coda_vop_error");
192 /* A generic do-nothing. For lease_check, advlock */
194 coda_vop_nop(struct vop_generic_args *ap)
196 struct syslink_desc *desc = ap->a_desc;
199 myprintf(("Vnode operation %s called, but unsupported\n",
206 coda_vnodeopstats_init(void)
210 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
211 coda_vnodeopstats[i].opcode = i;
212 coda_vnodeopstats[i].entries = 0;
213 coda_vnodeopstats[i].sat_intrn = 0;
214 coda_vnodeopstats[i].unsat_intrn = 0;
215 coda_vnodeopstats[i].gen_intrn = 0;
221 * coda_open calls Venus to return the device, inode pair of the cache
222 * file holding the data. Using iget, coda_open finds the vnode of the
223 * cache file, and then opens it.
226 coda_open(struct vop_open_args *ap)
229 * NetBSD can pass the O_EXCL flag in mode, even though the check
230 * has already happened. Venus defensively assumes that if open
231 * is passed the EXCL, it must be a bug. We strip the flag here.
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 = curthread;
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);
256 MARK_INT_SAT(CODA_OPEN_STATS);
261 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
265 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
266 (u_long)dev2udev(dev), (u_long)inode,
270 /* Translate the <device, inode> pair for the cache file into
272 error = coda_grab_vnode(dev, inode, &vp);
276 /* We get the vnode back locked. Needs unlocked */
278 /* Keep a reference until the close comes in. */
281 /* Save the vnode pointer for the cache file. */
282 if (cp->c_ovp == NULL) {
286 panic("coda_open: cp->c_ovp != ITOV(ip)");
290 /* Flush the attribute cached if writing the file. */
293 cp->c_flags &= ~C_VATTR;
296 /* Save the <device, inode> pair for the cache file to speed
297 up subsequent page_read's. */
301 /* Open the cache file. */
302 error = VOP_OPEN(vp, flag, cred, NULL);
304 printf("coda_open: VOP_OPEN on container failed %d\n", error);
307 /* grab (above) does this when it calls newvnode unless it's in the cache*/
308 if (vp->v_type == VREG) {
309 if (vp->v_object == NULL) {
311 printf("coda_open: cache file vp %p has no VM object!\n", vp);
322 * Close the cache file used for I/O and notify Venus.
325 coda_close(struct vop_close_args *ap)
328 struct vnode *vp = ap->a_vp;
329 struct cnode *cp = VTOC(vp);
330 int flag = ap->a_fflag;
331 struct thread *td = curthread;
335 MARK_ENTRY(CODA_CLOSE_STATS);
337 /* Check for close of control file. */
339 MARK_INT_SAT(CODA_CLOSE_STATS);
344 if (IS_UNMOUNTING(cp)) {
347 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
348 vp->v_usecount, cp->c_ovp, vp, cp);
353 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
358 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
364 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
368 if (--cp->c_ocount == 0)
371 if (flag & FWRITE) /* file was opened for write */
374 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
377 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
384 coda_read(struct vop_read_args *ap)
387 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
388 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
392 coda_write(struct vop_write_args *ap)
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(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
401 struct ucred *cred, struct thread *td)
404 /* NOTE: container file operation!!! */
406 struct cnode *cp = VTOC(vp);
407 struct vnode *cfvp = cp->c_ovp;
408 int igot_internally = 0;
409 int opened_internally = 0;
412 MARK_ENTRY(CODA_RDWR_STATS);
414 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
415 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
416 (long long)uiop->uio_offset, uiop->uio_segflg)); )
418 /* Check for rdwr of control object. */
420 MARK_INT_FAIL(CODA_RDWR_STATS);
425 * If file is not already open this must be a page
426 * {read,write} request. Iget the cache file's inode
427 * pointer if we still have its <device, inode> pair.
428 * Otherwise, we must do an internal open to derive the
433 * If we're dumping core, do the internal open. Otherwise
434 * venus won't have the correct size of the core when
435 * it's completely written.
437 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
439 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
441 MARK_INT_FAIL(CODA_RDWR_STATS);
445 * We get the vnode back locked in both Mach and
446 * NetBSD. Needs unlocked
451 opened_internally = 1;
452 MARK_INT_GEN(CODA_OPEN_STATS);
453 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, NULL);
454 printf("coda_rdwr: Internally Opening %p\n", vp);
456 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
459 if (vp->v_type == VREG) {
460 if (vp->v_object == NULL) {
462 printf("coda_rdwr: vnode %p has no VM object!\n", vp);
467 MARK_INT_FAIL(CODA_RDWR_STATS);
474 /* Have UFS handle the call. */
475 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
476 cp->c_fid.Volume, cp->c_fid.Vnode,
477 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
480 if (rw == UIO_READ) {
481 error = VOP_READ(cfvp, uiop, ioflag, cred);
483 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
484 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
488 if (VOP_GETATTR(cfvp, &attr) == 0) {
489 vnode_pager_setsize(vp, attr.va_size);
495 MARK_INT_FAIL(CODA_RDWR_STATS);
497 MARK_INT_SAT(CODA_RDWR_STATS);
499 /* Do an internal close if necessary. */
500 if (opened_internally) {
501 MARK_INT_GEN(CODA_CLOSE_STATS);
502 VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE));
505 /* Invalidate cached attributes if writing. */
507 cp->c_flags &= ~C_VATTR;
512 coda_ioctl(struct vop_ioctl_args *ap)
515 struct vnode *vp = ap->a_vp;
516 int com = ap->a_command;
517 caddr_t data = ap->a_data;
518 int flag = ap->a_fflag;
519 struct ucred *cred = ap->a_cred;
520 struct thread *td = curthread;
524 struct nlookupdata nd;
525 struct PioctlData *iap = (struct PioctlData *)data;
527 MARK_ENTRY(CODA_IOCTL_STATS);
529 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
531 /* Don't check for operation on a dying object, for ctlvp it
534 /* Must be control object to succeed. */
535 if (!IS_CTL_VP(vp)) {
536 MARK_INT_FAIL(CODA_IOCTL_STATS);
537 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
540 /* Look up the pathname. */
542 /* Should we use the name cache here? It would get it from
543 lookupname sooner or later anyway, right? */
546 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
547 (iap->follow ? NLC_FOLLOW : 0));
549 error = nlookup(&nd);
551 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
555 MARK_INT_FAIL(CODA_IOCTL_STATS);
556 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
562 * Make sure this is a coda style cnode, but it may be a
565 if (tvp->v_tag != VT_CODA) {
567 MARK_INT_FAIL(CODA_IOCTL_STATS);
568 CODADEBUG(CODA_IOCTL,
569 myprintf(("coda_ioctl error: %s not a coda object\n",
574 if (iap->vi.in_size > VC_MAXDATASIZE) {
578 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
581 MARK_INT_FAIL(CODA_IOCTL_STATS);
583 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
590 * To reduce the cost of a user-level venus;we cache attributes in
591 * the kernel. Each cnode has storage allocated for an attribute. If
592 * c_vattr is valid, return a reference to it. Otherwise, get the
593 * attributes from venus and store them in the cnode. There is some
594 * question if this method is a security leak. But I think that in
595 * order to make this call, the user must have done a lookup and
596 * opened the file, and therefore should already have access.
599 coda_getattr(struct vop_getattr_args *ap)
602 struct vnode *vp = ap->a_vp;
603 struct cnode *cp = VTOC(vp);
604 struct vattr *vap = ap->a_vap;
605 struct thread *td = curthread;
609 MARK_ENTRY(CODA_GETATTR_STATS);
611 if (IS_UNMOUNTING(cp))
614 /* Check for getattr of control object. */
616 MARK_INT_FAIL(CODA_GETATTR_STATS);
620 /* Check to see if the attributes have already been cached */
621 if (VALID_VATTR(cp)) {
622 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
625 cp->c_fid.Unique));});
626 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
627 print_vattr(&cp->c_vattr); );
630 MARK_INT_SAT(CODA_GETATTR_STATS);
634 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
637 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
643 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
646 { int size = vap->va_size;
647 struct vnode *convp = cp->c_ovp;
648 if (convp != (struct vnode *)0) {
649 vnode_pager_setsize(convp, size);
652 /* If not open for write, store attributes in cnode */
653 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
655 cp->c_flags |= C_VATTR;
663 coda_setattr(struct vop_setattr_args *ap)
666 struct vnode *vp = ap->a_vp;
667 struct cnode *cp = VTOC(vp);
668 struct vattr *vap = ap->a_vap;
669 struct ucred *cred = ap->a_cred;
670 struct thread *td = curthread;
674 MARK_ENTRY(CODA_SETATTR_STATS);
676 /* Check for setattr of control object. */
678 MARK_INT_FAIL(CODA_SETATTR_STATS);
682 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
685 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
688 cp->c_flags &= ~C_VATTR;
690 { int size = vap->va_size;
691 struct vnode *convp = cp->c_ovp;
692 if (size != VNOVAL && convp != (struct vnode *)0) {
693 vnode_pager_setsize(convp, size);
696 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
701 coda_access(struct vop_access_args *ap)
704 struct vnode *vp = ap->a_vp;
705 struct cnode *cp = VTOC(vp);
706 int mode = ap->a_mode;
707 struct ucred *cred = ap->a_cred;
708 struct thread *td = curthread;
712 MARK_ENTRY(CODA_ACCESS_STATS);
714 /* Check for access of control object. Only read access is
717 /* bogus hack - all will be marked as successes */
718 MARK_INT_SAT(CODA_ACCESS_STATS);
719 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
724 * if the file is a directory, and we are checking exec (eg lookup)
725 * access, and the file is in the namecache, then the user must have
726 * lookup access to it.
728 if (coda_access_cache) {
729 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
730 if (coda_nc_lookup(cp, ".", 1, cred)) {
731 MARK_INT_SAT(CODA_ACCESS_STATS);
732 return(0); /* it was in the cache */
737 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
743 coda_readlink(struct vop_readlink_args *ap)
746 struct vnode *vp = ap->a_vp;
747 struct cnode *cp = VTOC(vp);
748 struct uio *uiop = ap->a_uio;
749 struct ucred *cred = ap->a_cred;
750 struct thread *td = ap->a_uio->uio_td;
756 MARK_ENTRY(CODA_READLINK_STATS);
758 /* Check for readlink of control object. */
760 MARK_INT_FAIL(CODA_READLINK_STATS);
764 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
765 uiop->uio_rw = UIO_READ;
766 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
768 MARK_INT_FAIL(CODA_READLINK_STATS);
770 MARK_INT_SAT(CODA_READLINK_STATS);
774 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
777 uiop->uio_rw = UIO_READ;
778 error = uiomove(str, len, uiop);
780 if (coda_symlink_cache) {
783 cp->c_flags |= C_SYMLINK;
788 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
793 coda_fsync(struct vop_fsync_args *ap)
796 struct vnode *vp = ap->a_vp;
797 struct cnode *cp = VTOC(vp);
798 struct thread *td = curthread;
800 struct vnode *convp = cp->c_ovp;
803 MARK_ENTRY(CODA_FSYNC_STATS);
805 /* Check for fsync on an unmounting object */
806 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
807 * after an unmount has been initiated. This is a Bad Thing,
808 * which we have to avoid. Not a legitimate failure for stats.
810 if (IS_UNMOUNTING(cp)) {
814 /* Check for fsync of control object. */
816 MARK_INT_SAT(CODA_FSYNC_STATS);
821 VOP_FSYNC(convp, MNT_WAIT);
824 * We see fsyncs with usecount == 1 then usecount == 0.
825 * For now we ignore them.
828 if (!vp->v_usecount) {
829 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
830 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
835 * We can expect fsync on any vnode at all if venus is pruging it.
836 * Venus can't very well answer the fsync request, now can it?
837 * Hopefully, it won't have to, because hopefully, venus preserves
838 * the (possibly untrue) invariant that it never purges an open
841 if (cp->c_flags & C_PURGING) {
847 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
849 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
854 coda_inactive(struct vop_inactive_args *ap)
856 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
857 have a proc pointer. Oops. */
859 struct vnode *vp = ap->a_vp;
860 struct cnode *cp = VTOC(vp);
861 struct ucred *cred __attribute__((unused)) = NULL;
862 /*struct thread *td = curthread;*/
866 /* We don't need to send inactive to venus - DCS */
867 MARK_ENTRY(CODA_INACTIVE_STATS);
870 MARK_INT_SAT(CODA_INACTIVE_STATS);
874 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
875 cp->c_fid.Volume, cp->c_fid.Vnode,
876 cp->c_fid.Unique, vp->v_mount));)
878 /* If an array has been allocated to hold the symlink, deallocate it */
879 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
880 if (cp->c_symlink == NULL)
881 panic("coda_inactive: null symlink pointer in cnode");
883 CODA_FREE(cp->c_symlink, cp->c_symlen);
884 cp->c_flags &= ~C_SYMLINK;
888 /* Remove it from the table so it can't be found. */
890 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
891 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
892 panic("badness in coda_inactive\n");
895 if (IS_UNMOUNTING(cp)) {
897 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
898 if (cp->c_ovp != NULL)
899 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
900 vp->v_usecount, vp, cp);
903 #ifdef OLD_DIAGNOSTIC
904 if (CTOV(cp)->v_usecount) {
905 panic("coda_inactive: nonzero reference count");
907 if (cp->c_ovp != NULL) {
908 panic("coda_inactive: cp->ovp != NULL");
914 MARK_INT_SAT(CODA_INACTIVE_STATS);
919 * Remote file system operations having to do with directory manipulation.
923 * It appears that in NetBSD, lookup is supposed to return the vnode locked
926 coda_lookup(struct vop_old_lookup_args *ap)
929 struct vnode *dvp = ap->a_dvp;
930 struct cnode *dcp = VTOC(dvp);
931 struct vnode **vpp = ap->a_vpp;
933 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
934 * of the string to xlate, and that we must try to get at least
935 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
938 struct componentname *cnp = ap->a_cnp;
939 struct ucred *cred = cnp->cn_cred;
940 struct thread *td = cnp->cn_td;
943 const char *nm = cnp->cn_nameptr;
944 int len = cnp->cn_namelen;
949 MARK_ENTRY(CODA_LOOKUP_STATS);
951 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
952 nm, dcp->c_fid.Volume,
953 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
955 /* Check for lookup of control object. */
956 if (IS_CTL_NAME(dvp, nm, len)) {
959 MARK_INT_SAT(CODA_LOOKUP_STATS);
963 if (len+1 > CODA_MAXNAMLEN) {
964 MARK_INT_FAIL(CODA_LOOKUP_STATS);
965 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
966 dcp->c_fid.Volume, dcp->c_fid.Vnode,
967 dcp->c_fid.Unique, nm)););
968 *vpp = (struct vnode *)0;
972 /* First try to look the file up in the cfs name cache */
973 /* lock the parent vnode? */
974 cp = coda_nc_lookup(dcp, nm, len, cred);
978 CODADEBUG(CODA_LOOKUP,
979 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
982 /* The name wasn't cached, so we need to contact Venus */
983 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
986 MARK_INT_FAIL(CODA_LOOKUP_STATS);
987 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
988 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
989 *vpp = (struct vnode *)0;
991 MARK_INT_SAT(CODA_LOOKUP_STATS);
992 CODADEBUG(CODA_LOOKUP,
993 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
994 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
997 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1000 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1001 /* And don't enter a new vnode for an invalid one! */
1002 if (!(vtype & CODA_NOCACHE))
1003 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1009 * If we are creating, and this was the last name to be looked up,
1010 * and the error was ENOENT, then there really shouldn't be an
1011 * error and we can make the leaf NULL and return success. Since
1012 * this is supposed to work under Mach as well as NetBSD, we're
1013 * leaving this fn wrapped. We also must tell lookup/namei that
1014 * we need to save the last component of the name. (Create will
1015 * have to free the name buffer later...lucky us...)
1017 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1020 error = EJUSTRETURN;
1025 * If the lookup went well, we need to (potentially?) unlock the
1026 * parent, and lock the child. We are only responsible for
1027 * checking to see if the parent is supposed to be unlocked before
1028 * we return. We must always lock the child (provided there is
1029 * one, and (the parent isn't locked or it isn't the same as the
1030 * parent.) Simple, huh? We can never leave the parent locked unless
1033 if (!error || (error == EJUSTRETURN)) {
1034 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
1037 * The parent is unlocked. As long as there is a child,
1038 * lock it without bothering to check anything else.
1041 if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1042 printf("coda_lookup: ");
1043 panic("unlocked parent but couldn't lock child");
1047 /* The parent is locked, and may be the same as the child */
1048 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1049 /* Different, go ahead and lock it. */
1050 if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1051 printf("coda_lookup: ");
1052 panic("unlocked parent but couldn't lock child");
1057 /* If the lookup failed, we need to ensure that the leaf is NULL */
1058 /* Don't change any locking? */
1066 coda_create(struct vop_old_create_args *ap)
1069 struct vnode *dvp = ap->a_dvp;
1070 struct cnode *dcp = VTOC(dvp);
1071 struct vattr *va = ap->a_vap;
1073 int mode = ap->a_vap->va_mode;
1074 struct vnode **vpp = ap->a_vpp;
1075 struct componentname *cnp = ap->a_cnp;
1076 struct ucred *cred = cnp->cn_cred;
1077 struct thread *td = cnp->cn_td;
1081 const char *nm = cnp->cn_nameptr;
1082 int len = cnp->cn_namelen;
1086 MARK_ENTRY(CODA_CREATE_STATS);
1088 /* All creates are exclusive XXX */
1089 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1091 /* Check for create of control object. */
1092 if (IS_CTL_NAME(dvp, nm, len)) {
1093 *vpp = (struct vnode *)0;
1094 MARK_INT_FAIL(CODA_CREATE_STATS);
1098 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1102 /* If this is an exclusive create, panic if the file already exists. */
1103 /* Venus should have detected the file and reported EEXIST. */
1105 if ((exclusive == 1) &&
1106 (coda_find(&VFid) != NULL))
1107 panic("cnode existed for newly created file!");
1109 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1112 /* Update va to reflect the new attributes. */
1115 /* Update the attribute cache and mark it as valid */
1116 if (coda_attr_cache) {
1117 VTOC(*vpp)->c_vattr = attr;
1118 VTOC(*vpp)->c_flags |= C_VATTR;
1121 /* Invalidate the parent's attr cache, the modification time has changed */
1122 VTOC(dvp)->c_flags &= ~C_VATTR;
1124 /* enter the new vnode in the Name Cache */
1125 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1127 CODADEBUG(CODA_CREATE,
1128 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1129 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1131 *vpp = (struct vnode *)0;
1132 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1136 if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
1137 printf("coda_create: ");
1138 panic("unlocked parent but couldn't lock child");
1145 coda_remove(struct vop_old_remove_args *ap)
1148 struct vnode *dvp = ap->a_dvp;
1149 struct cnode *cp = VTOC(dvp);
1150 struct componentname *cnp = ap->a_cnp;
1151 struct ucred *cred = cnp->cn_cred;
1152 struct thread *td = cnp->cn_td;
1155 const char *nm = cnp->cn_nameptr;
1156 int len = cnp->cn_namelen;
1159 MARK_ENTRY(CODA_REMOVE_STATS);
1161 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1162 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1163 cp->c_fid.Unique)););
1165 /* Remove the file's entry from the CODA Name Cache */
1166 /* We're being conservative here, it might be that this person
1167 * doesn't really have sufficient access to delete the file
1168 * but we feel zapping the entry won't really hurt anyone -- dcs
1170 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1171 * exist, and one is removed, the link count on the other will be
1172 * off by 1. We could either invalidate the attrs if cached, or
1173 * fix them. I'll try to fix them. DCS 11/8/94
1175 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1177 if (VALID_VATTR(tp)) { /* If attrs are cached */
1178 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1179 tp->c_vattr.va_nlink--;
1183 coda_nc_zapfile(VTOC(dvp), nm, len);
1184 /* No need to flush it if it doesn't exist! */
1186 /* Invalidate the parent's attr cache, the modification time has changed */
1187 VTOC(dvp)->c_flags &= ~C_VATTR;
1189 /* Check for remove of control object. */
1190 if (IS_CTL_NAME(dvp, nm, len)) {
1191 MARK_INT_FAIL(CODA_REMOVE_STATS);
1195 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1197 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1203 coda_link(struct vop_old_link_args *ap)
1206 struct vnode *vp = ap->a_vp;
1207 struct cnode *cp = VTOC(vp);
1208 struct vnode *tdvp = ap->a_tdvp;
1209 struct cnode *tdcp = VTOC(tdvp);
1210 struct componentname *cnp = ap->a_cnp;
1211 struct ucred *cred = cnp->cn_cred;
1212 struct thread *td = cnp->cn_td;
1215 const char *nm = cnp->cn_nameptr;
1216 int len = cnp->cn_namelen;
1218 MARK_ENTRY(CODA_LINK_STATS);
1220 if (codadebug & CODADBGMSK(CODA_LINK)) {
1222 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1223 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1224 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1225 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1228 if (codadebug & CODADBGMSK(CODA_LINK)) {
1229 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1230 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1231 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1232 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1236 /* Check for link to/from control object. */
1237 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1238 MARK_INT_FAIL(CODA_LINK_STATS);
1242 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1244 /* Invalidate the parent's attr cache, the modification time has changed */
1245 VTOC(tdvp)->c_flags &= ~C_VATTR;
1246 VTOC(vp)->c_flags &= ~C_VATTR;
1248 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1254 coda_rename(struct vop_old_rename_args *ap)
1257 struct vnode *odvp = ap->a_fdvp;
1258 struct cnode *odcp = VTOC(odvp);
1259 struct componentname *fcnp = ap->a_fcnp;
1260 struct vnode *ndvp = ap->a_tdvp;
1261 struct cnode *ndcp = VTOC(ndvp);
1262 struct componentname *tcnp = ap->a_tcnp;
1263 struct ucred *cred = fcnp->cn_cred;
1264 struct thread *td = fcnp->cn_td;
1267 const char *fnm = fcnp->cn_nameptr;
1268 int flen = fcnp->cn_namelen;
1269 const char *tnm = tcnp->cn_nameptr;
1270 int tlen = tcnp->cn_namelen;
1272 MARK_ENTRY(CODA_RENAME_STATS);
1274 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1275 This could be Bad. XXX */
1276 #ifdef OLD_DIAGNOSTIC
1277 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1279 panic("coda_rename: component names don't agree");
1283 /* Check for rename involving control object. */
1284 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1285 MARK_INT_FAIL(CODA_RENAME_STATS);
1289 /* Problem with moving directories -- need to flush entry for .. */
1291 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1293 struct vnode *ovp = CTOV(ovcp);
1295 (ovp->v_type == VDIR)) /* If it's a directory */
1296 coda_nc_zapfile(VTOC(ovp),"..", 2);
1300 /* Remove the entries for both source and target files */
1301 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1302 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1304 /* Invalidate the parent's attr cache, the modification time has changed */
1305 VTOC(odvp)->c_flags &= ~C_VATTR;
1306 VTOC(ndvp)->c_flags &= ~C_VATTR;
1308 if (flen+1 > CODA_MAXNAMLEN) {
1309 MARK_INT_FAIL(CODA_RENAME_STATS);
1314 if (tlen+1 > CODA_MAXNAMLEN) {
1315 MARK_INT_FAIL(CODA_RENAME_STATS);
1320 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1323 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1325 /* It seems to be incumbent on us to drop locks on all four vnodes */
1326 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1332 if (ap->a_tvp == ndvp) {
1344 coda_mkdir(struct vop_old_mkdir_args *ap)
1347 struct vnode *dvp = ap->a_dvp;
1348 struct cnode *dcp = VTOC(dvp);
1349 struct componentname *cnp = ap->a_cnp;
1350 struct vattr *va = ap->a_vap;
1351 struct vnode **vpp = ap->a_vpp;
1352 struct ucred *cred = cnp->cn_cred;
1353 struct thread *td = cnp->cn_td;
1356 const char *nm = cnp->cn_nameptr;
1357 int len = cnp->cn_namelen;
1362 MARK_ENTRY(CODA_MKDIR_STATS);
1364 /* Check for mkdir of target object. */
1365 if (IS_CTL_NAME(dvp, nm, len)) {
1366 *vpp = (struct vnode *)0;
1367 MARK_INT_FAIL(CODA_MKDIR_STATS);
1371 if (len+1 > CODA_MAXNAMLEN) {
1372 *vpp = (struct vnode *)0;
1373 MARK_INT_FAIL(CODA_MKDIR_STATS);
1377 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1380 if (coda_find(&VFid) != NULL)
1381 panic("cnode existed for newly created directory!");
1384 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1387 /* enter the new vnode in the Name Cache */
1388 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1390 /* as a side effect, enter "." and ".." for the directory */
1391 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1392 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1394 if (coda_attr_cache) {
1395 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1396 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1399 /* Invalidate the parent's attr cache, the modification time has changed */
1400 VTOC(dvp)->c_flags &= ~C_VATTR;
1402 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1403 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1405 *vpp = (struct vnode *)0;
1406 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1413 coda_rmdir(struct vop_old_rmdir_args *ap)
1416 struct vnode *dvp = ap->a_dvp;
1417 struct cnode *dcp = VTOC(dvp);
1418 struct componentname *cnp = ap->a_cnp;
1419 struct ucred *cred = cnp->cn_cred;
1420 struct thread *td = cnp->cn_td;
1423 const char *nm = cnp->cn_nameptr;
1424 int len = cnp->cn_namelen;
1427 MARK_ENTRY(CODA_RMDIR_STATS);
1429 /* Check for rmdir of control object. */
1430 if (IS_CTL_NAME(dvp, nm, len)) {
1431 MARK_INT_FAIL(CODA_RMDIR_STATS);
1435 /* We're being conservative here, it might be that this person
1436 * doesn't really have sufficient access to delete the file
1437 * but we feel zapping the entry won't really hurt anyone -- dcs
1440 * As a side effect of the rmdir, remove any entries for children of
1441 * the directory, especially "." and "..".
1443 cp = coda_nc_lookup(dcp, nm, len, cred);
1444 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1446 /* Remove the file's entry from the CODA Name Cache */
1447 coda_nc_zapfile(dcp, nm, len);
1449 /* Invalidate the parent's attr cache, the modification time has changed */
1450 dcp->c_flags &= ~C_VATTR;
1452 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1454 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1460 coda_symlink(struct vop_old_symlink_args *ap)
1463 struct vnode *tdvp = ap->a_dvp;
1464 struct cnode *tdcp = VTOC(tdvp);
1465 struct componentname *cnp = ap->a_cnp;
1466 struct vattr *tva = ap->a_vap;
1467 char *path = ap->a_target;
1468 struct ucred *cred = cnp->cn_cred;
1469 struct thread *td = cnp->cn_td;
1470 struct vnode **vpp = ap->a_vpp;
1474 * XXX I'm assuming the following things about coda_symlink's
1476 * t(foo) is the new name/parent/etc being created.
1477 * lname is the contents of the new symlink.
1479 char *nm = cnp->cn_nameptr;
1480 int len = cnp->cn_namelen;
1481 int plen = strlen(path);
1484 * Here's the strategy for the moment: perform the symlink, then
1485 * do a lookup to grab the resulting vnode. I know this requires
1486 * two communications with Venus for a new sybolic link, but
1487 * that's the way the ball bounces. I don't yet want to change
1488 * the way the Mach symlink works. When Mach support is
1489 * deprecated, we should change symlink so that the common case
1490 * returns the resultant vnode in a vpp argument.
1493 MARK_ENTRY(CODA_SYMLINK_STATS);
1495 /* Check for symlink of control object. */
1496 if (IS_CTL_NAME(tdvp, nm, len)) {
1497 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1501 if (plen+1 > CODA_MAXPATHLEN) {
1502 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1506 if (len+1 > CODA_MAXNAMLEN) {
1507 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1512 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1514 /* Invalidate the parent's attr cache, the modification time has changed */
1515 tdcp->c_flags &= ~C_VATTR;
1518 error = VOP_OLD_LOOKUP(tdvp, vpp, cnp);
1521 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1526 * Read directory entries.
1529 coda_readdir(struct vop_readdir_args *ap)
1532 struct vnode *vp = ap->a_vp;
1533 struct cnode *cp = VTOC(vp);
1534 struct uio *uiop = ap->a_uio;
1535 struct ucred *cred = ap->a_cred;
1536 int *eofflag = ap->a_eofflag;
1537 u_long **cookies = ap->a_cookies;
1538 int *ncookies = ap->a_ncookies;
1543 MARK_ENTRY(CODA_READDIR_STATS);
1545 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1546 (void *)uiop->uio_iov->iov_base,
1548 (long long)uiop->uio_offset,
1549 uiop->uio_segflg)); )
1551 /* Check for readdir of control object. */
1552 if (IS_CTL_VP(vp)) {
1553 MARK_INT_FAIL(CODA_READDIR_STATS);
1558 /* If directory is not already open do an "internal open" on it. */
1559 int opened_internally = 0;
1560 if (cp->c_ovp == NULL) {
1561 opened_internally = 1;
1562 MARK_INT_GEN(CODA_OPEN_STATS);
1563 error = VOP_OPEN(vp, FREAD, cred, NULL);
1564 printf("coda_readdir: Internally Opening %p\n", vp);
1566 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1569 if (vp->v_type == VREG) {
1570 if (vp->v_object == NULL) {
1572 printf("coda_readdir: vnode %p has no VM object!\n", vp);
1576 if (error) return(error);
1579 /* Have UFS handle the call. */
1580 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)); )
1581 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1585 MARK_INT_FAIL(CODA_READDIR_STATS);
1587 MARK_INT_SAT(CODA_READDIR_STATS);
1589 /* Do an "internal close" if necessary. */
1590 if (opened_internally) {
1591 MARK_INT_GEN(CODA_CLOSE_STATS);
1592 VOP_CLOSE(vp, FREAD);
1600 * Convert from file system blocks to device blocks
1603 coda_bmap(struct vop_bmap_args *ap)
1605 /* XXX on the global proc */
1609 cp = VTOC(ap->a_vp);
1613 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1614 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1615 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1620 printf("coda_bmap: no container\n");
1627 * I don't think the following two things are used anywhere, so I've
1628 * commented them out
1630 * struct buf *async_bufhead;
1631 * int async_daemon_count;
1634 coda_strategy(struct vop_strategy_args *ap __unused)
1636 printf("coda_strategy: called ???\n");
1641 coda_reclaim(struct vop_reclaim_args *ap)
1644 struct vnode *vp = ap->a_vp;
1645 struct cnode *cp = VTOC(vp);
1650 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1654 if (IS_UNMOUNTING(cp)) {
1656 if (VTOC(vp)->c_ovp) {
1657 if (IS_UNMOUNTING(cp))
1658 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1662 #ifdef OLD_DIAGNOSTIC
1663 if (vp->v_usecount != 0)
1664 print("coda_reclaim: pushing active %p\n", vp);
1665 if (VTOC(vp)->c_ovp) {
1666 panic("coda_reclaim: c_ovp not void");
1670 coda_free(VTOC(vp));
1675 /* How one looks up a vnode given a device/inode pair: */
1677 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1679 /* This is like VFS_VGET() or igetinode()! */
1683 if (!(mp = devtomp(dev))) {
1684 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1685 (u_long)dev2udev(dev)));
1689 /* XXX - ensure that nonzero-return means failure */
1690 error = VFS_VGET(mp,ino,vpp);
1692 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1693 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1700 print_vattr(struct vattr *attr)
1704 switch (attr->va_type) {
1738 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1739 typestr, (int)attr->va_mode, (int)attr->va_uid,
1740 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1742 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1743 (int)attr->va_fileid, (int)attr->va_nlink,
1745 (int)attr->va_blocksize,(int)attr->va_bytes));
1746 myprintf((" gen %ld flags %ld vaflags %d\n",
1747 attr->va_gen, attr->va_flags, attr->va_vaflags));
1748 myprintf((" atime sec %d nsec %d\n",
1749 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1750 myprintf((" mtime sec %d nsec %d\n",
1751 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1752 myprintf((" ctime sec %d nsec %d\n",
1753 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1756 /* How to print a ucred */
1758 print_cred(struct ucred *cred)
1763 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1765 for (i=0; i < cred->cr_ngroups; i++)
1766 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1772 * Return a vnode for the given fid.
1773 * If no cnode exists for this fid create one and put it
1774 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1775 * this fid is already in the table return it (ref count is
1776 * incremented by coda_find. The cnode will be flushed from the
1777 * table when coda_inactive calls coda_unsave.
1780 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1785 if ((cp = coda_find(fid)) == NULL) {
1791 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
1793 panic("coda: getnewvnode returned error %d\n", err);