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.3 2003/06/24 02:11:53 dillon Exp $
36 * Mach Operating System
37 * Copyright (c) 1990 Carnegie-Mellon University
38 * Copyright (c) 1989 Carnegie-Mellon University
39 * All rights reserved. The CMU software License Agreement specifies
40 * the terms and conditions for use and redistribution.
44 * This code was written for the Coda file system at Carnegie Mellon
45 * University. Contributers include David Steere, James Kistler, and
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
53 #include <sys/malloc.h>
54 #include <sys/mount.h>
55 #include <sys/errno.h>
58 #include <sys/fcntl.h>
60 #include <sys/namei.h>
61 #include <sys/ioccom.h>
62 #include <sys/select.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_extern.h>
67 #include <vm/vm_zone.h>
69 #include <coda/coda.h>
70 #include <coda/cnode.h>
71 #include <coda/coda_vnops.h>
72 #include <coda/coda_venus.h>
73 #include <coda/coda_opstats.h>
74 #include <coda/coda_subr.h>
75 #include <coda/coda_namecache.h>
76 #include <coda/coda_pioctl.h>
79 * These flags select various performance enhancements.
81 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
82 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
83 int coda_access_cache = 1; /* Set to handle some access checks directly */
85 /* structure to keep track of vfs calls */
87 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
89 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
90 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
91 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
92 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
94 /* What we are delaying for in printf */
95 int coda_printf_delay = 0; /* in microseconds */
96 int coda_vnop_print_entry = 0;
97 static int coda_lockdebug = 0;
99 /* Definition of the vfs operation vector */
102 * Some NetBSD details:
104 * coda_start is called at the end of the mount syscall.
105 * coda_init is called at boot time.
108 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
110 /* Definition of the vnode operation vector */
112 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
113 { &vop_default_desc, coda_vop_error },
114 { &vop_lookup_desc, coda_lookup }, /* lookup */
115 { &vop_create_desc, coda_create }, /* create */
116 { &vop_mknod_desc, coda_vop_error }, /* mknod */
117 { &vop_open_desc, coda_open }, /* open */
118 { &vop_close_desc, coda_close }, /* close */
119 { &vop_access_desc, coda_access }, /* access */
120 { &vop_getattr_desc, coda_getattr }, /* getattr */
121 { &vop_setattr_desc, coda_setattr }, /* setattr */
122 { &vop_read_desc, coda_read }, /* read */
123 { &vop_write_desc, coda_write }, /* write */
124 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
125 { &vop_mmap_desc, coda_vop_error }, /* mmap */
126 { &vop_fsync_desc, coda_fsync }, /* fsync */
127 { &vop_remove_desc, coda_remove }, /* remove */
128 { &vop_link_desc, coda_link }, /* link */
129 { &vop_rename_desc, coda_rename }, /* rename */
130 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
131 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
132 { &vop_symlink_desc, coda_symlink }, /* symlink */
133 { &vop_readdir_desc, coda_readdir }, /* readdir */
134 { &vop_readlink_desc, coda_readlink }, /* readlink */
135 { &vop_inactive_desc, coda_inactive }, /* inactive */
136 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
137 { &vop_lock_desc, coda_lock }, /* lock */
138 { &vop_unlock_desc, coda_unlock }, /* unlock */
139 { &vop_bmap_desc, coda_bmap }, /* bmap */
140 { &vop_strategy_desc, coda_strategy }, /* strategy */
141 { &vop_print_desc, coda_vop_error }, /* print */
142 { &vop_islocked_desc, coda_islocked }, /* islocked */
143 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
144 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
145 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
146 { &vop_lease_desc, coda_vop_nop }, /* lease */
147 { &vop_poll_desc, (vop_t *) vop_stdpoll },
148 { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
149 { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
150 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
151 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
152 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
156 we need to define these someday
157 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
158 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
159 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
160 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
161 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
164 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
165 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
166 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
168 { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
171 static struct vnodeopv_desc coda_vnodeop_opv_desc =
172 { &coda_vnodeop_p, coda_vnodeop_entries };
174 VNODEOP_SET(coda_vnodeop_opv_desc);
176 /* A generic panic: we were called with something we didn't define yet */
178 coda_vop_error(void *anon) {
179 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
181 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
182 (*desc)->vdesc_name));
184 panic("coda_vop_error");
189 /* A generic do-nothing. For lease_check, advlock */
191 coda_vop_nop(void *anon) {
192 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
195 myprintf(("Vnode operation %s called, but unsupported\n",
196 (*desc)->vdesc_name));
202 coda_vnodeopstats_init(void)
206 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
207 coda_vnodeopstats[i].opcode = i;
208 coda_vnodeopstats[i].entries = 0;
209 coda_vnodeopstats[i].sat_intrn = 0;
210 coda_vnodeopstats[i].unsat_intrn = 0;
211 coda_vnodeopstats[i].gen_intrn = 0;
217 * coda_open calls Venus to return the device, inode pair of the cache
218 * file holding the data. Using iget, coda_open finds the vnode of the
219 * cache file, and then opens it.
226 * NetBSD can pass the O_EXCL flag in mode, even though the check
227 * has already happened. Venus defensively assumes that if open
228 * is passed the EXCL, it must be a bug. We strip the flag here.
231 struct vop_open_args *ap = v;
232 register struct vnode **vpp = &(ap->a_vp);
233 struct cnode *cp = VTOC(*vpp);
234 int flag = ap->a_mode & (~O_EXCL);
235 struct ucred *cred = ap->a_cred;
236 struct proc *p = ap->a_p;
243 MARK_ENTRY(CODA_OPEN_STATS);
245 /* Check for open of control file. */
246 if (IS_CTL_VP(*vpp)) {
248 /* if (WRITEABLE(flag)) */
249 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
250 MARK_INT_FAIL(CODA_OPEN_STATS);
253 MARK_INT_SAT(CODA_OPEN_STATS);
257 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, p, &dev, &inode);
261 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
262 (u_long)dev2udev(dev), (u_long)inode,
266 /* Translate the <device, inode> pair for the cache file into
268 error = coda_grab_vnode(dev, inode, &vp);
272 /* We get the vnode back locked. Needs unlocked */
273 VOP_UNLOCK(vp, 0, p);
274 /* Keep a reference until the close comes in. */
277 /* Save the vnode pointer for the cache file. */
278 if (cp->c_ovp == NULL) {
282 panic("coda_open: cp->c_ovp != ITOV(ip)");
286 /* Flush the attribute cached if writing the file. */
289 cp->c_flags &= ~C_VATTR;
292 /* Save the <device, inode> pair for the cache file to speed
293 up subsequent page_read's. */
297 /* Open the cache file. */
298 error = VOP_OPEN(vp, flag, cred, p);
300 printf("coda_open: VOP_OPEN on container failed %d\n", error);
303 /* grab (above) does this when it calls newvnode unless it's in the cache*/
304 if (vp->v_type == VREG) {
305 error = vfs_object_create(vp, p, cred);
307 printf("coda_open: vfs_object_create() returns %d\n", error);
316 * Close the cache file used for I/O and notify Venus.
323 struct vop_close_args *ap = v;
324 struct vnode *vp = ap->a_vp;
325 struct cnode *cp = VTOC(vp);
326 int flag = ap->a_fflag;
327 struct ucred *cred = ap->a_cred;
328 struct proc *p = ap->a_p;
332 MARK_ENTRY(CODA_CLOSE_STATS);
334 /* Check for close of control file. */
336 MARK_INT_SAT(CODA_CLOSE_STATS);
340 if (IS_UNMOUNTING(cp)) {
343 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
344 vp->v_usecount, cp->c_ovp, vp, cp);
349 VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */
354 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
359 VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */
363 if (--cp->c_ocount == 0)
366 if (flag & FWRITE) /* file was opened for write */
369 error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, p);
372 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
380 struct vop_read_args *ap = v;
383 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
384 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp));
391 struct vop_write_args *ap = v;
394 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
395 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp));
399 coda_rdwr(vp, uiop, rw, ioflag, cred, p)
408 /* NOTE: container file operation!!! */
410 struct cnode *cp = VTOC(vp);
411 struct vnode *cfvp = cp->c_ovp;
412 int igot_internally = 0;
413 int opened_internally = 0;
416 MARK_ENTRY(CODA_RDWR_STATS);
418 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
419 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
420 (long long)uiop->uio_offset, uiop->uio_segflg)); )
422 /* Check for rdwr of control object. */
424 MARK_INT_FAIL(CODA_RDWR_STATS);
429 * If file is not already open this must be a page
430 * {read,write} request. Iget the cache file's inode
431 * pointer if we still have its <device, inode> pair.
432 * Otherwise, we must do an internal open to derive the
437 * If we're dumping core, do the internal open. Otherwise
438 * venus won't have the correct size of the core when
439 * it's completely written.
441 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
443 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
445 MARK_INT_FAIL(CODA_RDWR_STATS);
449 * We get the vnode back locked in both Mach and
450 * NetBSD. Needs unlocked
452 VOP_UNLOCK(cfvp, 0, p);
455 opened_internally = 1;
456 MARK_INT_GEN(CODA_OPEN_STATS);
457 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
459 printf("coda_rdwr: Internally Opening %p\n", vp);
461 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
464 if (vp->v_type == VREG) {
465 error = vfs_object_create(vp, p, cred);
467 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
472 MARK_INT_FAIL(CODA_RDWR_STATS);
479 /* Have UFS handle the call. */
480 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
481 cp->c_fid.Volume, cp->c_fid.Vnode,
482 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
485 if (rw == UIO_READ) {
486 error = VOP_READ(cfvp, uiop, ioflag, cred);
488 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
489 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
493 if (VOP_GETATTR(cfvp, &attr, cred, p) == 0) {
494 vnode_pager_setsize(vp, attr.va_size);
500 MARK_INT_FAIL(CODA_RDWR_STATS);
502 MARK_INT_SAT(CODA_RDWR_STATS);
504 /* Do an internal close if necessary. */
505 if (opened_internally) {
506 MARK_INT_GEN(CODA_CLOSE_STATS);
507 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, p);
510 /* Invalidate cached attributes if writing. */
512 cp->c_flags &= ~C_VATTR;
521 struct vop_ioctl_args *ap = v;
522 struct vnode *vp = ap->a_vp;
523 int com = ap->a_command;
524 caddr_t data = ap->a_data;
525 int flag = ap->a_fflag;
526 struct ucred *cred = ap->a_cred;
527 struct proc *p = ap->a_p;
531 struct nameidata ndp;
532 struct PioctlData *iap = (struct PioctlData *)data;
534 MARK_ENTRY(CODA_IOCTL_STATS);
536 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
538 /* Don't check for operation on a dying object, for ctlvp it
541 /* Must be control object to succeed. */
542 if (!IS_CTL_VP(vp)) {
543 MARK_INT_FAIL(CODA_IOCTL_STATS);
544 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
547 /* Look up the pathname. */
549 /* Should we use the name cache here? It would get it from
550 lookupname sooner or later anyway, right? */
552 NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, p);
557 MARK_INT_FAIL(CODA_IOCTL_STATS);
558 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
564 * Make sure this is a coda style cnode, but it may be a
567 if (tvp->v_op != coda_vnodeop_p) {
569 NDFREE(&ndp, NDF_ONLY_PNBUF);
570 MARK_INT_FAIL(CODA_IOCTL_STATS);
571 CODADEBUG(CODA_IOCTL,
572 myprintf(("coda_ioctl error: %s not a coda object\n",
577 if (iap->vi.in_size > VC_MAXDATASIZE) {
581 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, p);
584 MARK_INT_FAIL(CODA_IOCTL_STATS);
586 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
589 NDFREE(&ndp, NDF_ONLY_PNBUF);
594 * To reduce the cost of a user-level venus;we cache attributes in
595 * the kernel. Each cnode has storage allocated for an attribute. If
596 * c_vattr is valid, return a reference to it. Otherwise, get the
597 * attributes from venus and store them in the cnode. There is some
598 * question if this method is a security leak. But I think that in
599 * order to make this call, the user must have done a lookup and
600 * opened the file, and therefore should already have access.
607 struct vop_getattr_args *ap = v;
608 struct vnode *vp = ap->a_vp;
609 struct cnode *cp = VTOC(vp);
610 struct vattr *vap = ap->a_vap;
611 struct ucred *cred = ap->a_cred;
612 struct proc *p = ap->a_p;
616 MARK_ENTRY(CODA_GETATTR_STATS);
618 if (IS_UNMOUNTING(cp))
621 /* Check for getattr of control object. */
623 MARK_INT_FAIL(CODA_GETATTR_STATS);
627 /* Check to see if the attributes have already been cached */
628 if (VALID_VATTR(cp)) {
629 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
632 cp->c_fid.Unique));});
633 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
634 print_vattr(&cp->c_vattr); );
637 MARK_INT_SAT(CODA_GETATTR_STATS);
641 error = venus_getattr(vtomi(vp), &cp->c_fid, cred, p, vap);
644 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
650 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
653 { int size = vap->va_size;
654 struct vnode *convp = cp->c_ovp;
655 if (convp != (struct vnode *)0) {
656 vnode_pager_setsize(convp, size);
659 /* If not open for write, store attributes in cnode */
660 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
662 cp->c_flags |= C_VATTR;
674 struct vop_setattr_args *ap = v;
675 register struct vnode *vp = ap->a_vp;
676 struct cnode *cp = VTOC(vp);
677 register struct vattr *vap = ap->a_vap;
678 struct ucred *cred = ap->a_cred;
679 struct proc *p = ap->a_p;
683 MARK_ENTRY(CODA_SETATTR_STATS);
685 /* Check for setattr of control object. */
687 MARK_INT_FAIL(CODA_SETATTR_STATS);
691 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
694 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, p);
697 cp->c_flags &= ~C_VATTR;
699 { int size = vap->va_size;
700 struct vnode *convp = cp->c_ovp;
701 if (size != VNOVAL && convp != (struct vnode *)0) {
702 vnode_pager_setsize(convp, size);
705 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
714 struct vop_access_args *ap = v;
715 struct vnode *vp = ap->a_vp;
716 struct cnode *cp = VTOC(vp);
717 int mode = ap->a_mode;
718 struct ucred *cred = ap->a_cred;
719 struct proc *p = ap->a_p;
723 MARK_ENTRY(CODA_ACCESS_STATS);
725 /* Check for access of control object. Only read access is
728 /* bogus hack - all will be marked as successes */
729 MARK_INT_SAT(CODA_ACCESS_STATS);
730 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
735 * if the file is a directory, and we are checking exec (eg lookup)
736 * access, and the file is in the namecache, then the user must have
737 * lookup access to it.
739 if (coda_access_cache) {
740 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
741 if (coda_nc_lookup(cp, ".", 1, cred)) {
742 MARK_INT_SAT(CODA_ACCESS_STATS);
743 return(0); /* it was in the cache */
748 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, p);
758 struct vop_readlink_args *ap = v;
759 struct vnode *vp = ap->a_vp;
760 struct cnode *cp = VTOC(vp);
761 struct uio *uiop = ap->a_uio;
762 struct ucred *cred = ap->a_cred;
763 struct proc *p = ap->a_uio->uio_procp;
769 MARK_ENTRY(CODA_READLINK_STATS);
771 /* Check for readlink of control object. */
773 MARK_INT_FAIL(CODA_READLINK_STATS);
777 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
778 uiop->uio_rw = UIO_READ;
779 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
781 MARK_INT_FAIL(CODA_READLINK_STATS);
783 MARK_INT_SAT(CODA_READLINK_STATS);
787 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, p, &str, &len);
790 uiop->uio_rw = UIO_READ;
791 error = uiomove(str, len, uiop);
793 if (coda_symlink_cache) {
796 cp->c_flags |= C_SYMLINK;
801 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
810 struct vop_fsync_args *ap = v;
811 struct vnode *vp = ap->a_vp;
812 struct cnode *cp = VTOC(vp);
813 struct ucred *cred = ap->a_cred;
814 struct proc *p = ap->a_p;
816 struct vnode *convp = cp->c_ovp;
819 MARK_ENTRY(CODA_FSYNC_STATS);
821 /* Check for fsync on an unmounting object */
822 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
823 * after an unmount has been initiated. This is a Bad Thing,
824 * which we have to avoid. Not a legitimate failure for stats.
826 if (IS_UNMOUNTING(cp)) {
830 /* Check for fsync of control object. */
832 MARK_INT_SAT(CODA_FSYNC_STATS);
837 VOP_FSYNC(convp, cred, MNT_WAIT, p);
840 * We see fsyncs with usecount == 1 then usecount == 0.
841 * For now we ignore them.
844 if (!vp->v_usecount) {
845 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
846 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
851 * We can expect fsync on any vnode at all if venus is pruging it.
852 * Venus can't very well answer the fsync request, now can it?
853 * Hopefully, it won't have to, because hopefully, venus preserves
854 * the (possibly untrue) invariant that it never purges an open
857 if (cp->c_flags & C_PURGING) {
863 error = venus_fsync(vtomi(vp), &cp->c_fid, cred, p);
865 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
873 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
874 have a proc pointer. Oops. */
876 struct vop_inactive_args *ap = v;
877 struct vnode *vp = ap->a_vp;
878 struct cnode *cp = VTOC(vp);
879 struct ucred *cred __attribute__((unused)) = NULL;
880 struct proc *p __attribute__((unused)) = curproc;
884 /* We don't need to send inactive to venus - DCS */
885 MARK_ENTRY(CODA_INACTIVE_STATS);
888 MARK_INT_SAT(CODA_INACTIVE_STATS);
892 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
893 cp->c_fid.Volume, cp->c_fid.Vnode,
894 cp->c_fid.Unique, vp->v_mount));)
896 /* If an array has been allocated to hold the symlink, deallocate it */
897 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
898 if (cp->c_symlink == NULL)
899 panic("coda_inactive: null symlink pointer in cnode");
901 CODA_FREE(cp->c_symlink, cp->c_symlen);
902 cp->c_flags &= ~C_SYMLINK;
906 /* Remove it from the table so it can't be found. */
908 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
909 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
910 panic("badness in coda_inactive\n");
913 if (IS_UNMOUNTING(cp)) {
915 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
916 if (cp->c_ovp != NULL)
917 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
918 vp->v_usecount, vp, cp);
920 lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, p);
922 #ifdef OLD_DIAGNOSTIC
923 if (CTOV(cp)->v_usecount) {
924 panic("coda_inactive: nonzero reference count");
926 if (cp->c_ovp != NULL) {
927 panic("coda_inactive: cp->ovp != NULL");
930 VOP_UNLOCK(vp, 0, p);
934 MARK_INT_SAT(CODA_INACTIVE_STATS);
939 * Remote file system operations having to do with directory manipulation.
943 * It appears that in NetBSD, lookup is supposed to return the vnode locked
950 struct vop_lookup_args *ap = v;
951 struct vnode *dvp = ap->a_dvp;
952 struct cnode *dcp = VTOC(dvp);
953 struct vnode **vpp = ap->a_vpp;
955 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
956 * of the string to xlate, and that we must try to get at least
957 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
960 struct componentname *cnp = ap->a_cnp;
961 struct ucred *cred = cnp->cn_cred;
962 struct proc *p = cnp->cn_proc;
965 const char *nm = cnp->cn_nameptr;
966 int len = cnp->cn_namelen;
971 MARK_ENTRY(CODA_LOOKUP_STATS);
973 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
974 nm, dcp->c_fid.Volume,
975 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
977 /* Check for lookup of control object. */
978 if (IS_CTL_NAME(dvp, nm, len)) {
981 MARK_INT_SAT(CODA_LOOKUP_STATS);
985 if (len+1 > CODA_MAXNAMLEN) {
986 MARK_INT_FAIL(CODA_LOOKUP_STATS);
987 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
988 dcp->c_fid.Volume, dcp->c_fid.Vnode,
989 dcp->c_fid.Unique, nm)););
990 *vpp = (struct vnode *)0;
994 /* First try to look the file up in the cfs name cache */
995 /* lock the parent vnode? */
996 cp = coda_nc_lookup(dcp, nm, len, cred);
1000 CODADEBUG(CODA_LOOKUP,
1001 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
1004 /* The name wasn't cached, so we need to contact Venus */
1005 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, p, &VFid, &vtype);
1008 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1009 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1010 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1011 *vpp = (struct vnode *)0;
1013 MARK_INT_SAT(CODA_LOOKUP_STATS);
1014 CODADEBUG(CODA_LOOKUP,
1015 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1016 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1019 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1022 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1023 /* And don't enter a new vnode for an invalid one! */
1024 if (!(vtype & CODA_NOCACHE))
1025 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1031 * If we are creating, and this was the last name to be looked up,
1032 * and the error was ENOENT, then there really shouldn't be an
1033 * error and we can make the leaf NULL and return success. Since
1034 * this is supposed to work under Mach as well as NetBSD, we're
1035 * leaving this fn wrapped. We also must tell lookup/namei that
1036 * we need to save the last component of the name. (Create will
1037 * have to free the name buffer later...lucky us...)
1039 if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
1040 && (cnp->cn_flags & ISLASTCN)
1041 && (error == ENOENT))
1043 error = EJUSTRETURN;
1044 cnp->cn_flags |= SAVENAME;
1049 * If we are removing, and we are at the last element, and we
1050 * found it, then we need to keep the name around so that the
1051 * removal will go ahead as planned. Unfortunately, this will
1052 * probably also lock the to-be-removed vnode, which may or may
1053 * not be a good idea. I'll have to look at the bits of
1054 * coda_remove to make sure. We'll only save the name if we did in
1055 * fact find the name, otherwise coda_remove won't have a chance
1056 * to free the pathname.
1058 if ((cnp->cn_nameiop == DELETE)
1059 && (cnp->cn_flags & ISLASTCN)
1062 cnp->cn_flags |= SAVENAME;
1066 * If the lookup went well, we need to (potentially?) unlock the
1067 * parent, and lock the child. We are only responsible for
1068 * checking to see if the parent is supposed to be unlocked before
1069 * we return. We must always lock the child (provided there is
1070 * one, and (the parent isn't locked or it isn't the same as the
1071 * parent.) Simple, huh? We can never leave the parent locked unless
1074 if (!error || (error == EJUSTRETURN)) {
1075 if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
1076 if ((error = VOP_UNLOCK(dvp, 0, p))) {
1080 * The parent is unlocked. As long as there is a child,
1081 * lock it without bothering to check anything else.
1084 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1085 printf("coda_lookup: ");
1086 panic("unlocked parent but couldn't lock child");
1090 /* The parent is locked, and may be the same as the child */
1091 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1092 /* Different, go ahead and lock it. */
1093 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1094 printf("coda_lookup: ");
1095 panic("unlocked parent but couldn't lock child");
1100 /* If the lookup failed, we need to ensure that the leaf is NULL */
1101 /* Don't change any locking? */
1113 struct vop_create_args *ap = v;
1114 struct vnode *dvp = ap->a_dvp;
1115 struct cnode *dcp = VTOC(dvp);
1116 struct vattr *va = ap->a_vap;
1118 int mode = ap->a_vap->va_mode;
1119 struct vnode **vpp = ap->a_vpp;
1120 struct componentname *cnp = ap->a_cnp;
1121 struct ucred *cred = cnp->cn_cred;
1122 struct proc *p = cnp->cn_proc;
1126 const char *nm = cnp->cn_nameptr;
1127 int len = cnp->cn_namelen;
1131 MARK_ENTRY(CODA_CREATE_STATS);
1133 /* All creates are exclusive XXX */
1134 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1136 /* Check for create of control object. */
1137 if (IS_CTL_NAME(dvp, nm, len)) {
1138 *vpp = (struct vnode *)0;
1139 MARK_INT_FAIL(CODA_CREATE_STATS);
1143 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, p, &VFid, &attr);
1147 /* If this is an exclusive create, panic if the file already exists. */
1148 /* Venus should have detected the file and reported EEXIST. */
1150 if ((exclusive == 1) &&
1151 (coda_find(&VFid) != NULL))
1152 panic("cnode existed for newly created file!");
1154 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1157 /* Update va to reflect the new attributes. */
1160 /* Update the attribute cache and mark it as valid */
1161 if (coda_attr_cache) {
1162 VTOC(*vpp)->c_vattr = attr;
1163 VTOC(*vpp)->c_flags |= C_VATTR;
1166 /* Invalidate the parent's attr cache, the modification time has changed */
1167 VTOC(dvp)->c_flags &= ~C_VATTR;
1169 /* enter the new vnode in the Name Cache */
1170 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1172 CODADEBUG(CODA_CREATE,
1173 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1174 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1176 *vpp = (struct vnode *)0;
1177 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1181 if (cnp->cn_flags & LOCKLEAF) {
1182 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1183 printf("coda_create: ");
1184 panic("unlocked parent but couldn't lock child");
1187 #ifdef OLD_DIAGNOSTIC
1189 printf("coda_create: LOCKLEAF not set!\n");
1201 struct vop_remove_args *ap = v;
1202 struct vnode *dvp = ap->a_dvp;
1203 struct cnode *cp = VTOC(dvp);
1204 struct componentname *cnp = ap->a_cnp;
1205 struct ucred *cred = cnp->cn_cred;
1206 struct proc *p = cnp->cn_proc;
1209 const char *nm = cnp->cn_nameptr;
1210 int len = cnp->cn_namelen;
1213 MARK_ENTRY(CODA_REMOVE_STATS);
1215 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1216 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1217 cp->c_fid.Unique)););
1219 /* Remove the file's entry from the CODA Name Cache */
1220 /* We're being conservative here, it might be that this person
1221 * doesn't really have sufficient access to delete the file
1222 * but we feel zapping the entry won't really hurt anyone -- dcs
1224 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1225 * exist, and one is removed, the link count on the other will be
1226 * off by 1. We could either invalidate the attrs if cached, or
1227 * fix them. I'll try to fix them. DCS 11/8/94
1229 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1231 if (VALID_VATTR(tp)) { /* If attrs are cached */
1232 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1233 tp->c_vattr.va_nlink--;
1237 coda_nc_zapfile(VTOC(dvp), nm, len);
1238 /* No need to flush it if it doesn't exist! */
1240 /* Invalidate the parent's attr cache, the modification time has changed */
1241 VTOC(dvp)->c_flags &= ~C_VATTR;
1243 /* Check for remove of control object. */
1244 if (IS_CTL_NAME(dvp, nm, len)) {
1245 MARK_INT_FAIL(CODA_REMOVE_STATS);
1249 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, p);
1251 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1261 struct vop_link_args *ap = v;
1262 struct vnode *vp = ap->a_vp;
1263 struct cnode *cp = VTOC(vp);
1264 struct vnode *tdvp = ap->a_tdvp;
1265 struct cnode *tdcp = VTOC(tdvp);
1266 struct componentname *cnp = ap->a_cnp;
1267 struct ucred *cred = cnp->cn_cred;
1268 struct proc *p = cnp->cn_proc;
1271 const char *nm = cnp->cn_nameptr;
1272 int len = cnp->cn_namelen;
1274 MARK_ENTRY(CODA_LINK_STATS);
1276 if (codadebug & CODADBGMSK(CODA_LINK)) {
1278 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1279 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1280 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1281 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1284 if (codadebug & CODADBGMSK(CODA_LINK)) {
1285 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1286 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1287 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1288 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1292 /* Check for link to/from control object. */
1293 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1294 MARK_INT_FAIL(CODA_LINK_STATS);
1298 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, p);
1300 /* Invalidate the parent's attr cache, the modification time has changed */
1301 VTOC(tdvp)->c_flags &= ~C_VATTR;
1302 VTOC(vp)->c_flags &= ~C_VATTR;
1304 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1314 struct vop_rename_args *ap = v;
1315 struct vnode *odvp = ap->a_fdvp;
1316 struct cnode *odcp = VTOC(odvp);
1317 struct componentname *fcnp = ap->a_fcnp;
1318 struct vnode *ndvp = ap->a_tdvp;
1319 struct cnode *ndcp = VTOC(ndvp);
1320 struct componentname *tcnp = ap->a_tcnp;
1321 struct ucred *cred = fcnp->cn_cred;
1322 struct proc *p = fcnp->cn_proc;
1325 const char *fnm = fcnp->cn_nameptr;
1326 int flen = fcnp->cn_namelen;
1327 const char *tnm = tcnp->cn_nameptr;
1328 int tlen = tcnp->cn_namelen;
1330 MARK_ENTRY(CODA_RENAME_STATS);
1332 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1333 This could be Bad. XXX */
1334 #ifdef OLD_DIAGNOSTIC
1335 if ((fcnp->cn_cred != tcnp->cn_cred)
1336 || (fcnp->cn_proc != tcnp->cn_proc))
1338 panic("coda_rename: component names don't agree");
1342 /* Check for rename involving control object. */
1343 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1344 MARK_INT_FAIL(CODA_RENAME_STATS);
1348 /* Problem with moving directories -- need to flush entry for .. */
1350 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1352 struct vnode *ovp = CTOV(ovcp);
1354 (ovp->v_type == VDIR)) /* If it's a directory */
1355 coda_nc_zapfile(VTOC(ovp),"..", 2);
1359 /* Remove the entries for both source and target files */
1360 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1361 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1363 /* Invalidate the parent's attr cache, the modification time has changed */
1364 VTOC(odvp)->c_flags &= ~C_VATTR;
1365 VTOC(ndvp)->c_flags &= ~C_VATTR;
1367 if (flen+1 > CODA_MAXNAMLEN) {
1368 MARK_INT_FAIL(CODA_RENAME_STATS);
1373 if (tlen+1 > CODA_MAXNAMLEN) {
1374 MARK_INT_FAIL(CODA_RENAME_STATS);
1379 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, p);
1382 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1383 /* XXX - do we need to call cache pureg on the moved vnode? */
1384 cache_purge(ap->a_fvp);
1386 /* It seems to be incumbent on us to drop locks on all four vnodes */
1387 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1393 if (ap->a_tvp == ndvp) {
1409 struct vop_mkdir_args *ap = v;
1410 struct vnode *dvp = ap->a_dvp;
1411 struct cnode *dcp = VTOC(dvp);
1412 struct componentname *cnp = ap->a_cnp;
1413 register struct vattr *va = ap->a_vap;
1414 struct vnode **vpp = ap->a_vpp;
1415 struct ucred *cred = cnp->cn_cred;
1416 struct proc *p = cnp->cn_proc;
1419 const char *nm = cnp->cn_nameptr;
1420 int len = cnp->cn_namelen;
1425 MARK_ENTRY(CODA_MKDIR_STATS);
1427 /* Check for mkdir of target object. */
1428 if (IS_CTL_NAME(dvp, nm, len)) {
1429 *vpp = (struct vnode *)0;
1430 MARK_INT_FAIL(CODA_MKDIR_STATS);
1434 if (len+1 > CODA_MAXNAMLEN) {
1435 *vpp = (struct vnode *)0;
1436 MARK_INT_FAIL(CODA_MKDIR_STATS);
1440 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, p, &VFid, &ova);
1443 if (coda_find(&VFid) != NULL)
1444 panic("cnode existed for newly created directory!");
1447 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1450 /* enter the new vnode in the Name Cache */
1451 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1453 /* as a side effect, enter "." and ".." for the directory */
1454 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1455 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1457 if (coda_attr_cache) {
1458 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1459 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1462 /* Invalidate the parent's attr cache, the modification time has changed */
1463 VTOC(dvp)->c_flags &= ~C_VATTR;
1465 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1466 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1468 *vpp = (struct vnode *)0;
1469 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1480 struct vop_rmdir_args *ap = v;
1481 struct vnode *dvp = ap->a_dvp;
1482 struct cnode *dcp = VTOC(dvp);
1483 struct componentname *cnp = ap->a_cnp;
1484 struct ucred *cred = cnp->cn_cred;
1485 struct proc *p = cnp->cn_proc;
1488 const char *nm = cnp->cn_nameptr;
1489 int len = cnp->cn_namelen;
1492 MARK_ENTRY(CODA_RMDIR_STATS);
1494 /* Check for rmdir of control object. */
1495 if (IS_CTL_NAME(dvp, nm, len)) {
1496 MARK_INT_FAIL(CODA_RMDIR_STATS);
1500 /* We're being conservative here, it might be that this person
1501 * doesn't really have sufficient access to delete the file
1502 * but we feel zapping the entry won't really hurt anyone -- dcs
1505 * As a side effect of the rmdir, remove any entries for children of
1506 * the directory, especially "." and "..".
1508 cp = coda_nc_lookup(dcp, nm, len, cred);
1509 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1511 /* Remove the file's entry from the CODA Name Cache */
1512 coda_nc_zapfile(dcp, nm, len);
1514 /* Invalidate the parent's attr cache, the modification time has changed */
1515 dcp->c_flags &= ~C_VATTR;
1517 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, p);
1519 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1529 struct vop_symlink_args *ap = v;
1530 struct vnode *tdvp = ap->a_dvp;
1531 struct cnode *tdcp = VTOC(tdvp);
1532 struct componentname *cnp = ap->a_cnp;
1533 struct vattr *tva = ap->a_vap;
1534 char *path = ap->a_target;
1535 struct ucred *cred = cnp->cn_cred;
1536 struct proc *p = cnp->cn_proc;
1537 struct vnode **vpp = ap->a_vpp;
1541 * XXX I'm assuming the following things about coda_symlink's
1543 * t(foo) is the new name/parent/etc being created.
1544 * lname is the contents of the new symlink.
1546 char *nm = cnp->cn_nameptr;
1547 int len = cnp->cn_namelen;
1548 int plen = strlen(path);
1551 * Here's the strategy for the moment: perform the symlink, then
1552 * do a lookup to grab the resulting vnode. I know this requires
1553 * two communications with Venus for a new sybolic link, but
1554 * that's the way the ball bounces. I don't yet want to change
1555 * the way the Mach symlink works. When Mach support is
1556 * deprecated, we should change symlink so that the common case
1557 * returns the resultant vnode in a vpp argument.
1560 MARK_ENTRY(CODA_SYMLINK_STATS);
1562 /* Check for symlink of control object. */
1563 if (IS_CTL_NAME(tdvp, nm, len)) {
1564 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1568 if (plen+1 > CODA_MAXPATHLEN) {
1569 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1573 if (len+1 > CODA_MAXNAMLEN) {
1574 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1579 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, p);
1581 /* Invalidate the parent's attr cache, the modification time has changed */
1582 tdcp->c_flags &= ~C_VATTR;
1585 error = VOP_LOOKUP(tdvp, vpp, cnp);
1588 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1593 * Read directory entries.
1600 struct vop_readdir_args *ap = v;
1601 struct vnode *vp = ap->a_vp;
1602 struct cnode *cp = VTOC(vp);
1603 register struct uio *uiop = ap->a_uio;
1604 struct ucred *cred = ap->a_cred;
1605 int *eofflag = ap->a_eofflag;
1606 u_long **cookies = ap->a_cookies;
1607 int *ncookies = ap->a_ncookies;
1608 struct proc *p = ap->a_uio->uio_procp;
1613 MARK_ENTRY(CODA_READDIR_STATS);
1615 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1616 (void *)uiop->uio_iov->iov_base,
1618 (long long)uiop->uio_offset,
1619 uiop->uio_segflg)); )
1621 /* Check for readdir of control object. */
1622 if (IS_CTL_VP(vp)) {
1623 MARK_INT_FAIL(CODA_READDIR_STATS);
1628 /* If directory is not already open do an "internal open" on it. */
1629 int opened_internally = 0;
1630 if (cp->c_ovp == NULL) {
1631 opened_internally = 1;
1632 MARK_INT_GEN(CODA_OPEN_STATS);
1633 error = VOP_OPEN(vp, FREAD, cred, p);
1634 printf("coda_readdir: Internally Opening %p\n", vp);
1636 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1639 if (vp->v_type == VREG) {
1640 error = vfs_object_create(vp, p, cred);
1642 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1646 if (error) return(error);
1649 /* Have UFS handle the call. */
1650 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)); )
1651 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1655 MARK_INT_FAIL(CODA_READDIR_STATS);
1657 MARK_INT_SAT(CODA_READDIR_STATS);
1659 /* Do an "internal close" if necessary. */
1660 if (opened_internally) {
1661 MARK_INT_GEN(CODA_CLOSE_STATS);
1662 (void)VOP_CLOSE(vp, FREAD, cred, p);
1670 * Convert from file system blocks to device blocks
1676 /* XXX on the global proc */
1678 struct vop_bmap_args *ap = v;
1679 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1680 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1681 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1682 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1683 struct proc *p __attribute__((unused)) = curproc;
1693 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1695 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1696 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1701 printf("coda_bmap: no container\n");
1708 * I don't think the following two things are used anywhere, so I've
1709 * commented them out
1711 * struct buf *async_bufhead;
1712 * int async_daemon_count;
1719 struct vop_strategy_args *ap = v;
1720 register struct buf *bp __attribute__((unused)) = ap->a_bp;
1721 struct proc *p __attribute__((unused)) = curproc;
1725 printf("coda_strategy: called ???\n");
1734 struct vop_reclaim_args *ap = v;
1735 struct vnode *vp = ap->a_vp;
1736 struct cnode *cp = VTOC(vp);
1741 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1745 if (IS_UNMOUNTING(cp)) {
1747 if (VTOC(vp)->c_ovp) {
1748 if (IS_UNMOUNTING(cp))
1749 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1753 #ifdef OLD_DIAGNOSTIC
1754 if (vp->v_usecount != 0)
1755 print("coda_reclaim: pushing active %p\n", vp);
1756 if (VTOC(vp)->c_ovp) {
1757 panic("coda_reclaim: c_ovp not void");
1762 coda_free(VTOC(vp));
1772 struct vop_lock_args *ap = v;
1773 struct vnode *vp = ap->a_vp;
1774 struct cnode *cp = VTOC(vp);
1775 struct proc *p = ap->a_p;
1781 if (coda_lockdebug) {
1782 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1783 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1787 return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p));
1789 return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p,
1790 "coda_lock", vp->filename, vp->line));
1799 struct vop_unlock_args *ap = v;
1800 struct vnode *vp = ap->a_vp;
1801 struct cnode *cp = VTOC(vp);
1802 struct proc *p = ap->a_p;
1807 if (coda_lockdebug) {
1808 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1809 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1812 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, p));
1820 struct vop_islocked_args *ap = v;
1821 struct cnode *cp = VTOC(ap->a_vp);
1824 return (lockstatus(&cp->c_lock, ap->a_p));
1827 /* How one looks up a vnode given a device/inode pair: */
1829 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1831 /* This is like VFS_VGET() or igetinode()! */
1835 if (!(mp = devtomp(dev))) {
1836 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1837 (u_long)dev2udev(dev)));
1841 /* XXX - ensure that nonzero-return means failure */
1842 error = VFS_VGET(mp,ino,vpp);
1844 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1845 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1857 switch (attr->va_type) {
1891 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1892 typestr, (int)attr->va_mode, (int)attr->va_uid,
1893 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1895 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1896 (int)attr->va_fileid, (int)attr->va_nlink,
1898 (int)attr->va_blocksize,(int)attr->va_bytes));
1899 myprintf((" gen %ld flags %ld vaflags %d\n",
1900 attr->va_gen, attr->va_flags, attr->va_vaflags));
1901 myprintf((" atime sec %d nsec %d\n",
1902 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1903 myprintf((" mtime sec %d nsec %d\n",
1904 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1905 myprintf((" ctime sec %d nsec %d\n",
1906 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1909 /* How to print a ucred */
1917 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1919 for (i=0; i < cred->cr_ngroups; i++)
1920 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1926 * Return a vnode for the given fid.
1927 * If no cnode exists for this fid create one and put it
1928 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1929 * this fid is already in the table return it (ref count is
1930 * incremented by coda_find. The cnode will be flushed from the
1931 * table when coda_inactive calls coda_unsave.
1934 make_coda_node(fid, vfsp, type)
1935 ViceFid *fid; struct mount *vfsp; short type;
1940 if ((cp = coda_find(fid)) == NULL) {
1944 lockinit(&cp->c_lock, PINOD, "cnode", 0, 0);
1947 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1949 panic("coda: getnewvnode returned error %d\n", err);