coda_vnops.c revision 111903
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 111903 2003-03-05 10:23:51Z tjr $ 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/* 4396755Strhodes * This code was written for the Coda filesystem 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> 5076166Smarkm#include <sys/acct.h> 5176166Smarkm#include <sys/errno.h> 5276166Smarkm#include <sys/fcntl.h> 5338759Srvb#include <sys/kernel.h> 5476166Smarkm#include <sys/lock.h> 5576166Smarkm#include <sys/malloc.h> 5676166Smarkm#include <sys/file.h> /* Must come after sys/malloc.h */ 5776166Smarkm#include <sys/mount.h> 5876166Smarkm#include <sys/mutex.h> 5976166Smarkm#include <sys/namei.h> 6038759Srvb#include <sys/proc.h> 6138625Srvb#include <sys/uio.h> 62111903Stjr#include <sys/unistd.h> 6338759Srvb 6438625Srvb#include <vm/vm.h> 6538625Srvb#include <vm/vm_object.h> 6638625Srvb#include <vm/vm_extern.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 */ 9989090Smsmithstatic int (**coda_vnodeop_p)(void *); 10038625Srvb 10138625Srvb/* 10238625Srvb * Some NetBSD details: 10338625Srvb * 10439085Srvb * coda_start is called at the end of the mount syscall. 10539085Srvb * coda_init is called at boot time. 10638625Srvb */ 10738625Srvb 10887599Sobrien#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__)) 10938625Srvb 11038625Srvb/* Definition of the vnode operation vector */ 11138625Srvb 11239085Srvbstruct vnodeopv_entry_desc coda_vnodeop_entries[] = { 11339085Srvb { &vop_default_desc, coda_vop_error }, 11439085Srvb { &vop_lookup_desc, coda_lookup }, /* lookup */ 11539085Srvb { &vop_create_desc, coda_create }, /* create */ 11639650Srvb { &vop_mknod_desc, coda_vop_error }, /* mknod */ 11739085Srvb { &vop_open_desc, coda_open }, /* open */ 11839085Srvb { &vop_close_desc, coda_close }, /* close */ 11939085Srvb { &vop_access_desc, coda_access }, /* access */ 12039650Srvb { &vop_getattr_desc, coda_getattr }, /* getattr */ 12139650Srvb { &vop_setattr_desc, coda_setattr }, /* setattr */ 12239085Srvb { &vop_read_desc, coda_read }, /* read */ 12339085Srvb { &vop_write_desc, coda_write }, /* write */ 12439085Srvb { &vop_ioctl_desc, coda_ioctl }, /* ioctl */ 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 */ 13439085Srvb { &vop_inactive_desc, coda_inactive }, /* inactive */ 13539650Srvb { &vop_reclaim_desc, coda_reclaim }, /* reclaim */ 13639085Srvb { &vop_lock_desc, coda_lock }, /* lock */ 13739085Srvb { &vop_unlock_desc, coda_unlock }, /* unlock */ 13839085Srvb { &vop_bmap_desc, coda_bmap }, /* bmap */ 13939085Srvb { &vop_strategy_desc, coda_strategy }, /* strategy */ 14039650Srvb { &vop_print_desc, coda_vop_error }, /* print */ 14139085Srvb { &vop_islocked_desc, coda_islocked }, /* islocked */ 142111903Stjr { &vop_pathconf_desc, coda_pathconf }, /* pathconf */ 14339650Srvb { &vop_advlock_desc, coda_vop_nop }, /* advlock */ 14439650Srvb { &vop_lease_desc, coda_vop_nop }, /* lease */ 14538759Srvb { &vop_poll_desc, (vop_t *) vop_stdpoll }, 14677784Sshafeeq { &vop_getpages_desc, (vop_t*)vop_stdgetpages }, /* pager intf.*/ 14777784Sshafeeq { &vop_putpages_desc, (vop_t*)vop_stdputpages }, /* pager intf.*/ 14878205Sbp { &vop_createvobject_desc, (vop_t*)vop_stdcreatevobject }, 14978205Sbp { &vop_destroyvobject_desc, (vop_t*)vop_stddestroyvobject }, 15078205Sbp { &vop_getvobject_desc, (vop_t*)vop_stdgetvobject }, 15138625Srvb 15238759Srvb#if 0 15338625Srvb 15438759Srvb we need to define these someday 15538625Srvb#define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd) 15638625Srvb#define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd) 15738625Srvb#define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc) 15838625Srvb#define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee) 15942374Sbde#define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb) 16038625Srvb 16138625Srvb missing 16238625Srvb { &vop_reallocblks_desc, (vop_t *) ufs_missingop }, 16338625Srvb { &vop_cachedlookup_desc, (vop_t *) ufs_lookup }, 16438625Srvb { &vop_whiteout_desc, (vop_t *) ufs_whiteout }, 16538625Srvb#endif 16677784Sshafeeq 16777784Sshafeeq { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, 16877784Sshafeeq { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, 16977784Sshafeeq { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 17077784Sshafeeq { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount }, 17138625Srvb { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL } 17238625Srvb}; 17338625Srvb 17439085Srvbstatic struct vnodeopv_desc coda_vnodeop_opv_desc = 17539085Srvb { &coda_vnodeop_p, coda_vnodeop_entries }; 17638625Srvb 17739085SrvbVNODEOP_SET(coda_vnodeop_opv_desc); 17838625Srvb 17938625Srvb/* A generic panic: we were called with something we didn't define yet */ 18038625Srvbint 18139085Srvbcoda_vop_error(void *anon) { 18238625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 18338625Srvb 18441202Srvb myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n", 18538625Srvb (*desc)->vdesc_name)); 18641202Srvb /* 18739085Srvb panic("coda_vop_error"); 18841202Srvb */ 18941202Srvb return EIO; 19038625Srvb} 19138625Srvb 19238625Srvb/* A generic do-nothing. For lease_check, advlock */ 19338625Srvbint 19439085Srvbcoda_vop_nop(void *anon) { 19538625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 19638625Srvb 19739085Srvb if (codadebug) { 19838625Srvb myprintf(("Vnode operation %s called, but unsupported\n", 19938625Srvb (*desc)->vdesc_name)); 20038625Srvb } 20138625Srvb return (0); 20238625Srvb} 20338625Srvb 20438625Srvbint 20539085Srvbcoda_vnodeopstats_init(void) 20638625Srvb{ 20738625Srvb register int i; 20838625Srvb 20939085Srvb for(i=0;i<CODA_VNODEOPS_SIZE;i++) { 21039085Srvb coda_vnodeopstats[i].opcode = i; 21139085Srvb coda_vnodeopstats[i].entries = 0; 21239085Srvb coda_vnodeopstats[i].sat_intrn = 0; 21339085Srvb coda_vnodeopstats[i].unsat_intrn = 0; 21439085Srvb coda_vnodeopstats[i].gen_intrn = 0; 21538625Srvb } 21638625Srvb return 0; 21738625Srvb} 21838625Srvb 21938625Srvb/* 22039085Srvb * coda_open calls Venus to return the device, inode pair of the cache 22139085Srvb * file holding the data. Using iget, coda_open finds the vnode of the 22238625Srvb * cache file, and then opens it. 22338625Srvb */ 22438625Srvbint 22539085Srvbcoda_open(v) 22638625Srvb void *v; 22738625Srvb{ 22838625Srvb /* 22938625Srvb * NetBSD can pass the O_EXCL flag in mode, even though the check 23038625Srvb * has already happened. Venus defensively assumes that if open 23138625Srvb * is passed the EXCL, it must be a bug. We strip the flag here. 23238625Srvb */ 23338625Srvb/* true args */ 23438625Srvb struct vop_open_args *ap = v; 23538625Srvb register struct vnode **vpp = &(ap->a_vp); 23638625Srvb struct cnode *cp = VTOC(*vpp); 23738625Srvb int flag = ap->a_mode & (~O_EXCL); 23838625Srvb struct ucred *cred = ap->a_cred; 23983366Sjulian struct thread *td = ap->a_td; 24038625Srvb/* locals */ 24138625Srvb int error; 24238625Srvb struct vnode *vp; 24338625Srvb dev_t dev; 24438625Srvb ino_t inode; 24538625Srvb 24639085Srvb MARK_ENTRY(CODA_OPEN_STATS); 24738625Srvb 24838625Srvb /* Check for open of control file. */ 24938625Srvb if (IS_CTL_VP(*vpp)) { 25038625Srvb /* XXX */ 25138625Srvb /* if (WRITEABLE(flag)) */ 25238625Srvb if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { 25339085Srvb MARK_INT_FAIL(CODA_OPEN_STATS); 25438625Srvb return(EACCES); 25538625Srvb } 25639085Srvb MARK_INT_SAT(CODA_OPEN_STATS); 25738625Srvb return(0); 25838625Srvb } 25938625Srvb 26083366Sjulian error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td->td_proc, &dev, &inode); 26138625Srvb if (error) 26238625Srvb return (error); 26338625Srvb if (!error) { 26449524Sbde CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n", 26549524Sbde (u_long)dev2udev(dev), (u_long)inode, 26649524Sbde error)); ) 26738625Srvb } 26838625Srvb 26938625Srvb /* Translate the <device, inode> pair for the cache file into 27038625Srvb an inode pointer. */ 27139085Srvb error = coda_grab_vnode(dev, inode, &vp); 27238625Srvb if (error) 27338625Srvb return (error); 27438625Srvb 27538759Srvb /* We get the vnode back locked. Needs unlocked */ 27683366Sjulian VOP_UNLOCK(vp, 0, td); 27738625Srvb /* Keep a reference until the close comes in. */ 27838625Srvb vref(*vpp); 27938625Srvb 28038625Srvb /* Save the vnode pointer for the cache file. */ 28138625Srvb if (cp->c_ovp == NULL) { 28238625Srvb cp->c_ovp = vp; 28338625Srvb } else { 28438625Srvb if (cp->c_ovp != vp) 28539085Srvb panic("coda_open: cp->c_ovp != ITOV(ip)"); 28638625Srvb } 28738625Srvb cp->c_ocount++; 28838625Srvb 28938625Srvb /* Flush the attribute cached if writing the file. */ 29038625Srvb if (flag & FWRITE) { 29138625Srvb cp->c_owrite++; 29238625Srvb cp->c_flags &= ~C_VATTR; 29338625Srvb } 29438625Srvb 29538625Srvb /* Save the <device, inode> pair for the cache file to speed 29638625Srvb up subsequent page_read's. */ 29738625Srvb cp->c_device = dev; 29838625Srvb cp->c_inode = inode; 29938625Srvb 30038625Srvb /* Open the cache file. */ 30183366Sjulian error = VOP_OPEN(vp, flag, cred, td); 30238625Srvb if (error) { 30339085Srvb printf("coda_open: VOP_OPEN on container failed %d\n", error); 30438625Srvb return (error); 30538625Srvb } 30639650Srvb/* grab (above) does this when it calls newvnode unless it's in the cache*/ 30738625Srvb if (vp->v_type == VREG) { 30883366Sjulian error = vfs_object_create(vp, td, cred); 30938625Srvb if (error != 0) { 31039085Srvb printf("coda_open: vfs_object_create() returns %d\n", error); 31138625Srvb vput(vp); 31238625Srvb } 31338625Srvb } 31439650Srvb 31538625Srvb return(error); 31638625Srvb} 31738625Srvb 31838625Srvb/* 31938625Srvb * Close the cache file used for I/O and notify Venus. 32038625Srvb */ 32138625Srvbint 32239085Srvbcoda_close(v) 32338625Srvb void *v; 32438625Srvb{ 32538625Srvb/* true args */ 32638625Srvb struct vop_close_args *ap = v; 32738625Srvb struct vnode *vp = ap->a_vp; 32838625Srvb struct cnode *cp = VTOC(vp); 32938625Srvb int flag = ap->a_fflag; 33038625Srvb struct ucred *cred = ap->a_cred; 33183366Sjulian struct thread *td = ap->a_td; 33238625Srvb/* locals */ 33338625Srvb int error; 33438625Srvb 33539085Srvb MARK_ENTRY(CODA_CLOSE_STATS); 33638625Srvb 33738625Srvb /* Check for close of control file. */ 33838625Srvb if (IS_CTL_VP(vp)) { 33939085Srvb MARK_INT_SAT(CODA_CLOSE_STATS); 34038625Srvb return(0); 34138625Srvb } 34238625Srvb 34338625Srvb if (IS_UNMOUNTING(cp)) { 34438625Srvb if (cp->c_ovp) { 34539728Srvb#ifdef CODA_VERBOSE 34639085Srvb printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n", 347103937Sjeff vrefcnt(vp), cp->c_ovp, vp, cp); 34839650Srvb#endif 34940708Srvb#ifdef hmm 35038625Srvb vgone(cp->c_ovp); 35140708Srvb#else 35283366Sjulian VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */ 35340708Srvb vrele(cp->c_ovp); 35440708Srvb#endif 35538625Srvb } else { 35639728Srvb#ifdef CODA_VERBOSE 35739085Srvb printf("coda_close: NO container vp %p/cp %p\n", vp, cp); 35839650Srvb#endif 35938625Srvb } 36038625Srvb return ENODEV; 36138625Srvb } else { 36283366Sjulian VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */ 36338625Srvb vrele(cp->c_ovp); 36438625Srvb } 36538625Srvb 36638625Srvb if (--cp->c_ocount == 0) 36738625Srvb cp->c_ovp = NULL; 36838625Srvb 36938625Srvb if (flag & FWRITE) /* file was opened for write */ 37038625Srvb --cp->c_owrite; 37138625Srvb 37283366Sjulian error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, td->td_proc); 37338625Srvb vrele(CTOV(cp)); 37438625Srvb 37539085Srvb CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); ) 37638625Srvb return(error); 37738625Srvb} 37838625Srvb 37938625Srvbint 38039085Srvbcoda_read(v) 38138625Srvb void *v; 38238625Srvb{ 38338625Srvb struct vop_read_args *ap = v; 38438625Srvb 38538625Srvb ENTRY; 38639085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, 38783366Sjulian ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); 38838625Srvb} 38938625Srvb 39038625Srvbint 39139085Srvbcoda_write(v) 39238625Srvb void *v; 39338625Srvb{ 39438625Srvb struct vop_write_args *ap = v; 39538625Srvb 39638625Srvb ENTRY; 39739085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, 39883366Sjulian ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); 39938625Srvb} 40038625Srvb 40138625Srvbint 40283366Sjuliancoda_rdwr(vp, uiop, rw, ioflag, cred, td) 40338625Srvb struct vnode *vp; 40438625Srvb struct uio *uiop; 40538625Srvb enum uio_rw rw; 40638625Srvb int ioflag; 40738625Srvb struct ucred *cred; 40883366Sjulian struct thread *td; 40938625Srvb{ 41038625Srvb/* upcall decl */ 41138625Srvb /* NOTE: container file operation!!! */ 41238625Srvb/* locals */ 41338625Srvb struct cnode *cp = VTOC(vp); 41438625Srvb struct vnode *cfvp = cp->c_ovp; 41583366Sjulian struct proc *p = td->td_proc; 41683366Sjulian struct thread *ltd = td; 41738625Srvb int igot_internally = 0; 41838625Srvb int opened_internally = 0; 41938625Srvb int error = 0; 42077784Sshafeeq int iscore = 0; 42138625Srvb 42239085Srvb MARK_ENTRY(CODA_RDWR_STATS); 42338625Srvb 42449524Sbde CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw, 42549524Sbde (void *)uiop->uio_iov->iov_base, uiop->uio_resid, 42649524Sbde (long long)uiop->uio_offset, uiop->uio_segflg)); ) 42738625Srvb 42838625Srvb /* Check for rdwr of control object. */ 42938625Srvb if (IS_CTL_VP(vp)) { 43039085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 43138625Srvb return(EINVAL); 43238625Srvb } 43338625Srvb 43438625Srvb /* 43538625Srvb * If file is not already open this must be a page 43638625Srvb * {read,write} request. Iget the cache file's inode 43738625Srvb * pointer if we still have its <device, inode> pair. 43838625Srvb * Otherwise, we must do an internal open to derive the 43938625Srvb * pair. 44038625Srvb */ 44138625Srvb if (cfvp == NULL) { 44238625Srvb /* 44338625Srvb * If we're dumping core, do the internal open. Otherwise 44438625Srvb * venus won't have the correct size of the core when 44538625Srvb * it's completely written. 44638625Srvb */ 44777784Sshafeeq if (p) { 44877784Sshafeeq PROC_LOCK(p); 44977784Sshafeeq iscore = (p->p_acflag & ACORE); 45069652Sjhb PROC_UNLOCK(p); 45177784Sshafeeq } 45277784Sshafeeq else 45383366Sjulian ltd = curthread; 45477784Sshafeeq 45577784Sshafeeq if (cp->c_inode != 0 && !iscore) { 45638625Srvb igot_internally = 1; 45739085Srvb error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp); 45838625Srvb if (error) { 45939085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 46038625Srvb return(error); 46138625Srvb } 46238625Srvb /* 46383366Sjulian * We get the vnode back locked by curthread in both Mach and 46438625Srvb * NetBSD. Needs unlocked 46538625Srvb */ 46683366Sjulian VOP_UNLOCK(cfvp, 0, ltd); 46738625Srvb } 46838625Srvb else { 46938625Srvb opened_internally = 1; 47039085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 47138625Srvb error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), 47283366Sjulian cred, td); 47339085Srvbprintf("coda_rdwr: Internally Opening %p\n", vp); 47438625Srvb if (error) { 47539085Srvb printf("coda_rdwr: VOP_OPEN on container failed %d\n", error); 47638625Srvb return (error); 47738625Srvb } 47838625Srvb if (vp->v_type == VREG) { 47983366Sjulian error = vfs_object_create(vp, td, cred); 48038625Srvb if (error != 0) { 48139085Srvb printf("coda_rdwr: vfs_object_create() returns %d\n", error); 48238625Srvb vput(vp); 48338625Srvb } 48438625Srvb } 48538625Srvb if (error) { 48639085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 48738625Srvb return(error); 48838625Srvb } 48938625Srvb cfvp = cp->c_ovp; 49038625Srvb } 49138625Srvb } 49238625Srvb 49338625Srvb /* Have UFS handle the call. */ 49439085Srvb CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n", 49538625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 496103937Sjeff cp->c_fid.Unique, vrefcnt(CTOV(cp)))); ) 49738625Srvb 49838625Srvb if (rw == UIO_READ) { 49938625Srvb error = VOP_READ(cfvp, uiop, ioflag, cred); 50038625Srvb } else { 50138625Srvb error = VOP_WRITE(cfvp, uiop, ioflag, cred); 50238625Srvb /* ufs_write updates the vnode_pager_setsize for the vnode/object */ 50339650Srvb 50438625Srvb { struct vattr attr; 50538625Srvb 50683366Sjulian if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) { 50738625Srvb vnode_pager_setsize(vp, attr.va_size); 50838625Srvb } 50938625Srvb } 51038625Srvb } 51138625Srvb 51238625Srvb if (error) 51339085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 51438625Srvb else 51539085Srvb MARK_INT_SAT(CODA_RDWR_STATS); 51638625Srvb 51738625Srvb /* Do an internal close if necessary. */ 51838625Srvb if (opened_internally) { 51939085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 52083366Sjulian (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td); 52138625Srvb } 52238625Srvb 52338625Srvb /* Invalidate cached attributes if writing. */ 52438625Srvb if (rw == UIO_WRITE) 52538625Srvb cp->c_flags &= ~C_VATTR; 52638625Srvb return(error); 52738625Srvb} 52838625Srvb 52977784Sshafeeq 53077784Sshafeeq 53138625Srvbint 53239085Srvbcoda_ioctl(v) 53338625Srvb void *v; 53438625Srvb{ 53538625Srvb/* true args */ 53638625Srvb struct vop_ioctl_args *ap = v; 53738625Srvb struct vnode *vp = ap->a_vp; 53838625Srvb int com = ap->a_command; 53938625Srvb caddr_t data = ap->a_data; 54038625Srvb int flag = ap->a_fflag; 54138625Srvb struct ucred *cred = ap->a_cred; 54283366Sjulian struct thread *td = ap->a_td; 54338625Srvb/* locals */ 54438625Srvb int error; 54538625Srvb struct vnode *tvp; 54638625Srvb struct nameidata ndp; 54738625Srvb struct PioctlData *iap = (struct PioctlData *)data; 54838625Srvb 54939085Srvb MARK_ENTRY(CODA_IOCTL_STATS); 55038625Srvb 55139085Srvb CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));) 55238625Srvb 55338625Srvb /* Don't check for operation on a dying object, for ctlvp it 55438625Srvb shouldn't matter */ 55538625Srvb 55638625Srvb /* Must be control object to succeed. */ 55738625Srvb if (!IS_CTL_VP(vp)) { 55839085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 55939085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));) 56038625Srvb return (EOPNOTSUPP); 56138625Srvb } 56238625Srvb /* Look up the pathname. */ 56338625Srvb 56438625Srvb /* Should we use the name cache here? It would get it from 56538625Srvb lookupname sooner or later anyway, right? */ 56638625Srvb 56783366Sjulian NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td); 56838625Srvb error = namei(&ndp); 56938625Srvb tvp = ndp.ni_vp; 57038625Srvb 57138625Srvb if (error) { 57239085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 57339085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n", 57438625Srvb error));) 57538625Srvb return(error); 57638625Srvb } 57738625Srvb 57838625Srvb /* 57938625Srvb * Make sure this is a coda style cnode, but it may be a 58038625Srvb * different vfsp 58138625Srvb */ 58249687Sphk if (tvp->v_op != coda_vnodeop_p) { 58338625Srvb vrele(tvp); 58454655Seivind NDFREE(&ndp, NDF_ONLY_PNBUF); 58539085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 58639085Srvb CODADEBUG(CODA_IOCTL, 58739085Srvb myprintf(("coda_ioctl error: %s not a coda object\n", 58838625Srvb iap->path));) 58938625Srvb return(EINVAL); 59038625Srvb } 59138625Srvb 59238625Srvb if (iap->vi.in_size > VC_MAXDATASIZE) { 59354655Seivind NDFREE(&ndp, 0); 59438625Srvb return(EINVAL); 59538625Srvb } 59683366Sjulian error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td->td_proc); 59738625Srvb 59838625Srvb if (error) 59939085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 60038625Srvb else 60139085Srvb CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); ) 60238625Srvb 60338625Srvb vrele(tvp); 60454655Seivind NDFREE(&ndp, NDF_ONLY_PNBUF); 60538625Srvb return(error); 60638625Srvb} 60738625Srvb 60838625Srvb/* 60938625Srvb * To reduce the cost of a user-level venus;we cache attributes in 61038625Srvb * the kernel. Each cnode has storage allocated for an attribute. If 61138625Srvb * c_vattr is valid, return a reference to it. Otherwise, get the 61238625Srvb * attributes from venus and store them in the cnode. There is some 61338625Srvb * question if this method is a security leak. But I think that in 61438625Srvb * order to make this call, the user must have done a lookup and 61538625Srvb * opened the file, and therefore should already have access. 61638625Srvb */ 61738625Srvbint 61839085Srvbcoda_getattr(v) 61938625Srvb void *v; 62038625Srvb{ 62138625Srvb/* true args */ 62238625Srvb struct vop_getattr_args *ap = v; 62338625Srvb struct vnode *vp = ap->a_vp; 62438625Srvb struct cnode *cp = VTOC(vp); 62538625Srvb struct vattr *vap = ap->a_vap; 62638625Srvb struct ucred *cred = ap->a_cred; 62783366Sjulian struct thread *td = ap->a_td; 62838625Srvb/* locals */ 62938625Srvb int error; 63038625Srvb 63139085Srvb MARK_ENTRY(CODA_GETATTR_STATS); 63238625Srvb 63338625Srvb if (IS_UNMOUNTING(cp)) 63438625Srvb return ENODEV; 63538759Srvb 63638625Srvb /* Check for getattr of control object. */ 63738625Srvb if (IS_CTL_VP(vp)) { 63839085Srvb MARK_INT_FAIL(CODA_GETATTR_STATS); 63938625Srvb return(ENOENT); 64038625Srvb } 64138625Srvb 64238625Srvb /* Check to see if the attributes have already been cached */ 64338625Srvb if (VALID_VATTR(cp)) { 64439085Srvb CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n", 64538625Srvb cp->c_fid.Volume, 64638625Srvb cp->c_fid.Vnode, 64738625Srvb cp->c_fid.Unique));}); 64839085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 64938625Srvb print_vattr(&cp->c_vattr); ); 65038625Srvb 65138625Srvb *vap = cp->c_vattr; 65239085Srvb MARK_INT_SAT(CODA_GETATTR_STATS); 65338625Srvb return(0); 65438625Srvb } 65538625Srvb 65683366Sjulian error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap); 65738625Srvb 65838625Srvb if (!error) { 65939085Srvb CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n", 66038625Srvb cp->c_fid.Volume, 66138625Srvb cp->c_fid.Vnode, 66238625Srvb cp->c_fid.Unique, 66338625Srvb error)); ) 66438625Srvb 66539085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 66638625Srvb print_vattr(vap); ); 66738625Srvb 66838625Srvb { int size = vap->va_size; 66938625Srvb struct vnode *convp = cp->c_ovp; 67038625Srvb if (convp != (struct vnode *)0) { 67138625Srvb vnode_pager_setsize(convp, size); 67238625Srvb } 67338625Srvb } 67438625Srvb /* If not open for write, store attributes in cnode */ 67539085Srvb if ((cp->c_owrite == 0) && (coda_attr_cache)) { 67638625Srvb cp->c_vattr = *vap; 67738625Srvb cp->c_flags |= C_VATTR; 67838625Srvb } 67938625Srvb 68038625Srvb } 68138625Srvb return(error); 68238625Srvb} 68338625Srvb 68438625Srvbint 68539085Srvbcoda_setattr(v) 68638625Srvb void *v; 68738625Srvb{ 68838625Srvb/* true args */ 68938625Srvb struct vop_setattr_args *ap = v; 69038625Srvb register struct vnode *vp = ap->a_vp; 69138625Srvb struct cnode *cp = VTOC(vp); 69238625Srvb register struct vattr *vap = ap->a_vap; 69338625Srvb struct ucred *cred = ap->a_cred; 69483366Sjulian struct thread *td = ap->a_td; 69538625Srvb/* locals */ 69638625Srvb int error; 69738625Srvb 69839085Srvb MARK_ENTRY(CODA_SETATTR_STATS); 69938625Srvb 70038625Srvb /* Check for setattr of control object. */ 70138625Srvb if (IS_CTL_VP(vp)) { 70239085Srvb MARK_INT_FAIL(CODA_SETATTR_STATS); 70338625Srvb return(ENOENT); 70438625Srvb } 70538625Srvb 70639085Srvb if (codadebug & CODADBGMSK(CODA_SETATTR)) { 70738625Srvb print_vattr(vap); 70838625Srvb } 70983366Sjulian error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc); 71038625Srvb 71138625Srvb if (!error) 71238625Srvb cp->c_flags &= ~C_VATTR; 71338625Srvb 71438625Srvb { int size = vap->va_size; 71538625Srvb struct vnode *convp = cp->c_ovp; 71638625Srvb if (size != VNOVAL && convp != (struct vnode *)0) { 71738625Srvb vnode_pager_setsize(convp, size); 71838625Srvb } 71938625Srvb } 72039085Srvb CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); ) 72138625Srvb return(error); 72238625Srvb} 72338625Srvb 72438625Srvbint 72539085Srvbcoda_access(v) 72638625Srvb void *v; 72738625Srvb{ 72838625Srvb/* true args */ 72938625Srvb struct vop_access_args *ap = v; 73038625Srvb struct vnode *vp = ap->a_vp; 73138625Srvb struct cnode *cp = VTOC(vp); 73238625Srvb int mode = ap->a_mode; 73338625Srvb struct ucred *cred = ap->a_cred; 73483366Sjulian struct thread *td = ap->a_td; 73538625Srvb/* locals */ 73638625Srvb int error; 73738625Srvb 73839085Srvb MARK_ENTRY(CODA_ACCESS_STATS); 73938625Srvb 74038625Srvb /* Check for access of control object. Only read access is 74138625Srvb allowed on it. */ 74238625Srvb if (IS_CTL_VP(vp)) { 74338625Srvb /* bogus hack - all will be marked as successes */ 74439085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 74538625Srvb return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) 74638625Srvb ? 0 : EACCES); 74738625Srvb } 74838625Srvb 74938625Srvb /* 75038625Srvb * if the file is a directory, and we are checking exec (eg lookup) 75138625Srvb * access, and the file is in the namecache, then the user must have 75238625Srvb * lookup access to it. 75338625Srvb */ 75439085Srvb if (coda_access_cache) { 75538625Srvb if ((vp->v_type == VDIR) && (mode & VEXEC)) { 75639085Srvb if (coda_nc_lookup(cp, ".", 1, cred)) { 75739085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 75838625Srvb return(0); /* it was in the cache */ 75938625Srvb } 76038625Srvb } 76138625Srvb } 76238625Srvb 76383366Sjulian error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc); 76438625Srvb 76538625Srvb return(error); 76638625Srvb} 76738625Srvb 76838625Srvbint 76939085Srvbcoda_readlink(v) 77038625Srvb void *v; 77138625Srvb{ 77238625Srvb/* true args */ 77338625Srvb struct vop_readlink_args *ap = v; 77438625Srvb struct vnode *vp = ap->a_vp; 77538625Srvb struct cnode *cp = VTOC(vp); 77638625Srvb struct uio *uiop = ap->a_uio; 77738625Srvb struct ucred *cred = ap->a_cred; 77883366Sjulian struct thread *td = ap->a_uio->uio_td; 77938625Srvb/* locals */ 78038625Srvb int error; 78138625Srvb char *str; 78238625Srvb int len; 78338625Srvb 78439085Srvb MARK_ENTRY(CODA_READLINK_STATS); 78538625Srvb 78638625Srvb /* Check for readlink of control object. */ 78738625Srvb if (IS_CTL_VP(vp)) { 78839085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 78938625Srvb return(ENOENT); 79038625Srvb } 79138625Srvb 79239085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */ 79338625Srvb uiop->uio_rw = UIO_READ; 79438625Srvb error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); 79538625Srvb if (error) 79639085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 79738625Srvb else 79839085Srvb MARK_INT_SAT(CODA_READLINK_STATS); 79938625Srvb return(error); 80038625Srvb } 80138625Srvb 802111902Stjr error = venus_readlink(vtomi(vp), &cp->c_fid, cred, 803111902Stjr td != NULL ? td->td_proc : NULL, &str, &len); 80438625Srvb 80538625Srvb if (!error) { 80638625Srvb uiop->uio_rw = UIO_READ; 80738625Srvb error = uiomove(str, len, uiop); 80838625Srvb 80939085Srvb if (coda_symlink_cache) { 81038625Srvb cp->c_symlink = str; 81138625Srvb cp->c_symlen = len; 81238625Srvb cp->c_flags |= C_SYMLINK; 81338625Srvb } else 81439085Srvb CODA_FREE(str, len); 81538625Srvb } 81638625Srvb 81739085Srvb CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));) 81838625Srvb return(error); 81938625Srvb} 82038625Srvb 82138625Srvbint 82239085Srvbcoda_fsync(v) 82338625Srvb void *v; 82438625Srvb{ 82538625Srvb/* true args */ 82638625Srvb struct vop_fsync_args *ap = v; 82738625Srvb struct vnode *vp = ap->a_vp; 82838625Srvb struct cnode *cp = VTOC(vp); 82938625Srvb struct ucred *cred = ap->a_cred; 83083366Sjulian struct thread *td = ap->a_td; 83138625Srvb/* locals */ 83238625Srvb struct vnode *convp = cp->c_ovp; 83338625Srvb int error; 83438625Srvb 83539085Srvb MARK_ENTRY(CODA_FSYNC_STATS); 83638625Srvb 83738625Srvb /* Check for fsync on an unmounting object */ 83838625Srvb /* The NetBSD kernel, in it's infinite wisdom, can try to fsync 83938625Srvb * after an unmount has been initiated. This is a Bad Thing, 84038625Srvb * which we have to avoid. Not a legitimate failure for stats. 84138625Srvb */ 84238625Srvb if (IS_UNMOUNTING(cp)) { 84338625Srvb return(ENODEV); 84438625Srvb } 84538625Srvb 84638625Srvb /* Check for fsync of control object. */ 84738625Srvb if (IS_CTL_VP(vp)) { 84839085Srvb MARK_INT_SAT(CODA_FSYNC_STATS); 84938625Srvb return(0); 85038625Srvb } 85138625Srvb 85238625Srvb if (convp) 85383366Sjulian VOP_FSYNC(convp, cred, MNT_WAIT, td); 85438625Srvb 85538625Srvb /* 85638625Srvb * We see fsyncs with usecount == 1 then usecount == 0. 85738625Srvb * For now we ignore them. 85838625Srvb */ 85938625Srvb /* 860103937Sjeff VI_LOCK(vp); 86138625Srvb if (!vp->v_usecount) { 86239085Srvb printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n", 86338625Srvb vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING); 86438625Srvb } 865103937Sjeff VI_UNLOCK(vp); 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; 88183366Sjulian error = venus_fsync(vtomi(vp), &cp->c_fid, cred, td->td_proc); 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; 89883366Sjulian struct thread *td __attribute__((unused)) = curthread; 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 933103937Sjeff printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vrefcnt(vp), vp, cp); 93438625Srvb if (cp->c_ovp != NULL) 93539085Srvb printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n", 936103937Sjeff vrefcnt(vp), vp, cp); 93738625Srvb#endif 93883366Sjulian lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td); 93938625Srvb } else { 94039650Srvb#ifdef OLD_DIAGNOSTIC 941103937Sjeff if (vrefcnt(CTOV(cp))) { 94239085Srvb panic("coda_inactive: nonzero reference count"); 94338625Srvb } 94438625Srvb if (cp->c_ovp != NULL) { 94539085Srvb panic("coda_inactive: cp->ovp != NULL"); 94638625Srvb } 94738625Srvb#endif 94883366Sjulian VOP_UNLOCK(vp, 0, td); 94938625Srvb vgone(vp); 95038625Srvb } 95138625Srvb 95239085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 95338625Srvb return(0); 95438625Srvb} 95538625Srvb 95638625Srvb/* 95796755Strhodes * Remote filesystem 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; 98083366Sjulian struct thread *td = cnp->cn_thread; 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 */ 102383366Sjulian error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc, &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)) { 109483366Sjulian if ((error = VOP_UNLOCK(dvp, 0, td))) { 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) { 110283366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 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. */ 111183366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 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; 114083366Sjulian struct thread *td = cnp->cn_thread; 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 116183366Sjulian error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td->td_proc, &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) { 120083366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 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 return(error); 121238625Srvb} 121338625Srvb 121438625Srvbint 121539085Srvbcoda_remove(v) 121638625Srvb void *v; 121738625Srvb{ 121838625Srvb/* true args */ 121938625Srvb struct vop_remove_args *ap = v; 122038625Srvb struct vnode *dvp = ap->a_dvp; 122138625Srvb struct cnode *cp = VTOC(dvp); 122238625Srvb struct componentname *cnp = ap->a_cnp; 122338625Srvb struct ucred *cred = cnp->cn_cred; 122483366Sjulian struct thread *td = cnp->cn_thread; 122538625Srvb/* locals */ 122638625Srvb int error; 122738625Srvb const char *nm = cnp->cn_nameptr; 122838625Srvb int len = cnp->cn_namelen; 122938625Srvb struct cnode *tp; 123038625Srvb 123139085Srvb MARK_ENTRY(CODA_REMOVE_STATS); 123238625Srvb 123339085Srvb CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n", 123438625Srvb nm, cp->c_fid.Volume, cp->c_fid.Vnode, 123538625Srvb cp->c_fid.Unique));); 123638625Srvb 123739085Srvb /* Remove the file's entry from the CODA Name Cache */ 123838625Srvb /* We're being conservative here, it might be that this person 123938625Srvb * doesn't really have sufficient access to delete the file 124038625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 124138625Srvb */ 124238625Srvb /* I'm gonna go out on a limb here. If a file and a hardlink to it 124338625Srvb * exist, and one is removed, the link count on the other will be 124438625Srvb * off by 1. We could either invalidate the attrs if cached, or 124538625Srvb * fix them. I'll try to fix them. DCS 11/8/94 124638625Srvb */ 124739085Srvb tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); 124838625Srvb if (tp) { 124938625Srvb if (VALID_VATTR(tp)) { /* If attrs are cached */ 125038625Srvb if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */ 125138625Srvb tp->c_vattr.va_nlink--; 125238625Srvb } 125338625Srvb } 125438625Srvb 125539085Srvb coda_nc_zapfile(VTOC(dvp), nm, len); 125638625Srvb /* No need to flush it if it doesn't exist! */ 125738625Srvb } 125838625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 125938625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 126038625Srvb 126138625Srvb /* Check for remove of control object. */ 126238625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 126339085Srvb MARK_INT_FAIL(CODA_REMOVE_STATS); 126438625Srvb return(ENOENT); 126538625Srvb } 126638625Srvb 126783366Sjulian error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td->td_proc); 126838625Srvb 126939085Srvb CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); ) 127038625Srvb 127138625Srvb return(error); 127238625Srvb} 127338625Srvb 127438625Srvbint 127539085Srvbcoda_link(v) 127638625Srvb void *v; 127738625Srvb{ 127838625Srvb/* true args */ 127938625Srvb struct vop_link_args *ap = v; 128038625Srvb struct vnode *vp = ap->a_vp; 128138625Srvb struct cnode *cp = VTOC(vp); 128238625Srvb struct vnode *tdvp = ap->a_tdvp; 128338625Srvb struct cnode *tdcp = VTOC(tdvp); 128438625Srvb struct componentname *cnp = ap->a_cnp; 128538625Srvb struct ucred *cred = cnp->cn_cred; 128683366Sjulian struct thread *td = cnp->cn_thread; 128738625Srvb/* locals */ 128838625Srvb int error; 128938625Srvb const char *nm = cnp->cn_nameptr; 129038625Srvb int len = cnp->cn_namelen; 129138625Srvb 129239085Srvb MARK_ENTRY(CODA_LINK_STATS); 129338625Srvb 129439085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 129538625Srvb 129638625Srvb myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n", 129738625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 129838625Srvb myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n", 129938625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 130038625Srvb 130138625Srvb } 130239085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 130338625Srvb myprintf(("link: vp fid: (%lx.%lx.%lx)\n", 130438625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 130538625Srvb myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n", 130638625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 130738625Srvb 130838625Srvb } 130938625Srvb 131038625Srvb /* Check for link to/from control object. */ 131138625Srvb if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { 131239085Srvb MARK_INT_FAIL(CODA_LINK_STATS); 131338625Srvb return(EACCES); 131438625Srvb } 131538625Srvb 131683366Sjulian error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td->td_proc); 131738625Srvb 131838625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 131938625Srvb VTOC(tdvp)->c_flags &= ~C_VATTR; 132038625Srvb VTOC(vp)->c_flags &= ~C_VATTR; 132138625Srvb 132239085Srvb CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); ) 132338625Srvb 132438625Srvb return(error); 132538625Srvb} 132638625Srvb 132738625Srvbint 132839085Srvbcoda_rename(v) 132938625Srvb void *v; 133038625Srvb{ 133138625Srvb/* true args */ 133238625Srvb struct vop_rename_args *ap = v; 133338625Srvb struct vnode *odvp = ap->a_fdvp; 133438625Srvb struct cnode *odcp = VTOC(odvp); 133538625Srvb struct componentname *fcnp = ap->a_fcnp; 133638625Srvb struct vnode *ndvp = ap->a_tdvp; 133738625Srvb struct cnode *ndcp = VTOC(ndvp); 133838625Srvb struct componentname *tcnp = ap->a_tcnp; 133938625Srvb struct ucred *cred = fcnp->cn_cred; 134083366Sjulian struct thread *td = fcnp->cn_thread; 134138625Srvb/* true args */ 134238625Srvb int error; 134338625Srvb const char *fnm = fcnp->cn_nameptr; 134438625Srvb int flen = fcnp->cn_namelen; 134538625Srvb const char *tnm = tcnp->cn_nameptr; 134638625Srvb int tlen = tcnp->cn_namelen; 134738625Srvb 134839085Srvb MARK_ENTRY(CODA_RENAME_STATS); 134938625Srvb 135038625Srvb /* Hmmm. The vnodes are already looked up. Perhaps they are locked? 135138625Srvb This could be Bad. XXX */ 135239650Srvb#ifdef OLD_DIAGNOSTIC 135338625Srvb if ((fcnp->cn_cred != tcnp->cn_cred) 135483366Sjulian || (fcnp->cn_thread != tcnp->cn_thread)) 135538625Srvb { 135639085Srvb panic("coda_rename: component names don't agree"); 135738625Srvb } 135839650Srvb#endif 135938625Srvb 136038625Srvb /* Check for rename involving control object. */ 136138625Srvb if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { 136239085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 136338625Srvb return(EACCES); 136438625Srvb } 136538625Srvb 136638625Srvb /* Problem with moving directories -- need to flush entry for .. */ 136738625Srvb if (odvp != ndvp) { 136839085Srvb struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred); 136938625Srvb if (ovcp) { 137038625Srvb struct vnode *ovp = CTOV(ovcp); 137138625Srvb if ((ovp) && 137238625Srvb (ovp->v_type == VDIR)) /* If it's a directory */ 137339085Srvb coda_nc_zapfile(VTOC(ovp),"..", 2); 137438625Srvb } 137538625Srvb } 137638625Srvb 137738625Srvb /* Remove the entries for both source and target files */ 137839085Srvb coda_nc_zapfile(VTOC(odvp), fnm, flen); 137939085Srvb coda_nc_zapfile(VTOC(ndvp), tnm, tlen); 138038625Srvb 138138625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 138238625Srvb VTOC(odvp)->c_flags &= ~C_VATTR; 138338625Srvb VTOC(ndvp)->c_flags &= ~C_VATTR; 138438625Srvb 138539085Srvb if (flen+1 > CODA_MAXNAMLEN) { 138639085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 138738625Srvb error = EINVAL; 138838625Srvb goto exit; 138938625Srvb } 139038625Srvb 139139085Srvb if (tlen+1 > CODA_MAXNAMLEN) { 139239085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 139338625Srvb error = EINVAL; 139438625Srvb goto exit; 139538625Srvb } 139638625Srvb 139783366Sjulian error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td->td_proc); 139838625Srvb 139938625Srvb exit: 140039085Srvb CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));) 140138625Srvb /* XXX - do we need to call cache pureg on the moved vnode? */ 140238625Srvb cache_purge(ap->a_fvp); 140338625Srvb 140438625Srvb /* It seems to be incumbent on us to drop locks on all four vnodes */ 140538625Srvb /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */ 140638625Srvb 140738625Srvb vrele(ap->a_fvp); 140838625Srvb vrele(odvp); 140938625Srvb 141038625Srvb if (ap->a_tvp) { 141138625Srvb if (ap->a_tvp == ndvp) { 141238625Srvb vrele(ap->a_tvp); 141338625Srvb } else { 141438625Srvb vput(ap->a_tvp); 141538625Srvb } 141638625Srvb } 141738625Srvb 141838625Srvb vput(ndvp); 141938625Srvb return(error); 142038625Srvb} 142138625Srvb 142238625Srvbint 142339085Srvbcoda_mkdir(v) 142438625Srvb void *v; 142538625Srvb{ 142638625Srvb/* true args */ 142738625Srvb struct vop_mkdir_args *ap = v; 142838625Srvb struct vnode *dvp = ap->a_dvp; 142938625Srvb struct cnode *dcp = VTOC(dvp); 143038625Srvb struct componentname *cnp = ap->a_cnp; 143138625Srvb register struct vattr *va = ap->a_vap; 143238625Srvb struct vnode **vpp = ap->a_vpp; 143338625Srvb struct ucred *cred = cnp->cn_cred; 143483366Sjulian struct thread *td = cnp->cn_thread; 143538625Srvb/* locals */ 143638625Srvb int error; 143738625Srvb const char *nm = cnp->cn_nameptr; 143838625Srvb int len = cnp->cn_namelen; 143938625Srvb struct cnode *cp; 144038625Srvb ViceFid VFid; 144138625Srvb struct vattr ova; 144238625Srvb 144339085Srvb MARK_ENTRY(CODA_MKDIR_STATS); 144438625Srvb 144538625Srvb /* Check for mkdir of target object. */ 144638625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 144738625Srvb *vpp = (struct vnode *)0; 144839085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 144938625Srvb return(EACCES); 145038625Srvb } 145138625Srvb 145239085Srvb if (len+1 > CODA_MAXNAMLEN) { 145338625Srvb *vpp = (struct vnode *)0; 145439085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 145538625Srvb return(EACCES); 145638625Srvb } 145738625Srvb 145883366Sjulian error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td->td_proc, &VFid, &ova); 145938625Srvb 146038625Srvb if (!error) { 146139085Srvb if (coda_find(&VFid) != NULL) 146238625Srvb panic("cnode existed for newly created directory!"); 146338625Srvb 146438625Srvb 146539085Srvb cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); 146638625Srvb *vpp = CTOV(cp); 146738625Srvb 146838625Srvb /* enter the new vnode in the Name Cache */ 146939085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 147038625Srvb 147138625Srvb /* as a side effect, enter "." and ".." for the directory */ 147239085Srvb coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); 147339085Srvb coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); 147438625Srvb 147539085Srvb if (coda_attr_cache) { 147638625Srvb VTOC(*vpp)->c_vattr = ova; /* update the attr cache */ 147738625Srvb VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */ 147838625Srvb } 147938625Srvb 148038625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 148138625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 148238625Srvb 148339085Srvb CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n", 148438625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 148538625Srvb } else { 148638625Srvb *vpp = (struct vnode *)0; 148739085Srvb CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));) 148838625Srvb } 148938625Srvb 149038625Srvb return(error); 149138625Srvb} 149238625Srvb 149338625Srvbint 149439085Srvbcoda_rmdir(v) 149538625Srvb void *v; 149638625Srvb{ 149738625Srvb/* true args */ 149838625Srvb struct vop_rmdir_args *ap = v; 149938625Srvb struct vnode *dvp = ap->a_dvp; 150038625Srvb struct cnode *dcp = VTOC(dvp); 150138625Srvb struct componentname *cnp = ap->a_cnp; 150238625Srvb struct ucred *cred = cnp->cn_cred; 150383366Sjulian struct thread *td = cnp->cn_thread; 150438625Srvb/* true args */ 150538625Srvb int error; 150638625Srvb const char *nm = cnp->cn_nameptr; 150738625Srvb int len = cnp->cn_namelen; 150838625Srvb struct cnode *cp; 150938625Srvb 151039085Srvb MARK_ENTRY(CODA_RMDIR_STATS); 151138625Srvb 151238625Srvb /* Check for rmdir of control object. */ 151338625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 151439085Srvb MARK_INT_FAIL(CODA_RMDIR_STATS); 151538625Srvb return(ENOENT); 151638625Srvb } 151738625Srvb 151838625Srvb /* We're being conservative here, it might be that this person 151938625Srvb * doesn't really have sufficient access to delete the file 152038625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 152138625Srvb */ 152238625Srvb /* 152338625Srvb * As a side effect of the rmdir, remove any entries for children of 152438625Srvb * the directory, especially "." and "..". 152538625Srvb */ 152639085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 152739085Srvb if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); 152838625Srvb 152939085Srvb /* Remove the file's entry from the CODA Name Cache */ 153039085Srvb coda_nc_zapfile(dcp, nm, len); 153138625Srvb 153238625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 153338625Srvb dcp->c_flags &= ~C_VATTR; 153438625Srvb 153583366Sjulian error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc); 153638625Srvb 153739085Srvb CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); ) 153838625Srvb 153938625Srvb return(error); 154038625Srvb} 154138625Srvb 154238625Srvbint 154339085Srvbcoda_symlink(v) 154438625Srvb void *v; 154538625Srvb{ 154638625Srvb/* true args */ 154738625Srvb struct vop_symlink_args *ap = v; 154838625Srvb struct vnode *tdvp = ap->a_dvp; 154938625Srvb struct cnode *tdcp = VTOC(tdvp); 155038625Srvb struct componentname *cnp = ap->a_cnp; 155138625Srvb struct vattr *tva = ap->a_vap; 155238625Srvb char *path = ap->a_target; 155338625Srvb struct ucred *cred = cnp->cn_cred; 155483366Sjulian struct thread *td = cnp->cn_thread; 155553131Seivind struct vnode **vpp = ap->a_vpp; 155638625Srvb/* locals */ 155738625Srvb int error; 155838625Srvb /* 155939085Srvb * XXX I'm assuming the following things about coda_symlink's 156038625Srvb * arguments: 156138625Srvb * t(foo) is the new name/parent/etc being created. 156238625Srvb * lname is the contents of the new symlink. 156338625Srvb */ 156438759Srvb char *nm = cnp->cn_nameptr; 156538625Srvb int len = cnp->cn_namelen; 156638625Srvb int plen = strlen(path); 156738625Srvb 156838625Srvb /* 156938625Srvb * Here's the strategy for the moment: perform the symlink, then 157038625Srvb * do a lookup to grab the resulting vnode. I know this requires 157138625Srvb * two communications with Venus for a new sybolic link, but 157238625Srvb * that's the way the ball bounces. I don't yet want to change 157338625Srvb * the way the Mach symlink works. When Mach support is 157438625Srvb * deprecated, we should change symlink so that the common case 157538625Srvb * returns the resultant vnode in a vpp argument. 157638625Srvb */ 157738625Srvb 157839085Srvb MARK_ENTRY(CODA_SYMLINK_STATS); 157938625Srvb 158038625Srvb /* Check for symlink of control object. */ 158138625Srvb if (IS_CTL_NAME(tdvp, nm, len)) { 158239085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 158338625Srvb return(EACCES); 158438625Srvb } 158538625Srvb 158639085Srvb if (plen+1 > CODA_MAXPATHLEN) { 158739085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 158838625Srvb return(EINVAL); 158938625Srvb } 159038625Srvb 159139085Srvb if (len+1 > CODA_MAXNAMLEN) { 159239085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 159338625Srvb error = EINVAL; 159438625Srvb goto exit; 159538625Srvb } 159638625Srvb 159783366Sjulian error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td->td_proc); 159838625Srvb 159938625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 160038625Srvb tdcp->c_flags &= ~C_VATTR; 160138625Srvb 160253131Seivind if (error == 0) 160353131Seivind error = VOP_LOOKUP(tdvp, vpp, cnp); 160438625Srvb 160538625Srvb exit: 160639085Srvb CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); ) 160738625Srvb return(error); 160838625Srvb} 160938625Srvb 161038625Srvb/* 161138625Srvb * Read directory entries. 161238625Srvb */ 161338625Srvbint 161439085Srvbcoda_readdir(v) 161538625Srvb void *v; 161638625Srvb{ 161738625Srvb/* true args */ 161838625Srvb struct vop_readdir_args *ap = v; 161938625Srvb struct vnode *vp = ap->a_vp; 162038625Srvb struct cnode *cp = VTOC(vp); 162138625Srvb register struct uio *uiop = ap->a_uio; 162238625Srvb struct ucred *cred = ap->a_cred; 162338625Srvb int *eofflag = ap->a_eofflag; 162438625Srvb u_long **cookies = ap->a_cookies; 162538625Srvb int *ncookies = ap->a_ncookies; 162683366Sjulian struct thread *td = ap->a_uio->uio_td; 162738625Srvb/* upcall decl */ 162838625Srvb/* locals */ 162938625Srvb int error = 0; 163038625Srvb 163139085Srvb MARK_ENTRY(CODA_READDIR_STATS); 163238625Srvb 163349524Sbde CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n", 163449524Sbde (void *)uiop->uio_iov->iov_base, 163549524Sbde uiop->uio_resid, 163649524Sbde (long long)uiop->uio_offset, 163749524Sbde uiop->uio_segflg)); ) 163838625Srvb 163938625Srvb /* Check for readdir of control object. */ 164038625Srvb if (IS_CTL_VP(vp)) { 164139085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 164238625Srvb return(ENOENT); 164338625Srvb } 164438625Srvb 164538759Srvb { 164638625Srvb /* If directory is not already open do an "internal open" on it. */ 164738625Srvb int opened_internally = 0; 164838625Srvb if (cp->c_ovp == NULL) { 164938625Srvb opened_internally = 1; 165039085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 165183366Sjulian error = VOP_OPEN(vp, FREAD, cred, td); 165239085Srvbprintf("coda_readdir: Internally Opening %p\n", vp); 165338625Srvb if (error) { 165439085Srvb printf("coda_readdir: VOP_OPEN on container failed %d\n", error); 165538625Srvb return (error); 165638625Srvb } 165738625Srvb if (vp->v_type == VREG) { 165883366Sjulian error = vfs_object_create(vp, td, cred); 165938625Srvb if (error != 0) { 166039085Srvb printf("coda_readdir: vfs_object_create() returns %d\n", error); 166138625Srvb vput(vp); 166238625Srvb } 166338625Srvb } 166438625Srvb if (error) return(error); 166538625Srvb } 166638625Srvb 166738625Srvb /* Have UFS handle the call. */ 1668103937Sjeff CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vrefcnt(vp))); ) 166938625Srvb error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, 167038625Srvb cookies); 167138625Srvb 167238625Srvb if (error) 167339085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 167438625Srvb else 167539085Srvb MARK_INT_SAT(CODA_READDIR_STATS); 167638625Srvb 167738625Srvb /* Do an "internal close" if necessary. */ 167838625Srvb if (opened_internally) { 167939085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 168083366Sjulian (void)VOP_CLOSE(vp, FREAD, cred, td); 168138625Srvb } 168238625Srvb } 168338625Srvb 168438625Srvb return(error); 168538625Srvb} 168638625Srvb 168738625Srvb/* 168896755Strhodes * Convert from filesystem blocks to device blocks 168938625Srvb */ 169038625Srvbint 169139085Srvbcoda_bmap(v) 169238625Srvb void *v; 169338625Srvb{ 169438625Srvb /* XXX on the global proc */ 169538625Srvb/* true args */ 169638625Srvb struct vop_bmap_args *ap = v; 169738625Srvb struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */ 169838625Srvb daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */ 169938625Srvb struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */ 170096572Sphk daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */ 170183366Sjulian struct thread *td __attribute__((unused)) = curthread; 170238625Srvb/* upcall decl */ 170338625Srvb/* locals */ 170438625Srvb 170538625Srvb int ret = 0; 170638625Srvb struct cnode *cp; 170738625Srvb 170838625Srvb cp = VTOC(vp); 170938625Srvb if (cp->c_ovp) { 171039728Srvb return EINVAL; 171138625Srvb ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb); 171239650Srvb#if 0 171392363Smckusick printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %lld, ap->a_runp %p, ap->a_runb %p) = %d\n", 171438625Srvb cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret); 171539650Srvb#endif 171638625Srvb return ret; 171738625Srvb } else { 171841504Srvb#if 0 171939085Srvb printf("coda_bmap: no container\n"); 172041504Srvb#endif 172138625Srvb return(EOPNOTSUPP); 172238625Srvb } 172338625Srvb} 172438625Srvb 172538625Srvb/* 172638625Srvb * I don't think the following two things are used anywhere, so I've 172738625Srvb * commented them out 172838625Srvb * 172938625Srvb * struct buf *async_bufhead; 173038625Srvb * int async_daemon_count; 173138625Srvb */ 173238625Srvbint 173339085Srvbcoda_strategy(v) 173438625Srvb void *v; 173538625Srvb{ 173638625Srvb/* true args */ 173738625Srvb struct vop_strategy_args *ap = v; 173838625Srvb register struct buf *bp __attribute__((unused)) = ap->a_bp; 173983366Sjulian struct thread *td __attribute__((unused)) = curthread; 174038625Srvb/* upcall decl */ 174138625Srvb/* locals */ 174238625Srvb 174339085Srvb printf("coda_strategy: called ???\n"); 174438625Srvb return(EOPNOTSUPP); 174538625Srvb} 174638625Srvb 174738625Srvbint 174839085Srvbcoda_reclaim(v) 174938625Srvb void *v; 175038625Srvb{ 175138625Srvb/* true args */ 175238625Srvb struct vop_reclaim_args *ap = v; 175338625Srvb struct vnode *vp = ap->a_vp; 175438625Srvb struct cnode *cp = VTOC(vp); 175538625Srvb/* upcall decl */ 175638625Srvb/* locals */ 175738625Srvb 175838625Srvb/* 175938625Srvb * Forced unmount/flush will let vnodes with non zero use be destroyed! 176038625Srvb */ 176138625Srvb ENTRY; 176238625Srvb 176338625Srvb if (IS_UNMOUNTING(cp)) { 176438625Srvb#ifdef DEBUG 176538625Srvb if (VTOC(vp)->c_ovp) { 176638625Srvb if (IS_UNMOUNTING(cp)) 176739085Srvb printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp); 176838625Srvb } 176938625Srvb#endif 177038625Srvb } else { 177139650Srvb#ifdef OLD_DIAGNOSTIC 1772103937Sjeff if (vrefcnt(vp) != 0) 177339650Srvb print("coda_reclaim: pushing active %p\n", vp); 177438625Srvb if (VTOC(vp)->c_ovp) { 177539085Srvb panic("coda_reclaim: c_ovp not void"); 177638625Srvb } 177739650Srvb#endif 177838625Srvb } 177938625Srvb cache_purge(vp); 178066615Sjasone lockdestroy(&(VTOC(vp)->c_lock)); 178139085Srvb coda_free(VTOC(vp)); 178238625Srvb VTOC(vp) = NULL; 178338625Srvb return (0); 178438625Srvb} 178538625Srvb 178638625Srvbint 178739085Srvbcoda_lock(v) 178838625Srvb void *v; 178938625Srvb{ 179038625Srvb/* true args */ 179138625Srvb struct vop_lock_args *ap = v; 179238625Srvb struct vnode *vp = ap->a_vp; 179338625Srvb struct cnode *cp = VTOC(vp); 179483366Sjulian struct thread *td = ap->a_td; 179538625Srvb/* upcall decl */ 179638625Srvb/* locals */ 179738625Srvb 179838625Srvb ENTRY; 179938625Srvb 180039085Srvb if (coda_lockdebug) { 180138625Srvb myprintf(("Attempting lock on %lx.%lx.%lx\n", 180238625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 180338625Srvb } 180438625Srvb 180542900Seivind#ifndef DEBUG_LOCKS 180683366Sjulian return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td)); 180742900Seivind#else 180883366Sjulian return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td, 180942900Seivind "coda_lock", vp->filename, vp->line)); 181042900Seivind#endif 181138625Srvb} 181238625Srvb 181338625Srvbint 181439085Srvbcoda_unlock(v) 181538625Srvb void *v; 181638625Srvb{ 181738625Srvb/* true args */ 181838625Srvb struct vop_unlock_args *ap = v; 181938625Srvb struct vnode *vp = ap->a_vp; 182038625Srvb struct cnode *cp = VTOC(vp); 182183366Sjulian struct thread *td = ap->a_td; 182238625Srvb/* upcall decl */ 182338625Srvb/* locals */ 182438625Srvb 182538625Srvb ENTRY; 182639085Srvb if (coda_lockdebug) { 182738625Srvb myprintf(("Attempting unlock on %lx.%lx.%lx\n", 182838625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 182938625Srvb } 183038625Srvb 183183366Sjulian return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td)); 183238625Srvb} 183338625Srvb 183438625Srvbint 183539085Srvbcoda_islocked(v) 183638625Srvb void *v; 183738625Srvb{ 183838625Srvb/* true args */ 183938625Srvb struct vop_islocked_args *ap = v; 184038625Srvb struct cnode *cp = VTOC(ap->a_vp); 184138625Srvb ENTRY; 184238625Srvb 184383366Sjulian return (lockstatus(&cp->c_lock, ap->a_td)); 184438625Srvb} 184538625Srvb 184638625Srvb/* How one looks up a vnode given a device/inode pair: */ 184738625Srvbint 184839085Srvbcoda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp) 184938625Srvb{ 185038625Srvb /* This is like VFS_VGET() or igetinode()! */ 185138625Srvb int error; 185238625Srvb struct mount *mp; 185338625Srvb 185438625Srvb if (!(mp = devtomp(dev))) { 185549524Sbde myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n", 185649524Sbde (u_long)dev2udev(dev))); 185738625Srvb return(ENXIO); 185838625Srvb } 185938625Srvb 186038625Srvb /* XXX - ensure that nonzero-return means failure */ 186192462Smckusick error = VFS_VGET(mp,ino,LK_EXCLUSIVE,vpp); 186238625Srvb if (error) { 186349524Sbde myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n", 186449524Sbde (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error)); 186538625Srvb return(ENOENT); 186638625Srvb } 186738625Srvb return(0); 186838625Srvb} 186938625Srvb 187038625Srvbvoid 187138625Srvbprint_vattr( attr ) 187238625Srvb struct vattr *attr; 187338625Srvb{ 187438625Srvb char *typestr; 187538625Srvb 187638625Srvb switch (attr->va_type) { 187738625Srvb case VNON: 187838625Srvb typestr = "VNON"; 187938625Srvb break; 188038625Srvb case VREG: 188138625Srvb typestr = "VREG"; 188238625Srvb break; 188338625Srvb case VDIR: 188438625Srvb typestr = "VDIR"; 188538625Srvb break; 188638625Srvb case VBLK: 188738625Srvb typestr = "VBLK"; 188838625Srvb break; 188938625Srvb case VCHR: 189038625Srvb typestr = "VCHR"; 189138625Srvb break; 189238625Srvb case VLNK: 189338625Srvb typestr = "VLNK"; 189438625Srvb break; 189538625Srvb case VSOCK: 189638625Srvb typestr = "VSCK"; 189738625Srvb break; 189838625Srvb case VFIFO: 189938625Srvb typestr = "VFFO"; 190038625Srvb break; 190138625Srvb case VBAD: 190238625Srvb typestr = "VBAD"; 190338625Srvb break; 190438625Srvb default: 190538625Srvb typestr = "????"; 190638625Srvb break; 190738625Srvb } 190838625Srvb 190938625Srvb 191038625Srvb myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", 191138625Srvb typestr, (int)attr->va_mode, (int)attr->va_uid, 191238625Srvb (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); 191338625Srvb 191438625Srvb myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", 191538625Srvb (int)attr->va_fileid, (int)attr->va_nlink, 191638625Srvb (int)attr->va_size, 191738625Srvb (int)attr->va_blocksize,(int)attr->va_bytes)); 191838625Srvb myprintf((" gen %ld flags %ld vaflags %d\n", 191938625Srvb attr->va_gen, attr->va_flags, attr->va_vaflags)); 192038625Srvb myprintf((" atime sec %d nsec %d\n", 192138625Srvb (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec)); 192238625Srvb myprintf((" mtime sec %d nsec %d\n", 192338625Srvb (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec)); 192438625Srvb myprintf((" ctime sec %d nsec %d\n", 192538625Srvb (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec)); 192638625Srvb} 192738625Srvb 192838625Srvb/* How to print a ucred */ 192938625Srvbvoid 193038625Srvbprint_cred(cred) 193138625Srvb struct ucred *cred; 193238625Srvb{ 193338625Srvb 193438625Srvb int i; 193538625Srvb 193638625Srvb myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid)); 193738625Srvb 193838625Srvb for (i=0; i < cred->cr_ngroups; i++) 193938625Srvb myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i])); 194038625Srvb myprintf(("\n")); 194138625Srvb 194238625Srvb} 194338625Srvb 194438625Srvb/* 194538625Srvb * Return a vnode for the given fid. 194638625Srvb * If no cnode exists for this fid create one and put it 194738625Srvb * in a table hashed by fid.Volume and fid.Vnode. If the cnode for 194838625Srvb * this fid is already in the table return it (ref count is 194939085Srvb * incremented by coda_find. The cnode will be flushed from the 195039085Srvb * table when coda_inactive calls coda_unsave. 195138625Srvb */ 195238625Srvbstruct cnode * 195339085Srvbmake_coda_node(fid, vfsp, type) 195438625Srvb ViceFid *fid; struct mount *vfsp; short type; 195538625Srvb{ 195638625Srvb struct cnode *cp; 195738625Srvb int err; 195838625Srvb 195939085Srvb if ((cp = coda_find(fid)) == NULL) { 196038625Srvb struct vnode *vp; 196138625Srvb 196239085Srvb cp = coda_alloc(); 196338625Srvb lockinit(&cp->c_lock, PINOD, "cnode", 0, 0); 196438625Srvb cp->c_fid = *fid; 196538625Srvb 1966103314Snjl err = getnewvnode("coda", vfsp, coda_vnodeop_p, &vp); 196738625Srvb if (err) { 196839085Srvb panic("coda: getnewvnode returned error %d\n", err); 196938625Srvb } 197038625Srvb vp->v_data = cp; 197138625Srvb vp->v_type = type; 197238625Srvb cp->c_vnode = vp; 197339085Srvb coda_save(cp); 197438625Srvb 197538625Srvb } else { 197638625Srvb vref(CTOV(cp)); 197738625Srvb } 197838625Srvb 197938625Srvb return cp; 198038625Srvb} 1981111903Stjr 1982111903Stjrint 1983111903Stjrcoda_pathconf(v) 1984111903Stjr void *v; 1985111903Stjr{ 1986111903Stjr struct vop_pathconf_args *ap; 1987111903Stjr int error; 1988111903Stjr int *retval; 1989111903Stjr 1990111903Stjr ap = v; 1991111903Stjr retval = ap->a_retval; 1992111903Stjr error = 0; 1993111903Stjr 1994111903Stjr switch (ap->a_name) { 1995111903Stjr case _PC_NAME_MAX: 1996111903Stjr *retval = CODA_MAXNAMLEN; 1997111903Stjr break; 1998111903Stjr case _PC_PATH_MAX: 1999111903Stjr *retval = CODA_MAXPATHLEN; 2000111903Stjr break; 2001111903Stjr default: 2002111903Stjr error = vop_stdpathconf(ap); 2003111903Stjr break; 2004111903Stjr } 2005111903Stjr 2006111903Stjr return (error); 2007111903Stjr} 2008