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.15 2004/03/31 02:34:37 cpressey 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>
71 #include "coda_vnops.h"
72 #include "coda_venus.h"
73 #include "coda_opstats.h"
74 #include "coda_subr.h"
75 #include "coda_namecache.h"
76 #include "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 int (**coda_vnodeop_p)(void *);
87 /* structure to keep track of vfs calls */
89 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
91 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
92 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
93 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
94 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
96 /* What we are delaying for in printf */
97 int coda_printf_delay = 0; /* in microseconds */
98 int coda_vnop_print_entry = 0;
99 static int coda_lockdebug = 0;
101 /* Definition of the vfs operation vector */
104 * Some NetBSD details:
106 * coda_start is called at the end of the mount syscall.
107 * coda_init is called at boot time.
110 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
112 /* Definition of the vnode operation vector */
114 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
115 { &vop_default_desc, coda_vop_error },
116 { &vop_lookup_desc, coda_lookup }, /* lookup */
117 { &vop_create_desc, coda_create }, /* create */
118 { &vop_mknod_desc, coda_vop_error }, /* mknod */
119 { &vop_open_desc, coda_open }, /* open */
120 { &vop_close_desc, coda_close }, /* close */
121 { &vop_access_desc, coda_access }, /* access */
122 { &vop_getattr_desc, coda_getattr }, /* getattr */
123 { &vop_setattr_desc, coda_setattr }, /* setattr */
124 { &vop_read_desc, coda_read }, /* read */
125 { &vop_write_desc, coda_write }, /* write */
126 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
127 { &vop_mmap_desc, coda_vop_error }, /* mmap */
128 { &vop_fsync_desc, coda_fsync }, /* fsync */
129 { &vop_remove_desc, coda_remove }, /* remove */
130 { &vop_link_desc, coda_link }, /* link */
131 { &vop_rename_desc, coda_rename }, /* rename */
132 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
133 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
134 { &vop_symlink_desc, coda_symlink }, /* symlink */
135 { &vop_readdir_desc, coda_readdir }, /* readdir */
136 { &vop_readlink_desc, coda_readlink }, /* readlink */
137 { &vop_inactive_desc, coda_inactive }, /* inactive */
138 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
139 { &vop_lock_desc, coda_lock }, /* lock */
140 { &vop_unlock_desc, coda_unlock }, /* unlock */
141 { &vop_bmap_desc, coda_bmap }, /* bmap */
142 { &vop_strategy_desc, coda_strategy }, /* strategy */
143 { &vop_print_desc, coda_vop_error }, /* print */
144 { &vop_islocked_desc, coda_islocked }, /* islocked */
145 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
146 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
147 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
148 { &vop_lease_desc, coda_vop_nop }, /* lease */
149 { &vop_poll_desc, (vop_t *) vop_stdpoll },
150 { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
151 { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
152 { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
153 { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
154 { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
158 we need to define these someday
159 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
160 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
161 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
162 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
163 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
166 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
167 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
168 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
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)
182 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
184 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
185 (*desc)->vdesc_name));
187 panic("coda_vop_error");
192 /* A generic do-nothing. For lease_check, advlock */
194 coda_vop_nop(void *anon)
196 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
199 myprintf(("Vnode operation %s called, but unsupported\n",
200 (*desc)->vdesc_name));
206 coda_vnodeopstats_init(void)
210 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
211 coda_vnodeopstats[i].opcode = i;
212 coda_vnodeopstats[i].entries = 0;
213 coda_vnodeopstats[i].sat_intrn = 0;
214 coda_vnodeopstats[i].unsat_intrn = 0;
215 coda_vnodeopstats[i].gen_intrn = 0;
221 * coda_open calls Venus to return the device, inode pair of the cache
222 * file holding the data. Using iget, coda_open finds the vnode of the
223 * cache file, and then opens it.
229 * NetBSD can pass the O_EXCL flag in mode, even though the check
230 * has already happened. Venus defensively assumes that if open
231 * is passed the EXCL, it must be a bug. We strip the flag here.
234 struct vop_open_args *ap = v;
235 struct vnode **vpp = &(ap->a_vp);
236 struct cnode *cp = VTOC(*vpp);
237 int flag = ap->a_mode & (~O_EXCL);
238 struct ucred *cred = ap->a_cred;
239 struct thread *td = ap->a_td;
246 MARK_ENTRY(CODA_OPEN_STATS);
248 /* Check for open of control file. */
249 if (IS_CTL_VP(*vpp)) {
251 /* if (WRITEABLE(flag)) */
252 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
253 MARK_INT_FAIL(CODA_OPEN_STATS);
256 MARK_INT_SAT(CODA_OPEN_STATS);
260 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
264 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
265 (u_long)dev2udev(dev), (u_long)inode,
269 /* Translate the <device, inode> pair for the cache file into
271 error = coda_grab_vnode(dev, inode, &vp);
275 /* We get the vnode back locked. Needs unlocked */
276 VOP_UNLOCK(vp, NULL, 0, td);
277 /* Keep a reference until the close comes in. */
280 /* Save the vnode pointer for the cache file. */
281 if (cp->c_ovp == NULL) {
285 panic("coda_open: cp->c_ovp != ITOV(ip)");
289 /* Flush the attribute cached if writing the file. */
292 cp->c_flags &= ~C_VATTR;
295 /* Save the <device, inode> pair for the cache file to speed
296 up subsequent page_read's. */
300 /* Open the cache file. */
301 error = VOP_OPEN(vp, flag, cred, td);
303 printf("coda_open: VOP_OPEN on container failed %d\n", error);
306 /* grab (above) does this when it calls newvnode unless it's in the cache*/
307 if (vp->v_type == VREG) {
308 error = vfs_object_create(vp, td);
310 printf("coda_open: vfs_object_create() returns %d\n", error);
319 * 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 thread *td = ap->a_td;
333 MARK_ENTRY(CODA_CLOSE_STATS);
335 /* Check for close of control file. */
337 MARK_INT_SAT(CODA_CLOSE_STATS);
341 if (IS_UNMOUNTING(cp)) {
344 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
345 vp->v_usecount, cp->c_ovp, vp, cp);
350 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
355 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
360 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
364 if (--cp->c_ocount == 0)
367 if (flag & FWRITE) /* file was opened for write */
370 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
373 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_td));
390 struct vop_write_args *ap = v;
393 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
394 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
398 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
399 struct ucred *cred, struct thread *td)
402 /* NOTE: container file operation!!! */
404 struct cnode *cp = VTOC(vp);
405 struct vnode *cfvp = cp->c_ovp;
406 int igot_internally = 0;
407 int opened_internally = 0;
410 MARK_ENTRY(CODA_RDWR_STATS);
412 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
413 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
414 (long long)uiop->uio_offset, uiop->uio_segflg)); )
416 /* Check for rdwr of control object. */
418 MARK_INT_FAIL(CODA_RDWR_STATS);
423 * If file is not already open this must be a page
424 * {read,write} request. Iget the cache file's inode
425 * pointer if we still have its <device, inode> pair.
426 * Otherwise, we must do an internal open to derive the
431 * If we're dumping core, do the internal open. Otherwise
432 * venus won't have the correct size of the core when
433 * it's completely written.
435 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
437 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
439 MARK_INT_FAIL(CODA_RDWR_STATS);
443 * We get the vnode back locked in both Mach and
444 * NetBSD. Needs unlocked
446 VOP_UNLOCK(cfvp, NULL, 0, td);
449 opened_internally = 1;
450 MARK_INT_GEN(CODA_OPEN_STATS);
451 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
453 printf("coda_rdwr: Internally Opening %p\n", vp);
455 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
458 if (vp->v_type == VREG) {
459 error = vfs_object_create(vp, td);
461 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
466 MARK_INT_FAIL(CODA_RDWR_STATS);
473 /* Have UFS handle the call. */
474 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
475 cp->c_fid.Volume, cp->c_fid.Vnode,
476 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
479 if (rw == UIO_READ) {
480 error = VOP_READ(cfvp, uiop, ioflag, cred);
482 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
483 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
487 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
488 vnode_pager_setsize(vp, attr.va_size);
494 MARK_INT_FAIL(CODA_RDWR_STATS);
496 MARK_INT_SAT(CODA_RDWR_STATS);
498 /* Do an internal close if necessary. */
499 if (opened_internally) {
500 MARK_INT_GEN(CODA_CLOSE_STATS);
501 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
504 /* Invalidate cached attributes if writing. */
506 cp->c_flags &= ~C_VATTR;
514 struct vop_ioctl_args *ap = v;
515 struct vnode *vp = ap->a_vp;
516 int com = ap->a_command;
517 caddr_t data = ap->a_data;
518 int flag = ap->a_fflag;
519 struct ucred *cred = ap->a_cred;
520 struct thread *td = ap->a_td;
524 struct nameidata ndp;
525 struct PioctlData *iap = (struct PioctlData *)data;
527 MARK_ENTRY(CODA_IOCTL_STATS);
529 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
531 /* Don't check for operation on a dying object, for ctlvp it
534 /* Must be control object to succeed. */
535 if (!IS_CTL_VP(vp)) {
536 MARK_INT_FAIL(CODA_IOCTL_STATS);
537 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
540 /* Look up the pathname. */
542 /* Should we use the name cache here? It would get it from
543 lookupname sooner or later anyway, right? */
545 NDINIT(&ndp, NAMEI_LOOKUP, (iap->follow ? CNP_FOLLOW : 0), UIO_USERSPACE, iap->path, td);
550 MARK_INT_FAIL(CODA_IOCTL_STATS);
551 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
557 * Make sure this is a coda style cnode, but it may be a
560 if (tvp->v_op != coda_vnodeop_p) {
562 NDFREE(&ndp, NDF_ONLY_PNBUF);
563 MARK_INT_FAIL(CODA_IOCTL_STATS);
564 CODADEBUG(CODA_IOCTL,
565 myprintf(("coda_ioctl error: %s not a coda object\n",
570 if (iap->vi.in_size > VC_MAXDATASIZE) {
574 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
577 MARK_INT_FAIL(CODA_IOCTL_STATS);
579 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
582 NDFREE(&ndp, NDF_ONLY_PNBUF);
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);
905 lockmgr(&cp->c_lock, LK_RELEASE, NULL, td);
907 #ifdef OLD_DIAGNOSTIC
908 if (CTOV(cp)->v_usecount) {
909 panic("coda_inactive: nonzero reference count");
911 if (cp->c_ovp != NULL) {
912 panic("coda_inactive: cp->ovp != NULL");
915 VOP_UNLOCK(vp, NULL, 0, td);
919 MARK_INT_SAT(CODA_INACTIVE_STATS);
924 * Remote file system operations having to do with directory manipulation.
928 * It appears that in NetBSD, lookup is supposed to return the vnode locked
934 struct vop_lookup_args *ap = v;
935 struct vnode *dvp = ap->a_dvp;
936 struct cnode *dcp = VTOC(dvp);
937 struct vnode **vpp = ap->a_vpp;
939 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
940 * of the string to xlate, and that we must try to get at least
941 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
944 struct componentname *cnp = ap->a_cnp;
945 struct ucred *cred = cnp->cn_cred;
946 struct thread *td = cnp->cn_td;
949 const char *nm = cnp->cn_nameptr;
950 int len = cnp->cn_namelen;
955 MARK_ENTRY(CODA_LOOKUP_STATS);
957 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
958 nm, dcp->c_fid.Volume,
959 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
961 /* Check for lookup of control object. */
962 if (IS_CTL_NAME(dvp, nm, len)) {
965 MARK_INT_SAT(CODA_LOOKUP_STATS);
969 if (len+1 > CODA_MAXNAMLEN) {
970 MARK_INT_FAIL(CODA_LOOKUP_STATS);
971 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
972 dcp->c_fid.Volume, dcp->c_fid.Vnode,
973 dcp->c_fid.Unique, nm)););
974 *vpp = (struct vnode *)0;
978 /* First try to look the file up in the cfs name cache */
979 /* lock the parent vnode? */
980 cp = coda_nc_lookup(dcp, nm, len, cred);
984 CODADEBUG(CODA_LOOKUP,
985 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
988 /* The name wasn't cached, so we need to contact Venus */
989 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
992 MARK_INT_FAIL(CODA_LOOKUP_STATS);
993 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
994 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
995 *vpp = (struct vnode *)0;
997 MARK_INT_SAT(CODA_LOOKUP_STATS);
998 CODADEBUG(CODA_LOOKUP,
999 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1000 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1003 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1006 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1007 /* And don't enter a new vnode for an invalid one! */
1008 if (!(vtype & CODA_NOCACHE))
1009 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1015 * If we are creating, and this was the last name to be looked up,
1016 * and the error was ENOENT, then there really shouldn't be an
1017 * error and we can make the leaf NULL and return success. Since
1018 * this is supposed to work under Mach as well as NetBSD, we're
1019 * leaving this fn wrapped. We also must tell lookup/namei that
1020 * we need to save the last component of the name. (Create will
1021 * have to free the name buffer later...lucky us...)
1023 if (((cnp->cn_nameiop == NAMEI_CREATE) || (cnp->cn_nameiop == NAMEI_RENAME))
1024 && (cnp->cn_flags & CNP_ISLASTCN)
1025 && (error == ENOENT))
1027 error = EJUSTRETURN;
1028 cnp->cn_flags |= CNP_SAVENAME;
1033 * If we are removing, and we are at the last element, and we
1034 * found it, then we need to keep the name around so that the
1035 * removal will go ahead as planned. Unfortunately, this will
1036 * probably also lock the to-be-removed vnode, which may or may
1037 * not be a good idea. I'll have to look at the bits of
1038 * coda_remove to make sure. We'll only save the name if we did in
1039 * fact find the name, otherwise coda_remove won't have a chance
1040 * to free the pathname.
1042 if ((cnp->cn_nameiop == NAMEI_DELETE)
1043 && (cnp->cn_flags & CNP_ISLASTCN)
1046 cnp->cn_flags |= CNP_SAVENAME;
1050 * If the lookup went well, we need to (potentially?) unlock the
1051 * parent, and lock the child. We are only responsible for
1052 * checking to see if the parent is supposed to be unlocked before
1053 * we return. We must always lock the child (provided there is
1054 * one, and (the parent isn't locked or it isn't the same as the
1055 * parent.) Simple, huh? We can never leave the parent locked unless
1058 if (!error || (error == EJUSTRETURN)) {
1059 if (!(cnp->cn_flags & CNP_LOCKPARENT) || !(cnp->cn_flags & CNP_ISLASTCN)) {
1060 if ((error = VOP_UNLOCK(dvp, NULL, 0, td))) {
1064 * The parent is unlocked. As long as there is a child,
1065 * lock it without bothering to check anything else.
1068 if ((error = VOP_LOCK(*ap->a_vpp, NULL, LK_EXCLUSIVE, td))) {
1069 printf("coda_lookup: ");
1070 panic("unlocked parent but couldn't lock child");
1074 /* The parent is locked, and may be the same as the child */
1075 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1076 /* Different, go ahead and lock it. */
1077 if ((error = VOP_LOCK(*ap->a_vpp, NULL, LK_EXCLUSIVE, td))) {
1078 printf("coda_lookup: ");
1079 panic("unlocked parent but couldn't lock child");
1084 /* If the lookup failed, we need to ensure that the leaf is NULL */
1085 /* Don't change any locking? */
1093 coda_create(void *v)
1096 struct vop_create_args *ap = v;
1097 struct vnode *dvp = ap->a_dvp;
1098 struct cnode *dcp = VTOC(dvp);
1099 struct vattr *va = ap->a_vap;
1101 int mode = ap->a_vap->va_mode;
1102 struct vnode **vpp = ap->a_vpp;
1103 struct componentname *cnp = ap->a_cnp;
1104 struct ucred *cred = cnp->cn_cred;
1105 struct thread *td = cnp->cn_td;
1109 const char *nm = cnp->cn_nameptr;
1110 int len = cnp->cn_namelen;
1114 MARK_ENTRY(CODA_CREATE_STATS);
1116 /* All creates are exclusive XXX */
1117 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1119 /* Check for create of control object. */
1120 if (IS_CTL_NAME(dvp, nm, len)) {
1121 *vpp = (struct vnode *)0;
1122 MARK_INT_FAIL(CODA_CREATE_STATS);
1126 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1130 /* If this is an exclusive create, panic if the file already exists. */
1131 /* Venus should have detected the file and reported EEXIST. */
1133 if ((exclusive == 1) &&
1134 (coda_find(&VFid) != NULL))
1135 panic("cnode existed for newly created file!");
1137 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1140 /* Update va to reflect the new attributes. */
1143 /* Update the attribute cache and mark it as valid */
1144 if (coda_attr_cache) {
1145 VTOC(*vpp)->c_vattr = attr;
1146 VTOC(*vpp)->c_flags |= C_VATTR;
1149 /* Invalidate the parent's attr cache, the modification time has changed */
1150 VTOC(dvp)->c_flags &= ~C_VATTR;
1152 /* enter the new vnode in the Name Cache */
1153 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1155 CODADEBUG(CODA_CREATE,
1156 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1157 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1159 *vpp = (struct vnode *)0;
1160 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1164 if (cnp->cn_flags & CNP_LOCKLEAF) {
1165 if ((error = VOP_LOCK(*ap->a_vpp, NULL, LK_EXCLUSIVE, td))) {
1166 printf("coda_create: ");
1167 panic("unlocked parent but couldn't lock child");
1170 #ifdef OLD_DIAGNOSTIC
1172 printf("coda_create: LOCKLEAF not set!\n");
1180 coda_remove(void *v)
1183 struct vop_remove_args *ap = v;
1184 struct vnode *dvp = ap->a_dvp;
1185 struct cnode *cp = VTOC(dvp);
1186 struct componentname *cnp = ap->a_cnp;
1187 struct ucred *cred = cnp->cn_cred;
1188 struct thread *td = cnp->cn_td;
1191 const char *nm = cnp->cn_nameptr;
1192 int len = cnp->cn_namelen;
1195 MARK_ENTRY(CODA_REMOVE_STATS);
1197 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1198 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1199 cp->c_fid.Unique)););
1201 /* Remove the file's entry from the CODA Name Cache */
1202 /* We're being conservative here, it might be that this person
1203 * doesn't really have sufficient access to delete the file
1204 * but we feel zapping the entry won't really hurt anyone -- dcs
1206 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1207 * exist, and one is removed, the link count on the other will be
1208 * off by 1. We could either invalidate the attrs if cached, or
1209 * fix them. I'll try to fix them. DCS 11/8/94
1211 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1213 if (VALID_VATTR(tp)) { /* If attrs are cached */
1214 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1215 tp->c_vattr.va_nlink--;
1219 coda_nc_zapfile(VTOC(dvp), nm, len);
1220 /* No need to flush it if it doesn't exist! */
1222 /* Invalidate the parent's attr cache, the modification time has changed */
1223 VTOC(dvp)->c_flags &= ~C_VATTR;
1225 /* Check for remove of control object. */
1226 if (IS_CTL_NAME(dvp, nm, len)) {
1227 MARK_INT_FAIL(CODA_REMOVE_STATS);
1231 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1233 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1242 struct vop_link_args *ap = v;
1243 struct vnode *vp = ap->a_vp;
1244 struct cnode *cp = VTOC(vp);
1245 struct vnode *tdvp = ap->a_tdvp;
1246 struct cnode *tdcp = VTOC(tdvp);
1247 struct componentname *cnp = ap->a_cnp;
1248 struct ucred *cred = cnp->cn_cred;
1249 struct thread *td = cnp->cn_td;
1252 const char *nm = cnp->cn_nameptr;
1253 int len = cnp->cn_namelen;
1255 MARK_ENTRY(CODA_LINK_STATS);
1257 if (codadebug & CODADBGMSK(CODA_LINK)) {
1259 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1260 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1261 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1262 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1265 if (codadebug & CODADBGMSK(CODA_LINK)) {
1266 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1267 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1268 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1269 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1273 /* Check for link to/from control object. */
1274 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1275 MARK_INT_FAIL(CODA_LINK_STATS);
1279 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1281 /* Invalidate the parent's attr cache, the modification time has changed */
1282 VTOC(tdvp)->c_flags &= ~C_VATTR;
1283 VTOC(vp)->c_flags &= ~C_VATTR;
1285 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1291 coda_rename(void *v)
1294 struct vop_rename_args *ap = v;
1295 struct vnode *odvp = ap->a_fdvp;
1296 struct cnode *odcp = VTOC(odvp);
1297 struct componentname *fcnp = ap->a_fcnp;
1298 struct vnode *ndvp = ap->a_tdvp;
1299 struct cnode *ndcp = VTOC(ndvp);
1300 struct componentname *tcnp = ap->a_tcnp;
1301 struct ucred *cred = fcnp->cn_cred;
1302 struct thread *td = fcnp->cn_td;
1305 const char *fnm = fcnp->cn_nameptr;
1306 int flen = fcnp->cn_namelen;
1307 const char *tnm = tcnp->cn_nameptr;
1308 int tlen = tcnp->cn_namelen;
1310 MARK_ENTRY(CODA_RENAME_STATS);
1312 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1313 This could be Bad. XXX */
1314 #ifdef OLD_DIAGNOSTIC
1315 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1317 panic("coda_rename: component names don't agree");
1321 /* Check for rename involving control object. */
1322 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1323 MARK_INT_FAIL(CODA_RENAME_STATS);
1327 /* Problem with moving directories -- need to flush entry for .. */
1329 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1331 struct vnode *ovp = CTOV(ovcp);
1333 (ovp->v_type == VDIR)) /* If it's a directory */
1334 coda_nc_zapfile(VTOC(ovp),"..", 2);
1338 /* Remove the entries for both source and target files */
1339 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1340 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1342 /* Invalidate the parent's attr cache, the modification time has changed */
1343 VTOC(odvp)->c_flags &= ~C_VATTR;
1344 VTOC(ndvp)->c_flags &= ~C_VATTR;
1346 if (flen+1 > CODA_MAXNAMLEN) {
1347 MARK_INT_FAIL(CODA_RENAME_STATS);
1352 if (tlen+1 > CODA_MAXNAMLEN) {
1353 MARK_INT_FAIL(CODA_RENAME_STATS);
1358 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1361 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1362 /* XXX - do we need to call cache pureg on the moved vnode? */
1363 cache_purge(ap->a_fvp);
1365 /* It seems to be incumbent on us to drop locks on all four vnodes */
1366 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1372 if (ap->a_tvp == ndvp) {
1387 struct vop_mkdir_args *ap = v;
1388 struct vnode *dvp = ap->a_dvp;
1389 struct cnode *dcp = VTOC(dvp);
1390 struct componentname *cnp = ap->a_cnp;
1391 struct vattr *va = ap->a_vap;
1392 struct vnode **vpp = ap->a_vpp;
1393 struct ucred *cred = cnp->cn_cred;
1394 struct thread *td = cnp->cn_td;
1397 const char *nm = cnp->cn_nameptr;
1398 int len = cnp->cn_namelen;
1403 MARK_ENTRY(CODA_MKDIR_STATS);
1405 /* Check for mkdir of target object. */
1406 if (IS_CTL_NAME(dvp, nm, len)) {
1407 *vpp = (struct vnode *)0;
1408 MARK_INT_FAIL(CODA_MKDIR_STATS);
1412 if (len+1 > CODA_MAXNAMLEN) {
1413 *vpp = (struct vnode *)0;
1414 MARK_INT_FAIL(CODA_MKDIR_STATS);
1418 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1421 if (coda_find(&VFid) != NULL)
1422 panic("cnode existed for newly created directory!");
1425 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1428 /* enter the new vnode in the Name Cache */
1429 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1431 /* as a side effect, enter "." and ".." for the directory */
1432 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1433 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1435 if (coda_attr_cache) {
1436 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1437 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1440 /* Invalidate the parent's attr cache, the modification time has changed */
1441 VTOC(dvp)->c_flags &= ~C_VATTR;
1443 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1444 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1446 *vpp = (struct vnode *)0;
1447 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1457 struct vop_rmdir_args *ap = v;
1458 struct vnode *dvp = ap->a_dvp;
1459 struct cnode *dcp = VTOC(dvp);
1460 struct componentname *cnp = ap->a_cnp;
1461 struct ucred *cred = cnp->cn_cred;
1462 struct thread *td = cnp->cn_td;
1465 const char *nm = cnp->cn_nameptr;
1466 int len = cnp->cn_namelen;
1469 MARK_ENTRY(CODA_RMDIR_STATS);
1471 /* Check for rmdir of control object. */
1472 if (IS_CTL_NAME(dvp, nm, len)) {
1473 MARK_INT_FAIL(CODA_RMDIR_STATS);
1477 /* We're being conservative here, it might be that this person
1478 * doesn't really have sufficient access to delete the file
1479 * but we feel zapping the entry won't really hurt anyone -- dcs
1482 * As a side effect of the rmdir, remove any entries for children of
1483 * the directory, especially "." and "..".
1485 cp = coda_nc_lookup(dcp, nm, len, cred);
1486 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1488 /* Remove the file's entry from the CODA Name Cache */
1489 coda_nc_zapfile(dcp, nm, len);
1491 /* Invalidate the parent's attr cache, the modification time has changed */
1492 dcp->c_flags &= ~C_VATTR;
1494 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1496 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1502 coda_symlink(void *v)
1505 struct vop_symlink_args *ap = v;
1506 struct vnode *tdvp = ap->a_dvp;
1507 struct cnode *tdcp = VTOC(tdvp);
1508 struct componentname *cnp = ap->a_cnp;
1509 struct vattr *tva = ap->a_vap;
1510 char *path = ap->a_target;
1511 struct ucred *cred = cnp->cn_cred;
1512 struct thread *td = cnp->cn_td;
1513 struct vnode **vpp = ap->a_vpp;
1517 * XXX I'm assuming the following things about coda_symlink's
1519 * t(foo) is the new name/parent/etc being created.
1520 * lname is the contents of the new symlink.
1522 char *nm = cnp->cn_nameptr;
1523 int len = cnp->cn_namelen;
1524 int plen = strlen(path);
1527 * Here's the strategy for the moment: perform the symlink, then
1528 * do a lookup to grab the resulting vnode. I know this requires
1529 * two communications with Venus for a new sybolic link, but
1530 * that's the way the ball bounces. I don't yet want to change
1531 * the way the Mach symlink works. When Mach support is
1532 * deprecated, we should change symlink so that the common case
1533 * returns the resultant vnode in a vpp argument.
1536 MARK_ENTRY(CODA_SYMLINK_STATS);
1538 /* Check for symlink of control object. */
1539 if (IS_CTL_NAME(tdvp, nm, len)) {
1540 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1544 if (plen+1 > CODA_MAXPATHLEN) {
1545 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1549 if (len+1 > CODA_MAXNAMLEN) {
1550 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1555 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1557 /* Invalidate the parent's attr cache, the modification time has changed */
1558 tdcp->c_flags &= ~C_VATTR;
1561 error = VOP_LOOKUP(tdvp, NCPNULL, vpp, NCPPNULL, cnp);
1564 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1569 * Read directory entries.
1572 coda_readdir(void *v)
1575 struct vop_readdir_args *ap = v;
1576 struct vnode *vp = ap->a_vp;
1577 struct cnode *cp = VTOC(vp);
1578 struct uio *uiop = ap->a_uio;
1579 struct ucred *cred = ap->a_cred;
1580 int *eofflag = ap->a_eofflag;
1581 u_long **cookies = ap->a_cookies;
1582 int *ncookies = ap->a_ncookies;
1583 struct thread *td = ap->a_uio->uio_td;
1588 MARK_ENTRY(CODA_READDIR_STATS);
1590 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1591 (void *)uiop->uio_iov->iov_base,
1593 (long long)uiop->uio_offset,
1594 uiop->uio_segflg)); )
1596 /* Check for readdir of control object. */
1597 if (IS_CTL_VP(vp)) {
1598 MARK_INT_FAIL(CODA_READDIR_STATS);
1603 /* If directory is not already open do an "internal open" on it. */
1604 int opened_internally = 0;
1605 if (cp->c_ovp == NULL) {
1606 opened_internally = 1;
1607 MARK_INT_GEN(CODA_OPEN_STATS);
1608 error = VOP_OPEN(vp, FREAD, cred, td);
1609 printf("coda_readdir: Internally Opening %p\n", vp);
1611 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1614 if (vp->v_type == VREG) {
1615 error = vfs_object_create(vp, td);
1617 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1621 if (error) return(error);
1624 /* Have UFS handle the call. */
1625 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)); )
1626 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1630 MARK_INT_FAIL(CODA_READDIR_STATS);
1632 MARK_INT_SAT(CODA_READDIR_STATS);
1634 /* Do an "internal close" if necessary. */
1635 if (opened_internally) {
1636 MARK_INT_GEN(CODA_CLOSE_STATS);
1637 (void)VOP_CLOSE(vp, FREAD, td);
1645 * Convert from file system blocks to device blocks
1650 /* XXX on the global proc */
1652 struct vop_bmap_args *ap = v;
1653 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1654 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1655 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1656 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1666 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1668 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1669 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1674 printf("coda_bmap: no container\n");
1681 * I don't think the following two things are used anywhere, so I've
1682 * commented them out
1684 * struct buf *async_bufhead;
1685 * int async_daemon_count;
1688 coda_strategy(void *v)
1691 struct vop_strategy_args *ap = v;
1692 struct buf *bp __attribute__((unused)) = ap->a_bp;
1696 printf("coda_strategy: called ???\n");
1701 coda_reclaim(void *v)
1704 struct vop_reclaim_args *ap = v;
1705 struct vnode *vp = ap->a_vp;
1706 struct cnode *cp = VTOC(vp);
1711 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1715 if (IS_UNMOUNTING(cp)) {
1717 if (VTOC(vp)->c_ovp) {
1718 if (IS_UNMOUNTING(cp))
1719 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1723 #ifdef OLD_DIAGNOSTIC
1724 if (vp->v_usecount != 0)
1725 print("coda_reclaim: pushing active %p\n", vp);
1726 if (VTOC(vp)->c_ovp) {
1727 panic("coda_reclaim: c_ovp not void");
1732 coda_free(VTOC(vp));
1741 struct vop_lock_args *ap = v;
1742 struct vnode *vp = ap->a_vp;
1743 struct cnode *cp = VTOC(vp);
1744 struct thread *td = ap->a_td;
1750 if (coda_lockdebug) {
1751 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1752 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1756 return (lockmgr(&cp->c_lock, ap->a_flags, ap->a_vlock, td));
1758 return (debuglockmgr(&cp->c_lock, ap->a_flags, ap->a_vlock, td,
1759 "coda_lock", vp->filename, vp->line));
1764 coda_unlock(void *v)
1767 struct vop_unlock_args *ap = v;
1768 struct vnode *vp = ap->a_vp;
1769 struct cnode *cp = VTOC(vp);
1770 struct thread *td = ap->a_td;
1775 if (coda_lockdebug) {
1776 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1777 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1780 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, ap->a_vlock, td));
1784 coda_islocked(void *v)
1787 struct vop_islocked_args *ap = v;
1788 struct cnode *cp = VTOC(ap->a_vp);
1791 return (lockstatus(&cp->c_lock, ap->a_td));
1794 /* How one looks up a vnode given a device/inode pair: */
1796 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1798 /* This is like VFS_VGET() or igetinode()! */
1802 if (!(mp = devtomp(dev))) {
1803 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1804 (u_long)dev2udev(dev)));
1808 /* XXX - ensure that nonzero-return means failure */
1809 error = VFS_VGET(mp,ino,vpp);
1811 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1812 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1819 print_vattr(struct vattr *attr)
1823 switch (attr->va_type) {
1857 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1858 typestr, (int)attr->va_mode, (int)attr->va_uid,
1859 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1861 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1862 (int)attr->va_fileid, (int)attr->va_nlink,
1864 (int)attr->va_blocksize,(int)attr->va_bytes));
1865 myprintf((" gen %ld flags %ld vaflags %d\n",
1866 attr->va_gen, attr->va_flags, attr->va_vaflags));
1867 myprintf((" atime sec %d nsec %d\n",
1868 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1869 myprintf((" mtime sec %d nsec %d\n",
1870 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1871 myprintf((" ctime sec %d nsec %d\n",
1872 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1875 /* How to print a ucred */
1877 print_cred(struct ucred *cred)
1882 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1884 for (i=0; i < cred->cr_ngroups; i++)
1885 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1891 * Return a vnode for the given fid.
1892 * If no cnode exists for this fid create one and put it
1893 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1894 * this fid is already in the table return it (ref count is
1895 * incremented by coda_find. The cnode will be flushed from the
1896 * table when coda_inactive calls coda_unsave.
1899 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1904 if ((cp = coda_find(fid)) == NULL) {
1908 lockinit(&cp->c_lock, 0, "cnode", 0, 0);
1911 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
1913 panic("coda: getnewvnode returned error %d\n", err);