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.37 2006/05/05 21:15: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 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
114 { &vop_default_desc, (vnodeopv_entry_t)coda_vop_error },
115 { &vop_old_lookup_desc, (vnodeopv_entry_t)coda_lookup }, /* lookup */
116 { &vop_old_create_desc, (vnodeopv_entry_t)coda_create }, /* create */
117 { &vop_old_mknod_desc, (vnodeopv_entry_t)coda_vop_error }, /* mknod */
118 { &vop_open_desc, (vnodeopv_entry_t)coda_open }, /* open */
119 { &vop_close_desc, (vnodeopv_entry_t)coda_close }, /* close */
120 { &vop_access_desc, (vnodeopv_entry_t)coda_access }, /* access */
121 { &vop_getattr_desc, (vnodeopv_entry_t)coda_getattr }, /* getattr */
122 { &vop_setattr_desc, (vnodeopv_entry_t)coda_setattr }, /* setattr */
123 { &vop_read_desc, (vnodeopv_entry_t)coda_read }, /* read */
124 { &vop_write_desc, (vnodeopv_entry_t)coda_write }, /* write */
125 { &vop_ioctl_desc, (vnodeopv_entry_t)coda_ioctl }, /* ioctl */
126 { &vop_mmap_desc, (vnodeopv_entry_t)coda_vop_error }, /* mmap */
127 { &vop_fsync_desc, (vnodeopv_entry_t)coda_fsync }, /* fsync */
128 { &vop_old_remove_desc, (vnodeopv_entry_t)coda_remove }, /* remove */
129 { &vop_old_link_desc, (vnodeopv_entry_t)coda_link }, /* link */
130 { &vop_old_rename_desc, (vnodeopv_entry_t)coda_rename }, /* rename */
131 { &vop_old_mkdir_desc, (vnodeopv_entry_t)coda_mkdir }, /* mkdir */
132 { &vop_old_rmdir_desc, (vnodeopv_entry_t)coda_rmdir }, /* rmdir */
133 { &vop_old_symlink_desc, (vnodeopv_entry_t)coda_symlink }, /* symlink */
134 { &vop_readdir_desc, (vnodeopv_entry_t)coda_readdir }, /* readdir */
135 { &vop_readlink_desc, (vnodeopv_entry_t)coda_readlink }, /* readlink */
136 { &vop_inactive_desc, (vnodeopv_entry_t)coda_inactive }, /* inactive */
137 { &vop_reclaim_desc, (vnodeopv_entry_t)coda_reclaim }, /* reclaim */
138 { &vop_lock_desc, (vnodeopv_entry_t)coda_lock }, /* lock */
139 { &vop_unlock_desc, (vnodeopv_entry_t)coda_unlock }, /* unlock */
140 { &vop_bmap_desc, (vnodeopv_entry_t)coda_bmap }, /* bmap */
141 { &vop_strategy_desc, (vnodeopv_entry_t)coda_strategy }, /* strategy */
142 { &vop_print_desc, (vnodeopv_entry_t)coda_vop_error }, /* print */
143 { &vop_islocked_desc, (vnodeopv_entry_t)coda_islocked }, /* islocked */
144 { &vop_pathconf_desc, (vnodeopv_entry_t)coda_vop_error }, /* pathconf */
145 { &vop_advlock_desc, (vnodeopv_entry_t)coda_vop_nop }, /* advlock */
146 { &vop_poll_desc, (vnodeopv_entry_t)vop_stdpoll }, /* poll */
147 { &vop_getpages_desc, (vnodeopv_entry_t)coda_fbsd_getpages }, /* pager intf.*/
148 { &vop_putpages_desc, (vnodeopv_entry_t)coda_fbsd_putpages }, /* pager intf.*/
152 we need to define these someday
153 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
154 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
155 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
156 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
157 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
160 { &vop_reallocblks_desc, (vnodeopv_entry_t) ufs_missingop },
161 { &vop_old_lookup_desc, (vnodeopv_entry_t) ufs_lookup },
162 { &vop_old_whiteout_desc, (vnodeopv_entry_t) ufs_whiteout },
167 /* A generic panic: we were called with something we didn't define yet */
169 coda_vop_error(void *anon)
171 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
173 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
174 (*desc)->vdesc_name));
176 panic("coda_vop_error");
181 /* A generic do-nothing. For lease_check, advlock */
183 coda_vop_nop(void *anon)
185 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
188 myprintf(("Vnode operation %s called, but unsupported\n",
189 (*desc)->vdesc_name));
195 coda_vnodeopstats_init(void)
199 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
200 coda_vnodeopstats[i].opcode = i;
201 coda_vnodeopstats[i].entries = 0;
202 coda_vnodeopstats[i].sat_intrn = 0;
203 coda_vnodeopstats[i].unsat_intrn = 0;
204 coda_vnodeopstats[i].gen_intrn = 0;
210 * coda_open calls Venus to return the device, inode pair of the cache
211 * file holding the data. Using iget, coda_open finds the vnode of the
212 * cache file, and then opens it.
218 * NetBSD can pass the O_EXCL flag in mode, even though the check
219 * has already happened. Venus defensively assumes that if open
220 * is passed the EXCL, it must be a bug. We strip the flag here.
223 struct vop_open_args *ap = v;
224 struct vnode **vpp = &(ap->a_vp);
225 struct cnode *cp = VTOC(*vpp);
226 int flag = ap->a_mode & (~O_EXCL);
227 struct ucred *cred = ap->a_cred;
228 struct thread *td = ap->a_td;
235 MARK_ENTRY(CODA_OPEN_STATS);
237 /* Check for open of control file. */
238 if (IS_CTL_VP(*vpp)) {
240 /* if (WRITEABLE(flag)) */
241 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
242 MARK_INT_FAIL(CODA_OPEN_STATS);
246 MARK_INT_SAT(CODA_OPEN_STATS);
251 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
255 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
256 (u_long)dev2udev(dev), (u_long)inode,
260 /* Translate the <device, inode> pair for the cache file into
262 error = coda_grab_vnode(dev, inode, &vp);
266 /* We get the vnode back locked. Needs unlocked */
268 /* Keep a reference until the close comes in. */
271 /* Save the vnode pointer for the cache file. */
272 if (cp->c_ovp == NULL) {
276 panic("coda_open: cp->c_ovp != ITOV(ip)");
280 /* Flush the attribute cached if writing the file. */
283 cp->c_flags &= ~C_VATTR;
286 /* Save the <device, inode> pair for the cache file to speed
287 up subsequent page_read's. */
291 /* Open the cache file. */
292 error = VOP_OPEN(vp, flag, cred, NULL, td);
294 printf("coda_open: VOP_OPEN on container failed %d\n", error);
297 /* grab (above) does this when it calls newvnode unless it's in the cache*/
298 if (vp->v_type == VREG) {
299 if (vp->v_object == NULL) {
301 printf("coda_open: cache file vp %p has no VM object!\n", vp);
312 * Close the cache file used for I/O and notify Venus.
318 struct vop_close_args *ap = v;
319 struct vnode *vp = ap->a_vp;
320 struct cnode *cp = VTOC(vp);
321 int flag = ap->a_fflag;
322 struct thread *td = ap->a_td;
326 MARK_ENTRY(CODA_CLOSE_STATS);
328 /* Check for close of control file. */
330 MARK_INT_SAT(CODA_CLOSE_STATS);
335 if (IS_UNMOUNTING(cp)) {
338 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
339 vp->v_usecount, cp->c_ovp, vp, cp);
344 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
349 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
355 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
359 if (--cp->c_ocount == 0)
362 if (flag & FWRITE) /* file was opened for write */
365 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
368 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
377 struct vop_read_args *ap = v;
380 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
381 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
387 struct vop_write_args *ap = v;
390 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
391 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
395 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
396 struct ucred *cred, struct thread *td)
399 /* NOTE: container file operation!!! */
401 struct cnode *cp = VTOC(vp);
402 struct vnode *cfvp = cp->c_ovp;
403 int igot_internally = 0;
404 int opened_internally = 0;
407 MARK_ENTRY(CODA_RDWR_STATS);
409 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
410 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
411 (long long)uiop->uio_offset, uiop->uio_segflg)); )
413 /* Check for rdwr of control object. */
415 MARK_INT_FAIL(CODA_RDWR_STATS);
420 * If file is not already open this must be a page
421 * {read,write} request. Iget the cache file's inode
422 * pointer if we still have its <device, inode> pair.
423 * Otherwise, we must do an internal open to derive the
428 * If we're dumping core, do the internal open. Otherwise
429 * venus won't have the correct size of the core when
430 * it's completely written.
432 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
434 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
436 MARK_INT_FAIL(CODA_RDWR_STATS);
440 * We get the vnode back locked in both Mach and
441 * NetBSD. Needs unlocked
446 opened_internally = 1;
447 MARK_INT_GEN(CODA_OPEN_STATS);
448 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
450 printf("coda_rdwr: Internally Opening %p\n", vp);
452 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
455 if (vp->v_type == VREG) {
456 if (vp->v_object == NULL) {
458 printf("coda_rdwr: vnode %p has no VM object!\n", vp);
463 MARK_INT_FAIL(CODA_RDWR_STATS);
470 /* Have UFS handle the call. */
471 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
472 cp->c_fid.Volume, cp->c_fid.Vnode,
473 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
476 if (rw == UIO_READ) {
477 error = VOP_READ(cfvp, uiop, ioflag, cred);
479 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
480 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
484 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
485 vnode_pager_setsize(vp, attr.va_size);
491 MARK_INT_FAIL(CODA_RDWR_STATS);
493 MARK_INT_SAT(CODA_RDWR_STATS);
495 /* Do an internal close if necessary. */
496 if (opened_internally) {
497 MARK_INT_GEN(CODA_CLOSE_STATS);
498 VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
501 /* Invalidate cached attributes if writing. */
503 cp->c_flags &= ~C_VATTR;
511 struct vop_ioctl_args *ap = v;
512 struct vnode *vp = ap->a_vp;
513 int com = ap->a_command;
514 caddr_t data = ap->a_data;
515 int flag = ap->a_fflag;
516 struct ucred *cred = ap->a_cred;
517 struct thread *td = ap->a_td;
521 struct nlookupdata nd;
522 struct PioctlData *iap = (struct PioctlData *)data;
524 MARK_ENTRY(CODA_IOCTL_STATS);
526 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
528 /* Don't check for operation on a dying object, for ctlvp it
531 /* Must be control object to succeed. */
532 if (!IS_CTL_VP(vp)) {
533 MARK_INT_FAIL(CODA_IOCTL_STATS);
534 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
537 /* Look up the pathname. */
539 /* Should we use the name cache here? It would get it from
540 lookupname sooner or later anyway, right? */
543 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
544 (iap->follow ? NLC_FOLLOW : 0));
546 error = nlookup(&nd);
548 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
552 MARK_INT_FAIL(CODA_IOCTL_STATS);
553 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
559 * Make sure this is a coda style cnode, but it may be a
562 if (tvp->v_tag != VT_CODA) {
564 MARK_INT_FAIL(CODA_IOCTL_STATS);
565 CODADEBUG(CODA_IOCTL,
566 myprintf(("coda_ioctl error: %s not a coda object\n",
571 if (iap->vi.in_size > VC_MAXDATASIZE) {
575 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
578 MARK_INT_FAIL(CODA_IOCTL_STATS);
580 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
587 * To reduce the cost of a user-level venus;we cache attributes in
588 * the kernel. Each cnode has storage allocated for an attribute. If
589 * c_vattr is valid, return a reference to it. Otherwise, get the
590 * attributes from venus and store them in the cnode. There is some
591 * question if this method is a security leak. But I think that in
592 * order to make this call, the user must have done a lookup and
593 * opened the file, and therefore should already have access.
596 coda_getattr(void *v)
599 struct vop_getattr_args *ap = v;
600 struct vnode *vp = ap->a_vp;
601 struct cnode *cp = VTOC(vp);
602 struct vattr *vap = ap->a_vap;
603 struct thread *td = ap->a_td;
607 MARK_ENTRY(CODA_GETATTR_STATS);
609 if (IS_UNMOUNTING(cp))
612 /* Check for getattr of control object. */
614 MARK_INT_FAIL(CODA_GETATTR_STATS);
618 /* Check to see if the attributes have already been cached */
619 if (VALID_VATTR(cp)) {
620 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
623 cp->c_fid.Unique));});
624 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
625 print_vattr(&cp->c_vattr); );
628 MARK_INT_SAT(CODA_GETATTR_STATS);
632 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
635 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
641 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
644 { int size = vap->va_size;
645 struct vnode *convp = cp->c_ovp;
646 if (convp != (struct vnode *)0) {
647 vnode_pager_setsize(convp, size);
650 /* If not open for write, store attributes in cnode */
651 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
653 cp->c_flags |= C_VATTR;
661 coda_setattr(void *v)
664 struct vop_setattr_args *ap = v;
665 struct vnode *vp = ap->a_vp;
666 struct cnode *cp = VTOC(vp);
667 struct vattr *vap = ap->a_vap;
668 struct ucred *cred = ap->a_cred;
669 struct thread *td = ap->a_td;
673 MARK_ENTRY(CODA_SETATTR_STATS);
675 /* Check for setattr of control object. */
677 MARK_INT_FAIL(CODA_SETATTR_STATS);
681 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
684 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
687 cp->c_flags &= ~C_VATTR;
689 { int size = vap->va_size;
690 struct vnode *convp = cp->c_ovp;
691 if (size != VNOVAL && convp != (struct vnode *)0) {
692 vnode_pager_setsize(convp, size);
695 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
703 struct vop_access_args *ap = v;
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 = ap->a_td;
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(void *v)
746 struct vop_readlink_args *ap = v;
747 struct vnode *vp = ap->a_vp;
748 struct cnode *cp = VTOC(vp);
749 struct uio *uiop = ap->a_uio;
750 struct ucred *cred = ap->a_cred;
751 struct thread *td = ap->a_uio->uio_td;
757 MARK_ENTRY(CODA_READLINK_STATS);
759 /* Check for readlink of control object. */
761 MARK_INT_FAIL(CODA_READLINK_STATS);
765 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
766 uiop->uio_rw = UIO_READ;
767 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
769 MARK_INT_FAIL(CODA_READLINK_STATS);
771 MARK_INT_SAT(CODA_READLINK_STATS);
775 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
778 uiop->uio_rw = UIO_READ;
779 error = uiomove(str, len, uiop);
781 if (coda_symlink_cache) {
784 cp->c_flags |= C_SYMLINK;
789 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
797 struct vop_fsync_args *ap = v;
798 struct vnode *vp = ap->a_vp;
799 struct cnode *cp = VTOC(vp);
800 struct thread *td = ap->a_td;
802 struct vnode *convp = cp->c_ovp;
805 MARK_ENTRY(CODA_FSYNC_STATS);
807 /* Check for fsync on an unmounting object */
808 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
809 * after an unmount has been initiated. This is a Bad Thing,
810 * which we have to avoid. Not a legitimate failure for stats.
812 if (IS_UNMOUNTING(cp)) {
816 /* Check for fsync of control object. */
818 MARK_INT_SAT(CODA_FSYNC_STATS);
823 VOP_FSYNC(convp, MNT_WAIT, td);
826 * We see fsyncs with usecount == 1 then usecount == 0.
827 * For now we ignore them.
830 if (!vp->v_usecount) {
831 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
832 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
837 * We can expect fsync on any vnode at all if venus is pruging it.
838 * Venus can't very well answer the fsync request, now can it?
839 * Hopefully, it won't have to, because hopefully, venus preserves
840 * the (possibly untrue) invariant that it never purges an open
843 if (cp->c_flags & C_PURGING) {
849 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
851 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
856 coda_inactive(void *v)
858 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
859 have a proc pointer. Oops. */
861 struct vop_inactive_args *ap = v;
862 struct vnode *vp = ap->a_vp;
863 struct cnode *cp = VTOC(vp);
864 struct ucred *cred __attribute__((unused)) = NULL;
865 /*struct thread *td = curthread;*/
869 /* We don't need to send inactive to venus - DCS */
870 MARK_ENTRY(CODA_INACTIVE_STATS);
873 MARK_INT_SAT(CODA_INACTIVE_STATS);
877 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
878 cp->c_fid.Volume, cp->c_fid.Vnode,
879 cp->c_fid.Unique, vp->v_mount));)
881 /* If an array has been allocated to hold the symlink, deallocate it */
882 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
883 if (cp->c_symlink == NULL)
884 panic("coda_inactive: null symlink pointer in cnode");
886 CODA_FREE(cp->c_symlink, cp->c_symlen);
887 cp->c_flags &= ~C_SYMLINK;
891 /* Remove it from the table so it can't be found. */
893 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
894 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
895 panic("badness in coda_inactive\n");
898 if (IS_UNMOUNTING(cp)) {
900 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
901 if (cp->c_ovp != NULL)
902 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
903 vp->v_usecount, vp, cp);
906 #ifdef OLD_DIAGNOSTIC
907 if (CTOV(cp)->v_usecount) {
908 panic("coda_inactive: nonzero reference count");
910 if (cp->c_ovp != NULL) {
911 panic("coda_inactive: cp->ovp != NULL");
917 MARK_INT_SAT(CODA_INACTIVE_STATS);
922 * Remote file system operations having to do with directory manipulation.
926 * It appears that in NetBSD, lookup is supposed to return the vnode locked
932 struct vop_old_lookup_args *ap = v;
933 struct vnode *dvp = ap->a_dvp;
934 struct cnode *dcp = VTOC(dvp);
935 struct vnode **vpp = ap->a_vpp;
937 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
938 * of the string to xlate, and that we must try to get at least
939 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
942 struct componentname *cnp = ap->a_cnp;
943 struct ucred *cred = cnp->cn_cred;
944 struct thread *td = cnp->cn_td;
947 const char *nm = cnp->cn_nameptr;
948 int len = cnp->cn_namelen;
953 MARK_ENTRY(CODA_LOOKUP_STATS);
955 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
956 nm, dcp->c_fid.Volume,
957 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
959 /* Check for lookup of control object. */
960 if (IS_CTL_NAME(dvp, nm, len)) {
963 MARK_INT_SAT(CODA_LOOKUP_STATS);
967 if (len+1 > CODA_MAXNAMLEN) {
968 MARK_INT_FAIL(CODA_LOOKUP_STATS);
969 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
970 dcp->c_fid.Volume, dcp->c_fid.Vnode,
971 dcp->c_fid.Unique, nm)););
972 *vpp = (struct vnode *)0;
976 /* First try to look the file up in the cfs name cache */
977 /* lock the parent vnode? */
978 cp = coda_nc_lookup(dcp, nm, len, cred);
982 CODADEBUG(CODA_LOOKUP,
983 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
986 /* The name wasn't cached, so we need to contact Venus */
987 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
990 MARK_INT_FAIL(CODA_LOOKUP_STATS);
991 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
992 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
993 *vpp = (struct vnode *)0;
995 MARK_INT_SAT(CODA_LOOKUP_STATS);
996 CODADEBUG(CODA_LOOKUP,
997 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
998 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1001 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1004 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1005 /* And don't enter a new vnode for an invalid one! */
1006 if (!(vtype & CODA_NOCACHE))
1007 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1013 * If we are creating, and this was the last name to be looked up,
1014 * and the error was ENOENT, then there really shouldn't be an
1015 * error and we can make the leaf NULL and return success. Since
1016 * this is supposed to work under Mach as well as NetBSD, we're
1017 * leaving this fn wrapped. We also must tell lookup/namei that
1018 * we need to save the last component of the name. (Create will
1019 * have to free the name buffer later...lucky us...)
1021 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1024 error = EJUSTRETURN;
1029 * If the lookup went well, we need to (potentially?) unlock the
1030 * parent, and lock the child. We are only responsible for
1031 * checking to see if the parent is supposed to be unlocked before
1032 * we return. We must always lock the child (provided there is
1033 * one, and (the parent isn't locked or it isn't the same as the
1034 * parent.) Simple, huh? We can never leave the parent locked unless
1037 if (!error || (error == EJUSTRETURN)) {
1038 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
1039 if ((error = VOP_UNLOCK(dvp, 0))) {
1043 * The parent is unlocked. As long as there is a child,
1044 * lock it without bothering to check anything else.
1047 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1048 printf("coda_lookup: ");
1049 panic("unlocked parent but couldn't lock child");
1053 /* The parent is locked, and may be the same as the child */
1054 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1055 /* Different, go ahead and lock it. */
1056 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1057 printf("coda_lookup: ");
1058 panic("unlocked parent but couldn't lock child");
1063 /* If the lookup failed, we need to ensure that the leaf is NULL */
1064 /* Don't change any locking? */
1072 coda_create(void *v)
1075 struct vop_old_create_args *ap = v;
1076 struct vnode *dvp = ap->a_dvp;
1077 struct cnode *dcp = VTOC(dvp);
1078 struct vattr *va = ap->a_vap;
1080 int mode = ap->a_vap->va_mode;
1081 struct vnode **vpp = ap->a_vpp;
1082 struct componentname *cnp = ap->a_cnp;
1083 struct ucred *cred = cnp->cn_cred;
1084 struct thread *td = cnp->cn_td;
1088 const char *nm = cnp->cn_nameptr;
1089 int len = cnp->cn_namelen;
1093 MARK_ENTRY(CODA_CREATE_STATS);
1095 /* All creates are exclusive XXX */
1096 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1098 /* Check for create of control object. */
1099 if (IS_CTL_NAME(dvp, nm, len)) {
1100 *vpp = (struct vnode *)0;
1101 MARK_INT_FAIL(CODA_CREATE_STATS);
1105 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1109 /* If this is an exclusive create, panic if the file already exists. */
1110 /* Venus should have detected the file and reported EEXIST. */
1112 if ((exclusive == 1) &&
1113 (coda_find(&VFid) != NULL))
1114 panic("cnode existed for newly created file!");
1116 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1119 /* Update va to reflect the new attributes. */
1122 /* Update the attribute cache and mark it as valid */
1123 if (coda_attr_cache) {
1124 VTOC(*vpp)->c_vattr = attr;
1125 VTOC(*vpp)->c_flags |= C_VATTR;
1128 /* Invalidate the parent's attr cache, the modification time has changed */
1129 VTOC(dvp)->c_flags &= ~C_VATTR;
1131 /* enter the new vnode in the Name Cache */
1132 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1134 CODADEBUG(CODA_CREATE,
1135 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1136 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1138 *vpp = (struct vnode *)0;
1139 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1143 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE))) {
1144 printf("coda_create: ");
1145 panic("unlocked parent but couldn't lock child");
1152 coda_remove(void *v)
1155 struct vop_old_remove_args *ap = v;
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)); )
1214 struct vop_old_link_args *ap = v;
1215 struct vnode *vp = ap->a_vp;
1216 struct cnode *cp = VTOC(vp);
1217 struct vnode *tdvp = ap->a_tdvp;
1218 struct cnode *tdcp = VTOC(tdvp);
1219 struct componentname *cnp = ap->a_cnp;
1220 struct ucred *cred = cnp->cn_cred;
1221 struct thread *td = cnp->cn_td;
1224 const char *nm = cnp->cn_nameptr;
1225 int len = cnp->cn_namelen;
1227 MARK_ENTRY(CODA_LINK_STATS);
1229 if (codadebug & CODADBGMSK(CODA_LINK)) {
1231 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1232 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1233 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1234 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1237 if (codadebug & CODADBGMSK(CODA_LINK)) {
1238 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1239 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1240 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1241 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1245 /* Check for link to/from control object. */
1246 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1247 MARK_INT_FAIL(CODA_LINK_STATS);
1251 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1253 /* Invalidate the parent's attr cache, the modification time has changed */
1254 VTOC(tdvp)->c_flags &= ~C_VATTR;
1255 VTOC(vp)->c_flags &= ~C_VATTR;
1257 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1263 coda_rename(void *v)
1266 struct vop_old_rename_args *ap = v;
1267 struct vnode *odvp = ap->a_fdvp;
1268 struct cnode *odcp = VTOC(odvp);
1269 struct componentname *fcnp = ap->a_fcnp;
1270 struct vnode *ndvp = ap->a_tdvp;
1271 struct cnode *ndcp = VTOC(ndvp);
1272 struct componentname *tcnp = ap->a_tcnp;
1273 struct ucred *cred = fcnp->cn_cred;
1274 struct thread *td = fcnp->cn_td;
1277 const char *fnm = fcnp->cn_nameptr;
1278 int flen = fcnp->cn_namelen;
1279 const char *tnm = tcnp->cn_nameptr;
1280 int tlen = tcnp->cn_namelen;
1282 MARK_ENTRY(CODA_RENAME_STATS);
1284 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1285 This could be Bad. XXX */
1286 #ifdef OLD_DIAGNOSTIC
1287 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1289 panic("coda_rename: component names don't agree");
1293 /* Check for rename involving control object. */
1294 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1295 MARK_INT_FAIL(CODA_RENAME_STATS);
1299 /* Problem with moving directories -- need to flush entry for .. */
1301 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1303 struct vnode *ovp = CTOV(ovcp);
1305 (ovp->v_type == VDIR)) /* If it's a directory */
1306 coda_nc_zapfile(VTOC(ovp),"..", 2);
1310 /* Remove the entries for both source and target files */
1311 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1312 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1314 /* Invalidate the parent's attr cache, the modification time has changed */
1315 VTOC(odvp)->c_flags &= ~C_VATTR;
1316 VTOC(ndvp)->c_flags &= ~C_VATTR;
1318 if (flen+1 > CODA_MAXNAMLEN) {
1319 MARK_INT_FAIL(CODA_RENAME_STATS);
1324 if (tlen+1 > CODA_MAXNAMLEN) {
1325 MARK_INT_FAIL(CODA_RENAME_STATS);
1330 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1333 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1335 /* It seems to be incumbent on us to drop locks on all four vnodes */
1336 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1342 if (ap->a_tvp == ndvp) {
1357 struct vop_old_mkdir_args *ap = v;
1358 struct vnode *dvp = ap->a_dvp;
1359 struct cnode *dcp = VTOC(dvp);
1360 struct componentname *cnp = ap->a_cnp;
1361 struct vattr *va = ap->a_vap;
1362 struct vnode **vpp = ap->a_vpp;
1363 struct ucred *cred = cnp->cn_cred;
1364 struct thread *td = cnp->cn_td;
1367 const char *nm = cnp->cn_nameptr;
1368 int len = cnp->cn_namelen;
1373 MARK_ENTRY(CODA_MKDIR_STATS);
1375 /* Check for mkdir of target object. */
1376 if (IS_CTL_NAME(dvp, nm, len)) {
1377 *vpp = (struct vnode *)0;
1378 MARK_INT_FAIL(CODA_MKDIR_STATS);
1382 if (len+1 > CODA_MAXNAMLEN) {
1383 *vpp = (struct vnode *)0;
1384 MARK_INT_FAIL(CODA_MKDIR_STATS);
1388 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1391 if (coda_find(&VFid) != NULL)
1392 panic("cnode existed for newly created directory!");
1395 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1398 /* enter the new vnode in the Name Cache */
1399 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1401 /* as a side effect, enter "." and ".." for the directory */
1402 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1403 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1405 if (coda_attr_cache) {
1406 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1407 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1410 /* Invalidate the parent's attr cache, the modification time has changed */
1411 VTOC(dvp)->c_flags &= ~C_VATTR;
1413 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1414 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1416 *vpp = (struct vnode *)0;
1417 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1427 struct vop_old_rmdir_args *ap = v;
1428 struct vnode *dvp = ap->a_dvp;
1429 struct cnode *dcp = VTOC(dvp);
1430 struct componentname *cnp = ap->a_cnp;
1431 struct ucred *cred = cnp->cn_cred;
1432 struct thread *td = cnp->cn_td;
1435 const char *nm = cnp->cn_nameptr;
1436 int len = cnp->cn_namelen;
1439 MARK_ENTRY(CODA_RMDIR_STATS);
1441 /* Check for rmdir of control object. */
1442 if (IS_CTL_NAME(dvp, nm, len)) {
1443 MARK_INT_FAIL(CODA_RMDIR_STATS);
1447 /* We're being conservative here, it might be that this person
1448 * doesn't really have sufficient access to delete the file
1449 * but we feel zapping the entry won't really hurt anyone -- dcs
1452 * As a side effect of the rmdir, remove any entries for children of
1453 * the directory, especially "." and "..".
1455 cp = coda_nc_lookup(dcp, nm, len, cred);
1456 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1458 /* Remove the file's entry from the CODA Name Cache */
1459 coda_nc_zapfile(dcp, nm, len);
1461 /* Invalidate the parent's attr cache, the modification time has changed */
1462 dcp->c_flags &= ~C_VATTR;
1464 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1466 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1472 coda_symlink(void *v)
1475 struct vop_old_symlink_args *ap = v;
1476 struct vnode *tdvp = ap->a_dvp;
1477 struct cnode *tdcp = VTOC(tdvp);
1478 struct componentname *cnp = ap->a_cnp;
1479 struct vattr *tva = ap->a_vap;
1480 char *path = ap->a_target;
1481 struct ucred *cred = cnp->cn_cred;
1482 struct thread *td = cnp->cn_td;
1483 struct vnode **vpp = ap->a_vpp;
1487 * XXX I'm assuming the following things about coda_symlink's
1489 * t(foo) is the new name/parent/etc being created.
1490 * lname is the contents of the new symlink.
1492 char *nm = cnp->cn_nameptr;
1493 int len = cnp->cn_namelen;
1494 int plen = strlen(path);
1497 * Here's the strategy for the moment: perform the symlink, then
1498 * do a lookup to grab the resulting vnode. I know this requires
1499 * two communications with Venus for a new sybolic link, but
1500 * that's the way the ball bounces. I don't yet want to change
1501 * the way the Mach symlink works. When Mach support is
1502 * deprecated, we should change symlink so that the common case
1503 * returns the resultant vnode in a vpp argument.
1506 MARK_ENTRY(CODA_SYMLINK_STATS);
1508 /* Check for symlink of control object. */
1509 if (IS_CTL_NAME(tdvp, nm, len)) {
1510 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1514 if (plen+1 > CODA_MAXPATHLEN) {
1515 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1519 if (len+1 > CODA_MAXNAMLEN) {
1520 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1525 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1527 /* Invalidate the parent's attr cache, the modification time has changed */
1528 tdcp->c_flags &= ~C_VATTR;
1531 error = VOP_OLD_LOOKUP(tdvp, vpp, cnp);
1534 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1539 * Read directory entries.
1542 coda_readdir(void *v)
1545 struct vop_readdir_args *ap = v;
1546 struct vnode *vp = ap->a_vp;
1547 struct cnode *cp = VTOC(vp);
1548 struct uio *uiop = ap->a_uio;
1549 struct ucred *cred = ap->a_cred;
1550 int *eofflag = ap->a_eofflag;
1551 u_long **cookies = ap->a_cookies;
1552 int *ncookies = ap->a_ncookies;
1553 struct thread *td = ap->a_uio->uio_td;
1558 MARK_ENTRY(CODA_READDIR_STATS);
1560 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1561 (void *)uiop->uio_iov->iov_base,
1563 (long long)uiop->uio_offset,
1564 uiop->uio_segflg)); )
1566 /* Check for readdir of control object. */
1567 if (IS_CTL_VP(vp)) {
1568 MARK_INT_FAIL(CODA_READDIR_STATS);
1573 /* If directory is not already open do an "internal open" on it. */
1574 int opened_internally = 0;
1575 if (cp->c_ovp == NULL) {
1576 opened_internally = 1;
1577 MARK_INT_GEN(CODA_OPEN_STATS);
1578 error = VOP_OPEN(vp, FREAD, cred, NULL, td);
1579 printf("coda_readdir: Internally Opening %p\n", vp);
1581 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1584 if (vp->v_type == VREG) {
1585 if (vp->v_object == NULL) {
1587 printf("coda_readdir: vnode %p has no VM object!\n", vp);
1591 if (error) return(error);
1594 /* Have UFS handle the call. */
1595 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)); )
1596 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1600 MARK_INT_FAIL(CODA_READDIR_STATS);
1602 MARK_INT_SAT(CODA_READDIR_STATS);
1604 /* Do an "internal close" if necessary. */
1605 if (opened_internally) {
1606 MARK_INT_GEN(CODA_CLOSE_STATS);
1607 VOP_CLOSE(vp, FREAD, td);
1615 * Convert from file system blocks to device blocks
1620 /* XXX on the global proc */
1621 struct vop_bmap_args *ap = v;
1625 cp = VTOC(ap->a_vp);
1629 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1630 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1631 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1636 printf("coda_bmap: no container\n");
1643 * I don't think the following two things are used anywhere, so I've
1644 * commented them out
1646 * struct buf *async_bufhead;
1647 * int async_daemon_count;
1650 coda_strategy(struct vop_strategy_args *ap __unused)
1652 printf("coda_strategy: called ???\n");
1657 coda_reclaim(void *v)
1660 struct vop_reclaim_args *ap = v;
1661 struct vnode *vp = ap->a_vp;
1662 struct cnode *cp = VTOC(vp);
1667 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1671 if (IS_UNMOUNTING(cp)) {
1673 if (VTOC(vp)->c_ovp) {
1674 if (IS_UNMOUNTING(cp))
1675 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1679 #ifdef OLD_DIAGNOSTIC
1680 if (vp->v_usecount != 0)
1681 print("coda_reclaim: pushing active %p\n", vp);
1682 if (VTOC(vp)->c_ovp) {
1683 panic("coda_reclaim: c_ovp not void");
1687 coda_free(VTOC(vp));
1696 struct vop_lock_args *ap = v;
1697 struct vnode *vp = ap->a_vp;
1698 struct cnode *cp = VTOC(vp);
1704 if (coda_lockdebug) {
1705 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1706 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1710 return (lockmgr(&vp->v_lock, ap->a_flags));
1712 return (debuglockmgr(&vp->v_lock, ap->a_flags,
1713 "coda_lock", vp->filename, vp->line));
1718 coda_unlock(void *v)
1721 struct vop_unlock_args *ap = v;
1722 struct vnode *vp = ap->a_vp;
1723 struct cnode *cp = VTOC(vp);
1728 if (coda_lockdebug) {
1729 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1730 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1733 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE));
1737 coda_islocked(void *v)
1740 struct vop_islocked_args *ap = v;
1743 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1746 /* How one looks up a vnode given a device/inode pair: */
1748 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1750 /* This is like VFS_VGET() or igetinode()! */
1754 if (!(mp = devtomp(dev))) {
1755 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1756 (u_long)dev2udev(dev)));
1760 /* XXX - ensure that nonzero-return means failure */
1761 error = VFS_VGET(mp,ino,vpp);
1763 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1764 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1771 print_vattr(struct vattr *attr)
1775 switch (attr->va_type) {
1809 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1810 typestr, (int)attr->va_mode, (int)attr->va_uid,
1811 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1813 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1814 (int)attr->va_fileid, (int)attr->va_nlink,
1816 (int)attr->va_blocksize,(int)attr->va_bytes));
1817 myprintf((" gen %ld flags %ld vaflags %d\n",
1818 attr->va_gen, attr->va_flags, attr->va_vaflags));
1819 myprintf((" atime sec %d nsec %d\n",
1820 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1821 myprintf((" mtime sec %d nsec %d\n",
1822 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1823 myprintf((" ctime sec %d nsec %d\n",
1824 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1827 /* How to print a ucred */
1829 print_cred(struct ucred *cred)
1834 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1836 for (i=0; i < cred->cr_ngroups; i++)
1837 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1843 * Return a vnode for the given fid.
1844 * If no cnode exists for this fid create one and put it
1845 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1846 * this fid is already in the table return it (ref count is
1847 * incremented by coda_find. The cnode will be flushed from the
1848 * table when coda_inactive calls coda_unsave.
1851 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1856 if ((cp = coda_find(fid)) == NULL) {
1862 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
1864 panic("coda: getnewvnode returned error %d\n", err);