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 $
35 * Mach Operating System
36 * Copyright (c) 1990 Carnegie-Mellon University
37 * Copyright (c) 1989 Carnegie-Mellon University
38 * All rights reserved. The CMU software License Agreement specifies
39 * the terms and conditions for use and redistribution.
43 * This code was written for the Coda filesystem at Carnegie Mellon
44 * University. Contributers include David Steere, James Kistler, and
48 #include <sys/param.h>
49 #include <sys/systm.h>
51 #include <sys/errno.h>
52 #include <sys/fcntl.h>
53 #include <sys/kernel.h>
55 #include <sys/malloc.h>
56 #include <sys/file.h> /* Must come after sys/malloc.h */
57 #include <sys/mount.h>
58 #include <sys/mutex.h>
59 #include <sys/namei.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_extern.h>
67 #include <coda/coda.h>
68 #include <coda/cnode.h>
69 #include <coda/coda_vnops.h>
70 #include <coda/coda_venus.h>
71 #include <coda/coda_opstats.h>
72 #include <coda/coda_subr.h>
73 #include <coda/coda_namecache.h>
74 #include <coda/coda_pioctl.h>
77 * These flags select various performance enhancements.
79 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
80 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
81 int coda_access_cache = 1; /* Set to handle some access checks directly */
83 /* structure to keep track of vfs calls */
85 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
87 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
88 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
89 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
90 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
92 /* What we are delaying for in printf */
93 int coda_printf_delay = 0; /* in microseconds */
94 int coda_vnop_print_entry = 0;
95 static int coda_lockdebug = 0;
97 /* Definition of the vfs operation vector */
98 static int (**coda_vnodeop_p)(void *);
101 * Some NetBSD details:
103 * coda_start is called at the end of the mount syscall.
104 * coda_init is called at boot time.
107 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
109 /* Definition of the vnode operation vector */
111 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
112 { &vop_default_desc, coda_vop_error },
113 { &vop_lookup_desc, coda_lookup }, /* lookup */
114 { &vop_create_desc, coda_create }, /* create */
115 { &vop_mknod_desc, coda_vop_error }, /* mknod */
116 { &vop_open_desc, coda_open }, /* open */
117 { &vop_close_desc, coda_close }, /* close */
118 { &vop_access_desc, coda_access }, /* access */
119 { &vop_getattr_desc, coda_getattr }, /* getattr */
120 { &vop_setattr_desc, coda_setattr }, /* setattr */
121 { &vop_read_desc, coda_read }, /* read */
122 { &vop_write_desc, coda_write }, /* write */
123 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
124 { &vop_fsync_desc, coda_fsync }, /* fsync */
125 { &vop_remove_desc, coda_remove }, /* remove */
126 { &vop_link_desc, coda_link }, /* link */
127 { &vop_rename_desc, coda_rename }, /* rename */
128 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
129 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
130 { &vop_symlink_desc, coda_symlink }, /* symlink */
131 { &vop_readdir_desc, coda_readdir }, /* readdir */
132 { &vop_readlink_desc, coda_readlink }, /* readlink */
133 { &vop_inactive_desc, coda_inactive }, /* inactive */
134 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
135 { &vop_lock_desc, coda_lock }, /* lock */
136 { &vop_unlock_desc, coda_unlock }, /* unlock */
137 { &vop_bmap_desc, coda_bmap }, /* bmap */
138 { &vop_strategy_desc, coda_strategy }, /* strategy */
139 { &vop_print_desc, coda_vop_error }, /* print */
140 { &vop_islocked_desc, coda_islocked }, /* islocked */
141 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
142 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
143 { &vop_lease_desc, coda_vop_nop }, /* lease */
144 { &vop_poll_desc, (vop_t *) vop_stdpoll },
145 { &vop_getpages_desc, (vop_t*)vop_stdgetpages }, /* pager intf.*/
146 { &vop_putpages_desc, (vop_t*)vop_stdputpages }, /* pager intf.*/
147 { &vop_createvobject_desc, (vop_t*)vop_stdcreatevobject },
148 { &vop_destroyvobject_desc, (vop_t*)vop_stddestroyvobject },
149 { &vop_getvobject_desc, (vop_t*)vop_stdgetvobject },
153 we need to define these someday
154 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
155 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
156 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
157 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
158 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
161 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
162 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
163 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
166 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
167 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
168 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
169 { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount },
170 { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
173 static struct vnodeopv_desc coda_vnodeop_opv_desc =
174 { &coda_vnodeop_p, coda_vnodeop_entries };
176 VNODEOP_SET(coda_vnodeop_opv_desc);
178 /* A generic panic: we were called with something we didn't define yet */
180 coda_vop_error(void *anon) {
181 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
183 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
184 (*desc)->vdesc_name));
186 panic("coda_vop_error");
191 /* A generic do-nothing. For lease_check, advlock */
193 coda_vop_nop(void *anon) {
194 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
197 myprintf(("Vnode operation %s called, but unsupported\n",
198 (*desc)->vdesc_name));
204 coda_vnodeopstats_init(void)
208 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
209 coda_vnodeopstats[i].opcode = i;
210 coda_vnodeopstats[i].entries = 0;
211 coda_vnodeopstats[i].sat_intrn = 0;
212 coda_vnodeopstats[i].unsat_intrn = 0;
213 coda_vnodeopstats[i].gen_intrn = 0;
219 * coda_open calls Venus to return the device, inode pair of the cache
220 * file holding the data. Using iget, coda_open finds the vnode of the
221 * cache file, and then opens it.
228 * NetBSD can pass the O_EXCL flag in mode, even though the check
229 * has already happened. Venus defensively assumes that if open
230 * is passed the EXCL, it must be a bug. We strip the flag here.
233 struct vop_open_args *ap = v;
234 register struct vnode **vpp = &(ap->a_vp);
235 struct cnode *cp = VTOC(*vpp);
236 int flag = ap->a_mode & (~O_EXCL);
237 struct ucred *cred = ap->a_cred;
238 struct thread *td = ap->a_td;
245 MARK_ENTRY(CODA_OPEN_STATS);
247 /* Check for open of control file. */
248 if (IS_CTL_VP(*vpp)) {
250 /* if (WRITEABLE(flag)) */
251 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
252 MARK_INT_FAIL(CODA_OPEN_STATS);
255 MARK_INT_SAT(CODA_OPEN_STATS);
259 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td->td_proc, &dev, &inode);
263 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
264 (u_long)dev2udev(dev), (u_long)inode,
268 /* Translate the <device, inode> pair for the cache file into
270 error = coda_grab_vnode(dev, inode, &vp);
274 /* We get the vnode back locked. Needs unlocked */
275 VOP_UNLOCK(vp, 0, td);
276 /* Keep a reference until the close comes in. */
279 /* Save the vnode pointer for the cache file. */
280 if (cp->c_ovp == NULL) {
284 panic("coda_open: cp->c_ovp != ITOV(ip)");
288 /* Flush the attribute cached if writing the file. */
291 cp->c_flags &= ~C_VATTR;
294 /* Save the <device, inode> pair for the cache file to speed
295 up subsequent page_read's. */
299 /* Open the cache file. */
300 error = VOP_OPEN(vp, flag, cred, td);
302 printf("coda_open: VOP_OPEN on container failed %d\n", error);
305 /* grab (above) does this when it calls newvnode unless it's in the cache*/
306 if (vp->v_type == VREG) {
307 error = vfs_object_create(vp, td, cred);
309 printf("coda_open: vfs_object_create() returns %d\n", error);
318 * Close the cache file used for I/O and notify Venus.
325 struct vop_close_args *ap = v;
326 struct vnode *vp = ap->a_vp;
327 struct cnode *cp = VTOC(vp);
328 int flag = ap->a_fflag;
329 struct ucred *cred = ap->a_cred;
330 struct thread *td = ap->a_td;
334 MARK_ENTRY(CODA_CLOSE_STATS);
336 /* Check for close of control file. */
338 MARK_INT_SAT(CODA_CLOSE_STATS);
342 if (IS_UNMOUNTING(cp)) {
345 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
346 vrefcnt(vp), cp->c_ovp, vp, cp);
351 VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */
356 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
361 VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */
365 if (--cp->c_ocount == 0)
368 if (flag & FWRITE) /* file was opened for write */
371 error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, td->td_proc);
374 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
382 struct vop_read_args *ap = v;
385 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
386 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
393 struct vop_write_args *ap = v;
396 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
397 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
401 coda_rdwr(vp, uiop, rw, ioflag, cred, td)
410 /* NOTE: container file operation!!! */
412 struct cnode *cp = VTOC(vp);
413 struct vnode *cfvp = cp->c_ovp;
414 struct proc *p = td->td_proc;
415 struct thread *ltd = td;
416 int igot_internally = 0;
417 int opened_internally = 0;
421 MARK_ENTRY(CODA_RDWR_STATS);
423 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
424 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
425 (long long)uiop->uio_offset, uiop->uio_segflg)); )
427 /* Check for rdwr of control object. */
429 MARK_INT_FAIL(CODA_RDWR_STATS);
434 * If file is not already open this must be a page
435 * {read,write} request. Iget the cache file's inode
436 * pointer if we still have its <device, inode> pair.
437 * Otherwise, we must do an internal open to derive the
442 * If we're dumping core, do the internal open. Otherwise
443 * venus won't have the correct size of the core when
444 * it's completely written.
448 iscore = (p->p_acflag & ACORE);
454 if (cp->c_inode != 0 && !iscore) {
456 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
458 MARK_INT_FAIL(CODA_RDWR_STATS);
462 * We get the vnode back locked by curthread in both Mach and
463 * NetBSD. Needs unlocked
465 VOP_UNLOCK(cfvp, 0, ltd);
468 opened_internally = 1;
469 MARK_INT_GEN(CODA_OPEN_STATS);
470 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
472 printf("coda_rdwr: Internally Opening %p\n", vp);
474 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
477 if (vp->v_type == VREG) {
478 error = vfs_object_create(vp, td, cred);
480 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
485 MARK_INT_FAIL(CODA_RDWR_STATS);
492 /* Have UFS handle the call. */
493 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
494 cp->c_fid.Volume, cp->c_fid.Vnode,
495 cp->c_fid.Unique, vrefcnt(CTOV(cp)))); )
497 if (rw == UIO_READ) {
498 error = VOP_READ(cfvp, uiop, ioflag, cred);
500 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
501 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
505 if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) {
506 vnode_pager_setsize(vp, attr.va_size);
512 MARK_INT_FAIL(CODA_RDWR_STATS);
514 MARK_INT_SAT(CODA_RDWR_STATS);
516 /* Do an internal close if necessary. */
517 if (opened_internally) {
518 MARK_INT_GEN(CODA_CLOSE_STATS);
519 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td);
522 /* Invalidate cached attributes if writing. */
524 cp->c_flags &= ~C_VATTR;
535 struct vop_ioctl_args *ap = v;
536 struct vnode *vp = ap->a_vp;
537 int com = ap->a_command;
538 caddr_t data = ap->a_data;
539 int flag = ap->a_fflag;
540 struct ucred *cred = ap->a_cred;
541 struct thread *td = ap->a_td;
545 struct nameidata ndp;
546 struct PioctlData *iap = (struct PioctlData *)data;
548 MARK_ENTRY(CODA_IOCTL_STATS);
550 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
552 /* Don't check for operation on a dying object, for ctlvp it
555 /* Must be control object to succeed. */
556 if (!IS_CTL_VP(vp)) {
557 MARK_INT_FAIL(CODA_IOCTL_STATS);
558 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
561 /* Look up the pathname. */
563 /* Should we use the name cache here? It would get it from
564 lookupname sooner or later anyway, right? */
566 NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td);
571 MARK_INT_FAIL(CODA_IOCTL_STATS);
572 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
578 * Make sure this is a coda style cnode, but it may be a
581 if (tvp->v_op != coda_vnodeop_p) {
583 NDFREE(&ndp, NDF_ONLY_PNBUF);
584 MARK_INT_FAIL(CODA_IOCTL_STATS);
585 CODADEBUG(CODA_IOCTL,
586 myprintf(("coda_ioctl error: %s not a coda object\n",
591 if (iap->vi.in_size > VC_MAXDATASIZE) {
595 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td->td_proc);
598 MARK_INT_FAIL(CODA_IOCTL_STATS);
600 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
603 NDFREE(&ndp, NDF_ONLY_PNBUF);
608 * To reduce the cost of a user-level venus;we cache attributes in
609 * the kernel. Each cnode has storage allocated for an attribute. If
610 * c_vattr is valid, return a reference to it. Otherwise, get the
611 * attributes from venus and store them in the cnode. There is some
612 * question if this method is a security leak. But I think that in
613 * order to make this call, the user must have done a lookup and
614 * opened the file, and therefore should already have access.
621 struct vop_getattr_args *ap = v;
622 struct vnode *vp = ap->a_vp;
623 struct cnode *cp = VTOC(vp);
624 struct vattr *vap = ap->a_vap;
625 struct ucred *cred = ap->a_cred;
626 struct thread *td = ap->a_td;
630 MARK_ENTRY(CODA_GETATTR_STATS);
632 if (IS_UNMOUNTING(cp))
635 /* Check for getattr of control object. */
637 MARK_INT_FAIL(CODA_GETATTR_STATS);
641 /* Check to see if the attributes have already been cached */
642 if (VALID_VATTR(cp)) {
643 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
646 cp->c_fid.Unique));});
647 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
648 print_vattr(&cp->c_vattr); );
651 MARK_INT_SAT(CODA_GETATTR_STATS);
655 error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap);
658 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
664 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
667 { int size = vap->va_size;
668 struct vnode *convp = cp->c_ovp;
669 if (convp != (struct vnode *)0) {
670 vnode_pager_setsize(convp, size);
673 /* If not open for write, store attributes in cnode */
674 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
676 cp->c_flags |= C_VATTR;
688 struct vop_setattr_args *ap = v;
689 register struct vnode *vp = ap->a_vp;
690 struct cnode *cp = VTOC(vp);
691 register struct vattr *vap = ap->a_vap;
692 struct ucred *cred = ap->a_cred;
693 struct thread *td = ap->a_td;
697 MARK_ENTRY(CODA_SETATTR_STATS);
699 /* Check for setattr of control object. */
701 MARK_INT_FAIL(CODA_SETATTR_STATS);
705 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
708 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc);
711 cp->c_flags &= ~C_VATTR;
713 { int size = vap->va_size;
714 struct vnode *convp = cp->c_ovp;
715 if (size != VNOVAL && convp != (struct vnode *)0) {
716 vnode_pager_setsize(convp, size);
719 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
728 struct vop_access_args *ap = v;
729 struct vnode *vp = ap->a_vp;
730 struct cnode *cp = VTOC(vp);
731 int mode = ap->a_mode;
732 struct ucred *cred = ap->a_cred;
733 struct thread *td = ap->a_td;
737 MARK_ENTRY(CODA_ACCESS_STATS);
739 /* Check for access of control object. Only read access is
742 /* bogus hack - all will be marked as successes */
743 MARK_INT_SAT(CODA_ACCESS_STATS);
744 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
749 * if the file is a directory, and we are checking exec (eg lookup)
750 * access, and the file is in the namecache, then the user must have
751 * lookup access to it.
753 if (coda_access_cache) {
754 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
755 if (coda_nc_lookup(cp, ".", 1, cred)) {
756 MARK_INT_SAT(CODA_ACCESS_STATS);
757 return(0); /* it was in the cache */
762 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc);
772 struct vop_readlink_args *ap = v;
773 struct vnode *vp = ap->a_vp;
774 struct cnode *cp = VTOC(vp);
775 struct uio *uiop = ap->a_uio;
776 struct ucred *cred = ap->a_cred;
777 struct thread *td = ap->a_uio->uio_td;
783 MARK_ENTRY(CODA_READLINK_STATS);
785 /* Check for readlink of control object. */
787 MARK_INT_FAIL(CODA_READLINK_STATS);
791 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
792 uiop->uio_rw = UIO_READ;
793 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
795 MARK_INT_FAIL(CODA_READLINK_STATS);
797 MARK_INT_SAT(CODA_READLINK_STATS);
801 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td->td_proc, &str, &len);
804 uiop->uio_rw = UIO_READ;
805 error = uiomove(str, len, uiop);
807 if (coda_symlink_cache) {
810 cp->c_flags |= C_SYMLINK;
815 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
824 struct vop_fsync_args *ap = v;
825 struct vnode *vp = ap->a_vp;
826 struct cnode *cp = VTOC(vp);
827 struct ucred *cred = ap->a_cred;
828 struct thread *td = ap->a_td;
830 struct vnode *convp = cp->c_ovp;
833 MARK_ENTRY(CODA_FSYNC_STATS);
835 /* Check for fsync on an unmounting object */
836 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
837 * after an unmount has been initiated. This is a Bad Thing,
838 * which we have to avoid. Not a legitimate failure for stats.
840 if (IS_UNMOUNTING(cp)) {
844 /* Check for fsync of control object. */
846 MARK_INT_SAT(CODA_FSYNC_STATS);
851 VOP_FSYNC(convp, cred, MNT_WAIT, td);
854 * We see fsyncs with usecount == 1 then usecount == 0.
855 * For now we ignore them.
859 if (!vp->v_usecount) {
860 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
861 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
867 * We can expect fsync on any vnode at all if venus is pruging it.
868 * Venus can't very well answer the fsync request, now can it?
869 * Hopefully, it won't have to, because hopefully, venus preserves
870 * the (possibly untrue) invariant that it never purges an open
873 if (cp->c_flags & C_PURGING) {
879 error = venus_fsync(vtomi(vp), &cp->c_fid, cred, td->td_proc);
881 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
889 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
890 have a proc pointer. Oops. */
892 struct vop_inactive_args *ap = v;
893 struct vnode *vp = ap->a_vp;
894 struct cnode *cp = VTOC(vp);
895 struct ucred *cred __attribute__((unused)) = NULL;
896 struct thread *td __attribute__((unused)) = curthread;
900 /* We don't need to send inactive to venus - DCS */
901 MARK_ENTRY(CODA_INACTIVE_STATS);
904 MARK_INT_SAT(CODA_INACTIVE_STATS);
908 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
909 cp->c_fid.Volume, cp->c_fid.Vnode,
910 cp->c_fid.Unique, vp->v_mount));)
912 /* If an array has been allocated to hold the symlink, deallocate it */
913 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
914 if (cp->c_symlink == NULL)
915 panic("coda_inactive: null symlink pointer in cnode");
917 CODA_FREE(cp->c_symlink, cp->c_symlen);
918 cp->c_flags &= ~C_SYMLINK;
922 /* Remove it from the table so it can't be found. */
924 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
925 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
926 panic("badness in coda_inactive\n");
929 if (IS_UNMOUNTING(cp)) {
931 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vrefcnt(vp), vp, cp);
932 if (cp->c_ovp != NULL)
933 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
934 vrefcnt(vp), vp, cp);
936 lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td);
938 #ifdef OLD_DIAGNOSTIC
939 if (vrefcnt(CTOV(cp))) {
940 panic("coda_inactive: nonzero reference count");
942 if (cp->c_ovp != NULL) {
943 panic("coda_inactive: cp->ovp != NULL");
946 VOP_UNLOCK(vp, 0, td);
950 MARK_INT_SAT(CODA_INACTIVE_STATS);
955 * Remote filesystem operations having to do with directory manipulation.
959 * It appears that in NetBSD, lookup is supposed to return the vnode locked
966 struct vop_lookup_args *ap = v;
967 struct vnode *dvp = ap->a_dvp;
968 struct cnode *dcp = VTOC(dvp);
969 struct vnode **vpp = ap->a_vpp;
971 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
972 * of the string to xlate, and that we must try to get at least
973 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
976 struct componentname *cnp = ap->a_cnp;
977 struct ucred *cred = cnp->cn_cred;
978 struct thread *td = cnp->cn_thread;
981 const char *nm = cnp->cn_nameptr;
982 int len = cnp->cn_namelen;
987 MARK_ENTRY(CODA_LOOKUP_STATS);
989 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
990 nm, dcp->c_fid.Volume,
991 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
993 /* Check for lookup of control object. */
994 if (IS_CTL_NAME(dvp, nm, len)) {
997 MARK_INT_SAT(CODA_LOOKUP_STATS);
1001 if (len+1 > CODA_MAXNAMLEN) {
1002 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1003 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
1004 dcp->c_fid.Volume, dcp->c_fid.Vnode,
1005 dcp->c_fid.Unique, nm)););
1006 *vpp = (struct vnode *)0;
1010 /* First try to look the file up in the cfs name cache */
1011 /* lock the parent vnode? */
1012 cp = coda_nc_lookup(dcp, nm, len, cred);
1016 CODADEBUG(CODA_LOOKUP,
1017 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
1020 /* The name wasn't cached, so we need to contact Venus */
1021 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc, &VFid, &vtype);
1024 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1025 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1026 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1027 *vpp = (struct vnode *)0;
1029 MARK_INT_SAT(CODA_LOOKUP_STATS);
1030 CODADEBUG(CODA_LOOKUP,
1031 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1032 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1035 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1038 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1039 /* And don't enter a new vnode for an invalid one! */
1040 if (!(vtype & CODA_NOCACHE))
1041 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1047 * If we are creating, and this was the last name to be looked up,
1048 * and the error was ENOENT, then there really shouldn't be an
1049 * error and we can make the leaf NULL and return success. Since
1050 * this is supposed to work under Mach as well as NetBSD, we're
1051 * leaving this fn wrapped. We also must tell lookup/namei that
1052 * we need to save the last component of the name. (Create will
1053 * have to free the name buffer later...lucky us...)
1055 if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
1056 && (cnp->cn_flags & ISLASTCN)
1057 && (error == ENOENT))
1059 error = EJUSTRETURN;
1060 cnp->cn_flags |= SAVENAME;
1065 * If we are removing, and we are at the last element, and we
1066 * found it, then we need to keep the name around so that the
1067 * removal will go ahead as planned. Unfortunately, this will
1068 * probably also lock the to-be-removed vnode, which may or may
1069 * not be a good idea. I'll have to look at the bits of
1070 * coda_remove to make sure. We'll only save the name if we did in
1071 * fact find the name, otherwise coda_remove won't have a chance
1072 * to free the pathname.
1074 if ((cnp->cn_nameiop == DELETE)
1075 && (cnp->cn_flags & ISLASTCN)
1078 cnp->cn_flags |= SAVENAME;
1082 * If the lookup went well, we need to (potentially?) unlock the
1083 * parent, and lock the child. We are only responsible for
1084 * checking to see if the parent is supposed to be unlocked before
1085 * we return. We must always lock the child (provided there is
1086 * one, and (the parent isn't locked or it isn't the same as the
1087 * parent.) Simple, huh? We can never leave the parent locked unless
1090 if (!error || (error == EJUSTRETURN)) {
1091 if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
1092 if ((error = VOP_UNLOCK(dvp, 0, td))) {
1096 * The parent is unlocked. As long as there is a child,
1097 * lock it without bothering to check anything else.
1100 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1101 printf("coda_lookup: ");
1102 panic("unlocked parent but couldn't lock child");
1106 /* The parent is locked, and may be the same as the child */
1107 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1108 /* Different, go ahead and lock it. */
1109 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1110 printf("coda_lookup: ");
1111 panic("unlocked parent but couldn't lock child");
1116 /* If the lookup failed, we need to ensure that the leaf is NULL */
1117 /* Don't change any locking? */
1129 struct vop_create_args *ap = v;
1130 struct vnode *dvp = ap->a_dvp;
1131 struct cnode *dcp = VTOC(dvp);
1132 struct vattr *va = ap->a_vap;
1134 int mode = ap->a_vap->va_mode;
1135 struct vnode **vpp = ap->a_vpp;
1136 struct componentname *cnp = ap->a_cnp;
1137 struct ucred *cred = cnp->cn_cred;
1138 struct thread *td = cnp->cn_thread;
1142 const char *nm = cnp->cn_nameptr;
1143 int len = cnp->cn_namelen;
1147 MARK_ENTRY(CODA_CREATE_STATS);
1149 /* All creates are exclusive XXX */
1150 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1152 /* Check for create of control object. */
1153 if (IS_CTL_NAME(dvp, nm, len)) {
1154 *vpp = (struct vnode *)0;
1155 MARK_INT_FAIL(CODA_CREATE_STATS);
1159 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td->td_proc, &VFid, &attr);
1163 /* If this is an exclusive create, panic if the file already exists. */
1164 /* Venus should have detected the file and reported EEXIST. */
1166 if ((exclusive == 1) &&
1167 (coda_find(&VFid) != NULL))
1168 panic("cnode existed for newly created file!");
1170 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1173 /* Update va to reflect the new attributes. */
1176 /* Update the attribute cache and mark it as valid */
1177 if (coda_attr_cache) {
1178 VTOC(*vpp)->c_vattr = attr;
1179 VTOC(*vpp)->c_flags |= C_VATTR;
1182 /* Invalidate the parent's attr cache, the modification time has changed */
1183 VTOC(dvp)->c_flags &= ~C_VATTR;
1185 /* enter the new vnode in the Name Cache */
1186 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1188 CODADEBUG(CODA_CREATE,
1189 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1190 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1192 *vpp = (struct vnode *)0;
1193 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1197 if (cnp->cn_flags & LOCKLEAF) {
1198 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1199 printf("coda_create: ");
1200 panic("unlocked parent but couldn't lock child");
1203 #ifdef OLD_DIAGNOSTIC
1205 printf("coda_create: LOCKLEAF not set!\n");
1217 struct vop_remove_args *ap = v;
1218 struct vnode *dvp = ap->a_dvp;
1219 struct cnode *cp = VTOC(dvp);
1220 struct componentname *cnp = ap->a_cnp;
1221 struct ucred *cred = cnp->cn_cred;
1222 struct thread *td = cnp->cn_thread;
1225 const char *nm = cnp->cn_nameptr;
1226 int len = cnp->cn_namelen;
1229 MARK_ENTRY(CODA_REMOVE_STATS);
1231 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1232 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1233 cp->c_fid.Unique)););
1235 /* Remove the file's entry from the CODA Name Cache */
1236 /* We're being conservative here, it might be that this person
1237 * doesn't really have sufficient access to delete the file
1238 * but we feel zapping the entry won't really hurt anyone -- dcs
1240 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1241 * exist, and one is removed, the link count on the other will be
1242 * off by 1. We could either invalidate the attrs if cached, or
1243 * fix them. I'll try to fix them. DCS 11/8/94
1245 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1247 if (VALID_VATTR(tp)) { /* If attrs are cached */
1248 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1249 tp->c_vattr.va_nlink--;
1253 coda_nc_zapfile(VTOC(dvp), nm, len);
1254 /* No need to flush it if it doesn't exist! */
1256 /* Invalidate the parent's attr cache, the modification time has changed */
1257 VTOC(dvp)->c_flags &= ~C_VATTR;
1259 /* Check for remove of control object. */
1260 if (IS_CTL_NAME(dvp, nm, len)) {
1261 MARK_INT_FAIL(CODA_REMOVE_STATS);
1265 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td->td_proc);
1267 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1277 struct vop_link_args *ap = v;
1278 struct vnode *vp = ap->a_vp;
1279 struct cnode *cp = VTOC(vp);
1280 struct vnode *tdvp = ap->a_tdvp;
1281 struct cnode *tdcp = VTOC(tdvp);
1282 struct componentname *cnp = ap->a_cnp;
1283 struct ucred *cred = cnp->cn_cred;
1284 struct thread *td = cnp->cn_thread;
1287 const char *nm = cnp->cn_nameptr;
1288 int len = cnp->cn_namelen;
1290 MARK_ENTRY(CODA_LINK_STATS);
1292 if (codadebug & CODADBGMSK(CODA_LINK)) {
1294 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1295 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1296 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1297 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1300 if (codadebug & CODADBGMSK(CODA_LINK)) {
1301 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1302 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1303 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1304 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1308 /* Check for link to/from control object. */
1309 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1310 MARK_INT_FAIL(CODA_LINK_STATS);
1314 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td->td_proc);
1316 /* Invalidate the parent's attr cache, the modification time has changed */
1317 VTOC(tdvp)->c_flags &= ~C_VATTR;
1318 VTOC(vp)->c_flags &= ~C_VATTR;
1320 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1330 struct vop_rename_args *ap = v;
1331 struct vnode *odvp = ap->a_fdvp;
1332 struct cnode *odcp = VTOC(odvp);
1333 struct componentname *fcnp = ap->a_fcnp;
1334 struct vnode *ndvp = ap->a_tdvp;
1335 struct cnode *ndcp = VTOC(ndvp);
1336 struct componentname *tcnp = ap->a_tcnp;
1337 struct ucred *cred = fcnp->cn_cred;
1338 struct thread *td = fcnp->cn_thread;
1341 const char *fnm = fcnp->cn_nameptr;
1342 int flen = fcnp->cn_namelen;
1343 const char *tnm = tcnp->cn_nameptr;
1344 int tlen = tcnp->cn_namelen;
1346 MARK_ENTRY(CODA_RENAME_STATS);
1348 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1349 This could be Bad. XXX */
1350 #ifdef OLD_DIAGNOSTIC
1351 if ((fcnp->cn_cred != tcnp->cn_cred)
1352 || (fcnp->cn_thread != tcnp->cn_thread))
1354 panic("coda_rename: component names don't agree");
1358 /* Check for rename involving control object. */
1359 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1360 MARK_INT_FAIL(CODA_RENAME_STATS);
1364 /* Problem with moving directories -- need to flush entry for .. */
1366 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1368 struct vnode *ovp = CTOV(ovcp);
1370 (ovp->v_type == VDIR)) /* If it's a directory */
1371 coda_nc_zapfile(VTOC(ovp),"..", 2);
1375 /* Remove the entries for both source and target files */
1376 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1377 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1379 /* Invalidate the parent's attr cache, the modification time has changed */
1380 VTOC(odvp)->c_flags &= ~C_VATTR;
1381 VTOC(ndvp)->c_flags &= ~C_VATTR;
1383 if (flen+1 > CODA_MAXNAMLEN) {
1384 MARK_INT_FAIL(CODA_RENAME_STATS);
1389 if (tlen+1 > CODA_MAXNAMLEN) {
1390 MARK_INT_FAIL(CODA_RENAME_STATS);
1395 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td->td_proc);
1398 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1399 /* XXX - do we need to call cache pureg on the moved vnode? */
1400 cache_purge(ap->a_fvp);
1402 /* It seems to be incumbent on us to drop locks on all four vnodes */
1403 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1409 if (ap->a_tvp == ndvp) {
1425 struct vop_mkdir_args *ap = v;
1426 struct vnode *dvp = ap->a_dvp;
1427 struct cnode *dcp = VTOC(dvp);
1428 struct componentname *cnp = ap->a_cnp;
1429 register struct vattr *va = ap->a_vap;
1430 struct vnode **vpp = ap->a_vpp;
1431 struct ucred *cred = cnp->cn_cred;
1432 struct thread *td = cnp->cn_thread;
1435 const char *nm = cnp->cn_nameptr;
1436 int len = cnp->cn_namelen;
1441 MARK_ENTRY(CODA_MKDIR_STATS);
1443 /* Check for mkdir of target object. */
1444 if (IS_CTL_NAME(dvp, nm, len)) {
1445 *vpp = (struct vnode *)0;
1446 MARK_INT_FAIL(CODA_MKDIR_STATS);
1450 if (len+1 > CODA_MAXNAMLEN) {
1451 *vpp = (struct vnode *)0;
1452 MARK_INT_FAIL(CODA_MKDIR_STATS);
1456 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td->td_proc, &VFid, &ova);
1459 if (coda_find(&VFid) != NULL)
1460 panic("cnode existed for newly created directory!");
1463 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1466 /* enter the new vnode in the Name Cache */
1467 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1469 /* as a side effect, enter "." and ".." for the directory */
1470 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1471 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1473 if (coda_attr_cache) {
1474 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1475 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1478 /* Invalidate the parent's attr cache, the modification time has changed */
1479 VTOC(dvp)->c_flags &= ~C_VATTR;
1481 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1482 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1484 *vpp = (struct vnode *)0;
1485 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1496 struct vop_rmdir_args *ap = v;
1497 struct vnode *dvp = ap->a_dvp;
1498 struct cnode *dcp = VTOC(dvp);
1499 struct componentname *cnp = ap->a_cnp;
1500 struct ucred *cred = cnp->cn_cred;
1501 struct thread *td = cnp->cn_thread;
1504 const char *nm = cnp->cn_nameptr;
1505 int len = cnp->cn_namelen;
1508 MARK_ENTRY(CODA_RMDIR_STATS);
1510 /* Check for rmdir of control object. */
1511 if (IS_CTL_NAME(dvp, nm, len)) {
1512 MARK_INT_FAIL(CODA_RMDIR_STATS);
1516 /* We're being conservative here, it might be that this person
1517 * doesn't really have sufficient access to delete the file
1518 * but we feel zapping the entry won't really hurt anyone -- dcs
1521 * As a side effect of the rmdir, remove any entries for children of
1522 * the directory, especially "." and "..".
1524 cp = coda_nc_lookup(dcp, nm, len, cred);
1525 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1527 /* Remove the file's entry from the CODA Name Cache */
1528 coda_nc_zapfile(dcp, nm, len);
1530 /* Invalidate the parent's attr cache, the modification time has changed */
1531 dcp->c_flags &= ~C_VATTR;
1533 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc);
1535 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1545 struct vop_symlink_args *ap = v;
1546 struct vnode *tdvp = ap->a_dvp;
1547 struct cnode *tdcp = VTOC(tdvp);
1548 struct componentname *cnp = ap->a_cnp;
1549 struct vattr *tva = ap->a_vap;
1550 char *path = ap->a_target;
1551 struct ucred *cred = cnp->cn_cred;
1552 struct thread *td = cnp->cn_thread;
1553 struct vnode **vpp = ap->a_vpp;
1557 * XXX I'm assuming the following things about coda_symlink's
1559 * t(foo) is the new name/parent/etc being created.
1560 * lname is the contents of the new symlink.
1562 char *nm = cnp->cn_nameptr;
1563 int len = cnp->cn_namelen;
1564 int plen = strlen(path);
1567 * Here's the strategy for the moment: perform the symlink, then
1568 * do a lookup to grab the resulting vnode. I know this requires
1569 * two communications with Venus for a new sybolic link, but
1570 * that's the way the ball bounces. I don't yet want to change
1571 * the way the Mach symlink works. When Mach support is
1572 * deprecated, we should change symlink so that the common case
1573 * returns the resultant vnode in a vpp argument.
1576 MARK_ENTRY(CODA_SYMLINK_STATS);
1578 /* Check for symlink of control object. */
1579 if (IS_CTL_NAME(tdvp, nm, len)) {
1580 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1584 if (plen+1 > CODA_MAXPATHLEN) {
1585 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1589 if (len+1 > CODA_MAXNAMLEN) {
1590 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1595 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td->td_proc);
1597 /* Invalidate the parent's attr cache, the modification time has changed */
1598 tdcp->c_flags &= ~C_VATTR;
1601 error = VOP_LOOKUP(tdvp, vpp, cnp);
1604 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1609 * Read directory entries.
1616 struct vop_readdir_args *ap = v;
1617 struct vnode *vp = ap->a_vp;
1618 struct cnode *cp = VTOC(vp);
1619 register struct uio *uiop = ap->a_uio;
1620 struct ucred *cred = ap->a_cred;
1621 int *eofflag = ap->a_eofflag;
1622 u_long **cookies = ap->a_cookies;
1623 int *ncookies = ap->a_ncookies;
1624 struct thread *td = ap->a_uio->uio_td;
1629 MARK_ENTRY(CODA_READDIR_STATS);
1631 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1632 (void *)uiop->uio_iov->iov_base,
1634 (long long)uiop->uio_offset,
1635 uiop->uio_segflg)); )
1637 /* Check for readdir of control object. */
1638 if (IS_CTL_VP(vp)) {
1639 MARK_INT_FAIL(CODA_READDIR_STATS);
1644 /* If directory is not already open do an "internal open" on it. */
1645 int opened_internally = 0;
1646 if (cp->c_ovp == NULL) {
1647 opened_internally = 1;
1648 MARK_INT_GEN(CODA_OPEN_STATS);
1649 error = VOP_OPEN(vp, FREAD, cred, td);
1650 printf("coda_readdir: Internally Opening %p\n", vp);
1652 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1655 if (vp->v_type == VREG) {
1656 error = vfs_object_create(vp, td, cred);
1658 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1662 if (error) return(error);
1665 /* Have UFS handle the call. */
1666 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, vrefcnt(vp))); )
1667 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1671 MARK_INT_FAIL(CODA_READDIR_STATS);
1673 MARK_INT_SAT(CODA_READDIR_STATS);
1675 /* Do an "internal close" if necessary. */
1676 if (opened_internally) {
1677 MARK_INT_GEN(CODA_CLOSE_STATS);
1678 (void)VOP_CLOSE(vp, FREAD, cred, td);
1686 * Convert from filesystem blocks to device blocks
1692 /* XXX on the global proc */
1694 struct vop_bmap_args *ap = v;
1695 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1696 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1697 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1698 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1699 struct thread *td __attribute__((unused)) = curthread;
1709 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1711 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %lld, ap->a_runp %p, ap->a_runb %p) = %d\n",
1712 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1717 printf("coda_bmap: no container\n");
1724 * I don't think the following two things are used anywhere, so I've
1725 * commented them out
1727 * struct buf *async_bufhead;
1728 * int async_daemon_count;
1735 struct vop_strategy_args *ap = v;
1736 register struct buf *bp __attribute__((unused)) = ap->a_bp;
1737 struct thread *td __attribute__((unused)) = curthread;
1741 printf("coda_strategy: called ???\n");
1750 struct vop_reclaim_args *ap = v;
1751 struct vnode *vp = ap->a_vp;
1752 struct cnode *cp = VTOC(vp);
1757 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1761 if (IS_UNMOUNTING(cp)) {
1763 if (VTOC(vp)->c_ovp) {
1764 if (IS_UNMOUNTING(cp))
1765 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1769 #ifdef OLD_DIAGNOSTIC
1770 if (vrefcnt(vp) != 0)
1771 print("coda_reclaim: pushing active %p\n", vp);
1772 if (VTOC(vp)->c_ovp) {
1773 panic("coda_reclaim: c_ovp not void");
1778 lockdestroy(&(VTOC(vp)->c_lock));
1779 coda_free(VTOC(vp));
1789 struct vop_lock_args *ap = v;
1790 struct vnode *vp = ap->a_vp;
1791 struct cnode *cp = VTOC(vp);
1792 struct thread *td = ap->a_td;
1798 if (coda_lockdebug) {
1799 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1800 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1804 return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td));
1806 return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td,
1807 "coda_lock", vp->filename, vp->line));
1816 struct vop_unlock_args *ap = v;
1817 struct vnode *vp = ap->a_vp;
1818 struct cnode *cp = VTOC(vp);
1819 struct thread *td = ap->a_td;
1824 if (coda_lockdebug) {
1825 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1826 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1829 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td));
1837 struct vop_islocked_args *ap = v;
1838 struct cnode *cp = VTOC(ap->a_vp);
1841 return (lockstatus(&cp->c_lock, ap->a_td));
1844 /* How one looks up a vnode given a device/inode pair: */
1846 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1848 /* This is like VFS_VGET() or igetinode()! */
1852 if (!(mp = devtomp(dev))) {
1853 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1854 (u_long)dev2udev(dev)));
1858 /* XXX - ensure that nonzero-return means failure */
1859 error = VFS_VGET(mp,ino,LK_EXCLUSIVE,vpp);
1861 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1862 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1874 switch (attr->va_type) {
1908 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1909 typestr, (int)attr->va_mode, (int)attr->va_uid,
1910 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1912 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1913 (int)attr->va_fileid, (int)attr->va_nlink,
1915 (int)attr->va_blocksize,(int)attr->va_bytes));
1916 myprintf((" gen %ld flags %ld vaflags %d\n",
1917 attr->va_gen, attr->va_flags, attr->va_vaflags));
1918 myprintf((" atime sec %d nsec %d\n",
1919 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1920 myprintf((" mtime sec %d nsec %d\n",
1921 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1922 myprintf((" ctime sec %d nsec %d\n",
1923 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1926 /* How to print a ucred */
1934 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1936 for (i=0; i < cred->cr_ngroups; i++)
1937 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1943 * Return a vnode for the given fid.
1944 * If no cnode exists for this fid create one and put it
1945 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1946 * this fid is already in the table return it (ref count is
1947 * incremented by coda_find. The cnode will be flushed from the
1948 * table when coda_inactive calls coda_unsave.
1951 make_coda_node(fid, vfsp, type)
1952 ViceFid *fid; struct mount *vfsp; short type;
1957 if ((cp = coda_find(fid)) == NULL) {
1961 lockinit(&cp->c_lock, PINOD, "cnode", 0, 0);
1964 err = getnewvnode("coda", vfsp, coda_vnodeop_p, &vp);
1966 panic("coda: getnewvnode returned error %d\n", err);