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.26 2005/02/17 14:00:10 joerg Exp $
36 * Mach Operating System
37 * Copyright (c) 1990 Carnegie-Mellon University
38 * Copyright (c) 1989 Carnegie-Mellon University
39 * All rights reserved. The CMU software License Agreement specifies
40 * the terms and conditions for use and redistribution.
44 * This code was written for the Coda file system at Carnegie Mellon
45 * University. Contributers include David Steere, James Kistler, and
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
53 #include <sys/malloc.h>
54 #include <sys/mount.h>
55 #include <sys/errno.h>
58 #include <sys/fcntl.h>
60 #include <sys/nlookup.h>
61 #include <sys/namei.h>
62 #include <sys/ioccom.h>
63 #include <sys/select.h>
66 #include <vm/vm_object.h>
67 #include <vm/vm_extern.h>
68 #include <vm/vm_zone.h>
72 #include "coda_vnops.h"
73 #include "coda_venus.h"
74 #include "coda_opstats.h"
75 #include "coda_subr.h"
76 #include "coda_namecache.h"
77 #include "coda_pioctl.h"
80 * These flags select various performance enhancements.
82 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
83 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
84 int coda_access_cache = 1; /* Set to handle some access checks directly */
86 /* structure to keep track of vfs calls */
88 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
90 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
91 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
92 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
93 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
95 /* What we are delaying for in printf */
96 int coda_printf_delay = 0; /* in microseconds */
97 int coda_vnop_print_entry = 0;
98 static int coda_lockdebug = 0;
100 /* Definition of the vfs operation vector */
103 * Some NetBSD details:
105 * coda_start is called at the end of the mount syscall.
106 * coda_init is called at boot time.
109 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
111 /* Definition of the vnode operation vector */
113 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
114 { &vop_default_desc, (vnodeopv_entry_t)coda_vop_error },
115 { &vop_lookup_desc, (vnodeopv_entry_t)coda_lookup }, /* lookup */
116 { &vop_create_desc, (vnodeopv_entry_t)coda_create }, /* create */
117 { &vop_mknod_desc, (vnodeopv_entry_t)coda_vop_error }, /* mknod */
118 { &vop_open_desc, (vnodeopv_entry_t)coda_open }, /* open */
119 { &vop_close_desc, (vnodeopv_entry_t)coda_close }, /* close */
120 { &vop_access_desc, (vnodeopv_entry_t)coda_access }, /* access */
121 { &vop_getattr_desc, (vnodeopv_entry_t)coda_getattr }, /* getattr */
122 { &vop_setattr_desc, (vnodeopv_entry_t)coda_setattr }, /* setattr */
123 { &vop_read_desc, (vnodeopv_entry_t)coda_read }, /* read */
124 { &vop_write_desc, (vnodeopv_entry_t)coda_write }, /* write */
125 { &vop_ioctl_desc, (vnodeopv_entry_t)coda_ioctl }, /* ioctl */
126 { &vop_mmap_desc, (vnodeopv_entry_t)coda_vop_error }, /* mmap */
127 { &vop_fsync_desc, (vnodeopv_entry_t)coda_fsync }, /* fsync */
128 { &vop_remove_desc, (vnodeopv_entry_t)coda_remove }, /* remove */
129 { &vop_link_desc, (vnodeopv_entry_t)coda_link }, /* link */
130 { &vop_rename_desc, (vnodeopv_entry_t)coda_rename }, /* rename */
131 { &vop_mkdir_desc, (vnodeopv_entry_t)coda_mkdir }, /* mkdir */
132 { &vop_rmdir_desc, (vnodeopv_entry_t)coda_rmdir }, /* rmdir */
133 { &vop_symlink_desc, (vnodeopv_entry_t)coda_symlink }, /* symlink */
134 { &vop_readdir_desc, (vnodeopv_entry_t)coda_readdir }, /* readdir */
135 { &vop_readlink_desc, (vnodeopv_entry_t)coda_readlink }, /* readlink */
136 { &vop_inactive_desc, (vnodeopv_entry_t)coda_inactive }, /* inactive */
137 { &vop_reclaim_desc, (vnodeopv_entry_t)coda_reclaim }, /* reclaim */
138 { &vop_lock_desc, (vnodeopv_entry_t)coda_lock }, /* lock */
139 { &vop_unlock_desc, (vnodeopv_entry_t)coda_unlock }, /* unlock */
140 { &vop_bmap_desc, (vnodeopv_entry_t)coda_bmap }, /* bmap */
141 { &vop_strategy_desc, (vnodeopv_entry_t)coda_strategy }, /* strategy */
142 { &vop_print_desc, (vnodeopv_entry_t)coda_vop_error }, /* print */
143 { &vop_islocked_desc, (vnodeopv_entry_t)coda_islocked }, /* islocked */
144 { &vop_pathconf_desc, (vnodeopv_entry_t)coda_vop_error }, /* pathconf */
145 { &vop_advlock_desc, (vnodeopv_entry_t)coda_vop_nop }, /* advlock */
146 { &vop_bwrite_desc, (vnodeopv_entry_t)coda_vop_error }, /* bwrite */
147 { &vop_lease_desc, (vnodeopv_entry_t)coda_vop_nop }, /* lease */
148 { &vop_poll_desc, vop_stdpoll }, /* poll */
149 { &vop_getpages_desc, (vnodeopv_entry_t)coda_fbsd_getpages }, /* pager intf.*/
150 { &vop_putpages_desc, (vnodeopv_entry_t)coda_fbsd_putpages }, /* pager intf.*/
151 { &vop_createvobject_desc, vop_stdcreatevobject },
152 { &vop_destroyvobject_desc, vop_stddestroyvobject },
153 { &vop_getvobject_desc, vop_stdgetvobject },
157 we need to define these someday
158 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
159 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
160 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
161 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
162 #define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
165 { &vop_reallocblks_desc, (vnodeopv_entry_t) ufs_missingop },
166 { &vop_lookup_desc, (vnodeopv_entry_t) ufs_lookup },
167 { &vop_whiteout_desc, (vnodeopv_entry_t) ufs_whiteout },
172 /* A generic panic: we were called with something we didn't define yet */
174 coda_vop_error(void *anon)
176 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
178 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
179 (*desc)->vdesc_name));
181 panic("coda_vop_error");
186 /* A generic do-nothing. For lease_check, advlock */
188 coda_vop_nop(void *anon)
190 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
193 myprintf(("Vnode operation %s called, but unsupported\n",
194 (*desc)->vdesc_name));
200 coda_vnodeopstats_init(void)
204 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
205 coda_vnodeopstats[i].opcode = i;
206 coda_vnodeopstats[i].entries = 0;
207 coda_vnodeopstats[i].sat_intrn = 0;
208 coda_vnodeopstats[i].unsat_intrn = 0;
209 coda_vnodeopstats[i].gen_intrn = 0;
215 * coda_open calls Venus to return the device, inode pair of the cache
216 * file holding the data. Using iget, coda_open finds the vnode of the
217 * cache file, and then opens it.
223 * NetBSD can pass the O_EXCL flag in mode, even though the check
224 * has already happened. Venus defensively assumes that if open
225 * is passed the EXCL, it must be a bug. We strip the flag here.
228 struct vop_open_args *ap = v;
229 struct vnode **vpp = &(ap->a_vp);
230 struct cnode *cp = VTOC(*vpp);
231 int flag = ap->a_mode & (~O_EXCL);
232 struct ucred *cred = ap->a_cred;
233 struct thread *td = ap->a_td;
240 MARK_ENTRY(CODA_OPEN_STATS);
242 /* Check for open of control file. */
243 if (IS_CTL_VP(*vpp)) {
245 /* if (WRITEABLE(flag)) */
246 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
247 MARK_INT_FAIL(CODA_OPEN_STATS);
250 MARK_INT_SAT(CODA_OPEN_STATS);
254 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
258 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
259 (u_long)dev2udev(dev), (u_long)inode,
263 /* Translate the <device, inode> pair for the cache file into
265 error = coda_grab_vnode(dev, inode, &vp);
269 /* We get the vnode back locked. Needs unlocked */
270 VOP_UNLOCK(vp, 0, td);
271 /* Keep a reference until the close comes in. */
274 /* Save the vnode pointer for the cache file. */
275 if (cp->c_ovp == NULL) {
279 panic("coda_open: cp->c_ovp != ITOV(ip)");
283 /* Flush the attribute cached if writing the file. */
286 cp->c_flags &= ~C_VATTR;
289 /* Save the <device, inode> pair for the cache file to speed
290 up subsequent page_read's. */
294 /* Open the cache file. */
295 error = VOP_OPEN(vp, flag, cred, NULL, td);
297 printf("coda_open: VOP_OPEN on container failed %d\n", error);
300 /* grab (above) does this when it calls newvnode unless it's in the cache*/
301 if (vp->v_type == VREG) {
302 error = vfs_object_create(vp, td);
304 printf("coda_open: vfs_object_create() returns %d\n", error);
313 * Close the cache file used for I/O and notify Venus.
319 struct vop_close_args *ap = v;
320 struct vnode *vp = ap->a_vp;
321 struct cnode *cp = VTOC(vp);
322 int flag = ap->a_fflag;
323 struct thread *td = ap->a_td;
327 MARK_ENTRY(CODA_CLOSE_STATS);
329 /* Check for close of control file. */
331 MARK_INT_SAT(CODA_CLOSE_STATS);
335 if (IS_UNMOUNTING(cp)) {
338 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
339 vp->v_usecount, cp->c_ovp, vp, cp);
344 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
349 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
354 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
358 if (--cp->c_ocount == 0)
361 if (flag & FWRITE) /* file was opened for write */
364 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
367 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
374 struct vop_read_args *ap = v;
377 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
378 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
384 struct vop_write_args *ap = v;
387 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
388 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
392 coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
393 struct ucred *cred, struct thread *td)
396 /* NOTE: container file operation!!! */
398 struct cnode *cp = VTOC(vp);
399 struct vnode *cfvp = cp->c_ovp;
400 int igot_internally = 0;
401 int opened_internally = 0;
404 MARK_ENTRY(CODA_RDWR_STATS);
406 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
407 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
408 (long long)uiop->uio_offset, uiop->uio_segflg)); )
410 /* Check for rdwr of control object. */
412 MARK_INT_FAIL(CODA_RDWR_STATS);
417 * If file is not already open this must be a page
418 * {read,write} request. Iget the cache file's inode
419 * pointer if we still have its <device, inode> pair.
420 * Otherwise, we must do an internal open to derive the
425 * If we're dumping core, do the internal open. Otherwise
426 * venus won't have the correct size of the core when
427 * it's completely written.
429 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
431 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
433 MARK_INT_FAIL(CODA_RDWR_STATS);
437 * We get the vnode back locked in both Mach and
438 * NetBSD. Needs unlocked
440 VOP_UNLOCK(cfvp, 0, td);
443 opened_internally = 1;
444 MARK_INT_GEN(CODA_OPEN_STATS);
445 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
447 printf("coda_rdwr: Internally Opening %p\n", vp);
449 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
452 if (vp->v_type == VREG) {
453 error = vfs_object_create(vp, td);
455 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
460 MARK_INT_FAIL(CODA_RDWR_STATS);
467 /* Have UFS handle the call. */
468 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
469 cp->c_fid.Volume, cp->c_fid.Vnode,
470 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
473 if (rw == UIO_READ) {
474 error = VOP_READ(cfvp, uiop, ioflag, cred);
476 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
477 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
481 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
482 vnode_pager_setsize(vp, attr.va_size);
488 MARK_INT_FAIL(CODA_RDWR_STATS);
490 MARK_INT_SAT(CODA_RDWR_STATS);
492 /* Do an internal close if necessary. */
493 if (opened_internally) {
494 MARK_INT_GEN(CODA_CLOSE_STATS);
495 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
498 /* Invalidate cached attributes if writing. */
500 cp->c_flags &= ~C_VATTR;
508 struct vop_ioctl_args *ap = v;
509 struct vnode *vp = ap->a_vp;
510 int com = ap->a_command;
511 caddr_t data = ap->a_data;
512 int flag = ap->a_fflag;
513 struct ucred *cred = ap->a_cred;
514 struct thread *td = ap->a_td;
518 struct nlookupdata nd;
519 struct PioctlData *iap = (struct PioctlData *)data;
521 MARK_ENTRY(CODA_IOCTL_STATS);
523 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
525 /* Don't check for operation on a dying object, for ctlvp it
528 /* Must be control object to succeed. */
529 if (!IS_CTL_VP(vp)) {
530 MARK_INT_FAIL(CODA_IOCTL_STATS);
531 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
534 /* Look up the pathname. */
536 /* Should we use the name cache here? It would get it from
537 lookupname sooner or later anyway, right? */
540 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
541 (iap->follow ? NLC_FOLLOW : 0));
543 error = nlookup(&nd);
545 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
549 MARK_INT_FAIL(CODA_IOCTL_STATS);
550 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
556 * Make sure this is a coda style cnode, but it may be a
559 if (tvp->v_tag != VT_CODA) {
561 MARK_INT_FAIL(CODA_IOCTL_STATS);
562 CODADEBUG(CODA_IOCTL,
563 myprintf(("coda_ioctl error: %s not a coda object\n",
568 if (iap->vi.in_size > VC_MAXDATASIZE) {
572 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
575 MARK_INT_FAIL(CODA_IOCTL_STATS);
577 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
584 * To reduce the cost of a user-level venus;we cache attributes in
585 * the kernel. Each cnode has storage allocated for an attribute. If
586 * c_vattr is valid, return a reference to it. Otherwise, get the
587 * attributes from venus and store them in the cnode. There is some
588 * question if this method is a security leak. But I think that in
589 * order to make this call, the user must have done a lookup and
590 * opened the file, and therefore should already have access.
593 coda_getattr(void *v)
596 struct vop_getattr_args *ap = v;
597 struct vnode *vp = ap->a_vp;
598 struct cnode *cp = VTOC(vp);
599 struct vattr *vap = ap->a_vap;
600 struct thread *td = ap->a_td;
604 MARK_ENTRY(CODA_GETATTR_STATS);
606 if (IS_UNMOUNTING(cp))
609 /* Check for getattr of control object. */
611 MARK_INT_FAIL(CODA_GETATTR_STATS);
615 /* Check to see if the attributes have already been cached */
616 if (VALID_VATTR(cp)) {
617 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
620 cp->c_fid.Unique));});
621 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
622 print_vattr(&cp->c_vattr); );
625 MARK_INT_SAT(CODA_GETATTR_STATS);
629 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
632 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
638 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
641 { int size = vap->va_size;
642 struct vnode *convp = cp->c_ovp;
643 if (convp != (struct vnode *)0) {
644 vnode_pager_setsize(convp, size);
647 /* If not open for write, store attributes in cnode */
648 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
650 cp->c_flags |= C_VATTR;
658 coda_setattr(void *v)
661 struct vop_setattr_args *ap = v;
662 struct vnode *vp = ap->a_vp;
663 struct cnode *cp = VTOC(vp);
664 struct vattr *vap = ap->a_vap;
665 struct ucred *cred = ap->a_cred;
666 struct thread *td = ap->a_td;
670 MARK_ENTRY(CODA_SETATTR_STATS);
672 /* Check for setattr of control object. */
674 MARK_INT_FAIL(CODA_SETATTR_STATS);
678 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
681 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
684 cp->c_flags &= ~C_VATTR;
686 { int size = vap->va_size;
687 struct vnode *convp = cp->c_ovp;
688 if (size != VNOVAL && convp != (struct vnode *)0) {
689 vnode_pager_setsize(convp, size);
692 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
700 struct vop_access_args *ap = v;
701 struct vnode *vp = ap->a_vp;
702 struct cnode *cp = VTOC(vp);
703 int mode = ap->a_mode;
704 struct ucred *cred = ap->a_cred;
705 struct thread *td = ap->a_td;
709 MARK_ENTRY(CODA_ACCESS_STATS);
711 /* Check for access of control object. Only read access is
714 /* bogus hack - all will be marked as successes */
715 MARK_INT_SAT(CODA_ACCESS_STATS);
716 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
721 * if the file is a directory, and we are checking exec (eg lookup)
722 * access, and the file is in the namecache, then the user must have
723 * lookup access to it.
725 if (coda_access_cache) {
726 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
727 if (coda_nc_lookup(cp, ".", 1, cred)) {
728 MARK_INT_SAT(CODA_ACCESS_STATS);
729 return(0); /* it was in the cache */
734 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
740 coda_readlink(void *v)
743 struct vop_readlink_args *ap = v;
744 struct vnode *vp = ap->a_vp;
745 struct cnode *cp = VTOC(vp);
746 struct uio *uiop = ap->a_uio;
747 struct ucred *cred = ap->a_cred;
748 struct thread *td = ap->a_uio->uio_td;
754 MARK_ENTRY(CODA_READLINK_STATS);
756 /* Check for readlink of control object. */
758 MARK_INT_FAIL(CODA_READLINK_STATS);
762 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
763 uiop->uio_rw = UIO_READ;
764 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
766 MARK_INT_FAIL(CODA_READLINK_STATS);
768 MARK_INT_SAT(CODA_READLINK_STATS);
772 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
775 uiop->uio_rw = UIO_READ;
776 error = uiomove(str, len, uiop);
778 if (coda_symlink_cache) {
781 cp->c_flags |= C_SYMLINK;
786 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
794 struct vop_fsync_args *ap = v;
795 struct vnode *vp = ap->a_vp;
796 struct cnode *cp = VTOC(vp);
797 struct thread *td = ap->a_td;
799 struct vnode *convp = cp->c_ovp;
802 MARK_ENTRY(CODA_FSYNC_STATS);
804 /* Check for fsync on an unmounting object */
805 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
806 * after an unmount has been initiated. This is a Bad Thing,
807 * which we have to avoid. Not a legitimate failure for stats.
809 if (IS_UNMOUNTING(cp)) {
813 /* Check for fsync of control object. */
815 MARK_INT_SAT(CODA_FSYNC_STATS);
820 VOP_FSYNC(convp, MNT_WAIT, td);
823 * We see fsyncs with usecount == 1 then usecount == 0.
824 * For now we ignore them.
827 if (!vp->v_usecount) {
828 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
829 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
834 * We can expect fsync on any vnode at all if venus is pruging it.
835 * Venus can't very well answer the fsync request, now can it?
836 * Hopefully, it won't have to, because hopefully, venus preserves
837 * the (possibly untrue) invariant that it never purges an open
840 if (cp->c_flags & C_PURGING) {
846 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
848 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
853 coda_inactive(void *v)
855 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
856 have a proc pointer. Oops. */
858 struct vop_inactive_args *ap = v;
859 struct vnode *vp = ap->a_vp;
860 struct cnode *cp = VTOC(vp);
861 struct ucred *cred __attribute__((unused)) = NULL;
862 /*struct thread *td = curthread;*/
866 /* We don't need to send inactive to venus - DCS */
867 MARK_ENTRY(CODA_INACTIVE_STATS);
870 MARK_INT_SAT(CODA_INACTIVE_STATS);
874 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
875 cp->c_fid.Volume, cp->c_fid.Vnode,
876 cp->c_fid.Unique, vp->v_mount));)
878 /* If an array has been allocated to hold the symlink, deallocate it */
879 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
880 if (cp->c_symlink == NULL)
881 panic("coda_inactive: null symlink pointer in cnode");
883 CODA_FREE(cp->c_symlink, cp->c_symlen);
884 cp->c_flags &= ~C_SYMLINK;
888 /* Remove it from the table so it can't be found. */
890 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
891 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
892 panic("badness in coda_inactive\n");
895 if (IS_UNMOUNTING(cp)) {
897 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
898 if (cp->c_ovp != NULL)
899 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
900 vp->v_usecount, vp, cp);
903 #ifdef OLD_DIAGNOSTIC
904 if (CTOV(cp)->v_usecount) {
905 panic("coda_inactive: nonzero reference count");
907 if (cp->c_ovp != NULL) {
908 panic("coda_inactive: cp->ovp != NULL");
914 MARK_INT_SAT(CODA_INACTIVE_STATS);
919 * Remote file system operations having to do with directory manipulation.
923 * It appears that in NetBSD, lookup is supposed to return the vnode locked
929 struct vop_lookup_args *ap = v;
930 struct vnode *dvp = ap->a_dvp;
931 struct cnode *dcp = VTOC(dvp);
932 struct vnode **vpp = ap->a_vpp;
934 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
935 * of the string to xlate, and that we must try to get at least
936 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
939 struct componentname *cnp = ap->a_cnp;
940 struct ucred *cred = cnp->cn_cred;
941 struct thread *td = cnp->cn_td;
944 const char *nm = cnp->cn_nameptr;
945 int len = cnp->cn_namelen;
950 MARK_ENTRY(CODA_LOOKUP_STATS);
952 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
953 nm, dcp->c_fid.Volume,
954 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
956 /* Check for lookup of control object. */
957 if (IS_CTL_NAME(dvp, nm, len)) {
960 MARK_INT_SAT(CODA_LOOKUP_STATS);
964 if (len+1 > CODA_MAXNAMLEN) {
965 MARK_INT_FAIL(CODA_LOOKUP_STATS);
966 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
967 dcp->c_fid.Volume, dcp->c_fid.Vnode,
968 dcp->c_fid.Unique, nm)););
969 *vpp = (struct vnode *)0;
973 /* First try to look the file up in the cfs name cache */
974 /* lock the parent vnode? */
975 cp = coda_nc_lookup(dcp, nm, len, cred);
979 CODADEBUG(CODA_LOOKUP,
980 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
983 /* The name wasn't cached, so we need to contact Venus */
984 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
987 MARK_INT_FAIL(CODA_LOOKUP_STATS);
988 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
989 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
990 *vpp = (struct vnode *)0;
992 MARK_INT_SAT(CODA_LOOKUP_STATS);
993 CODADEBUG(CODA_LOOKUP,
994 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
995 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
998 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1001 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1002 /* And don't enter a new vnode for an invalid one! */
1003 if (!(vtype & CODA_NOCACHE))
1004 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1010 * If we are creating, and this was the last name to be looked up,
1011 * and the error was ENOENT, then there really shouldn't be an
1012 * error and we can make the leaf NULL and return success. Since
1013 * this is supposed to work under Mach as well as NetBSD, we're
1014 * leaving this fn wrapped. We also must tell lookup/namei that
1015 * we need to save the last component of the name. (Create will
1016 * have to free the name buffer later...lucky us...)
1018 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1021 error = EJUSTRETURN;
1026 * If the lookup went well, we need to (potentially?) unlock the
1027 * parent, and lock the child. We are only responsible for
1028 * checking to see if the parent is supposed to be unlocked before
1029 * we return. We must always lock the child (provided there is
1030 * one, and (the parent isn't locked or it isn't the same as the
1031 * parent.) Simple, huh? We can never leave the parent locked unless
1034 if (!error || (error == EJUSTRETURN)) {
1035 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
1036 if ((error = VOP_UNLOCK(dvp, 0, td))) {
1040 * The parent is unlocked. As long as there is a child,
1041 * lock it without bothering to check anything else.
1044 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1045 printf("coda_lookup: ");
1046 panic("unlocked parent but couldn't lock child");
1050 /* The parent is locked, and may be the same as the child */
1051 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1052 /* Different, go ahead and lock it. */
1053 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1054 printf("coda_lookup: ");
1055 panic("unlocked parent but couldn't lock child");
1060 /* If the lookup failed, we need to ensure that the leaf is NULL */
1061 /* Don't change any locking? */
1069 coda_create(void *v)
1072 struct vop_create_args *ap = v;
1073 struct vnode *dvp = ap->a_dvp;
1074 struct cnode *dcp = VTOC(dvp);
1075 struct vattr *va = ap->a_vap;
1077 int mode = ap->a_vap->va_mode;
1078 struct vnode **vpp = ap->a_vpp;
1079 struct componentname *cnp = ap->a_cnp;
1080 struct ucred *cred = cnp->cn_cred;
1081 struct thread *td = cnp->cn_td;
1085 const char *nm = cnp->cn_nameptr;
1086 int len = cnp->cn_namelen;
1090 MARK_ENTRY(CODA_CREATE_STATS);
1092 /* All creates are exclusive XXX */
1093 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1095 /* Check for create of control object. */
1096 if (IS_CTL_NAME(dvp, nm, len)) {
1097 *vpp = (struct vnode *)0;
1098 MARK_INT_FAIL(CODA_CREATE_STATS);
1102 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
1106 /* If this is an exclusive create, panic if the file already exists. */
1107 /* Venus should have detected the file and reported EEXIST. */
1109 if ((exclusive == 1) &&
1110 (coda_find(&VFid) != NULL))
1111 panic("cnode existed for newly created file!");
1113 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1116 /* Update va to reflect the new attributes. */
1119 /* Update the attribute cache and mark it as valid */
1120 if (coda_attr_cache) {
1121 VTOC(*vpp)->c_vattr = attr;
1122 VTOC(*vpp)->c_flags |= C_VATTR;
1125 /* Invalidate the parent's attr cache, the modification time has changed */
1126 VTOC(dvp)->c_flags &= ~C_VATTR;
1128 /* enter the new vnode in the Name Cache */
1129 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1131 CODADEBUG(CODA_CREATE,
1132 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1133 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1135 *vpp = (struct vnode *)0;
1136 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1140 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1141 printf("coda_create: ");
1142 panic("unlocked parent but couldn't lock child");
1149 coda_remove(void *v)
1152 struct vop_remove_args *ap = v;
1153 struct vnode *dvp = ap->a_dvp;
1154 struct cnode *cp = VTOC(dvp);
1155 struct componentname *cnp = ap->a_cnp;
1156 struct ucred *cred = cnp->cn_cred;
1157 struct thread *td = cnp->cn_td;
1160 const char *nm = cnp->cn_nameptr;
1161 int len = cnp->cn_namelen;
1164 MARK_ENTRY(CODA_REMOVE_STATS);
1166 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1167 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1168 cp->c_fid.Unique)););
1170 /* Remove the file's entry from the CODA Name Cache */
1171 /* We're being conservative here, it might be that this person
1172 * doesn't really have sufficient access to delete the file
1173 * but we feel zapping the entry won't really hurt anyone -- dcs
1175 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1176 * exist, and one is removed, the link count on the other will be
1177 * off by 1. We could either invalidate the attrs if cached, or
1178 * fix them. I'll try to fix them. DCS 11/8/94
1180 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1182 if (VALID_VATTR(tp)) { /* If attrs are cached */
1183 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1184 tp->c_vattr.va_nlink--;
1188 coda_nc_zapfile(VTOC(dvp), nm, len);
1189 /* No need to flush it if it doesn't exist! */
1191 /* Invalidate the parent's attr cache, the modification time has changed */
1192 VTOC(dvp)->c_flags &= ~C_VATTR;
1194 /* Check for remove of control object. */
1195 if (IS_CTL_NAME(dvp, nm, len)) {
1196 MARK_INT_FAIL(CODA_REMOVE_STATS);
1200 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
1202 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1211 struct vop_link_args *ap = v;
1212 struct vnode *vp = ap->a_vp;
1213 struct cnode *cp = VTOC(vp);
1214 struct vnode *tdvp = ap->a_tdvp;
1215 struct cnode *tdcp = VTOC(tdvp);
1216 struct componentname *cnp = ap->a_cnp;
1217 struct ucred *cred = cnp->cn_cred;
1218 struct thread *td = cnp->cn_td;
1221 const char *nm = cnp->cn_nameptr;
1222 int len = cnp->cn_namelen;
1224 MARK_ENTRY(CODA_LINK_STATS);
1226 if (codadebug & CODADBGMSK(CODA_LINK)) {
1228 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1229 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1230 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1231 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1234 if (codadebug & CODADBGMSK(CODA_LINK)) {
1235 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1236 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1237 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1238 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1242 /* Check for link to/from control object. */
1243 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1244 MARK_INT_FAIL(CODA_LINK_STATS);
1248 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
1250 /* Invalidate the parent's attr cache, the modification time has changed */
1251 VTOC(tdvp)->c_flags &= ~C_VATTR;
1252 VTOC(vp)->c_flags &= ~C_VATTR;
1254 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1260 coda_rename(void *v)
1263 struct vop_rename_args *ap = v;
1264 struct vnode *odvp = ap->a_fdvp;
1265 struct cnode *odcp = VTOC(odvp);
1266 struct componentname *fcnp = ap->a_fcnp;
1267 struct vnode *ndvp = ap->a_tdvp;
1268 struct cnode *ndcp = VTOC(ndvp);
1269 struct componentname *tcnp = ap->a_tcnp;
1270 struct ucred *cred = fcnp->cn_cred;
1271 struct thread *td = fcnp->cn_td;
1274 const char *fnm = fcnp->cn_nameptr;
1275 int flen = fcnp->cn_namelen;
1276 const char *tnm = tcnp->cn_nameptr;
1277 int tlen = tcnp->cn_namelen;
1279 MARK_ENTRY(CODA_RENAME_STATS);
1281 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1282 This could be Bad. XXX */
1283 #ifdef OLD_DIAGNOSTIC
1284 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
1286 panic("coda_rename: component names don't agree");
1290 /* Check for rename involving control object. */
1291 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1292 MARK_INT_FAIL(CODA_RENAME_STATS);
1296 /* Problem with moving directories -- need to flush entry for .. */
1298 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1300 struct vnode *ovp = CTOV(ovcp);
1302 (ovp->v_type == VDIR)) /* If it's a directory */
1303 coda_nc_zapfile(VTOC(ovp),"..", 2);
1307 /* Remove the entries for both source and target files */
1308 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1309 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1311 /* Invalidate the parent's attr cache, the modification time has changed */
1312 VTOC(odvp)->c_flags &= ~C_VATTR;
1313 VTOC(ndvp)->c_flags &= ~C_VATTR;
1315 if (flen+1 > CODA_MAXNAMLEN) {
1316 MARK_INT_FAIL(CODA_RENAME_STATS);
1321 if (tlen+1 > CODA_MAXNAMLEN) {
1322 MARK_INT_FAIL(CODA_RENAME_STATS);
1327 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
1330 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1332 /* It seems to be incumbent on us to drop locks on all four vnodes */
1333 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1339 if (ap->a_tvp == ndvp) {
1354 struct vop_mkdir_args *ap = v;
1355 struct vnode *dvp = ap->a_dvp;
1356 struct cnode *dcp = VTOC(dvp);
1357 struct componentname *cnp = ap->a_cnp;
1358 struct vattr *va = ap->a_vap;
1359 struct vnode **vpp = ap->a_vpp;
1360 struct ucred *cred = cnp->cn_cred;
1361 struct thread *td = cnp->cn_td;
1364 const char *nm = cnp->cn_nameptr;
1365 int len = cnp->cn_namelen;
1370 MARK_ENTRY(CODA_MKDIR_STATS);
1372 /* Check for mkdir of target object. */
1373 if (IS_CTL_NAME(dvp, nm, len)) {
1374 *vpp = (struct vnode *)0;
1375 MARK_INT_FAIL(CODA_MKDIR_STATS);
1379 if (len+1 > CODA_MAXNAMLEN) {
1380 *vpp = (struct vnode *)0;
1381 MARK_INT_FAIL(CODA_MKDIR_STATS);
1385 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
1388 if (coda_find(&VFid) != NULL)
1389 panic("cnode existed for newly created directory!");
1392 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1395 /* enter the new vnode in the Name Cache */
1396 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1398 /* as a side effect, enter "." and ".." for the directory */
1399 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1400 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1402 if (coda_attr_cache) {
1403 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1404 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1407 /* Invalidate the parent's attr cache, the modification time has changed */
1408 VTOC(dvp)->c_flags &= ~C_VATTR;
1410 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1411 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1413 *vpp = (struct vnode *)0;
1414 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1424 struct vop_rmdir_args *ap = v;
1425 struct vnode *dvp = ap->a_dvp;
1426 struct cnode *dcp = VTOC(dvp);
1427 struct componentname *cnp = ap->a_cnp;
1428 struct ucred *cred = cnp->cn_cred;
1429 struct thread *td = cnp->cn_td;
1432 const char *nm = cnp->cn_nameptr;
1433 int len = cnp->cn_namelen;
1436 MARK_ENTRY(CODA_RMDIR_STATS);
1438 /* Check for rmdir of control object. */
1439 if (IS_CTL_NAME(dvp, nm, len)) {
1440 MARK_INT_FAIL(CODA_RMDIR_STATS);
1444 /* We're being conservative here, it might be that this person
1445 * doesn't really have sufficient access to delete the file
1446 * but we feel zapping the entry won't really hurt anyone -- dcs
1449 * As a side effect of the rmdir, remove any entries for children of
1450 * the directory, especially "." and "..".
1452 cp = coda_nc_lookup(dcp, nm, len, cred);
1453 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1455 /* Remove the file's entry from the CODA Name Cache */
1456 coda_nc_zapfile(dcp, nm, len);
1458 /* Invalidate the parent's attr cache, the modification time has changed */
1459 dcp->c_flags &= ~C_VATTR;
1461 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
1463 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1469 coda_symlink(void *v)
1472 struct vop_symlink_args *ap = v;
1473 struct vnode *tdvp = ap->a_dvp;
1474 struct cnode *tdcp = VTOC(tdvp);
1475 struct componentname *cnp = ap->a_cnp;
1476 struct vattr *tva = ap->a_vap;
1477 char *path = ap->a_target;
1478 struct ucred *cred = cnp->cn_cred;
1479 struct thread *td = cnp->cn_td;
1480 struct vnode **vpp = ap->a_vpp;
1484 * XXX I'm assuming the following things about coda_symlink's
1486 * t(foo) is the new name/parent/etc being created.
1487 * lname is the contents of the new symlink.
1489 char *nm = cnp->cn_nameptr;
1490 int len = cnp->cn_namelen;
1491 int plen = strlen(path);
1494 * Here's the strategy for the moment: perform the symlink, then
1495 * do a lookup to grab the resulting vnode. I know this requires
1496 * two communications with Venus for a new sybolic link, but
1497 * that's the way the ball bounces. I don't yet want to change
1498 * the way the Mach symlink works. When Mach support is
1499 * deprecated, we should change symlink so that the common case
1500 * returns the resultant vnode in a vpp argument.
1503 MARK_ENTRY(CODA_SYMLINK_STATS);
1505 /* Check for symlink of control object. */
1506 if (IS_CTL_NAME(tdvp, nm, len)) {
1507 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1511 if (plen+1 > CODA_MAXPATHLEN) {
1512 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1516 if (len+1 > CODA_MAXNAMLEN) {
1517 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1522 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
1524 /* Invalidate the parent's attr cache, the modification time has changed */
1525 tdcp->c_flags &= ~C_VATTR;
1528 error = VOP_LOOKUP(tdvp, vpp, cnp);
1531 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1536 * Read directory entries.
1539 coda_readdir(void *v)
1542 struct vop_readdir_args *ap = v;
1543 struct vnode *vp = ap->a_vp;
1544 struct cnode *cp = VTOC(vp);
1545 struct uio *uiop = ap->a_uio;
1546 struct ucred *cred = ap->a_cred;
1547 int *eofflag = ap->a_eofflag;
1548 u_long **cookies = ap->a_cookies;
1549 int *ncookies = ap->a_ncookies;
1550 struct thread *td = ap->a_uio->uio_td;
1555 MARK_ENTRY(CODA_READDIR_STATS);
1557 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1558 (void *)uiop->uio_iov->iov_base,
1560 (long long)uiop->uio_offset,
1561 uiop->uio_segflg)); )
1563 /* Check for readdir of control object. */
1564 if (IS_CTL_VP(vp)) {
1565 MARK_INT_FAIL(CODA_READDIR_STATS);
1570 /* If directory is not already open do an "internal open" on it. */
1571 int opened_internally = 0;
1572 if (cp->c_ovp == NULL) {
1573 opened_internally = 1;
1574 MARK_INT_GEN(CODA_OPEN_STATS);
1575 error = VOP_OPEN(vp, FREAD, cred, NULL, td);
1576 printf("coda_readdir: Internally Opening %p\n", vp);
1578 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1581 if (vp->v_type == VREG) {
1582 error = vfs_object_create(vp, td);
1584 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1588 if (error) return(error);
1591 /* Have UFS handle the call. */
1592 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)); )
1593 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1597 MARK_INT_FAIL(CODA_READDIR_STATS);
1599 MARK_INT_SAT(CODA_READDIR_STATS);
1601 /* Do an "internal close" if necessary. */
1602 if (opened_internally) {
1603 MARK_INT_GEN(CODA_CLOSE_STATS);
1604 (void)VOP_CLOSE(vp, FREAD, td);
1612 * Convert from file system blocks to device blocks
1617 /* XXX on the global proc */
1619 struct vop_bmap_args *ap = v;
1620 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1621 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1622 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1623 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1633 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1635 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1636 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1641 printf("coda_bmap: no container\n");
1648 * I don't think the following two things are used anywhere, so I've
1649 * commented them out
1651 * struct buf *async_bufhead;
1652 * int async_daemon_count;
1655 coda_strategy(void *v)
1658 struct vop_strategy_args *ap = v;
1659 struct buf *bp __attribute__((unused)) = ap->a_bp;
1663 printf("coda_strategy: called ???\n");
1668 coda_reclaim(void *v)
1671 struct vop_reclaim_args *ap = v;
1672 struct vnode *vp = ap->a_vp;
1673 struct cnode *cp = VTOC(vp);
1678 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1682 if (IS_UNMOUNTING(cp)) {
1684 if (VTOC(vp)->c_ovp) {
1685 if (IS_UNMOUNTING(cp))
1686 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1690 #ifdef OLD_DIAGNOSTIC
1691 if (vp->v_usecount != 0)
1692 print("coda_reclaim: pushing active %p\n", vp);
1693 if (VTOC(vp)->c_ovp) {
1694 panic("coda_reclaim: c_ovp not void");
1698 coda_free(VTOC(vp));
1707 struct vop_lock_args *ap = v;
1708 struct vnode *vp = ap->a_vp;
1709 struct cnode *cp = VTOC(vp);
1710 struct thread *td = ap->a_td;
1716 if (coda_lockdebug) {
1717 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1718 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1722 return (lockmgr(&vp->v_lock, ap->a_flags, NULL, td));
1724 return (debuglockmgr(&vp->v_lock, ap->a_flags, NULL, td,
1725 "coda_lock", vp->filename, vp->line));
1730 coda_unlock(void *v)
1733 struct vop_unlock_args *ap = v;
1734 struct vnode *vp = ap->a_vp;
1735 struct cnode *cp = VTOC(vp);
1736 struct thread *td = ap->a_td;
1741 if (coda_lockdebug) {
1742 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1743 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1746 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, NULL, td));
1750 coda_islocked(void *v)
1753 struct vop_islocked_args *ap = v;
1756 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
1759 /* How one looks up a vnode given a device/inode pair: */
1761 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1763 /* This is like VFS_VGET() or igetinode()! */
1767 if (!(mp = devtomp(dev))) {
1768 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1769 (u_long)dev2udev(dev)));
1773 /* XXX - ensure that nonzero-return means failure */
1774 error = VFS_VGET(mp,ino,vpp);
1776 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1777 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1784 print_vattr(struct vattr *attr)
1788 switch (attr->va_type) {
1822 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1823 typestr, (int)attr->va_mode, (int)attr->va_uid,
1824 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1826 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1827 (int)attr->va_fileid, (int)attr->va_nlink,
1829 (int)attr->va_blocksize,(int)attr->va_bytes));
1830 myprintf((" gen %ld flags %ld vaflags %d\n",
1831 attr->va_gen, attr->va_flags, attr->va_vaflags));
1832 myprintf((" atime sec %d nsec %d\n",
1833 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1834 myprintf((" mtime sec %d nsec %d\n",
1835 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1836 myprintf((" ctime sec %d nsec %d\n",
1837 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1840 /* How to print a ucred */
1842 print_cred(struct ucred *cred)
1847 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1849 for (i=0; i < cred->cr_ngroups; i++)
1850 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1856 * Return a vnode for the given fid.
1857 * If no cnode exists for this fid create one and put it
1858 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1859 * this fid is already in the table return it (ref count is
1860 * incremented by coda_find. The cnode will be flushed from the
1861 * table when coda_inactive calls coda_unsave.
1864 make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
1869 if ((cp = coda_find(fid)) == NULL) {
1875 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
1877 panic("coda: getnewvnode returned error %d\n", err);