Home | History | Annotate | Line # | Download | only in coda
coda_vnops.c revision 1.85
      1  1.85  christos /*	$NetBSD: coda_vnops.c,v 1.85 2012/05/02 16:51:01 christos Exp $	*/
      2   1.1       rvb 
      3   1.2       rvb /*
      4  1.40     perry  *
      5   1.2       rvb  *             Coda: an Experimental Distributed File System
      6   1.2       rvb  *                              Release 3.1
      7  1.40     perry  *
      8   1.2       rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9   1.2       rvb  *                          All Rights Reserved
     10  1.40     perry  *
     11   1.2       rvb  * Permission  to  use, copy, modify and distribute this software and its
     12   1.2       rvb  * documentation is hereby granted,  provided  that  both  the  copyright
     13   1.2       rvb  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14   1.2       rvb  * software, derivative works or  modified  versions,  and  any  portions
     15   1.2       rvb  * thereof, and that both notices appear in supporting documentation, and
     16   1.2       rvb  * that credit is given to Carnegie Mellon University  in  all  documents
     17   1.2       rvb  * and publicity pertaining to direct or indirect use of this code or its
     18   1.2       rvb  * derivatives.
     19  1.40     perry  *
     20   1.2       rvb  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21   1.2       rvb  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22   1.2       rvb  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23   1.2       rvb  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24   1.2       rvb  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25   1.2       rvb  * ANY DERIVATIVE WORK.
     26  1.40     perry  *
     27   1.2       rvb  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28   1.2       rvb  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29   1.2       rvb  * Mellon the rights to redistribute these changes without encumbrance.
     30  1.40     perry  *
     31  1.40     perry  * 	@(#) coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
     32   1.2       rvb  */
     33   1.1       rvb 
     34  1.40     perry /*
     35   1.1       rvb  * Mach Operating System
     36   1.1       rvb  * Copyright (c) 1990 Carnegie-Mellon University
     37   1.1       rvb  * Copyright (c) 1989 Carnegie-Mellon University
     38   1.1       rvb  * All rights reserved.  The CMU software License Agreement specifies
     39   1.1       rvb  * the terms and conditions for use and redistribution.
     40   1.1       rvb  */
     41   1.1       rvb 
     42   1.1       rvb /*
     43   1.1       rvb  * This code was written for the Coda file system at Carnegie Mellon
     44   1.1       rvb  * University.  Contributers include David Steere, James Kistler, and
     45  1.40     perry  * M. Satyanarayanan.
     46   1.1       rvb  */
     47  1.27     lukem 
     48  1.27     lukem #include <sys/cdefs.h>
     49  1.85  christos __KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.85 2012/05/02 16:51:01 christos Exp $");
     50   1.1       rvb 
     51   1.1       rvb #include <sys/param.h>
     52   1.1       rvb #include <sys/systm.h>
     53   1.1       rvb #include <sys/malloc.h>
     54   1.1       rvb #include <sys/errno.h>
     55   1.1       rvb #include <sys/acct.h>
     56   1.1       rvb #include <sys/file.h>
     57   1.1       rvb #include <sys/uio.h>
     58   1.1       rvb #include <sys/namei.h>
     59   1.1       rvb #include <sys/ioctl.h>
     60   1.1       rvb #include <sys/mount.h>
     61   1.1       rvb #include <sys/proc.h>
     62   1.1       rvb #include <sys/select.h>
     63  1.61    dogcow #include <sys/vnode.h>
     64  1.49      elad #include <sys/kauth.h>
     65  1.49      elad 
     66   1.1       rvb #include <miscfs/genfs/genfs.h>
     67   1.1       rvb 
     68   1.4       rvb #include <coda/coda.h>
     69   1.4       rvb #include <coda/cnode.h>
     70   1.4       rvb #include <coda/coda_vnops.h>
     71   1.4       rvb #include <coda/coda_venus.h>
     72   1.4       rvb #include <coda/coda_opstats.h>
     73   1.4       rvb #include <coda/coda_subr.h>
     74   1.4       rvb #include <coda/coda_namecache.h>
     75   1.4       rvb #include <coda/coda_pioctl.h>
     76   1.1       rvb 
     77  1.40     perry /*
     78   1.1       rvb  * These flags select various performance enhancements.
     79   1.1       rvb  */
     80   1.3       rvb int coda_attr_cache  = 1;       /* Set to cache attributes in the kernel */
     81   1.3       rvb int coda_symlink_cache = 1;     /* Set to cache symbolic link information */
     82   1.3       rvb int coda_access_cache = 1;      /* Set to handle some access checks directly */
     83   1.1       rvb 
     84   1.1       rvb /* structure to keep track of vfs calls */
     85   1.1       rvb 
     86   1.3       rvb struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
     87   1.1       rvb 
     88   1.3       rvb #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
     89   1.3       rvb #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
     90   1.3       rvb #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
     91   1.3       rvb #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
     92   1.1       rvb 
     93   1.1       rvb /* What we are delaying for in printf */
     94   1.3       rvb static int coda_lockdebug = 0;
     95   1.1       rvb 
     96  1.28     perry #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
     97   1.1       rvb 
     98   1.1       rvb /* Definition of the vnode operation vector */
     99   1.1       rvb 
    100  1.23  jdolecek const struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
    101   1.3       rvb     { &vop_default_desc, coda_vop_error },
    102   1.3       rvb     { &vop_lookup_desc, coda_lookup },		/* lookup */
    103   1.3       rvb     { &vop_create_desc, coda_create },		/* create */
    104   1.5       rvb     { &vop_mknod_desc, coda_vop_error },	/* mknod */
    105   1.3       rvb     { &vop_open_desc, coda_open },		/* open */
    106   1.3       rvb     { &vop_close_desc, coda_close },		/* close */
    107   1.3       rvb     { &vop_access_desc, coda_access },		/* access */
    108   1.5       rvb     { &vop_getattr_desc, coda_getattr },	/* getattr */
    109   1.5       rvb     { &vop_setattr_desc, coda_setattr },	/* setattr */
    110   1.3       rvb     { &vop_read_desc, coda_read },		/* read */
    111   1.3       rvb     { &vop_write_desc, coda_write },		/* write */
    112  1.11  wrstuden     { &vop_fcntl_desc, genfs_fcntl },		/* fcntl */
    113   1.3       rvb     { &vop_ioctl_desc, coda_ioctl },		/* ioctl */
    114  1.24       chs     { &vop_mmap_desc, genfs_mmap },		/* mmap */
    115   1.3       rvb     { &vop_fsync_desc, coda_fsync },		/* fsync */
    116   1.3       rvb     { &vop_remove_desc, coda_remove },		/* remove */
    117   1.3       rvb     { &vop_link_desc, coda_link },		/* link */
    118   1.3       rvb     { &vop_rename_desc, coda_rename },		/* rename */
    119   1.3       rvb     { &vop_mkdir_desc, coda_mkdir },		/* mkdir */
    120   1.3       rvb     { &vop_rmdir_desc, coda_rmdir },		/* rmdir */
    121   1.5       rvb     { &vop_symlink_desc, coda_symlink },	/* symlink */
    122   1.5       rvb     { &vop_readdir_desc, coda_readdir },	/* readdir */
    123   1.3       rvb     { &vop_readlink_desc, coda_readlink },	/* readlink */
    124   1.5       rvb     { &vop_abortop_desc, coda_abortop },	/* abortop */
    125   1.3       rvb     { &vop_inactive_desc, coda_inactive },	/* inactive */
    126   1.5       rvb     { &vop_reclaim_desc, coda_reclaim },	/* reclaim */
    127   1.3       rvb     { &vop_lock_desc, coda_lock },		/* lock */
    128   1.3       rvb     { &vop_unlock_desc, coda_unlock },		/* unlock */
    129   1.3       rvb     { &vop_bmap_desc, coda_bmap },		/* bmap */
    130   1.3       rvb     { &vop_strategy_desc, coda_strategy },	/* strategy */
    131   1.5       rvb     { &vop_print_desc, coda_vop_error },	/* print */
    132   1.3       rvb     { &vop_islocked_desc, coda_islocked },	/* islocked */
    133   1.3       rvb     { &vop_pathconf_desc, coda_vop_error },	/* pathconf */
    134   1.5       rvb     { &vop_advlock_desc, coda_vop_nop },	/* advlock */
    135   1.3       rvb     { &vop_bwrite_desc, coda_vop_error },	/* bwrite */
    136   1.1       rvb     { &vop_seek_desc, genfs_seek },		/* seek */
    137   1.5       rvb     { &vop_poll_desc, genfs_poll },		/* poll */
    138  1.25       chs     { &vop_getpages_desc, coda_getpages },	/* getpages */
    139  1.25       chs     { &vop_putpages_desc, coda_putpages },	/* putpages */
    140  1.24       chs     { NULL, NULL }
    141   1.1       rvb };
    142   1.1       rvb 
    143  1.40     perry const struct vnodeopv_desc coda_vnodeop_opv_desc =
    144   1.3       rvb         { &coda_vnodeop_p, coda_vnodeop_entries };
    145   1.1       rvb 
    146   1.1       rvb /* Definitions of NetBSD vnodeop interfaces */
    147   1.1       rvb 
    148  1.54       gdt /*
    149  1.54       gdt  * A generic error routine.  Return EIO without looking at arguments.
    150  1.54       gdt  */
    151   1.1       rvb int
    152   1.3       rvb coda_vop_error(void *anon) {
    153   1.1       rvb     struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
    154   1.1       rvb 
    155  1.54       gdt     if (codadebug) {
    156  1.84  christos 	myprintf(("%s: Vnode operation %s called (error).\n",
    157  1.84  christos 	    __func__, (*desc)->vdesc_name));
    158  1.54       gdt     }
    159  1.54       gdt 
    160   1.9       rvb     return EIO;
    161   1.1       rvb }
    162   1.1       rvb 
    163  1.67        ad /* A generic do-nothing. */
    164   1.1       rvb int
    165   1.3       rvb coda_vop_nop(void *anon) {
    166   1.1       rvb     struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
    167   1.1       rvb 
    168   1.3       rvb     if (codadebug) {
    169   1.1       rvb 	myprintf(("Vnode operation %s called, but unsupported\n",
    170   1.1       rvb 		  (*desc)->vdesc_name));
    171  1.40     perry     }
    172   1.1       rvb    return (0);
    173   1.1       rvb }
    174   1.1       rvb 
    175   1.1       rvb int
    176   1.3       rvb coda_vnodeopstats_init(void)
    177   1.1       rvb {
    178  1.17  augustss 	int i;
    179  1.40     perry 
    180   1.3       rvb 	for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
    181   1.3       rvb 		coda_vnodeopstats[i].opcode = i;
    182   1.3       rvb 		coda_vnodeopstats[i].entries = 0;
    183   1.3       rvb 		coda_vnodeopstats[i].sat_intrn = 0;
    184   1.3       rvb 		coda_vnodeopstats[i].unsat_intrn = 0;
    185   1.3       rvb 		coda_vnodeopstats[i].gen_intrn = 0;
    186   1.1       rvb 	}
    187  1.40     perry 
    188   1.1       rvb 	return 0;
    189   1.1       rvb }
    190  1.40     perry 
    191  1.40     perry /*
    192  1.58       gdt  * XXX The entire relationship between VOP_OPEN and having a container
    193  1.58       gdt  * file (via venus_open) needs to be reexamined.  In particular, it's
    194  1.58       gdt  * valid to open/mmap/close and then reference.  Instead of doing
    195  1.58       gdt  * VOP_OPEN when getpages needs a container, we should do the
    196  1.58       gdt  * venus_open part, and record that the vnode has opened the container
    197  1.58       gdt  * for getpages, and do the matching logical close on coda_inactive.
    198  1.58       gdt  * Further, coda_rdwr needs a container file, and sometimes needs to
    199  1.58       gdt  * do the equivalent of open (core dumps).
    200  1.58       gdt  */
    201  1.58       gdt /*
    202  1.55       gdt  * coda_open calls Venus to return the device and inode of the
    203  1.55       gdt  * container file, and then obtains a vnode for that file.  The
    204  1.55       gdt  * container vnode is stored in the coda vnode, and a reference is
    205  1.55       gdt  * added for each open file.
    206   1.1       rvb  */
    207   1.1       rvb int
    208  1.43   xtraeme coda_open(void *v)
    209   1.1       rvb {
    210  1.40     perry     /*
    211   1.1       rvb      * NetBSD can pass the O_EXCL flag in mode, even though the check
    212   1.1       rvb      * has already happened.  Venus defensively assumes that if open
    213   1.1       rvb      * is passed the EXCL, it must be a bug.  We strip the flag here.
    214   1.1       rvb      */
    215   1.1       rvb /* true args */
    216   1.1       rvb     struct vop_open_args *ap = v;
    217  1.84  christos     vnode_t *vp = ap->a_vp;
    218  1.55       gdt     struct cnode *cp = VTOC(vp);
    219   1.1       rvb     int flag = ap->a_mode & (~O_EXCL);
    220  1.49      elad     kauth_cred_t cred = ap->a_cred;
    221   1.1       rvb /* locals */
    222   1.1       rvb     int error;
    223  1.55       gdt     dev_t dev;			/* container file device, inode, vnode */
    224   1.1       rvb     ino_t inode;
    225  1.84  christos     vnode_t *container_vp;
    226   1.1       rvb 
    227   1.3       rvb     MARK_ENTRY(CODA_OPEN_STATS);
    228   1.1       rvb 
    229   1.1       rvb     /* Check for open of control file. */
    230  1.55       gdt     if (IS_CTL_VP(vp)) {
    231  1.40     perry 	/* if (WRITABLE(flag)) */
    232   1.1       rvb 	if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
    233   1.3       rvb 	    MARK_INT_FAIL(CODA_OPEN_STATS);
    234   1.1       rvb 	    return(EACCES);
    235   1.1       rvb 	}
    236   1.3       rvb 	MARK_INT_SAT(CODA_OPEN_STATS);
    237   1.1       rvb 	return(0);
    238   1.1       rvb     }
    239   1.1       rvb 
    240  1.63     pooka     error = venus_open(vtomi(vp), &cp->c_fid, flag, cred, curlwp, &dev, &inode);
    241   1.1       rvb     if (error)
    242   1.1       rvb 	return (error);
    243   1.1       rvb     if (!error) {
    244  1.84  christos 	    CODADEBUG(CODA_OPEN, myprintf((
    245  1.84  christos 		"%s: dev 0x%llx inode %llu result %d\n", __func__,
    246  1.84  christos 		(unsigned long long)dev, (unsigned long long)inode, error));)
    247   1.1       rvb     }
    248   1.1       rvb 
    249  1.55       gdt     /*
    250  1.55       gdt      * Obtain locked and referenced container vnode from container
    251  1.58       gdt      * device/inode.
    252  1.55       gdt      */
    253  1.83  christos     error = coda_grab_vnode(vp, dev, inode, &container_vp);
    254   1.1       rvb     if (error)
    255   1.1       rvb 	return (error);
    256   1.1       rvb 
    257  1.55       gdt     /* Save the vnode pointer for the container file. */
    258   1.1       rvb     if (cp->c_ovp == NULL) {
    259  1.55       gdt 	cp->c_ovp = container_vp;
    260   1.1       rvb     } else {
    261  1.55       gdt 	if (cp->c_ovp != container_vp)
    262  1.55       gdt 	    /*
    263  1.55       gdt 	     * Perhaps venus returned a different container, or
    264  1.55       gdt 	     * something else went wrong.
    265  1.55       gdt 	     */
    266  1.84  christos 	    panic("%s: cp->c_ovp != container_vp", __func__);
    267   1.1       rvb     }
    268   1.1       rvb     cp->c_ocount++;
    269   1.1       rvb 
    270  1.55       gdt     /* Flush the attribute cache if writing the file. */
    271   1.1       rvb     if (flag & FWRITE) {
    272   1.1       rvb 	cp->c_owrite++;
    273   1.1       rvb 	cp->c_flags &= ~C_VATTR;
    274   1.1       rvb     }
    275   1.1       rvb 
    276  1.60       gdt     /*
    277  1.60       gdt      * Save the <device, inode> pair for the container file to speed
    278  1.60       gdt      * up subsequent reads while closed (mmap, program execution).
    279  1.60       gdt      * This is perhaps safe because venus will invalidate the node
    280  1.60       gdt      * before changing the container file mapping.
    281  1.60       gdt      */
    282   1.1       rvb     cp->c_device = dev;
    283   1.1       rvb     cp->c_inode = inode;
    284   1.1       rvb 
    285  1.60       gdt     /* Open the container file. */
    286  1.63     pooka     error = VOP_OPEN(container_vp, flag, cred);
    287  1.55       gdt     /*
    288  1.55       gdt      * Drop the lock on the container, after we have done VOP_OPEN
    289  1.55       gdt      * (which requires a locked vnode).
    290  1.55       gdt      */
    291  1.74   hannken     VOP_UNLOCK(container_vp);
    292   1.1       rvb     return(error);
    293   1.1       rvb }
    294   1.1       rvb 
    295   1.1       rvb /*
    296   1.1       rvb  * Close the cache file used for I/O and notify Venus.
    297   1.1       rvb  */
    298   1.1       rvb int
    299  1.43   xtraeme coda_close(void *v)
    300   1.1       rvb {
    301   1.1       rvb /* true args */
    302   1.1       rvb     struct vop_close_args *ap = v;
    303  1.84  christos     vnode_t *vp = ap->a_vp;
    304   1.1       rvb     struct cnode *cp = VTOC(vp);
    305   1.1       rvb     int flag = ap->a_fflag;
    306  1.49      elad     kauth_cred_t cred = ap->a_cred;
    307   1.1       rvb /* locals */
    308   1.1       rvb     int error;
    309   1.1       rvb 
    310   1.3       rvb     MARK_ENTRY(CODA_CLOSE_STATS);
    311   1.1       rvb 
    312   1.1       rvb     /* Check for close of control file. */
    313   1.1       rvb     if (IS_CTL_VP(vp)) {
    314   1.3       rvb 	MARK_INT_SAT(CODA_CLOSE_STATS);
    315   1.1       rvb 	return(0);
    316   1.1       rvb     }
    317   1.1       rvb 
    318  1.55       gdt     /*
    319  1.58       gdt      * XXX The IS_UNMOUNTING part of this is very suspect.
    320  1.55       gdt      */
    321   1.1       rvb     if (IS_UNMOUNTING(cp)) {
    322   1.1       rvb 	if (cp->c_ovp) {
    323   1.7       rvb #ifdef	CODA_VERBOSE
    324  1.84  christos 	    printf("%s: destroying container %d, ufs vp %p of vp %p/cp %p\n",
    325  1.84  christos 		__func__, vp->v_usecount, cp->c_ovp, vp, cp);
    326   1.5       rvb #endif
    327   1.8       rvb #ifdef	hmm
    328   1.1       rvb 	    vgone(cp->c_ovp);
    329   1.8       rvb #else
    330  1.14  wrstuden 	    vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
    331  1.63     pooka 	    VOP_CLOSE(cp->c_ovp, flag, cred); /* Do errors matter here? */
    332  1.14  wrstuden 	    vput(cp->c_ovp);
    333   1.8       rvb #endif
    334   1.1       rvb 	} else {
    335   1.7       rvb #ifdef	CODA_VERBOSE
    336  1.84  christos 	    printf("%s: NO container vp %p/cp %p\n", __func__, vp, cp);
    337   1.5       rvb #endif
    338   1.1       rvb 	}
    339   1.1       rvb 	return ENODEV;
    340   1.1       rvb     }
    341   1.1       rvb 
    342  1.58       gdt     /* Lock the container node, and VOP_CLOSE it. */
    343  1.55       gdt     vn_lock(cp->c_ovp, LK_EXCLUSIVE | LK_RETRY);
    344  1.63     pooka     VOP_CLOSE(cp->c_ovp, flag, cred); /* Do errors matter here? */
    345  1.55       gdt     /*
    346  1.55       gdt      * Drop the lock we just obtained, and vrele the container vnode.
    347  1.55       gdt      * Decrement reference counts, and clear container vnode pointer on
    348  1.55       gdt      * last close.
    349  1.55       gdt      */
    350  1.55       gdt     vput(cp->c_ovp);
    351  1.55       gdt     if (flag & FWRITE)
    352  1.55       gdt 	--cp->c_owrite;
    353   1.1       rvb     if (--cp->c_ocount == 0)
    354   1.1       rvb 	cp->c_ovp = NULL;
    355   1.1       rvb 
    356  1.63     pooka     error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, curlwp);
    357  1.54       gdt 
    358  1.84  christos     CODADEBUG(CODA_CLOSE, myprintf(("%s: result %d\n", __func__, error)); )
    359   1.1       rvb     return(error);
    360   1.1       rvb }
    361   1.1       rvb 
    362   1.1       rvb int
    363  1.43   xtraeme coda_read(void *v)
    364   1.1       rvb {
    365   1.1       rvb     struct vop_read_args *ap = v;
    366   1.1       rvb 
    367   1.1       rvb     ENTRY;
    368   1.3       rvb     return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
    369  1.47      yamt 		    ap->a_ioflag, ap->a_cred, curlwp));
    370   1.1       rvb }
    371   1.1       rvb 
    372   1.1       rvb int
    373  1.43   xtraeme coda_write(void *v)
    374   1.1       rvb {
    375   1.1       rvb     struct vop_write_args *ap = v;
    376   1.1       rvb 
    377   1.1       rvb     ENTRY;
    378   1.3       rvb     return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
    379  1.47      yamt 		    ap->a_ioflag, ap->a_cred, curlwp));
    380   1.1       rvb }
    381   1.1       rvb 
    382   1.1       rvb int
    383  1.84  christos coda_rdwr(vnode_t *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
    384  1.49      elad 	kauth_cred_t cred, struct lwp *l)
    385  1.40     perry {
    386   1.1       rvb /* upcall decl */
    387   1.1       rvb   /* NOTE: container file operation!!! */
    388   1.1       rvb /* locals */
    389   1.1       rvb     struct cnode *cp = VTOC(vp);
    390  1.84  christos     vnode_t *cfvp = cp->c_ovp;
    391  1.45  christos     struct proc *p = l->l_proc;
    392   1.1       rvb     int opened_internally = 0;
    393   1.1       rvb     int error = 0;
    394   1.1       rvb 
    395   1.3       rvb     MARK_ENTRY(CODA_RDWR_STATS);
    396   1.1       rvb 
    397  1.47      yamt     CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %lu, %lld)\n", rw,
    398  1.84  christos 	uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid,
    399  1.84  christos 	(long long) uiop->uio_offset)); )
    400  1.40     perry 
    401   1.1       rvb     /* Check for rdwr of control object. */
    402   1.1       rvb     if (IS_CTL_VP(vp)) {
    403   1.3       rvb 	MARK_INT_FAIL(CODA_RDWR_STATS);
    404   1.1       rvb 	return(EINVAL);
    405   1.1       rvb     }
    406   1.1       rvb 
    407   1.1       rvb     /* Redirect the request to UFS. */
    408   1.1       rvb 
    409  1.40     perry     /*
    410   1.1       rvb      * If file is not already open this must be a page
    411   1.1       rvb      * {read,write} request.  Iget the cache file's inode
    412   1.1       rvb      * pointer if we still have its <device, inode> pair.
    413   1.1       rvb      * Otherwise, we must do an internal open to derive the
    414  1.40     perry      * pair.
    415  1.58       gdt      * XXX Integrate this into a coherent strategy for container
    416  1.58       gdt      * file acquisition.
    417   1.1       rvb      */
    418   1.1       rvb     if (cfvp == NULL) {
    419  1.40     perry 	/*
    420   1.1       rvb 	 * If we're dumping core, do the internal open. Otherwise
    421   1.1       rvb 	 * venus won't have the correct size of the core when
    422   1.1       rvb 	 * it's completely written.
    423   1.1       rvb 	 */
    424  1.40     perry 	if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) {
    425  1.84  christos 	    printf("%s: grabbing container vnode, losing reference\n",
    426  1.84  christos 		__func__);
    427  1.58       gdt 	    /* Get locked and refed vnode. */
    428  1.83  christos 	    error = coda_grab_vnode(vp, cp->c_device, cp->c_inode, &cfvp);
    429   1.1       rvb 	    if (error) {
    430   1.3       rvb 		MARK_INT_FAIL(CODA_RDWR_STATS);
    431   1.1       rvb 		return(error);
    432   1.1       rvb 	    }
    433  1.58       gdt 	    /*
    434  1.58       gdt 	     * Drop lock.
    435  1.58       gdt 	     * XXX Where is reference released.
    436   1.1       rvb 	     */
    437  1.74   hannken 	    VOP_UNLOCK(cfvp);
    438   1.1       rvb 	}
    439   1.1       rvb 	else {
    440  1.84  christos 	    printf("%s: internal VOP_OPEN\n", __func__);
    441   1.1       rvb 	    opened_internally = 1;
    442   1.3       rvb 	    MARK_INT_GEN(CODA_OPEN_STATS);
    443  1.63     pooka 	    error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE), cred);
    444  1.18      phil #ifdef	CODA_VERBOSE
    445  1.84  christos 	    printf("%s: Internally Opening %p\n", __func__, vp);
    446  1.18      phil #endif
    447   1.1       rvb 	    if (error) {
    448   1.3       rvb 		MARK_INT_FAIL(CODA_RDWR_STATS);
    449   1.1       rvb 		return(error);
    450   1.1       rvb 	    }
    451   1.1       rvb 	    cfvp = cp->c_ovp;
    452   1.1       rvb 	}
    453   1.1       rvb     }
    454   1.1       rvb 
    455   1.1       rvb     /* Have UFS handle the call. */
    456  1.84  christos     CODADEBUG(CODA_RDWR, myprintf(("%s: fid = %s, refcnt = %d\n", __func__,
    457  1.84  christos 	coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); )
    458   1.1       rvb 
    459   1.1       rvb     if (rw == UIO_READ) {
    460   1.1       rvb 	error = VOP_READ(cfvp, uiop, ioflag, cred);
    461   1.1       rvb     } else {
    462   1.1       rvb 	error = VOP_WRITE(cfvp, uiop, ioflag, cred);
    463   1.1       rvb     }
    464   1.1       rvb 
    465   1.1       rvb     if (error)
    466   1.3       rvb 	MARK_INT_FAIL(CODA_RDWR_STATS);
    467   1.1       rvb     else
    468   1.3       rvb 	MARK_INT_SAT(CODA_RDWR_STATS);
    469   1.1       rvb 
    470   1.1       rvb     /* Do an internal close if necessary. */
    471   1.1       rvb     if (opened_internally) {
    472   1.3       rvb 	MARK_INT_GEN(CODA_CLOSE_STATS);
    473  1.63     pooka 	(void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred);
    474   1.1       rvb     }
    475   1.1       rvb 
    476   1.1       rvb     /* Invalidate cached attributes if writing. */
    477   1.1       rvb     if (rw == UIO_WRITE)
    478   1.1       rvb 	cp->c_flags &= ~C_VATTR;
    479   1.1       rvb     return(error);
    480   1.1       rvb }
    481   1.1       rvb 
    482   1.1       rvb int
    483  1.43   xtraeme coda_ioctl(void *v)
    484   1.1       rvb {
    485   1.1       rvb /* true args */
    486   1.1       rvb     struct vop_ioctl_args *ap = v;
    487  1.84  christos     vnode_t *vp = ap->a_vp;
    488   1.1       rvb     int com = ap->a_command;
    489  1.52  christos     void *data = ap->a_data;
    490   1.1       rvb     int flag = ap->a_fflag;
    491  1.49      elad     kauth_cred_t cred = ap->a_cred;
    492   1.1       rvb /* locals */
    493   1.1       rvb     int error;
    494  1.84  christos     vnode_t *tvp;
    495   1.1       rvb     struct PioctlData *iap = (struct PioctlData *)data;
    496  1.70  dholland     namei_simple_flags_t sflags;
    497   1.1       rvb 
    498   1.3       rvb     MARK_ENTRY(CODA_IOCTL_STATS);
    499   1.1       rvb 
    500   1.3       rvb     CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
    501  1.40     perry 
    502   1.1       rvb     /* Don't check for operation on a dying object, for ctlvp it
    503   1.1       rvb        shouldn't matter */
    504  1.40     perry 
    505   1.1       rvb     /* Must be control object to succeed. */
    506   1.1       rvb     if (!IS_CTL_VP(vp)) {
    507   1.3       rvb 	MARK_INT_FAIL(CODA_IOCTL_STATS);
    508  1.84  christos 	CODADEBUG(CODA_IOCTL, myprintf(("%s error: vp != ctlvp", __func__));)
    509  1.84  christos 	return (EOPNOTSUPP);
    510   1.1       rvb     }
    511   1.1       rvb     /* Look up the pathname. */
    512   1.1       rvb 
    513   1.1       rvb     /* Should we use the name cache here? It would get it from
    514   1.1       rvb        lookupname sooner or later anyway, right? */
    515   1.1       rvb 
    516  1.70  dholland     sflags = iap->follow ? NSM_FOLLOW_NOEMULROOT : NSM_NOFOLLOW_NOEMULROOT;
    517  1.70  dholland     error = namei_simple_user(iap->path, sflags, &tvp);
    518   1.1       rvb 
    519   1.1       rvb     if (error) {
    520   1.3       rvb 	MARK_INT_FAIL(CODA_IOCTL_STATS);
    521  1.84  christos 	CODADEBUG(CODA_IOCTL, myprintf(("%s error: lookup returns %d\n",
    522  1.84  christos 	    __func__, error));)
    523   1.1       rvb 	return(error);
    524   1.1       rvb     }
    525   1.1       rvb 
    526  1.40     perry     /*
    527   1.1       rvb      * Make sure this is a coda style cnode, but it may be a
    528  1.40     perry      * different vfsp
    529   1.1       rvb      */
    530   1.1       rvb     /* XXX: this totally violates the comment about vtagtype in vnode.h */
    531   1.3       rvb     if (tvp->v_tag != VT_CODA) {
    532   1.1       rvb 	vrele(tvp);
    533   1.3       rvb 	MARK_INT_FAIL(CODA_IOCTL_STATS);
    534  1.84  christos 	CODADEBUG(CODA_IOCTL, myprintf(("%s error: %s not a coda object\n",
    535  1.84  christos 	    __func__, iap->path));)
    536   1.1       rvb 	return(EINVAL);
    537   1.1       rvb     }
    538   1.1       rvb 
    539  1.76  christos     if (iap->vi.in_size > VC_MAXDATASIZE || iap->vi.out_size > VC_MAXDATASIZE) {
    540   1.1       rvb 	vrele(tvp);
    541   1.1       rvb 	return(EINVAL);
    542   1.1       rvb     }
    543  1.63     pooka     error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data,
    544  1.63     pooka 	cred, curlwp);
    545   1.1       rvb 
    546   1.1       rvb     if (error)
    547   1.3       rvb 	MARK_INT_FAIL(CODA_IOCTL_STATS);
    548   1.1       rvb     else
    549   1.3       rvb 	CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
    550   1.1       rvb 
    551   1.1       rvb     vrele(tvp);
    552   1.1       rvb     return(error);
    553   1.1       rvb }
    554   1.1       rvb 
    555   1.1       rvb /*
    556   1.1       rvb  * To reduce the cost of a user-level venus;we cache attributes in
    557   1.1       rvb  * the kernel.  Each cnode has storage allocated for an attribute. If
    558   1.1       rvb  * c_vattr is valid, return a reference to it. Otherwise, get the
    559   1.1       rvb  * attributes from venus and store them in the cnode.  There is some
    560   1.1       rvb  * question if this method is a security leak. But I think that in
    561   1.1       rvb  * order to make this call, the user must have done a lookup and
    562  1.40     perry  * opened the file, and therefore should already have access.
    563   1.1       rvb  */
    564   1.1       rvb int
    565  1.43   xtraeme coda_getattr(void *v)
    566   1.1       rvb {
    567   1.1       rvb /* true args */
    568   1.1       rvb     struct vop_getattr_args *ap = v;
    569  1.84  christos     vnode_t *vp = ap->a_vp;
    570   1.1       rvb     struct cnode *cp = VTOC(vp);
    571   1.1       rvb     struct vattr *vap = ap->a_vap;
    572  1.49      elad     kauth_cred_t cred = ap->a_cred;
    573   1.1       rvb /* locals */
    574   1.1       rvb     int error;
    575   1.1       rvb 
    576   1.3       rvb     MARK_ENTRY(CODA_GETATTR_STATS);
    577   1.1       rvb 
    578   1.1       rvb     /* Check for getattr of control object. */
    579   1.1       rvb     if (IS_CTL_VP(vp)) {
    580   1.3       rvb 	MARK_INT_FAIL(CODA_GETATTR_STATS);
    581   1.1       rvb 	return(ENOENT);
    582   1.1       rvb     }
    583   1.1       rvb 
    584   1.1       rvb     /* Check to see if the attributes have already been cached */
    585  1.40     perry     if (VALID_VATTR(cp)) {
    586  1.84  christos 	CODADEBUG(CODA_GETATTR, { myprintf(("%s: attr cache hit: %s\n",
    587  1.84  christos 	    __func__, coda_f2s(&cp->c_fid)));})
    588   1.3       rvb 	CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
    589  1.84  christos 	    print_vattr(&cp->c_vattr); )
    590  1.40     perry 
    591   1.1       rvb 	*vap = cp->c_vattr;
    592   1.3       rvb 	MARK_INT_SAT(CODA_GETATTR_STATS);
    593   1.1       rvb 	return(0);
    594   1.1       rvb     }
    595   1.1       rvb 
    596  1.63     pooka     error = venus_getattr(vtomi(vp), &cp->c_fid, cred, curlwp, vap);
    597   1.1       rvb 
    598   1.1       rvb     if (!error) {
    599  1.84  christos 	CODADEBUG(CODA_GETATTR, myprintf(("%s miss %s: result %d\n",
    600  1.84  christos 	    __func__, coda_f2s(&cp->c_fid), error)); )
    601  1.40     perry 
    602   1.3       rvb 	CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
    603  1.84  christos 	    print_vattr(vap);	)
    604  1.40     perry 
    605  1.40     perry 	/* If not open for write, store attributes in cnode */
    606  1.40     perry 	if ((cp->c_owrite == 0) && (coda_attr_cache)) {
    607   1.1       rvb 	    cp->c_vattr = *vap;
    608  1.40     perry 	    cp->c_flags |= C_VATTR;
    609   1.1       rvb 	}
    610  1.40     perry 
    611   1.1       rvb     }
    612   1.1       rvb     return(error);
    613   1.1       rvb }
    614   1.1       rvb 
    615   1.1       rvb int
    616  1.43   xtraeme coda_setattr(void *v)
    617   1.1       rvb {
    618   1.1       rvb /* true args */
    619   1.1       rvb     struct vop_setattr_args *ap = v;
    620  1.84  christos     vnode_t *vp = ap->a_vp;
    621   1.1       rvb     struct cnode *cp = VTOC(vp);
    622  1.17  augustss     struct vattr *vap = ap->a_vap;
    623  1.49      elad     kauth_cred_t cred = ap->a_cred;
    624   1.1       rvb /* locals */
    625   1.1       rvb     int error;
    626   1.1       rvb 
    627   1.3       rvb     MARK_ENTRY(CODA_SETATTR_STATS);
    628   1.1       rvb 
    629   1.1       rvb     /* Check for setattr of control object. */
    630   1.1       rvb     if (IS_CTL_VP(vp)) {
    631   1.3       rvb 	MARK_INT_FAIL(CODA_SETATTR_STATS);
    632   1.1       rvb 	return(ENOENT);
    633   1.1       rvb     }
    634   1.1       rvb 
    635   1.3       rvb     if (codadebug & CODADBGMSK(CODA_SETATTR)) {
    636   1.1       rvb 	print_vattr(vap);
    637   1.1       rvb     }
    638  1.63     pooka     error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, curlwp);
    639   1.1       rvb 
    640   1.1       rvb     if (!error)
    641   1.1       rvb 	cp->c_flags &= ~C_VATTR;
    642   1.1       rvb 
    643   1.3       rvb     CODADEBUG(CODA_SETATTR,	myprintf(("setattr %d\n", error)); )
    644   1.1       rvb     return(error);
    645   1.1       rvb }
    646   1.1       rvb 
    647   1.1       rvb int
    648  1.43   xtraeme coda_access(void *v)
    649   1.1       rvb {
    650   1.1       rvb /* true args */
    651   1.1       rvb     struct vop_access_args *ap = v;
    652  1.84  christos     vnode_t *vp = ap->a_vp;
    653   1.1       rvb     struct cnode *cp = VTOC(vp);
    654   1.1       rvb     int mode = ap->a_mode;
    655  1.49      elad     kauth_cred_t cred = ap->a_cred;
    656   1.1       rvb /* locals */
    657   1.1       rvb     int error;
    658   1.1       rvb 
    659   1.3       rvb     MARK_ENTRY(CODA_ACCESS_STATS);
    660   1.1       rvb 
    661   1.1       rvb     /* Check for access of control object.  Only read access is
    662   1.1       rvb        allowed on it. */
    663   1.1       rvb     if (IS_CTL_VP(vp)) {
    664   1.1       rvb 	/* bogus hack - all will be marked as successes */
    665   1.3       rvb 	MARK_INT_SAT(CODA_ACCESS_STATS);
    666  1.40     perry 	return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
    667   1.1       rvb 	       ? 0 : EACCES);
    668   1.1       rvb     }
    669   1.1       rvb 
    670   1.1       rvb     /*
    671  1.40     perry      * if the file is a directory, and we are checking exec (eg lookup)
    672  1.40     perry      * access, and the file is in the namecache, then the user must have
    673   1.1       rvb      * lookup access to it.
    674   1.1       rvb      */
    675   1.3       rvb     if (coda_access_cache) {
    676   1.1       rvb 	if ((vp->v_type == VDIR) && (mode & VEXEC)) {
    677   1.3       rvb 	    if (coda_nc_lookup(cp, ".", 1, cred)) {
    678   1.3       rvb 		MARK_INT_SAT(CODA_ACCESS_STATS);
    679   1.1       rvb 		return(0);                     /* it was in the cache */
    680   1.1       rvb 	    }
    681   1.1       rvb 	}
    682   1.1       rvb     }
    683   1.1       rvb 
    684  1.63     pooka     error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, curlwp);
    685   1.1       rvb 
    686   1.1       rvb     return(error);
    687   1.1       rvb }
    688   1.1       rvb 
    689   1.1       rvb /*
    690   1.3       rvb  * CODA abort op, called after namei() when a CREATE/DELETE isn't actually
    691   1.3       rvb  * done. If a buffer has been saved in anticipation of a coda_create or
    692   1.3       rvb  * a coda_remove, delete it.
    693   1.1       rvb  */
    694   1.1       rvb /* ARGSUSED */
    695   1.1       rvb int
    696  1.43   xtraeme coda_abortop(void *v)
    697   1.1       rvb {
    698   1.1       rvb /* true args */
    699   1.1       rvb     struct vop_abortop_args /* {
    700  1.84  christos 	vnode_t *a_dvp;
    701   1.1       rvb 	struct componentname *a_cnp;
    702   1.1       rvb     } */ *ap = v;
    703  1.77  dholland 
    704  1.77  dholland     (void)ap;
    705   1.1       rvb /* upcall decl */
    706   1.1       rvb /* locals */
    707   1.1       rvb 
    708   1.1       rvb     return (0);
    709   1.1       rvb }
    710   1.1       rvb 
    711   1.1       rvb int
    712  1.43   xtraeme coda_readlink(void *v)
    713   1.1       rvb {
    714   1.1       rvb /* true args */
    715   1.1       rvb     struct vop_readlink_args *ap = v;
    716  1.84  christos     vnode_t *vp = ap->a_vp;
    717   1.1       rvb     struct cnode *cp = VTOC(vp);
    718   1.1       rvb     struct uio *uiop = ap->a_uio;
    719  1.49      elad     kauth_cred_t cred = ap->a_cred;
    720   1.1       rvb /* locals */
    721  1.47      yamt     struct lwp *l = curlwp;
    722   1.1       rvb     int error;
    723   1.1       rvb     char *str;
    724   1.1       rvb     int len;
    725   1.1       rvb 
    726   1.3       rvb     MARK_ENTRY(CODA_READLINK_STATS);
    727   1.1       rvb 
    728   1.1       rvb     /* Check for readlink of control object. */
    729   1.1       rvb     if (IS_CTL_VP(vp)) {
    730   1.3       rvb 	MARK_INT_FAIL(CODA_READLINK_STATS);
    731   1.1       rvb 	return(ENOENT);
    732   1.1       rvb     }
    733   1.1       rvb 
    734   1.3       rvb     if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
    735   1.1       rvb 	uiop->uio_rw = UIO_READ;
    736   1.1       rvb 	error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
    737   1.1       rvb 	if (error)
    738   1.3       rvb 	    MARK_INT_FAIL(CODA_READLINK_STATS);
    739   1.1       rvb 	else
    740   1.3       rvb 	    MARK_INT_SAT(CODA_READLINK_STATS);
    741   1.1       rvb 	return(error);
    742   1.1       rvb     }
    743   1.1       rvb 
    744  1.45  christos     error = venus_readlink(vtomi(vp), &cp->c_fid, cred, l, &str, &len);
    745   1.1       rvb 
    746   1.1       rvb     if (!error) {
    747   1.1       rvb 	uiop->uio_rw = UIO_READ;
    748   1.1       rvb 	error = uiomove(str, len, uiop);
    749   1.1       rvb 
    750   1.3       rvb 	if (coda_symlink_cache) {
    751   1.1       rvb 	    cp->c_symlink = str;
    752   1.1       rvb 	    cp->c_symlen = len;
    753   1.1       rvb 	    cp->c_flags |= C_SYMLINK;
    754   1.1       rvb 	} else
    755   1.3       rvb 	    CODA_FREE(str, len);
    756   1.1       rvb     }
    757   1.1       rvb 
    758   1.3       rvb     CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
    759   1.1       rvb     return(error);
    760   1.1       rvb }
    761   1.1       rvb 
    762   1.1       rvb int
    763  1.43   xtraeme coda_fsync(void *v)
    764   1.1       rvb {
    765   1.1       rvb /* true args */
    766   1.1       rvb     struct vop_fsync_args *ap = v;
    767  1.84  christos     vnode_t *vp = ap->a_vp;
    768   1.1       rvb     struct cnode *cp = VTOC(vp);
    769  1.49      elad     kauth_cred_t cred = ap->a_cred;
    770   1.1       rvb /* locals */
    771  1.84  christos     vnode_t *convp = cp->c_ovp;
    772   1.1       rvb     int error;
    773  1.40     perry 
    774   1.3       rvb     MARK_ENTRY(CODA_FSYNC_STATS);
    775   1.1       rvb 
    776   1.1       rvb     /* Check for fsync on an unmounting object */
    777   1.1       rvb     /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
    778   1.1       rvb      * after an unmount has been initiated.  This is a Bad Thing,
    779   1.1       rvb      * which we have to avoid.  Not a legitimate failure for stats.
    780   1.1       rvb      */
    781   1.1       rvb     if (IS_UNMOUNTING(cp)) {
    782   1.1       rvb 	return(ENODEV);
    783   1.1       rvb     }
    784   1.1       rvb 
    785   1.1       rvb     /* Check for fsync of control object. */
    786   1.1       rvb     if (IS_CTL_VP(vp)) {
    787   1.3       rvb 	MARK_INT_SAT(CODA_FSYNC_STATS);
    788   1.1       rvb 	return(0);
    789   1.1       rvb     }
    790   1.1       rvb 
    791   1.1       rvb     if (convp)
    792  1.63     pooka     	VOP_FSYNC(convp, cred, MNT_WAIT, 0, 0);
    793   1.1       rvb 
    794   1.1       rvb     /*
    795   1.1       rvb      * We can expect fsync on any vnode at all if venus is pruging it.
    796   1.1       rvb      * Venus can't very well answer the fsync request, now can it?
    797   1.1       rvb      * Hopefully, it won't have to, because hopefully, venus preserves
    798   1.1       rvb      * the (possibly untrue) invariant that it never purges an open
    799   1.1       rvb      * vnode.  Hopefully.
    800   1.1       rvb      */
    801   1.1       rvb     if (cp->c_flags & C_PURGING) {
    802   1.1       rvb 	return(0);
    803   1.1       rvb     }
    804   1.1       rvb 
    805  1.63     pooka     error = venus_fsync(vtomi(vp), &cp->c_fid, cred, curlwp);
    806   1.1       rvb 
    807  1.84  christos     CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); )
    808   1.1       rvb     return(error);
    809   1.1       rvb }
    810   1.1       rvb 
    811  1.60       gdt /*
    812  1.60       gdt  * vp is locked on entry, and we must unlock it.
    813  1.60       gdt  * XXX This routine is suspect and probably needs rewriting.
    814  1.60       gdt  */
    815   1.1       rvb int
    816  1.43   xtraeme coda_inactive(void *v)
    817   1.1       rvb {
    818   1.1       rvb /* true args */
    819   1.1       rvb     struct vop_inactive_args *ap = v;
    820  1.84  christos     vnode_t *vp = ap->a_vp;
    821   1.1       rvb     struct cnode *cp = VTOC(vp);
    822  1.65     perry     kauth_cred_t cred __unused = NULL;
    823   1.1       rvb 
    824   1.1       rvb     /* We don't need to send inactive to venus - DCS */
    825   1.3       rvb     MARK_ENTRY(CODA_INACTIVE_STATS);
    826   1.1       rvb 
    827   1.1       rvb     if (IS_CTL_VP(vp)) {
    828   1.3       rvb 	MARK_INT_SAT(CODA_INACTIVE_STATS);
    829   1.1       rvb 	return 0;
    830   1.1       rvb     }
    831   1.1       rvb 
    832  1.37  drochner     CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %s, vfsp %p\n",
    833  1.37  drochner 				  coda_f2s(&cp->c_fid), vp->v_mount));)
    834   1.1       rvb 
    835   1.1       rvb     /* If an array has been allocated to hold the symlink, deallocate it */
    836   1.3       rvb     if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
    837   1.1       rvb 	if (cp->c_symlink == NULL)
    838  1.84  christos 	    panic("%s: null symlink pointer in cnode", __func__);
    839  1.40     perry 
    840   1.3       rvb 	CODA_FREE(cp->c_symlink, cp->c_symlen);
    841   1.1       rvb 	cp->c_flags &= ~C_SYMLINK;
    842   1.1       rvb 	cp->c_symlen = 0;
    843   1.1       rvb     }
    844   1.1       rvb 
    845   1.1       rvb     /* Remove it from the table so it can't be found. */
    846   1.3       rvb     coda_unsave(cp);
    847  1.31     soren     if (vp->v_mount->mnt_data == NULL) {
    848   1.1       rvb 	myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
    849  1.32    provos 	panic("badness in coda_inactive");
    850   1.1       rvb     }
    851   1.1       rvb 
    852   1.1       rvb     if (IS_UNMOUNTING(cp)) {
    853  1.60       gdt 	/* XXX Do we need to VOP_CLOSE container vnodes? */
    854  1.81       gdt 	if (vp->v_usecount > 1)
    855  1.84  christos 	    printf("%s: IS_UNMOUNTING %p usecount %d\n",
    856  1.84  christos 		__func__, vp, vp->v_usecount);
    857   1.1       rvb 	if (cp->c_ovp != NULL)
    858  1.84  christos 	    printf("%s: %p ovp != NULL\n", __func__, vp);
    859  1.74   hannken 	VOP_UNLOCK(vp);
    860   1.1       rvb     } else {
    861  1.60       gdt         /* Sanity checks that perhaps should be panic. */
    862  1.81       gdt 	if (vp->v_usecount > 1) {
    863  1.84  christos 	    printf("%s: %p usecount %d\n", __func__, vp, vp->v_usecount);
    864   1.1       rvb 	}
    865   1.1       rvb 	if (cp->c_ovp != NULL) {
    866  1.84  christos 	    printf("%s: %p ovp != NULL\n", __func__, vp);
    867   1.1       rvb 	}
    868  1.74   hannken 	VOP_UNLOCK(vp);
    869  1.66        ad 	*ap->a_recycle = true;
    870   1.1       rvb     }
    871   1.1       rvb 
    872   1.3       rvb     MARK_INT_SAT(CODA_INACTIVE_STATS);
    873   1.1       rvb     return(0);
    874   1.1       rvb }
    875   1.1       rvb 
    876   1.1       rvb /*
    877  1.60       gdt  * Coda does not use the normal namecache, but a private version.
    878  1.60       gdt  * Consider how to use the standard facility instead.
    879   1.1       rvb  */
    880   1.1       rvb int
    881  1.43   xtraeme coda_lookup(void *v)
    882   1.1       rvb {
    883   1.1       rvb /* true args */
    884   1.1       rvb     struct vop_lookup_args *ap = v;
    885  1.53       gdt     /* (locked) vnode of dir in which to do lookup */
    886  1.84  christos     vnode_t *dvp = ap->a_dvp;
    887   1.1       rvb     struct cnode *dcp = VTOC(dvp);
    888  1.53       gdt     /* output variable for result */
    889  1.84  christos     vnode_t **vpp = ap->a_vpp;
    890  1.53       gdt     /* name to lookup */
    891  1.53       gdt     struct componentname *cnp = ap->a_cnp;
    892  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
    893  1.64     pooka     struct lwp *l = curlwp;
    894   1.1       rvb /* locals */
    895   1.1       rvb     struct cnode *cp;
    896   1.1       rvb     const char *nm = cnp->cn_nameptr;
    897   1.1       rvb     int len = cnp->cn_namelen;
    898  1.53       gdt     int flags = cnp->cn_flags;
    899  1.54       gdt     int isdot;
    900  1.37  drochner     CodaFid VFid;
    901   1.1       rvb     int	vtype;
    902   1.1       rvb     int error = 0;
    903   1.1       rvb 
    904   1.3       rvb     MARK_ENTRY(CODA_LOOKUP_STATS);
    905   1.1       rvb 
    906  1.84  christos     CODADEBUG(CODA_LOOKUP, myprintf(("%s: %s in %s\n", __func__,
    907  1.84  christos 	nm, coda_f2s(&dcp->c_fid)));)
    908   1.1       rvb 
    909  1.53       gdt     /*
    910  1.53       gdt      * XXX componentname flags in MODMASK are not handled at all
    911  1.53       gdt      */
    912  1.53       gdt 
    913  1.53       gdt     /*
    914  1.53       gdt      * The overall strategy is to switch on the lookup type and get a
    915  1.53       gdt      * result vnode that is vref'd but not locked.  Then, the code at
    916  1.53       gdt      * exit: switches on ., .., and regular lookups and does the right
    917  1.53       gdt      * locking.
    918  1.53       gdt      */
    919  1.53       gdt 
    920   1.1       rvb     /* Check for lookup of control object. */
    921   1.1       rvb     if (IS_CTL_NAME(dvp, nm, len)) {
    922   1.3       rvb 	*vpp = coda_ctlvp;
    923   1.1       rvb 	vref(*vpp);
    924   1.3       rvb 	MARK_INT_SAT(CODA_LOOKUP_STATS);
    925   1.1       rvb 	goto exit;
    926   1.1       rvb     }
    927   1.1       rvb 
    928  1.53       gdt     /* Avoid trying to hand venus an unreasonably long name. */
    929   1.3       rvb     if (len+1 > CODA_MAXNAMLEN) {
    930   1.3       rvb 	MARK_INT_FAIL(CODA_LOOKUP_STATS);
    931  1.84  christos 	CODADEBUG(CODA_LOOKUP, myprintf(("%s: name too long:, %s (%s)\n",
    932  1.84  christos 	    __func__, coda_f2s(&dcp->c_fid), nm));)
    933  1.84  christos 	*vpp = (vnode_t *)0;
    934   1.1       rvb 	error = EINVAL;
    935   1.1       rvb 	goto exit;
    936   1.1       rvb     }
    937  1.53       gdt 
    938  1.53       gdt     /*
    939  1.60       gdt      * XXX Check for DOT lookups, and short circuit all the caches,
    940  1.54       gdt      * just doing an extra vref.  (venus guarantees that lookup of
    941  1.54       gdt      * . returns self.)
    942  1.54       gdt      */
    943  1.54       gdt     isdot = (len == 1 && nm[0] == '.');
    944  1.54       gdt 
    945  1.54       gdt     /*
    946  1.53       gdt      * Try to resolve the lookup in the minicache.  If that fails, ask
    947  1.53       gdt      * venus to do the lookup.  XXX The interaction between vnode
    948  1.53       gdt      * locking and any locking that coda does is not clear.
    949  1.53       gdt      */
    950   1.3       rvb     cp = coda_nc_lookup(dcp, nm, len, cred);
    951   1.1       rvb     if (cp) {
    952   1.1       rvb 	*vpp = CTOV(cp);
    953   1.1       rvb 	vref(*vpp);
    954  1.40     perry 	CODADEBUG(CODA_LOOKUP,
    955   1.1       rvb 		 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
    956   1.1       rvb     } else {
    957  1.53       gdt 	/* The name wasn't cached, so ask Venus. */
    958  1.45  christos 	error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, l, &VFid, &vtype);
    959  1.40     perry 
    960   1.1       rvb 	if (error) {
    961   1.3       rvb 	    MARK_INT_FAIL(CODA_LOOKUP_STATS);
    962  1.37  drochner 	    CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %s (%s)%d\n",
    963  1.37  drochner 					coda_f2s(&dcp->c_fid), nm, error));)
    964  1.84  christos 	    *vpp = (vnode_t *)0;
    965   1.1       rvb 	} else {
    966   1.3       rvb 	    MARK_INT_SAT(CODA_LOOKUP_STATS);
    967  1.84  christos 	    CODADEBUG(CODA_LOOKUP, myprintf(("%s: %s type %o result %d\n",
    968  1.84  christos 		__func__, coda_f2s(&VFid), vtype, error)); )
    969  1.40     perry 
    970   1.3       rvb 	    cp = make_coda_node(&VFid, dvp->v_mount, vtype);
    971   1.1       rvb 	    *vpp = CTOV(cp);
    972  1.53       gdt 	    /* vpp is now vrefed. */
    973  1.40     perry 
    974  1.53       gdt 	    /*
    975  1.53       gdt 	     * Unless this vnode is marked CODA_NOCACHE, enter it into
    976  1.53       gdt 	     * the coda name cache to avoid a future venus round-trip.
    977  1.53       gdt 	     * XXX Interaction with componentname NOCACHE is unclear.
    978  1.53       gdt 	     */
    979   1.3       rvb 	    if (!(vtype & CODA_NOCACHE))
    980   1.3       rvb 		coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
    981   1.1       rvb 	}
    982   1.1       rvb     }
    983   1.1       rvb 
    984   1.1       rvb  exit:
    985  1.40     perry     /*
    986   1.1       rvb      * If we are creating, and this was the last name to be looked up,
    987  1.53       gdt      * and the error was ENOENT, then make the leaf NULL and return
    988  1.53       gdt      * success.
    989  1.53       gdt      * XXX Check against new lookup rules.
    990   1.1       rvb      */
    991   1.1       rvb     if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
    992   1.1       rvb 	&& (cnp->cn_flags & ISLASTCN)
    993   1.1       rvb 	&& (error == ENOENT))
    994   1.1       rvb     {
    995   1.1       rvb 	error = EJUSTRETURN;
    996   1.1       rvb 	*ap->a_vpp = NULL;
    997   1.1       rvb     }
    998   1.1       rvb 
    999  1.40     perry     /*
   1000  1.53       gdt      * If the lookup succeeded, we must generally lock the returned
   1001  1.53       gdt      * vnode.  This could be a ., .., or normal lookup.  See
   1002  1.53       gdt      * vnodeops(9) for the details.
   1003  1.53       gdt      */
   1004  1.53       gdt     /*
   1005  1.53       gdt      * XXX LK_RETRY is likely incorrect.  Handle vn_lock failure
   1006  1.53       gdt      * somehow, and remove LK_RETRY.
   1007   1.1       rvb      */
   1008   1.1       rvb     if (!error || (error == EJUSTRETURN)) {
   1009  1.53       gdt 	/* Lookup has a value and it isn't "."? */
   1010  1.51       chs 	if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
   1011  1.53       gdt 	    if (flags & ISDOTDOT)
   1012  1.53       gdt 		/* ..: unlock parent */
   1013  1.74   hannken 		VOP_UNLOCK(dvp);
   1014  1.53       gdt 	    /* all but .: lock child */
   1015  1.53       gdt 	    vn_lock(*ap->a_vpp, LK_EXCLUSIVE | LK_RETRY);
   1016  1.53       gdt 	    if (flags & ISDOTDOT)
   1017  1.53       gdt 		/* ..: relock parent */
   1018  1.53       gdt 	        vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
   1019   1.1       rvb 	}
   1020  1.53       gdt 	/* else .: leave dvp locked */
   1021   1.1       rvb     } else {
   1022  1.53       gdt 	/* The lookup failed, so return NULL.  Leave dvp locked. */
   1023   1.1       rvb 	*ap->a_vpp = NULL;
   1024   1.1       rvb     }
   1025   1.1       rvb     return(error);
   1026   1.1       rvb }
   1027   1.1       rvb 
   1028   1.1       rvb /*ARGSUSED*/
   1029   1.1       rvb int
   1030  1.43   xtraeme coda_create(void *v)
   1031   1.1       rvb {
   1032   1.1       rvb /* true args */
   1033   1.1       rvb     struct vop_create_args *ap = v;
   1034  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1035   1.1       rvb     struct cnode *dcp = VTOC(dvp);
   1036   1.1       rvb     struct vattr *va = ap->a_vap;
   1037   1.1       rvb     int exclusive = 1;
   1038   1.1       rvb     int mode = ap->a_vap->va_mode;
   1039  1.84  christos     vnode_t **vpp = ap->a_vpp;
   1040   1.1       rvb     struct componentname  *cnp = ap->a_cnp;
   1041  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1042  1.64     pooka     struct lwp *l = curlwp;
   1043   1.1       rvb /* locals */
   1044   1.1       rvb     int error;
   1045   1.1       rvb     struct cnode *cp;
   1046   1.1       rvb     const char *nm = cnp->cn_nameptr;
   1047   1.1       rvb     int len = cnp->cn_namelen;
   1048  1.37  drochner     CodaFid VFid;
   1049   1.1       rvb     struct vattr attr;
   1050   1.1       rvb 
   1051   1.3       rvb     MARK_ENTRY(CODA_CREATE_STATS);
   1052   1.1       rvb 
   1053   1.1       rvb     /* All creates are exclusive XXX */
   1054   1.1       rvb     /* I'm assuming the 'mode' argument is the file mode bits XXX */
   1055   1.1       rvb 
   1056   1.1       rvb     /* Check for create of control object. */
   1057   1.1       rvb     if (IS_CTL_NAME(dvp, nm, len)) {
   1058  1.84  christos 	*vpp = (vnode_t *)0;
   1059   1.3       rvb 	MARK_INT_FAIL(CODA_CREATE_STATS);
   1060   1.1       rvb 	return(EACCES);
   1061   1.1       rvb     }
   1062   1.1       rvb 
   1063  1.45  christos     error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, l, &VFid, &attr);
   1064   1.1       rvb 
   1065   1.1       rvb     if (!error) {
   1066  1.40     perry 
   1067  1.54       gdt         /*
   1068  1.54       gdt 	 * XXX Violation of venus/kernel invariants is a difficult case,
   1069  1.54       gdt 	 * but venus should not be able to cause a panic.
   1070  1.54       gdt 	 */
   1071   1.1       rvb 	/* If this is an exclusive create, panic if the file already exists. */
   1072   1.1       rvb 	/* Venus should have detected the file and reported EEXIST. */
   1073   1.1       rvb 
   1074   1.1       rvb 	if ((exclusive == 1) &&
   1075   1.3       rvb 	    (coda_find(&VFid) != NULL))
   1076   1.1       rvb 	    panic("cnode existed for newly created file!");
   1077  1.40     perry 
   1078   1.3       rvb 	cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
   1079   1.1       rvb 	*vpp = CTOV(cp);
   1080  1.40     perry 
   1081  1.54       gdt 	/* XXX vnodeops doesn't say this argument can be changed. */
   1082   1.1       rvb 	/* Update va to reflect the new attributes. */
   1083   1.1       rvb 	(*va) = attr;
   1084  1.40     perry 
   1085   1.1       rvb 	/* Update the attribute cache and mark it as valid */
   1086   1.3       rvb 	if (coda_attr_cache) {
   1087   1.1       rvb 	    VTOC(*vpp)->c_vattr = attr;
   1088  1.40     perry 	    VTOC(*vpp)->c_flags |= C_VATTR;
   1089   1.1       rvb 	}
   1090   1.1       rvb 
   1091  1.54       gdt 	/* Invalidate parent's attr cache (modification time has changed). */
   1092   1.1       rvb 	VTOC(dvp)->c_flags &= ~C_VATTR;
   1093  1.40     perry 
   1094   1.1       rvb 	/* enter the new vnode in the Name Cache */
   1095   1.3       rvb 	coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
   1096  1.40     perry 
   1097  1.84  christos 	CODADEBUG(CODA_CREATE, myprintf(("%s: %s, result %d\n", __func__,
   1098  1.84  christos 	    coda_f2s(&VFid), error)); )
   1099   1.1       rvb     } else {
   1100  1.84  christos 	*vpp = (vnode_t *)0;
   1101   1.3       rvb 	CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
   1102   1.1       rvb     }
   1103   1.1       rvb 
   1104   1.1       rvb     /*
   1105  1.54       gdt      * vnodeops(9) says that we must unlock the parent and lock the child.
   1106  1.54       gdt      * XXX Should we lock the child first?
   1107   1.1       rvb      */
   1108   1.1       rvb     vput(dvp);
   1109   1.1       rvb     if (!error) {
   1110  1.54       gdt 	if ((cnp->cn_flags & LOCKLEAF) == 0) {
   1111  1.54       gdt 	    /* This should not happen; flags are for lookup only. */
   1112  1.84  christos 	    printf("%s: LOCKLEAF not set!\n", __func__);
   1113   1.1       rvb 	}
   1114  1.54       gdt 
   1115  1.54       gdt 	if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
   1116  1.54       gdt 	    /* XXX Perhaps avoid this panic. */
   1117  1.84  christos 	    panic("%s: couldn't lock child", __func__);
   1118   1.1       rvb 	}
   1119   1.1       rvb     }
   1120  1.54       gdt 
   1121   1.1       rvb     return(error);
   1122   1.1       rvb }
   1123   1.1       rvb 
   1124   1.1       rvb int
   1125  1.43   xtraeme coda_remove(void *v)
   1126   1.1       rvb {
   1127   1.1       rvb /* true args */
   1128   1.1       rvb     struct vop_remove_args *ap = v;
   1129  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1130   1.1       rvb     struct cnode *cp = VTOC(dvp);
   1131  1.84  christos     vnode_t *vp = ap->a_vp;
   1132   1.1       rvb     struct componentname  *cnp = ap->a_cnp;
   1133  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1134  1.64     pooka     struct lwp *l = curlwp;
   1135   1.1       rvb /* locals */
   1136   1.1       rvb     int error;
   1137   1.1       rvb     const char *nm = cnp->cn_nameptr;
   1138   1.1       rvb     int len = cnp->cn_namelen;
   1139   1.1       rvb     struct cnode *tp;
   1140   1.1       rvb 
   1141   1.3       rvb     MARK_ENTRY(CODA_REMOVE_STATS);
   1142   1.1       rvb 
   1143  1.84  christos     CODADEBUG(CODA_REMOVE, myprintf(("%s: %s in %s\n", __func__,
   1144  1.84  christos 	nm, coda_f2s(&cp->c_fid)));)
   1145   1.1       rvb 
   1146   1.3       rvb     /* Remove the file's entry from the CODA Name Cache */
   1147   1.1       rvb     /* We're being conservative here, it might be that this person
   1148   1.1       rvb      * doesn't really have sufficient access to delete the file
   1149   1.1       rvb      * but we feel zapping the entry won't really hurt anyone -- dcs
   1150   1.1       rvb      */
   1151   1.1       rvb     /* I'm gonna go out on a limb here. If a file and a hardlink to it
   1152   1.1       rvb      * exist, and one is removed, the link count on the other will be
   1153   1.1       rvb      * off by 1. We could either invalidate the attrs if cached, or
   1154   1.1       rvb      * fix them. I'll try to fix them. DCS 11/8/94
   1155   1.1       rvb      */
   1156   1.3       rvb     tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
   1157   1.1       rvb     if (tp) {
   1158   1.1       rvb 	if (VALID_VATTR(tp)) {	/* If attrs are cached */
   1159   1.1       rvb 	    if (tp->c_vattr.va_nlink > 1) {	/* If it's a hard link */
   1160   1.1       rvb 		tp->c_vattr.va_nlink--;
   1161   1.1       rvb 	    }
   1162   1.1       rvb 	}
   1163  1.40     perry 
   1164  1.40     perry 	coda_nc_zapfile(VTOC(dvp), nm, len);
   1165   1.1       rvb 	/* No need to flush it if it doesn't exist! */
   1166   1.1       rvb     }
   1167   1.1       rvb     /* Invalidate the parent's attr cache, the modification time has changed */
   1168   1.1       rvb     VTOC(dvp)->c_flags &= ~C_VATTR;
   1169   1.1       rvb 
   1170   1.1       rvb     /* Check for remove of control object. */
   1171   1.1       rvb     if (IS_CTL_NAME(dvp, nm, len)) {
   1172   1.3       rvb 	MARK_INT_FAIL(CODA_REMOVE_STATS);
   1173   1.1       rvb 	return(ENOENT);
   1174   1.1       rvb     }
   1175   1.1       rvb 
   1176  1.45  christos     error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, l);
   1177   1.1       rvb 
   1178   1.3       rvb     CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
   1179   1.1       rvb 
   1180  1.40     perry     /*
   1181  1.55       gdt      * Unlock parent and child (avoiding double if ".").
   1182   1.1       rvb      */
   1183  1.54       gdt     if (dvp == vp) {
   1184  1.54       gdt 	vrele(vp);
   1185   1.1       rvb     } else {
   1186  1.54       gdt 	vput(vp);
   1187   1.1       rvb     }
   1188   1.1       rvb     vput(dvp);
   1189   1.1       rvb 
   1190   1.1       rvb     return(error);
   1191   1.1       rvb }
   1192   1.1       rvb 
   1193  1.55       gdt /*
   1194  1.55       gdt  * dvp is the directory where the link is to go, and is locked.
   1195  1.55       gdt  * vp is the object to be linked to, and is unlocked.
   1196  1.55       gdt  * At exit, we must unlock dvp, and vput dvp.
   1197  1.55       gdt  */
   1198   1.1       rvb int
   1199  1.43   xtraeme coda_link(void *v)
   1200   1.1       rvb {
   1201   1.1       rvb /* true args */
   1202   1.1       rvb     struct vop_link_args *ap = v;
   1203  1.84  christos     vnode_t *vp = ap->a_vp;
   1204   1.1       rvb     struct cnode *cp = VTOC(vp);
   1205  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1206  1.55       gdt     struct cnode *dcp = VTOC(dvp);
   1207   1.1       rvb     struct componentname *cnp = ap->a_cnp;
   1208  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1209  1.64     pooka     struct lwp *l = curlwp;
   1210   1.1       rvb /* locals */
   1211   1.1       rvb     int error;
   1212   1.1       rvb     const char *nm = cnp->cn_nameptr;
   1213   1.1       rvb     int len = cnp->cn_namelen;
   1214   1.1       rvb 
   1215   1.3       rvb     MARK_ENTRY(CODA_LINK_STATS);
   1216   1.1       rvb 
   1217   1.3       rvb     if (codadebug & CODADBGMSK(CODA_LINK)) {
   1218   1.1       rvb 
   1219  1.84  christos 	myprintf(("%s: vp fid: %s\n", __func__, coda_f2s(&cp->c_fid)));
   1220  1.84  christos 	myprintf(("%s: dvp fid: %s)\n", __func__, coda_f2s(&dcp->c_fid)));
   1221  1.40     perry 
   1222   1.1       rvb     }
   1223   1.3       rvb     if (codadebug & CODADBGMSK(CODA_LINK)) {
   1224  1.84  christos 	myprintf(("%s: vp fid: %s\n", __func__, coda_f2s(&cp->c_fid)));
   1225  1.84  christos 	myprintf(("%s: dvp fid: %s\n", __func__, coda_f2s(&dcp->c_fid)));
   1226   1.1       rvb 
   1227   1.1       rvb     }
   1228   1.1       rvb 
   1229   1.1       rvb     /* Check for link to/from control object. */
   1230  1.55       gdt     if (IS_CTL_NAME(dvp, nm, len) || IS_CTL_VP(vp)) {
   1231   1.3       rvb 	MARK_INT_FAIL(CODA_LINK_STATS);
   1232   1.1       rvb 	return(EACCES);
   1233   1.1       rvb     }
   1234   1.1       rvb 
   1235  1.55       gdt     /* If linking . to a name, error out earlier. */
   1236  1.55       gdt     if (vp == dvp) {
   1237  1.55       gdt         printf("coda_link vp==dvp\n");
   1238  1.55       gdt 	error = EISDIR;
   1239  1.55       gdt 	goto exit;
   1240  1.55       gdt     }
   1241   1.1       rvb 
   1242  1.55       gdt     /* XXX Why does venus_link need the vnode to be locked?*/
   1243  1.55       gdt     if ((error = vn_lock(vp, LK_EXCLUSIVE)) != 0) {
   1244  1.84  christos 	printf("%s: couldn't lock vnode %p\n", __func__, vp);
   1245  1.55       gdt 	error = EFAULT;		/* XXX better value */
   1246   1.1       rvb 	goto exit;
   1247   1.1       rvb     }
   1248  1.55       gdt     error = venus_link(vtomi(vp), &cp->c_fid, &dcp->c_fid, nm, len, cred, l);
   1249  1.74   hannken     VOP_UNLOCK(vp);
   1250  1.40     perry 
   1251  1.55       gdt     /* Invalidate parent's attr cache (the modification time has changed). */
   1252  1.55       gdt     VTOC(dvp)->c_flags &= ~C_VATTR;
   1253  1.55       gdt     /* Invalidate child's attr cache (XXX why). */
   1254   1.1       rvb     VTOC(vp)->c_flags &= ~C_VATTR;
   1255   1.1       rvb 
   1256   1.3       rvb     CODADEBUG(CODA_LINK,	myprintf(("in link result %d\n",error)); )
   1257   1.1       rvb 
   1258   1.1       rvb exit:
   1259  1.55       gdt     vput(dvp);
   1260   1.1       rvb     return(error);
   1261   1.1       rvb }
   1262   1.1       rvb 
   1263   1.1       rvb int
   1264  1.43   xtraeme coda_rename(void *v)
   1265   1.1       rvb {
   1266   1.1       rvb /* true args */
   1267   1.1       rvb     struct vop_rename_args *ap = v;
   1268  1.84  christos     vnode_t *odvp = ap->a_fdvp;
   1269   1.1       rvb     struct cnode *odcp = VTOC(odvp);
   1270   1.1       rvb     struct componentname  *fcnp = ap->a_fcnp;
   1271  1.84  christos     vnode_t *ndvp = ap->a_tdvp;
   1272   1.1       rvb     struct cnode *ndcp = VTOC(ndvp);
   1273   1.1       rvb     struct componentname  *tcnp = ap->a_tcnp;
   1274  1.49      elad     kauth_cred_t cred = fcnp->cn_cred;
   1275  1.64     pooka     struct lwp *l = curlwp;
   1276   1.1       rvb /* true args */
   1277   1.1       rvb     int error;
   1278   1.1       rvb     const char *fnm = fcnp->cn_nameptr;
   1279   1.1       rvb     int flen = fcnp->cn_namelen;
   1280   1.1       rvb     const char *tnm = tcnp->cn_nameptr;
   1281   1.1       rvb     int tlen = tcnp->cn_namelen;
   1282   1.1       rvb 
   1283   1.3       rvb     MARK_ENTRY(CODA_RENAME_STATS);
   1284   1.1       rvb 
   1285   1.1       rvb     /* Hmmm.  The vnodes are already looked up.  Perhaps they are locked?
   1286   1.1       rvb        This could be Bad. XXX */
   1287   1.5       rvb #ifdef OLD_DIAGNOSTIC
   1288   1.1       rvb     if ((fcnp->cn_cred != tcnp->cn_cred)
   1289  1.45  christos 	|| (fcnp->cn_lwp != tcnp->cn_lwp))
   1290   1.1       rvb     {
   1291  1.84  christos 	panic("%s: component names don't agree", __func__);
   1292   1.1       rvb     }
   1293   1.5       rvb #endif
   1294   1.1       rvb 
   1295  1.40     perry     /* Check for rename involving control object. */
   1296   1.1       rvb     if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
   1297   1.3       rvb 	MARK_INT_FAIL(CODA_RENAME_STATS);
   1298   1.1       rvb 	return(EACCES);
   1299   1.1       rvb     }
   1300   1.1       rvb 
   1301   1.1       rvb     /* Problem with moving directories -- need to flush entry for .. */
   1302   1.1       rvb     if (odvp != ndvp) {
   1303   1.3       rvb 	struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
   1304   1.1       rvb 	if (ovcp) {
   1305  1.84  christos 	    vnode_t *ovp = CTOV(ovcp);
   1306   1.1       rvb 	    if ((ovp) &&
   1307   1.1       rvb 		(ovp->v_type == VDIR)) /* If it's a directory */
   1308   1.3       rvb 		coda_nc_zapfile(VTOC(ovp),"..", 2);
   1309   1.1       rvb 	}
   1310   1.1       rvb     }
   1311   1.1       rvb 
   1312   1.1       rvb     /* Remove the entries for both source and target files */
   1313   1.3       rvb     coda_nc_zapfile(VTOC(odvp), fnm, flen);
   1314   1.3       rvb     coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
   1315   1.1       rvb 
   1316   1.1       rvb     /* Invalidate the parent's attr cache, the modification time has changed */
   1317   1.1       rvb     VTOC(odvp)->c_flags &= ~C_VATTR;
   1318   1.1       rvb     VTOC(ndvp)->c_flags &= ~C_VATTR;
   1319   1.1       rvb 
   1320   1.3       rvb     if (flen+1 > CODA_MAXNAMLEN) {
   1321   1.3       rvb 	MARK_INT_FAIL(CODA_RENAME_STATS);
   1322   1.1       rvb 	error = EINVAL;
   1323   1.1       rvb 	goto exit;
   1324   1.1       rvb     }
   1325   1.1       rvb 
   1326   1.3       rvb     if (tlen+1 > CODA_MAXNAMLEN) {
   1327   1.3       rvb 	MARK_INT_FAIL(CODA_RENAME_STATS);
   1328   1.1       rvb 	error = EINVAL;
   1329   1.1       rvb 	goto exit;
   1330   1.1       rvb     }
   1331   1.1       rvb 
   1332  1.45  christos     error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, l);
   1333   1.1       rvb 
   1334   1.1       rvb  exit:
   1335   1.3       rvb     CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
   1336   1.1       rvb     /* XXX - do we need to call cache pureg on the moved vnode? */
   1337   1.1       rvb     cache_purge(ap->a_fvp);
   1338   1.1       rvb 
   1339   1.1       rvb     /* It seems to be incumbent on us to drop locks on all four vnodes */
   1340   1.1       rvb     /* From-vnodes are not locked, only ref'd.  To-vnodes are locked. */
   1341   1.1       rvb 
   1342   1.1       rvb     vrele(ap->a_fvp);
   1343   1.1       rvb     vrele(odvp);
   1344   1.1       rvb 
   1345   1.1       rvb     if (ap->a_tvp) {
   1346   1.1       rvb 	if (ap->a_tvp == ndvp) {
   1347   1.1       rvb 	    vrele(ap->a_tvp);
   1348   1.1       rvb 	} else {
   1349   1.1       rvb 	    vput(ap->a_tvp);
   1350   1.1       rvb 	}
   1351   1.1       rvb     }
   1352   1.1       rvb 
   1353   1.1       rvb     vput(ndvp);
   1354   1.1       rvb     return(error);
   1355   1.1       rvb }
   1356   1.1       rvb 
   1357   1.1       rvb int
   1358  1.43   xtraeme coda_mkdir(void *v)
   1359   1.1       rvb {
   1360   1.1       rvb /* true args */
   1361   1.1       rvb     struct vop_mkdir_args *ap = v;
   1362  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1363  1.40     perry     struct cnode *dcp = VTOC(dvp);
   1364   1.1       rvb     struct componentname  *cnp = ap->a_cnp;
   1365  1.17  augustss     struct vattr *va = ap->a_vap;
   1366  1.84  christos     vnode_t **vpp = ap->a_vpp;
   1367  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1368  1.64     pooka     struct lwp *l = curlwp;
   1369   1.1       rvb /* locals */
   1370   1.1       rvb     int error;
   1371   1.1       rvb     const char *nm = cnp->cn_nameptr;
   1372   1.1       rvb     int len = cnp->cn_namelen;
   1373   1.1       rvb     struct cnode *cp;
   1374  1.37  drochner     CodaFid VFid;
   1375   1.1       rvb     struct vattr ova;
   1376   1.1       rvb 
   1377   1.3       rvb     MARK_ENTRY(CODA_MKDIR_STATS);
   1378   1.1       rvb 
   1379   1.1       rvb     /* Check for mkdir of target object. */
   1380   1.1       rvb     if (IS_CTL_NAME(dvp, nm, len)) {
   1381  1.84  christos 	*vpp = (vnode_t *)0;
   1382   1.3       rvb 	MARK_INT_FAIL(CODA_MKDIR_STATS);
   1383   1.1       rvb 	return(EACCES);
   1384   1.1       rvb     }
   1385   1.1       rvb 
   1386   1.3       rvb     if (len+1 > CODA_MAXNAMLEN) {
   1387  1.84  christos 	*vpp = (vnode_t *)0;
   1388   1.3       rvb 	MARK_INT_FAIL(CODA_MKDIR_STATS);
   1389   1.1       rvb 	return(EACCES);
   1390   1.1       rvb     }
   1391   1.1       rvb 
   1392  1.45  christos     error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, l, &VFid, &ova);
   1393   1.1       rvb 
   1394   1.1       rvb     if (!error) {
   1395   1.3       rvb 	if (coda_find(&VFid) != NULL)
   1396   1.1       rvb 	    panic("cnode existed for newly created directory!");
   1397  1.40     perry 
   1398  1.40     perry 
   1399   1.3       rvb 	cp =  make_coda_node(&VFid, dvp->v_mount, va->va_type);
   1400   1.1       rvb 	*vpp = CTOV(cp);
   1401  1.40     perry 
   1402   1.1       rvb 	/* enter the new vnode in the Name Cache */
   1403   1.3       rvb 	coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
   1404   1.1       rvb 
   1405   1.1       rvb 	/* as a side effect, enter "." and ".." for the directory */
   1406   1.3       rvb 	coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
   1407   1.3       rvb 	coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
   1408   1.1       rvb 
   1409   1.3       rvb 	if (coda_attr_cache) {
   1410   1.1       rvb 	    VTOC(*vpp)->c_vattr = ova;		/* update the attr cache */
   1411   1.1       rvb 	    VTOC(*vpp)->c_flags |= C_VATTR;	/* Valid attributes in cnode */
   1412   1.1       rvb 	}
   1413   1.1       rvb 
   1414   1.1       rvb 	/* Invalidate the parent's attr cache, the modification time has changed */
   1415   1.1       rvb 	VTOC(dvp)->c_flags &= ~C_VATTR;
   1416  1.40     perry 
   1417  1.84  christos 	CODADEBUG( CODA_MKDIR, myprintf(("%s: %s result %d\n", __func__,
   1418  1.84  christos 	    coda_f2s(&VFid), error)); )
   1419   1.1       rvb     } else {
   1420  1.84  christos 	*vpp = (vnode_t *)0;
   1421  1.84  christos 	CODADEBUG(CODA_MKDIR, myprintf(("%s error %d\n", __func__, error));)
   1422   1.1       rvb     }
   1423   1.1       rvb 
   1424   1.1       rvb     /*
   1425   1.1       rvb      * Currently, all mkdirs explicitly vput their dvp's.
   1426   1.1       rvb      * It also appears that we *must* lock the vpp, since
   1427   1.1       rvb      * lockleaf isn't set, but someone down the road is going
   1428   1.1       rvb      * to try to unlock the new directory.
   1429   1.1       rvb      */
   1430   1.1       rvb     vput(dvp);
   1431   1.1       rvb     if (!error) {
   1432   1.2       rvb 	if ((error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE))) {
   1433  1.84  christos 	    panic("%s: couldn't lock child", __func__);
   1434   1.1       rvb 	}
   1435   1.1       rvb     }
   1436   1.1       rvb 
   1437   1.1       rvb     return(error);
   1438   1.1       rvb }
   1439   1.1       rvb 
   1440   1.1       rvb int
   1441  1.43   xtraeme coda_rmdir(void *v)
   1442   1.1       rvb {
   1443   1.1       rvb /* true args */
   1444   1.1       rvb     struct vop_rmdir_args *ap = v;
   1445  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1446   1.1       rvb     struct cnode *dcp = VTOC(dvp);
   1447  1.84  christos     vnode_t *vp = ap->a_vp;
   1448   1.1       rvb     struct componentname  *cnp = ap->a_cnp;
   1449  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1450  1.64     pooka     struct lwp *l = curlwp;
   1451   1.1       rvb /* true args */
   1452   1.1       rvb     int error;
   1453   1.1       rvb     const char *nm = cnp->cn_nameptr;
   1454   1.1       rvb     int len = cnp->cn_namelen;
   1455   1.1       rvb     struct cnode *cp;
   1456  1.40     perry 
   1457   1.3       rvb     MARK_ENTRY(CODA_RMDIR_STATS);
   1458   1.1       rvb 
   1459   1.1       rvb     /* Check for rmdir of control object. */
   1460   1.1       rvb     if (IS_CTL_NAME(dvp, nm, len)) {
   1461   1.3       rvb 	MARK_INT_FAIL(CODA_RMDIR_STATS);
   1462   1.1       rvb 	return(ENOENT);
   1463   1.1       rvb     }
   1464   1.1       rvb 
   1465  1.55       gdt     /* Can't remove . in self. */
   1466  1.55       gdt     if (dvp == vp) {
   1467  1.84  christos 	printf("%s: dvp == vp\n", __func__);
   1468  1.55       gdt 	error = EINVAL;
   1469  1.55       gdt 	goto exit;
   1470  1.55       gdt     }
   1471  1.55       gdt 
   1472   1.1       rvb     /*
   1473  1.55       gdt      * The caller may not have adequate permissions, and the venus
   1474  1.55       gdt      * operation may fail, but it doesn't hurt from a correctness
   1475  1.55       gdt      * viewpoint to invalidate cache entries.
   1476  1.55       gdt      * XXX Why isn't this done after the venus_rmdir call?
   1477   1.1       rvb      */
   1478  1.55       gdt     /* Look up child in name cache (by name, from parent). */
   1479   1.3       rvb     cp = coda_nc_lookup(dcp, nm, len, cred);
   1480  1.55       gdt     /* If found, remove all children of the child (., ..). */
   1481   1.3       rvb     if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
   1482   1.1       rvb 
   1483  1.55       gdt     /* Remove child's own entry. */
   1484   1.3       rvb     coda_nc_zapfile(dcp, nm, len);
   1485   1.1       rvb 
   1486  1.55       gdt     /* Invalidate parent's attr cache (the modification time has changed). */
   1487   1.1       rvb     dcp->c_flags &= ~C_VATTR;
   1488   1.1       rvb 
   1489  1.45  christos     error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, l);
   1490   1.1       rvb 
   1491   1.3       rvb     CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
   1492   1.1       rvb 
   1493  1.55       gdt exit:
   1494  1.55       gdt     /* vput both vnodes */
   1495  1.55       gdt     vput(dvp);
   1496  1.55       gdt     if (dvp == vp) {
   1497  1.55       gdt 	vrele(vp);
   1498   1.1       rvb     } else {
   1499  1.55       gdt 	vput(vp);
   1500   1.1       rvb     }
   1501   1.1       rvb 
   1502   1.1       rvb     return(error);
   1503   1.1       rvb }
   1504   1.1       rvb 
   1505   1.1       rvb int
   1506  1.43   xtraeme coda_symlink(void *v)
   1507   1.1       rvb {
   1508   1.1       rvb /* true args */
   1509   1.1       rvb     struct vop_symlink_args *ap = v;
   1510  1.84  christos     vnode_t *dvp = ap->a_dvp;
   1511  1.54       gdt     struct cnode *dcp = VTOC(dvp);
   1512  1.54       gdt     /* a_vpp is used in place below */
   1513   1.1       rvb     struct componentname *cnp = ap->a_cnp;
   1514   1.1       rvb     struct vattr *tva = ap->a_vap;
   1515   1.1       rvb     char *path = ap->a_target;
   1516  1.49      elad     kauth_cred_t cred = cnp->cn_cred;
   1517  1.64     pooka     struct lwp *l = curlwp;
   1518   1.1       rvb /* locals */
   1519   1.1       rvb     int error;
   1520  1.39    petrov     u_long saved_cn_flags;
   1521   1.2       rvb     const char *nm = cnp->cn_nameptr;
   1522   1.1       rvb     int len = cnp->cn_namelen;
   1523   1.1       rvb     int plen = strlen(path);
   1524   1.1       rvb 
   1525  1.40     perry     /*
   1526   1.1       rvb      * Here's the strategy for the moment: perform the symlink, then
   1527   1.1       rvb      * do a lookup to grab the resulting vnode.  I know this requires
   1528   1.1       rvb      * two communications with Venus for a new sybolic link, but
   1529   1.1       rvb      * that's the way the ball bounces.  I don't yet want to change
   1530   1.1       rvb      * the way the Mach symlink works.  When Mach support is
   1531   1.1       rvb      * deprecated, we should change symlink so that the common case
   1532   1.1       rvb      * returns the resultant vnode in a vpp argument.
   1533   1.1       rvb      */
   1534   1.1       rvb 
   1535   1.3       rvb     MARK_ENTRY(CODA_SYMLINK_STATS);
   1536   1.1       rvb 
   1537   1.1       rvb     /* Check for symlink of control object. */
   1538  1.54       gdt     if (IS_CTL_NAME(dvp, nm, len)) {
   1539   1.3       rvb 	MARK_INT_FAIL(CODA_SYMLINK_STATS);
   1540  1.54       gdt 	error = EACCES;
   1541  1.54       gdt 	goto exit;
   1542   1.1       rvb     }
   1543   1.1       rvb 
   1544   1.3       rvb     if (plen+1 > CODA_MAXPATHLEN) {
   1545   1.3       rvb 	MARK_INT_FAIL(CODA_SYMLINK_STATS);
   1546  1.54       gdt 	error = EINVAL;
   1547  1.54       gdt 	goto exit;
   1548   1.1       rvb     }
   1549   1.1       rvb 
   1550   1.3       rvb     if (len+1 > CODA_MAXNAMLEN) {
   1551   1.3       rvb 	MARK_INT_FAIL(CODA_SYMLINK_STATS);
   1552   1.1       rvb 	error = EINVAL;
   1553   1.1       rvb 	goto exit;
   1554   1.1       rvb     }
   1555   1.1       rvb 
   1556  1.54       gdt     error = venus_symlink(vtomi(dvp), &dcp->c_fid, path, plen, nm, len, tva, cred, l);
   1557   1.1       rvb 
   1558  1.54       gdt     /* Invalidate the parent's attr cache (modification time has changed). */
   1559  1.54       gdt     dcp->c_flags &= ~C_VATTR;
   1560   1.1       rvb 
   1561  1.39    petrov     if (!error) {
   1562  1.39    petrov 	/*
   1563  1.39    petrov 	 * VOP_SYMLINK is not defined to pay attention to cnp->cn_flags;
   1564  1.39    petrov 	 * these are defined only for VOP_LOOKUP.   We desire to reuse
   1565  1.39    petrov 	 * cnp for a VOP_LOOKUP operation, and must be sure to not pass
   1566  1.39    petrov 	 * stray flags passed to us.  Such stray flags can occur because
   1567  1.39    petrov 	 * sys_symlink makes a namei call and then reuses the
   1568  1.39    petrov 	 * componentname structure.
   1569  1.39    petrov 	 */
   1570  1.39    petrov 	/*
   1571  1.39    petrov 	 * XXX Arguably we should create our own componentname structure
   1572  1.39    petrov 	 * and not reuse the one that was passed in.
   1573  1.39    petrov 	 */
   1574  1.39    petrov 	saved_cn_flags = cnp->cn_flags;
   1575  1.39    petrov 	cnp->cn_flags &= ~(MODMASK | OPMASK);
   1576  1.39    petrov 	cnp->cn_flags |= LOOKUP;
   1577  1.54       gdt 	error = VOP_LOOKUP(dvp, ap->a_vpp, cnp);
   1578  1.39    petrov 	cnp->cn_flags = saved_cn_flags;
   1579  1.39    petrov 	/* Either an error occurs, or ap->a_vpp is locked. */
   1580   1.1       rvb     }
   1581  1.54       gdt 
   1582  1.54       gdt  exit:
   1583  1.51       chs     /* unlock and deference parent */
   1584  1.54       gdt     vput(dvp);
   1585  1.54       gdt 
   1586   1.3       rvb     CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
   1587   1.1       rvb     return(error);
   1588   1.1       rvb }
   1589   1.1       rvb 
   1590   1.1       rvb /*
   1591   1.1       rvb  * Read directory entries.
   1592   1.1       rvb  */
   1593   1.1       rvb int
   1594  1.43   xtraeme coda_readdir(void *v)
   1595   1.1       rvb {
   1596   1.1       rvb /* true args */
   1597   1.1       rvb     struct vop_readdir_args *ap = v;
   1598  1.84  christos     vnode_t *vp = ap->a_vp;
   1599   1.1       rvb     struct cnode *cp = VTOC(vp);
   1600  1.17  augustss     struct uio *uiop = ap->a_uio;
   1601  1.49      elad     kauth_cred_t cred = ap->a_cred;
   1602   1.1       rvb     int *eofflag = ap->a_eofflag;
   1603   1.1       rvb     off_t **cookies = ap->a_cookies;
   1604   1.1       rvb     int *ncookies = ap->a_ncookies;
   1605   1.1       rvb /* upcall decl */
   1606   1.1       rvb /* locals */
   1607   1.1       rvb     int error = 0;
   1608   1.1       rvb 
   1609   1.3       rvb     MARK_ENTRY(CODA_READDIR_STATS);
   1610   1.1       rvb 
   1611  1.84  christos     CODADEBUG(CODA_READDIR, myprintf(("%s: (%p, %lu, %lld)\n", __func__,
   1612  1.84  christos 	uiop->uio_iov->iov_base, (unsigned long) uiop->uio_resid,
   1613  1.84  christos 	(long long) uiop->uio_offset)); )
   1614  1.40     perry 
   1615   1.1       rvb     /* Check for readdir of control object. */
   1616   1.1       rvb     if (IS_CTL_VP(vp)) {
   1617   1.3       rvb 	MARK_INT_FAIL(CODA_READDIR_STATS);
   1618   1.1       rvb 	return(ENOENT);
   1619   1.1       rvb     }
   1620   1.1       rvb 
   1621   1.2       rvb     {
   1622   1.1       rvb 	/* Redirect the request to UFS. */
   1623  1.40     perry 
   1624   1.1       rvb 	/* If directory is not already open do an "internal open" on it. */
   1625   1.1       rvb 	int opened_internally = 0;
   1626   1.1       rvb 	if (cp->c_ovp == NULL) {
   1627   1.1       rvb 	    opened_internally = 1;
   1628   1.3       rvb 	    MARK_INT_GEN(CODA_OPEN_STATS);
   1629  1.63     pooka 	    error = VOP_OPEN(vp, FREAD, cred);
   1630  1.18      phil #ifdef	CODA_VERBOSE
   1631  1.84  christos 	    printf("%s: Internally Opening %p\n", __func__, vp);
   1632  1.18      phil #endif
   1633   1.1       rvb 	    if (error) return(error);
   1634  1.48  christos 	} else
   1635  1.48  christos 	    vp = cp->c_ovp;
   1636  1.40     perry 
   1637   1.1       rvb 	/* Have UFS handle the call. */
   1638  1.84  christos 	CODADEBUG(CODA_READDIR, myprintf(("%s: fid = %s, refcnt = %d\n",
   1639  1.84  christos 	    __func__, coda_f2s(&cp->c_fid), vp->v_usecount)); )
   1640  1.48  christos 	error = VOP_READDIR(vp, uiop, cred, eofflag, cookies, ncookies);
   1641   1.1       rvb 	if (error)
   1642   1.3       rvb 	    MARK_INT_FAIL(CODA_READDIR_STATS);
   1643   1.1       rvb 	else
   1644   1.3       rvb 	    MARK_INT_SAT(CODA_READDIR_STATS);
   1645  1.40     perry 
   1646  1.40     perry 	/* Do an "internal close" if necessary. */
   1647   1.1       rvb 	if (opened_internally) {
   1648   1.3       rvb 	    MARK_INT_GEN(CODA_CLOSE_STATS);
   1649  1.63     pooka 	    (void)VOP_CLOSE(vp, FREAD, cred);
   1650   1.1       rvb 	}
   1651   1.1       rvb     }
   1652   1.1       rvb 
   1653   1.1       rvb     return(error);
   1654   1.1       rvb }
   1655   1.1       rvb 
   1656   1.1       rvb /*
   1657   1.1       rvb  * Convert from file system blocks to device blocks
   1658   1.1       rvb  */
   1659   1.1       rvb int
   1660  1.43   xtraeme coda_bmap(void *v)
   1661   1.1       rvb {
   1662   1.1       rvb     /* XXX on the global proc */
   1663   1.1       rvb /* true args */
   1664   1.1       rvb     struct vop_bmap_args *ap = v;
   1665  1.84  christos     vnode_t *vp __unused = ap->a_vp;	/* file's vnode */
   1666  1.65     perry     daddr_t bn __unused = ap->a_bn;	/* fs block number */
   1667  1.84  christos     vnode_t **vpp = ap->a_vpp;			/* RETURN vp of device */
   1668  1.65     perry     daddr_t *bnp __unused = ap->a_bnp;	/* RETURN device block number */
   1669  1.65     perry     struct lwp *l __unused = curlwp;
   1670   1.1       rvb /* upcall decl */
   1671   1.1       rvb /* locals */
   1672   1.1       rvb 
   1673  1.84  christos 	*vpp = (vnode_t *)0;
   1674   1.3       rvb 	myprintf(("coda_bmap called!\n"));
   1675   1.1       rvb 	return(EINVAL);
   1676   1.1       rvb }
   1677   1.1       rvb 
   1678   1.1       rvb /*
   1679   1.1       rvb  * I don't think the following two things are used anywhere, so I've
   1680  1.40     perry  * commented them out
   1681  1.40     perry  *
   1682  1.40     perry  * struct buf *async_bufhead;
   1683   1.1       rvb  * int async_daemon_count;
   1684   1.1       rvb  */
   1685   1.1       rvb int
   1686  1.43   xtraeme coda_strategy(void *v)
   1687   1.1       rvb {
   1688   1.1       rvb /* true args */
   1689   1.1       rvb     struct vop_strategy_args *ap = v;
   1690  1.65     perry     struct buf *bp __unused = ap->a_bp;
   1691  1.65     perry     struct lwp *l __unused = curlwp;
   1692   1.1       rvb /* upcall decl */
   1693   1.1       rvb /* locals */
   1694   1.1       rvb 
   1695   1.3       rvb 	myprintf(("coda_strategy called!  "));
   1696   1.1       rvb 	return(EINVAL);
   1697   1.1       rvb }
   1698   1.1       rvb 
   1699   1.1       rvb int
   1700  1.43   xtraeme coda_reclaim(void *v)
   1701   1.1       rvb {
   1702   1.1       rvb /* true args */
   1703   1.1       rvb     struct vop_reclaim_args *ap = v;
   1704  1.84  christos     vnode_t *vp = ap->a_vp;
   1705   1.1       rvb     struct cnode *cp = VTOC(vp);
   1706   1.1       rvb /* upcall decl */
   1707   1.1       rvb /* locals */
   1708   1.1       rvb 
   1709   1.1       rvb /*
   1710   1.1       rvb  * Forced unmount/flush will let vnodes with non zero use be destroyed!
   1711   1.1       rvb  */
   1712   1.1       rvb     ENTRY;
   1713   1.1       rvb 
   1714   1.1       rvb     if (IS_UNMOUNTING(cp)) {
   1715   1.1       rvb #ifdef	DEBUG
   1716   1.1       rvb 	if (VTOC(vp)->c_ovp) {
   1717   1.1       rvb 	    if (IS_UNMOUNTING(cp))
   1718  1.84  christos 		printf("%s: c_ovp not void: vp %p, cp %p\n", __func__, vp, cp);
   1719   1.1       rvb 	}
   1720   1.1       rvb #endif
   1721   1.1       rvb     } else {
   1722   1.5       rvb #ifdef OLD_DIAGNOSTIC
   1723  1.40     perry 	if (vp->v_usecount != 0)
   1724  1.84  christos 	    print("%s: pushing active %p\n", __func__, vp);
   1725   1.1       rvb 	if (VTOC(vp)->c_ovp) {
   1726  1.84  christos 	    panic("%s: c_ovp not void", __func__);
   1727   1.2       rvb 	}
   1728   1.5       rvb #endif
   1729   1.1       rvb     }
   1730   1.3       rvb     coda_free(VTOC(vp));
   1731  1.29     perry     SET_VTOC(vp) = NULL;
   1732   1.1       rvb     return (0);
   1733   1.1       rvb }
   1734   1.1       rvb 
   1735   1.1       rvb int
   1736  1.43   xtraeme coda_lock(void *v)
   1737   1.1       rvb {
   1738   1.1       rvb /* true args */
   1739   1.1       rvb     struct vop_lock_args *ap = v;
   1740  1.84  christos     vnode_t *vp = ap->a_vp;
   1741   1.1       rvb     struct cnode *cp = VTOC(vp);
   1742   1.1       rvb /* upcall decl */
   1743   1.1       rvb /* locals */
   1744   1.1       rvb 
   1745   1.1       rvb     ENTRY;
   1746   1.1       rvb 
   1747   1.3       rvb     if (coda_lockdebug) {
   1748  1.37  drochner 	myprintf(("Attempting lock on %s\n",
   1749  1.37  drochner 		  coda_f2s(&cp->c_fid)));
   1750   1.1       rvb     }
   1751   1.1       rvb 
   1752  1.75   hannken     return genfs_lock(v);
   1753   1.1       rvb }
   1754   1.1       rvb 
   1755   1.1       rvb int
   1756  1.43   xtraeme coda_unlock(void *v)
   1757   1.1       rvb {
   1758   1.1       rvb /* true args */
   1759   1.1       rvb     struct vop_unlock_args *ap = v;
   1760  1.84  christos     vnode_t *vp = ap->a_vp;
   1761   1.1       rvb     struct cnode *cp = VTOC(vp);
   1762   1.1       rvb /* upcall decl */
   1763   1.1       rvb /* locals */
   1764   1.1       rvb 
   1765   1.1       rvb     ENTRY;
   1766   1.3       rvb     if (coda_lockdebug) {
   1767  1.37  drochner 	myprintf(("Attempting unlock on %s\n",
   1768  1.37  drochner 		  coda_f2s(&cp->c_fid)));
   1769   1.1       rvb     }
   1770   1.1       rvb 
   1771  1.75   hannken     return genfs_unlock(v);
   1772   1.1       rvb }
   1773   1.1       rvb 
   1774   1.1       rvb int
   1775  1.43   xtraeme coda_islocked(void *v)
   1776   1.1       rvb {
   1777   1.1       rvb /* true args */
   1778   1.1       rvb     ENTRY;
   1779   1.1       rvb 
   1780  1.75   hannken     return genfs_islocked(v);
   1781   1.1       rvb }
   1782   1.1       rvb 
   1783  1.55       gdt /*
   1784  1.55       gdt  * Given a device and inode, obtain a locked vnode.  One reference is
   1785  1.55       gdt  * obtained and passed back to the caller.
   1786  1.55       gdt  */
   1787   1.1       rvb int
   1788  1.84  christos coda_grab_vnode(vnode_t *uvp, dev_t dev, ino_t ino, vnode_t **vpp)
   1789   1.1       rvb {
   1790   1.1       rvb     int           error;
   1791   1.1       rvb     struct mount *mp;
   1792   1.1       rvb 
   1793  1.55       gdt     /* Obtain mount point structure from device. */
   1794   1.1       rvb     if (!(mp = devtomp(dev))) {
   1795  1.84  christos 	myprintf(("%s: devtomp(0x%llx) returns NULL\n", __func__,
   1796  1.69  christos 	    (unsigned long long)dev));
   1797   1.1       rvb 	return(ENXIO);
   1798   1.1       rvb     }
   1799   1.1       rvb 
   1800  1.55       gdt     /*
   1801  1.55       gdt      * Obtain vnode from mount point and inode.
   1802  1.55       gdt      * XXX VFS_VGET does not clearly define locked/referenced state of
   1803  1.55       gdt      * returned vnode.
   1804  1.55       gdt      */
   1805  1.45  christos     error = VFS_VGET(mp, ino, vpp);
   1806   1.1       rvb     if (error) {
   1807  1.84  christos 	myprintf(("%s: iget/vget(0x%llx, %llu) returns %p, err %d\n", __func__,
   1808  1.69  christos 	    (unsigned long long)dev, (unsigned long long)ino, *vpp, error));
   1809   1.1       rvb 	return(ENOENT);
   1810   1.1       rvb     }
   1811  1.85  christos     /* share the underlying vnode lock with the coda vnode */
   1812  1.85  christos     mutex_obj_hold((*vpp)->v_interlock);
   1813  1.85  christos     uvm_obj_setlock(&uvp->v_uobj, (*vpp)->v_interlock);
   1814   1.1       rvb     return(0);
   1815   1.1       rvb }
   1816   1.1       rvb 
   1817   1.1       rvb void
   1818  1.43   xtraeme print_vattr(struct vattr *attr)
   1819   1.1       rvb {
   1820  1.41  christos     const char *typestr;
   1821   1.1       rvb 
   1822   1.1       rvb     switch (attr->va_type) {
   1823   1.1       rvb     case VNON:
   1824   1.1       rvb 	typestr = "VNON";
   1825   1.1       rvb 	break;
   1826   1.1       rvb     case VREG:
   1827   1.1       rvb 	typestr = "VREG";
   1828   1.1       rvb 	break;
   1829   1.1       rvb     case VDIR:
   1830   1.1       rvb 	typestr = "VDIR";
   1831   1.1       rvb 	break;
   1832   1.1       rvb     case VBLK:
   1833   1.1       rvb 	typestr = "VBLK";
   1834   1.1       rvb 	break;
   1835   1.1       rvb     case VCHR:
   1836   1.1       rvb 	typestr = "VCHR";
   1837   1.1       rvb 	break;
   1838   1.1       rvb     case VLNK:
   1839   1.1       rvb 	typestr = "VLNK";
   1840   1.1       rvb 	break;
   1841   1.1       rvb     case VSOCK:
   1842   1.1       rvb 	typestr = "VSCK";
   1843   1.1       rvb 	break;
   1844   1.1       rvb     case VFIFO:
   1845   1.1       rvb 	typestr = "VFFO";
   1846   1.1       rvb 	break;
   1847   1.1       rvb     case VBAD:
   1848   1.1       rvb 	typestr = "VBAD";
   1849   1.1       rvb 	break;
   1850   1.1       rvb     default:
   1851   1.1       rvb 	typestr = "????";
   1852   1.1       rvb 	break;
   1853   1.1       rvb     }
   1854   1.1       rvb 
   1855   1.1       rvb 
   1856   1.1       rvb     myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
   1857   1.1       rvb 	      typestr, (int)attr->va_mode, (int)attr->va_uid,
   1858   1.1       rvb 	      (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
   1859   1.1       rvb 
   1860   1.1       rvb     myprintf(("      fileid %d nlink %d size %d blocksize %d bytes %d\n",
   1861  1.40     perry 	      (int)attr->va_fileid, (int)attr->va_nlink,
   1862   1.1       rvb 	      (int)attr->va_size,
   1863   1.1       rvb 	      (int)attr->va_blocksize,(int)attr->va_bytes));
   1864   1.1       rvb     myprintf(("      gen %ld flags %ld vaflags %d\n",
   1865   1.1       rvb 	      attr->va_gen, attr->va_flags, attr->va_vaflags));
   1866   1.1       rvb     myprintf(("      atime sec %d nsec %d\n",
   1867   1.1       rvb 	      (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
   1868   1.1       rvb     myprintf(("      mtime sec %d nsec %d\n",
   1869   1.1       rvb 	      (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
   1870   1.1       rvb     myprintf(("      ctime sec %d nsec %d\n",
   1871   1.1       rvb 	      (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
   1872   1.1       rvb }
   1873   1.1       rvb 
   1874   1.1       rvb /* How to print a ucred */
   1875   1.1       rvb void
   1876  1.49      elad print_cred(kauth_cred_t cred)
   1877   1.1       rvb {
   1878   1.1       rvb 
   1879  1.49      elad 	uint16_t ngroups;
   1880   1.1       rvb 	int i;
   1881   1.1       rvb 
   1882  1.49      elad 	myprintf(("ref %d\tuid %d\n", kauth_cred_getrefcnt(cred),
   1883  1.49      elad 		 kauth_cred_geteuid(cred)));
   1884   1.1       rvb 
   1885  1.49      elad 	ngroups = kauth_cred_ngroups(cred);
   1886  1.49      elad 	for (i=0; i < ngroups; i++)
   1887  1.49      elad 		myprintf(("\tgroup %d: (%d)\n", i, kauth_cred_group(cred, i)));
   1888   1.1       rvb 	myprintf(("\n"));
   1889   1.1       rvb 
   1890   1.1       rvb }
   1891   1.1       rvb 
   1892   1.1       rvb /*
   1893   1.1       rvb  * Return a vnode for the given fid.
   1894   1.1       rvb  * If no cnode exists for this fid create one and put it
   1895  1.37  drochner  * in a table hashed by coda_f2i().  If the cnode for
   1896   1.1       rvb  * this fid is already in the table return it (ref count is
   1897   1.3       rvb  * incremented by coda_find.  The cnode will be flushed from the
   1898   1.3       rvb  * table when coda_inactive calls coda_unsave.
   1899   1.1       rvb  */
   1900   1.1       rvb struct cnode *
   1901  1.43   xtraeme make_coda_node(CodaFid *fid, struct mount *vfsp, short type)
   1902   1.1       rvb {
   1903   1.1       rvb     struct cnode *cp;
   1904   1.1       rvb     int          err;
   1905   1.1       rvb 
   1906   1.3       rvb     if ((cp = coda_find(fid)) == NULL) {
   1907  1.84  christos 	vnode_t *vp;
   1908  1.40     perry 
   1909   1.3       rvb 	cp = coda_alloc();
   1910   1.1       rvb 	cp->c_fid = *fid;
   1911  1.40     perry 
   1912  1.80     rmind 	err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, NULL, &vp);
   1913  1.40     perry 	if (err) {
   1914  1.84  christos 	    panic("%s: getnewvnode returned error %d", __func__, err);
   1915  1.40     perry 	}
   1916  1.40     perry 	vp->v_data = cp;
   1917  1.40     perry 	vp->v_type = type;
   1918  1.40     perry 	cp->c_vnode = vp;
   1919  1.62     pooka 	uvm_vnp_setsize(vp, 0);
   1920   1.3       rvb 	coda_save(cp);
   1921  1.40     perry 
   1922   1.1       rvb     } else {
   1923   1.1       rvb 	vref(CTOV(cp));
   1924   1.1       rvb     }
   1925   1.1       rvb 
   1926   1.1       rvb     return cp;
   1927  1.25       chs }
   1928  1.25       chs 
   1929  1.57       gdt /*
   1930  1.57       gdt  * coda_getpages may be called on a vnode which has not been opened,
   1931  1.57       gdt  * e.g. to fault in pages to execute a program.  In that case, we must
   1932  1.57       gdt  * open the file to get the container.  The vnode may or may not be
   1933  1.57       gdt  * locked, and we must leave it in the same state.
   1934  1.57       gdt  */
   1935  1.25       chs int
   1936  1.43   xtraeme coda_getpages(void *v)
   1937  1.25       chs {
   1938  1.25       chs 	struct vop_getpages_args /* {
   1939  1.84  christos 		vnode_t *a_vp;
   1940  1.25       chs 		voff_t a_offset;
   1941  1.25       chs 		struct vm_page **a_m;
   1942  1.25       chs 		int *a_count;
   1943  1.25       chs 		int a_centeridx;
   1944  1.25       chs 		vm_prot_t a_access_type;
   1945  1.25       chs 		int a_advice;
   1946  1.25       chs 		int a_flags;
   1947  1.25       chs 	} */ *ap = v;
   1948  1.84  christos 	vnode_t *vp = ap->a_vp, *cvp;
   1949  1.25       chs 	struct cnode *cp = VTOC(vp);
   1950  1.45  christos 	struct lwp *l = curlwp;
   1951  1.50        ad 	kauth_cred_t cred = l->l_cred;
   1952  1.57       gdt 	int error, cerror;
   1953  1.57       gdt 	int waslocked;	       /* 1 if vnode lock was held on entry */
   1954  1.57       gdt 	int didopen = 0;	/* 1 if we opened container file */
   1955  1.57       gdt 
   1956  1.83  christos 	KASSERT(mutex_owned(vp->v_interlock));
   1957  1.83  christos 
   1958  1.58       gdt 	/*
   1959  1.58       gdt 	 * Handle a case that uvm_fault doesn't quite use yet.
   1960  1.58       gdt 	 * See layer_vnops.c. for inspiration.
   1961  1.58       gdt 	 */
   1962  1.57       gdt 	if (ap->a_flags & PGO_LOCKED) {
   1963  1.57       gdt 		return EBUSY;
   1964  1.57       gdt 	}
   1965  1.25       chs 
   1966  1.25       chs 	/* Check for control object. */
   1967  1.25       chs 	if (IS_CTL_VP(vp)) {
   1968  1.84  christos 		printf("%s: control object %p\n", __func__, vp);
   1969  1.25       chs 		return(EINVAL);
   1970  1.25       chs 	}
   1971  1.25       chs 
   1972  1.58       gdt 	/*
   1973  1.58       gdt 	 * XXX It's really not ok to be releasing the lock we get,
   1974  1.58       gdt 	 * because we could be overlapping with another call to
   1975  1.58       gdt 	 * getpages and drop a lock they are relying on.  We need to
   1976  1.58       gdt 	 * figure out whether getpages ever is called holding the
   1977  1.58       gdt 	 * lock, and if we should serialize getpages calls by some
   1978  1.58       gdt 	 * mechanism.
   1979  1.58       gdt 	 */
   1980  1.72   hannken 	/* XXX VOP_ISLOCKED() may not be used for lock decisions. */
   1981  1.57       gdt 	waslocked = VOP_ISLOCKED(vp);
   1982  1.57       gdt 
   1983  1.58       gdt 	/* Get container file if not already present. */
   1984  1.83  christos 	cvp = cp->c_ovp;
   1985  1.83  christos 	if (cvp == NULL) {
   1986  1.57       gdt 		/*
   1987  1.57       gdt 		 * VOP_OPEN requires a locked vnode.  We must avoid
   1988  1.57       gdt 		 * locking the vnode if it is already locked, and
   1989  1.57       gdt 		 * leave it in the same state on exit.
   1990  1.57       gdt 		 */
   1991  1.57       gdt 		if (waslocked == 0) {
   1992  1.57       gdt 			cerror = vn_lock(vp, LK_EXCLUSIVE);
   1993  1.57       gdt 			if (cerror) {
   1994  1.84  christos 				printf("%s: can't lock vnode %p\n",
   1995  1.84  christos 				    __func__, vp);
   1996  1.57       gdt 				return cerror;
   1997  1.57       gdt 			}
   1998  1.57       gdt #if 0
   1999  1.84  christos 			printf("%s: locked vnode %p\n", __func__, vp);
   2000  1.57       gdt #endif
   2001  1.57       gdt 		}
   2002  1.57       gdt 
   2003  1.57       gdt 		/*
   2004  1.57       gdt 		 * Open file (causes upcall to venus).
   2005  1.57       gdt 		 * XXX Perhaps we should not fully open the file, but
   2006  1.57       gdt 		 * simply obtain a container file.
   2007  1.57       gdt 		 */
   2008  1.57       gdt 		/* XXX Is it ok to do this while holding the simplelock? */
   2009  1.63     pooka 		cerror = VOP_OPEN(vp, FREAD, cred);
   2010  1.57       gdt 
   2011  1.57       gdt 		if (cerror) {
   2012  1.84  christos 			printf("%s: cannot open vnode %p => %d\n", __func__,
   2013  1.57       gdt 			       vp, cerror);
   2014  1.57       gdt 			if (waslocked == 0)
   2015  1.74   hannken 				VOP_UNLOCK(vp);
   2016  1.57       gdt 			return cerror;
   2017  1.57       gdt 		}
   2018  1.57       gdt 
   2019  1.57       gdt #if 0
   2020  1.84  christos 		printf("%s: opened vnode %p\n", __func__, vp);
   2021  1.57       gdt #endif
   2022  1.83  christos 		cvp = cp->c_ovp;
   2023  1.57       gdt 		didopen = 1;
   2024  1.25       chs 	}
   2025  1.83  christos 	KASSERT(cvp != NULL);
   2026  1.57       gdt 
   2027  1.59       gdt 	/* Munge the arg structure to refer to the container vnode. */
   2028  1.83  christos 	KASSERT(cvp->v_interlock == vp->v_interlock);
   2029  1.25       chs 	ap->a_vp = cp->c_ovp;
   2030  1.57       gdt 
   2031  1.83  christos 	/* Finally, call getpages on it. */
   2032  1.57       gdt 	error = VCALL(ap->a_vp, VOFFSET(vop_getpages), ap);
   2033  1.57       gdt 
   2034  1.57       gdt 	/* If we opened the vnode, we must close it. */
   2035  1.57       gdt 	if (didopen) {
   2036  1.57       gdt 		/*
   2037  1.57       gdt 		 * VOP_CLOSE requires a locked vnode, but we are still
   2038  1.58       gdt 		 * holding the lock (or riding a caller's lock).
   2039  1.57       gdt 		 */
   2040  1.63     pooka 		cerror = VOP_CLOSE(vp, FREAD, cred);
   2041  1.57       gdt 		if (cerror != 0)
   2042  1.57       gdt 			/* XXX How should we handle this? */
   2043  1.84  christos 			printf("%s: closed vnode %p -> %d\n", __func__,
   2044  1.84  christos 			    vp, cerror);
   2045  1.57       gdt 
   2046  1.58       gdt 		/* If we obtained a lock, drop it. */
   2047  1.57       gdt 		if (waslocked == 0)
   2048  1.74   hannken 			VOP_UNLOCK(vp);
   2049  1.57       gdt 	}
   2050  1.57       gdt 
   2051  1.25       chs 	return error;
   2052  1.25       chs }
   2053  1.25       chs 
   2054  1.57       gdt /*
   2055  1.83  christos  * The protocol requires v_interlock to be held by the caller.
   2056  1.57       gdt  */
   2057  1.25       chs int
   2058  1.43   xtraeme coda_putpages(void *v)
   2059  1.25       chs {
   2060  1.25       chs 	struct vop_putpages_args /* {
   2061  1.84  christos 		vnode_t *a_vp;
   2062  1.25       chs 		voff_t a_offlo;
   2063  1.25       chs 		voff_t a_offhi;
   2064  1.25       chs 		int a_flags;
   2065  1.25       chs 	} */ *ap = v;
   2066  1.84  christos 	vnode_t *vp = ap->a_vp, *cvp;
   2067  1.57       gdt 	struct cnode *cp = VTOC(vp);
   2068  1.57       gdt 	int error;
   2069  1.25       chs 
   2070  1.83  christos 	KASSERT(mutex_owned(vp->v_interlock));
   2071  1.59       gdt 
   2072  1.25       chs 	/* Check for control object. */
   2073  1.25       chs 	if (IS_CTL_VP(vp)) {
   2074  1.83  christos 		mutex_exit(vp->v_interlock);
   2075  1.84  christos 		printf("%s: control object %p\n", __func__, vp);
   2076  1.25       chs 		return(EINVAL);
   2077  1.25       chs 	}
   2078  1.25       chs 
   2079  1.25       chs 	/*
   2080  1.57       gdt 	 * If container object is not present, then there are no pages
   2081  1.57       gdt 	 * to put; just return without error.  This happens all the
   2082  1.57       gdt 	 * time, apparently during discard of a closed vnode (which
   2083  1.57       gdt 	 * trivially can't have dirty pages).
   2084  1.25       chs 	 */
   2085  1.83  christos 	cvp = cp->c_ovp;
   2086  1.83  christos 	if (cvp == NULL) {
   2087  1.83  christos 		mutex_exit(vp->v_interlock);
   2088  1.57       gdt 		return 0;
   2089  1.83  christos 	}
   2090  1.25       chs 
   2091  1.59       gdt 	/* Munge the arg structure to refer to the container vnode. */
   2092  1.83  christos 	KASSERT(cvp->v_interlock == vp->v_interlock);
   2093  1.83  christos 	ap->a_vp = cvp;
   2094  1.57       gdt 
   2095  1.83  christos 	/* Finally, call putpages on it. */
   2096  1.57       gdt 	error = VCALL(ap->a_vp, VOFFSET(vop_putpages), ap);
   2097  1.57       gdt 
   2098  1.57       gdt 	return error;
   2099   1.1       rvb }
   2100