coda_vnops.c revision 116173
138625Srvb/* 238759Srvb * Coda: an Experimental Distributed File System 338759Srvb * Release 3.1 438759Srvb * 538759Srvb * Copyright (c) 1987-1998 Carnegie Mellon University 638759Srvb * All Rights Reserved 738759Srvb * 838759Srvb * Permission to use, copy, modify and distribute this software and its 938759Srvb * documentation is hereby granted, provided that both the copyright 1038759Srvb * notice and this permission notice appear in all copies of the 1138759Srvb * software, derivative works or modified versions, and any portions 1238759Srvb * thereof, and that both notices appear in supporting documentation, and 1338759Srvb * that credit is given to Carnegie Mellon University in all documents 1438759Srvb * and publicity pertaining to direct or indirect use of this code or its 1538759Srvb * derivatives. 1638759Srvb * 1738759Srvb * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, 1838759Srvb * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS 1938759Srvb * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON 2038759Srvb * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER 2138759Srvb * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF 2238759Srvb * ANY DERIVATIVE WORK. 2338759Srvb * 2438759Srvb * Carnegie Mellon encourages users of this software to return any 2538759Srvb * improvements or extensions that they make, and to grant Carnegie 2638759Srvb * Mellon the rights to redistribute these changes without encumbrance. 2738759Srvb * 2839126Srvb * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ 2938759Srvb */ 3038625Srvb/* 3138625Srvb * Mach Operating System 3238625Srvb * Copyright (c) 1990 Carnegie-Mellon University 3338625Srvb * Copyright (c) 1989 Carnegie-Mellon University 3438625Srvb * All rights reserved. The CMU software License Agreement specifies 3538625Srvb * the terms and conditions for use and redistribution. 3638625Srvb */ 3738625Srvb 3838625Srvb/* 3996755Strhodes * This code was written for the Coda filesystem at Carnegie Mellon 4038625Srvb * University. Contributers include David Steere, James Kistler, and 4138625Srvb * M. Satyanarayanan. 4238625Srvb */ 4338625Srvb 44116173Sobrien#include <sys/cdefs.h> 45116173Sobrien__FBSDID("$FreeBSD: head/sys/fs/coda/coda_vnops.c 116173 2003-06-10 21:29:12Z obrien $"); 46116173Sobrien 4738625Srvb#include <sys/param.h> 4838625Srvb#include <sys/systm.h> 4976166Smarkm#include <sys/acct.h> 5076166Smarkm#include <sys/errno.h> 5176166Smarkm#include <sys/fcntl.h> 5238759Srvb#include <sys/kernel.h> 5376166Smarkm#include <sys/lock.h> 5476166Smarkm#include <sys/malloc.h> 5576166Smarkm#include <sys/file.h> /* Must come after sys/malloc.h */ 5676166Smarkm#include <sys/mount.h> 5776166Smarkm#include <sys/mutex.h> 5876166Smarkm#include <sys/namei.h> 5938759Srvb#include <sys/proc.h> 6038625Srvb#include <sys/uio.h> 61111903Stjr#include <sys/unistd.h> 6238759Srvb 6338625Srvb#include <vm/vm.h> 6438625Srvb#include <vm/vm_object.h> 6538625Srvb#include <vm/vm_extern.h> 6638625Srvb 6739126Srvb#include <coda/coda.h> 6839126Srvb#include <coda/cnode.h> 6939126Srvb#include <coda/coda_vnops.h> 7039126Srvb#include <coda/coda_venus.h> 7139126Srvb#include <coda/coda_opstats.h> 7239126Srvb#include <coda/coda_subr.h> 7339126Srvb#include <coda/coda_namecache.h> 7439126Srvb#include <coda/coda_pioctl.h> 7538625Srvb 7638625Srvb/* 7738625Srvb * These flags select various performance enhancements. 7838625Srvb */ 7939085Srvbint coda_attr_cache = 1; /* Set to cache attributes in the kernel */ 8039085Srvbint coda_symlink_cache = 1; /* Set to cache symbolic link information */ 8139085Srvbint coda_access_cache = 1; /* Set to handle some access checks directly */ 8238625Srvb 8338625Srvb/* structure to keep track of vfs calls */ 8438625Srvb 8539085Srvbstruct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE]; 8638625Srvb 8739085Srvb#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++) 8839085Srvb#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++) 8939085Srvb#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++) 9039085Srvb#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++) 9138625Srvb 9238625Srvb/* What we are delaying for in printf */ 9339085Srvbint coda_printf_delay = 0; /* in microseconds */ 9439085Srvbint coda_vnop_print_entry = 0; 9539085Srvbstatic int coda_lockdebug = 0; 9638625Srvb 9738625Srvb/* Definition of the vfs operation vector */ 9889090Smsmithstatic int (**coda_vnodeop_p)(void *); 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 10787599Sobrien#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__)) 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 */ 12439085Srvb { &vop_fsync_desc, coda_fsync }, /* fsync */ 12539085Srvb { &vop_remove_desc, coda_remove }, /* remove */ 12639085Srvb { &vop_link_desc, coda_link }, /* link */ 12739085Srvb { &vop_rename_desc, coda_rename }, /* rename */ 12839085Srvb { &vop_mkdir_desc, coda_mkdir }, /* mkdir */ 12939085Srvb { &vop_rmdir_desc, coda_rmdir }, /* rmdir */ 13039650Srvb { &vop_symlink_desc, coda_symlink }, /* symlink */ 13139650Srvb { &vop_readdir_desc, coda_readdir }, /* readdir */ 13239085Srvb { &vop_readlink_desc, coda_readlink }, /* readlink */ 13339085Srvb { &vop_inactive_desc, coda_inactive }, /* inactive */ 13439650Srvb { &vop_reclaim_desc, coda_reclaim }, /* reclaim */ 13539085Srvb { &vop_lock_desc, coda_lock }, /* lock */ 13639085Srvb { &vop_unlock_desc, coda_unlock }, /* unlock */ 13739085Srvb { &vop_bmap_desc, coda_bmap }, /* bmap */ 13839085Srvb { &vop_strategy_desc, coda_strategy }, /* strategy */ 13939650Srvb { &vop_print_desc, coda_vop_error }, /* print */ 14039085Srvb { &vop_islocked_desc, coda_islocked }, /* islocked */ 141111903Stjr { &vop_pathconf_desc, coda_pathconf }, /* pathconf */ 14239650Srvb { &vop_advlock_desc, coda_vop_nop }, /* advlock */ 14339650Srvb { &vop_lease_desc, coda_vop_nop }, /* lease */ 14438759Srvb { &vop_poll_desc, (vop_t *) vop_stdpoll }, 14577784Sshafeeq { &vop_getpages_desc, (vop_t*)vop_stdgetpages }, /* pager intf.*/ 14677784Sshafeeq { &vop_putpages_desc, (vop_t*)vop_stdputpages }, /* pager intf.*/ 14778205Sbp { &vop_createvobject_desc, (vop_t*)vop_stdcreatevobject }, 14878205Sbp { &vop_destroyvobject_desc, (vop_t*)vop_stddestroyvobject }, 14978205Sbp { &vop_getvobject_desc, (vop_t*)vop_stdgetvobject }, 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 16577784Sshafeeq 16677784Sshafeeq { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, 16777784Sshafeeq { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, 16877784Sshafeeq { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 16977784Sshafeeq { &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount }, 17038625Srvb { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL } 17138625Srvb}; 17238625Srvb 17339085Srvbstatic struct vnodeopv_desc coda_vnodeop_opv_desc = 17439085Srvb { &coda_vnodeop_p, coda_vnodeop_entries }; 17538625Srvb 17639085SrvbVNODEOP_SET(coda_vnodeop_opv_desc); 17738625Srvb 17838625Srvb/* A generic panic: we were called with something we didn't define yet */ 17938625Srvbint 18039085Srvbcoda_vop_error(void *anon) { 18138625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 18238625Srvb 18341202Srvb myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n", 18438625Srvb (*desc)->vdesc_name)); 18541202Srvb /* 18639085Srvb panic("coda_vop_error"); 18741202Srvb */ 18841202Srvb return EIO; 18938625Srvb} 19038625Srvb 19138625Srvb/* A generic do-nothing. For lease_check, advlock */ 19238625Srvbint 19339085Srvbcoda_vop_nop(void *anon) { 19438625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 19538625Srvb 19639085Srvb if (codadebug) { 19738625Srvb myprintf(("Vnode operation %s called, but unsupported\n", 19838625Srvb (*desc)->vdesc_name)); 19938625Srvb } 20038625Srvb return (0); 20138625Srvb} 20238625Srvb 20338625Srvbint 20439085Srvbcoda_vnodeopstats_init(void) 20538625Srvb{ 20638625Srvb register int i; 20738625Srvb 20839085Srvb for(i=0;i<CODA_VNODEOPS_SIZE;i++) { 20939085Srvb coda_vnodeopstats[i].opcode = i; 21039085Srvb coda_vnodeopstats[i].entries = 0; 21139085Srvb coda_vnodeopstats[i].sat_intrn = 0; 21239085Srvb coda_vnodeopstats[i].unsat_intrn = 0; 21339085Srvb coda_vnodeopstats[i].gen_intrn = 0; 21438625Srvb } 21538625Srvb return 0; 21638625Srvb} 21738625Srvb 21838625Srvb/* 21939085Srvb * coda_open calls Venus to return the device, inode pair of the cache 22039085Srvb * file holding the data. Using iget, coda_open finds the vnode of the 22138625Srvb * cache file, and then opens it. 22238625Srvb */ 22338625Srvbint 22439085Srvbcoda_open(v) 22538625Srvb void *v; 22638625Srvb{ 22738625Srvb /* 22838625Srvb * NetBSD can pass the O_EXCL flag in mode, even though the check 22938625Srvb * has already happened. Venus defensively assumes that if open 23038625Srvb * is passed the EXCL, it must be a bug. We strip the flag here. 23138625Srvb */ 23238625Srvb/* true args */ 23338625Srvb struct vop_open_args *ap = v; 23438625Srvb register struct vnode **vpp = &(ap->a_vp); 23538625Srvb struct cnode *cp = VTOC(*vpp); 23638625Srvb int flag = ap->a_mode & (~O_EXCL); 23738625Srvb struct ucred *cred = ap->a_cred; 23883366Sjulian struct thread *td = ap->a_td; 23938625Srvb/* locals */ 24038625Srvb int error; 24138625Srvb struct vnode *vp; 24238625Srvb dev_t dev; 24338625Srvb ino_t inode; 24438625Srvb 24539085Srvb MARK_ENTRY(CODA_OPEN_STATS); 24638625Srvb 24738625Srvb /* Check for open of control file. */ 24838625Srvb if (IS_CTL_VP(*vpp)) { 24938625Srvb /* XXX */ 25038625Srvb /* if (WRITEABLE(flag)) */ 25138625Srvb if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { 25239085Srvb MARK_INT_FAIL(CODA_OPEN_STATS); 25338625Srvb return(EACCES); 25438625Srvb } 25539085Srvb MARK_INT_SAT(CODA_OPEN_STATS); 25638625Srvb return(0); 25738625Srvb } 25838625Srvb 25983366Sjulian error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td->td_proc, &dev, &inode); 26038625Srvb if (error) 26138625Srvb return (error); 26238625Srvb if (!error) { 26349524Sbde CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n", 26449524Sbde (u_long)dev2udev(dev), (u_long)inode, 26549524Sbde error)); ) 26638625Srvb } 26738625Srvb 26838625Srvb /* Translate the <device, inode> pair for the cache file into 26938625Srvb an inode pointer. */ 27039085Srvb error = coda_grab_vnode(dev, inode, &vp); 27138625Srvb if (error) 27238625Srvb return (error); 27338625Srvb 27438759Srvb /* We get the vnode back locked. Needs unlocked */ 27583366Sjulian VOP_UNLOCK(vp, 0, td); 27638625Srvb /* Keep a reference until the close comes in. */ 27738625Srvb vref(*vpp); 27838625Srvb 27938625Srvb /* Save the vnode pointer for the cache file. */ 28038625Srvb if (cp->c_ovp == NULL) { 28138625Srvb cp->c_ovp = vp; 28238625Srvb } else { 28338625Srvb if (cp->c_ovp != vp) 28439085Srvb panic("coda_open: cp->c_ovp != ITOV(ip)"); 28538625Srvb } 28638625Srvb cp->c_ocount++; 28738625Srvb 28838625Srvb /* Flush the attribute cached if writing the file. */ 28938625Srvb if (flag & FWRITE) { 29038625Srvb cp->c_owrite++; 29138625Srvb cp->c_flags &= ~C_VATTR; 29238625Srvb } 29338625Srvb 29438625Srvb /* Save the <device, inode> pair for the cache file to speed 29538625Srvb up subsequent page_read's. */ 29638625Srvb cp->c_device = dev; 29738625Srvb cp->c_inode = inode; 29838625Srvb 29938625Srvb /* Open the cache file. */ 30083366Sjulian error = VOP_OPEN(vp, flag, cred, td); 30138625Srvb if (error) { 30239085Srvb printf("coda_open: VOP_OPEN on container failed %d\n", error); 30338625Srvb return (error); 30438625Srvb } 30539650Srvb/* grab (above) does this when it calls newvnode unless it's in the cache*/ 30638625Srvb if (vp->v_type == VREG) { 30783366Sjulian error = vfs_object_create(vp, td, cred); 30838625Srvb if (error != 0) { 30939085Srvb printf("coda_open: vfs_object_create() returns %d\n", error); 31038625Srvb vput(vp); 31138625Srvb } 31238625Srvb } 31339650Srvb 31438625Srvb return(error); 31538625Srvb} 31638625Srvb 31738625Srvb/* 31838625Srvb * Close the cache file used for I/O and notify Venus. 31938625Srvb */ 32038625Srvbint 32139085Srvbcoda_close(v) 32238625Srvb void *v; 32338625Srvb{ 32438625Srvb/* true args */ 32538625Srvb struct vop_close_args *ap = v; 32638625Srvb struct vnode *vp = ap->a_vp; 32738625Srvb struct cnode *cp = VTOC(vp); 32838625Srvb int flag = ap->a_fflag; 32938625Srvb struct ucred *cred = ap->a_cred; 33083366Sjulian struct thread *td = ap->a_td; 33138625Srvb/* locals */ 33238625Srvb int error; 33338625Srvb 33439085Srvb MARK_ENTRY(CODA_CLOSE_STATS); 33538625Srvb 33638625Srvb /* Check for close of control file. */ 33738625Srvb if (IS_CTL_VP(vp)) { 33839085Srvb MARK_INT_SAT(CODA_CLOSE_STATS); 33938625Srvb return(0); 34038625Srvb } 34138625Srvb 34238625Srvb if (IS_UNMOUNTING(cp)) { 34338625Srvb if (cp->c_ovp) { 34439728Srvb#ifdef CODA_VERBOSE 34539085Srvb printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n", 346103937Sjeff vrefcnt(vp), cp->c_ovp, vp, cp); 34739650Srvb#endif 34840708Srvb#ifdef hmm 34938625Srvb vgone(cp->c_ovp); 35040708Srvb#else 35183366Sjulian VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */ 35240708Srvb vrele(cp->c_ovp); 35340708Srvb#endif 35438625Srvb } else { 35539728Srvb#ifdef CODA_VERBOSE 35639085Srvb printf("coda_close: NO container vp %p/cp %p\n", vp, cp); 35739650Srvb#endif 35838625Srvb } 35938625Srvb return ENODEV; 36038625Srvb } else { 36183366Sjulian VOP_CLOSE(cp->c_ovp, flag, cred, td); /* Do errors matter here? */ 36238625Srvb vrele(cp->c_ovp); 36338625Srvb } 36438625Srvb 36538625Srvb if (--cp->c_ocount == 0) 36638625Srvb cp->c_ovp = NULL; 36738625Srvb 36838625Srvb if (flag & FWRITE) /* file was opened for write */ 36938625Srvb --cp->c_owrite; 37038625Srvb 37183366Sjulian error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, td->td_proc); 37238625Srvb vrele(CTOV(cp)); 37338625Srvb 37439085Srvb CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); ) 37538625Srvb return(error); 37638625Srvb} 37738625Srvb 37838625Srvbint 37939085Srvbcoda_read(v) 38038625Srvb void *v; 38138625Srvb{ 38238625Srvb struct vop_read_args *ap = v; 38338625Srvb 38438625Srvb ENTRY; 38539085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, 38683366Sjulian ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); 38738625Srvb} 38838625Srvb 38938625Srvbint 39039085Srvbcoda_write(v) 39138625Srvb void *v; 39238625Srvb{ 39338625Srvb struct vop_write_args *ap = v; 39438625Srvb 39538625Srvb ENTRY; 39639085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, 39783366Sjulian ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td)); 39838625Srvb} 39938625Srvb 40038625Srvbint 40183366Sjuliancoda_rdwr(vp, uiop, rw, ioflag, cred, td) 40238625Srvb struct vnode *vp; 40338625Srvb struct uio *uiop; 40438625Srvb enum uio_rw rw; 40538625Srvb int ioflag; 40638625Srvb struct ucred *cred; 40783366Sjulian struct thread *td; 40838625Srvb{ 40938625Srvb/* upcall decl */ 41038625Srvb /* NOTE: container file operation!!! */ 41138625Srvb/* locals */ 41238625Srvb struct cnode *cp = VTOC(vp); 41338625Srvb struct vnode *cfvp = cp->c_ovp; 41483366Sjulian struct proc *p = td->td_proc; 41583366Sjulian struct thread *ltd = td; 41638625Srvb int igot_internally = 0; 41738625Srvb int opened_internally = 0; 41838625Srvb int error = 0; 41977784Sshafeeq int iscore = 0; 42038625Srvb 42139085Srvb MARK_ENTRY(CODA_RDWR_STATS); 42238625Srvb 42349524Sbde CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw, 42449524Sbde (void *)uiop->uio_iov->iov_base, uiop->uio_resid, 42549524Sbde (long long)uiop->uio_offset, uiop->uio_segflg)); ) 42638625Srvb 42738625Srvb /* Check for rdwr of control object. */ 42838625Srvb if (IS_CTL_VP(vp)) { 42939085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 43038625Srvb return(EINVAL); 43138625Srvb } 43238625Srvb 43338625Srvb /* 43438625Srvb * If file is not already open this must be a page 43538625Srvb * {read,write} request. Iget the cache file's inode 43638625Srvb * pointer if we still have its <device, inode> pair. 43738625Srvb * Otherwise, we must do an internal open to derive the 43838625Srvb * pair. 43938625Srvb */ 44038625Srvb if (cfvp == NULL) { 44138625Srvb /* 44238625Srvb * If we're dumping core, do the internal open. Otherwise 44338625Srvb * venus won't have the correct size of the core when 44438625Srvb * it's completely written. 44538625Srvb */ 44677784Sshafeeq if (p) { 44777784Sshafeeq PROC_LOCK(p); 44877784Sshafeeq iscore = (p->p_acflag & ACORE); 44969652Sjhb PROC_UNLOCK(p); 45077784Sshafeeq } 45177784Sshafeeq else 45283366Sjulian ltd = curthread; 45377784Sshafeeq 45477784Sshafeeq if (cp->c_inode != 0 && !iscore) { 45538625Srvb igot_internally = 1; 45639085Srvb error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp); 45738625Srvb if (error) { 45839085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 45938625Srvb return(error); 46038625Srvb } 46138625Srvb /* 46283366Sjulian * We get the vnode back locked by curthread in both Mach and 46338625Srvb * NetBSD. Needs unlocked 46438625Srvb */ 46583366Sjulian VOP_UNLOCK(cfvp, 0, ltd); 46638625Srvb } 46738625Srvb else { 46838625Srvb opened_internally = 1; 46939085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 47038625Srvb error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), 47183366Sjulian cred, td); 47239085Srvbprintf("coda_rdwr: Internally Opening %p\n", vp); 47338625Srvb if (error) { 47439085Srvb printf("coda_rdwr: VOP_OPEN on container failed %d\n", error); 47538625Srvb return (error); 47638625Srvb } 47738625Srvb if (vp->v_type == VREG) { 47883366Sjulian error = vfs_object_create(vp, td, cred); 47938625Srvb if (error != 0) { 48039085Srvb printf("coda_rdwr: vfs_object_create() returns %d\n", error); 48138625Srvb vput(vp); 48238625Srvb } 48338625Srvb } 48438625Srvb if (error) { 48539085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 48638625Srvb return(error); 48738625Srvb } 48838625Srvb cfvp = cp->c_ovp; 48938625Srvb } 49038625Srvb } 49138625Srvb 49238625Srvb /* Have UFS handle the call. */ 49339085Srvb CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n", 49438625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 495103937Sjeff cp->c_fid.Unique, vrefcnt(CTOV(cp)))); ) 49638625Srvb 49738625Srvb if (rw == UIO_READ) { 49838625Srvb error = VOP_READ(cfvp, uiop, ioflag, cred); 49938625Srvb } else { 50038625Srvb error = VOP_WRITE(cfvp, uiop, ioflag, cred); 50138625Srvb /* ufs_write updates the vnode_pager_setsize for the vnode/object */ 50239650Srvb 50338625Srvb { struct vattr attr; 50438625Srvb 50583366Sjulian if (VOP_GETATTR(cfvp, &attr, cred, td) == 0) { 50638625Srvb vnode_pager_setsize(vp, attr.va_size); 50738625Srvb } 50838625Srvb } 50938625Srvb } 51038625Srvb 51138625Srvb if (error) 51239085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 51338625Srvb else 51439085Srvb MARK_INT_SAT(CODA_RDWR_STATS); 51538625Srvb 51638625Srvb /* Do an internal close if necessary. */ 51738625Srvb if (opened_internally) { 51839085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 51983366Sjulian (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, td); 52038625Srvb } 52138625Srvb 52238625Srvb /* Invalidate cached attributes if writing. */ 52338625Srvb if (rw == UIO_WRITE) 52438625Srvb cp->c_flags &= ~C_VATTR; 52538625Srvb return(error); 52638625Srvb} 52738625Srvb 52877784Sshafeeq 52977784Sshafeeq 53038625Srvbint 53139085Srvbcoda_ioctl(v) 53238625Srvb void *v; 53338625Srvb{ 53438625Srvb/* true args */ 53538625Srvb struct vop_ioctl_args *ap = v; 53638625Srvb struct vnode *vp = ap->a_vp; 53738625Srvb int com = ap->a_command; 53838625Srvb caddr_t data = ap->a_data; 53938625Srvb int flag = ap->a_fflag; 54038625Srvb struct ucred *cred = ap->a_cred; 54183366Sjulian struct thread *td = ap->a_td; 54238625Srvb/* locals */ 54338625Srvb int error; 54438625Srvb struct vnode *tvp; 54538625Srvb struct nameidata ndp; 54638625Srvb struct PioctlData *iap = (struct PioctlData *)data; 54738625Srvb 54839085Srvb MARK_ENTRY(CODA_IOCTL_STATS); 54938625Srvb 55039085Srvb CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));) 55138625Srvb 55238625Srvb /* Don't check for operation on a dying object, for ctlvp it 55338625Srvb shouldn't matter */ 55438625Srvb 55538625Srvb /* Must be control object to succeed. */ 55638625Srvb if (!IS_CTL_VP(vp)) { 55739085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 55839085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));) 55938625Srvb return (EOPNOTSUPP); 56038625Srvb } 56138625Srvb /* Look up the pathname. */ 56238625Srvb 56338625Srvb /* Should we use the name cache here? It would get it from 56438625Srvb lookupname sooner or later anyway, right? */ 56538625Srvb 56683366Sjulian NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, iap->path, td); 56738625Srvb error = namei(&ndp); 56838625Srvb tvp = ndp.ni_vp; 56938625Srvb 57038625Srvb if (error) { 57139085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 57239085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n", 57338625Srvb error));) 57438625Srvb return(error); 57538625Srvb } 57638625Srvb 57738625Srvb /* 57838625Srvb * Make sure this is a coda style cnode, but it may be a 57938625Srvb * different vfsp 58038625Srvb */ 58149687Sphk if (tvp->v_op != coda_vnodeop_p) { 58238625Srvb vrele(tvp); 58354655Seivind NDFREE(&ndp, NDF_ONLY_PNBUF); 58439085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 58539085Srvb CODADEBUG(CODA_IOCTL, 58639085Srvb myprintf(("coda_ioctl error: %s not a coda object\n", 58738625Srvb iap->path));) 58838625Srvb return(EINVAL); 58938625Srvb } 59038625Srvb 59138625Srvb if (iap->vi.in_size > VC_MAXDATASIZE) { 59254655Seivind NDFREE(&ndp, 0); 59338625Srvb return(EINVAL); 59438625Srvb } 59583366Sjulian error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td->td_proc); 59638625Srvb 59738625Srvb if (error) 59839085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 59938625Srvb else 60039085Srvb CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); ) 60138625Srvb 60238625Srvb vrele(tvp); 60354655Seivind NDFREE(&ndp, NDF_ONLY_PNBUF); 60438625Srvb return(error); 60538625Srvb} 60638625Srvb 60738625Srvb/* 60838625Srvb * To reduce the cost of a user-level venus;we cache attributes in 60938625Srvb * the kernel. Each cnode has storage allocated for an attribute. If 61038625Srvb * c_vattr is valid, return a reference to it. Otherwise, get the 61138625Srvb * attributes from venus and store them in the cnode. There is some 61238625Srvb * question if this method is a security leak. But I think that in 61338625Srvb * order to make this call, the user must have done a lookup and 61438625Srvb * opened the file, and therefore should already have access. 61538625Srvb */ 61638625Srvbint 61739085Srvbcoda_getattr(v) 61838625Srvb void *v; 61938625Srvb{ 62038625Srvb/* true args */ 62138625Srvb struct vop_getattr_args *ap = v; 62238625Srvb struct vnode *vp = ap->a_vp; 62338625Srvb struct cnode *cp = VTOC(vp); 62438625Srvb struct vattr *vap = ap->a_vap; 62538625Srvb struct ucred *cred = ap->a_cred; 62683366Sjulian struct thread *td = ap->a_td; 62738625Srvb/* locals */ 62838625Srvb int error; 62938625Srvb 63039085Srvb MARK_ENTRY(CODA_GETATTR_STATS); 63138625Srvb 63238625Srvb if (IS_UNMOUNTING(cp)) 63338625Srvb return ENODEV; 63438759Srvb 63538625Srvb /* Check for getattr of control object. */ 63638625Srvb if (IS_CTL_VP(vp)) { 63739085Srvb MARK_INT_FAIL(CODA_GETATTR_STATS); 63838625Srvb return(ENOENT); 63938625Srvb } 64038625Srvb 64138625Srvb /* Check to see if the attributes have already been cached */ 64238625Srvb if (VALID_VATTR(cp)) { 64339085Srvb CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n", 64438625Srvb cp->c_fid.Volume, 64538625Srvb cp->c_fid.Vnode, 64638625Srvb cp->c_fid.Unique));}); 64739085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 64838625Srvb print_vattr(&cp->c_vattr); ); 64938625Srvb 65038625Srvb *vap = cp->c_vattr; 65139085Srvb MARK_INT_SAT(CODA_GETATTR_STATS); 65238625Srvb return(0); 65338625Srvb } 65438625Srvb 65583366Sjulian error = venus_getattr(vtomi(vp), &cp->c_fid, cred, td->td_proc, vap); 65638625Srvb 65738625Srvb if (!error) { 65839085Srvb CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n", 65938625Srvb cp->c_fid.Volume, 66038625Srvb cp->c_fid.Vnode, 66138625Srvb cp->c_fid.Unique, 66238625Srvb error)); ) 66338625Srvb 66439085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 66538625Srvb print_vattr(vap); ); 66638625Srvb 66738625Srvb { int size = vap->va_size; 66838625Srvb struct vnode *convp = cp->c_ovp; 66938625Srvb if (convp != (struct vnode *)0) { 67038625Srvb vnode_pager_setsize(convp, size); 67138625Srvb } 67238625Srvb } 67338625Srvb /* If not open for write, store attributes in cnode */ 67439085Srvb if ((cp->c_owrite == 0) && (coda_attr_cache)) { 67538625Srvb cp->c_vattr = *vap; 67638625Srvb cp->c_flags |= C_VATTR; 67738625Srvb } 67838625Srvb 67938625Srvb } 68038625Srvb return(error); 68138625Srvb} 68238625Srvb 68338625Srvbint 68439085Srvbcoda_setattr(v) 68538625Srvb void *v; 68638625Srvb{ 68738625Srvb/* true args */ 68838625Srvb struct vop_setattr_args *ap = v; 68938625Srvb register struct vnode *vp = ap->a_vp; 69038625Srvb struct cnode *cp = VTOC(vp); 69138625Srvb register struct vattr *vap = ap->a_vap; 69238625Srvb struct ucred *cred = ap->a_cred; 69383366Sjulian struct thread *td = ap->a_td; 69438625Srvb/* locals */ 69538625Srvb int error; 69638625Srvb 69739085Srvb MARK_ENTRY(CODA_SETATTR_STATS); 69838625Srvb 69938625Srvb /* Check for setattr of control object. */ 70038625Srvb if (IS_CTL_VP(vp)) { 70139085Srvb MARK_INT_FAIL(CODA_SETATTR_STATS); 70238625Srvb return(ENOENT); 70338625Srvb } 70438625Srvb 70539085Srvb if (codadebug & CODADBGMSK(CODA_SETATTR)) { 70638625Srvb print_vattr(vap); 70738625Srvb } 70883366Sjulian error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td->td_proc); 70938625Srvb 71038625Srvb if (!error) 71138625Srvb cp->c_flags &= ~C_VATTR; 71238625Srvb 71338625Srvb { int size = vap->va_size; 71438625Srvb struct vnode *convp = cp->c_ovp; 71538625Srvb if (size != VNOVAL && convp != (struct vnode *)0) { 71638625Srvb vnode_pager_setsize(convp, size); 71738625Srvb } 71838625Srvb } 71939085Srvb CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); ) 72038625Srvb return(error); 72138625Srvb} 72238625Srvb 72338625Srvbint 72439085Srvbcoda_access(v) 72538625Srvb void *v; 72638625Srvb{ 72738625Srvb/* true args */ 72838625Srvb struct vop_access_args *ap = v; 72938625Srvb struct vnode *vp = ap->a_vp; 73038625Srvb struct cnode *cp = VTOC(vp); 73138625Srvb int mode = ap->a_mode; 73238625Srvb struct ucred *cred = ap->a_cred; 73383366Sjulian struct thread *td = ap->a_td; 73438625Srvb/* locals */ 73538625Srvb int error; 73638625Srvb 73739085Srvb MARK_ENTRY(CODA_ACCESS_STATS); 73838625Srvb 73938625Srvb /* Check for access of control object. Only read access is 74038625Srvb allowed on it. */ 74138625Srvb if (IS_CTL_VP(vp)) { 74238625Srvb /* bogus hack - all will be marked as successes */ 74339085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 74438625Srvb return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) 74538625Srvb ? 0 : EACCES); 74638625Srvb } 74738625Srvb 74838625Srvb /* 74938625Srvb * if the file is a directory, and we are checking exec (eg lookup) 75038625Srvb * access, and the file is in the namecache, then the user must have 75138625Srvb * lookup access to it. 75238625Srvb */ 75339085Srvb if (coda_access_cache) { 75438625Srvb if ((vp->v_type == VDIR) && (mode & VEXEC)) { 75539085Srvb if (coda_nc_lookup(cp, ".", 1, cred)) { 75639085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 75738625Srvb return(0); /* it was in the cache */ 75838625Srvb } 75938625Srvb } 76038625Srvb } 76138625Srvb 76283366Sjulian error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td->td_proc); 76338625Srvb 76438625Srvb return(error); 76538625Srvb} 76638625Srvb 76738625Srvbint 76839085Srvbcoda_readlink(v) 76938625Srvb void *v; 77038625Srvb{ 77138625Srvb/* true args */ 77238625Srvb struct vop_readlink_args *ap = v; 77338625Srvb struct vnode *vp = ap->a_vp; 77438625Srvb struct cnode *cp = VTOC(vp); 77538625Srvb struct uio *uiop = ap->a_uio; 77638625Srvb struct ucred *cred = ap->a_cred; 77783366Sjulian struct thread *td = ap->a_uio->uio_td; 77838625Srvb/* locals */ 77938625Srvb int error; 78038625Srvb char *str; 78138625Srvb int len; 78238625Srvb 78339085Srvb MARK_ENTRY(CODA_READLINK_STATS); 78438625Srvb 78538625Srvb /* Check for readlink of control object. */ 78638625Srvb if (IS_CTL_VP(vp)) { 78739085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 78838625Srvb return(ENOENT); 78938625Srvb } 79038625Srvb 79139085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */ 79238625Srvb uiop->uio_rw = UIO_READ; 79338625Srvb error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); 79438625Srvb if (error) 79539085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 79638625Srvb else 79739085Srvb MARK_INT_SAT(CODA_READLINK_STATS); 79838625Srvb return(error); 79938625Srvb } 80038625Srvb 801111902Stjr error = venus_readlink(vtomi(vp), &cp->c_fid, cred, 802111902Stjr td != NULL ? td->td_proc : NULL, &str, &len); 80338625Srvb 80438625Srvb if (!error) { 80538625Srvb uiop->uio_rw = UIO_READ; 80638625Srvb error = uiomove(str, len, uiop); 80738625Srvb 80839085Srvb if (coda_symlink_cache) { 80938625Srvb cp->c_symlink = str; 81038625Srvb cp->c_symlen = len; 81138625Srvb cp->c_flags |= C_SYMLINK; 81238625Srvb } else 81339085Srvb CODA_FREE(str, len); 81438625Srvb } 81538625Srvb 81639085Srvb CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));) 81738625Srvb return(error); 81838625Srvb} 81938625Srvb 82038625Srvbint 82139085Srvbcoda_fsync(v) 82238625Srvb void *v; 82338625Srvb{ 82438625Srvb/* true args */ 82538625Srvb struct vop_fsync_args *ap = v; 82638625Srvb struct vnode *vp = ap->a_vp; 82738625Srvb struct cnode *cp = VTOC(vp); 82838625Srvb struct ucred *cred = ap->a_cred; 82983366Sjulian struct thread *td = ap->a_td; 83038625Srvb/* locals */ 83138625Srvb struct vnode *convp = cp->c_ovp; 83238625Srvb int error; 83338625Srvb 83439085Srvb MARK_ENTRY(CODA_FSYNC_STATS); 83538625Srvb 83638625Srvb /* Check for fsync on an unmounting object */ 83738625Srvb /* The NetBSD kernel, in it's infinite wisdom, can try to fsync 83838625Srvb * after an unmount has been initiated. This is a Bad Thing, 83938625Srvb * which we have to avoid. Not a legitimate failure for stats. 84038625Srvb */ 84138625Srvb if (IS_UNMOUNTING(cp)) { 84238625Srvb return(ENODEV); 84338625Srvb } 84438625Srvb 84538625Srvb /* Check for fsync of control object. */ 84638625Srvb if (IS_CTL_VP(vp)) { 84739085Srvb MARK_INT_SAT(CODA_FSYNC_STATS); 84838625Srvb return(0); 84938625Srvb } 85038625Srvb 85138625Srvb if (convp) 85283366Sjulian VOP_FSYNC(convp, cred, MNT_WAIT, td); 85338625Srvb 85438625Srvb /* 85538625Srvb * We see fsyncs with usecount == 1 then usecount == 0. 85638625Srvb * For now we ignore them. 85738625Srvb */ 85838625Srvb /* 859103937Sjeff VI_LOCK(vp); 86038625Srvb if (!vp->v_usecount) { 86139085Srvb printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n", 86238625Srvb vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING); 86338625Srvb } 864103937Sjeff VI_UNLOCK(vp); 86538625Srvb */ 86638625Srvb 86738625Srvb /* 86838625Srvb * We can expect fsync on any vnode at all if venus is pruging it. 86938625Srvb * Venus can't very well answer the fsync request, now can it? 87038625Srvb * Hopefully, it won't have to, because hopefully, venus preserves 87138625Srvb * the (possibly untrue) invariant that it never purges an open 87238625Srvb * vnode. Hopefully. 87338625Srvb */ 87438625Srvb if (cp->c_flags & C_PURGING) { 87538625Srvb return(0); 87638625Srvb } 87738625Srvb 87838625Srvb /* needs research */ 87938625Srvb return 0; 88083366Sjulian error = venus_fsync(vtomi(vp), &cp->c_fid, cred, td->td_proc); 88138625Srvb 88239085Srvb CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); ); 88338625Srvb return(error); 88438625Srvb} 88538625Srvb 88638625Srvbint 88739085Srvbcoda_inactive(v) 88838625Srvb void *v; 88938625Srvb{ 89038625Srvb /* XXX - at the moment, inactive doesn't look at cred, and doesn't 89138625Srvb have a proc pointer. Oops. */ 89238625Srvb/* true args */ 89338625Srvb struct vop_inactive_args *ap = v; 89438625Srvb struct vnode *vp = ap->a_vp; 89538625Srvb struct cnode *cp = VTOC(vp); 89638625Srvb struct ucred *cred __attribute__((unused)) = NULL; 89783366Sjulian struct thread *td __attribute__((unused)) = curthread; 89838625Srvb/* upcall decl */ 89938625Srvb/* locals */ 90038625Srvb 90138625Srvb /* We don't need to send inactive to venus - DCS */ 90239085Srvb MARK_ENTRY(CODA_INACTIVE_STATS); 90338625Srvb 90438625Srvb if (IS_CTL_VP(vp)) { 90539085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 90638625Srvb return 0; 90738625Srvb } 90838625Srvb 90939085Srvb CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n", 91038625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 91138625Srvb cp->c_fid.Unique, vp->v_mount));) 91238625Srvb 91338625Srvb /* If an array has been allocated to hold the symlink, deallocate it */ 91439085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { 91538625Srvb if (cp->c_symlink == NULL) 91639085Srvb panic("coda_inactive: null symlink pointer in cnode"); 91738625Srvb 91839085Srvb CODA_FREE(cp->c_symlink, cp->c_symlen); 91938625Srvb cp->c_flags &= ~C_SYMLINK; 92038625Srvb cp->c_symlen = 0; 92138625Srvb } 92238625Srvb 92338625Srvb /* Remove it from the table so it can't be found. */ 92439085Srvb coda_unsave(cp); 92539085Srvb if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) { 92638625Srvb myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp)); 92739085Srvb panic("badness in coda_inactive\n"); 92838625Srvb } 92938625Srvb 93038625Srvb if (IS_UNMOUNTING(cp)) { 93138625Srvb#ifdef DEBUG 932103937Sjeff printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vrefcnt(vp), vp, cp); 93338625Srvb if (cp->c_ovp != NULL) 93439085Srvb printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n", 935103937Sjeff vrefcnt(vp), vp, cp); 93638625Srvb#endif 93783366Sjulian lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, td); 93838625Srvb } else { 93939650Srvb#ifdef OLD_DIAGNOSTIC 940103937Sjeff if (vrefcnt(CTOV(cp))) { 94139085Srvb panic("coda_inactive: nonzero reference count"); 94238625Srvb } 94338625Srvb if (cp->c_ovp != NULL) { 94439085Srvb panic("coda_inactive: cp->ovp != NULL"); 94538625Srvb } 94638625Srvb#endif 94783366Sjulian VOP_UNLOCK(vp, 0, td); 94838625Srvb vgone(vp); 94938625Srvb } 95038625Srvb 95139085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 95238625Srvb return(0); 95338625Srvb} 95438625Srvb 95538625Srvb/* 95696755Strhodes * Remote filesystem operations having to do with directory manipulation. 95738625Srvb */ 95838625Srvb 95938625Srvb/* 96038625Srvb * It appears that in NetBSD, lookup is supposed to return the vnode locked 96138625Srvb */ 96238625Srvbint 96339085Srvbcoda_lookup(v) 96438625Srvb void *v; 96538625Srvb{ 96638625Srvb/* true args */ 96738625Srvb struct vop_lookup_args *ap = v; 96838625Srvb struct vnode *dvp = ap->a_dvp; 96938625Srvb struct cnode *dcp = VTOC(dvp); 97038625Srvb struct vnode **vpp = ap->a_vpp; 97138625Srvb /* 97238625Srvb * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest 97338625Srvb * of the string to xlate, and that we must try to get at least 97438625Srvb * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I 97538625Srvb * could be wrong. 97638625Srvb */ 97738625Srvb struct componentname *cnp = ap->a_cnp; 97838625Srvb struct ucred *cred = cnp->cn_cred; 97983366Sjulian struct thread *td = cnp->cn_thread; 98038625Srvb/* locals */ 98138625Srvb struct cnode *cp; 98238625Srvb const char *nm = cnp->cn_nameptr; 98338625Srvb int len = cnp->cn_namelen; 98438625Srvb ViceFid VFid; 98538625Srvb int vtype; 98638625Srvb int error = 0; 98738625Srvb 98839085Srvb MARK_ENTRY(CODA_LOOKUP_STATS); 98938625Srvb 99039085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n", 99138625Srvb nm, dcp->c_fid.Volume, 99238625Srvb dcp->c_fid.Vnode, dcp->c_fid.Unique));); 99338625Srvb 99438625Srvb /* Check for lookup of control object. */ 99538625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 99639085Srvb *vpp = coda_ctlvp; 99738625Srvb vref(*vpp); 99839085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 99938625Srvb goto exit; 100038625Srvb } 100138625Srvb 100239085Srvb if (len+1 > CODA_MAXNAMLEN) { 100339085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 100439085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n", 100538625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, 100638625Srvb dcp->c_fid.Unique, nm));); 100738625Srvb *vpp = (struct vnode *)0; 100838625Srvb error = EINVAL; 100938625Srvb goto exit; 101038625Srvb } 101138625Srvb /* First try to look the file up in the cfs name cache */ 101238625Srvb /* lock the parent vnode? */ 101339085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 101438625Srvb if (cp) { 101538625Srvb *vpp = CTOV(cp); 101638625Srvb vref(*vpp); 101739085Srvb CODADEBUG(CODA_LOOKUP, 101838625Srvb myprintf(("lookup result %d vpp %p\n",error,*vpp));) 101938625Srvb } else { 102038625Srvb 102138625Srvb /* The name wasn't cached, so we need to contact Venus */ 102283366Sjulian error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc, &VFid, &vtype); 102338625Srvb 102438625Srvb if (error) { 102539085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 102639085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n", 102738625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));) 102838625Srvb *vpp = (struct vnode *)0; 102938625Srvb } else { 103039085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 103139085Srvb CODADEBUG(CODA_LOOKUP, 103238625Srvb myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n", 103338625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, vtype, 103438625Srvb error)); ) 103538625Srvb 103639085Srvb cp = make_coda_node(&VFid, dvp->v_mount, vtype); 103738625Srvb *vpp = CTOV(cp); 103838625Srvb 103938625Srvb /* enter the new vnode in the Name Cache only if the top bit isn't set */ 104038625Srvb /* And don't enter a new vnode for an invalid one! */ 104139085Srvb if (!(vtype & CODA_NOCACHE)) 104239085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 104338625Srvb } 104438625Srvb } 104538625Srvb 104638625Srvb exit: 104738625Srvb /* 104838625Srvb * If we are creating, and this was the last name to be looked up, 104938625Srvb * and the error was ENOENT, then there really shouldn't be an 105038625Srvb * error and we can make the leaf NULL and return success. Since 105138625Srvb * this is supposed to work under Mach as well as NetBSD, we're 105238625Srvb * leaving this fn wrapped. We also must tell lookup/namei that 105338625Srvb * we need to save the last component of the name. (Create will 105438625Srvb * have to free the name buffer later...lucky us...) 105538625Srvb */ 105638625Srvb if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) 105738625Srvb && (cnp->cn_flags & ISLASTCN) 105838625Srvb && (error == ENOENT)) 105938625Srvb { 106038625Srvb error = EJUSTRETURN; 106138625Srvb cnp->cn_flags |= SAVENAME; 106238625Srvb *ap->a_vpp = NULL; 106338625Srvb } 106438625Srvb 106538625Srvb /* 106638625Srvb * If we are removing, and we are at the last element, and we 106738625Srvb * found it, then we need to keep the name around so that the 106838625Srvb * removal will go ahead as planned. Unfortunately, this will 106938625Srvb * probably also lock the to-be-removed vnode, which may or may 107038625Srvb * not be a good idea. I'll have to look at the bits of 107139085Srvb * coda_remove to make sure. We'll only save the name if we did in 107239085Srvb * fact find the name, otherwise coda_remove won't have a chance 107338625Srvb * to free the pathname. 107438625Srvb */ 107538625Srvb if ((cnp->cn_nameiop == DELETE) 107638625Srvb && (cnp->cn_flags & ISLASTCN) 107738625Srvb && !error) 107838625Srvb { 107938625Srvb cnp->cn_flags |= SAVENAME; 108038625Srvb } 108138625Srvb 108238625Srvb /* 108338625Srvb * If the lookup went well, we need to (potentially?) unlock the 108438625Srvb * parent, and lock the child. We are only responsible for 108538625Srvb * checking to see if the parent is supposed to be unlocked before 108638625Srvb * we return. We must always lock the child (provided there is 108738625Srvb * one, and (the parent isn't locked or it isn't the same as the 108838625Srvb * parent.) Simple, huh? We can never leave the parent locked unless 108938625Srvb * we are ISLASTCN 109038625Srvb */ 109138625Srvb if (!error || (error == EJUSTRETURN)) { 109238625Srvb if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) { 109383366Sjulian if ((error = VOP_UNLOCK(dvp, 0, td))) { 109438625Srvb return error; 109538625Srvb } 109638625Srvb /* 109738625Srvb * The parent is unlocked. As long as there is a child, 109838625Srvb * lock it without bothering to check anything else. 109938625Srvb */ 110038625Srvb if (*ap->a_vpp) { 110183366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 110239085Srvb printf("coda_lookup: "); 110338625Srvb panic("unlocked parent but couldn't lock child"); 110438625Srvb } 110538625Srvb } 110638625Srvb } else { 110738625Srvb /* The parent is locked, and may be the same as the child */ 110838625Srvb if (*ap->a_vpp && (*ap->a_vpp != dvp)) { 110938625Srvb /* Different, go ahead and lock it. */ 111083366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 111139085Srvb printf("coda_lookup: "); 111238625Srvb panic("unlocked parent but couldn't lock child"); 111338625Srvb } 111438625Srvb } 111538625Srvb } 111638625Srvb } else { 111738625Srvb /* If the lookup failed, we need to ensure that the leaf is NULL */ 111838625Srvb /* Don't change any locking? */ 111938625Srvb *ap->a_vpp = NULL; 112038625Srvb } 112138625Srvb return(error); 112238625Srvb} 112338625Srvb 112438625Srvb/*ARGSUSED*/ 112538625Srvbint 112639085Srvbcoda_create(v) 112738625Srvb void *v; 112838625Srvb{ 112938625Srvb/* true args */ 113038625Srvb struct vop_create_args *ap = v; 113138625Srvb struct vnode *dvp = ap->a_dvp; 113238625Srvb struct cnode *dcp = VTOC(dvp); 113338625Srvb struct vattr *va = ap->a_vap; 113438625Srvb int exclusive = 1; 113538625Srvb int mode = ap->a_vap->va_mode; 113638625Srvb struct vnode **vpp = ap->a_vpp; 113738625Srvb struct componentname *cnp = ap->a_cnp; 113838625Srvb struct ucred *cred = cnp->cn_cred; 113983366Sjulian struct thread *td = cnp->cn_thread; 114038625Srvb/* locals */ 114138625Srvb int error; 114238625Srvb struct cnode *cp; 114338625Srvb const char *nm = cnp->cn_nameptr; 114438625Srvb int len = cnp->cn_namelen; 114538625Srvb ViceFid VFid; 114638625Srvb struct vattr attr; 114738625Srvb 114839085Srvb MARK_ENTRY(CODA_CREATE_STATS); 114938625Srvb 115038625Srvb /* All creates are exclusive XXX */ 115138625Srvb /* I'm assuming the 'mode' argument is the file mode bits XXX */ 115238625Srvb 115338625Srvb /* Check for create of control object. */ 115438625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 115538625Srvb *vpp = (struct vnode *)0; 115639085Srvb MARK_INT_FAIL(CODA_CREATE_STATS); 115738625Srvb return(EACCES); 115838625Srvb } 115938625Srvb 116083366Sjulian error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td->td_proc, &VFid, &attr); 116138625Srvb 116238625Srvb if (!error) { 116338625Srvb 116438625Srvb /* If this is an exclusive create, panic if the file already exists. */ 116538625Srvb /* Venus should have detected the file and reported EEXIST. */ 116638625Srvb 116738625Srvb if ((exclusive == 1) && 116839085Srvb (coda_find(&VFid) != NULL)) 116938625Srvb panic("cnode existed for newly created file!"); 117038625Srvb 117139085Srvb cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type); 117238625Srvb *vpp = CTOV(cp); 117338625Srvb 117438625Srvb /* Update va to reflect the new attributes. */ 117538625Srvb (*va) = attr; 117638625Srvb 117738625Srvb /* Update the attribute cache and mark it as valid */ 117839085Srvb if (coda_attr_cache) { 117938625Srvb VTOC(*vpp)->c_vattr = attr; 118038625Srvb VTOC(*vpp)->c_flags |= C_VATTR; 118138625Srvb } 118238625Srvb 118338625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 118438625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 118538625Srvb 118638625Srvb /* enter the new vnode in the Name Cache */ 118739085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 118838625Srvb 118939085Srvb CODADEBUG(CODA_CREATE, 119038625Srvb myprintf(("create: (%lx.%lx.%lx), result %d\n", 119138625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 119238625Srvb } else { 119338625Srvb *vpp = (struct vnode *)0; 119439085Srvb CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));) 119538625Srvb } 119638625Srvb 119738625Srvb if (!error) { 119838625Srvb if (cnp->cn_flags & LOCKLEAF) { 119983366Sjulian if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) { 120039085Srvb printf("coda_create: "); 120138625Srvb panic("unlocked parent but couldn't lock child"); 120238625Srvb } 120338625Srvb } 120439650Srvb#ifdef OLD_DIAGNOSTIC 120538625Srvb else { 120639085Srvb printf("coda_create: LOCKLEAF not set!\n"); 120738625Srvb } 120839650Srvb#endif 120938625Srvb } 121038625Srvb return(error); 121138625Srvb} 121238625Srvb 121338625Srvbint 121439085Srvbcoda_remove(v) 121538625Srvb void *v; 121638625Srvb{ 121738625Srvb/* true args */ 121838625Srvb struct vop_remove_args *ap = v; 121938625Srvb struct vnode *dvp = ap->a_dvp; 122038625Srvb struct cnode *cp = VTOC(dvp); 122138625Srvb struct componentname *cnp = ap->a_cnp; 122238625Srvb struct ucred *cred = cnp->cn_cred; 122383366Sjulian struct thread *td = cnp->cn_thread; 122438625Srvb/* locals */ 122538625Srvb int error; 122638625Srvb const char *nm = cnp->cn_nameptr; 122738625Srvb int len = cnp->cn_namelen; 122838625Srvb struct cnode *tp; 122938625Srvb 123039085Srvb MARK_ENTRY(CODA_REMOVE_STATS); 123138625Srvb 123239085Srvb CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n", 123338625Srvb nm, cp->c_fid.Volume, cp->c_fid.Vnode, 123438625Srvb cp->c_fid.Unique));); 123538625Srvb 123639085Srvb /* Remove the file's entry from the CODA Name Cache */ 123738625Srvb /* We're being conservative here, it might be that this person 123838625Srvb * doesn't really have sufficient access to delete the file 123938625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 124038625Srvb */ 124138625Srvb /* I'm gonna go out on a limb here. If a file and a hardlink to it 124238625Srvb * exist, and one is removed, the link count on the other will be 124338625Srvb * off by 1. We could either invalidate the attrs if cached, or 124438625Srvb * fix them. I'll try to fix them. DCS 11/8/94 124538625Srvb */ 124639085Srvb tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); 124738625Srvb if (tp) { 124838625Srvb if (VALID_VATTR(tp)) { /* If attrs are cached */ 124938625Srvb if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */ 125038625Srvb tp->c_vattr.va_nlink--; 125138625Srvb } 125238625Srvb } 125338625Srvb 125439085Srvb coda_nc_zapfile(VTOC(dvp), nm, len); 125538625Srvb /* No need to flush it if it doesn't exist! */ 125638625Srvb } 125738625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 125838625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 125938625Srvb 126038625Srvb /* Check for remove of control object. */ 126138625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 126239085Srvb MARK_INT_FAIL(CODA_REMOVE_STATS); 126338625Srvb return(ENOENT); 126438625Srvb } 126538625Srvb 126683366Sjulian error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td->td_proc); 126738625Srvb 126839085Srvb CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); ) 126938625Srvb 127038625Srvb return(error); 127138625Srvb} 127238625Srvb 127338625Srvbint 127439085Srvbcoda_link(v) 127538625Srvb void *v; 127638625Srvb{ 127738625Srvb/* true args */ 127838625Srvb struct vop_link_args *ap = v; 127938625Srvb struct vnode *vp = ap->a_vp; 128038625Srvb struct cnode *cp = VTOC(vp); 128138625Srvb struct vnode *tdvp = ap->a_tdvp; 128238625Srvb struct cnode *tdcp = VTOC(tdvp); 128338625Srvb struct componentname *cnp = ap->a_cnp; 128438625Srvb struct ucred *cred = cnp->cn_cred; 128583366Sjulian struct thread *td = cnp->cn_thread; 128638625Srvb/* locals */ 128738625Srvb int error; 128838625Srvb const char *nm = cnp->cn_nameptr; 128938625Srvb int len = cnp->cn_namelen; 129038625Srvb 129139085Srvb MARK_ENTRY(CODA_LINK_STATS); 129238625Srvb 129339085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 129438625Srvb 129538625Srvb myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n", 129638625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 129738625Srvb myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n", 129838625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 129938625Srvb 130038625Srvb } 130139085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 130238625Srvb myprintf(("link: vp fid: (%lx.%lx.%lx)\n", 130338625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 130438625Srvb myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n", 130538625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 130638625Srvb 130738625Srvb } 130838625Srvb 130938625Srvb /* Check for link to/from control object. */ 131038625Srvb if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { 131139085Srvb MARK_INT_FAIL(CODA_LINK_STATS); 131238625Srvb return(EACCES); 131338625Srvb } 131438625Srvb 131583366Sjulian error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td->td_proc); 131638625Srvb 131738625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 131838625Srvb VTOC(tdvp)->c_flags &= ~C_VATTR; 131938625Srvb VTOC(vp)->c_flags &= ~C_VATTR; 132038625Srvb 132139085Srvb CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); ) 132238625Srvb 132338625Srvb return(error); 132438625Srvb} 132538625Srvb 132638625Srvbint 132739085Srvbcoda_rename(v) 132838625Srvb void *v; 132938625Srvb{ 133038625Srvb/* true args */ 133138625Srvb struct vop_rename_args *ap = v; 133238625Srvb struct vnode *odvp = ap->a_fdvp; 133338625Srvb struct cnode *odcp = VTOC(odvp); 133438625Srvb struct componentname *fcnp = ap->a_fcnp; 133538625Srvb struct vnode *ndvp = ap->a_tdvp; 133638625Srvb struct cnode *ndcp = VTOC(ndvp); 133738625Srvb struct componentname *tcnp = ap->a_tcnp; 133838625Srvb struct ucred *cred = fcnp->cn_cred; 133983366Sjulian struct thread *td = fcnp->cn_thread; 134038625Srvb/* true args */ 134138625Srvb int error; 134238625Srvb const char *fnm = fcnp->cn_nameptr; 134338625Srvb int flen = fcnp->cn_namelen; 134438625Srvb const char *tnm = tcnp->cn_nameptr; 134538625Srvb int tlen = tcnp->cn_namelen; 134638625Srvb 134739085Srvb MARK_ENTRY(CODA_RENAME_STATS); 134838625Srvb 134938625Srvb /* Hmmm. The vnodes are already looked up. Perhaps they are locked? 135038625Srvb This could be Bad. XXX */ 135139650Srvb#ifdef OLD_DIAGNOSTIC 135238625Srvb if ((fcnp->cn_cred != tcnp->cn_cred) 135383366Sjulian || (fcnp->cn_thread != tcnp->cn_thread)) 135438625Srvb { 135539085Srvb panic("coda_rename: component names don't agree"); 135638625Srvb } 135739650Srvb#endif 135838625Srvb 135938625Srvb /* Check for rename involving control object. */ 136038625Srvb if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { 136139085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 136238625Srvb return(EACCES); 136338625Srvb } 136438625Srvb 136538625Srvb /* Problem with moving directories -- need to flush entry for .. */ 136638625Srvb if (odvp != ndvp) { 136739085Srvb struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred); 136838625Srvb if (ovcp) { 136938625Srvb struct vnode *ovp = CTOV(ovcp); 137038625Srvb if ((ovp) && 137138625Srvb (ovp->v_type == VDIR)) /* If it's a directory */ 137239085Srvb coda_nc_zapfile(VTOC(ovp),"..", 2); 137338625Srvb } 137438625Srvb } 137538625Srvb 137638625Srvb /* Remove the entries for both source and target files */ 137739085Srvb coda_nc_zapfile(VTOC(odvp), fnm, flen); 137839085Srvb coda_nc_zapfile(VTOC(ndvp), tnm, tlen); 137938625Srvb 138038625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 138138625Srvb VTOC(odvp)->c_flags &= ~C_VATTR; 138238625Srvb VTOC(ndvp)->c_flags &= ~C_VATTR; 138338625Srvb 138439085Srvb if (flen+1 > CODA_MAXNAMLEN) { 138539085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 138638625Srvb error = EINVAL; 138738625Srvb goto exit; 138838625Srvb } 138938625Srvb 139039085Srvb if (tlen+1 > CODA_MAXNAMLEN) { 139139085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 139238625Srvb error = EINVAL; 139338625Srvb goto exit; 139438625Srvb } 139538625Srvb 139683366Sjulian error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td->td_proc); 139738625Srvb 139838625Srvb exit: 139939085Srvb CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));) 140038625Srvb /* XXX - do we need to call cache pureg on the moved vnode? */ 140138625Srvb cache_purge(ap->a_fvp); 140238625Srvb 140338625Srvb /* It seems to be incumbent on us to drop locks on all four vnodes */ 140438625Srvb /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */ 140538625Srvb 140638625Srvb vrele(ap->a_fvp); 140738625Srvb vrele(odvp); 140838625Srvb 140938625Srvb if (ap->a_tvp) { 141038625Srvb if (ap->a_tvp == ndvp) { 141138625Srvb vrele(ap->a_tvp); 141238625Srvb } else { 141338625Srvb vput(ap->a_tvp); 141438625Srvb } 141538625Srvb } 141638625Srvb 141738625Srvb vput(ndvp); 141838625Srvb return(error); 141938625Srvb} 142038625Srvb 142138625Srvbint 142239085Srvbcoda_mkdir(v) 142338625Srvb void *v; 142438625Srvb{ 142538625Srvb/* true args */ 142638625Srvb struct vop_mkdir_args *ap = v; 142738625Srvb struct vnode *dvp = ap->a_dvp; 142838625Srvb struct cnode *dcp = VTOC(dvp); 142938625Srvb struct componentname *cnp = ap->a_cnp; 143038625Srvb register struct vattr *va = ap->a_vap; 143138625Srvb struct vnode **vpp = ap->a_vpp; 143238625Srvb struct ucred *cred = cnp->cn_cred; 143383366Sjulian struct thread *td = cnp->cn_thread; 143438625Srvb/* locals */ 143538625Srvb int error; 143638625Srvb const char *nm = cnp->cn_nameptr; 143738625Srvb int len = cnp->cn_namelen; 143838625Srvb struct cnode *cp; 143938625Srvb ViceFid VFid; 144038625Srvb struct vattr ova; 144138625Srvb 144239085Srvb MARK_ENTRY(CODA_MKDIR_STATS); 144338625Srvb 144438625Srvb /* Check for mkdir of target object. */ 144538625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 144638625Srvb *vpp = (struct vnode *)0; 144739085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 144838625Srvb return(EACCES); 144938625Srvb } 145038625Srvb 145139085Srvb if (len+1 > CODA_MAXNAMLEN) { 145238625Srvb *vpp = (struct vnode *)0; 145339085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 145438625Srvb return(EACCES); 145538625Srvb } 145638625Srvb 145783366Sjulian error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td->td_proc, &VFid, &ova); 145838625Srvb 145938625Srvb if (!error) { 146039085Srvb if (coda_find(&VFid) != NULL) 146138625Srvb panic("cnode existed for newly created directory!"); 146238625Srvb 146338625Srvb 146439085Srvb cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); 146538625Srvb *vpp = CTOV(cp); 146638625Srvb 146738625Srvb /* enter the new vnode in the Name Cache */ 146839085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 146938625Srvb 147038625Srvb /* as a side effect, enter "." and ".." for the directory */ 147139085Srvb coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); 147239085Srvb coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); 147338625Srvb 147439085Srvb if (coda_attr_cache) { 147538625Srvb VTOC(*vpp)->c_vattr = ova; /* update the attr cache */ 147638625Srvb VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */ 147738625Srvb } 147838625Srvb 147938625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 148038625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 148138625Srvb 148239085Srvb CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n", 148338625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 148438625Srvb } else { 148538625Srvb *vpp = (struct vnode *)0; 148639085Srvb CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));) 148738625Srvb } 148838625Srvb 148938625Srvb return(error); 149038625Srvb} 149138625Srvb 149238625Srvbint 149339085Srvbcoda_rmdir(v) 149438625Srvb void *v; 149538625Srvb{ 149638625Srvb/* true args */ 149738625Srvb struct vop_rmdir_args *ap = v; 149838625Srvb struct vnode *dvp = ap->a_dvp; 149938625Srvb struct cnode *dcp = VTOC(dvp); 150038625Srvb struct componentname *cnp = ap->a_cnp; 150138625Srvb struct ucred *cred = cnp->cn_cred; 150283366Sjulian struct thread *td = cnp->cn_thread; 150338625Srvb/* true args */ 150438625Srvb int error; 150538625Srvb const char *nm = cnp->cn_nameptr; 150638625Srvb int len = cnp->cn_namelen; 150738625Srvb struct cnode *cp; 150838625Srvb 150939085Srvb MARK_ENTRY(CODA_RMDIR_STATS); 151038625Srvb 151138625Srvb /* Check for rmdir of control object. */ 151238625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 151339085Srvb MARK_INT_FAIL(CODA_RMDIR_STATS); 151438625Srvb return(ENOENT); 151538625Srvb } 151638625Srvb 151738625Srvb /* We're being conservative here, it might be that this person 151838625Srvb * doesn't really have sufficient access to delete the file 151938625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 152038625Srvb */ 152138625Srvb /* 152238625Srvb * As a side effect of the rmdir, remove any entries for children of 152338625Srvb * the directory, especially "." and "..". 152438625Srvb */ 152539085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 152639085Srvb if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); 152738625Srvb 152839085Srvb /* Remove the file's entry from the CODA Name Cache */ 152939085Srvb coda_nc_zapfile(dcp, nm, len); 153038625Srvb 153138625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 153238625Srvb dcp->c_flags &= ~C_VATTR; 153338625Srvb 153483366Sjulian error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td->td_proc); 153538625Srvb 153639085Srvb CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); ) 153738625Srvb 153838625Srvb return(error); 153938625Srvb} 154038625Srvb 154138625Srvbint 154239085Srvbcoda_symlink(v) 154338625Srvb void *v; 154438625Srvb{ 154538625Srvb/* true args */ 154638625Srvb struct vop_symlink_args *ap = v; 154738625Srvb struct vnode *tdvp = ap->a_dvp; 154838625Srvb struct cnode *tdcp = VTOC(tdvp); 154938625Srvb struct componentname *cnp = ap->a_cnp; 155038625Srvb struct vattr *tva = ap->a_vap; 155138625Srvb char *path = ap->a_target; 155238625Srvb struct ucred *cred = cnp->cn_cred; 155383366Sjulian struct thread *td = cnp->cn_thread; 155453131Seivind struct vnode **vpp = ap->a_vpp; 155538625Srvb/* locals */ 155638625Srvb int error; 155738625Srvb /* 155839085Srvb * XXX I'm assuming the following things about coda_symlink's 155938625Srvb * arguments: 156038625Srvb * t(foo) is the new name/parent/etc being created. 156138625Srvb * lname is the contents of the new symlink. 156238625Srvb */ 156338759Srvb char *nm = cnp->cn_nameptr; 156438625Srvb int len = cnp->cn_namelen; 156538625Srvb int plen = strlen(path); 156638625Srvb 156738625Srvb /* 156838625Srvb * Here's the strategy for the moment: perform the symlink, then 156938625Srvb * do a lookup to grab the resulting vnode. I know this requires 157038625Srvb * two communications with Venus for a new sybolic link, but 157138625Srvb * that's the way the ball bounces. I don't yet want to change 157238625Srvb * the way the Mach symlink works. When Mach support is 157338625Srvb * deprecated, we should change symlink so that the common case 157438625Srvb * returns the resultant vnode in a vpp argument. 157538625Srvb */ 157638625Srvb 157739085Srvb MARK_ENTRY(CODA_SYMLINK_STATS); 157838625Srvb 157938625Srvb /* Check for symlink of control object. */ 158038625Srvb if (IS_CTL_NAME(tdvp, nm, len)) { 158139085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 158238625Srvb return(EACCES); 158338625Srvb } 158438625Srvb 158539085Srvb if (plen+1 > CODA_MAXPATHLEN) { 158639085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 158738625Srvb return(EINVAL); 158838625Srvb } 158938625Srvb 159039085Srvb if (len+1 > CODA_MAXNAMLEN) { 159139085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 159238625Srvb error = EINVAL; 159338625Srvb goto exit; 159438625Srvb } 159538625Srvb 159683366Sjulian error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td->td_proc); 159738625Srvb 159838625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 159938625Srvb tdcp->c_flags &= ~C_VATTR; 160038625Srvb 160153131Seivind if (error == 0) 160253131Seivind error = VOP_LOOKUP(tdvp, vpp, cnp); 160338625Srvb 160438625Srvb exit: 160539085Srvb CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); ) 160638625Srvb return(error); 160738625Srvb} 160838625Srvb 160938625Srvb/* 161038625Srvb * Read directory entries. 161138625Srvb */ 161238625Srvbint 161339085Srvbcoda_readdir(v) 161438625Srvb void *v; 161538625Srvb{ 161638625Srvb/* true args */ 161738625Srvb struct vop_readdir_args *ap = v; 161838625Srvb struct vnode *vp = ap->a_vp; 161938625Srvb struct cnode *cp = VTOC(vp); 162038625Srvb register struct uio *uiop = ap->a_uio; 162138625Srvb struct ucred *cred = ap->a_cred; 162238625Srvb int *eofflag = ap->a_eofflag; 162338625Srvb u_long **cookies = ap->a_cookies; 162438625Srvb int *ncookies = ap->a_ncookies; 162583366Sjulian struct thread *td = ap->a_uio->uio_td; 162638625Srvb/* upcall decl */ 162738625Srvb/* locals */ 162838625Srvb int error = 0; 162938625Srvb 163039085Srvb MARK_ENTRY(CODA_READDIR_STATS); 163138625Srvb 163249524Sbde CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n", 163349524Sbde (void *)uiop->uio_iov->iov_base, 163449524Sbde uiop->uio_resid, 163549524Sbde (long long)uiop->uio_offset, 163649524Sbde uiop->uio_segflg)); ) 163738625Srvb 163838625Srvb /* Check for readdir of control object. */ 163938625Srvb if (IS_CTL_VP(vp)) { 164039085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 164138625Srvb return(ENOENT); 164238625Srvb } 164338625Srvb 164438759Srvb { 164538625Srvb /* If directory is not already open do an "internal open" on it. */ 164638625Srvb int opened_internally = 0; 164738625Srvb if (cp->c_ovp == NULL) { 164838625Srvb opened_internally = 1; 164939085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 165083366Sjulian error = VOP_OPEN(vp, FREAD, cred, td); 165139085Srvbprintf("coda_readdir: Internally Opening %p\n", vp); 165238625Srvb if (error) { 165339085Srvb printf("coda_readdir: VOP_OPEN on container failed %d\n", error); 165438625Srvb return (error); 165538625Srvb } 165638625Srvb if (vp->v_type == VREG) { 165783366Sjulian error = vfs_object_create(vp, td, cred); 165838625Srvb if (error != 0) { 165939085Srvb printf("coda_readdir: vfs_object_create() returns %d\n", error); 166038625Srvb vput(vp); 166138625Srvb } 166238625Srvb } 166338625Srvb if (error) return(error); 166438625Srvb } 166538625Srvb 166638625Srvb /* Have UFS handle the call. */ 1667103937Sjeff 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))); ) 166838625Srvb error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, 166938625Srvb cookies); 167038625Srvb 167138625Srvb if (error) 167239085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 167338625Srvb else 167439085Srvb MARK_INT_SAT(CODA_READDIR_STATS); 167538625Srvb 167638625Srvb /* Do an "internal close" if necessary. */ 167738625Srvb if (opened_internally) { 167839085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 167983366Sjulian (void)VOP_CLOSE(vp, FREAD, cred, td); 168038625Srvb } 168138625Srvb } 168238625Srvb 168338625Srvb return(error); 168438625Srvb} 168538625Srvb 168638625Srvb/* 168796755Strhodes * Convert from filesystem blocks to device blocks 168838625Srvb */ 168938625Srvbint 169039085Srvbcoda_bmap(v) 169138625Srvb void *v; 169238625Srvb{ 169338625Srvb /* XXX on the global proc */ 169438625Srvb/* true args */ 169538625Srvb struct vop_bmap_args *ap = v; 169638625Srvb struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */ 169738625Srvb daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */ 169838625Srvb struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */ 169996572Sphk daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */ 170083366Sjulian struct thread *td __attribute__((unused)) = curthread; 170138625Srvb/* upcall decl */ 170238625Srvb/* locals */ 170338625Srvb 170438625Srvb int ret = 0; 170538625Srvb struct cnode *cp; 170638625Srvb 170738625Srvb cp = VTOC(vp); 170838625Srvb if (cp->c_ovp) { 170939728Srvb return EINVAL; 171038625Srvb ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb); 171139650Srvb#if 0 171292363Smckusick printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %lld, ap->a_runp %p, ap->a_runb %p) = %d\n", 171338625Srvb cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret); 171439650Srvb#endif 171538625Srvb return ret; 171638625Srvb } else { 171741504Srvb#if 0 171839085Srvb printf("coda_bmap: no container\n"); 171941504Srvb#endif 172038625Srvb return(EOPNOTSUPP); 172138625Srvb } 172238625Srvb} 172338625Srvb 172438625Srvb/* 172538625Srvb * I don't think the following two things are used anywhere, so I've 172638625Srvb * commented them out 172738625Srvb * 172838625Srvb * struct buf *async_bufhead; 172938625Srvb * int async_daemon_count; 173038625Srvb */ 173138625Srvbint 173239085Srvbcoda_strategy(v) 173338625Srvb void *v; 173438625Srvb{ 173538625Srvb/* true args */ 173638625Srvb struct vop_strategy_args *ap = v; 173738625Srvb register struct buf *bp __attribute__((unused)) = ap->a_bp; 173883366Sjulian struct thread *td __attribute__((unused)) = curthread; 173938625Srvb/* upcall decl */ 174038625Srvb/* locals */ 174138625Srvb 174239085Srvb printf("coda_strategy: called ???\n"); 174338625Srvb return(EOPNOTSUPP); 174438625Srvb} 174538625Srvb 174638625Srvbint 174739085Srvbcoda_reclaim(v) 174838625Srvb void *v; 174938625Srvb{ 175038625Srvb/* true args */ 175138625Srvb struct vop_reclaim_args *ap = v; 175238625Srvb struct vnode *vp = ap->a_vp; 175338625Srvb struct cnode *cp = VTOC(vp); 175438625Srvb/* upcall decl */ 175538625Srvb/* locals */ 175638625Srvb 175738625Srvb/* 175838625Srvb * Forced unmount/flush will let vnodes with non zero use be destroyed! 175938625Srvb */ 176038625Srvb ENTRY; 176138625Srvb 176238625Srvb if (IS_UNMOUNTING(cp)) { 176338625Srvb#ifdef DEBUG 176438625Srvb if (VTOC(vp)->c_ovp) { 176538625Srvb if (IS_UNMOUNTING(cp)) 176639085Srvb printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp); 176738625Srvb } 176838625Srvb#endif 176938625Srvb } else { 177039650Srvb#ifdef OLD_DIAGNOSTIC 1771103937Sjeff if (vrefcnt(vp) != 0) 177239650Srvb print("coda_reclaim: pushing active %p\n", vp); 177338625Srvb if (VTOC(vp)->c_ovp) { 177439085Srvb panic("coda_reclaim: c_ovp not void"); 177538625Srvb } 177639650Srvb#endif 177738625Srvb } 177838625Srvb cache_purge(vp); 177966615Sjasone lockdestroy(&(VTOC(vp)->c_lock)); 178039085Srvb coda_free(VTOC(vp)); 178138625Srvb VTOC(vp) = NULL; 178238625Srvb return (0); 178338625Srvb} 178438625Srvb 178538625Srvbint 178639085Srvbcoda_lock(v) 178738625Srvb void *v; 178838625Srvb{ 178938625Srvb/* true args */ 179038625Srvb struct vop_lock_args *ap = v; 179138625Srvb struct vnode *vp = ap->a_vp; 179238625Srvb struct cnode *cp = VTOC(vp); 179383366Sjulian struct thread *td = ap->a_td; 179438625Srvb/* upcall decl */ 179538625Srvb/* locals */ 179638625Srvb 179738625Srvb ENTRY; 179838625Srvb 179939085Srvb if (coda_lockdebug) { 180038625Srvb myprintf(("Attempting lock on %lx.%lx.%lx\n", 180138625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 180238625Srvb } 180338625Srvb 180442900Seivind#ifndef DEBUG_LOCKS 180583366Sjulian return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td)); 180642900Seivind#else 180783366Sjulian return (debuglockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, td, 180842900Seivind "coda_lock", vp->filename, vp->line)); 180942900Seivind#endif 181038625Srvb} 181138625Srvb 181238625Srvbint 181339085Srvbcoda_unlock(v) 181438625Srvb void *v; 181538625Srvb{ 181638625Srvb/* true args */ 181738625Srvb struct vop_unlock_args *ap = v; 181838625Srvb struct vnode *vp = ap->a_vp; 181938625Srvb struct cnode *cp = VTOC(vp); 182083366Sjulian struct thread *td = ap->a_td; 182138625Srvb/* upcall decl */ 182238625Srvb/* locals */ 182338625Srvb 182438625Srvb ENTRY; 182539085Srvb if (coda_lockdebug) { 182638625Srvb myprintf(("Attempting unlock on %lx.%lx.%lx\n", 182738625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 182838625Srvb } 182938625Srvb 183083366Sjulian return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, td)); 183138625Srvb} 183238625Srvb 183338625Srvbint 183439085Srvbcoda_islocked(v) 183538625Srvb void *v; 183638625Srvb{ 183738625Srvb/* true args */ 183838625Srvb struct vop_islocked_args *ap = v; 183938625Srvb struct cnode *cp = VTOC(ap->a_vp); 184038625Srvb ENTRY; 184138625Srvb 184283366Sjulian return (lockstatus(&cp->c_lock, ap->a_td)); 184338625Srvb} 184438625Srvb 184538625Srvb/* How one looks up a vnode given a device/inode pair: */ 184638625Srvbint 184739085Srvbcoda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp) 184838625Srvb{ 184938625Srvb /* This is like VFS_VGET() or igetinode()! */ 185038625Srvb int error; 185138625Srvb struct mount *mp; 185238625Srvb 185338625Srvb if (!(mp = devtomp(dev))) { 185449524Sbde myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n", 185549524Sbde (u_long)dev2udev(dev))); 185638625Srvb return(ENXIO); 185738625Srvb } 185838625Srvb 185938625Srvb /* XXX - ensure that nonzero-return means failure */ 186092462Smckusick error = VFS_VGET(mp,ino,LK_EXCLUSIVE,vpp); 186138625Srvb if (error) { 186249524Sbde myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n", 186349524Sbde (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error)); 186438625Srvb return(ENOENT); 186538625Srvb } 186638625Srvb return(0); 186738625Srvb} 186838625Srvb 186938625Srvbvoid 187038625Srvbprint_vattr( attr ) 187138625Srvb struct vattr *attr; 187238625Srvb{ 187338625Srvb char *typestr; 187438625Srvb 187538625Srvb switch (attr->va_type) { 187638625Srvb case VNON: 187738625Srvb typestr = "VNON"; 187838625Srvb break; 187938625Srvb case VREG: 188038625Srvb typestr = "VREG"; 188138625Srvb break; 188238625Srvb case VDIR: 188338625Srvb typestr = "VDIR"; 188438625Srvb break; 188538625Srvb case VBLK: 188638625Srvb typestr = "VBLK"; 188738625Srvb break; 188838625Srvb case VCHR: 188938625Srvb typestr = "VCHR"; 189038625Srvb break; 189138625Srvb case VLNK: 189238625Srvb typestr = "VLNK"; 189338625Srvb break; 189438625Srvb case VSOCK: 189538625Srvb typestr = "VSCK"; 189638625Srvb break; 189738625Srvb case VFIFO: 189838625Srvb typestr = "VFFO"; 189938625Srvb break; 190038625Srvb case VBAD: 190138625Srvb typestr = "VBAD"; 190238625Srvb break; 190338625Srvb default: 190438625Srvb typestr = "????"; 190538625Srvb break; 190638625Srvb } 190738625Srvb 190838625Srvb 190938625Srvb myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", 191038625Srvb typestr, (int)attr->va_mode, (int)attr->va_uid, 191138625Srvb (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); 191238625Srvb 191338625Srvb myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", 191438625Srvb (int)attr->va_fileid, (int)attr->va_nlink, 191538625Srvb (int)attr->va_size, 191638625Srvb (int)attr->va_blocksize,(int)attr->va_bytes)); 191738625Srvb myprintf((" gen %ld flags %ld vaflags %d\n", 191838625Srvb attr->va_gen, attr->va_flags, attr->va_vaflags)); 191938625Srvb myprintf((" atime sec %d nsec %d\n", 192038625Srvb (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec)); 192138625Srvb myprintf((" mtime sec %d nsec %d\n", 192238625Srvb (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec)); 192338625Srvb myprintf((" ctime sec %d nsec %d\n", 192438625Srvb (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec)); 192538625Srvb} 192638625Srvb 192738625Srvb/* How to print a ucred */ 192838625Srvbvoid 192938625Srvbprint_cred(cred) 193038625Srvb struct ucred *cred; 193138625Srvb{ 193238625Srvb 193338625Srvb int i; 193438625Srvb 193538625Srvb myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid)); 193638625Srvb 193738625Srvb for (i=0; i < cred->cr_ngroups; i++) 193838625Srvb myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i])); 193938625Srvb myprintf(("\n")); 194038625Srvb 194138625Srvb} 194238625Srvb 194338625Srvb/* 194438625Srvb * Return a vnode for the given fid. 194538625Srvb * If no cnode exists for this fid create one and put it 194638625Srvb * in a table hashed by fid.Volume and fid.Vnode. If the cnode for 194738625Srvb * this fid is already in the table return it (ref count is 194839085Srvb * incremented by coda_find. The cnode will be flushed from the 194939085Srvb * table when coda_inactive calls coda_unsave. 195038625Srvb */ 195138625Srvbstruct cnode * 195239085Srvbmake_coda_node(fid, vfsp, type) 195338625Srvb ViceFid *fid; struct mount *vfsp; short type; 195438625Srvb{ 195538625Srvb struct cnode *cp; 195638625Srvb int err; 195738625Srvb 195839085Srvb if ((cp = coda_find(fid)) == NULL) { 195938625Srvb struct vnode *vp; 196038625Srvb 196139085Srvb cp = coda_alloc(); 196238625Srvb lockinit(&cp->c_lock, PINOD, "cnode", 0, 0); 196338625Srvb cp->c_fid = *fid; 196438625Srvb 1965103314Snjl err = getnewvnode("coda", vfsp, coda_vnodeop_p, &vp); 196638625Srvb if (err) { 196739085Srvb panic("coda: getnewvnode returned error %d\n", err); 196838625Srvb } 196938625Srvb vp->v_data = cp; 197038625Srvb vp->v_type = type; 197138625Srvb cp->c_vnode = vp; 197239085Srvb coda_save(cp); 197338625Srvb 197438625Srvb } else { 197538625Srvb vref(CTOV(cp)); 197638625Srvb } 197738625Srvb 197838625Srvb return cp; 197938625Srvb} 1980111903Stjr 1981111903Stjrint 1982111903Stjrcoda_pathconf(v) 1983111903Stjr void *v; 1984111903Stjr{ 1985111903Stjr struct vop_pathconf_args *ap; 1986111903Stjr int error; 1987111931Stjr register_t *retval; 1988111903Stjr 1989111903Stjr ap = v; 1990111903Stjr retval = ap->a_retval; 1991111903Stjr error = 0; 1992111903Stjr 1993111903Stjr switch (ap->a_name) { 1994111903Stjr case _PC_NAME_MAX: 1995111903Stjr *retval = CODA_MAXNAMLEN; 1996111903Stjr break; 1997111903Stjr case _PC_PATH_MAX: 1998111903Stjr *retval = CODA_MAXPATHLEN; 1999111903Stjr break; 2000111903Stjr default: 2001111903Stjr error = vop_stdpathconf(ap); 2002111903Stjr break; 2003111903Stjr } 2004111903Stjr 2005111903Stjr return (error); 2006111903Stjr} 2007