3 * Coda: an Experimental Distributed File System
6 * Copyright (c) 1987-1998 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation, and
14 * that credit is given to Carnegie Mellon University in all documents
15 * and publicity pertaining to direct or indirect use of this code or its
18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
23 * ANY DERIVATIVE WORK.
25 * Carnegie Mellon encourages users of this software to return any
26 * improvements or extensions that they make, and to grant Carnegie
27 * Mellon the rights to redistribute these changes without encumbrance.
29 * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $Id: coda_vnops.c,v 1.5 1998/09/25 17:38:32 rvb Exp $
35 * Mach Operating System
36 * Copyright (c) 1990 Carnegie-Mellon University
37 * Copyright (c) 1989 Carnegie-Mellon University
38 * All rights reserved. The CMU software License Agreement specifies
39 * the terms and conditions for use and redistribution.
43 * This code was written for the Coda file system at Carnegie Mellon
44 * University. Contributers include David Steere, James Kistler, and
50 * $Log: coda_vnops.c,v $
51 * Revision 1.5 1998/09/25 17:38:32 rvb
52 * Put "stray" printouts under DIAGNOSTIC. Make everything build
53 * with DEBUG on. Add support for lkm. (The macro's don't work
54 * for me; for a good chuckle look at the end of coda_fbsd.c.)
56 * Revision 1.4 1998/09/13 13:57:59 rvb
57 * Finish conversion of cfs -> coda
59 * Revision 1.3 1998/09/11 18:50:17 rvb
60 * All the references to cfs, in symbols, structs, and strings
61 * have been changed to coda. (Same for CFS.)
63 * Revision 1.2 1998/09/02 19:09:53 rvb
66 * Revision 1.1.1.1 1998/08/29 21:14:52 rvb
67 * Very Preliminary Coda
69 * Revision 1.12 1998/08/28 18:28:00 rvb
70 * NetBSD -current is stricter!
72 * Revision 1.11 1998/08/28 18:12:23 rvb
73 * Now it also works on FreeBSD -current. This code will be
74 * committed to the FreeBSD -current and NetBSD -current
75 * trees. It will then be tailored to the particular platform
76 * by flushing conditional code.
78 * Revision 1.10 1998/08/18 17:05:21 rvb
79 * Don't use __RCSID now
81 * Revision 1.9 1998/08/18 16:31:46 rvb
82 * Sync the code for NetBSD -current; test on 1.3 later
84 * Revision 1.8 98/02/24 22:22:50 rvb
85 * Fixes up mainly to flush iopen and friends
87 * Revision 1.7 98/01/31 20:53:15 rvb
88 * First version that works on FreeBSD 2.2.5
90 * Revision 1.6 98/01/23 11:53:47 rvb
91 * Bring RVB_CODA1_1 to HEAD
93 * Revision 1.5.2.8 98/01/23 11:21:11 rvb
96 * Revision 1.5.2.7 97/12/19 14:26:08 rvb
99 * Revision 1.5.2.6 97/12/16 22:01:34 rvb
100 * Oops add cfs_subr.h cfs_venus.h; sync with peter
102 * Revision 1.5.2.5 97/12/16 12:40:14 rvb
105 * Revision 1.5.2.4 97/12/10 14:08:31 rvb
106 * Fix O_ flags; check result in coda_call
108 * Revision 1.5.2.3 97/12/10 11:40:27 rvb
111 * Revision 1.5.2.2 97/12/09 16:07:15 rvb
112 * Sync with vfs/include/coda.h
114 * Revision 1.5.2.1 97/12/06 17:41:25 rvb
115 * Sync with peters coda.h
117 * Revision 1.5 97/12/05 10:39:23 rvb
120 * Revision 1.4.14.10 97/11/25 08:08:48 rvb
121 * cfs_venus ... done; until cred/vattr change
123 * Revision 1.4.14.9 97/11/24 15:44:48 rvb
124 * Final cfs_venus.c w/o macros, but one locking bug
126 * Revision 1.4.14.8 97/11/21 11:28:04 rvb
127 * cfs_venus.c is done: first pass
129 * Revision 1.4.14.7 97/11/20 11:46:51 rvb
130 * Capture current cfs_venus
132 * Revision 1.4.14.6 97/11/18 10:27:19 rvb
133 * cfs_nbsd.c is DEAD!!!; integrated into cfs_vf/vnops.c
134 * cfs_nb_foo and cfs_foo are joined
136 * Revision 1.4.14.5 97/11/13 22:03:03 rvb
137 * pass2 cfs_NetBSD.h mt
139 * Revision 1.4.14.4 97/11/12 12:09:42 rvb
142 * Revision 1.4.14.3 97/11/06 21:03:28 rvb
143 * don't include headers in headers
145 * Revision 1.4.14.2 97/10/29 16:06:30 rvb
148 * Revision 1.4.14.1 1997/10/28 23:10:18 rvb
149 * >64Meg; venus can be killed!
151 * Revision 1.4 1997/02/20 13:54:50 lily
152 * check for NULL return from coda_nc_lookup before CTOV
154 * Revision 1.3 1996/12/12 22:11:02 bnoble
155 * Fixed the "downcall invokes venus operation" deadlock in all known cases.
158 * Revision 1.2 1996/01/02 16:57:07 bnoble
159 * Added support for Coda MiniCache and raw inode calls (final commit)
161 * Revision 1.1.2.1 1995/12/20 01:57:34 bnoble
162 * Added CODA-specific files
164 * Revision 3.1.1.1 1995/03/04 19:08:06 bnoble
165 * Branch for NetBSD port revisions
167 * Revision 3.1 1995/03/04 19:08:04 bnoble
168 * Bump to major revision 3 to prepare for NetBSD port
170 * Revision 2.6 1995/02/17 16:25:26 dcs
171 * These versions represent several changes:
172 * 1. Allow venus to restart even if outstanding references exist.
173 * 2. Have only one ctlvp per client, as opposed to one per mounted cfs device.d
174 * 3. Allow ody_expand to return many members, not just one.
176 * Revision 2.5 94/11/09 20:29:27 dcs
177 * Small bug in remove dealing with hard links and link counts was fixed.
179 * Revision 2.4 94/10/14 09:58:42 dcs
180 * Made changes 'cause sun4s have braindead compilers
182 * Revision 2.3 94/10/12 16:46:37 dcs
183 * Cleaned kernel/venus interface by removing XDR junk, plus
184 * so cleanup to allow this code to be more easily ported.
186 * Revision 2.2 94/09/20 14:12:41 dcs
187 * Fixed bug in rename when moving a directory.
189 * Revision 2.1 94/07/21 16:25:22 satya
190 * Conversion to C++ 3.0; start of Coda Release 2.0
192 * Revision 1.4 93/12/17 01:38:01 luqi
193 * Changes made for kernel to pass process info to Venus:
196 * add process id and process group id in most of the cfs argument types.
198 * (2) in file cfs_vnodeops.c
199 * add process info passing in most of the cfs vnode operations.
201 * (3) in file cfs_xdr.c
202 * expand xdr routines according changes in (1).
203 * add variable pass_process_info to allow venus for kernel version checking.
205 * Revision 1.3 93/05/28 16:24:33 bnoble
206 * *** empty log message ***
208 * Revision 1.2 92/10/27 17:58:25 lily
209 * merge kernel/latest and alpha/src/cfs
211 * Revision 2.4 92/09/30 14:16:37 mja
212 * Redid buffer allocation so that it does kmem_{alloc,free} for all
213 * architectures. Zone allocation, previously used on the 386, caused
214 * panics if it was invoked repeatedly. Stack allocation, previously
215 * used on all other architectures, tickled some Mach bug that appeared
216 * with large stack frames.
219 * Added contributors blurb.
222 * Revision 2.3 90/07/26 15:50:09 mrt
223 * Fixed fix to rename to remove .. from moved directories.
226 * Revision 1.7 90/06/28 16:24:25 dcs
227 * Fixed bug with moving directories, we weren't flushing .. for the moved directory.
229 * Revision 1.6 90/05/31 17:01:47 dcs
230 * Prepare for merge with facilities kernel.
235 #include <sys/param.h>
236 #include <sys/systm.h>
237 #include <sys/kernel.h>
238 #include <sys/proc.h>
239 #include <sys/malloc.h>
240 #include <sys/mount.h>
241 #include <sys/errno.h>
242 #include <sys/acct.h>
243 #include <sys/file.h>
244 #include <sys/fcntl.h>
246 #include <sys/namei.h>
247 #include <sys/ioccom.h>
248 #include <sys/select.h>
251 #include <vm/vm_object.h>
252 #include <vm/vm_extern.h>
253 #include <vm/vm_zone.h>
255 #include <coda/coda.h>
256 #include <coda/cnode.h>
257 #include <coda/coda_vnops.h>
258 #include <coda/coda_venus.h>
259 #include <coda/coda_opstats.h>
260 #include <coda/coda_subr.h>
261 #include <coda/coda_namecache.h>
262 #include <coda/coda_pioctl.h>
265 * These flags select various performance enhancements.
267 int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
268 int coda_symlink_cache = 1; /* Set to cache symbolic link information */
269 int coda_access_cache = 1; /* Set to handle some access checks directly */
271 /* structure to keep track of vfs calls */
273 struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
275 #define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
276 #define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
277 #define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
278 #define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
280 /* What we are delaying for in printf */
281 int coda_printf_delay = 0; /* in microseconds */
282 int coda_vnop_print_entry = 0;
283 static int coda_lockdebug = 0;
285 /* Definition of the vfs operation vector */
288 * Some NetBSD details:
290 * coda_start is called at the end of the mount syscall.
291 * coda_init is called at boot time.
294 #define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
296 /* Definition of the vnode operation vector */
298 struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
299 { &vop_default_desc, coda_vop_error },
300 { &vop_lookup_desc, coda_lookup }, /* lookup */
301 { &vop_create_desc, coda_create }, /* create */
302 { &vop_mknod_desc, coda_vop_error }, /* mknod */
303 { &vop_open_desc, coda_open }, /* open */
304 { &vop_close_desc, coda_close }, /* close */
305 { &vop_access_desc, coda_access }, /* access */
306 { &vop_getattr_desc, coda_getattr }, /* getattr */
307 { &vop_setattr_desc, coda_setattr }, /* setattr */
308 { &vop_read_desc, coda_read }, /* read */
309 { &vop_write_desc, coda_write }, /* write */
310 { &vop_ioctl_desc, coda_ioctl }, /* ioctl */
311 { &vop_mmap_desc, coda_vop_error }, /* mmap */
312 { &vop_fsync_desc, coda_fsync }, /* fsync */
313 { &vop_remove_desc, coda_remove }, /* remove */
314 { &vop_link_desc, coda_link }, /* link */
315 { &vop_rename_desc, coda_rename }, /* rename */
316 { &vop_mkdir_desc, coda_mkdir }, /* mkdir */
317 { &vop_rmdir_desc, coda_rmdir }, /* rmdir */
318 { &vop_symlink_desc, coda_symlink }, /* symlink */
319 { &vop_readdir_desc, coda_readdir }, /* readdir */
320 { &vop_readlink_desc, coda_readlink }, /* readlink */
321 { &vop_abortop_desc, coda_abortop }, /* abortop */
322 { &vop_inactive_desc, coda_inactive }, /* inactive */
323 { &vop_reclaim_desc, coda_reclaim }, /* reclaim */
324 { &vop_lock_desc, coda_lock }, /* lock */
325 { &vop_unlock_desc, coda_unlock }, /* unlock */
326 { &vop_bmap_desc, coda_bmap }, /* bmap */
327 { &vop_strategy_desc, coda_strategy }, /* strategy */
328 { &vop_print_desc, coda_vop_error }, /* print */
329 { &vop_islocked_desc, coda_islocked }, /* islocked */
330 { &vop_pathconf_desc, coda_vop_error }, /* pathconf */
331 { &vop_advlock_desc, coda_vop_nop }, /* advlock */
332 { &vop_bwrite_desc, coda_vop_error }, /* bwrite */
333 { &vop_lease_desc, coda_vop_nop }, /* lease */
334 { &vop_poll_desc, (vop_t *) vop_stdpoll },
335 { &vop_getpages_desc, coda_fbsd_getpages }, /* pager intf.*/
336 { &vop_putpages_desc, coda_fbsd_putpages }, /* pager intf.*/
340 we need to define these someday
341 #define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
342 #define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
343 #define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
344 #define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
345 #define UFS_UPDATE(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_update(aa, bb, cc, dd)
348 { &vop_reallocblks_desc, (vop_t *) ufs_missingop },
349 { &vop_cachedlookup_desc, (vop_t *) ufs_lookup },
350 { &vop_whiteout_desc, (vop_t *) ufs_whiteout },
352 { (struct vnodeop_desc*)NULL, (int(*)(void *))NULL }
355 static struct vnodeopv_desc coda_vnodeop_opv_desc =
356 { &coda_vnodeop_p, coda_vnodeop_entries };
358 VNODEOP_SET(coda_vnodeop_opv_desc);
360 /* A generic panic: we were called with something we didn't define yet */
362 coda_vop_error(void *anon) {
363 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
365 myprintf(("Vnode operation %s called, but not defined\n",
366 (*desc)->vdesc_name));
367 panic("coda_vop_error");
371 /* A generic do-nothing. For lease_check, advlock */
373 coda_vop_nop(void *anon) {
374 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
377 myprintf(("Vnode operation %s called, but unsupported\n",
378 (*desc)->vdesc_name));
384 coda_vnodeopstats_init(void)
388 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
389 coda_vnodeopstats[i].opcode = i;
390 coda_vnodeopstats[i].entries = 0;
391 coda_vnodeopstats[i].sat_intrn = 0;
392 coda_vnodeopstats[i].unsat_intrn = 0;
393 coda_vnodeopstats[i].gen_intrn = 0;
399 * coda_open calls Venus to return the device, inode pair of the cache
400 * file holding the data. Using iget, coda_open finds the vnode of the
401 * cache file, and then opens it.
408 * NetBSD can pass the O_EXCL flag in mode, even though the check
409 * has already happened. Venus defensively assumes that if open
410 * is passed the EXCL, it must be a bug. We strip the flag here.
413 struct vop_open_args *ap = v;
414 register struct vnode **vpp = &(ap->a_vp);
415 struct cnode *cp = VTOC(*vpp);
416 int flag = ap->a_mode & (~O_EXCL);
417 struct ucred *cred = ap->a_cred;
418 struct proc *p = ap->a_p;
425 MARK_ENTRY(CODA_OPEN_STATS);
427 /* Check for open of control file. */
428 if (IS_CTL_VP(*vpp)) {
430 /* if (WRITEABLE(flag)) */
431 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
432 MARK_INT_FAIL(CODA_OPEN_STATS);
435 MARK_INT_SAT(CODA_OPEN_STATS);
439 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, p, &dev, &inode);
443 CODADEBUG( CODA_OPEN,myprintf(("open: dev %d inode %d result %d\n",
444 dev, inode, error)); )
447 /* Translate the <device, inode> pair for the cache file into
449 error = coda_grab_vnode(dev, inode, &vp);
453 /* We get the vnode back locked. Needs unlocked */
454 VOP_UNLOCK(vp, 0, p);
455 /* Keep a reference until the close comes in. */
458 /* Save the vnode pointer for the cache file. */
459 if (cp->c_ovp == NULL) {
463 panic("coda_open: cp->c_ovp != ITOV(ip)");
467 /* Flush the attribute cached if writing the file. */
470 cp->c_flags &= ~C_VATTR;
473 /* Save the <device, inode> pair for the cache file to speed
474 up subsequent page_read's. */
478 /* Open the cache file. */
479 error = VOP_OPEN(vp, flag, cred, p);
481 printf("coda_open: VOP_OPEN on container failed %d\n", error);
484 /* grab (above) does this when it calls newvnode unless it's in the cache*/
485 if (vp->v_type == VREG) {
486 error = vfs_object_create(vp, p, cred, 1);
488 printf("coda_open: vfs_object_create() returns %d\n", error);
497 * Close the cache file used for I/O and notify Venus.
504 struct vop_close_args *ap = v;
505 struct vnode *vp = ap->a_vp;
506 struct cnode *cp = VTOC(vp);
507 int flag = ap->a_fflag;
508 struct ucred *cred = ap->a_cred;
509 struct proc *p = ap->a_p;
513 MARK_ENTRY(CODA_CLOSE_STATS);
515 /* Check for close of control file. */
517 MARK_INT_SAT(CODA_CLOSE_STATS);
521 if (IS_UNMOUNTING(cp)) {
524 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
525 vp->v_usecount, cp->c_ovp, vp, cp);
530 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
535 VOP_CLOSE(cp->c_ovp, flag, cred, p); /* Do errors matter here? */
539 if (--cp->c_ocount == 0)
542 if (flag & FWRITE) /* file was opened for write */
545 error = venus_close(vtomi(vp), &cp->c_fid, flag, cred, p);
548 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
556 struct vop_read_args *ap = v;
559 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
560 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp));
567 struct vop_write_args *ap = v;
570 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
571 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_procp));
575 coda_rdwr(vp, uiop, rw, ioflag, cred, p)
584 /* NOTE: container file operation!!! */
586 struct cnode *cp = VTOC(vp);
587 struct vnode *cfvp = cp->c_ovp;
588 int igot_internally = 0;
589 int opened_internally = 0;
592 MARK_ENTRY(CODA_RDWR_STATS);
594 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %qd, %d)\n", rw,
595 uiop->uio_iov->iov_base, uiop->uio_resid,
596 uiop->uio_offset, uiop->uio_segflg)); )
598 /* Check for rdwr of control object. */
600 MARK_INT_FAIL(CODA_RDWR_STATS);
605 * If file is not already open this must be a page
606 * {read,write} request. Iget the cache file's inode
607 * pointer if we still have its <device, inode> pair.
608 * Otherwise, we must do an internal open to derive the
613 * If we're dumping core, do the internal open. Otherwise
614 * venus won't have the correct size of the core when
615 * it's completely written.
617 if (cp->c_inode != 0 && !(p && (p->p_acflag & ACORE))) {
619 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
621 MARK_INT_FAIL(CODA_RDWR_STATS);
625 * We get the vnode back locked in both Mach and
626 * NetBSD. Needs unlocked
628 VOP_UNLOCK(cfvp, 0, p);
631 opened_internally = 1;
632 MARK_INT_GEN(CODA_OPEN_STATS);
633 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
635 printf("coda_rdwr: Internally Opening %p\n", vp);
637 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
640 if (vp->v_type == VREG) {
641 error = vfs_object_create(vp, p, cred, 1);
643 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
648 MARK_INT_FAIL(CODA_RDWR_STATS);
655 /* Have UFS handle the call. */
656 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
657 cp->c_fid.Volume, cp->c_fid.Vnode,
658 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
661 if (rw == UIO_READ) {
662 error = VOP_READ(cfvp, uiop, ioflag, cred);
664 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
665 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
669 if (VOP_GETATTR(cfvp, &attr, cred, p) == 0) {
670 vnode_pager_setsize(vp, attr.va_size);
676 MARK_INT_FAIL(CODA_RDWR_STATS);
678 MARK_INT_SAT(CODA_RDWR_STATS);
680 /* Do an internal close if necessary. */
681 if (opened_internally) {
682 MARK_INT_GEN(CODA_CLOSE_STATS);
683 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), cred, p);
686 /* Invalidate cached attributes if writing. */
688 cp->c_flags &= ~C_VATTR;
697 struct vop_ioctl_args *ap = v;
698 struct vnode *vp = ap->a_vp;
699 int com = ap->a_command;
700 caddr_t data = ap->a_data;
701 int flag = ap->a_fflag;
702 struct ucred *cred = ap->a_cred;
703 struct proc *p = ap->a_p;
707 struct nameidata ndp;
708 struct PioctlData *iap = (struct PioctlData *)data;
710 MARK_ENTRY(CODA_IOCTL_STATS);
712 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
714 /* Don't check for operation on a dying object, for ctlvp it
717 /* Must be control object to succeed. */
718 if (!IS_CTL_VP(vp)) {
719 MARK_INT_FAIL(CODA_IOCTL_STATS);
720 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
723 /* Look up the pathname. */
725 /* Should we use the name cache here? It would get it from
726 lookupname sooner or later anyway, right? */
728 NDINIT(&ndp, LOOKUP, (iap->follow ? FOLLOW : NOFOLLOW), UIO_USERSPACE, ((caddr_t)iap->path), p);
733 MARK_INT_FAIL(CODA_IOCTL_STATS);
734 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
740 * Make sure this is a coda style cnode, but it may be a
743 /* XXX: this totally violates the comment about vtagtype in vnode.h */
744 if (tvp->v_tag != VT_CODA) {
746 MARK_INT_FAIL(CODA_IOCTL_STATS);
747 CODADEBUG(CODA_IOCTL,
748 myprintf(("coda_ioctl error: %s not a coda object\n",
753 if (iap->vi.in_size > VC_MAXDATASIZE) {
757 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, p);
760 MARK_INT_FAIL(CODA_IOCTL_STATS);
762 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
769 * To reduce the cost of a user-level venus;we cache attributes in
770 * the kernel. Each cnode has storage allocated for an attribute. If
771 * c_vattr is valid, return a reference to it. Otherwise, get the
772 * attributes from venus and store them in the cnode. There is some
773 * question if this method is a security leak. But I think that in
774 * order to make this call, the user must have done a lookup and
775 * opened the file, and therefore should already have access.
782 struct vop_getattr_args *ap = v;
783 struct vnode *vp = ap->a_vp;
784 struct cnode *cp = VTOC(vp);
785 struct vattr *vap = ap->a_vap;
786 struct ucred *cred = ap->a_cred;
787 struct proc *p = ap->a_p;
791 MARK_ENTRY(CODA_GETATTR_STATS);
793 if (IS_UNMOUNTING(cp))
796 /* Check for getattr of control object. */
798 MARK_INT_FAIL(CODA_GETATTR_STATS);
802 /* Check to see if the attributes have already been cached */
803 if (VALID_VATTR(cp)) {
804 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
807 cp->c_fid.Unique));});
808 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
809 print_vattr(&cp->c_vattr); );
812 MARK_INT_SAT(CODA_GETATTR_STATS);
816 error = venus_getattr(vtomi(vp), &cp->c_fid, cred, p, vap);
819 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
825 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
828 { int size = vap->va_size;
829 struct vnode *convp = cp->c_ovp;
830 if (convp != (struct vnode *)0) {
831 vnode_pager_setsize(convp, size);
834 /* If not open for write, store attributes in cnode */
835 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
837 cp->c_flags |= C_VATTR;
849 struct vop_setattr_args *ap = v;
850 register struct vnode *vp = ap->a_vp;
851 struct cnode *cp = VTOC(vp);
852 register struct vattr *vap = ap->a_vap;
853 struct ucred *cred = ap->a_cred;
854 struct proc *p = ap->a_p;
858 MARK_ENTRY(CODA_SETATTR_STATS);
860 /* Check for setattr of control object. */
862 MARK_INT_FAIL(CODA_SETATTR_STATS);
866 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
869 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, p);
872 cp->c_flags &= ~C_VATTR;
874 { int size = vap->va_size;
875 struct vnode *convp = cp->c_ovp;
876 if (size != VNOVAL && convp != (struct vnode *)0) {
877 vnode_pager_setsize(convp, size);
880 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
889 struct vop_access_args *ap = v;
890 struct vnode *vp = ap->a_vp;
891 struct cnode *cp = VTOC(vp);
892 int mode = ap->a_mode;
893 struct ucred *cred = ap->a_cred;
894 struct proc *p = ap->a_p;
898 MARK_ENTRY(CODA_ACCESS_STATS);
900 /* Check for access of control object. Only read access is
903 /* bogus hack - all will be marked as successes */
904 MARK_INT_SAT(CODA_ACCESS_STATS);
905 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
910 * if the file is a directory, and we are checking exec (eg lookup)
911 * access, and the file is in the namecache, then the user must have
912 * lookup access to it.
914 if (coda_access_cache) {
915 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
916 if (coda_nc_lookup(cp, ".", 1, cred)) {
917 MARK_INT_SAT(CODA_ACCESS_STATS);
918 return(0); /* it was in the cache */
923 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, p);
929 * CODA abort op, called after namei() when a CREATE/DELETE isn't actually
930 * done. If a buffer has been saved in anticipation of a coda_create or
931 * a coda_remove, delete it.
939 struct vop_abortop_args /* {
941 struct componentname *a_cnp;
946 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
947 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
956 struct vop_readlink_args *ap = v;
957 struct vnode *vp = ap->a_vp;
958 struct cnode *cp = VTOC(vp);
959 struct uio *uiop = ap->a_uio;
960 struct ucred *cred = ap->a_cred;
961 struct proc *p = ap->a_uio->uio_procp;
967 MARK_ENTRY(CODA_READLINK_STATS);
969 /* Check for readlink of control object. */
971 MARK_INT_FAIL(CODA_READLINK_STATS);
975 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
976 uiop->uio_rw = UIO_READ;
977 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
979 MARK_INT_FAIL(CODA_READLINK_STATS);
981 MARK_INT_SAT(CODA_READLINK_STATS);
985 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, p, &str, &len);
988 uiop->uio_rw = UIO_READ;
989 error = uiomove(str, len, uiop);
991 if (coda_symlink_cache) {
994 cp->c_flags |= C_SYMLINK;
999 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
1008 struct vop_fsync_args *ap = v;
1009 struct vnode *vp = ap->a_vp;
1010 struct cnode *cp = VTOC(vp);
1011 struct ucred *cred = ap->a_cred;
1012 struct proc *p = ap->a_p;
1014 struct vnode *convp = cp->c_ovp;
1017 MARK_ENTRY(CODA_FSYNC_STATS);
1019 /* Check for fsync on an unmounting object */
1020 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
1021 * after an unmount has been initiated. This is a Bad Thing,
1022 * which we have to avoid. Not a legitimate failure for stats.
1024 if (IS_UNMOUNTING(cp)) {
1028 /* Check for fsync of control object. */
1029 if (IS_CTL_VP(vp)) {
1030 MARK_INT_SAT(CODA_FSYNC_STATS);
1035 VOP_FSYNC(convp, cred, MNT_WAIT, p);
1038 * We see fsyncs with usecount == 1 then usecount == 0.
1039 * For now we ignore them.
1042 if (!vp->v_usecount) {
1043 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
1044 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
1049 * We can expect fsync on any vnode at all if venus is pruging it.
1050 * Venus can't very well answer the fsync request, now can it?
1051 * Hopefully, it won't have to, because hopefully, venus preserves
1052 * the (possibly untrue) invariant that it never purges an open
1055 if (cp->c_flags & C_PURGING) {
1059 /* needs research */
1061 error = venus_fsync(vtomi(vp), &cp->c_fid, cred, p);
1063 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
1071 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
1072 have a proc pointer. Oops. */
1074 struct vop_inactive_args *ap = v;
1075 struct vnode *vp = ap->a_vp;
1076 struct cnode *cp = VTOC(vp);
1077 struct ucred *cred __attribute__((unused)) = NULL;
1078 struct proc *p __attribute__((unused)) = curproc;
1082 /* We don't need to send inactive to venus - DCS */
1083 MARK_ENTRY(CODA_INACTIVE_STATS);
1085 if (IS_CTL_VP(vp)) {
1086 MARK_INT_SAT(CODA_INACTIVE_STATS);
1090 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
1091 cp->c_fid.Volume, cp->c_fid.Vnode,
1092 cp->c_fid.Unique, vp->v_mount));)
1094 /* If an array has been allocated to hold the symlink, deallocate it */
1095 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
1096 if (cp->c_symlink == NULL)
1097 panic("coda_inactive: null symlink pointer in cnode");
1099 CODA_FREE(cp->c_symlink, cp->c_symlen);
1100 cp->c_flags &= ~C_SYMLINK;
1104 /* Remove it from the table so it can't be found. */
1106 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
1107 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
1108 panic("badness in coda_inactive\n");
1111 if (IS_UNMOUNTING(cp)) {
1113 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
1114 if (cp->c_ovp != NULL)
1115 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
1116 vp->v_usecount, vp, cp);
1118 lockmgr(&cp->c_lock, LK_RELEASE, &vp->v_interlock, p);
1120 #ifdef OLD_DIAGNOSTIC
1121 if (CTOV(cp)->v_usecount) {
1122 panic("coda_inactive: nonzero reference count");
1124 if (cp->c_ovp != NULL) {
1125 panic("coda_inactive: cp->ovp != NULL");
1128 VOP_UNLOCK(vp, 0, p);
1132 MARK_INT_SAT(CODA_INACTIVE_STATS);
1137 * Remote file system operations having to do with directory manipulation.
1141 * It appears that in NetBSD, lookup is supposed to return the vnode locked
1148 struct vop_lookup_args *ap = v;
1149 struct vnode *dvp = ap->a_dvp;
1150 struct cnode *dcp = VTOC(dvp);
1151 struct vnode **vpp = ap->a_vpp;
1153 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
1154 * of the string to xlate, and that we must try to get at least
1155 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
1158 struct componentname *cnp = ap->a_cnp;
1159 struct ucred *cred = cnp->cn_cred;
1160 struct proc *p = cnp->cn_proc;
1163 const char *nm = cnp->cn_nameptr;
1164 int len = cnp->cn_namelen;
1169 MARK_ENTRY(CODA_LOOKUP_STATS);
1171 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
1172 nm, dcp->c_fid.Volume,
1173 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
1175 /* Check for lookup of control object. */
1176 if (IS_CTL_NAME(dvp, nm, len)) {
1179 MARK_INT_SAT(CODA_LOOKUP_STATS);
1183 if (len+1 > CODA_MAXNAMLEN) {
1184 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1185 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
1186 dcp->c_fid.Volume, dcp->c_fid.Vnode,
1187 dcp->c_fid.Unique, nm)););
1188 *vpp = (struct vnode *)0;
1192 /* First try to look the file up in the cfs name cache */
1193 /* lock the parent vnode? */
1194 cp = coda_nc_lookup(dcp, nm, len, cred);
1198 CODADEBUG(CODA_LOOKUP,
1199 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
1202 /* The name wasn't cached, so we need to contact Venus */
1203 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, p, &VFid, &vtype);
1206 MARK_INT_FAIL(CODA_LOOKUP_STATS);
1207 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
1208 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
1209 *vpp = (struct vnode *)0;
1211 MARK_INT_SAT(CODA_LOOKUP_STATS);
1212 CODADEBUG(CODA_LOOKUP,
1213 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
1214 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
1217 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
1220 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1221 /* And don't enter a new vnode for an invalid one! */
1222 if (!(vtype & CODA_NOCACHE))
1223 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1229 * If we are creating, and this was the last name to be looked up,
1230 * and the error was ENOENT, then there really shouldn't be an
1231 * error and we can make the leaf NULL and return success. Since
1232 * this is supposed to work under Mach as well as NetBSD, we're
1233 * leaving this fn wrapped. We also must tell lookup/namei that
1234 * we need to save the last component of the name. (Create will
1235 * have to free the name buffer later...lucky us...)
1237 if (((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME))
1238 && (cnp->cn_flags & ISLASTCN)
1239 && (error == ENOENT))
1241 error = EJUSTRETURN;
1242 cnp->cn_flags |= SAVENAME;
1247 * If we are removing, and we are at the last element, and we
1248 * found it, then we need to keep the name around so that the
1249 * removal will go ahead as planned. Unfortunately, this will
1250 * probably also lock the to-be-removed vnode, which may or may
1251 * not be a good idea. I'll have to look at the bits of
1252 * coda_remove to make sure. We'll only save the name if we did in
1253 * fact find the name, otherwise coda_remove won't have a chance
1254 * to free the pathname.
1256 if ((cnp->cn_nameiop == DELETE)
1257 && (cnp->cn_flags & ISLASTCN)
1260 cnp->cn_flags |= SAVENAME;
1264 * If the lookup went well, we need to (potentially?) unlock the
1265 * parent, and lock the child. We are only responsible for
1266 * checking to see if the parent is supposed to be unlocked before
1267 * we return. We must always lock the child (provided there is
1268 * one, and (the parent isn't locked or it isn't the same as the
1269 * parent.) Simple, huh? We can never leave the parent locked unless
1272 if (!error || (error == EJUSTRETURN)) {
1273 if (!(cnp->cn_flags & LOCKPARENT) || !(cnp->cn_flags & ISLASTCN)) {
1274 if ((error = VOP_UNLOCK(dvp, 0, p))) {
1278 * The parent is unlocked. As long as there is a child,
1279 * lock it without bothering to check anything else.
1282 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1283 printf("coda_lookup: ");
1284 panic("unlocked parent but couldn't lock child");
1288 /* The parent is locked, and may be the same as the child */
1289 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1290 /* Different, go ahead and lock it. */
1291 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1292 printf("coda_lookup: ");
1293 panic("unlocked parent but couldn't lock child");
1298 /* If the lookup failed, we need to ensure that the leaf is NULL */
1299 /* Don't change any locking? */
1311 struct vop_create_args *ap = v;
1312 struct vnode *dvp = ap->a_dvp;
1313 struct cnode *dcp = VTOC(dvp);
1314 struct vattr *va = ap->a_vap;
1316 int mode = ap->a_vap->va_mode;
1317 struct vnode **vpp = ap->a_vpp;
1318 struct componentname *cnp = ap->a_cnp;
1319 struct ucred *cred = cnp->cn_cred;
1320 struct proc *p = cnp->cn_proc;
1324 const char *nm = cnp->cn_nameptr;
1325 int len = cnp->cn_namelen;
1329 MARK_ENTRY(CODA_CREATE_STATS);
1331 /* All creates are exclusive XXX */
1332 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1334 /* Check for create of control object. */
1335 if (IS_CTL_NAME(dvp, nm, len)) {
1336 *vpp = (struct vnode *)0;
1337 MARK_INT_FAIL(CODA_CREATE_STATS);
1341 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, p, &VFid, &attr);
1345 /* If this is an exclusive create, panic if the file already exists. */
1346 /* Venus should have detected the file and reported EEXIST. */
1348 if ((exclusive == 1) &&
1349 (coda_find(&VFid) != NULL))
1350 panic("cnode existed for newly created file!");
1352 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1355 /* Update va to reflect the new attributes. */
1358 /* Update the attribute cache and mark it as valid */
1359 if (coda_attr_cache) {
1360 VTOC(*vpp)->c_vattr = attr;
1361 VTOC(*vpp)->c_flags |= C_VATTR;
1364 /* Invalidate the parent's attr cache, the modification time has changed */
1365 VTOC(dvp)->c_flags &= ~C_VATTR;
1367 /* enter the new vnode in the Name Cache */
1368 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1370 CODADEBUG(CODA_CREATE,
1371 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1372 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1374 *vpp = (struct vnode *)0;
1375 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1379 if (cnp->cn_flags & LOCKLEAF) {
1380 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, p))) {
1381 printf("coda_create: ");
1382 panic("unlocked parent but couldn't lock child");
1385 #ifdef OLD_DIAGNOSTIC
1387 printf("coda_create: LOCKLEAF not set!\n");
1391 /* Have to free the previously saved name */
1393 * This condition is stolen from ufs_makeinode. I have no idea
1394 * why it's here, but what the hey...
1396 if ((cnp->cn_flags & SAVESTART) == 0) {
1397 zfree(namei_zone, cnp->cn_pnbuf);
1407 struct vop_remove_args *ap = v;
1408 struct vnode *dvp = ap->a_dvp;
1409 struct cnode *cp = VTOC(dvp);
1410 struct componentname *cnp = ap->a_cnp;
1411 struct ucred *cred = cnp->cn_cred;
1412 struct proc *p = cnp->cn_proc;
1415 const char *nm = cnp->cn_nameptr;
1416 int len = cnp->cn_namelen;
1419 MARK_ENTRY(CODA_REMOVE_STATS);
1421 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1422 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1423 cp->c_fid.Unique)););
1425 /* Remove the file's entry from the CODA Name Cache */
1426 /* We're being conservative here, it might be that this person
1427 * doesn't really have sufficient access to delete the file
1428 * but we feel zapping the entry won't really hurt anyone -- dcs
1430 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1431 * exist, and one is removed, the link count on the other will be
1432 * off by 1. We could either invalidate the attrs if cached, or
1433 * fix them. I'll try to fix them. DCS 11/8/94
1435 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1437 if (VALID_VATTR(tp)) { /* If attrs are cached */
1438 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1439 tp->c_vattr.va_nlink--;
1443 coda_nc_zapfile(VTOC(dvp), nm, len);
1444 /* No need to flush it if it doesn't exist! */
1446 /* Invalidate the parent's attr cache, the modification time has changed */
1447 VTOC(dvp)->c_flags &= ~C_VATTR;
1449 /* Check for remove of control object. */
1450 if (IS_CTL_NAME(dvp, nm, len)) {
1451 MARK_INT_FAIL(CODA_REMOVE_STATS);
1455 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, p);
1457 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1459 if ((cnp->cn_flags & SAVESTART) == 0) {
1460 zfree(namei_zone, cnp->cn_pnbuf);
1470 struct vop_link_args *ap = v;
1471 struct vnode *vp = ap->a_vp;
1472 struct cnode *cp = VTOC(vp);
1473 struct vnode *tdvp = ap->a_tdvp;
1474 struct cnode *tdcp = VTOC(tdvp);
1475 struct componentname *cnp = ap->a_cnp;
1476 struct ucred *cred = cnp->cn_cred;
1477 struct proc *p = cnp->cn_proc;
1480 const char *nm = cnp->cn_nameptr;
1481 int len = cnp->cn_namelen;
1483 MARK_ENTRY(CODA_LINK_STATS);
1485 if (codadebug & CODADBGMSK(CODA_LINK)) {
1487 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1488 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1489 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1490 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1493 if (codadebug & CODADBGMSK(CODA_LINK)) {
1494 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1495 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1496 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1497 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1501 /* Check for link to/from control object. */
1502 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1503 MARK_INT_FAIL(CODA_LINK_STATS);
1507 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, p);
1509 /* Invalidate the parent's attr cache, the modification time has changed */
1510 VTOC(tdvp)->c_flags &= ~C_VATTR;
1511 VTOC(vp)->c_flags &= ~C_VATTR;
1513 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1517 /* Drop the name buffer if we don't need to SAVESTART */
1518 if ((cnp->cn_flags & SAVESTART) == 0) {
1519 zfree(namei_zone, cnp->cn_pnbuf);
1529 struct vop_rename_args *ap = v;
1530 struct vnode *odvp = ap->a_fdvp;
1531 struct cnode *odcp = VTOC(odvp);
1532 struct componentname *fcnp = ap->a_fcnp;
1533 struct vnode *ndvp = ap->a_tdvp;
1534 struct cnode *ndcp = VTOC(ndvp);
1535 struct componentname *tcnp = ap->a_tcnp;
1536 struct ucred *cred = fcnp->cn_cred;
1537 struct proc *p = fcnp->cn_proc;
1540 const char *fnm = fcnp->cn_nameptr;
1541 int flen = fcnp->cn_namelen;
1542 const char *tnm = tcnp->cn_nameptr;
1543 int tlen = tcnp->cn_namelen;
1545 MARK_ENTRY(CODA_RENAME_STATS);
1547 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1548 This could be Bad. XXX */
1549 #ifdef OLD_DIAGNOSTIC
1550 if ((fcnp->cn_cred != tcnp->cn_cred)
1551 || (fcnp->cn_proc != tcnp->cn_proc))
1553 panic("coda_rename: component names don't agree");
1557 /* Check for rename involving control object. */
1558 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1559 MARK_INT_FAIL(CODA_RENAME_STATS);
1563 /* Problem with moving directories -- need to flush entry for .. */
1565 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1567 struct vnode *ovp = CTOV(ovcp);
1569 (ovp->v_type == VDIR)) /* If it's a directory */
1570 coda_nc_zapfile(VTOC(ovp),"..", 2);
1574 /* Remove the entries for both source and target files */
1575 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1576 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1578 /* Invalidate the parent's attr cache, the modification time has changed */
1579 VTOC(odvp)->c_flags &= ~C_VATTR;
1580 VTOC(ndvp)->c_flags &= ~C_VATTR;
1582 if (flen+1 > CODA_MAXNAMLEN) {
1583 MARK_INT_FAIL(CODA_RENAME_STATS);
1588 if (tlen+1 > CODA_MAXNAMLEN) {
1589 MARK_INT_FAIL(CODA_RENAME_STATS);
1594 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, p);
1597 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
1598 /* XXX - do we need to call cache pureg on the moved vnode? */
1599 cache_purge(ap->a_fvp);
1601 /* It seems to be incumbent on us to drop locks on all four vnodes */
1602 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1608 if (ap->a_tvp == ndvp) {
1624 struct vop_mkdir_args *ap = v;
1625 struct vnode *dvp = ap->a_dvp;
1626 struct cnode *dcp = VTOC(dvp);
1627 struct componentname *cnp = ap->a_cnp;
1628 register struct vattr *va = ap->a_vap;
1629 struct vnode **vpp = ap->a_vpp;
1630 struct ucred *cred = cnp->cn_cred;
1631 struct proc *p = cnp->cn_proc;
1634 const char *nm = cnp->cn_nameptr;
1635 int len = cnp->cn_namelen;
1640 MARK_ENTRY(CODA_MKDIR_STATS);
1642 /* Check for mkdir of target object. */
1643 if (IS_CTL_NAME(dvp, nm, len)) {
1644 *vpp = (struct vnode *)0;
1645 MARK_INT_FAIL(CODA_MKDIR_STATS);
1649 if (len+1 > CODA_MAXNAMLEN) {
1650 *vpp = (struct vnode *)0;
1651 MARK_INT_FAIL(CODA_MKDIR_STATS);
1655 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, p, &VFid, &ova);
1658 if (coda_find(&VFid) != NULL)
1659 panic("cnode existed for newly created directory!");
1662 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1665 /* enter the new vnode in the Name Cache */
1666 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1668 /* as a side effect, enter "." and ".." for the directory */
1669 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1670 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1672 if (coda_attr_cache) {
1673 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1674 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1677 /* Invalidate the parent's attr cache, the modification time has changed */
1678 VTOC(dvp)->c_flags &= ~C_VATTR;
1680 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1681 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1683 *vpp = (struct vnode *)0;
1684 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1687 /* Have to free the previously saved name */
1689 * ufs_mkdir doesn't check for SAVESTART before freeing the
1690 * pathname buffer, but ufs_create does. For the moment, I'll
1691 * follow their lead, but this seems like it is probably
1694 zfree(namei_zone, cnp->cn_pnbuf);
1703 struct vop_rmdir_args *ap = v;
1704 struct vnode *dvp = ap->a_dvp;
1705 struct cnode *dcp = VTOC(dvp);
1706 struct componentname *cnp = ap->a_cnp;
1707 struct ucred *cred = cnp->cn_cred;
1708 struct proc *p = cnp->cn_proc;
1711 const char *nm = cnp->cn_nameptr;
1712 int len = cnp->cn_namelen;
1715 MARK_ENTRY(CODA_RMDIR_STATS);
1717 /* Check for rmdir of control object. */
1718 if (IS_CTL_NAME(dvp, nm, len)) {
1719 MARK_INT_FAIL(CODA_RMDIR_STATS);
1723 /* We're being conservative here, it might be that this person
1724 * doesn't really have sufficient access to delete the file
1725 * but we feel zapping the entry won't really hurt anyone -- dcs
1728 * As a side effect of the rmdir, remove any entries for children of
1729 * the directory, especially "." and "..".
1731 cp = coda_nc_lookup(dcp, nm, len, cred);
1732 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1734 /* Remove the file's entry from the CODA Name Cache */
1735 coda_nc_zapfile(dcp, nm, len);
1737 /* Invalidate the parent's attr cache, the modification time has changed */
1738 dcp->c_flags &= ~C_VATTR;
1740 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, p);
1742 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1744 if ((cnp->cn_flags & SAVESTART) == 0) {
1745 zfree(namei_zone, cnp->cn_pnbuf);
1755 struct vop_symlink_args *ap = v;
1756 struct vnode *tdvp = ap->a_dvp;
1757 struct cnode *tdcp = VTOC(tdvp);
1758 struct componentname *cnp = ap->a_cnp;
1759 struct vattr *tva = ap->a_vap;
1760 char *path = ap->a_target;
1761 struct ucred *cred = cnp->cn_cred;
1762 struct proc *p = cnp->cn_proc;
1766 * XXX I'm assuming the following things about coda_symlink's
1768 * t(foo) is the new name/parent/etc being created.
1769 * lname is the contents of the new symlink.
1771 char *nm = cnp->cn_nameptr;
1772 int len = cnp->cn_namelen;
1773 int plen = strlen(path);
1775 /* XXX What about the vpp argument? Do we need it? */
1777 * Here's the strategy for the moment: perform the symlink, then
1778 * do a lookup to grab the resulting vnode. I know this requires
1779 * two communications with Venus for a new sybolic link, but
1780 * that's the way the ball bounces. I don't yet want to change
1781 * the way the Mach symlink works. When Mach support is
1782 * deprecated, we should change symlink so that the common case
1783 * returns the resultant vnode in a vpp argument.
1786 MARK_ENTRY(CODA_SYMLINK_STATS);
1788 /* Check for symlink of control object. */
1789 if (IS_CTL_NAME(tdvp, nm, len)) {
1790 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1794 if (plen+1 > CODA_MAXPATHLEN) {
1795 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1799 if (len+1 > CODA_MAXNAMLEN) {
1800 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1805 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, p);
1807 /* Invalidate the parent's attr cache, the modification time has changed */
1808 tdcp->c_flags &= ~C_VATTR;
1811 * Free the name buffer
1813 if ((cnp->cn_flags & SAVESTART) == 0) {
1814 zfree(namei_zone, cnp->cn_pnbuf);
1818 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1823 * Read directory entries.
1830 struct vop_readdir_args *ap = v;
1831 struct vnode *vp = ap->a_vp;
1832 struct cnode *cp = VTOC(vp);
1833 register struct uio *uiop = ap->a_uio;
1834 struct ucred *cred = ap->a_cred;
1835 int *eofflag = ap->a_eofflag;
1836 u_long **cookies = ap->a_cookies;
1837 int *ncookies = ap->a_ncookies;
1838 struct proc *p = ap->a_uio->uio_procp;
1843 MARK_ENTRY(CODA_READDIR_STATS);
1845 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %qd, %d)\n", uiop->uio_iov->iov_base, uiop->uio_resid, uiop->uio_offset, uiop->uio_segflg)); )
1847 /* Check for readdir of control object. */
1848 if (IS_CTL_VP(vp)) {
1849 MARK_INT_FAIL(CODA_READDIR_STATS);
1854 /* If directory is not already open do an "internal open" on it. */
1855 int opened_internally = 0;
1856 if (cp->c_ovp == NULL) {
1857 opened_internally = 1;
1858 MARK_INT_GEN(CODA_OPEN_STATS);
1859 error = VOP_OPEN(vp, FREAD, cred, p);
1860 printf("coda_readdir: Internally Opening %p\n", vp);
1862 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1865 if (vp->v_type == VREG) {
1866 error = vfs_object_create(vp, p, cred, 1);
1868 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1872 if (error) return(error);
1875 /* Have UFS handle the call. */
1876 CODADEBUG(CODA_READDIR, myprintf(("indirect readdir: fid = (%lx.%lx.%lx), refcnt = %d\n",cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique, vp->v_usecount)); )
1877 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1881 MARK_INT_FAIL(CODA_READDIR_STATS);
1883 MARK_INT_SAT(CODA_READDIR_STATS);
1885 /* Do an "internal close" if necessary. */
1886 if (opened_internally) {
1887 MARK_INT_GEN(CODA_CLOSE_STATS);
1888 (void)VOP_CLOSE(vp, FREAD, cred, p);
1896 * Convert from file system blocks to device blocks
1902 /* XXX on the global proc */
1904 struct vop_bmap_args *ap = v;
1905 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1906 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1907 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1908 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
1909 struct proc *p __attribute__((unused)) = curproc;
1919 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1921 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1922 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1926 printf("coda_bmap: no container\n");
1932 * I don't think the following two things are used anywhere, so I've
1933 * commented them out
1935 * struct buf *async_bufhead;
1936 * int async_daemon_count;
1943 struct vop_strategy_args *ap = v;
1944 register struct buf *bp __attribute__((unused)) = ap->a_bp;
1945 struct proc *p __attribute__((unused)) = curproc;
1949 printf("coda_strategy: called ???\n");
1958 struct vop_reclaim_args *ap = v;
1959 struct vnode *vp = ap->a_vp;
1960 struct cnode *cp = VTOC(vp);
1965 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1969 if (IS_UNMOUNTING(cp)) {
1971 if (VTOC(vp)->c_ovp) {
1972 if (IS_UNMOUNTING(cp))
1973 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1977 #ifdef OLD_DIAGNOSTIC
1978 if (vp->v_usecount != 0)
1979 print("coda_reclaim: pushing active %p\n", vp);
1980 if (VTOC(vp)->c_ovp) {
1981 panic("coda_reclaim: c_ovp not void");
1986 coda_free(VTOC(vp));
1996 struct vop_lock_args *ap = v;
1997 struct vnode *vp = ap->a_vp;
1998 struct cnode *cp = VTOC(vp);
1999 struct proc *p = ap->a_p;
2005 if (coda_lockdebug) {
2006 myprintf(("Attempting lock on %lx.%lx.%lx\n",
2007 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
2010 return (lockmgr(&cp->c_lock, ap->a_flags, &vp->v_interlock, p));
2018 struct vop_unlock_args *ap = v;
2019 struct vnode *vp = ap->a_vp;
2020 struct cnode *cp = VTOC(vp);
2021 struct proc *p = ap->a_p;
2026 if (coda_lockdebug) {
2027 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
2028 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
2031 return (lockmgr(&cp->c_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, p));
2039 struct vop_islocked_args *ap = v;
2040 struct cnode *cp = VTOC(ap->a_vp);
2043 return (lockstatus(&cp->c_lock));
2046 /* How one looks up a vnode given a device/inode pair: */
2048 coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
2050 /* This is like VFS_VGET() or igetinode()! */
2054 if (!(mp = devtomp(dev))) {
2055 myprintf(("coda_grab_vnode: devtomp(%d) returns NULL\n", dev));
2059 /* XXX - ensure that nonzero-return means failure */
2060 error = VFS_VGET(mp,ino,vpp);
2062 myprintf(("coda_grab_vnode: iget/vget(%d, %d) returns %p, err %d\n",
2063 dev, ino, *vpp, error));
2075 switch (attr->va_type) {
2109 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
2110 typestr, (int)attr->va_mode, (int)attr->va_uid,
2111 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
2113 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
2114 (int)attr->va_fileid, (int)attr->va_nlink,
2116 (int)attr->va_blocksize,(int)attr->va_bytes));
2117 myprintf((" gen %ld flags %ld vaflags %d\n",
2118 attr->va_gen, attr->va_flags, attr->va_vaflags));
2119 myprintf((" atime sec %d nsec %d\n",
2120 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
2121 myprintf((" mtime sec %d nsec %d\n",
2122 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
2123 myprintf((" ctime sec %d nsec %d\n",
2124 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
2127 /* How to print a ucred */
2135 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
2137 for (i=0; i < cred->cr_ngroups; i++)
2138 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
2144 * Return a vnode for the given fid.
2145 * If no cnode exists for this fid create one and put it
2146 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
2147 * this fid is already in the table return it (ref count is
2148 * incremented by coda_find. The cnode will be flushed from the
2149 * table when coda_inactive calls coda_unsave.
2152 make_coda_node(fid, vfsp, type)
2153 ViceFid *fid; struct mount *vfsp; short type;
2158 if ((cp = coda_find(fid)) == NULL) {
2162 lockinit(&cp->c_lock, PINOD, "cnode", 0, 0);
2165 err = getnewvnode(VT_CODA, vfsp, coda_vnodeop_p, &vp);
2167 panic("coda: getnewvnode returned error %d\n", err);