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.41 2006/07/19 06:08:09 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_lock(struct vop_lock_args *ap);
141 static int coda_unlock(struct vop_unlock_args *ap);
142 static int coda_bmap(struct vop_bmap_args *ap);
143 static int coda_strategy(struct vop_strategy_args *ap);
144 static int coda_islocked(struct vop_islocked_args *ap);
146 struct vop_ops coda_vnode_ops = {
147 .vop_default = (void *)coda_vop_error,
148 .vop_old_lookup = coda_lookup,
149 .vop_old_create = coda_create,
150 .vop_old_mknod = (void *)coda_vop_error,
151 .vop_open = coda_open,
152 .vop_close = coda_close,
153 .vop_access = coda_access,
154 .vop_getattr = coda_getattr,
155 .vop_setattr = coda_setattr,
156 .vop_read = coda_read,
157 .vop_write = coda_write,
158 .vop_ioctl = coda_ioctl,
159 .vop_mmap = (void *)coda_vop_error,
160 .vop_fsync = coda_fsync,
161 .vop_old_remove = coda_remove,
162 .vop_old_link = coda_link,
163 .vop_old_rename = coda_rename,
164 .vop_old_mkdir = coda_mkdir,
165 .vop_old_rmdir = coda_rmdir,
166 .vop_old_symlink = coda_symlink,
167 .vop_readdir = coda_readdir,
168 .vop_readlink = coda_readlink,
169 .vop_inactive = coda_inactive,
170 .vop_reclaim = coda_reclaim,
171 .vop_lock = coda_lock,
172 .vop_unlock = coda_unlock,
173 .vop_bmap = coda_bmap,
174 .vop_strategy = coda_strategy,
175 .vop_print = (void *)coda_vop_error,
176 .vop_islocked = coda_islocked,
177 .vop_pathconf = (void *)coda_vop_error,
178 .vop_advlock = (void *)coda_vop_nop,
179 .vop_poll = vop_stdpoll,
180 .vop_getpages = coda_fbsd_getpages,
181 .vop_putpages = coda_fbsd_putpages
184 /* A generic panic: we were called with something we didn't define yet */
186 coda_vop_error(struct vop_generic_args *ap)
188 struct syslink_desc *desc = ap->a_desc;
190 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
193 panic("coda_vop_error");
198 /* A generic do-nothing. For lease_check, advlock */
200 coda_vop_nop(struct vop_generic_args *ap)
202 struct syslink_desc *desc = ap->a_desc;
205 myprintf(("Vnode operation %s called, but unsupported\n",
212 coda_vnodeopstats_init(void)
216 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
217 coda_vnodeopstats[i].opcode = i;
218 coda_vnodeopstats[i].entries = 0;
219 coda_vnodeopstats[i].sat_intrn = 0;
220 coda_vnodeopstats[i].unsat_intrn = 0;
221 coda_vnodeopstats[i].gen_intrn = 0;
227 * coda_open calls Venus to return the device, inode pair of the cache
228 * file holding the data. Using iget, coda_open finds the vnode of the
229 * cache file, and then opens it.
232 coda_open(struct vop_open_args *ap)
235 * NetBSD can pass the O_EXCL flag in mode, even though the check
236 * has already happened. Venus defensively assumes that if open
237 * is passed the EXCL, it must be a bug. We strip the flag here.
240 struct vnode **vpp = &(ap->a_vp);
241 struct cnode *cp = VTOC(*vpp);
242 int flag = ap->a_mode & (~O_EXCL);
243 struct ucred *cred = ap->a_cred;
244 struct thread *td = curthread;
251 MARK_ENTRY(CODA_OPEN_STATS);
253 /* Check for open of control file. */
254 if (IS_CTL_VP(*vpp)) {
256 /* if (WRITEABLE(flag)) */
257 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
258 MARK_INT_FAIL(CODA_OPEN_STATS);
262 MARK_INT_SAT(CODA_OPEN_STATS);
267 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
271 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
272 (u_long)dev2udev(dev), (u_long)inode,
276 /* Translate the <device, inode> pair for the cache file into
278 error = coda_grab_vnode(dev, inode, &vp);
282 /* We get the vnode back locked. Needs unlocked */
284 /* Keep a reference until the close comes in. */
287 /* Save the vnode pointer for the cache file. */
288 if (cp->c_ovp == NULL) {
292 panic("coda_open: cp->c_ovp != ITOV(ip)");
296 /* Flush the attribute cached if writing the file. */
299 cp->c_flags &= ~C_VATTR;
302 /* Save the <device, inode> pair for the cache file to speed
303 up subsequent page_read's. */
307 /* Open the cache file. */
308 error = VOP_OPEN(vp, flag, cred, NULL);
310 printf("coda_open: VOP_OPEN on container failed %d\n", error);
313 /* grab (above) does this when it calls newvnode unless it's in the cache*/
314 if (vp->v_type == VREG) {
315 if (vp->v_object == NULL) {
317 printf("coda_open: cache file vp %p has no VM object!\n", vp);
328 * Close the cache file used for I/O and notify Venus.
331 coda_close(struct vop_close_args *ap)
334 struct vnode *vp = ap->a_vp;
335 struct cnode *cp = VTOC(vp);
336 int flag = ap->a_fflag;
337 struct thread *td = curthread;
341 MARK_ENTRY(CODA_CLOSE_STATS);
343 /* Check for close of control file. */
345 MARK_INT_SAT(CODA_CLOSE_STATS);
350 if (IS_UNMOUNTING(cp)) {
353 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
354 vp->v_usecount, cp->c_ovp, vp, cp);
359 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
364 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
370 VOP_CLOSE(cp->c_ovp, flag); /* Do errors matter here? */
374 if (--cp->c_ocount == 0)
377 if (flag & FWRITE) /* file was opened for write */
380 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
383 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
390 coda_read(struct vop_read_args *ap)
393 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
394 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
398 coda_write(struct vop_write_args *ap)
401 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
402 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
406 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
407 struct ucred *cred, struct thread *td)
410 /* NOTE: container file operation!!! */
412 struct cnode *cp = VTOC(vp);
413 struct vnode *cfvp = cp->c_ovp;
414 int igot_internally = 0;
415 int opened_internally = 0;
418 MARK_ENTRY(CODA_RDWR_STATS);
420 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
421 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
422 (long long)uiop->uio_offset, uiop->uio_segflg)); )
424 /* Check for rdwr of control object. */
426 MARK_INT_FAIL(CODA_RDWR_STATS);
431 * If file is not already open this must be a page
432 * {read,write} request. Iget the cache file's inode
433 * pointer if we still have its <device, inode> pair.
434 * Otherwise, we must do an internal open to derive the
439 * If we're dumping core, do the internal open. Otherwise
440 * venus won't have the correct size of the core when
441 * it's completely written.
443 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
445 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
447 MARK_INT_FAIL(CODA_RDWR_STATS);
451 * We get the vnode back locked in both Mach and
452 * NetBSD. Needs unlocked
457 opened_internally = 1;
458 MARK_INT_GEN(CODA_OPEN_STATS);
459 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, NULL);
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 if (vp->v_object == NULL) {
468 printf("coda_rdwr: vnode %p has no VM object!\n", vp);
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) == 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 VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE));
511 /* Invalidate cached attributes if writing. */
513 cp->c_flags &= ~C_VATTR;
518 coda_ioctl(struct vop_ioctl_args *ap)
521 struct vnode *vp = ap->a_vp;
522 int com = ap->a_command;
523 caddr_t data = ap->a_data;
524 int flag = ap->a_fflag;
525 struct ucred *cred = ap->a_cred;
526 struct thread *td = curthread;
530 struct nlookupdata nd;
531 struct PioctlData *iap = (struct PioctlData *)data;
533 MARK_ENTRY(CODA_IOCTL_STATS);
535 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
537 /* Don't check for operation on a dying object, for ctlvp it
540 /* Must be control object to succeed. */
541 if (!IS_CTL_VP(vp)) {
542 MARK_INT_FAIL(CODA_IOCTL_STATS);
543 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
546 /* Look up the pathname. */
548 /* Should we use the name cache here? It would get it from
549 lookupname sooner or later anyway, right? */
552 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
553 (iap->follow ? NLC_FOLLOW : 0));
555 error = nlookup(&nd);
557 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
561 MARK_INT_FAIL(CODA_IOCTL_STATS);
562 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
568 * Make sure this is a coda style cnode, but it may be a
571 if (tvp->v_tag != VT_CODA) {
573 MARK_INT_FAIL(CODA_IOCTL_STATS);
574 CODADEBUG(CODA_IOCTL,
575 myprintf(("coda_ioctl error: %s not a coda object\n",
580 if (iap->vi.in_size > VC_MAXDATASIZE) {
584 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
587 MARK_INT_FAIL(CODA_IOCTL_STATS);
589 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
596 * To reduce the cost of a user-level venus;we cache attributes in
597 * the kernel. Each cnode has storage allocated for an attribute. If
598 * c_vattr is valid, return a reference to it. Otherwise, get the
599 * attributes from venus and store them in the cnode. There is some
600 * question if this method is a security leak. But I think that in
601 * order to make this call, the user must have done a lookup and
602 * opened the file, and therefore should already have access.
605 coda_getattr(struct vop_getattr_args *ap)
608 struct vnode *vp = ap->a_vp;
609 struct cnode *cp = VTOC(vp);
610 struct vattr *vap = ap->a_vap;
611 struct thread *td = curthread;
615 MARK_ENTRY(CODA_GETATTR_STATS);
617 if (IS_UNMOUNTING(cp))
620 /* Check for getattr of control object. */
622 MARK_INT_FAIL(CODA_GETATTR_STATS);
626 /* Check to see if the attributes have already been cached */
627 if (VALID_VATTR(cp)) {
628 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
631 cp->c_fid.Unique));});
632 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
633 print_vattr(&cp->c_vattr); );
636 MARK_INT_SAT(CODA_GETATTR_STATS);
640 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
643 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
649 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
652 { int size = vap->va_size;
653 struct vnode *convp = cp->c_ovp;
654 if (convp != (struct vnode *)0) {
655 vnode_pager_setsize(convp, size);
658 /* If not open for write, store attributes in cnode */
659 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
661 cp->c_flags |= C_VATTR;
669 coda_setattr(struct vop_setattr_args *ap)
672 struct vnode *vp = ap->a_vp;
673 struct cnode *cp = VTOC(vp);
674 struct vattr *vap = ap->a_vap;
675 struct ucred *cred = ap->a_cred;
676 struct thread *td = curthread;
680 MARK_ENTRY(CODA_SETATTR_STATS);
682 /* Check for setattr of control object. */
684 MARK_INT_FAIL(CODA_SETATTR_STATS);
688 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
691 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
694 cp->c_flags &= ~C_VATTR;
696 { int size = vap->va_size;
697 struct vnode *convp = cp->c_ovp;
698 if (size != VNOVAL && convp != (struct vnode *)0) {
699 vnode_pager_setsize(convp, size);
702 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
707 coda_access(struct vop_access_args *ap)
710 struct vnode *vp = ap->a_vp;
711 struct cnode *cp = VTOC(vp);
712 int mode = ap->a_mode;
713 struct ucred *cred = ap->a_cred;
714 struct thread *td = curthread;
718 MARK_ENTRY(CODA_ACCESS_STATS);
720 /* Check for access of control object. Only read access is
723 /* bogus hack - all will be marked as successes */
724 MARK_INT_SAT(CODA_ACCESS_STATS);
725 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
730 * if the file is a directory, and we are checking exec (eg lookup)
731 * access, and the file is in the namecache, then the user must have
732 * lookup access to it.
734 if (coda_access_cache) {
735 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
736 if (coda_nc_lookup(cp, ".", 1, cred)) {
737 MARK_INT_SAT(CODA_ACCESS_STATS);
738 return(0); /* it was in the cache */
743 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
749 coda_readlink(struct vop_readlink_args *ap)
752 struct vnode *vp = ap->a_vp;
753 struct cnode *cp = VTOC(vp);
754 struct uio *uiop = ap->a_uio;
755 struct ucred *cred = ap->a_cred;
756 struct thread *td = ap->a_uio->uio_td;
762 MARK_ENTRY(CODA_READLINK_STATS);
764 /* Check for readlink of control object. */
766 MARK_INT_FAIL(CODA_READLINK_STATS);
770 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
771 uiop->uio_rw = UIO_READ;
772 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
774 MARK_INT_FAIL(CODA_READLINK_STATS);
776 MARK_INT_SAT(CODA_READLINK_STATS);
780 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
783 uiop->uio_rw = UIO_READ;
784 error = uiomove(str, len, uiop);
786 if (coda_symlink_cache) {
789 cp->c_flags |= C_SYMLINK;
794 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
799 coda_fsync(struct vop_fsync_args *ap)
802 struct vnode *vp = ap->a_vp;
803 struct cnode *cp = VTOC(vp);
804 struct thread *td = curthread;
806 struct vnode *convp = cp->c_ovp;
809 MARK_ENTRY(CODA_FSYNC_STATS);
811 /* Check for fsync on an unmounting object */
812 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
813 * after an unmount has been initiated. This is a Bad Thing,
814 * which we have to avoid. Not a legitimate failure for stats.
816 if (IS_UNMOUNTING(cp)) {
820 /* Check for fsync of control object. */
822 MARK_INT_SAT(CODA_FSYNC_STATS);
827 VOP_FSYNC(convp, MNT_WAIT);
830 * We see fsyncs with usecount == 1 then usecount == 0.
831 * For now we ignore them.
834 if (!vp->v_usecount) {
835 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
836 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
841 * We can expect fsync on any vnode at all if venus is pruging it.
842 * Venus can't very well answer the fsync request, now can it?
843 * Hopefully, it won't have to, because hopefully, venus preserves
844 * the (possibly untrue) invariant that it never purges an open
847 if (cp->c_flags & C_PURGING) {
853 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
855 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
860 coda_inactive(struct vop_inactive_args *ap)
862 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
863 have a proc pointer. Oops. */
865 struct vnode *vp = ap->a_vp;
866 struct cnode *cp = VTOC(vp);
867 struct ucred *cred __attribute__((unused)) = NULL;
868 /*struct thread *td = curthread;*/
872 /* We don't need to send inactive to venus - DCS */
873 MARK_ENTRY(CODA_INACTIVE_STATS);
876 MARK_INT_SAT(CODA_INACTIVE_STATS);
880 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
881 cp->c_fid.Volume, cp->c_fid.Vnode,
882 cp->c_fid.Unique, vp->v_mount));)
884 /* If an array has been allocated to hold the symlink, deallocate it */
885 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
886 if (cp->c_symlink == NULL)
887 panic("coda_inactive: null symlink pointer in cnode");
889 CODA_FREE(cp->c_symlink, cp->c_symlen);
890 cp->c_flags &= ~C_SYMLINK;
894 /* Remove it from the table so it can't be found. */
896 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
897 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
898 panic("badness in coda_inactive\n");
901 if (IS_UNMOUNTING(cp)) {
903 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
904 if (cp->c_ovp != NULL)
905 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
906 vp->v_usecount, vp, cp);
909 #ifdef OLD_DIAGNOSTIC
910 if (CTOV(cp)->v_usecount) {
911 panic("coda_inactive: nonzero reference count");
913 if (cp->c_ovp != NULL) {
914 panic("coda_inactive: cp->ovp != NULL");
920 MARK_INT_SAT(CODA_INACTIVE_STATS);
925 * Remote file system operations having to do with directory manipulation.
929 * It appears that in NetBSD, lookup is supposed to return the vnode locked
932 coda_lookup(struct vop_old_lookup_args *ap)
935 struct vnode *dvp = ap->a_dvp;
936 struct cnode *dcp = VTOC(dvp);
937 struct vnode **vpp = ap->a_vpp;
939 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
940 * of the string to xlate, and that we must try to get at least
941 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
944 struct componentname *cnp = ap->a_cnp;
945 struct ucred *cred = cnp->cn_cred;
946 struct thread *td = cnp->cn_td;
949 const char *nm = cnp->cn_nameptr;
950 int len = cnp->cn_namelen;
955 MARK_ENTRY(CODA_LOOKUP_STATS);
957 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
958 nm, dcp->c_fid.Volume,
959 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
961 /* Check for lookup of control object. */
962 if (IS_CTL_NAME(dvp, nm, len)) {
965 MARK_INT_SAT(CODA_LOOKUP_STATS);
969 if (len+1 > CODA_MAXNAMLEN) {
970 MARK_INT_FAIL(CODA_LOOKUP_STATS);
971 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
972 dcp->c_fid.Volume, dcp->c_fid.Vnode,
973 dcp->c_fid.Unique, nm)););
974 *vpp = (struct vnode *)0;
978 /* First try to look the file up in the cfs name cache */
979 /* lock the parent vnode? */
980 cp = coda_nc_lookup(dcp, nm, len, cred);
984 CODADEBUG(CODA_LOOKUP,
985 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
988 /* The name wasn't cached, so we need to contact Venus */
989 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
992 MARK_INT_FAIL(CODA_LOOKUP_STATS);
993 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
994 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
995 *vpp = (struct vnode *)0;
997 MARK_INT_SAT(CODA_LOOKUP_STATS);
998 CODADEBUG(CODA_LOOKUP,
999 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1000 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1003 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1006 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1007 /* And don't enter a new vnode for an invalid one! */
1008 if (!(vtype & CODA_NOCACHE))
1009 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1015 * If we are creating, and this was the last name to be looked up,
1016 * and the error was ENOENT, then there really shouldn't be an
1017 * error and we can make the leaf NULL and return success. Since
1018 * this is supposed to work under Mach as well as NetBSD, we're
1019 * leaving this fn wrapped. We also must tell lookup/namei that
1020 * we need to save the last component of the name. (Create will
1021 * have to free the name buffer later...lucky us...)
1023 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1026 error = EJUSTRETURN;
1031 * If the lookup went well, we need to (potentially?) unlock the
1032 * parent, and lock the child. We are only responsible for
1033 * checking to see if the parent is supposed to be unlocked before
1034 * we return. We must always lock the child (provided there is
1035 * one, and (the parent isn't locked or it isn't the same as the
1036 * parent.) Simple, huh? We can never leave the parent locked unless
1039 if (!error || (error == EJUSTRETURN)) {
1040 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
1041 if ((error = VOP_UNLOCK(dvp, 0))) {
1045 * The parent is unlocked. As long as there is a child,
1046 * lock it without bothering to check anything else.
1049 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1050 printf("coda_lookup: ");
1051 panic("unlocked parent but couldn't lock child");
1055 /* The parent is locked, and may be the same as the child */
1056 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1057 /* Different, go ahead and lock it. */
1058 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1059 printf("coda_lookup: ");
1060 panic("unlocked parent but couldn't lock child");
1065 /* If the lookup failed, we need to ensure that the leaf is NULL */
1066 /* Don't change any locking? */
1074 coda_create(struct vop_old_create_args *ap)
1077 struct vnode *dvp = ap->a_dvp;
1078 struct cnode *dcp = VTOC(dvp);
1079 struct vattr *va = ap->a_vap;
1081 int mode = ap->a_vap->va_mode;
1082 struct vnode **vpp = ap->a_vpp;
1083 struct componentname *cnp = ap->a_cnp;
1084 struct ucred *cred = cnp->cn_cred;
1085 struct thread *td = cnp->cn_td;
1089 const char *nm = cnp->cn_nameptr;
1090 int len = cnp->cn_namelen;
1094 MARK_ENTRY(CODA_CREATE_STATS);
1096 /* All creates are exclusive XXX */
1097 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1099 /* Check for create of control object. */
1100 if (IS_CTL_NAME(dvp, nm, len)) {
1101 *vpp = (struct vnode *)0;
1102 MARK_INT_FAIL(CODA_CREATE_STATS);
1106 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1110 /* If this is an exclusive create, panic if the file already exists. */
1111 /* Venus should have detected the file and reported EEXIST. */
1113 if ((exclusive == 1) &&
1114 (coda_find(&VFid) != NULL))
1115 panic("cnode existed for newly created file!");
1117 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1120 /* Update va to reflect the new attributes. */
1123 /* Update the attribute cache and mark it as valid */
1124 if (coda_attr_cache) {
1125 VTOC(*vpp)->c_vattr = attr;
1126 VTOC(*vpp)->c_flags |= C_VATTR;
1129 /* Invalidate the parent's attr cache, the modification time has changed */
1130 VTOC(dvp)->c_flags &= ~C_VATTR;
1132 /* enter the new vnode in the Name Cache */
1133 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1135 CODADEBUG(CODA_CREATE,
1136 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1137 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1139 *vpp = (struct vnode *)0;
1140 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1144 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1145 printf("coda_create: ");
1146 panic("unlocked parent but couldn't lock child");
1153 coda_remove(struct vop_old_remove_args *ap)
1156 struct vnode *dvp = ap->a_dvp;
1157 struct cnode *cp = VTOC(dvp);
1158 struct componentname *cnp = ap->a_cnp;
1159 struct ucred *cred = cnp->cn_cred;
1160 struct thread *td = cnp->cn_td;
1163 const char *nm = cnp->cn_nameptr;
1164 int len = cnp->cn_namelen;
1167 MARK_ENTRY(CODA_REMOVE_STATS);
1169 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1170 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1171 cp->c_fid.Unique)););
1173 /* Remove the file's entry from the CODA Name Cache */
1174 /* We're being conservative here, it might be that this person
1175 * doesn't really have sufficient access to delete the file
1176 * but we feel zapping the entry won't really hurt anyone -- dcs
1178 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1179 * exist, and one is removed, the link count on the other will be
1180 * off by 1. We could either invalidate the attrs if cached, or
1181 * fix them. I'll try to fix them. DCS 11/8/94
1183 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1185 if (VALID_VATTR(tp)) { /* If attrs are cached */
1186 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1187 tp->c_vattr.va_nlink--;
1191 coda_nc_zapfile(VTOC(dvp), nm, len);
1192 /* No need to flush it if it doesn't exist! */
1194 /* Invalidate the parent's attr cache, the modification time has changed */
1195 VTOC(dvp)->c_flags &= ~C_VATTR;
1197 /* Check for remove of control object. */
1198 if (IS_CTL_NAME(dvp, nm, len)) {
1199 MARK_INT_FAIL(CODA_REMOVE_STATS);
1203 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1205 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1211 coda_link(struct vop_old_link_args *ap)
1214 struct vnode *vp = ap->a_vp;
1215 struct cnode *cp = VTOC(vp);
1216 struct vnode *tdvp = ap->a_tdvp;
1217 struct cnode *tdcp = VTOC(tdvp);
1218 struct componentname *cnp = ap->a_cnp;
1219 struct ucred *cred = cnp->cn_cred;
1220 struct thread *td = cnp->cn_td;
1223 const char *nm = cnp->cn_nameptr;
1224 int len = cnp->cn_namelen;
1226 MARK_ENTRY(CODA_LINK_STATS);
1228 if (codadebug & CODADBGMSK(CODA_LINK)) {
1230 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1231 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1232 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1233 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1236 if (codadebug & CODADBGMSK(CODA_LINK)) {
1237 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1238 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1239 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1240 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1244 /* Check for link to/from control object. */
1245 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1246 MARK_INT_FAIL(CODA_LINK_STATS);
1250 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1252 /* Invalidate the parent's attr cache, the modification time has changed */
1253 VTOC(tdvp)->c_flags &= ~C_VATTR;
1254 VTOC(vp)->c_flags &= ~C_VATTR;
1256 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1262 coda_rename(struct vop_old_rename_args *ap)
1265 struct vnode *odvp = ap->a_fdvp;
1266 struct cnode *odcp = VTOC(odvp);
1267 struct componentname *fcnp = ap->a_fcnp;
1268 struct vnode *ndvp = ap->a_tdvp;
1269 struct cnode *ndcp = VTOC(ndvp);
1270 struct componentname *tcnp = ap->a_tcnp;
1271 struct ucred *cred = fcnp->cn_cred;
1272 struct thread *td = fcnp->cn_td;
1275 const char *fnm = fcnp->cn_nameptr;
1276 int flen = fcnp->cn_namelen;
1277 const char *tnm = tcnp->cn_nameptr;
1278 int tlen = tcnp->cn_namelen;
1280 MARK_ENTRY(CODA_RENAME_STATS);
1282 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1283 This could be Bad. XXX */
1284 #ifdef OLD_DIAGNOSTIC
1285 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1287 panic("coda_rename: component names don't agree");
1291 /* Check for rename involving control object. */
1292 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1293 MARK_INT_FAIL(CODA_RENAME_STATS);
1297 /* Problem with moving directories -- need to flush entry for .. */
1299 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1301 struct vnode *ovp = CTOV(ovcp);
1303 (ovp->v_type == VDIR)) /* If it's a directory */
1304 coda_nc_zapfile(VTOC(ovp),"..", 2);
1308 /* Remove the entries for both source and target files */
1309 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1310 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1312 /* Invalidate the parent's attr cache, the modification time has changed */
1313 VTOC(odvp)->c_flags &= ~C_VATTR;
1314 VTOC(ndvp)->c_flags &= ~C_VATTR;
1316 if (flen+1 > CODA_MAXNAMLEN) {
1317 MARK_INT_FAIL(CODA_RENAME_STATS);
1322 if (tlen+1 > CODA_MAXNAMLEN) {
1323 MARK_INT_FAIL(CODA_RENAME_STATS);
1328 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1331 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1333 /* It seems to be incumbent on us to drop locks on all four vnodes */
1334 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1340 if (ap->a_tvp == ndvp) {
1352 coda_mkdir(struct vop_old_mkdir_args *ap)
1355 struct vnode *dvp = ap->a_dvp;
1356 struct cnode *dcp = VTOC(dvp);
1357 struct componentname *cnp = ap->a_cnp;
1358 struct vattr *va = ap->a_vap;
1359 struct vnode **vpp = ap->a_vpp;
1360 struct ucred *cred = cnp->cn_cred;
1361 struct thread *td = cnp->cn_td;
1364 const char *nm = cnp->cn_nameptr;
1365 int len = cnp->cn_namelen;
1370 MARK_ENTRY(CODA_MKDIR_STATS);
1372 /* Check for mkdir of target object. */
1373 if (IS_CTL_NAME(dvp, nm, len)) {
1374 *vpp = (struct vnode *)0;
1375 MARK_INT_FAIL(CODA_MKDIR_STATS);
1379 if (len+1 > CODA_MAXNAMLEN) {
1380 *vpp = (struct vnode *)0;
1381 MARK_INT_FAIL(CODA_MKDIR_STATS);
1385 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1388 if (coda_find(&VFid) != NULL)
1389 panic("cnode existed for newly created directory!");
1392 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1395 /* enter the new vnode in the Name Cache */
1396 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1398 /* as a side effect, enter "." and ".." for the directory */
1399 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1400 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1402 if (coda_attr_cache) {
1403 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1404 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1407 /* Invalidate the parent's attr cache, the modification time has changed */
1408 VTOC(dvp)->c_flags &= ~C_VATTR;
1410 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1411 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1413 *vpp = (struct vnode *)0;
1414 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1421 coda_rmdir(struct vop_old_rmdir_args *ap)
1424 struct vnode *dvp = ap->a_dvp;
1425 struct cnode *dcp = VTOC(dvp);
1426 struct componentname *cnp = ap->a_cnp;
1427 struct ucred *cred = cnp->cn_cred;
1428 struct thread *td = cnp->cn_td;
1431 const char *nm = cnp->cn_nameptr;
1432 int len = cnp->cn_namelen;
1435 MARK_ENTRY(CODA_RMDIR_STATS);
1437 /* Check for rmdir of control object. */
1438 if (IS_CTL_NAME(dvp, nm, len)) {
1439 MARK_INT_FAIL(CODA_RMDIR_STATS);
1443 /* We're being conservative here, it might be that this person
1444 * doesn't really have sufficient access to delete the file
1445 * but we feel zapping the entry won't really hurt anyone -- dcs
1448 * As a side effect of the rmdir, remove any entries for children of
1449 * the directory, especially "." and "..".
1451 cp = coda_nc_lookup(dcp, nm, len, cred);
1452 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1454 /* Remove the file's entry from the CODA Name Cache */
1455 coda_nc_zapfile(dcp, nm, len);
1457 /* Invalidate the parent's attr cache, the modification time has changed */
1458 dcp->c_flags &= ~C_VATTR;
1460 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1462 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1468 coda_symlink(struct vop_old_symlink_args *ap)
1471 struct vnode *tdvp = ap->a_dvp;
1472 struct cnode *tdcp = VTOC(tdvp);
1473 struct componentname *cnp = ap->a_cnp;
1474 struct vattr *tva = ap->a_vap;
1475 char *path = ap->a_target;
1476 struct ucred *cred = cnp->cn_cred;
1477 struct thread *td = cnp->cn_td;
1478 struct vnode **vpp = ap->a_vpp;
1482 * XXX I'm assuming the following things about coda_symlink's
1484 * t(foo) is the new name/parent/etc being created.
1485 * lname is the contents of the new symlink.
1487 char *nm = cnp->cn_nameptr;
1488 int len = cnp->cn_namelen;
1489 int plen = strlen(path);
1492 * Here's the strategy for the moment: perform the symlink, then
1493 * do a lookup to grab the resulting vnode. I know this requires
1494 * two communications with Venus for a new sybolic link, but
1495 * that's the way the ball bounces. I don't yet want to change
1496 * the way the Mach symlink works. When Mach support is
1497 * deprecated, we should change symlink so that the common case
1498 * returns the resultant vnode in a vpp argument.
1501 MARK_ENTRY(CODA_SYMLINK_STATS);
1503 /* Check for symlink of control object. */
1504 if (IS_CTL_NAME(tdvp, nm, len)) {
1505 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1509 if (plen+1 > CODA_MAXPATHLEN) {
1510 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1514 if (len+1 > CODA_MAXNAMLEN) {
1515 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1520 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1522 /* Invalidate the parent's attr cache, the modification time has changed */
1523 tdcp->c_flags &= ~C_VATTR;
1526 error = VOP_OLD_LOOKUP(tdvp, vpp, cnp);
1529 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1534 * Read directory entries.
1537 coda_readdir(struct vop_readdir_args *ap)
1540 struct vnode *vp = ap->a_vp;
1541 struct cnode *cp = VTOC(vp);
1542 struct uio *uiop = ap->a_uio;
1543 struct ucred *cred = ap->a_cred;
1544 int *eofflag = ap->a_eofflag;
1545 u_long **cookies = ap->a_cookies;
1546 int *ncookies = ap->a_ncookies;
1551 MARK_ENTRY(CODA_READDIR_STATS);
1553 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1554 (void *)uiop->uio_iov->iov_base,
1556 (long long)uiop->uio_offset,
1557 uiop->uio_segflg)); )
1559 /* Check for readdir of control object. */
1560 if (IS_CTL_VP(vp)) {
1561 MARK_INT_FAIL(CODA_READDIR_STATS);
1566 /* If directory is not already open do an "internal open" on it. */
1567 int opened_internally = 0;
1568 if (cp->c_ovp == NULL) {
1569 opened_internally = 1;
1570 MARK_INT_GEN(CODA_OPEN_STATS);
1571 error = VOP_OPEN(vp, FREAD, cred, NULL);
1572 printf("coda_readdir: Internally Opening %p\n", vp);
1574 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1577 if (vp->v_type == VREG) {
1578 if (vp->v_object == NULL) {
1580 printf("coda_readdir: vnode %p has no VM object!\n", vp);
1584 if (error) return(error);
1587 /* Have UFS handle the call. */
1588 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)); )
1589 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1593 MARK_INT_FAIL(CODA_READDIR_STATS);
1595 MARK_INT_SAT(CODA_READDIR_STATS);
1597 /* Do an "internal close" if necessary. */
1598 if (opened_internally) {
1599 MARK_INT_GEN(CODA_CLOSE_STATS);
1600 VOP_CLOSE(vp, FREAD);
1608 * Convert from file system blocks to device blocks
1611 coda_bmap(struct vop_bmap_args *ap)
1613 /* XXX on the global proc */
1617 cp = VTOC(ap->a_vp);
1621 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1622 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1623 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1628 printf("coda_bmap: no container\n");
1635 * I don't think the following two things are used anywhere, so I've
1636 * commented them out
1638 * struct buf *async_bufhead;
1639 * int async_daemon_count;
1642 coda_strategy(struct vop_strategy_args *ap __unused)
1644 printf("coda_strategy: called ???\n");
1649 coda_reclaim(struct vop_reclaim_args *ap)
1652 struct vnode *vp = ap->a_vp;
1653 struct cnode *cp = VTOC(vp);
1658 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1662 if (IS_UNMOUNTING(cp)) {
1664 if (VTOC(vp)->c_ovp) {
1665 if (IS_UNMOUNTING(cp))
1666 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1670 #ifdef OLD_DIAGNOSTIC
1671 if (vp->v_usecount != 0)
1672 print("coda_reclaim: pushing active %p\n", vp);
1673 if (VTOC(vp)->c_ovp) {
1674 panic("coda_reclaim: c_ovp not void");
1678 coda_free(VTOC(vp));
1684 coda_lock(struct vop_lock_args *ap)
1687 struct vnode *vp = ap->a_vp;
1688 struct cnode *cp = VTOC(vp);
1694 if (coda_lockdebug) {
1695 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1696 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1700 return (lockmgr(&vp->v_lock, ap->a_flags));
1702 return (debuglockmgr(&vp->v_lock, ap->a_flags,
1703 "coda_lock", vp->filename, vp->line));
1708 coda_unlock(struct vop_unlock_args *ap)
1711 struct vnode *vp = ap->a_vp;
1712 struct cnode *cp = VTOC(vp);
1717 if (coda_lockdebug) {
1718 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1719 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1722 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE));
1726 coda_islocked(struct vop_islocked_args *ap)
1731 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1734 /* How one looks up a vnode given a device/inode pair: */
1736 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1738 /* This is like VFS_VGET() or igetinode()! */
1742 if (!(mp = devtomp(dev))) {
1743 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1744 (u_long)dev2udev(dev)));
1748 /* XXX - ensure that nonzero-return means failure */
1749 error = VFS_VGET(mp,ino,vpp);
1751 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1752 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1759 print_vattr(struct vattr *attr)
1763 switch (attr->va_type) {
1797 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1798 typestr, (int)attr->va_mode, (int)attr->va_uid,
1799 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1801 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1802 (int)attr->va_fileid, (int)attr->va_nlink,
1804 (int)attr->va_blocksize,(int)attr->va_bytes));
1805 myprintf((" gen %ld flags %ld vaflags %d\n",
1806 attr->va_gen, attr->va_flags, attr->va_vaflags));
1807 myprintf((" atime sec %d nsec %d\n",
1808 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1809 myprintf((" mtime sec %d nsec %d\n",
1810 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1811 myprintf((" ctime sec %d nsec %d\n",
1812 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1815 /* How to print a ucred */
1817 print_cred(struct ucred *cred)
1822 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1824 for (i=0; i < cred->cr_ngroups; i++)
1825 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1831 * Return a vnode for the given fid.
1832 * If no cnode exists for this fid create one and put it
1833 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1834 * this fid is already in the table return it (ref count is
1835 * incremented by coda_find. The cnode will be flushed from the
1836 * table when coda_inactive calls coda_unsave.
1839 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1844 if ((cp = coda_find(fid)) == NULL) {
1850 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
1852 panic("coda: getnewvnode returned error %d\n", err);