coda_vnops.c revision 54444
138625Srvb/* 238759Srvb * 338759Srvb * Coda: an Experimental Distributed File System 438759Srvb * Release 3.1 538759Srvb * 638759Srvb * Copyright (c) 1987-1998 Carnegie Mellon University 738759Srvb * All Rights Reserved 838759Srvb * 938759Srvb * Permission to use, copy, modify and distribute this software and its 1038759Srvb * documentation is hereby granted, provided that both the copyright 1138759Srvb * notice and this permission notice appear in all copies of the 1238759Srvb * software, derivative works or modified versions, and any portions 1338759Srvb * thereof, and that both notices appear in supporting documentation, and 1438759Srvb * that credit is given to Carnegie Mellon University in all documents 1538759Srvb * and publicity pertaining to direct or indirect use of this code or its 1638759Srvb * derivatives. 1738759Srvb * 1838759Srvb * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, 1938759Srvb * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS 2038759Srvb * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON 2138759Srvb * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER 2238759Srvb * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF 2338759Srvb * ANY DERIVATIVE WORK. 2438759Srvb * 2538759Srvb * Carnegie Mellon encourages users of this software to return any 2638759Srvb * improvements or extensions that they make, and to grant Carnegie 2738759Srvb * Mellon the rights to redistribute these changes without encumbrance. 2838759Srvb * 2939126Srvb * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ 3050477Speter * $FreeBSD: head/sys/fs/coda/coda_vnops.c 54444 1999-12-11 16:13:02Z eivind $ 3138759Srvb * 3238759Srvb */ 3338625Srvb 3438625Srvb/* 3538625Srvb * Mach Operating System 3638625Srvb * Copyright (c) 1990 Carnegie-Mellon University 3738625Srvb * Copyright (c) 1989 Carnegie-Mellon University 3838625Srvb * All rights reserved. The CMU software License Agreement specifies 3938625Srvb * the terms and conditions for use and redistribution. 4038625Srvb */ 4138625Srvb 4238625Srvb/* 4338625Srvb * This code was written for the Coda file system at Carnegie Mellon 4438625Srvb * University. Contributers include David Steere, James Kistler, and 4538625Srvb * M. Satyanarayanan. 4638625Srvb */ 4738625Srvb 4838625Srvb#include <sys/param.h> 4938625Srvb#include <sys/systm.h> 5038759Srvb#include <sys/kernel.h> 5138759Srvb#include <sys/proc.h> 5238625Srvb#include <sys/malloc.h> 5338759Srvb#include <sys/mount.h> 5438625Srvb#include <sys/errno.h> 5538625Srvb#include <sys/acct.h> 5638625Srvb#include <sys/file.h> 5738759Srvb#include <sys/fcntl.h> 5838625Srvb#include <sys/uio.h> 5938625Srvb#include <sys/namei.h> 6038625Srvb#include <sys/ioccom.h> 6138625Srvb#include <sys/select.h> 6238759Srvb 6338625Srvb#include <vm/vm.h> 6438625Srvb#include <vm/vm_object.h> 6538625Srvb#include <vm/vm_extern.h> 6638759Srvb#include <vm/vm_zone.h> 6738625Srvb 6839126Srvb#include <coda/coda.h> 6939126Srvb#include <coda/cnode.h> 7039126Srvb#include <coda/coda_vnops.h> 7139126Srvb#include <coda/coda_venus.h> 7239126Srvb#include <coda/coda_opstats.h> 7339126Srvb#include <coda/coda_subr.h> 7439126Srvb#include <coda/coda_namecache.h> 7539126Srvb#include <coda/coda_pioctl.h> 7638625Srvb 7738625Srvb/* 7838625Srvb * These flags select various performance enhancements. 7938625Srvb */ 8039085Srvbint coda_attr_cache = 1; /* Set to cache attributes in the kernel */ 8139085Srvbint coda_symlink_cache = 1; /* Set to cache symbolic link information */ 8239085Srvbint coda_access_cache = 1; /* Set to handle some access checks directly */ 8338625Srvb 8438625Srvb/* structure to keep track of vfs calls */ 8538625Srvb 8639085Srvbstruct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE]; 8738625Srvb 8839085Srvb#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++) 8939085Srvb#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++) 9039085Srvb#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++) 9139085Srvb#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++) 9238625Srvb 9338625Srvb/* What we are delaying for in printf */ 9439085Srvbint coda_printf_delay = 0; /* in microseconds */ 9539085Srvbint coda_vnop_print_entry = 0; 9639085Srvbstatic int coda_lockdebug = 0; 9738625Srvb 9838625Srvb/* Definition of the vfs operation vector */ 9938625Srvb 10038625Srvb/* 10138625Srvb * Some NetBSD details: 10238625Srvb * 10339085Srvb * coda_start is called at the end of the mount syscall. 10439085Srvb * coda_init is called at boot time. 10538625Srvb */ 10638625Srvb 10739085Srvb#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__)) 10838625Srvb 10938625Srvb/* Definition of the vnode operation vector */ 11038625Srvb 11139085Srvbstruct vnodeopv_entry_desc coda_vnodeop_entries[] = { 11239085Srvb { &vop_default_desc, coda_vop_error }, 11339085Srvb { &vop_lookup_desc, coda_lookup }, /* lookup */ 11439085Srvb { &vop_create_desc, coda_create }, /* create */ 11539650Srvb { &vop_mknod_desc, coda_vop_error }, /* mknod */ 11639085Srvb { &vop_open_desc, coda_open }, /* open */ 11739085Srvb { &vop_close_desc, coda_close }, /* close */ 11839085Srvb { &vop_access_desc, coda_access }, /* access */ 11939650Srvb { &vop_getattr_desc, coda_getattr }, /* getattr */ 12039650Srvb { &vop_setattr_desc, coda_setattr }, /* setattr */ 12139085Srvb { &vop_read_desc, coda_read }, /* read */ 12239085Srvb { &vop_write_desc, coda_write }, /* write */ 12339085Srvb { &vop_ioctl_desc, coda_ioctl }, /* ioctl */ 12439650Srvb { &vop_mmap_desc, coda_vop_error }, /* mmap */ 12539085Srvb { &vop_fsync_desc, coda_fsync }, /* fsync */ 12639085Srvb { &vop_remove_desc, coda_remove }, /* remove */ 12739085Srvb { &vop_link_desc, coda_link }, /* link */ 12839085Srvb { &vop_rename_desc, coda_rename }, /* rename */ 12939085Srvb { &vop_mkdir_desc, coda_mkdir }, /* mkdir */ 13039085Srvb { &vop_rmdir_desc, coda_rmdir }, /* rmdir */ 13139650Srvb { &vop_symlink_desc, coda_symlink }, /* symlink */ 13239650Srvb { &vop_readdir_desc, coda_readdir }, /* readdir */ 13339085Srvb { &vop_readlink_desc, coda_readlink }, /* readlink */ 13439650Srvb { &vop_abortop_desc, coda_abortop }, /* abortop */ 13539085Srvb { &vop_inactive_desc, coda_inactive }, /* inactive */ 13639650Srvb { &vop_reclaim_desc, coda_reclaim }, /* reclaim */ 13739085Srvb { &vop_lock_desc, coda_lock }, /* lock */ 13839085Srvb { &vop_unlock_desc, coda_unlock }, /* unlock */ 13939085Srvb { &vop_bmap_desc, coda_bmap }, /* bmap */ 14039085Srvb { &vop_strategy_desc, coda_strategy }, /* strategy */ 14139650Srvb { &vop_print_desc, coda_vop_error }, /* print */ 14239085Srvb { &vop_islocked_desc, coda_islocked }, /* islocked */ 14339650Srvb { &vop_pathconf_desc, coda_vop_error }, /* pathconf */ 14439650Srvb { &vop_advlock_desc, coda_vop_nop }, /* advlock */ 14539650Srvb { &vop_bwrite_desc, coda_vop_error }, /* bwrite */ 14639650Srvb { &vop_lease_desc, coda_vop_nop }, /* lease */ 14738759Srvb { &vop_poll_desc, (vop_t *) vop_stdpoll }, 14839085Srvb { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/ 14939085Srvb { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/ 15038625Srvb 15138759Srvb#if 0 15238625Srvb 15338759Srvb we need to define these someday 15438625Srvb#define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd) 15538625Srvb#define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd) 15638625Srvb#define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc) 15738625Srvb#define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee) 15842374Sbde#define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb) 15938625Srvb 16038625Srvb missing 16138625Srvb { &vop_reallocblks_desc, (vop_t *) ufs_missingop }, 16238625Srvb { &vop_cachedlookup_desc, (vop_t *) ufs_lookup }, 16338625Srvb { &vop_whiteout_desc, (vop_t *) ufs_whiteout }, 16438625Srvb#endif 16538625Srvb { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL } 16638625Srvb}; 16738625Srvb 16839085Srvbstatic struct vnodeopv_desc coda_vnodeop_opv_desc = 16939085Srvb { &coda_vnodeop_p, coda_vnodeop_entries }; 17038625Srvb 17139085SrvbVNODEOP_SET(coda_vnodeop_opv_desc); 17238625Srvb 17338625Srvb/* A generic panic: we were called with something we didn't define yet */ 17438625Srvbint 17539085Srvbcoda_vop_error(void *anon) { 17638625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 17738625Srvb 17841202Srvb myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n", 17938625Srvb (*desc)->vdesc_name)); 18041202Srvb /* 18139085Srvb panic("coda_vop_error"); 18241202Srvb */ 18341202Srvb return EIO; 18438625Srvb} 18538625Srvb 18638625Srvb/* A generic do-nothing. For lease_check, advlock */ 18738625Srvbint 18839085Srvbcoda_vop_nop(void *anon) { 18938625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 19038625Srvb 19139085Srvb if (codadebug) { 19238625Srvb myprintf(("Vnode operation %s called, but unsupported\n", 19338625Srvb (*desc)->vdesc_name)); 19438625Srvb } 19538625Srvb return (0); 19638625Srvb} 19738625Srvb 19838625Srvbint 19939085Srvbcoda_vnodeopstats_init(void) 20038625Srvb{ 20138625Srvb register int i; 20238625Srvb 20339085Srvb for(i=0;i<CODA_VNODEOPS_SIZE;i++) { 20439085Srvb coda_vnodeopstats[i].opcode = i; 20539085Srvb coda_vnodeopstats[i].entries = 0; 20639085Srvb coda_vnodeopstats[i].sat_intrn = 0; 20739085Srvb coda_vnodeopstats[i].unsat_intrn = 0; 20839085Srvb coda_vnodeopstats[i].gen_intrn = 0; 20938625Srvb } 21038625Srvb return 0; 21138625Srvb} 21238625Srvb 21338625Srvb/* 21439085Srvb * coda_open calls Venus to return the device, inode pair of the cache 21539085Srvb * file holding the data. Using iget, coda_open finds the vnode of the 21638625Srvb * cache file, and then opens it. 21738625Srvb */ 21838625Srvbint 21939085Srvbcoda_open(v) 22038625Srvb void *v; 22138625Srvb{ 22238625Srvb /* 22338625Srvb * NetBSD can pass the O_EXCL flag in mode, even though the check 22438625Srvb * has already happened. Venus defensively assumes that if open 22538625Srvb * is passed the EXCL, it must be a bug. We strip the flag here. 22638625Srvb */ 22738625Srvb/* true args */ 22838625Srvb struct vop_open_args *ap = v; 22938625Srvb register struct vnode **vpp = &(ap->a_vp); 23038625Srvb struct cnode *cp = VTOC(*vpp); 23138625Srvb int flag = ap->a_mode & (~O_EXCL); 23238625Srvb struct ucred *cred = ap->a_cred; 23338625Srvb struct proc *p = ap->a_p; 23438625Srvb/* locals */ 23538625Srvb int error; 23638625Srvb struct vnode *vp; 23738625Srvb dev_t dev; 23838625Srvb ino_t inode; 23938625Srvb 24039085Srvb MARK_ENTRY(CODA_OPEN_STATS); 24138625Srvb 24238625Srvb /* Check for open of control file. */ 24338625Srvb if (IS_CTL_VP(*vpp)) { 24438625Srvb /* XXX */ 24538625Srvb /* if (WRITEABLE(flag)) */ 24638625Srvb if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { 24739085Srvb MARK_INT_FAIL(CODA_OPEN_STATS); 24838625Srvb return(EACCES); 24938625Srvb } 25039085Srvb MARK_INT_SAT(CODA_OPEN_STATS); 25138625Srvb return(0); 25238625Srvb } 25338625Srvb 25438625Srvb error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, p, &dev, &inode); 25538625Srvb if (error) 25638625Srvb return (error); 25738625Srvb if (!error) { 25849524Sbde CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n", 25949524Sbde (u_long)dev2udev(dev), (u_long)inode, 26049524Sbde error)); ) 26138625Srvb } 26238625Srvb 26338625Srvb /* Translate the <device, inode> pair for the cache file into 26438625Srvb an inode pointer. */ 26539085Srvb error = coda_grab_vnode(dev, inode, &vp); 26638625Srvb if (error) 26738625Srvb return (error); 26838625Srvb 26938759Srvb /* We get the vnode back locked. Needs unlocked */ 27038759Srvb VOP_UNLOCK(vp, 0, p); 27138625Srvb /* Keep a reference until the close comes in. */ 27238625Srvb vref(*vpp); 27338625Srvb 27438625Srvb /* Save the vnode pointer for the cache file. */ 27538625Srvb if (cp->c_ovp == NULL) { 27638625Srvb cp->c_ovp = vp; 27738625Srvb } else { 27838625Srvb if (cp->c_ovp != vp) 27939085Srvb panic("coda_open: cp->c_ovp != ITOV(ip)"); 28038625Srvb } 28138625Srvb cp->c_ocount++; 28238625Srvb 28338625Srvb /* Flush the attribute cached if writing the file. */ 28438625Srvb if (flag & FWRITE) { 28538625Srvb cp->c_owrite++; 28638625Srvb cp->c_flags &= ~C_VATTR; 28738625Srvb } 28838625Srvb 28938625Srvb /* Save the <device, inode> pair for the cache file to speed 29038625Srvb up subsequent page_read's. */ 29138625Srvb cp->c_device = dev; 29238625Srvb cp->c_inode = inode; 29338625Srvb 29438625Srvb /* Open the cache file. */ 29538625Srvb error = VOP_OPEN(vp, flag, cred, p); 29638625Srvb if (error) { 29739085Srvb printf("coda_open: VOP_OPEN on container failed %d\n", error); 29838625Srvb return (error); 29938625Srvb } 30039650Srvb/* grab (above) does this when it calls newvnode unless it's in the cache*/ 30138625Srvb if (vp->v_type == VREG) { 30242315Seivind error = vfs_object_create(vp, p, cred); 30338625Srvb if (error != 0) { 30439085Srvb printf("coda_open: vfs_object_create() returns %d\n", error); 30538625Srvb vput(vp); 30638625Srvb } 30738625Srvb } 30839650Srvb 30938625Srvb return(error); 31038625Srvb} 31138625Srvb 31238625Srvb/* 31338625Srvb * Close the cache file used for I/O and notify Venus. 31438625Srvb */ 31538625Srvbint 31639085Srvbcoda_close(v) 31738625Srvb void *v; 31838625Srvb{ 31938625Srvb/* true args */ 32038625Srvb struct vop_close_args *ap = v; 32138625Srvb struct vnode *vp = ap->a_vp; 32238625Srvb struct cnode *cp = VTOC(vp); 32338625Srvb int flag = ap->a_fflag; 32438625Srvb struct ucred *cred = ap->a_cred; 32538625Srvb struct proc *p = ap->a_p; 32638625Srvb/* locals */ 32738625Srvb int error; 32838625Srvb 32939085Srvb MARK_ENTRY(CODA_CLOSE_STATS); 33038625Srvb 33138625Srvb /* Check for close of control file. */ 33238625Srvb if (IS_CTL_VP(vp)) { 33339085Srvb MARK_INT_SAT(CODA_CLOSE_STATS); 33438625Srvb return(0); 33538625Srvb } 33638625Srvb 33738625Srvb if (IS_UNMOUNTING(cp)) { 33838625Srvb if (cp->c_ovp) { 33939728Srvb#ifdef CODA_VERBOSE 34039085Srvb printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n", 34138625Srvb vp->v_usecount, cp->c_ovp, vp, cp); 34239650Srvb#endif 34340708Srvb#ifdef hmm 34438625Srvb vgone(cp->c_ovp); 34540708Srvb#else 34640708Srvb VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */ 34740708Srvb vrele(cp->c_ovp); 34840708Srvb#endif 34938625Srvb } else { 35039728Srvb#ifdef CODA_VERBOSE 35139085Srvb printf("coda_close: NO container vp %p/cp %p\n", vp, cp); 35239650Srvb#endif 35338625Srvb } 35438625Srvb return ENODEV; 35538625Srvb } else { 35638625Srvb VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */ 35738625Srvb vrele(cp->c_ovp); 35838625Srvb } 35938625Srvb 36038625Srvb if (--cp->c_ocount == 0) 36138625Srvb cp->c_ovp = NULL; 36238625Srvb 36338625Srvb if (flag & FWRITE) /* file was opened for write */ 36438625Srvb --cp->c_owrite; 36538625Srvb 36638625Srvb error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, p); 36738625Srvb vrele(CTOV(cp)); 36838625Srvb 36939085Srvb CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); ) 37038625Srvb return(error); 37138625Srvb} 37238625Srvb 37338625Srvbint 37439085Srvbcoda_read(v) 37538625Srvb void *v; 37638625Srvb{ 37738625Srvb struct vop_read_args *ap = v; 37838625Srvb 37938625Srvb ENTRY; 38039085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, 38138625Srvb ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp)); 38238625Srvb} 38338625Srvb 38438625Srvbint 38539085Srvbcoda_write(v) 38638625Srvb void *v; 38738625Srvb{ 38838625Srvb struct vop_write_args *ap = v; 38938625Srvb 39038625Srvb ENTRY; 39139085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, 39238625Srvb ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp)); 39338625Srvb} 39438625Srvb 39538625Srvbint 39639085Srvbcoda_rdwr(vp, uiop, rw, ioflag, cred, p) 39738625Srvb struct vnode *vp; 39838625Srvb struct uio *uiop; 39938625Srvb enum uio_rw rw; 40038625Srvb int ioflag; 40138625Srvb struct ucred *cred; 40238625Srvb struct proc *p; 40338625Srvb{ 40438625Srvb/* upcall decl */ 40538625Srvb /* NOTE: container file operation!!! */ 40638625Srvb/* locals */ 40738625Srvb struct cnode *cp = VTOC(vp); 40838625Srvb struct vnode *cfvp = cp->c_ovp; 40938625Srvb int igot_internally = 0; 41038625Srvb int opened_internally = 0; 41138625Srvb int error = 0; 41238625Srvb 41339085Srvb MARK_ENTRY(CODA_RDWR_STATS); 41438625Srvb 41549524Sbde CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw, 41649524Sbde (void *)uiop->uio_iov->iov_base, uiop->uio_resid, 41749524Sbde (long long)uiop->uio_offset, uiop->uio_segflg)); ) 41838625Srvb 41938625Srvb /* Check for rdwr of control object. */ 42038625Srvb if (IS_CTL_VP(vp)) { 42139085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 42238625Srvb return(EINVAL); 42338625Srvb } 42438625Srvb 42538625Srvb /* 42638625Srvb * If file is not already open this must be a page 42738625Srvb * {read,write} request. Iget the cache file's inode 42838625Srvb * pointer if we still have its <device, inode> pair. 42938625Srvb * Otherwise, we must do an internal open to derive the 43038625Srvb * pair. 43138625Srvb */ 43238625Srvb if (cfvp == NULL) { 43338625Srvb /* 43438625Srvb * If we're dumping core, do the internal open. Otherwise 43538625Srvb * venus won't have the correct size of the core when 43638625Srvb * it's completely written. 43738625Srvb */ 43838625Srvb if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) { 43938625Srvb igot_internally = 1; 44039085Srvb error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp); 44138625Srvb if (error) { 44239085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 44338625Srvb return(error); 44438625Srvb } 44538625Srvb /* 44638625Srvb * We get the vnode back locked in both Mach and 44738625Srvb * NetBSD. Needs unlocked 44838625Srvb */ 44938759Srvb VOP_UNLOCK(cfvp, 0, p); 45038625Srvb } 45138625Srvb else { 45238625Srvb opened_internally = 1; 45339085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 45438625Srvb error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), 45538625Srvb cred, p); 45639085Srvbprintf("coda_rdwr: Internally Opening %p\n", vp); 45738625Srvb if (error) { 45839085Srvb printf("coda_rdwr: VOP_OPEN on container failed %d\n", error); 45938625Srvb return (error); 46038625Srvb } 46138625Srvb if (vp->v_type == VREG) { 46242315Seivind error = vfs_object_create(vp, p, cred); 46338625Srvb if (error != 0) { 46439085Srvb printf("coda_rdwr: vfs_object_create() returns %d\n", error); 46538625Srvb vput(vp); 46638625Srvb } 46738625Srvb } 46838625Srvb if (error) { 46939085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 47038625Srvb return(error); 47138625Srvb } 47238625Srvb cfvp = cp->c_ovp; 47338625Srvb } 47438625Srvb } 47538625Srvb 47638625Srvb /* Have UFS handle the call. */ 47739085Srvb CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n", 47838625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 47938625Srvb cp->c_fid.Unique, CTOV(cp)->v_usecount)); ) 48038625Srvb 48139650Srvb 48238625Srvb if (rw == UIO_READ) { 48338625Srvb error = VOP_READ(cfvp, uiop, ioflag, cred); 48438625Srvb } else { 48538625Srvb error = VOP_WRITE(cfvp, uiop, ioflag, cred); 48638625Srvb /* ufs_write updates the vnode_pager_setsize for the vnode/object */ 48739650Srvb 48838625Srvb { struct vattr attr; 48938625Srvb 49038625Srvb if (VOP_GETATTR(cfvp, &attr, cred, p) == 0) { 49138625Srvb vnode_pager_setsize(vp, attr.va_size); 49238625Srvb } 49338625Srvb } 49438625Srvb } 49538625Srvb 49638625Srvb if (error) 49739085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 49838625Srvb else 49939085Srvb MARK_INT_SAT(CODA_RDWR_STATS); 50038625Srvb 50138625Srvb /* Do an internal close if necessary. */ 50238625Srvb if (opened_internally) { 50339085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 50438625Srvb (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, p); 50538625Srvb } 50638625Srvb 50738625Srvb /* Invalidate cached attributes if writing. */ 50838625Srvb if (rw == UIO_WRITE) 50938625Srvb cp->c_flags &= ~C_VATTR; 51038625Srvb return(error); 51138625Srvb} 51238625Srvb 51338625Srvbint 51439085Srvbcoda_ioctl(v) 51538625Srvb void *v; 51638625Srvb{ 51738625Srvb/* true args */ 51838625Srvb struct vop_ioctl_args *ap = v; 51938625Srvb struct vnode *vp = ap->a_vp; 52038625Srvb int com = ap->a_command; 52138625Srvb caddr_t data = ap->a_data; 52238625Srvb int flag = ap->a_fflag; 52338625Srvb struct ucred *cred = ap->a_cred; 52438625Srvb struct proc *p = ap->a_p; 52538625Srvb/* locals */ 52638625Srvb int error; 52738625Srvb struct vnode *tvp; 52838625Srvb struct nameidata ndp; 52938625Srvb struct PioctlData *iap = (struct PioctlData *)data; 53038625Srvb 53139085Srvb MARK_ENTRY(CODA_IOCTL_STATS); 53238625Srvb 53339085Srvb CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));) 53438625Srvb 53538625Srvb /* Don't check for operation on a dying object, for ctlvp it 53638625Srvb shouldn't matter */ 53738625Srvb 53838625Srvb /* Must be control object to succeed. */ 53938625Srvb if (!IS_CTL_VP(vp)) { 54039085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 54139085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));) 54238625Srvb return (EOPNOTSUPP); 54338625Srvb } 54438625Srvb /* Look up the pathname. */ 54538625Srvb 54638625Srvb /* Should we use the name cache here? It would get it from 54738625Srvb lookupname sooner or later anyway, right? */ 54838625Srvb 54943382Sbde NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, p); 55038625Srvb error = namei(&ndp); 55138625Srvb tvp = ndp.ni_vp; 55238625Srvb 55338625Srvb if (error) { 55439085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 55539085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n", 55638625Srvb error));) 55738625Srvb return(error); 55838625Srvb } 55938625Srvb 56038625Srvb /* 56138625Srvb * Make sure this is a coda style cnode, but it may be a 56238625Srvb * different vfsp 56338625Srvb */ 56449687Sphk if (tvp->v_op != coda_vnodeop_p) { 56538625Srvb vrele(tvp); 56639085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 56739085Srvb CODADEBUG(CODA_IOCTL, 56839085Srvb myprintf(("coda_ioctl error: %s not a coda object\n", 56938625Srvb iap->path));) 57038625Srvb return(EINVAL); 57138625Srvb } 57238625Srvb 57338625Srvb if (iap->vi.in_size > VC_MAXDATASIZE) { 57438625Srvb vrele(tvp); 57538625Srvb return(EINVAL); 57638625Srvb } 57738625Srvb error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, p); 57838625Srvb 57938625Srvb if (error) 58039085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 58138625Srvb else 58239085Srvb CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); ) 58338625Srvb 58438625Srvb vrele(tvp); 58538625Srvb return(error); 58638625Srvb} 58738625Srvb 58838625Srvb/* 58938625Srvb * To reduce the cost of a user-level venus;we cache attributes in 59038625Srvb * the kernel. Each cnode has storage allocated for an attribute. If 59138625Srvb * c_vattr is valid, return a reference to it. Otherwise, get the 59238625Srvb * attributes from venus and store them in the cnode. There is some 59338625Srvb * question if this method is a security leak. But I think that in 59438625Srvb * order to make this call, the user must have done a lookup and 59538625Srvb * opened the file, and therefore should already have access. 59638625Srvb */ 59738625Srvbint 59839085Srvbcoda_getattr(v) 59938625Srvb void *v; 60038625Srvb{ 60138625Srvb/* true args */ 60238625Srvb struct vop_getattr_args *ap = v; 60338625Srvb struct vnode *vp = ap->a_vp; 60438625Srvb struct cnode *cp = VTOC(vp); 60538625Srvb struct vattr *vap = ap->a_vap; 60638625Srvb struct ucred *cred = ap->a_cred; 60738625Srvb struct proc *p = ap->a_p; 60838625Srvb/* locals */ 60938625Srvb int error; 61038625Srvb 61139085Srvb MARK_ENTRY(CODA_GETATTR_STATS); 61238625Srvb 61338625Srvb if (IS_UNMOUNTING(cp)) 61438625Srvb return ENODEV; 61538759Srvb 61638625Srvb /* Check for getattr of control object. */ 61738625Srvb if (IS_CTL_VP(vp)) { 61839085Srvb MARK_INT_FAIL(CODA_GETATTR_STATS); 61938625Srvb return(ENOENT); 62038625Srvb } 62138625Srvb 62238625Srvb /* Check to see if the attributes have already been cached */ 62338625Srvb if (VALID_VATTR(cp)) { 62439085Srvb CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n", 62538625Srvb cp->c_fid.Volume, 62638625Srvb cp->c_fid.Vnode, 62738625Srvb cp->c_fid.Unique));}); 62839085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 62938625Srvb print_vattr(&cp->c_vattr); ); 63038625Srvb 63138625Srvb *vap = cp->c_vattr; 63239085Srvb MARK_INT_SAT(CODA_GETATTR_STATS); 63338625Srvb return(0); 63438625Srvb } 63538625Srvb 63638625Srvb error = venus_getattr(vtomi(vp), &cp->c_fid, cred, p, vap); 63738625Srvb 63838625Srvb if (!error) { 63939085Srvb CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n", 64038625Srvb cp->c_fid.Volume, 64138625Srvb cp->c_fid.Vnode, 64238625Srvb cp->c_fid.Unique, 64338625Srvb error)); ) 64438625Srvb 64539085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 64638625Srvb print_vattr(vap); ); 64738625Srvb 64838625Srvb { int size = vap->va_size; 64938625Srvb struct vnode *convp = cp->c_ovp; 65038625Srvb if (convp != (struct vnode *)0) { 65138625Srvb vnode_pager_setsize(convp, size); 65238625Srvb } 65338625Srvb } 65438625Srvb /* If not open for write, store attributes in cnode */ 65539085Srvb if ((cp->c_owrite == 0) && (coda_attr_cache)) { 65638625Srvb cp->c_vattr = *vap; 65738625Srvb cp->c_flags |= C_VATTR; 65838625Srvb } 65938625Srvb 66038625Srvb } 66138625Srvb return(error); 66238625Srvb} 66338625Srvb 66438625Srvbint 66539085Srvbcoda_setattr(v) 66638625Srvb void *v; 66738625Srvb{ 66838625Srvb/* true args */ 66938625Srvb struct vop_setattr_args *ap = v; 67038625Srvb register struct vnode *vp = ap->a_vp; 67138625Srvb struct cnode *cp = VTOC(vp); 67238625Srvb register struct vattr *vap = ap->a_vap; 67338625Srvb struct ucred *cred = ap->a_cred; 67438625Srvb struct proc *p = ap->a_p; 67538625Srvb/* locals */ 67638625Srvb int error; 67738625Srvb 67839085Srvb MARK_ENTRY(CODA_SETATTR_STATS); 67938625Srvb 68038625Srvb /* Check for setattr of control object. */ 68138625Srvb if (IS_CTL_VP(vp)) { 68239085Srvb MARK_INT_FAIL(CODA_SETATTR_STATS); 68338625Srvb return(ENOENT); 68438625Srvb } 68538625Srvb 68639085Srvb if (codadebug & CODADBGMSK(CODA_SETATTR)) { 68738625Srvb print_vattr(vap); 68838625Srvb } 68938625Srvb error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, p); 69038625Srvb 69138625Srvb if (!error) 69238625Srvb cp->c_flags &= ~C_VATTR; 69338625Srvb 69438625Srvb { int size = vap->va_size; 69538625Srvb struct vnode *convp = cp->c_ovp; 69638625Srvb if (size != VNOVAL && convp != (struct vnode *)0) { 69738625Srvb vnode_pager_setsize(convp, size); 69838625Srvb } 69938625Srvb } 70039085Srvb CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); ) 70138625Srvb return(error); 70238625Srvb} 70338625Srvb 70438625Srvbint 70539085Srvbcoda_access(v) 70638625Srvb void *v; 70738625Srvb{ 70838625Srvb/* true args */ 70938625Srvb struct vop_access_args *ap = v; 71038625Srvb struct vnode *vp = ap->a_vp; 71138625Srvb struct cnode *cp = VTOC(vp); 71238625Srvb int mode = ap->a_mode; 71338625Srvb struct ucred *cred = ap->a_cred; 71438625Srvb struct proc *p = ap->a_p; 71538625Srvb/* locals */ 71638625Srvb int error; 71738625Srvb 71839085Srvb MARK_ENTRY(CODA_ACCESS_STATS); 71938625Srvb 72038625Srvb /* Check for access of control object. Only read access is 72138625Srvb allowed on it. */ 72238625Srvb if (IS_CTL_VP(vp)) { 72338625Srvb /* bogus hack - all will be marked as successes */ 72439085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 72538625Srvb return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) 72638625Srvb ? 0 : EACCES); 72738625Srvb } 72838625Srvb 72938625Srvb /* 73038625Srvb * if the file is a directory, and we are checking exec (eg lookup) 73138625Srvb * access, and the file is in the namecache, then the user must have 73238625Srvb * lookup access to it. 73338625Srvb */ 73439085Srvb if (coda_access_cache) { 73538625Srvb if ((vp->v_type == VDIR) && (mode & VEXEC)) { 73639085Srvb if (coda_nc_lookup(cp, ".", 1, cred)) { 73739085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 73838625Srvb return(0); /* it was in the cache */ 73938625Srvb } 74038625Srvb } 74138625Srvb } 74238625Srvb 74338625Srvb error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, p); 74438625Srvb 74538625Srvb return(error); 74638625Srvb} 74738625Srvb 74838625Srvb/* 74939085Srvb * CODA abort op, called after namei() when a CREATE/DELETE isn't actually 75039085Srvb * done. If a buffer has been saved in anticipation of a coda_create or 75139085Srvb * a coda_remove, delete it. 75238625Srvb */ 75338625Srvb/* ARGSUSED */ 75438625Srvbint 75539085Srvbcoda_abortop(v) 75638625Srvb void *v; 75738625Srvb{ 75838625Srvb/* true args */ 75938625Srvb struct vop_abortop_args /* { 76038625Srvb struct vnode *a_dvp; 76138625Srvb struct componentname *a_cnp; 76238625Srvb } */ *ap = v; 76338625Srvb/* upcall decl */ 76438625Srvb/* locals */ 76538625Srvb 76638625Srvb if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF) 76738759Srvb zfree(namei_zone, ap->a_cnp->cn_pnbuf); 76838625Srvb return (0); 76938625Srvb} 77038625Srvb 77138625Srvbint 77239085Srvbcoda_readlink(v) 77338625Srvb void *v; 77438625Srvb{ 77538625Srvb/* true args */ 77638625Srvb struct vop_readlink_args *ap = v; 77738625Srvb struct vnode *vp = ap->a_vp; 77838625Srvb struct cnode *cp = VTOC(vp); 77938625Srvb struct uio *uiop = ap->a_uio; 78038625Srvb struct ucred *cred = ap->a_cred; 78138625Srvb struct proc *p = ap->a_uio->uio_procp; 78238625Srvb/* locals */ 78338625Srvb int error; 78438625Srvb char *str; 78538625Srvb int len; 78638625Srvb 78739085Srvb MARK_ENTRY(CODA_READLINK_STATS); 78838625Srvb 78938625Srvb /* Check for readlink of control object. */ 79038625Srvb if (IS_CTL_VP(vp)) { 79139085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 79238625Srvb return(ENOENT); 79338625Srvb } 79438625Srvb 79539085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */ 79638625Srvb uiop->uio_rw = UIO_READ; 79738625Srvb error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); 79838625Srvb if (error) 79939085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 80038625Srvb else 80139085Srvb MARK_INT_SAT(CODA_READLINK_STATS); 80238625Srvb return(error); 80338625Srvb } 80438625Srvb 80538625Srvb error = venus_readlink(vtomi(vp), &cp->c_fid, cred, p, &str, &len); 80638625Srvb 80738625Srvb if (!error) { 80838625Srvb uiop->uio_rw = UIO_READ; 80938625Srvb error = uiomove(str, len, uiop); 81038625Srvb 81139085Srvb if (coda_symlink_cache) { 81238625Srvb cp->c_symlink = str; 81338625Srvb cp->c_symlen = len; 81438625Srvb cp->c_flags |= C_SYMLINK; 81538625Srvb } else 81639085Srvb CODA_FREE(str, len); 81738625Srvb } 81838625Srvb 81939085Srvb CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));) 82038625Srvb return(error); 82138625Srvb} 82238625Srvb 82338625Srvbint 82439085Srvbcoda_fsync(v) 82538625Srvb void *v; 82638625Srvb{ 82738625Srvb/* true args */ 82838625Srvb struct vop_fsync_args *ap = v; 82938625Srvb struct vnode *vp = ap->a_vp; 83038625Srvb struct cnode *cp = VTOC(vp); 83138625Srvb struct ucred *cred = ap->a_cred; 83238625Srvb struct proc *p = ap->a_p; 83338625Srvb/* locals */ 83438625Srvb struct vnode *convp = cp->c_ovp; 83538625Srvb int error; 83638625Srvb 83739085Srvb MARK_ENTRY(CODA_FSYNC_STATS); 83838625Srvb 83938625Srvb /* Check for fsync on an unmounting object */ 84038625Srvb /* The NetBSD kernel, in it's infinite wisdom, can try to fsync 84138625Srvb * after an unmount has been initiated. This is a Bad Thing, 84238625Srvb * which we have to avoid. Not a legitimate failure for stats. 84338625Srvb */ 84438625Srvb if (IS_UNMOUNTING(cp)) { 84538625Srvb return(ENODEV); 84638625Srvb } 84738625Srvb 84838625Srvb /* Check for fsync of control object. */ 84938625Srvb if (IS_CTL_VP(vp)) { 85039085Srvb MARK_INT_SAT(CODA_FSYNC_STATS); 85138625Srvb return(0); 85238625Srvb } 85338625Srvb 85438625Srvb if (convp) 85538625Srvb VOP_FSYNC(convp, cred, MNT_WAIT, p); 85638625Srvb 85738625Srvb /* 85838625Srvb * We see fsyncs with usecount == 1 then usecount == 0. 85938625Srvb * For now we ignore them. 86038625Srvb */ 86138625Srvb /* 86238625Srvb if (!vp->v_usecount) { 86339085Srvb printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n", 86438625Srvb vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING); 86538625Srvb } 86638625Srvb */ 86738625Srvb 86838625Srvb /* 86938625Srvb * We can expect fsync on any vnode at all if venus is pruging it. 87038625Srvb * Venus can't very well answer the fsync request, now can it? 87138625Srvb * Hopefully, it won't have to, because hopefully, venus preserves 87238625Srvb * the (possibly untrue) invariant that it never purges an open 87338625Srvb * vnode. Hopefully. 87438625Srvb */ 87538625Srvb if (cp->c_flags & C_PURGING) { 87638625Srvb return(0); 87738625Srvb } 87838625Srvb 87938625Srvb /* needs research */ 88038625Srvb return 0; 88138625Srvb error = venus_fsync(vtomi(vp), &cp->c_fid, cred, p); 88238625Srvb 88339085Srvb CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); ); 88438625Srvb return(error); 88538625Srvb} 88638625Srvb 88738625Srvbint 88839085Srvbcoda_inactive(v) 88938625Srvb void *v; 89038625Srvb{ 89138625Srvb /* XXX - at the moment, inactive doesn't look at cred, and doesn't 89238625Srvb have a proc pointer. Oops. */ 89338625Srvb/* true args */ 89438625Srvb struct vop_inactive_args *ap = v; 89538625Srvb struct vnode *vp = ap->a_vp; 89638625Srvb struct cnode *cp = VTOC(vp); 89738625Srvb struct ucred *cred __attribute__((unused)) = NULL; 89838625Srvb struct proc *p __attribute__((unused)) = curproc; 89938625Srvb/* upcall decl */ 90038625Srvb/* locals */ 90138625Srvb 90238625Srvb /* We don't need to send inactive to venus - DCS */ 90339085Srvb MARK_ENTRY(CODA_INACTIVE_STATS); 90438625Srvb 90538625Srvb if (IS_CTL_VP(vp)) { 90639085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 90738625Srvb return 0; 90838625Srvb } 90938625Srvb 91039085Srvb CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n", 91138625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 91238625Srvb cp->c_fid.Unique, vp->v_mount));) 91338625Srvb 91438625Srvb /* If an array has been allocated to hold the symlink, deallocate it */ 91539085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { 91638625Srvb if (cp->c_symlink == NULL) 91739085Srvb panic("coda_inactive: null symlink pointer in cnode"); 91838625Srvb 91939085Srvb CODA_FREE(cp->c_symlink, cp->c_symlen); 92038625Srvb cp->c_flags &= ~C_SYMLINK; 92138625Srvb cp->c_symlen = 0; 92238625Srvb } 92338625Srvb 92438625Srvb /* Remove it from the table so it can't be found. */ 92539085Srvb coda_unsave(cp); 92639085Srvb if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) { 92738625Srvb myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp)); 92839085Srvb panic("badness in coda_inactive\n"); 92938625Srvb } 93038625Srvb 93138625Srvb if (IS_UNMOUNTING(cp)) { 93238625Srvb#ifdef DEBUG 93339085Srvb printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp); 93438625Srvb if (cp->c_ovp != NULL) 93539085Srvb printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n", 93638625Srvb vp->v_usecount, vp, cp); 93738625Srvb#endif 93838759Srvb lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, p); 93938625Srvb } else { 94039650Srvb#ifdef OLD_DIAGNOSTIC 94138625Srvb if (CTOV(cp)->v_usecount) { 94239085Srvb panic("coda_inactive: nonzero reference count"); 94338625Srvb } 94438625Srvb if (cp->c_ovp != NULL) { 94539085Srvb panic("coda_inactive: cp->ovp != NULL"); 94638625Srvb } 94738625Srvb#endif 94838759Srvb VOP_UNLOCK(vp, 0, p); 94938625Srvb vgone(vp); 95038625Srvb } 95138625Srvb 95239085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 95338625Srvb return(0); 95438625Srvb} 95538625Srvb 95638625Srvb/* 95738625Srvb * Remote file system operations having to do with directory manipulation. 95838625Srvb */ 95938625Srvb 96038625Srvb/* 96138625Srvb * It appears that in NetBSD, lookup is supposed to return the vnode locked 96238625Srvb */ 96338625Srvbint 96439085Srvbcoda_lookup(v) 96538625Srvb void *v; 96638625Srvb{ 96738625Srvb/* true args */ 96838625Srvb struct vop_lookup_args *ap = v; 96938625Srvb struct vnode *dvp = ap->a_dvp; 97038625Srvb struct cnode *dcp = VTOC(dvp); 97138625Srvb struct vnode **vpp = ap->a_vpp; 97238625Srvb /* 97338625Srvb * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest 97438625Srvb * of the string to xlate, and that we must try to get at least 97538625Srvb * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I 97638625Srvb * could be wrong. 97738625Srvb */ 97838625Srvb struct componentname *cnp = ap->a_cnp; 97938625Srvb struct ucred *cred = cnp->cn_cred; 98038625Srvb struct proc *p = cnp->cn_proc; 98138625Srvb/* locals */ 98238625Srvb struct cnode *cp; 98338625Srvb const char *nm = cnp->cn_nameptr; 98438625Srvb int len = cnp->cn_namelen; 98538625Srvb ViceFid VFid; 98638625Srvb int vtype; 98738625Srvb int error = 0; 98838625Srvb 98939085Srvb MARK_ENTRY(CODA_LOOKUP_STATS); 99038625Srvb 99139085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n", 99238625Srvb nm, dcp->c_fid.Volume, 99338625Srvb dcp->c_fid.Vnode, dcp->c_fid.Unique));); 99438625Srvb 99538625Srvb /* Check for lookup of control object. */ 99638625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 99739085Srvb *vpp = coda_ctlvp; 99838625Srvb vref(*vpp); 99939085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 100038625Srvb goto exit; 100138625Srvb } 100238625Srvb 100339085Srvb if (len+1 > CODA_MAXNAMLEN) { 100439085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 100539085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n", 100638625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, 100738625Srvb dcp->c_fid.Unique, nm));); 100838625Srvb *vpp = (struct vnode *)0; 100938625Srvb error = EINVAL; 101038625Srvb goto exit; 101138625Srvb } 101238625Srvb /* First try to look the file up in the cfs name cache */ 101338625Srvb /* lock the parent vnode? */ 101439085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 101538625Srvb if (cp) { 101638625Srvb *vpp = CTOV(cp); 101738625Srvb vref(*vpp); 101839085Srvb CODADEBUG(CODA_LOOKUP, 101938625Srvb myprintf(("lookup result %d vpp %p\n",error,*vpp));) 102038625Srvb } else { 102138625Srvb 102238625Srvb /* The name wasn't cached, so we need to contact Venus */ 102338625Srvb error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, p, &VFid, &vtype); 102438625Srvb 102538625Srvb if (error) { 102639085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 102739085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n", 102838625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));) 102938625Srvb *vpp = (struct vnode *)0; 103038625Srvb } else { 103139085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 103239085Srvb CODADEBUG(CODA_LOOKUP, 103338625Srvb myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n", 103438625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, vtype, 103538625Srvb error)); ) 103638625Srvb 103739085Srvb cp = make_coda_node(&VFid, dvp->v_mount, vtype); 103838625Srvb *vpp = CTOV(cp); 103938625Srvb 104038625Srvb /* enter the new vnode in the Name Cache only if the top bit isn't set */ 104138625Srvb /* And don't enter a new vnode for an invalid one! */ 104239085Srvb if (!(vtype & CODA_NOCACHE)) 104339085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 104438625Srvb } 104538625Srvb } 104638625Srvb 104738625Srvb exit: 104838625Srvb /* 104938625Srvb * If we are creating, and this was the last name to be looked up, 105038625Srvb * and the error was ENOENT, then there really shouldn't be an 105138625Srvb * error and we can make the leaf NULL and return success. Since 105238625Srvb * this is supposed to work under Mach as well as NetBSD, we're 105338625Srvb * leaving this fn wrapped. We also must tell lookup/namei that 105438625Srvb * we need to save the last component of the name. (Create will 105538625Srvb * have to free the name buffer later...lucky us...) 105638625Srvb */ 105738625Srvb if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) 105838625Srvb && (cnp->cn_flags & ISLASTCN) 105938625Srvb && (error == ENOENT)) 106038625Srvb { 106138625Srvb error = EJUSTRETURN; 106238625Srvb cnp->cn_flags |= SAVENAME; 106338625Srvb *ap->a_vpp = NULL; 106438625Srvb } 106538625Srvb 106638625Srvb /* 106738625Srvb * If we are removing, and we are at the last element, and we 106838625Srvb * found it, then we need to keep the name around so that the 106938625Srvb * removal will go ahead as planned. Unfortunately, this will 107038625Srvb * probably also lock the to-be-removed vnode, which may or may 107138625Srvb * not be a good idea. I'll have to look at the bits of 107239085Srvb * coda_remove to make sure. We'll only save the name if we did in 107339085Srvb * fact find the name, otherwise coda_remove won't have a chance 107438625Srvb * to free the pathname. 107538625Srvb */ 107638625Srvb if ((cnp->cn_nameiop == DELETE) 107738625Srvb && (cnp->cn_flags & ISLASTCN) 107838625Srvb && !error) 107938625Srvb { 108038625Srvb cnp->cn_flags |= SAVENAME; 108138625Srvb } 108238625Srvb 108338625Srvb /* 108438625Srvb * If the lookup went well, we need to (potentially?) unlock the 108538625Srvb * parent, and lock the child. We are only responsible for 108638625Srvb * checking to see if the parent is supposed to be unlocked before 108738625Srvb * we return. We must always lock the child (provided there is 108838625Srvb * one, and (the parent isn't locked or it isn't the same as the 108938625Srvb * parent.) Simple, huh? We can never leave the parent locked unless 109038625Srvb * we are ISLASTCN 109138625Srvb */ 109238625Srvb if (!error || (error == EJUSTRETURN)) { 109338625Srvb if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) { 109438759Srvb if ((error = VOP_UNLOCK(dvp, 0, p))) { 109538625Srvb return error; 109638625Srvb } 109738625Srvb /* 109838625Srvb * The parent is unlocked. As long as there is a child, 109938625Srvb * lock it without bothering to check anything else. 110038625Srvb */ 110138625Srvb if (*ap->a_vpp) { 110238759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 110339085Srvb printf("coda_lookup: "); 110438625Srvb panic("unlocked parent but couldn't lock child"); 110538625Srvb } 110638625Srvb } 110738625Srvb } else { 110838625Srvb /* The parent is locked, and may be the same as the child */ 110938625Srvb if (*ap->a_vpp && (*ap->a_vpp != dvp)) { 111038625Srvb /* Different, go ahead and lock it. */ 111138759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 111239085Srvb printf("coda_lookup: "); 111338625Srvb panic("unlocked parent but couldn't lock child"); 111438625Srvb } 111538625Srvb } 111638625Srvb } 111738625Srvb } else { 111838625Srvb /* If the lookup failed, we need to ensure that the leaf is NULL */ 111938625Srvb /* Don't change any locking? */ 112038625Srvb *ap->a_vpp = NULL; 112138625Srvb } 112238625Srvb return(error); 112338625Srvb} 112438625Srvb 112538625Srvb/*ARGSUSED*/ 112638625Srvbint 112739085Srvbcoda_create(v) 112838625Srvb void *v; 112938625Srvb{ 113038625Srvb/* true args */ 113138625Srvb struct vop_create_args *ap = v; 113238625Srvb struct vnode *dvp = ap->a_dvp; 113338625Srvb struct cnode *dcp = VTOC(dvp); 113438625Srvb struct vattr *va = ap->a_vap; 113538625Srvb int exclusive = 1; 113638625Srvb int mode = ap->a_vap->va_mode; 113738625Srvb struct vnode **vpp = ap->a_vpp; 113838625Srvb struct componentname *cnp = ap->a_cnp; 113938625Srvb struct ucred *cred = cnp->cn_cred; 114038625Srvb struct proc *p = cnp->cn_proc; 114138625Srvb/* locals */ 114238625Srvb int error; 114338625Srvb struct cnode *cp; 114438625Srvb const char *nm = cnp->cn_nameptr; 114538625Srvb int len = cnp->cn_namelen; 114638625Srvb ViceFid VFid; 114738625Srvb struct vattr attr; 114838625Srvb 114939085Srvb MARK_ENTRY(CODA_CREATE_STATS); 115038625Srvb 115138625Srvb /* All creates are exclusive XXX */ 115238625Srvb /* I'm assuming the 'mode' argument is the file mode bits XXX */ 115338625Srvb 115438625Srvb /* Check for create of control object. */ 115538625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 115638625Srvb *vpp = (struct vnode *)0; 115739085Srvb MARK_INT_FAIL(CODA_CREATE_STATS); 115838625Srvb return(EACCES); 115938625Srvb } 116038625Srvb 116138625Srvb error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, p, &VFid, &attr); 116238625Srvb 116338625Srvb if (!error) { 116438625Srvb 116538625Srvb /* If this is an exclusive create, panic if the file already exists. */ 116638625Srvb /* Venus should have detected the file and reported EEXIST. */ 116738625Srvb 116838625Srvb if ((exclusive == 1) && 116939085Srvb (coda_find(&VFid) != NULL)) 117038625Srvb panic("cnode existed for newly created file!"); 117138625Srvb 117239085Srvb cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type); 117338625Srvb *vpp = CTOV(cp); 117438625Srvb 117538625Srvb /* Update va to reflect the new attributes. */ 117638625Srvb (*va) = attr; 117738625Srvb 117838625Srvb /* Update the attribute cache and mark it as valid */ 117939085Srvb if (coda_attr_cache) { 118038625Srvb VTOC(*vpp)->c_vattr = attr; 118138625Srvb VTOC(*vpp)->c_flags |= C_VATTR; 118238625Srvb } 118338625Srvb 118438625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 118538625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 118638625Srvb 118738625Srvb /* enter the new vnode in the Name Cache */ 118839085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 118938625Srvb 119039085Srvb CODADEBUG(CODA_CREATE, 119138625Srvb myprintf(("create: (%lx.%lx.%lx), result %d\n", 119238625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 119338625Srvb } else { 119438625Srvb *vpp = (struct vnode *)0; 119539085Srvb CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));) 119638625Srvb } 119738625Srvb 119838625Srvb if (!error) { 119938625Srvb if (cnp->cn_flags & LOCKLEAF) { 120038759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 120139085Srvb printf("coda_create: "); 120238625Srvb panic("unlocked parent but couldn't lock child"); 120338625Srvb } 120438625Srvb } 120539650Srvb#ifdef OLD_DIAGNOSTIC 120638625Srvb else { 120739085Srvb printf("coda_create: LOCKLEAF not set!\n"); 120838625Srvb } 120939650Srvb#endif 121038625Srvb } 121138625Srvb /* Have to free the previously saved name */ 121238625Srvb /* 121338625Srvb * This condition is stolen from ufs_makeinode. I have no idea 121438625Srvb * why it's here, but what the hey... 121538625Srvb */ 121638625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 121738759Srvb zfree(namei_zone, cnp->cn_pnbuf); 121838625Srvb } 121938625Srvb return(error); 122038625Srvb} 122138625Srvb 122238625Srvbint 122339085Srvbcoda_remove(v) 122438625Srvb void *v; 122538625Srvb{ 122638625Srvb/* true args */ 122738625Srvb struct vop_remove_args *ap = v; 122838625Srvb struct vnode *dvp = ap->a_dvp; 122938625Srvb struct cnode *cp = VTOC(dvp); 123038625Srvb struct componentname *cnp = ap->a_cnp; 123138625Srvb struct ucred *cred = cnp->cn_cred; 123238625Srvb struct proc *p = cnp->cn_proc; 123338625Srvb/* locals */ 123438625Srvb int error; 123538625Srvb const char *nm = cnp->cn_nameptr; 123638625Srvb int len = cnp->cn_namelen; 123738625Srvb struct cnode *tp; 123838625Srvb 123939085Srvb MARK_ENTRY(CODA_REMOVE_STATS); 124038625Srvb 124139085Srvb CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n", 124238625Srvb nm, cp->c_fid.Volume, cp->c_fid.Vnode, 124338625Srvb cp->c_fid.Unique));); 124438625Srvb 124539085Srvb /* Remove the file's entry from the CODA Name Cache */ 124638625Srvb /* We're being conservative here, it might be that this person 124738625Srvb * doesn't really have sufficient access to delete the file 124838625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 124938625Srvb */ 125038625Srvb /* I'm gonna go out on a limb here. If a file and a hardlink to it 125138625Srvb * exist, and one is removed, the link count on the other will be 125238625Srvb * off by 1. We could either invalidate the attrs if cached, or 125338625Srvb * fix them. I'll try to fix them. DCS 11/8/94 125438625Srvb */ 125539085Srvb tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); 125638625Srvb if (tp) { 125738625Srvb if (VALID_VATTR(tp)) { /* If attrs are cached */ 125838625Srvb if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */ 125938625Srvb tp->c_vattr.va_nlink--; 126038625Srvb } 126138625Srvb } 126238625Srvb 126339085Srvb coda_nc_zapfile(VTOC(dvp), nm, len); 126438625Srvb /* No need to flush it if it doesn't exist! */ 126538625Srvb } 126638625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 126738625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 126838625Srvb 126938625Srvb /* Check for remove of control object. */ 127038625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 127139085Srvb MARK_INT_FAIL(CODA_REMOVE_STATS); 127238625Srvb return(ENOENT); 127338625Srvb } 127438625Srvb 127538625Srvb error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, p); 127638625Srvb 127739085Srvb CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); ) 127838625Srvb 127938625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 128038759Srvb zfree(namei_zone, cnp->cn_pnbuf); 128138625Srvb } 128238625Srvb return(error); 128338625Srvb} 128438625Srvb 128538625Srvbint 128639085Srvbcoda_link(v) 128738625Srvb void *v; 128838625Srvb{ 128938625Srvb/* true args */ 129038625Srvb struct vop_link_args *ap = v; 129138625Srvb struct vnode *vp = ap->a_vp; 129238625Srvb struct cnode *cp = VTOC(vp); 129338625Srvb struct vnode *tdvp = ap->a_tdvp; 129438625Srvb struct cnode *tdcp = VTOC(tdvp); 129538625Srvb struct componentname *cnp = ap->a_cnp; 129638625Srvb struct ucred *cred = cnp->cn_cred; 129738625Srvb struct proc *p = cnp->cn_proc; 129838625Srvb/* locals */ 129938625Srvb int error; 130038625Srvb const char *nm = cnp->cn_nameptr; 130138625Srvb int len = cnp->cn_namelen; 130238625Srvb 130339085Srvb MARK_ENTRY(CODA_LINK_STATS); 130438625Srvb 130539085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 130638625Srvb 130738625Srvb myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n", 130838625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 130938625Srvb myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n", 131038625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 131138625Srvb 131238625Srvb } 131339085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 131438625Srvb myprintf(("link: vp fid: (%lx.%lx.%lx)\n", 131538625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 131638625Srvb myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n", 131738625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 131838625Srvb 131938625Srvb } 132038625Srvb 132138625Srvb /* Check for link to/from control object. */ 132238625Srvb if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { 132339085Srvb MARK_INT_FAIL(CODA_LINK_STATS); 132438625Srvb return(EACCES); 132538625Srvb } 132638625Srvb 132738625Srvb error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, p); 132838625Srvb 132938625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 133038625Srvb VTOC(tdvp)->c_flags &= ~C_VATTR; 133138625Srvb VTOC(vp)->c_flags &= ~C_VATTR; 133238625Srvb 133339085Srvb CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); ) 133438625Srvb 133538625Srvb /* Drop the name buffer if we don't need to SAVESTART */ 133638625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 133738759Srvb zfree(namei_zone, cnp->cn_pnbuf); 133838625Srvb } 133938625Srvb return(error); 134038625Srvb} 134138625Srvb 134238625Srvbint 134339085Srvbcoda_rename(v) 134438625Srvb void *v; 134538625Srvb{ 134638625Srvb/* true args */ 134738625Srvb struct vop_rename_args *ap = v; 134838625Srvb struct vnode *odvp = ap->a_fdvp; 134938625Srvb struct cnode *odcp = VTOC(odvp); 135038625Srvb struct componentname *fcnp = ap->a_fcnp; 135138625Srvb struct vnode *ndvp = ap->a_tdvp; 135238625Srvb struct cnode *ndcp = VTOC(ndvp); 135338625Srvb struct componentname *tcnp = ap->a_tcnp; 135438625Srvb struct ucred *cred = fcnp->cn_cred; 135538625Srvb struct proc *p = fcnp->cn_proc; 135638625Srvb/* true args */ 135738625Srvb int error; 135838625Srvb const char *fnm = fcnp->cn_nameptr; 135938625Srvb int flen = fcnp->cn_namelen; 136038625Srvb const char *tnm = tcnp->cn_nameptr; 136138625Srvb int tlen = tcnp->cn_namelen; 136238625Srvb 136339085Srvb MARK_ENTRY(CODA_RENAME_STATS); 136438625Srvb 136538625Srvb /* Hmmm. The vnodes are already looked up. Perhaps they are locked? 136638625Srvb This could be Bad. XXX */ 136739650Srvb#ifdef OLD_DIAGNOSTIC 136838625Srvb if ((fcnp->cn_cred != tcnp->cn_cred) 136938625Srvb || (fcnp->cn_proc != tcnp->cn_proc)) 137038625Srvb { 137139085Srvb panic("coda_rename: component names don't agree"); 137238625Srvb } 137339650Srvb#endif 137438625Srvb 137538625Srvb /* Check for rename involving control object. */ 137638625Srvb if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { 137739085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 137838625Srvb return(EACCES); 137938625Srvb } 138038625Srvb 138138625Srvb /* Problem with moving directories -- need to flush entry for .. */ 138238625Srvb if (odvp != ndvp) { 138339085Srvb struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred); 138438625Srvb if (ovcp) { 138538625Srvb struct vnode *ovp = CTOV(ovcp); 138638625Srvb if ((ovp) && 138738625Srvb (ovp->v_type == VDIR)) /* If it's a directory */ 138839085Srvb coda_nc_zapfile(VTOC(ovp),"..", 2); 138938625Srvb } 139038625Srvb } 139138625Srvb 139238625Srvb /* Remove the entries for both source and target files */ 139339085Srvb coda_nc_zapfile(VTOC(odvp), fnm, flen); 139439085Srvb coda_nc_zapfile(VTOC(ndvp), tnm, tlen); 139538625Srvb 139638625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 139738625Srvb VTOC(odvp)->c_flags &= ~C_VATTR; 139838625Srvb VTOC(ndvp)->c_flags &= ~C_VATTR; 139938625Srvb 140039085Srvb if (flen+1 > CODA_MAXNAMLEN) { 140139085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 140238625Srvb error = EINVAL; 140338625Srvb goto exit; 140438625Srvb } 140538625Srvb 140639085Srvb if (tlen+1 > CODA_MAXNAMLEN) { 140739085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 140838625Srvb error = EINVAL; 140938625Srvb goto exit; 141038625Srvb } 141138625Srvb 141238625Srvb error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, p); 141338625Srvb 141438625Srvb exit: 141539085Srvb CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));) 141638625Srvb /* XXX - do we need to call cache pureg on the moved vnode? */ 141738625Srvb cache_purge(ap->a_fvp); 141838625Srvb 141938625Srvb /* It seems to be incumbent on us to drop locks on all four vnodes */ 142038625Srvb /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */ 142138625Srvb 142238625Srvb vrele(ap->a_fvp); 142338625Srvb vrele(odvp); 142438625Srvb 142538625Srvb if (ap->a_tvp) { 142638625Srvb if (ap->a_tvp == ndvp) { 142738625Srvb vrele(ap->a_tvp); 142838625Srvb } else { 142938625Srvb vput(ap->a_tvp); 143038625Srvb } 143138625Srvb } 143238625Srvb 143338625Srvb vput(ndvp); 143438625Srvb return(error); 143538625Srvb} 143638625Srvb 143738625Srvbint 143839085Srvbcoda_mkdir(v) 143938625Srvb void *v; 144038625Srvb{ 144138625Srvb/* true args */ 144238625Srvb struct vop_mkdir_args *ap = v; 144338625Srvb struct vnode *dvp = ap->a_dvp; 144438625Srvb struct cnode *dcp = VTOC(dvp); 144538625Srvb struct componentname *cnp = ap->a_cnp; 144638625Srvb register struct vattr *va = ap->a_vap; 144738625Srvb struct vnode **vpp = ap->a_vpp; 144838625Srvb struct ucred *cred = cnp->cn_cred; 144938625Srvb struct proc *p = cnp->cn_proc; 145038625Srvb/* locals */ 145138625Srvb int error; 145238625Srvb const char *nm = cnp->cn_nameptr; 145338625Srvb int len = cnp->cn_namelen; 145438625Srvb struct cnode *cp; 145538625Srvb ViceFid VFid; 145638625Srvb struct vattr ova; 145738625Srvb 145839085Srvb MARK_ENTRY(CODA_MKDIR_STATS); 145938625Srvb 146038625Srvb /* Check for mkdir of target object. */ 146138625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 146238625Srvb *vpp = (struct vnode *)0; 146339085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 146438625Srvb return(EACCES); 146538625Srvb } 146638625Srvb 146739085Srvb if (len+1 > CODA_MAXNAMLEN) { 146838625Srvb *vpp = (struct vnode *)0; 146939085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 147038625Srvb return(EACCES); 147138625Srvb } 147238625Srvb 147338625Srvb error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, p, &VFid, &ova); 147438625Srvb 147538625Srvb if (!error) { 147639085Srvb if (coda_find(&VFid) != NULL) 147738625Srvb panic("cnode existed for newly created directory!"); 147838625Srvb 147938625Srvb 148039085Srvb cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); 148138625Srvb *vpp = CTOV(cp); 148238625Srvb 148338625Srvb /* enter the new vnode in the Name Cache */ 148439085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 148538625Srvb 148638625Srvb /* as a side effect, enter "." and ".." for the directory */ 148739085Srvb coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); 148839085Srvb coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); 148938625Srvb 149039085Srvb if (coda_attr_cache) { 149138625Srvb VTOC(*vpp)->c_vattr = ova; /* update the attr cache */ 149238625Srvb VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */ 149338625Srvb } 149438625Srvb 149538625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 149638625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 149738625Srvb 149839085Srvb CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n", 149938625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 150038625Srvb } else { 150138625Srvb *vpp = (struct vnode *)0; 150239085Srvb CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));) 150338625Srvb } 150438625Srvb 150538625Srvb /* Have to free the previously saved name */ 150638625Srvb /* 150738625Srvb * ufs_mkdir doesn't check for SAVESTART before freeing the 150838625Srvb * pathname buffer, but ufs_create does. For the moment, I'll 150938625Srvb * follow their lead, but this seems like it is probably 151038625Srvb * incorrect. 151138625Srvb */ 151238759Srvb zfree(namei_zone, cnp->cn_pnbuf); 151338625Srvb return(error); 151438625Srvb} 151538625Srvb 151638625Srvbint 151739085Srvbcoda_rmdir(v) 151838625Srvb void *v; 151938625Srvb{ 152038625Srvb/* true args */ 152138625Srvb struct vop_rmdir_args *ap = v; 152238625Srvb struct vnode *dvp = ap->a_dvp; 152338625Srvb struct cnode *dcp = VTOC(dvp); 152438625Srvb struct componentname *cnp = ap->a_cnp; 152538625Srvb struct ucred *cred = cnp->cn_cred; 152638625Srvb struct proc *p = cnp->cn_proc; 152738625Srvb/* true args */ 152838625Srvb int error; 152938625Srvb const char *nm = cnp->cn_nameptr; 153038625Srvb int len = cnp->cn_namelen; 153138625Srvb struct cnode *cp; 153238625Srvb 153339085Srvb MARK_ENTRY(CODA_RMDIR_STATS); 153438625Srvb 153538625Srvb /* Check for rmdir of control object. */ 153638625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 153739085Srvb MARK_INT_FAIL(CODA_RMDIR_STATS); 153838625Srvb return(ENOENT); 153938625Srvb } 154038625Srvb 154138625Srvb /* We're being conservative here, it might be that this person 154238625Srvb * doesn't really have sufficient access to delete the file 154338625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 154438625Srvb */ 154538625Srvb /* 154638625Srvb * As a side effect of the rmdir, remove any entries for children of 154738625Srvb * the directory, especially "." and "..". 154838625Srvb */ 154939085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 155039085Srvb if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); 155138625Srvb 155239085Srvb /* Remove the file's entry from the CODA Name Cache */ 155339085Srvb coda_nc_zapfile(dcp, nm, len); 155438625Srvb 155538625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 155638625Srvb dcp->c_flags &= ~C_VATTR; 155738625Srvb 155838625Srvb error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, p); 155938625Srvb 156039085Srvb CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); ) 156138625Srvb 156238625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 156338759Srvb zfree(namei_zone, cnp->cn_pnbuf); 156438625Srvb } 156538625Srvb return(error); 156638625Srvb} 156738625Srvb 156838625Srvbint 156939085Srvbcoda_symlink(v) 157038625Srvb void *v; 157138625Srvb{ 157238625Srvb/* true args */ 157338625Srvb struct vop_symlink_args *ap = v; 157438625Srvb struct vnode *tdvp = ap->a_dvp; 157538625Srvb struct cnode *tdcp = VTOC(tdvp); 157638625Srvb struct componentname *cnp = ap->a_cnp; 157738625Srvb struct vattr *tva = ap->a_vap; 157838625Srvb char *path = ap->a_target; 157938625Srvb struct ucred *cred = cnp->cn_cred; 158038625Srvb struct proc *p = cnp->cn_proc; 158153131Seivind struct vnode **vpp = ap->a_vpp; 158238625Srvb/* locals */ 158338625Srvb int error; 158438625Srvb /* 158539085Srvb * XXX I'm assuming the following things about coda_symlink's 158638625Srvb * arguments: 158738625Srvb * t(foo) is the new name/parent/etc being created. 158838625Srvb * lname is the contents of the new symlink. 158938625Srvb */ 159038759Srvb char *nm = cnp->cn_nameptr; 159138625Srvb int len = cnp->cn_namelen; 159238625Srvb int plen = strlen(path); 159338625Srvb 159438625Srvb /* 159538625Srvb * Here's the strategy for the moment: perform the symlink, then 159638625Srvb * do a lookup to grab the resulting vnode. I know this requires 159738625Srvb * two communications with Venus for a new sybolic link, but 159838625Srvb * that's the way the ball bounces. I don't yet want to change 159938625Srvb * the way the Mach symlink works. When Mach support is 160038625Srvb * deprecated, we should change symlink so that the common case 160138625Srvb * returns the resultant vnode in a vpp argument. 160238625Srvb */ 160338625Srvb 160439085Srvb MARK_ENTRY(CODA_SYMLINK_STATS); 160538625Srvb 160638625Srvb /* Check for symlink of control object. */ 160738625Srvb if (IS_CTL_NAME(tdvp, nm, len)) { 160839085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 160938625Srvb return(EACCES); 161038625Srvb } 161138625Srvb 161239085Srvb if (plen+1 > CODA_MAXPATHLEN) { 161339085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 161438625Srvb return(EINVAL); 161538625Srvb } 161638625Srvb 161739085Srvb if (len+1 > CODA_MAXNAMLEN) { 161839085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 161938625Srvb error = EINVAL; 162038625Srvb goto exit; 162138625Srvb } 162238625Srvb 162338625Srvb error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, p); 162438625Srvb 162538625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 162638625Srvb tdcp->c_flags &= ~C_VATTR; 162738625Srvb 162853131Seivind if (error == 0) 162953131Seivind error = VOP_LOOKUP(tdvp, vpp, cnp); 163038625Srvb 163138625Srvb exit: 163239085Srvb CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); ) 163338625Srvb return(error); 163438625Srvb} 163538625Srvb 163638625Srvb/* 163738625Srvb * Read directory entries. 163838625Srvb */ 163938625Srvbint 164039085Srvbcoda_readdir(v) 164138625Srvb void *v; 164238625Srvb{ 164338625Srvb/* true args */ 164438625Srvb struct vop_readdir_args *ap = v; 164538625Srvb struct vnode *vp = ap->a_vp; 164638625Srvb struct cnode *cp = VTOC(vp); 164738625Srvb register struct uio *uiop = ap->a_uio; 164838625Srvb struct ucred *cred = ap->a_cred; 164938625Srvb int *eofflag = ap->a_eofflag; 165038625Srvb u_long **cookies = ap->a_cookies; 165138625Srvb int *ncookies = ap->a_ncookies; 165238625Srvb struct proc *p = ap->a_uio->uio_procp; 165338625Srvb/* upcall decl */ 165438625Srvb/* locals */ 165538625Srvb int error = 0; 165638625Srvb 165739085Srvb MARK_ENTRY(CODA_READDIR_STATS); 165838625Srvb 165949524Sbde CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n", 166049524Sbde (void *)uiop->uio_iov->iov_base, 166149524Sbde uiop->uio_resid, 166249524Sbde (long long)uiop->uio_offset, 166349524Sbde uiop->uio_segflg)); ) 166438625Srvb 166538625Srvb /* Check for readdir of control object. */ 166638625Srvb if (IS_CTL_VP(vp)) { 166739085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 166838625Srvb return(ENOENT); 166938625Srvb } 167038625Srvb 167138759Srvb { 167238625Srvb /* If directory is not already open do an "internal open" on it. */ 167338625Srvb int opened_internally = 0; 167438625Srvb if (cp->c_ovp == NULL) { 167538625Srvb opened_internally = 1; 167639085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 167738625Srvb error = VOP_OPEN(vp, FREAD, cred, p); 167839085Srvbprintf("coda_readdir: Internally Opening %p\n", vp); 167938625Srvb if (error) { 168039085Srvb printf("coda_readdir: VOP_OPEN on container failed %d\n", error); 168138625Srvb return (error); 168238625Srvb } 168338625Srvb if (vp->v_type == VREG) { 168442315Seivind error = vfs_object_create(vp, p, cred); 168538625Srvb if (error != 0) { 168639085Srvb printf("coda_readdir: vfs_object_create() returns %d\n", error); 168738625Srvb vput(vp); 168838625Srvb } 168938625Srvb } 169038625Srvb if (error) return(error); 169138625Srvb } 169238625Srvb 169338625Srvb /* Have UFS handle the call. */ 169439085Srvb 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)); ) 169538625Srvb error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, 169638625Srvb cookies); 169738625Srvb 169838625Srvb if (error) 169939085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 170038625Srvb else 170139085Srvb MARK_INT_SAT(CODA_READDIR_STATS); 170238625Srvb 170338625Srvb /* Do an "internal close" if necessary. */ 170438625Srvb if (opened_internally) { 170539085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 170638625Srvb (void)VOP_CLOSE(vp, FREAD, cred, p); 170738625Srvb } 170838625Srvb } 170938625Srvb 171038625Srvb return(error); 171138625Srvb} 171238625Srvb 171338625Srvb/* 171438625Srvb * Convert from file system blocks to device blocks 171538625Srvb */ 171638625Srvbint 171739085Srvbcoda_bmap(v) 171838625Srvb void *v; 171938625Srvb{ 172038625Srvb /* XXX on the global proc */ 172138625Srvb/* true args */ 172238625Srvb struct vop_bmap_args *ap = v; 172338625Srvb struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */ 172438625Srvb daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */ 172538625Srvb struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */ 172638625Srvb daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */ 172738625Srvb struct proc *p __attribute__((unused)) = curproc; 172838625Srvb/* upcall decl */ 172938625Srvb/* locals */ 173038625Srvb 173138625Srvb int ret = 0; 173238625Srvb struct cnode *cp; 173338625Srvb 173438625Srvb cp = VTOC(vp); 173538625Srvb if (cp->c_ovp) { 173639728Srvb return EINVAL; 173738625Srvb ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb); 173839650Srvb#if 0 173938625Srvb printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n", 174038625Srvb cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret); 174139650Srvb#endif 174238625Srvb return ret; 174338625Srvb } else { 174441504Srvb#if 0 174539085Srvb printf("coda_bmap: no container\n"); 174641504Srvb#endif 174738625Srvb return(EOPNOTSUPP); 174838625Srvb } 174938625Srvb} 175038625Srvb 175138625Srvb/* 175238625Srvb * I don't think the following two things are used anywhere, so I've 175338625Srvb * commented them out 175438625Srvb * 175538625Srvb * struct buf *async_bufhead; 175638625Srvb * int async_daemon_count; 175738625Srvb */ 175838625Srvbint 175939085Srvbcoda_strategy(v) 176038625Srvb void *v; 176138625Srvb{ 176238625Srvb/* true args */ 176338625Srvb struct vop_strategy_args *ap = v; 176438625Srvb register struct buf *bp __attribute__((unused)) = ap->a_bp; 176538625Srvb struct proc *p __attribute__((unused)) = curproc; 176638625Srvb/* upcall decl */ 176738625Srvb/* locals */ 176838625Srvb 176939085Srvb printf("coda_strategy: called ???\n"); 177038625Srvb return(EOPNOTSUPP); 177138625Srvb} 177238625Srvb 177338625Srvbint 177439085Srvbcoda_reclaim(v) 177538625Srvb void *v; 177638625Srvb{ 177738625Srvb/* true args */ 177838625Srvb struct vop_reclaim_args *ap = v; 177938625Srvb struct vnode *vp = ap->a_vp; 178038625Srvb struct cnode *cp = VTOC(vp); 178138625Srvb/* upcall decl */ 178238625Srvb/* locals */ 178338625Srvb 178438625Srvb/* 178538625Srvb * Forced unmount/flush will let vnodes with non zero use be destroyed! 178638625Srvb */ 178738625Srvb ENTRY; 178838625Srvb 178938625Srvb if (IS_UNMOUNTING(cp)) { 179038625Srvb#ifdef DEBUG 179138625Srvb if (VTOC(vp)->c_ovp) { 179238625Srvb if (IS_UNMOUNTING(cp)) 179339085Srvb printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp); 179438625Srvb } 179538625Srvb#endif 179638625Srvb } else { 179739650Srvb#ifdef OLD_DIAGNOSTIC 179838625Srvb if (vp->v_usecount != 0) 179939650Srvb print("coda_reclaim: pushing active %p\n", vp); 180038625Srvb if (VTOC(vp)->c_ovp) { 180139085Srvb panic("coda_reclaim: c_ovp not void"); 180238625Srvb } 180339650Srvb#endif 180438625Srvb } 180538625Srvb cache_purge(vp); 180639085Srvb coda_free(VTOC(vp)); 180738625Srvb VTOC(vp) = NULL; 180838625Srvb return (0); 180938625Srvb} 181038625Srvb 181138625Srvbint 181239085Srvbcoda_lock(v) 181338625Srvb void *v; 181438625Srvb{ 181538625Srvb/* true args */ 181638625Srvb struct vop_lock_args *ap = v; 181738625Srvb struct vnode *vp = ap->a_vp; 181838625Srvb struct cnode *cp = VTOC(vp); 181938625Srvb struct proc *p = ap->a_p; 182038625Srvb/* upcall decl */ 182138625Srvb/* locals */ 182238625Srvb 182338625Srvb ENTRY; 182438625Srvb 182539085Srvb if (coda_lockdebug) { 182638625Srvb myprintf(("Attempting lock on %lx.%lx.%lx\n", 182738625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 182838625Srvb } 182938625Srvb 183042900Seivind#ifndef DEBUG_LOCKS 183138759Srvb return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p)); 183242900Seivind#else 183342900Seivind return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p, 183442900Seivind "coda_lock", vp->filename, vp->line)); 183542900Seivind#endif 183638625Srvb} 183738625Srvb 183838625Srvbint 183939085Srvbcoda_unlock(v) 184038625Srvb void *v; 184138625Srvb{ 184238625Srvb/* true args */ 184338625Srvb struct vop_unlock_args *ap = v; 184438625Srvb struct vnode *vp = ap->a_vp; 184538625Srvb struct cnode *cp = VTOC(vp); 184638625Srvb struct proc *p = ap->a_p; 184738625Srvb/* upcall decl */ 184838625Srvb/* locals */ 184938625Srvb 185038625Srvb ENTRY; 185139085Srvb if (coda_lockdebug) { 185238625Srvb myprintf(("Attempting unlock on %lx.%lx.%lx\n", 185338625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 185438625Srvb } 185538625Srvb 185638759Srvb return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, p)); 185738625Srvb} 185838625Srvb 185938625Srvbint 186039085Srvbcoda_islocked(v) 186138625Srvb void *v; 186238625Srvb{ 186338625Srvb/* true args */ 186438625Srvb struct vop_islocked_args *ap = v; 186538625Srvb struct cnode *cp = VTOC(ap->a_vp); 186638625Srvb ENTRY; 186738625Srvb 186854444Seivind return (lockstatus(&cp->c_lock, ap->a_p)); 186938625Srvb} 187038625Srvb 187138625Srvb/* How one looks up a vnode given a device/inode pair: */ 187238625Srvbint 187339085Srvbcoda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp) 187438625Srvb{ 187538625Srvb /* This is like VFS_VGET() or igetinode()! */ 187638625Srvb int error; 187738625Srvb struct mount *mp; 187838625Srvb 187938625Srvb if (!(mp = devtomp(dev))) { 188049524Sbde myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n", 188149524Sbde (u_long)dev2udev(dev))); 188238625Srvb return(ENXIO); 188338625Srvb } 188438625Srvb 188538625Srvb /* XXX - ensure that nonzero-return means failure */ 188638625Srvb error = VFS_VGET(mp,ino,vpp); 188738625Srvb if (error) { 188849524Sbde myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n", 188949524Sbde (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error)); 189038625Srvb return(ENOENT); 189138625Srvb } 189238625Srvb return(0); 189338625Srvb} 189438625Srvb 189538625Srvbvoid 189638625Srvbprint_vattr( attr ) 189738625Srvb struct vattr *attr; 189838625Srvb{ 189938625Srvb char *typestr; 190038625Srvb 190138625Srvb switch (attr->va_type) { 190238625Srvb case VNON: 190338625Srvb typestr = "VNON"; 190438625Srvb break; 190538625Srvb case VREG: 190638625Srvb typestr = "VREG"; 190738625Srvb break; 190838625Srvb case VDIR: 190938625Srvb typestr = "VDIR"; 191038625Srvb break; 191138625Srvb case VBLK: 191238625Srvb typestr = "VBLK"; 191338625Srvb break; 191438625Srvb case VCHR: 191538625Srvb typestr = "VCHR"; 191638625Srvb break; 191738625Srvb case VLNK: 191838625Srvb typestr = "VLNK"; 191938625Srvb break; 192038625Srvb case VSOCK: 192138625Srvb typestr = "VSCK"; 192238625Srvb break; 192338625Srvb case VFIFO: 192438625Srvb typestr = "VFFO"; 192538625Srvb break; 192638625Srvb case VBAD: 192738625Srvb typestr = "VBAD"; 192838625Srvb break; 192938625Srvb default: 193038625Srvb typestr = "????"; 193138625Srvb break; 193238625Srvb } 193338625Srvb 193438625Srvb 193538625Srvb myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", 193638625Srvb typestr, (int)attr->va_mode, (int)attr->va_uid, 193738625Srvb (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); 193838625Srvb 193938625Srvb myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", 194038625Srvb (int)attr->va_fileid, (int)attr->va_nlink, 194138625Srvb (int)attr->va_size, 194238625Srvb (int)attr->va_blocksize,(int)attr->va_bytes)); 194338625Srvb myprintf((" gen %ld flags %ld vaflags %d\n", 194438625Srvb attr->va_gen, attr->va_flags, attr->va_vaflags)); 194538625Srvb myprintf((" atime sec %d nsec %d\n", 194638625Srvb (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec)); 194738625Srvb myprintf((" mtime sec %d nsec %d\n", 194838625Srvb (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec)); 194938625Srvb myprintf((" ctime sec %d nsec %d\n", 195038625Srvb (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec)); 195138625Srvb} 195238625Srvb 195338625Srvb/* How to print a ucred */ 195438625Srvbvoid 195538625Srvbprint_cred(cred) 195638625Srvb struct ucred *cred; 195738625Srvb{ 195838625Srvb 195938625Srvb int i; 196038625Srvb 196138625Srvb myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid)); 196238625Srvb 196338625Srvb for (i=0; i < cred->cr_ngroups; i++) 196438625Srvb myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i])); 196538625Srvb myprintf(("\n")); 196638625Srvb 196738625Srvb} 196838625Srvb 196938625Srvb/* 197038625Srvb * Return a vnode for the given fid. 197138625Srvb * If no cnode exists for this fid create one and put it 197238625Srvb * in a table hashed by fid.Volume and fid.Vnode. If the cnode for 197338625Srvb * this fid is already in the table return it (ref count is 197439085Srvb * incremented by coda_find. The cnode will be flushed from the 197539085Srvb * table when coda_inactive calls coda_unsave. 197638625Srvb */ 197738625Srvbstruct cnode * 197839085Srvbmake_coda_node(fid, vfsp, type) 197938625Srvb ViceFid *fid; struct mount *vfsp; short type; 198038625Srvb{ 198138625Srvb struct cnode *cp; 198238625Srvb int err; 198338625Srvb 198439085Srvb if ((cp = coda_find(fid)) == NULL) { 198538625Srvb struct vnode *vp; 198638625Srvb 198739085Srvb cp = coda_alloc(); 198838625Srvb lockinit(&cp->c_lock, PINOD, "cnode", 0, 0); 198938625Srvb cp->c_fid = *fid; 199038625Srvb 199139085Srvb err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp); 199238625Srvb if (err) { 199339085Srvb panic("coda: getnewvnode returned error %d\n", err); 199438625Srvb } 199538625Srvb vp->v_data = cp; 199638625Srvb vp->v_type = type; 199738625Srvb cp->c_vnode = vp; 199839085Srvb coda_save(cp); 199938625Srvb 200038625Srvb } else { 200138625Srvb vref(CTOV(cp)); 200238625Srvb } 200338625Srvb 200438625Srvb return cp; 200538625Srvb} 2006