coda_vnops.c revision 39126
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 $ 3039126Srvb * $Id: coda_vnops.c,v 1.3 1998/09/11 18:50:17 rvb Exp $ 3138759Srvb * 3238759Srvb */ 3338625Srvb 3438625Srvb/* 3538625Srvb * Mach Operating System 3638625Srvb * Copyright (c) 1990 Carnegie-Mellon University 3738625Srvb * Copyright (c) 1989 Carnegie-Mellon University 3838625Srvb * All rights reserved. The CMU software License Agreement specifies 3938625Srvb * the terms and conditions for use and redistribution. 4038625Srvb */ 4138625Srvb 4238625Srvb/* 4338625Srvb * This code was written for the Coda file system at Carnegie Mellon 4438625Srvb * University. Contributers include David Steere, James Kistler, and 4538625Srvb * M. Satyanarayanan. 4638625Srvb */ 4738625Srvb 4838625Srvb/* 4938625Srvb * HISTORY 5039126Srvb * $Log: coda_vnops.c,v $ 5139126Srvb * Revision 1.3 1998/09/11 18:50:17 rvb 5239126Srvb * All the references to cfs, in symbols, structs, and strings 5339126Srvb * have been changed to coda. (Same for CFS.) 5439126Srvb * 5539085Srvb * Revision 1.2 1998/09/02 19:09:53 rvb 5639085Srvb * Pass2 complete 5739085Srvb * 5838759Srvb * Revision 1.1.1.1 1998/08/29 21:14:52 rvb 5938759Srvb * Very Preliminary Coda 6038759Srvb * 6138625Srvb * Revision 1.12 1998/08/28 18:28:00 rvb 6238625Srvb * NetBSD -current is stricter! 6338625Srvb * 6438625Srvb * Revision 1.11 1998/08/28 18:12:23 rvb 6538625Srvb * Now it also works on FreeBSD -current. This code will be 6638625Srvb * committed to the FreeBSD -current and NetBSD -current 6738625Srvb * trees. It will then be tailored to the particular platform 6838625Srvb * by flushing conditional code. 6938625Srvb * 7038625Srvb * Revision 1.10 1998/08/18 17:05:21 rvb 7138625Srvb * Don't use __RCSID now 7238625Srvb * 7338625Srvb * Revision 1.9 1998/08/18 16:31:46 rvb 7438625Srvb * Sync the code for NetBSD -current; test on 1.3 later 7538625Srvb * 7638625Srvb * Revision 1.8 98/02/24 22:22:50 rvb 7738625Srvb * Fixes up mainly to flush iopen and friends 7838625Srvb * 7938625Srvb * Revision 1.7 98/01/31 20:53:15 rvb 8038625Srvb * First version that works on FreeBSD 2.2.5 8138625Srvb * 8238625Srvb * Revision 1.6 98/01/23 11:53:47 rvb 8339085Srvb * Bring RVB_CODA1_1 to HEAD 8438625Srvb * 8538625Srvb * Revision 1.5.2.8 98/01/23 11:21:11 rvb 8638625Srvb * Sync with 2.2.5 8738625Srvb * 8838625Srvb * Revision 1.5.2.7 97/12/19 14:26:08 rvb 8938625Srvb * session id 9038625Srvb * 9138625Srvb * Revision 1.5.2.6 97/12/16 22:01:34 rvb 9238625Srvb * Oops add cfs_subr.h cfs_venus.h; sync with peter 9338625Srvb * 9438625Srvb * Revision 1.5.2.5 97/12/16 12:40:14 rvb 9538625Srvb * Sync with 1.3 9638625Srvb * 9738625Srvb * Revision 1.5.2.4 97/12/10 14:08:31 rvb 9839085Srvb * Fix O_ flags; check result in coda_call 9938625Srvb * 10038625Srvb * Revision 1.5.2.3 97/12/10 11:40:27 rvb 10138625Srvb * No more ody 10238625Srvb * 10338625Srvb * Revision 1.5.2.2 97/12/09 16:07:15 rvb 10438625Srvb * Sync with vfs/include/coda.h 10538625Srvb * 10638625Srvb * Revision 1.5.2.1 97/12/06 17:41:25 rvb 10738625Srvb * Sync with peters coda.h 10838625Srvb * 10938625Srvb * Revision 1.5 97/12/05 10:39:23 rvb 11038625Srvb * Read CHANGES 11138625Srvb * 11238625Srvb * Revision 1.4.14.10 97/11/25 08:08:48 rvb 11338625Srvb * cfs_venus ... done; until cred/vattr change 11438625Srvb * 11538625Srvb * Revision 1.4.14.9 97/11/24 15:44:48 rvb 11638625Srvb * Final cfs_venus.c w/o macros, but one locking bug 11738625Srvb * 11838625Srvb * Revision 1.4.14.8 97/11/21 11:28:04 rvb 11938625Srvb * cfs_venus.c is done: first pass 12038625Srvb * 12138625Srvb * Revision 1.4.14.7 97/11/20 11:46:51 rvb 12238625Srvb * Capture current cfs_venus 12338625Srvb * 12438625Srvb * Revision 1.4.14.6 97/11/18 10:27:19 rvb 12538625Srvb * cfs_nbsd.c is DEAD!!!; integrated into cfs_vf/vnops.c 12638625Srvb * cfs_nb_foo and cfs_foo are joined 12738625Srvb * 12838625Srvb * Revision 1.4.14.5 97/11/13 22:03:03 rvb 12938625Srvb * pass2 cfs_NetBSD.h mt 13038625Srvb * 13138625Srvb * Revision 1.4.14.4 97/11/12 12:09:42 rvb 13238625Srvb * reorg pass1 13338625Srvb * 13438625Srvb * Revision 1.4.14.3 97/11/06 21:03:28 rvb 13538625Srvb * don't include headers in headers 13638625Srvb * 13738625Srvb * Revision 1.4.14.2 97/10/29 16:06:30 rvb 13838625Srvb * Kill DYING 13938625Srvb * 14038625Srvb * Revision 1.4.14.1 1997/10/28 23:10:18 rvb 14138625Srvb * >64Meg; venus can be killed! 14238625Srvb * 14338625Srvb * Revision 1.4 1997/02/20 13:54:50 lily 14439085Srvb * check for NULL return from coda_nc_lookup before CTOV 14538625Srvb * 14638625Srvb * Revision 1.3 1996/12/12 22:11:02 bnoble 14738625Srvb * Fixed the "downcall invokes venus operation" deadlock in all known cases. 14838625Srvb * There may be more 14938625Srvb * 15038625Srvb * Revision 1.2 1996/01/02 16:57:07 bnoble 15138625Srvb * Added support for Coda MiniCache and raw inode calls (final commit) 15238625Srvb * 15338625Srvb * Revision 1.1.2.1 1995/12/20 01:57:34 bnoble 15439085Srvb * Added CODA-specific files 15538625Srvb * 15638625Srvb * Revision 3.1.1.1 1995/03/04 19:08:06 bnoble 15738625Srvb * Branch for NetBSD port revisions 15838625Srvb * 15938625Srvb * Revision 3.1 1995/03/04 19:08:04 bnoble 16038625Srvb * Bump to major revision 3 to prepare for NetBSD port 16138625Srvb * 16238625Srvb * Revision 2.6 1995/02/17 16:25:26 dcs 16338625Srvb * These versions represent several changes: 16438625Srvb * 1. Allow venus to restart even if outstanding references exist. 16538625Srvb * 2. Have only one ctlvp per client, as opposed to one per mounted cfs device.d 16638625Srvb * 3. Allow ody_expand to return many members, not just one. 16738625Srvb * 16838625Srvb * Revision 2.5 94/11/09 20:29:27 dcs 16938625Srvb * Small bug in remove dealing with hard links and link counts was fixed. 17038625Srvb * 17138625Srvb * Revision 2.4 94/10/14 09:58:42 dcs 17238625Srvb * Made changes 'cause sun4s have braindead compilers 17338625Srvb * 17438625Srvb * Revision 2.3 94/10/12 16:46:37 dcs 17538625Srvb * Cleaned kernel/venus interface by removing XDR junk, plus 17638625Srvb * so cleanup to allow this code to be more easily ported. 17738625Srvb * 17838625Srvb * Revision 2.2 94/09/20 14:12:41 dcs 17938625Srvb * Fixed bug in rename when moving a directory. 18038625Srvb * 18138625Srvb * Revision 2.1 94/07/21 16:25:22 satya 18238625Srvb * Conversion to C++ 3.0; start of Coda Release 2.0 18338625Srvb * 18438625Srvb * Revision 1.4 93/12/17 01:38:01 luqi 18538625Srvb * Changes made for kernel to pass process info to Venus: 18638625Srvb * 18738625Srvb * (1) in file cfs.h 18838625Srvb * add process id and process group id in most of the cfs argument types. 18938625Srvb * 19038625Srvb * (2) in file cfs_vnodeops.c 19138625Srvb * add process info passing in most of the cfs vnode operations. 19238625Srvb * 19338625Srvb * (3) in file cfs_xdr.c 19438625Srvb * expand xdr routines according changes in (1). 19538625Srvb * add variable pass_process_info to allow venus for kernel version checking. 19638625Srvb * 19738625Srvb * Revision 1.3 93/05/28 16:24:33 bnoble 19838625Srvb * *** empty log message *** 19938625Srvb * 20038625Srvb * Revision 1.2 92/10/27 17:58:25 lily 20138625Srvb * merge kernel/latest and alpha/src/cfs 20238625Srvb * 20338625Srvb * Revision 2.4 92/09/30 14:16:37 mja 20438625Srvb * Redid buffer allocation so that it does kmem_{alloc,free} for all 20538625Srvb * architectures. Zone allocation, previously used on the 386, caused 20638625Srvb * panics if it was invoked repeatedly. Stack allocation, previously 20738625Srvb * used on all other architectures, tickled some Mach bug that appeared 20838625Srvb * with large stack frames. 20938625Srvb * [91/02/09 jjk] 21038625Srvb * 21138625Srvb * Added contributors blurb. 21238625Srvb * [90/12/13 jjk] 21338625Srvb * 21438625Srvb * Revision 2.3 90/07/26 15:50:09 mrt 21538625Srvb * Fixed fix to rename to remove .. from moved directories. 21638625Srvb * [90/06/28 dcs] 21738625Srvb * 21838625Srvb * Revision 1.7 90/06/28 16:24:25 dcs 21938625Srvb * Fixed bug with moving directories, we weren't flushing .. for the moved directory. 22038625Srvb * 22138625Srvb * Revision 1.6 90/05/31 17:01:47 dcs 22238625Srvb * Prepare for merge with facilities kernel. 22338625Srvb * 22438625Srvb * 22538625Srvb */ 22638625Srvb 22738625Srvb#include <sys/param.h> 22838625Srvb#include <sys/systm.h> 22938759Srvb#include <sys/kernel.h> 23038759Srvb#include <sys/proc.h> 23138625Srvb#include <sys/malloc.h> 23238759Srvb#include <sys/mount.h> 23338625Srvb#include <sys/errno.h> 23438625Srvb#include <sys/acct.h> 23538625Srvb#include <sys/file.h> 23638759Srvb#include <sys/fcntl.h> 23738625Srvb#include <sys/uio.h> 23838625Srvb#include <sys/namei.h> 23938625Srvb#include <sys/ioccom.h> 24038625Srvb#include <sys/select.h> 24138759Srvb 24238625Srvb#include <vm/vm.h> 24338625Srvb#include <vm/vm_object.h> 24438625Srvb#include <vm/vm_extern.h> 24538759Srvb#include <vm/vm_zone.h> 24638625Srvb 24739126Srvb#include <coda/coda.h> 24839126Srvb#include <coda/cnode.h> 24939126Srvb#include <coda/coda_vnops.h> 25039126Srvb#include <coda/coda_venus.h> 25139126Srvb#include <coda/coda_opstats.h> 25239126Srvb#include <coda/coda_subr.h> 25339126Srvb#include <coda/coda_namecache.h> 25439126Srvb#include <coda/coda_pioctl.h> 25538625Srvb 25638625Srvb/* 25738625Srvb * These flags select various performance enhancements. 25838625Srvb */ 25939085Srvbint coda_attr_cache = 1; /* Set to cache attributes in the kernel */ 26039085Srvbint coda_symlink_cache = 1; /* Set to cache symbolic link information */ 26139085Srvbint coda_access_cache = 1; /* Set to handle some access checks directly */ 26238625Srvb 26338625Srvb/* structure to keep track of vfs calls */ 26438625Srvb 26539085Srvbstruct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE]; 26638625Srvb 26739085Srvb#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++) 26839085Srvb#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++) 26939085Srvb#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++) 27039085Srvb#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++) 27138625Srvb 27238625Srvb/* What we are delaying for in printf */ 27339085Srvbint coda_printf_delay = 0; /* in microseconds */ 27439085Srvbint coda_vnop_print_entry = 0; 27539085Srvbstatic int coda_lockdebug = 0; 27638625Srvb 27738625Srvb/* Definition of the vfs operation vector */ 27838625Srvb 27938625Srvb/* 28038625Srvb * Some NetBSD details: 28138625Srvb * 28239085Srvb * coda_start is called at the end of the mount syscall. 28339085Srvb * coda_init is called at boot time. 28438625Srvb */ 28538625Srvb 28639085Srvb#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__)) 28738625Srvb 28838625Srvb/* Definition of the vnode operation vector */ 28938625Srvb 29039085Srvbstruct vnodeopv_entry_desc coda_vnodeop_entries[] = { 29139085Srvb { &vop_default_desc, coda_vop_error }, 29239085Srvb { &vop_lookup_desc, coda_lookup }, /* lookup */ 29339085Srvb { &vop_create_desc, coda_create }, /* create */ 29439085Srvb { &vop_mknod_desc, coda_vop_error }, /* mknod */ 29539085Srvb { &vop_open_desc, coda_open }, /* open */ 29639085Srvb { &vop_close_desc, coda_close }, /* close */ 29739085Srvb { &vop_access_desc, coda_access }, /* access */ 29839085Srvb { &vop_getattr_desc, coda_getattr }, /* getattr */ 29939085Srvb { &vop_setattr_desc, coda_setattr }, /* setattr */ 30039085Srvb { &vop_read_desc, coda_read }, /* read */ 30139085Srvb { &vop_write_desc, coda_write }, /* write */ 30239085Srvb { &vop_ioctl_desc, coda_ioctl }, /* ioctl */ 30339085Srvb { &vop_mmap_desc, coda_vop_error }, /* mmap */ 30439085Srvb { &vop_fsync_desc, coda_fsync }, /* fsync */ 30539085Srvb { &vop_remove_desc, coda_remove }, /* remove */ 30639085Srvb { &vop_link_desc, coda_link }, /* link */ 30739085Srvb { &vop_rename_desc, coda_rename }, /* rename */ 30839085Srvb { &vop_mkdir_desc, coda_mkdir }, /* mkdir */ 30939085Srvb { &vop_rmdir_desc, coda_rmdir }, /* rmdir */ 31039085Srvb { &vop_symlink_desc, coda_symlink }, /* symlink */ 31139085Srvb { &vop_readdir_desc, coda_readdir }, /* readdir */ 31239085Srvb { &vop_readlink_desc, coda_readlink }, /* readlink */ 31339085Srvb { &vop_abortop_desc, coda_abortop }, /* abortop */ 31439085Srvb { &vop_inactive_desc, coda_inactive }, /* inactive */ 31539085Srvb { &vop_reclaim_desc, coda_reclaim }, /* reclaim */ 31639085Srvb { &vop_lock_desc, coda_lock }, /* lock */ 31739085Srvb { &vop_unlock_desc, coda_unlock }, /* unlock */ 31839085Srvb { &vop_bmap_desc, coda_bmap }, /* bmap */ 31939085Srvb { &vop_strategy_desc, coda_strategy }, /* strategy */ 32039085Srvb { &vop_print_desc, coda_vop_error }, /* print */ 32139085Srvb { &vop_islocked_desc, coda_islocked }, /* islocked */ 32239085Srvb { &vop_pathconf_desc, coda_vop_error }, /* pathconf */ 32339085Srvb { &vop_advlock_desc, coda_vop_nop }, /* advlock */ 32439085Srvb { &vop_bwrite_desc, coda_vop_error }, /* bwrite */ 32539085Srvb { &vop_lease_desc, coda_vop_nop }, /* lease */ 32638759Srvb { &vop_poll_desc, (vop_t *) vop_stdpoll }, 32739085Srvb { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/ 32839085Srvb { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/ 32938625Srvb 33038759Srvb#if 0 33138625Srvb 33238759Srvb we need to define these someday 33338625Srvb#define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd) 33438625Srvb#define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd) 33538625Srvb#define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc) 33638625Srvb#define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee) 33738625Srvb#define UFS_UPDATE(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_update(aa, bb, cc, dd) 33838625Srvb 33938625Srvb missing 34038625Srvb { &vop_reallocblks_desc, (vop_t *) ufs_missingop }, 34138625Srvb { &vop_cachedlookup_desc, (vop_t *) ufs_lookup }, 34238625Srvb { &vop_whiteout_desc, (vop_t *) ufs_whiteout }, 34338625Srvb#endif 34438625Srvb { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL } 34538625Srvb}; 34638625Srvb 34739085Srvbstatic struct vnodeopv_desc coda_vnodeop_opv_desc = 34839085Srvb { &coda_vnodeop_p, coda_vnodeop_entries }; 34938625Srvb 35039085SrvbVNODEOP_SET(coda_vnodeop_opv_desc); 35138625Srvb 35238625Srvb/* A generic panic: we were called with something we didn't define yet */ 35338625Srvbint 35439085Srvbcoda_vop_error(void *anon) { 35538625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 35638625Srvb 35738625Srvb myprintf(("Vnode operation %s called, but not defined\n", 35838625Srvb (*desc)->vdesc_name)); 35939085Srvb panic("coda_vop_error"); 36038625Srvb return 0; 36138625Srvb} 36238625Srvb 36338625Srvb/* A generic do-nothing. For lease_check, advlock */ 36438625Srvbint 36539085Srvbcoda_vop_nop(void *anon) { 36638625Srvb struct vnodeop_desc **desc = (struct vnodeop_desc **)anon; 36738625Srvb 36839085Srvb if (codadebug) { 36938625Srvb myprintf(("Vnode operation %s called, but unsupported\n", 37038625Srvb (*desc)->vdesc_name)); 37138625Srvb } 37238625Srvb return (0); 37338625Srvb} 37438625Srvb 37538625Srvbint 37639085Srvbcoda_vnodeopstats_init(void) 37738625Srvb{ 37838625Srvb register int i; 37938625Srvb 38039085Srvb for(i=0;i<CODA_VNODEOPS_SIZE;i++) { 38139085Srvb coda_vnodeopstats[i].opcode = i; 38239085Srvb coda_vnodeopstats[i].entries = 0; 38339085Srvb coda_vnodeopstats[i].sat_intrn = 0; 38439085Srvb coda_vnodeopstats[i].unsat_intrn = 0; 38539085Srvb coda_vnodeopstats[i].gen_intrn = 0; 38638625Srvb } 38738625Srvb return 0; 38838625Srvb} 38938625Srvb 39038625Srvb/* 39139085Srvb * coda_open calls Venus to return the device, inode pair of the cache 39239085Srvb * file holding the data. Using iget, coda_open finds the vnode of the 39338625Srvb * cache file, and then opens it. 39438625Srvb */ 39538625Srvbint 39639085Srvbcoda_open(v) 39738625Srvb void *v; 39838625Srvb{ 39938625Srvb /* 40038625Srvb * NetBSD can pass the O_EXCL flag in mode, even though the check 40138625Srvb * has already happened. Venus defensively assumes that if open 40238625Srvb * is passed the EXCL, it must be a bug. We strip the flag here. 40338625Srvb */ 40438625Srvb/* true args */ 40538625Srvb struct vop_open_args *ap = v; 40638625Srvb register struct vnode **vpp = &(ap->a_vp); 40738625Srvb struct cnode *cp = VTOC(*vpp); 40838625Srvb int flag = ap->a_mode & (~O_EXCL); 40938625Srvb struct ucred *cred = ap->a_cred; 41038625Srvb struct proc *p = ap->a_p; 41138625Srvb/* locals */ 41238625Srvb int error; 41338625Srvb struct vnode *vp; 41438625Srvb dev_t dev; 41538625Srvb ino_t inode; 41638625Srvb 41739085Srvb MARK_ENTRY(CODA_OPEN_STATS); 41838625Srvb 41938625Srvb /* Check for open of control file. */ 42038625Srvb if (IS_CTL_VP(*vpp)) { 42138625Srvb /* XXX */ 42238625Srvb /* if (WRITEABLE(flag)) */ 42338625Srvb if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) { 42439085Srvb MARK_INT_FAIL(CODA_OPEN_STATS); 42538625Srvb return(EACCES); 42638625Srvb } 42739085Srvb MARK_INT_SAT(CODA_OPEN_STATS); 42838625Srvb return(0); 42938625Srvb } 43038625Srvb 43138625Srvb error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, p, &dev, &inode); 43238625Srvb if (error) 43338625Srvb return (error); 43438625Srvb if (!error) { 43539085Srvb CODADEBUG( CODA_OPEN,myprintf(("open: dev %d inode %d result %d\n", 43638625Srvb dev, inode, error)); ) 43738625Srvb } 43838625Srvb 43938625Srvb /* Translate the <device, inode> pair for the cache file into 44038625Srvb an inode pointer. */ 44139085Srvb error = coda_grab_vnode(dev, inode, &vp); 44238625Srvb if (error) 44338625Srvb return (error); 44438625Srvb 44538759Srvb /* We get the vnode back locked. Needs unlocked */ 44638759Srvb VOP_UNLOCK(vp, 0, p); 44738625Srvb /* Keep a reference until the close comes in. */ 44838625Srvb vref(*vpp); 44938625Srvb 45038625Srvb /* Save the vnode pointer for the cache file. */ 45138625Srvb if (cp->c_ovp == NULL) { 45238625Srvb cp->c_ovp = vp; 45338625Srvb } else { 45438625Srvb if (cp->c_ovp != vp) 45539085Srvb panic("coda_open: cp->c_ovp != ITOV(ip)"); 45638625Srvb } 45738625Srvb cp->c_ocount++; 45838625Srvb 45938625Srvb /* Flush the attribute cached if writing the file. */ 46038625Srvb if (flag & FWRITE) { 46138625Srvb cp->c_owrite++; 46238625Srvb cp->c_flags &= ~C_VATTR; 46338625Srvb } 46438625Srvb 46538625Srvb /* Save the <device, inode> pair for the cache file to speed 46638625Srvb up subsequent page_read's. */ 46738625Srvb cp->c_device = dev; 46838625Srvb cp->c_inode = inode; 46938625Srvb 47038625Srvb /* Open the cache file. */ 47138625Srvb error = VOP_OPEN(vp, flag, cred, p); 47238625Srvb if (error) { 47339085Srvb printf("coda_open: VOP_OPEN on container failed %d\n", error); 47438625Srvb return (error); 47538625Srvb } 47638625Srvb if (vp->v_type == VREG) { 47738625Srvb error = vfs_object_create(vp, p, cred, 1); 47838625Srvb if (error != 0) { 47939085Srvb printf("coda_open: vfs_object_create() returns %d\n", error); 48038625Srvb vput(vp); 48138625Srvb } 48238625Srvb } 48338625Srvb return(error); 48438625Srvb} 48538625Srvb 48638625Srvb/* 48738625Srvb * Close the cache file used for I/O and notify Venus. 48838625Srvb */ 48938625Srvbint 49039085Srvbcoda_close(v) 49138625Srvb void *v; 49238625Srvb{ 49338625Srvb/* true args */ 49438625Srvb struct vop_close_args *ap = v; 49538625Srvb struct vnode *vp = ap->a_vp; 49638625Srvb struct cnode *cp = VTOC(vp); 49738625Srvb int flag = ap->a_fflag; 49838625Srvb struct ucred *cred = ap->a_cred; 49938625Srvb struct proc *p = ap->a_p; 50038625Srvb/* locals */ 50138625Srvb int error; 50238625Srvb 50339085Srvb MARK_ENTRY(CODA_CLOSE_STATS); 50438625Srvb 50538625Srvb /* Check for close of control file. */ 50638625Srvb if (IS_CTL_VP(vp)) { 50739085Srvb MARK_INT_SAT(CODA_CLOSE_STATS); 50838625Srvb return(0); 50938625Srvb } 51038625Srvb 51138625Srvb if (IS_UNMOUNTING(cp)) { 51238625Srvb if (cp->c_ovp) { 51339085Srvb printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n", 51438625Srvb vp->v_usecount, cp->c_ovp, vp, cp); 51538625Srvb vgone(cp->c_ovp); 51638625Srvb } else { 51739085Srvb printf("coda_close: NO container vp %p/cp %p\n", vp, cp); 51838625Srvb } 51938625Srvb return ENODEV; 52038625Srvb } else { 52138625Srvb VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */ 52238625Srvb vrele(cp->c_ovp); 52338625Srvb } 52438625Srvb 52538625Srvb if (--cp->c_ocount == 0) 52638625Srvb cp->c_ovp = NULL; 52738625Srvb 52838625Srvb if (flag & FWRITE) /* file was opened for write */ 52938625Srvb --cp->c_owrite; 53038625Srvb 53138625Srvb error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, p); 53238625Srvb vrele(CTOV(cp)); 53338625Srvb 53439085Srvb CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); ) 53538625Srvb return(error); 53638625Srvb} 53738625Srvb 53838625Srvbint 53939085Srvbcoda_read(v) 54038625Srvb void *v; 54138625Srvb{ 54238625Srvb struct vop_read_args *ap = v; 54338625Srvb 54438625Srvb ENTRY; 54539085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ, 54638625Srvb ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp)); 54738625Srvb} 54838625Srvb 54938625Srvbint 55039085Srvbcoda_write(v) 55138625Srvb void *v; 55238625Srvb{ 55338625Srvb struct vop_write_args *ap = v; 55438625Srvb 55538625Srvb ENTRY; 55639085Srvb return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE, 55738625Srvb ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp)); 55838625Srvb} 55938625Srvb 56038625Srvbint 56139085Srvbcoda_rdwr(vp, uiop, rw, ioflag, cred, p) 56238625Srvb struct vnode *vp; 56338625Srvb struct uio *uiop; 56438625Srvb enum uio_rw rw; 56538625Srvb int ioflag; 56638625Srvb struct ucred *cred; 56738625Srvb struct proc *p; 56838625Srvb{ 56938625Srvb/* upcall decl */ 57038625Srvb /* NOTE: container file operation!!! */ 57138625Srvb/* locals */ 57238625Srvb struct cnode *cp = VTOC(vp); 57338625Srvb struct vnode *cfvp = cp->c_ovp; 57438625Srvb int igot_internally = 0; 57538625Srvb int opened_internally = 0; 57638625Srvb int error = 0; 57738625Srvb 57839085Srvb MARK_ENTRY(CODA_RDWR_STATS); 57938625Srvb 58039085Srvb CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %qd, %d)\n", rw, 58138625Srvb uiop->uio_iov->iov_base, uiop->uio_resid, 58238625Srvb uiop->uio_offset, uiop->uio_segflg)); ) 58338625Srvb 58438625Srvb /* Check for rdwr of control object. */ 58538625Srvb if (IS_CTL_VP(vp)) { 58639085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 58738625Srvb return(EINVAL); 58838625Srvb } 58938625Srvb 59038625Srvb /* 59138625Srvb * If file is not already open this must be a page 59238625Srvb * {read,write} request. Iget the cache file's inode 59338625Srvb * pointer if we still have its <device, inode> pair. 59438625Srvb * Otherwise, we must do an internal open to derive the 59538625Srvb * pair. 59638625Srvb */ 59738625Srvb if (cfvp == NULL) { 59838625Srvb /* 59938625Srvb * If we're dumping core, do the internal open. Otherwise 60038625Srvb * venus won't have the correct size of the core when 60138625Srvb * it's completely written. 60238625Srvb */ 60338625Srvb if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) { 60438625Srvb igot_internally = 1; 60539085Srvb error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp); 60638625Srvb if (error) { 60739085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 60838625Srvb return(error); 60938625Srvb } 61038625Srvb /* 61138625Srvb * We get the vnode back locked in both Mach and 61238625Srvb * NetBSD. Needs unlocked 61338625Srvb */ 61438759Srvb VOP_UNLOCK(cfvp, 0, p); 61538625Srvb } 61638625Srvb else { 61738625Srvb opened_internally = 1; 61839085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 61938625Srvb error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), 62038625Srvb cred, p); 62139085Srvbprintf("coda_rdwr: Internally Opening %p\n", vp); 62238625Srvb if (error) { 62339085Srvb printf("coda_rdwr: VOP_OPEN on container failed %d\n", error); 62438625Srvb return (error); 62538625Srvb } 62638625Srvb if (vp->v_type == VREG) { 62738625Srvb error = vfs_object_create(vp, p, cred, 1); 62838625Srvb if (error != 0) { 62939085Srvb printf("coda_rdwr: vfs_object_create() returns %d\n", error); 63038625Srvb vput(vp); 63138625Srvb } 63238625Srvb } 63338625Srvb if (error) { 63439085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 63538625Srvb return(error); 63638625Srvb } 63738625Srvb cfvp = cp->c_ovp; 63838625Srvb } 63938625Srvb } 64038625Srvb 64138625Srvb /* Have UFS handle the call. */ 64239085Srvb CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n", 64338625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 64438625Srvb cp->c_fid.Unique, CTOV(cp)->v_usecount)); ) 64538625Srvb 64638625Srvb if (rw == UIO_READ) { 64738625Srvb error = VOP_READ(cfvp, uiop, ioflag, cred); 64838625Srvb } else { 64938625Srvb error = VOP_WRITE(cfvp, uiop, ioflag, cred); 65038625Srvb /* ufs_write updates the vnode_pager_setsize for the vnode/object */ 65138625Srvb { struct vattr attr; 65238625Srvb 65338625Srvb if (VOP_GETATTR(cfvp, &attr, cred, p) == 0) { 65438625Srvb vnode_pager_setsize(vp, attr.va_size); 65538625Srvb } 65638625Srvb } 65738625Srvb } 65838625Srvb 65938625Srvb if (error) 66039085Srvb MARK_INT_FAIL(CODA_RDWR_STATS); 66138625Srvb else 66239085Srvb MARK_INT_SAT(CODA_RDWR_STATS); 66338625Srvb 66438625Srvb /* Do an internal close if necessary. */ 66538625Srvb if (opened_internally) { 66639085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 66738625Srvb (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, p); 66838625Srvb } 66938625Srvb 67038625Srvb /* Invalidate cached attributes if writing. */ 67138625Srvb if (rw == UIO_WRITE) 67238625Srvb cp->c_flags &= ~C_VATTR; 67338625Srvb return(error); 67438625Srvb} 67538625Srvb 67638625Srvbint 67739085Srvbcoda_ioctl(v) 67838625Srvb void *v; 67938625Srvb{ 68038625Srvb/* true args */ 68138625Srvb struct vop_ioctl_args *ap = v; 68238625Srvb struct vnode *vp = ap->a_vp; 68338625Srvb int com = ap->a_command; 68438625Srvb caddr_t data = ap->a_data; 68538625Srvb int flag = ap->a_fflag; 68638625Srvb struct ucred *cred = ap->a_cred; 68738625Srvb struct proc *p = ap->a_p; 68838625Srvb/* locals */ 68938625Srvb int error; 69038625Srvb struct vnode *tvp; 69138625Srvb struct nameidata ndp; 69238625Srvb struct PioctlData *iap = (struct PioctlData *)data; 69338625Srvb 69439085Srvb MARK_ENTRY(CODA_IOCTL_STATS); 69538625Srvb 69639085Srvb CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));) 69738625Srvb 69838625Srvb /* Don't check for operation on a dying object, for ctlvp it 69938625Srvb shouldn't matter */ 70038625Srvb 70138625Srvb /* Must be control object to succeed. */ 70238625Srvb if (!IS_CTL_VP(vp)) { 70339085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 70439085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));) 70538625Srvb return (EOPNOTSUPP); 70638625Srvb } 70738625Srvb /* Look up the pathname. */ 70838625Srvb 70938625Srvb /* Should we use the name cache here? It would get it from 71038625Srvb lookupname sooner or later anyway, right? */ 71138625Srvb 71238625Srvb NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, ((caddr_t)iap->path), p); 71338625Srvb error = namei(&ndp); 71438625Srvb tvp = ndp.ni_vp; 71538625Srvb 71638625Srvb if (error) { 71739085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 71839085Srvb CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n", 71938625Srvb error));) 72038625Srvb return(error); 72138625Srvb } 72238625Srvb 72338625Srvb /* 72438625Srvb * Make sure this is a coda style cnode, but it may be a 72538625Srvb * different vfsp 72638625Srvb */ 72738625Srvb /* XXX: this totally violates the comment about vtagtype in vnode.h */ 72839085Srvb if (tvp->v_tag != VT_CODA) { 72938625Srvb vrele(tvp); 73039085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 73139085Srvb CODADEBUG(CODA_IOCTL, 73239085Srvb myprintf(("coda_ioctl error: %s not a coda object\n", 73338625Srvb iap->path));) 73438625Srvb return(EINVAL); 73538625Srvb } 73638625Srvb 73738625Srvb if (iap->vi.in_size > VC_MAXDATASIZE) { 73838625Srvb vrele(tvp); 73938625Srvb return(EINVAL); 74038625Srvb } 74138625Srvb error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, p); 74238625Srvb 74338625Srvb if (error) 74439085Srvb MARK_INT_FAIL(CODA_IOCTL_STATS); 74538625Srvb else 74639085Srvb CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); ) 74738625Srvb 74838625Srvb vrele(tvp); 74938625Srvb return(error); 75038625Srvb} 75138625Srvb 75238625Srvb/* 75338625Srvb * To reduce the cost of a user-level venus;we cache attributes in 75438625Srvb * the kernel. Each cnode has storage allocated for an attribute. If 75538625Srvb * c_vattr is valid, return a reference to it. Otherwise, get the 75638625Srvb * attributes from venus and store them in the cnode. There is some 75738625Srvb * question if this method is a security leak. But I think that in 75838625Srvb * order to make this call, the user must have done a lookup and 75938625Srvb * opened the file, and therefore should already have access. 76038625Srvb */ 76138625Srvbint 76239085Srvbcoda_getattr(v) 76338625Srvb void *v; 76438625Srvb{ 76538625Srvb/* true args */ 76638625Srvb struct vop_getattr_args *ap = v; 76738625Srvb struct vnode *vp = ap->a_vp; 76838625Srvb struct cnode *cp = VTOC(vp); 76938625Srvb struct vattr *vap = ap->a_vap; 77038625Srvb struct ucred *cred = ap->a_cred; 77138625Srvb struct proc *p = ap->a_p; 77238625Srvb/* locals */ 77338625Srvb int error; 77438625Srvb 77539085Srvb MARK_ENTRY(CODA_GETATTR_STATS); 77638625Srvb 77738625Srvb if (IS_UNMOUNTING(cp)) 77838625Srvb return ENODEV; 77938759Srvb 78038625Srvb /* Check for getattr of control object. */ 78138625Srvb if (IS_CTL_VP(vp)) { 78239085Srvb MARK_INT_FAIL(CODA_GETATTR_STATS); 78338625Srvb return(ENOENT); 78438625Srvb } 78538625Srvb 78638625Srvb /* Check to see if the attributes have already been cached */ 78738625Srvb if (VALID_VATTR(cp)) { 78839085Srvb CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n", 78938625Srvb cp->c_fid.Volume, 79038625Srvb cp->c_fid.Vnode, 79138625Srvb cp->c_fid.Unique));}); 79239085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 79338625Srvb print_vattr(&cp->c_vattr); ); 79438625Srvb 79538625Srvb *vap = cp->c_vattr; 79639085Srvb MARK_INT_SAT(CODA_GETATTR_STATS); 79738625Srvb return(0); 79838625Srvb } 79938625Srvb 80038625Srvb error = venus_getattr(vtomi(vp), &cp->c_fid, cred, p, vap); 80138625Srvb 80238625Srvb if (!error) { 80339085Srvb CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n", 80438625Srvb cp->c_fid.Volume, 80538625Srvb cp->c_fid.Vnode, 80638625Srvb cp->c_fid.Unique, 80738625Srvb error)); ) 80838625Srvb 80939085Srvb CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR)) 81038625Srvb print_vattr(vap); ); 81138625Srvb 81238625Srvb { int size = vap->va_size; 81338625Srvb struct vnode *convp = cp->c_ovp; 81438625Srvb if (convp != (struct vnode *)0) { 81538625Srvb vnode_pager_setsize(convp, size); 81638625Srvb } 81738625Srvb } 81838625Srvb /* If not open for write, store attributes in cnode */ 81939085Srvb if ((cp->c_owrite == 0) && (coda_attr_cache)) { 82038625Srvb cp->c_vattr = *vap; 82138625Srvb cp->c_flags |= C_VATTR; 82238625Srvb } 82338625Srvb 82438625Srvb } 82538625Srvb return(error); 82638625Srvb} 82738625Srvb 82838625Srvbint 82939085Srvbcoda_setattr(v) 83038625Srvb void *v; 83138625Srvb{ 83238625Srvb/* true args */ 83338625Srvb struct vop_setattr_args *ap = v; 83438625Srvb register struct vnode *vp = ap->a_vp; 83538625Srvb struct cnode *cp = VTOC(vp); 83638625Srvb register struct vattr *vap = ap->a_vap; 83738625Srvb struct ucred *cred = ap->a_cred; 83838625Srvb struct proc *p = ap->a_p; 83938625Srvb/* locals */ 84038625Srvb int error; 84138625Srvb 84239085Srvb MARK_ENTRY(CODA_SETATTR_STATS); 84338625Srvb 84438625Srvb /* Check for setattr of control object. */ 84538625Srvb if (IS_CTL_VP(vp)) { 84639085Srvb MARK_INT_FAIL(CODA_SETATTR_STATS); 84738625Srvb return(ENOENT); 84838625Srvb } 84938625Srvb 85039085Srvb if (codadebug & CODADBGMSK(CODA_SETATTR)) { 85138625Srvb print_vattr(vap); 85238625Srvb } 85338625Srvb error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, p); 85438625Srvb 85538625Srvb if (!error) 85638625Srvb cp->c_flags &= ~C_VATTR; 85738625Srvb 85838625Srvb { int size = vap->va_size; 85938625Srvb struct vnode *convp = cp->c_ovp; 86038625Srvb if (size != VNOVAL && convp != (struct vnode *)0) { 86138625Srvb vnode_pager_setsize(convp, size); 86238625Srvb } 86338625Srvb } 86439085Srvb CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); ) 86538625Srvb return(error); 86638625Srvb} 86738625Srvb 86838625Srvbint 86939085Srvbcoda_access(v) 87038625Srvb void *v; 87138625Srvb{ 87238625Srvb/* true args */ 87338625Srvb struct vop_access_args *ap = v; 87438625Srvb struct vnode *vp = ap->a_vp; 87538625Srvb struct cnode *cp = VTOC(vp); 87638625Srvb int mode = ap->a_mode; 87738625Srvb struct ucred *cred = ap->a_cred; 87838625Srvb struct proc *p = ap->a_p; 87938625Srvb/* locals */ 88038625Srvb int error; 88138625Srvb 88239085Srvb MARK_ENTRY(CODA_ACCESS_STATS); 88338625Srvb 88438625Srvb /* Check for access of control object. Only read access is 88538625Srvb allowed on it. */ 88638625Srvb if (IS_CTL_VP(vp)) { 88738625Srvb /* bogus hack - all will be marked as successes */ 88839085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 88938625Srvb return(((mode & VREAD) && !(mode & (VWRITE | VEXEC))) 89038625Srvb ? 0 : EACCES); 89138625Srvb } 89238625Srvb 89338625Srvb /* 89438625Srvb * if the file is a directory, and we are checking exec (eg lookup) 89538625Srvb * access, and the file is in the namecache, then the user must have 89638625Srvb * lookup access to it. 89738625Srvb */ 89839085Srvb if (coda_access_cache) { 89938625Srvb if ((vp->v_type == VDIR) && (mode & VEXEC)) { 90039085Srvb if (coda_nc_lookup(cp, ".", 1, cred)) { 90139085Srvb MARK_INT_SAT(CODA_ACCESS_STATS); 90238625Srvb return(0); /* it was in the cache */ 90338625Srvb } 90438625Srvb } 90538625Srvb } 90638625Srvb 90738625Srvb error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, p); 90838625Srvb 90938625Srvb return(error); 91038625Srvb} 91138625Srvb 91238625Srvb/* 91339085Srvb * CODA abort op, called after namei() when a CREATE/DELETE isn't actually 91439085Srvb * done. If a buffer has been saved in anticipation of a coda_create or 91539085Srvb * a coda_remove, delete it. 91638625Srvb */ 91738625Srvb/* ARGSUSED */ 91838625Srvbint 91939085Srvbcoda_abortop(v) 92038625Srvb void *v; 92138625Srvb{ 92238625Srvb/* true args */ 92338625Srvb struct vop_abortop_args /* { 92438625Srvb struct vnode *a_dvp; 92538625Srvb struct componentname *a_cnp; 92638625Srvb } */ *ap = v; 92738625Srvb/* upcall decl */ 92838625Srvb/* locals */ 92938625Srvb 93038625Srvb if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF) 93138759Srvb zfree(namei_zone, ap->a_cnp->cn_pnbuf); 93238625Srvb return (0); 93338625Srvb} 93438625Srvb 93538625Srvbint 93639085Srvbcoda_readlink(v) 93738625Srvb void *v; 93838625Srvb{ 93938625Srvb/* true args */ 94038625Srvb struct vop_readlink_args *ap = v; 94138625Srvb struct vnode *vp = ap->a_vp; 94238625Srvb struct cnode *cp = VTOC(vp); 94338625Srvb struct uio *uiop = ap->a_uio; 94438625Srvb struct ucred *cred = ap->a_cred; 94538625Srvb struct proc *p = ap->a_uio->uio_procp; 94638625Srvb/* locals */ 94738625Srvb int error; 94838625Srvb char *str; 94938625Srvb int len; 95038625Srvb 95139085Srvb MARK_ENTRY(CODA_READLINK_STATS); 95238625Srvb 95338625Srvb /* Check for readlink of control object. */ 95438625Srvb if (IS_CTL_VP(vp)) { 95539085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 95638625Srvb return(ENOENT); 95738625Srvb } 95838625Srvb 95939085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */ 96038625Srvb uiop->uio_rw = UIO_READ; 96138625Srvb error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop); 96238625Srvb if (error) 96339085Srvb MARK_INT_FAIL(CODA_READLINK_STATS); 96438625Srvb else 96539085Srvb MARK_INT_SAT(CODA_READLINK_STATS); 96638625Srvb return(error); 96738625Srvb } 96838625Srvb 96938625Srvb error = venus_readlink(vtomi(vp), &cp->c_fid, cred, p, &str, &len); 97038625Srvb 97138625Srvb if (!error) { 97238625Srvb uiop->uio_rw = UIO_READ; 97338625Srvb error = uiomove(str, len, uiop); 97438625Srvb 97539085Srvb if (coda_symlink_cache) { 97638625Srvb cp->c_symlink = str; 97738625Srvb cp->c_symlen = len; 97838625Srvb cp->c_flags |= C_SYMLINK; 97938625Srvb } else 98039085Srvb CODA_FREE(str, len); 98138625Srvb } 98238625Srvb 98339085Srvb CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));) 98438625Srvb return(error); 98538625Srvb} 98638625Srvb 98738625Srvbint 98839085Srvbcoda_fsync(v) 98938625Srvb void *v; 99038625Srvb{ 99138625Srvb/* true args */ 99238625Srvb struct vop_fsync_args *ap = v; 99338625Srvb struct vnode *vp = ap->a_vp; 99438625Srvb struct cnode *cp = VTOC(vp); 99538625Srvb struct ucred *cred = ap->a_cred; 99638625Srvb struct proc *p = ap->a_p; 99738625Srvb/* locals */ 99838625Srvb struct vnode *convp = cp->c_ovp; 99938625Srvb int error; 100038625Srvb 100139085Srvb MARK_ENTRY(CODA_FSYNC_STATS); 100238625Srvb 100338625Srvb /* Check for fsync on an unmounting object */ 100438625Srvb /* The NetBSD kernel, in it's infinite wisdom, can try to fsync 100538625Srvb * after an unmount has been initiated. This is a Bad Thing, 100638625Srvb * which we have to avoid. Not a legitimate failure for stats. 100738625Srvb */ 100838625Srvb if (IS_UNMOUNTING(cp)) { 100938625Srvb return(ENODEV); 101038625Srvb } 101138625Srvb 101238625Srvb /* Check for fsync of control object. */ 101338625Srvb if (IS_CTL_VP(vp)) { 101439085Srvb MARK_INT_SAT(CODA_FSYNC_STATS); 101538625Srvb return(0); 101638625Srvb } 101738625Srvb 101838625Srvb if (convp) 101938625Srvb VOP_FSYNC(convp, cred, MNT_WAIT, p); 102038625Srvb 102138625Srvb /* 102238625Srvb * We see fsyncs with usecount == 1 then usecount == 0. 102338625Srvb * For now we ignore them. 102438625Srvb */ 102538625Srvb /* 102638625Srvb if (!vp->v_usecount) { 102739085Srvb printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n", 102838625Srvb vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING); 102938625Srvb } 103038625Srvb */ 103138625Srvb 103238625Srvb /* 103338625Srvb * We can expect fsync on any vnode at all if venus is pruging it. 103438625Srvb * Venus can't very well answer the fsync request, now can it? 103538625Srvb * Hopefully, it won't have to, because hopefully, venus preserves 103638625Srvb * the (possibly untrue) invariant that it never purges an open 103738625Srvb * vnode. Hopefully. 103838625Srvb */ 103938625Srvb if (cp->c_flags & C_PURGING) { 104038625Srvb return(0); 104138625Srvb } 104238625Srvb 104338625Srvb /* needs research */ 104438625Srvb return 0; 104538625Srvb error = venus_fsync(vtomi(vp), &cp->c_fid, cred, p); 104638625Srvb 104739085Srvb CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); ); 104838625Srvb return(error); 104938625Srvb} 105038625Srvb 105138625Srvbint 105239085Srvbcoda_inactive(v) 105338625Srvb void *v; 105438625Srvb{ 105538625Srvb /* XXX - at the moment, inactive doesn't look at cred, and doesn't 105638625Srvb have a proc pointer. Oops. */ 105738625Srvb/* true args */ 105838625Srvb struct vop_inactive_args *ap = v; 105938625Srvb struct vnode *vp = ap->a_vp; 106038625Srvb struct cnode *cp = VTOC(vp); 106138625Srvb struct ucred *cred __attribute__((unused)) = NULL; 106238625Srvb struct proc *p __attribute__((unused)) = curproc; 106338625Srvb/* upcall decl */ 106438625Srvb/* locals */ 106538625Srvb 106638625Srvb /* We don't need to send inactive to venus - DCS */ 106739085Srvb MARK_ENTRY(CODA_INACTIVE_STATS); 106838625Srvb 106938625Srvb if (IS_CTL_VP(vp)) { 107039085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 107138625Srvb return 0; 107238625Srvb } 107338625Srvb 107439085Srvb CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n", 107538625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, 107638625Srvb cp->c_fid.Unique, vp->v_mount));) 107738625Srvb 107838625Srvb /* If an array has been allocated to hold the symlink, deallocate it */ 107939085Srvb if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { 108038625Srvb if (cp->c_symlink == NULL) 108139085Srvb panic("coda_inactive: null symlink pointer in cnode"); 108238625Srvb 108339085Srvb CODA_FREE(cp->c_symlink, cp->c_symlen); 108438625Srvb cp->c_flags &= ~C_SYMLINK; 108538625Srvb cp->c_symlen = 0; 108638625Srvb } 108738625Srvb 108838625Srvb /* Remove it from the table so it can't be found. */ 108939085Srvb coda_unsave(cp); 109039085Srvb if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) { 109138625Srvb myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp)); 109239085Srvb panic("badness in coda_inactive\n"); 109338625Srvb } 109438625Srvb 109538625Srvb if (IS_UNMOUNTING(cp)) { 109638625Srvb#ifdef DEBUG 109739085Srvb printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp); 109838625Srvb if (cp->c_ovp != NULL) 109939085Srvb printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n", 110038625Srvb vp->v_usecount, vp, cp); 110138625Srvb#endif 110238759Srvb lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, p); 110338625Srvb } else { 110438625Srvb#ifdef DIAGNOSTIC 110538625Srvb if (CTOV(cp)->v_usecount) { 110639085Srvb panic("coda_inactive: nonzero reference count"); 110738625Srvb } 110838625Srvb if (cp->c_ovp != NULL) { 110939085Srvb panic("coda_inactive: cp->ovp != NULL"); 111038625Srvb } 111138625Srvb#endif 111238759Srvb VOP_UNLOCK(vp, 0, p); 111338625Srvb vgone(vp); 111438625Srvb } 111538625Srvb 111639085Srvb MARK_INT_SAT(CODA_INACTIVE_STATS); 111738625Srvb return(0); 111838625Srvb} 111938625Srvb 112038625Srvb/* 112138625Srvb * Remote file system operations having to do with directory manipulation. 112238625Srvb */ 112338625Srvb 112438625Srvb/* 112538625Srvb * It appears that in NetBSD, lookup is supposed to return the vnode locked 112638625Srvb */ 112738625Srvbint 112839085Srvbcoda_lookup(v) 112938625Srvb void *v; 113038625Srvb{ 113138625Srvb/* true args */ 113238625Srvb struct vop_lookup_args *ap = v; 113338625Srvb struct vnode *dvp = ap->a_dvp; 113438625Srvb struct cnode *dcp = VTOC(dvp); 113538625Srvb struct vnode **vpp = ap->a_vpp; 113638625Srvb /* 113738625Srvb * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest 113838625Srvb * of the string to xlate, and that we must try to get at least 113938625Srvb * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I 114038625Srvb * could be wrong. 114138625Srvb */ 114238625Srvb struct componentname *cnp = ap->a_cnp; 114338625Srvb struct ucred *cred = cnp->cn_cred; 114438625Srvb struct proc *p = cnp->cn_proc; 114538625Srvb/* locals */ 114638625Srvb struct cnode *cp; 114738625Srvb const char *nm = cnp->cn_nameptr; 114838625Srvb int len = cnp->cn_namelen; 114938625Srvb ViceFid VFid; 115038625Srvb int vtype; 115138625Srvb int error = 0; 115238625Srvb 115339085Srvb MARK_ENTRY(CODA_LOOKUP_STATS); 115438625Srvb 115539085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n", 115638625Srvb nm, dcp->c_fid.Volume, 115738625Srvb dcp->c_fid.Vnode, dcp->c_fid.Unique));); 115838625Srvb 115938625Srvb /* Check for lookup of control object. */ 116038625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 116139085Srvb *vpp = coda_ctlvp; 116238625Srvb vref(*vpp); 116339085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 116438625Srvb goto exit; 116538625Srvb } 116638625Srvb 116739085Srvb if (len+1 > CODA_MAXNAMLEN) { 116839085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 116939085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n", 117038625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, 117138625Srvb dcp->c_fid.Unique, nm));); 117238625Srvb *vpp = (struct vnode *)0; 117338625Srvb error = EINVAL; 117438625Srvb goto exit; 117538625Srvb } 117638625Srvb /* First try to look the file up in the cfs name cache */ 117738625Srvb /* lock the parent vnode? */ 117839085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 117938625Srvb if (cp) { 118038625Srvb *vpp = CTOV(cp); 118138625Srvb vref(*vpp); 118239085Srvb CODADEBUG(CODA_LOOKUP, 118338625Srvb myprintf(("lookup result %d vpp %p\n",error,*vpp));) 118438625Srvb } else { 118538625Srvb 118638625Srvb /* The name wasn't cached, so we need to contact Venus */ 118738625Srvb error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, p, &VFid, &vtype); 118838625Srvb 118938625Srvb if (error) { 119039085Srvb MARK_INT_FAIL(CODA_LOOKUP_STATS); 119139085Srvb CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n", 119238625Srvb dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));) 119338625Srvb *vpp = (struct vnode *)0; 119438625Srvb } else { 119539085Srvb MARK_INT_SAT(CODA_LOOKUP_STATS); 119639085Srvb CODADEBUG(CODA_LOOKUP, 119738625Srvb myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n", 119838625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, vtype, 119938625Srvb error)); ) 120038625Srvb 120139085Srvb cp = make_coda_node(&VFid, dvp->v_mount, vtype); 120238625Srvb *vpp = CTOV(cp); 120338625Srvb 120438625Srvb /* enter the new vnode in the Name Cache only if the top bit isn't set */ 120538625Srvb /* And don't enter a new vnode for an invalid one! */ 120639085Srvb if (!(vtype & CODA_NOCACHE)) 120739085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 120838625Srvb } 120938625Srvb } 121038625Srvb 121138625Srvb exit: 121238625Srvb /* 121338625Srvb * If we are creating, and this was the last name to be looked up, 121438625Srvb * and the error was ENOENT, then there really shouldn't be an 121538625Srvb * error and we can make the leaf NULL and return success. Since 121638625Srvb * this is supposed to work under Mach as well as NetBSD, we're 121738625Srvb * leaving this fn wrapped. We also must tell lookup/namei that 121838625Srvb * we need to save the last component of the name. (Create will 121938625Srvb * have to free the name buffer later...lucky us...) 122038625Srvb */ 122138625Srvb if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) 122238625Srvb && (cnp->cn_flags & ISLASTCN) 122338625Srvb && (error == ENOENT)) 122438625Srvb { 122538625Srvb error = EJUSTRETURN; 122638625Srvb cnp->cn_flags |= SAVENAME; 122738625Srvb *ap->a_vpp = NULL; 122838625Srvb } 122938625Srvb 123038625Srvb /* 123138625Srvb * If we are removing, and we are at the last element, and we 123238625Srvb * found it, then we need to keep the name around so that the 123338625Srvb * removal will go ahead as planned. Unfortunately, this will 123438625Srvb * probably also lock the to-be-removed vnode, which may or may 123538625Srvb * not be a good idea. I'll have to look at the bits of 123639085Srvb * coda_remove to make sure. We'll only save the name if we did in 123739085Srvb * fact find the name, otherwise coda_remove won't have a chance 123838625Srvb * to free the pathname. 123938625Srvb */ 124038625Srvb if ((cnp->cn_nameiop == DELETE) 124138625Srvb && (cnp->cn_flags & ISLASTCN) 124238625Srvb && !error) 124338625Srvb { 124438625Srvb cnp->cn_flags |= SAVENAME; 124538625Srvb } 124638625Srvb 124738625Srvb /* 124838625Srvb * If the lookup went well, we need to (potentially?) unlock the 124938625Srvb * parent, and lock the child. We are only responsible for 125038625Srvb * checking to see if the parent is supposed to be unlocked before 125138625Srvb * we return. We must always lock the child (provided there is 125238625Srvb * one, and (the parent isn't locked or it isn't the same as the 125338625Srvb * parent.) Simple, huh? We can never leave the parent locked unless 125438625Srvb * we are ISLASTCN 125538625Srvb */ 125638625Srvb if (!error || (error == EJUSTRETURN)) { 125738625Srvb if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) { 125838759Srvb if ((error = VOP_UNLOCK(dvp, 0, p))) { 125938625Srvb return error; 126038625Srvb } 126138625Srvb /* 126238625Srvb * The parent is unlocked. As long as there is a child, 126338625Srvb * lock it without bothering to check anything else. 126438625Srvb */ 126538625Srvb if (*ap->a_vpp) { 126638759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 126739085Srvb printf("coda_lookup: "); 126838625Srvb panic("unlocked parent but couldn't lock child"); 126938625Srvb } 127038625Srvb } 127138625Srvb } else { 127238625Srvb /* The parent is locked, and may be the same as the child */ 127338625Srvb if (*ap->a_vpp && (*ap->a_vpp != dvp)) { 127438625Srvb /* Different, go ahead and lock it. */ 127538759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 127639085Srvb printf("coda_lookup: "); 127738625Srvb panic("unlocked parent but couldn't lock child"); 127838625Srvb } 127938625Srvb } 128038625Srvb } 128138625Srvb } else { 128238625Srvb /* If the lookup failed, we need to ensure that the leaf is NULL */ 128338625Srvb /* Don't change any locking? */ 128438625Srvb *ap->a_vpp = NULL; 128538625Srvb } 128638625Srvb return(error); 128738625Srvb} 128838625Srvb 128938625Srvb/*ARGSUSED*/ 129038625Srvbint 129139085Srvbcoda_create(v) 129238625Srvb void *v; 129338625Srvb{ 129438625Srvb/* true args */ 129538625Srvb struct vop_create_args *ap = v; 129638625Srvb struct vnode *dvp = ap->a_dvp; 129738625Srvb struct cnode *dcp = VTOC(dvp); 129838625Srvb struct vattr *va = ap->a_vap; 129938625Srvb int exclusive = 1; 130038625Srvb int mode = ap->a_vap->va_mode; 130138625Srvb struct vnode **vpp = ap->a_vpp; 130238625Srvb struct componentname *cnp = ap->a_cnp; 130338625Srvb struct ucred *cred = cnp->cn_cred; 130438625Srvb struct proc *p = cnp->cn_proc; 130538625Srvb/* locals */ 130638625Srvb int error; 130738625Srvb struct cnode *cp; 130838625Srvb const char *nm = cnp->cn_nameptr; 130938625Srvb int len = cnp->cn_namelen; 131038625Srvb ViceFid VFid; 131138625Srvb struct vattr attr; 131238625Srvb 131339085Srvb MARK_ENTRY(CODA_CREATE_STATS); 131438625Srvb 131538625Srvb /* All creates are exclusive XXX */ 131638625Srvb /* I'm assuming the 'mode' argument is the file mode bits XXX */ 131738625Srvb 131838625Srvb /* Check for create of control object. */ 131938625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 132038625Srvb *vpp = (struct vnode *)0; 132139085Srvb MARK_INT_FAIL(CODA_CREATE_STATS); 132238625Srvb return(EACCES); 132338625Srvb } 132438625Srvb 132538625Srvb error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, p, &VFid, &attr); 132638625Srvb 132738625Srvb if (!error) { 132838625Srvb 132938625Srvb /* If this is an exclusive create, panic if the file already exists. */ 133038625Srvb /* Venus should have detected the file and reported EEXIST. */ 133138625Srvb 133238625Srvb if ((exclusive == 1) && 133339085Srvb (coda_find(&VFid) != NULL)) 133438625Srvb panic("cnode existed for newly created file!"); 133538625Srvb 133639085Srvb cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type); 133738625Srvb *vpp = CTOV(cp); 133838625Srvb 133938625Srvb /* Update va to reflect the new attributes. */ 134038625Srvb (*va) = attr; 134138625Srvb 134238625Srvb /* Update the attribute cache and mark it as valid */ 134339085Srvb if (coda_attr_cache) { 134438625Srvb VTOC(*vpp)->c_vattr = attr; 134538625Srvb VTOC(*vpp)->c_flags |= C_VATTR; 134638625Srvb } 134738625Srvb 134838625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 134938625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 135038625Srvb 135138625Srvb /* enter the new vnode in the Name Cache */ 135239085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 135338625Srvb 135439085Srvb CODADEBUG(CODA_CREATE, 135538625Srvb myprintf(("create: (%lx.%lx.%lx), result %d\n", 135638625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 135738625Srvb } else { 135838625Srvb *vpp = (struct vnode *)0; 135939085Srvb CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));) 136038625Srvb } 136138625Srvb 136238625Srvb if (!error) { 136338625Srvb if (cnp->cn_flags & LOCKLEAF) { 136438759Srvb if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) { 136539085Srvb printf("coda_create: "); 136638625Srvb panic("unlocked parent but couldn't lock child"); 136738625Srvb } 136838625Srvb } 136938625Srvb#ifdef DIAGNOSTIC 137038625Srvb else { 137139085Srvb printf("coda_create: LOCKLEAF not set!\n"); 137238625Srvb } 137338625Srvb#endif /* DIAGNOSTIC */ 137438625Srvb } 137538625Srvb /* Have to free the previously saved name */ 137638625Srvb /* 137738625Srvb * This condition is stolen from ufs_makeinode. I have no idea 137838625Srvb * why it's here, but what the hey... 137938625Srvb */ 138038625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 138138759Srvb zfree(namei_zone, cnp->cn_pnbuf); 138238625Srvb } 138338625Srvb return(error); 138438625Srvb} 138538625Srvb 138638625Srvbint 138739085Srvbcoda_remove(v) 138838625Srvb void *v; 138938625Srvb{ 139038625Srvb/* true args */ 139138625Srvb struct vop_remove_args *ap = v; 139238625Srvb struct vnode *dvp = ap->a_dvp; 139338625Srvb struct cnode *cp = VTOC(dvp); 139438625Srvb struct componentname *cnp = ap->a_cnp; 139538625Srvb struct ucred *cred = cnp->cn_cred; 139638625Srvb struct proc *p = cnp->cn_proc; 139738625Srvb/* locals */ 139838625Srvb int error; 139938625Srvb const char *nm = cnp->cn_nameptr; 140038625Srvb int len = cnp->cn_namelen; 140138625Srvb struct cnode *tp; 140238625Srvb 140339085Srvb MARK_ENTRY(CODA_REMOVE_STATS); 140438625Srvb 140539085Srvb CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n", 140638625Srvb nm, cp->c_fid.Volume, cp->c_fid.Vnode, 140738625Srvb cp->c_fid.Unique));); 140838625Srvb 140939085Srvb /* Remove the file's entry from the CODA Name Cache */ 141038625Srvb /* We're being conservative here, it might be that this person 141138625Srvb * doesn't really have sufficient access to delete the file 141238625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 141338625Srvb */ 141438625Srvb /* I'm gonna go out on a limb here. If a file and a hardlink to it 141538625Srvb * exist, and one is removed, the link count on the other will be 141638625Srvb * off by 1. We could either invalidate the attrs if cached, or 141738625Srvb * fix them. I'll try to fix them. DCS 11/8/94 141838625Srvb */ 141939085Srvb tp = coda_nc_lookup(VTOC(dvp), nm, len, cred); 142038625Srvb if (tp) { 142138625Srvb if (VALID_VATTR(tp)) { /* If attrs are cached */ 142238625Srvb if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */ 142338625Srvb tp->c_vattr.va_nlink--; 142438625Srvb } 142538625Srvb } 142638625Srvb 142739085Srvb coda_nc_zapfile(VTOC(dvp), nm, len); 142838625Srvb /* No need to flush it if it doesn't exist! */ 142938625Srvb } 143038625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 143138625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 143238625Srvb 143338625Srvb /* Check for remove of control object. */ 143438625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 143539085Srvb MARK_INT_FAIL(CODA_REMOVE_STATS); 143638625Srvb return(ENOENT); 143738625Srvb } 143838625Srvb 143938625Srvb error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, p); 144038625Srvb 144139085Srvb CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); ) 144238625Srvb 144338625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 144438759Srvb zfree(namei_zone, cnp->cn_pnbuf); 144538625Srvb } 144638625Srvb return(error); 144738625Srvb} 144838625Srvb 144938625Srvbint 145039085Srvbcoda_link(v) 145138625Srvb void *v; 145238625Srvb{ 145338625Srvb/* true args */ 145438625Srvb struct vop_link_args *ap = v; 145538625Srvb struct vnode *vp = ap->a_vp; 145638625Srvb struct cnode *cp = VTOC(vp); 145738625Srvb struct vnode *tdvp = ap->a_tdvp; 145838625Srvb struct cnode *tdcp = VTOC(tdvp); 145938625Srvb struct componentname *cnp = ap->a_cnp; 146038625Srvb struct ucred *cred = cnp->cn_cred; 146138625Srvb struct proc *p = cnp->cn_proc; 146238625Srvb/* locals */ 146338625Srvb int error; 146438625Srvb const char *nm = cnp->cn_nameptr; 146538625Srvb int len = cnp->cn_namelen; 146638625Srvb 146739085Srvb MARK_ENTRY(CODA_LINK_STATS); 146838625Srvb 146939085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 147038625Srvb 147138625Srvb myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n", 147238625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 147338625Srvb myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n", 147438625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 147538625Srvb 147638625Srvb } 147739085Srvb if (codadebug & CODADBGMSK(CODA_LINK)) { 147838625Srvb myprintf(("link: vp fid: (%lx.%lx.%lx)\n", 147938625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 148038625Srvb myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n", 148138625Srvb tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique)); 148238625Srvb 148338625Srvb } 148438625Srvb 148538625Srvb /* Check for link to/from control object. */ 148638625Srvb if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) { 148739085Srvb MARK_INT_FAIL(CODA_LINK_STATS); 148838625Srvb return(EACCES); 148938625Srvb } 149038625Srvb 149138625Srvb error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, p); 149238625Srvb 149338625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 149438625Srvb VTOC(tdvp)->c_flags &= ~C_VATTR; 149538625Srvb VTOC(vp)->c_flags &= ~C_VATTR; 149638625Srvb 149739085Srvb CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); ) 149838625Srvb 149938625Srvbexit: 150038625Srvb 150138625Srvb /* Drop the name buffer if we don't need to SAVESTART */ 150238625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 150338759Srvb zfree(namei_zone, cnp->cn_pnbuf); 150438625Srvb } 150538625Srvb return(error); 150638625Srvb} 150738625Srvb 150838625Srvbint 150939085Srvbcoda_rename(v) 151038625Srvb void *v; 151138625Srvb{ 151238625Srvb/* true args */ 151338625Srvb struct vop_rename_args *ap = v; 151438625Srvb struct vnode *odvp = ap->a_fdvp; 151538625Srvb struct cnode *odcp = VTOC(odvp); 151638625Srvb struct componentname *fcnp = ap->a_fcnp; 151738625Srvb struct vnode *ndvp = ap->a_tdvp; 151838625Srvb struct cnode *ndcp = VTOC(ndvp); 151938625Srvb struct componentname *tcnp = ap->a_tcnp; 152038625Srvb struct ucred *cred = fcnp->cn_cred; 152138625Srvb struct proc *p = fcnp->cn_proc; 152238625Srvb/* true args */ 152338625Srvb int error; 152438625Srvb const char *fnm = fcnp->cn_nameptr; 152538625Srvb int flen = fcnp->cn_namelen; 152638625Srvb const char *tnm = tcnp->cn_nameptr; 152738625Srvb int tlen = tcnp->cn_namelen; 152838625Srvb 152939085Srvb MARK_ENTRY(CODA_RENAME_STATS); 153038625Srvb 153138625Srvb /* Hmmm. The vnodes are already looked up. Perhaps they are locked? 153238625Srvb This could be Bad. XXX */ 153338625Srvb#ifdef DIAGNOSTIC 153438625Srvb if ((fcnp->cn_cred != tcnp->cn_cred) 153538625Srvb || (fcnp->cn_proc != tcnp->cn_proc)) 153638625Srvb { 153739085Srvb panic("coda_rename: component names don't agree"); 153838625Srvb } 153938625Srvb#endif DIAGNOSTIC 154038625Srvb 154138625Srvb /* Check for rename involving control object. */ 154238625Srvb if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) { 154339085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 154438625Srvb return(EACCES); 154538625Srvb } 154638625Srvb 154738625Srvb /* Problem with moving directories -- need to flush entry for .. */ 154838625Srvb if (odvp != ndvp) { 154939085Srvb struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred); 155038625Srvb if (ovcp) { 155138625Srvb struct vnode *ovp = CTOV(ovcp); 155238625Srvb if ((ovp) && 155338625Srvb (ovp->v_type == VDIR)) /* If it's a directory */ 155439085Srvb coda_nc_zapfile(VTOC(ovp),"..", 2); 155538625Srvb } 155638625Srvb } 155738625Srvb 155838625Srvb /* Remove the entries for both source and target files */ 155939085Srvb coda_nc_zapfile(VTOC(odvp), fnm, flen); 156039085Srvb coda_nc_zapfile(VTOC(ndvp), tnm, tlen); 156138625Srvb 156238625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 156338625Srvb VTOC(odvp)->c_flags &= ~C_VATTR; 156438625Srvb VTOC(ndvp)->c_flags &= ~C_VATTR; 156538625Srvb 156639085Srvb if (flen+1 > CODA_MAXNAMLEN) { 156739085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 156838625Srvb error = EINVAL; 156938625Srvb goto exit; 157038625Srvb } 157138625Srvb 157239085Srvb if (tlen+1 > CODA_MAXNAMLEN) { 157339085Srvb MARK_INT_FAIL(CODA_RENAME_STATS); 157438625Srvb error = EINVAL; 157538625Srvb goto exit; 157638625Srvb } 157738625Srvb 157838625Srvb error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, p); 157938625Srvb 158038625Srvb exit: 158139085Srvb CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));) 158238625Srvb /* XXX - do we need to call cache pureg on the moved vnode? */ 158338625Srvb cache_purge(ap->a_fvp); 158438625Srvb 158538625Srvb /* It seems to be incumbent on us to drop locks on all four vnodes */ 158638625Srvb /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */ 158738625Srvb 158838625Srvb vrele(ap->a_fvp); 158938625Srvb vrele(odvp); 159038625Srvb 159138625Srvb if (ap->a_tvp) { 159238625Srvb if (ap->a_tvp == ndvp) { 159338625Srvb vrele(ap->a_tvp); 159438625Srvb } else { 159538625Srvb vput(ap->a_tvp); 159638625Srvb } 159738625Srvb } 159838625Srvb 159938625Srvb vput(ndvp); 160038625Srvb return(error); 160138625Srvb} 160238625Srvb 160338625Srvbint 160439085Srvbcoda_mkdir(v) 160538625Srvb void *v; 160638625Srvb{ 160738625Srvb/* true args */ 160838625Srvb struct vop_mkdir_args *ap = v; 160938625Srvb struct vnode *dvp = ap->a_dvp; 161038625Srvb struct cnode *dcp = VTOC(dvp); 161138625Srvb struct componentname *cnp = ap->a_cnp; 161238625Srvb register struct vattr *va = ap->a_vap; 161338625Srvb struct vnode **vpp = ap->a_vpp; 161438625Srvb struct ucred *cred = cnp->cn_cred; 161538625Srvb struct proc *p = cnp->cn_proc; 161638625Srvb/* locals */ 161738625Srvb int error; 161838625Srvb const char *nm = cnp->cn_nameptr; 161938625Srvb int len = cnp->cn_namelen; 162038625Srvb struct cnode *cp; 162138625Srvb ViceFid VFid; 162238625Srvb struct vattr ova; 162338625Srvb 162439085Srvb MARK_ENTRY(CODA_MKDIR_STATS); 162538625Srvb 162638625Srvb /* Check for mkdir of target object. */ 162738625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 162838625Srvb *vpp = (struct vnode *)0; 162939085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 163038625Srvb return(EACCES); 163138625Srvb } 163238625Srvb 163339085Srvb if (len+1 > CODA_MAXNAMLEN) { 163438625Srvb *vpp = (struct vnode *)0; 163539085Srvb MARK_INT_FAIL(CODA_MKDIR_STATS); 163638625Srvb return(EACCES); 163738625Srvb } 163838625Srvb 163938625Srvb error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, p, &VFid, &ova); 164038625Srvb 164138625Srvb if (!error) { 164239085Srvb if (coda_find(&VFid) != NULL) 164338625Srvb panic("cnode existed for newly created directory!"); 164438625Srvb 164538625Srvb 164639085Srvb cp = make_coda_node(&VFid, dvp->v_mount, va->va_type); 164738625Srvb *vpp = CTOV(cp); 164838625Srvb 164938625Srvb /* enter the new vnode in the Name Cache */ 165039085Srvb coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp)); 165138625Srvb 165238625Srvb /* as a side effect, enter "." and ".." for the directory */ 165339085Srvb coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp)); 165439085Srvb coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp)); 165538625Srvb 165639085Srvb if (coda_attr_cache) { 165738625Srvb VTOC(*vpp)->c_vattr = ova; /* update the attr cache */ 165838625Srvb VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */ 165938625Srvb } 166038625Srvb 166138625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 166238625Srvb VTOC(dvp)->c_flags &= ~C_VATTR; 166338625Srvb 166439085Srvb CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n", 166538625Srvb VFid.Volume, VFid.Vnode, VFid.Unique, error)); ) 166638625Srvb } else { 166738625Srvb *vpp = (struct vnode *)0; 166839085Srvb CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));) 166938625Srvb } 167038625Srvb 167138625Srvb /* Have to free the previously saved name */ 167238625Srvb /* 167338625Srvb * ufs_mkdir doesn't check for SAVESTART before freeing the 167438625Srvb * pathname buffer, but ufs_create does. For the moment, I'll 167538625Srvb * follow their lead, but this seems like it is probably 167638625Srvb * incorrect. 167738625Srvb */ 167838759Srvb zfree(namei_zone, cnp->cn_pnbuf); 167938625Srvb return(error); 168038625Srvb} 168138625Srvb 168238625Srvbint 168339085Srvbcoda_rmdir(v) 168438625Srvb void *v; 168538625Srvb{ 168638625Srvb/* true args */ 168738625Srvb struct vop_rmdir_args *ap = v; 168838625Srvb struct vnode *dvp = ap->a_dvp; 168938625Srvb struct cnode *dcp = VTOC(dvp); 169038625Srvb struct componentname *cnp = ap->a_cnp; 169138625Srvb struct ucred *cred = cnp->cn_cred; 169238625Srvb struct proc *p = cnp->cn_proc; 169338625Srvb/* true args */ 169438625Srvb int error; 169538625Srvb const char *nm = cnp->cn_nameptr; 169638625Srvb int len = cnp->cn_namelen; 169738625Srvb struct cnode *cp; 169838625Srvb 169939085Srvb MARK_ENTRY(CODA_RMDIR_STATS); 170038625Srvb 170138625Srvb /* Check for rmdir of control object. */ 170238625Srvb if (IS_CTL_NAME(dvp, nm, len)) { 170339085Srvb MARK_INT_FAIL(CODA_RMDIR_STATS); 170438625Srvb return(ENOENT); 170538625Srvb } 170638625Srvb 170738625Srvb /* We're being conservative here, it might be that this person 170838625Srvb * doesn't really have sufficient access to delete the file 170938625Srvb * but we feel zapping the entry won't really hurt anyone -- dcs 171038625Srvb */ 171138625Srvb /* 171238625Srvb * As a side effect of the rmdir, remove any entries for children of 171338625Srvb * the directory, especially "." and "..". 171438625Srvb */ 171539085Srvb cp = coda_nc_lookup(dcp, nm, len, cred); 171639085Srvb if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL); 171738625Srvb 171839085Srvb /* Remove the file's entry from the CODA Name Cache */ 171939085Srvb coda_nc_zapfile(dcp, nm, len); 172038625Srvb 172138625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 172238625Srvb dcp->c_flags &= ~C_VATTR; 172338625Srvb 172438625Srvb error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, p); 172538625Srvb 172639085Srvb CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); ) 172738625Srvb 172838625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 172938759Srvb zfree(namei_zone, cnp->cn_pnbuf); 173038625Srvb } 173138625Srvb return(error); 173238625Srvb} 173338625Srvb 173438625Srvbint 173539085Srvbcoda_symlink(v) 173638625Srvb void *v; 173738625Srvb{ 173838625Srvb/* true args */ 173938625Srvb struct vop_symlink_args *ap = v; 174038625Srvb struct vnode *tdvp = ap->a_dvp; 174138625Srvb struct cnode *tdcp = VTOC(tdvp); 174238625Srvb struct componentname *cnp = ap->a_cnp; 174338625Srvb struct vattr *tva = ap->a_vap; 174438625Srvb char *path = ap->a_target; 174538625Srvb struct ucred *cred = cnp->cn_cred; 174638625Srvb struct proc *p = cnp->cn_proc; 174738625Srvb/* locals */ 174838625Srvb int error; 174938625Srvb /* 175039085Srvb * XXX I'm assuming the following things about coda_symlink's 175138625Srvb * arguments: 175238625Srvb * t(foo) is the new name/parent/etc being created. 175338625Srvb * lname is the contents of the new symlink. 175438625Srvb */ 175538759Srvb char *nm = cnp->cn_nameptr; 175638625Srvb int len = cnp->cn_namelen; 175738625Srvb int plen = strlen(path); 175838625Srvb 175938625Srvb /* XXX What about the vpp argument? Do we need it? */ 176038625Srvb /* 176138625Srvb * Here's the strategy for the moment: perform the symlink, then 176238625Srvb * do a lookup to grab the resulting vnode. I know this requires 176338625Srvb * two communications with Venus for a new sybolic link, but 176438625Srvb * that's the way the ball bounces. I don't yet want to change 176538625Srvb * the way the Mach symlink works. When Mach support is 176638625Srvb * deprecated, we should change symlink so that the common case 176738625Srvb * returns the resultant vnode in a vpp argument. 176838625Srvb */ 176938625Srvb 177039085Srvb MARK_ENTRY(CODA_SYMLINK_STATS); 177138625Srvb 177238625Srvb /* Check for symlink of control object. */ 177338625Srvb if (IS_CTL_NAME(tdvp, nm, len)) { 177439085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 177538625Srvb return(EACCES); 177638625Srvb } 177738625Srvb 177839085Srvb if (plen+1 > CODA_MAXPATHLEN) { 177939085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 178038625Srvb return(EINVAL); 178138625Srvb } 178238625Srvb 178339085Srvb if (len+1 > CODA_MAXNAMLEN) { 178439085Srvb MARK_INT_FAIL(CODA_SYMLINK_STATS); 178538625Srvb error = EINVAL; 178638625Srvb goto exit; 178738625Srvb } 178838625Srvb 178938625Srvb error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, p); 179038625Srvb 179138625Srvb /* Invalidate the parent's attr cache, the modification time has changed */ 179238625Srvb tdcp->c_flags &= ~C_VATTR; 179338625Srvb 179438625Srvb /* 179538625Srvb * Free the name buffer 179638625Srvb */ 179738625Srvb if ((cnp->cn_flags & SAVESTART) == 0) { 179838759Srvb zfree(namei_zone, cnp->cn_pnbuf); 179938625Srvb } 180038625Srvb 180138625Srvb exit: 180239085Srvb CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); ) 180338625Srvb return(error); 180438625Srvb} 180538625Srvb 180638625Srvb/* 180738625Srvb * Read directory entries. 180838625Srvb */ 180938625Srvbint 181039085Srvbcoda_readdir(v) 181138625Srvb void *v; 181238625Srvb{ 181338625Srvb/* true args */ 181438625Srvb struct vop_readdir_args *ap = v; 181538625Srvb struct vnode *vp = ap->a_vp; 181638625Srvb struct cnode *cp = VTOC(vp); 181738625Srvb register struct uio *uiop = ap->a_uio; 181838625Srvb struct ucred *cred = ap->a_cred; 181938625Srvb int *eofflag = ap->a_eofflag; 182038625Srvb u_long **cookies = ap->a_cookies; 182138625Srvb int *ncookies = ap->a_ncookies; 182238625Srvb struct proc *p = ap->a_uio->uio_procp; 182338625Srvb/* upcall decl */ 182438625Srvb/* locals */ 182538625Srvb int error = 0; 182638625Srvb 182739085Srvb MARK_ENTRY(CODA_READDIR_STATS); 182838625Srvb 182939085Srvb CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %qd, %d)\n", uiop->uio_iov->iov_base, uiop->uio_resid, uiop->uio_offset, uiop->uio_segflg)); ) 183038625Srvb 183138625Srvb /* Check for readdir of control object. */ 183238625Srvb if (IS_CTL_VP(vp)) { 183339085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 183438625Srvb return(ENOENT); 183538625Srvb } 183638625Srvb 183738759Srvb { 183838625Srvb /* If directory is not already open do an "internal open" on it. */ 183938625Srvb int opened_internally = 0; 184038625Srvb if (cp->c_ovp == NULL) { 184138625Srvb opened_internally = 1; 184239085Srvb MARK_INT_GEN(CODA_OPEN_STATS); 184338625Srvb error = VOP_OPEN(vp, FREAD, cred, p); 184439085Srvbprintf("coda_readdir: Internally Opening %p\n", vp); 184538625Srvb if (error) { 184639085Srvb printf("coda_readdir: VOP_OPEN on container failed %d\n", error); 184738625Srvb return (error); 184838625Srvb } 184938625Srvb if (vp->v_type == VREG) { 185038625Srvb error = vfs_object_create(vp, p, cred, 1); 185138625Srvb if (error != 0) { 185239085Srvb printf("coda_readdir: vfs_object_create() returns %d\n", error); 185338625Srvb vput(vp); 185438625Srvb } 185538625Srvb } 185638625Srvb if (error) return(error); 185738625Srvb } 185838625Srvb 185938625Srvb /* Have UFS handle the call. */ 186039085Srvb CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vp->v_usecount)); ) 186138625Srvb error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies, 186238625Srvb cookies); 186338625Srvb 186438625Srvb if (error) 186539085Srvb MARK_INT_FAIL(CODA_READDIR_STATS); 186638625Srvb else 186739085Srvb MARK_INT_SAT(CODA_READDIR_STATS); 186838625Srvb 186938625Srvb /* Do an "internal close" if necessary. */ 187038625Srvb if (opened_internally) { 187139085Srvb MARK_INT_GEN(CODA_CLOSE_STATS); 187238625Srvb (void)VOP_CLOSE(vp, FREAD, cred, p); 187338625Srvb } 187438625Srvb } 187538625Srvb 187638625Srvb return(error); 187738625Srvb} 187838625Srvb 187938625Srvb/* 188038625Srvb * Convert from file system blocks to device blocks 188138625Srvb */ 188238625Srvbint 188339085Srvbcoda_bmap(v) 188438625Srvb void *v; 188538625Srvb{ 188638625Srvb /* XXX on the global proc */ 188738625Srvb/* true args */ 188838625Srvb struct vop_bmap_args *ap = v; 188938625Srvb struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */ 189038625Srvb daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */ 189138625Srvb struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */ 189238625Srvb daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */ 189338625Srvb struct proc *p __attribute__((unused)) = curproc; 189438625Srvb/* upcall decl */ 189538625Srvb/* locals */ 189638625Srvb 189738625Srvb int ret = 0; 189838625Srvb struct cnode *cp; 189938625Srvb 190038625Srvb cp = VTOC(vp); 190138625Srvb if (cp->c_ovp) { 190239085Srvb printf("coda_bmap: container .. "); 190338625Srvb ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb); 190438625Srvb printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n", 190538625Srvb cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret); 190638625Srvb return ret; 190738625Srvb } else { 190839085Srvb printf("coda_bmap: no container\n"); 190938625Srvb return(EOPNOTSUPP); 191038625Srvb } 191138625Srvb} 191238625Srvb 191338625Srvb/* 191438625Srvb * I don't think the following two things are used anywhere, so I've 191538625Srvb * commented them out 191638625Srvb * 191738625Srvb * struct buf *async_bufhead; 191838625Srvb * int async_daemon_count; 191938625Srvb */ 192038625Srvbint 192139085Srvbcoda_strategy(v) 192238625Srvb void *v; 192338625Srvb{ 192438625Srvb/* true args */ 192538625Srvb struct vop_strategy_args *ap = v; 192638625Srvb register struct buf *bp __attribute__((unused)) = ap->a_bp; 192738625Srvb struct proc *p __attribute__((unused)) = curproc; 192838625Srvb/* upcall decl */ 192938625Srvb/* locals */ 193038625Srvb 193139085Srvb printf("coda_strategy: called ???\n"); 193238625Srvb return(EOPNOTSUPP); 193338625Srvb} 193438625Srvb 193538625Srvbint 193639085Srvbcoda_reclaim(v) 193738625Srvb void *v; 193838625Srvb{ 193938625Srvb/* true args */ 194038625Srvb struct vop_reclaim_args *ap = v; 194138625Srvb struct vnode *vp = ap->a_vp; 194238625Srvb struct cnode *cp = VTOC(vp); 194338625Srvb/* upcall decl */ 194438625Srvb/* locals */ 194538625Srvb 194638625Srvb/* 194738625Srvb * Forced unmount/flush will let vnodes with non zero use be destroyed! 194838625Srvb */ 194938625Srvb ENTRY; 195038625Srvb 195138625Srvb if (IS_UNMOUNTING(cp)) { 195238625Srvb#ifdef DEBUG 195338625Srvb if (VTOC(vp)->c_ovp) { 195438625Srvb if (IS_UNMOUNTING(cp)) 195539085Srvb printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp); 195638625Srvb } 195738625Srvb#endif 195838625Srvb } else { 195938625Srvb#ifdef DIAGNOSTIC 196038625Srvb if (vp->v_usecount != 0) 196139085Srvb vprint("coda_reclaim: pushing active", vp); 196238625Srvb if (VTOC(vp)->c_ovp) { 196339085Srvb panic("coda_reclaim: c_ovp not void"); 196438625Srvb } 196538625Srvb#endif DIAGNOSTIC 196638625Srvb } 196738625Srvb cache_purge(vp); 196839085Srvb coda_free(VTOC(vp)); 196938625Srvb VTOC(vp) = NULL; 197038625Srvb return (0); 197138625Srvb} 197238625Srvb 197338625Srvbint 197439085Srvbcoda_lock(v) 197538625Srvb void *v; 197638625Srvb{ 197738625Srvb/* true args */ 197838625Srvb struct vop_lock_args *ap = v; 197938625Srvb struct vnode *vp = ap->a_vp; 198038625Srvb struct cnode *cp = VTOC(vp); 198138625Srvb struct proc *p = ap->a_p; 198238625Srvb/* upcall decl */ 198338625Srvb/* locals */ 198438625Srvb 198538625Srvb ENTRY; 198638625Srvb 198739085Srvb if (coda_lockdebug) { 198838625Srvb myprintf(("Attempting lock on %lx.%lx.%lx\n", 198938625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 199038625Srvb } 199138625Srvb 199238759Srvb return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p)); 199338625Srvb} 199438625Srvb 199538625Srvbint 199639085Srvbcoda_unlock(v) 199738625Srvb void *v; 199838625Srvb{ 199938625Srvb/* true args */ 200038625Srvb struct vop_unlock_args *ap = v; 200138625Srvb struct vnode *vp = ap->a_vp; 200238625Srvb struct cnode *cp = VTOC(vp); 200338625Srvb struct proc *p = ap->a_p; 200438625Srvb/* upcall decl */ 200538625Srvb/* locals */ 200638625Srvb 200738625Srvb ENTRY; 200839085Srvb if (coda_lockdebug) { 200938625Srvb myprintf(("Attempting unlock on %lx.%lx.%lx\n", 201038625Srvb cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique)); 201138625Srvb } 201238625Srvb 201338759Srvb return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, p)); 201438625Srvb} 201538625Srvb 201638625Srvbint 201739085Srvbcoda_islocked(v) 201838625Srvb void *v; 201938625Srvb{ 202038625Srvb/* true args */ 202138625Srvb struct vop_islocked_args *ap = v; 202238625Srvb struct cnode *cp = VTOC(ap->a_vp); 202338625Srvb ENTRY; 202438625Srvb 202538625Srvb return (lockstatus(&cp->c_lock)); 202638625Srvb} 202738625Srvb 202838625Srvb/* How one looks up a vnode given a device/inode pair: */ 202938625Srvbint 203039085Srvbcoda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp) 203138625Srvb{ 203238625Srvb /* This is like VFS_VGET() or igetinode()! */ 203338625Srvb int error; 203438625Srvb struct mount *mp; 203538625Srvb 203638625Srvb if (!(mp = devtomp(dev))) { 203739085Srvb myprintf(("coda_grab_vnode: devtomp(%d) returns NULL\n", dev)); 203838625Srvb return(ENXIO); 203938625Srvb } 204038625Srvb 204138625Srvb /* XXX - ensure that nonzero-return means failure */ 204238625Srvb error = VFS_VGET(mp,ino,vpp); 204338625Srvb if (error) { 204439085Srvb myprintf(("coda_grab_vnode: iget/vget(%d, %d) returns %p, err %d\n", 204538625Srvb dev, ino, *vpp, error)); 204638625Srvb return(ENOENT); 204738625Srvb } 204838625Srvb return(0); 204938625Srvb} 205038625Srvb 205138625Srvbvoid 205238625Srvbprint_vattr( attr ) 205338625Srvb struct vattr *attr; 205438625Srvb{ 205538625Srvb char *typestr; 205638625Srvb 205738625Srvb switch (attr->va_type) { 205838625Srvb case VNON: 205938625Srvb typestr = "VNON"; 206038625Srvb break; 206138625Srvb case VREG: 206238625Srvb typestr = "VREG"; 206338625Srvb break; 206438625Srvb case VDIR: 206538625Srvb typestr = "VDIR"; 206638625Srvb break; 206738625Srvb case VBLK: 206838625Srvb typestr = "VBLK"; 206938625Srvb break; 207038625Srvb case VCHR: 207138625Srvb typestr = "VCHR"; 207238625Srvb break; 207338625Srvb case VLNK: 207438625Srvb typestr = "VLNK"; 207538625Srvb break; 207638625Srvb case VSOCK: 207738625Srvb typestr = "VSCK"; 207838625Srvb break; 207938625Srvb case VFIFO: 208038625Srvb typestr = "VFFO"; 208138625Srvb break; 208238625Srvb case VBAD: 208338625Srvb typestr = "VBAD"; 208438625Srvb break; 208538625Srvb default: 208638625Srvb typestr = "????"; 208738625Srvb break; 208838625Srvb } 208938625Srvb 209038625Srvb 209138625Srvb myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n", 209238625Srvb typestr, (int)attr->va_mode, (int)attr->va_uid, 209338625Srvb (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev)); 209438625Srvb 209538625Srvb myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n", 209638625Srvb (int)attr->va_fileid, (int)attr->va_nlink, 209738625Srvb (int)attr->va_size, 209838625Srvb (int)attr->va_blocksize,(int)attr->va_bytes)); 209938625Srvb myprintf((" gen %ld flags %ld vaflags %d\n", 210038625Srvb attr->va_gen, attr->va_flags, attr->va_vaflags)); 210138625Srvb myprintf((" atime sec %d nsec %d\n", 210238625Srvb (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec)); 210338625Srvb myprintf((" mtime sec %d nsec %d\n", 210438625Srvb (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec)); 210538625Srvb myprintf((" ctime sec %d nsec %d\n", 210638625Srvb (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec)); 210738625Srvb} 210838625Srvb 210938625Srvb/* How to print a ucred */ 211038625Srvbvoid 211138625Srvbprint_cred(cred) 211238625Srvb struct ucred *cred; 211338625Srvb{ 211438625Srvb 211538625Srvb int i; 211638625Srvb 211738625Srvb myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid)); 211838625Srvb 211938625Srvb for (i=0; i < cred->cr_ngroups; i++) 212038625Srvb myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i])); 212138625Srvb myprintf(("\n")); 212238625Srvb 212338625Srvb} 212438625Srvb 212538625Srvb/* 212638625Srvb * Return a vnode for the given fid. 212738625Srvb * If no cnode exists for this fid create one and put it 212838625Srvb * in a table hashed by fid.Volume and fid.Vnode. If the cnode for 212938625Srvb * this fid is already in the table return it (ref count is 213039085Srvb * incremented by coda_find. The cnode will be flushed from the 213139085Srvb * table when coda_inactive calls coda_unsave. 213238625Srvb */ 213338625Srvbstruct cnode * 213439085Srvbmake_coda_node(fid, vfsp, type) 213538625Srvb ViceFid *fid; struct mount *vfsp; short type; 213638625Srvb{ 213738625Srvb struct cnode *cp; 213838625Srvb int err; 213938625Srvb 214039085Srvb if ((cp = coda_find(fid)) == NULL) { 214138625Srvb struct vnode *vp; 214238625Srvb 214339085Srvb cp = coda_alloc(); 214438625Srvb lockinit(&cp->c_lock, PINOD, "cnode", 0, 0); 214538625Srvb cp->c_fid = *fid; 214638625Srvb 214739085Srvb err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp); 214838625Srvb if (err) { 214939085Srvb panic("coda: getnewvnode returned error %d\n", err); 215038625Srvb } 215138625Srvb vp->v_data = cp; 215238625Srvb vp->v_type = type; 215338625Srvb cp->c_vnode = vp; 215439085Srvb coda_save(cp); 215538625Srvb 215638625Srvb } else { 215738625Srvb vref(CTOV(cp)); 215838625Srvb } 215938625Srvb 216038625Srvb return cp; 216138625Srvb} 2162