Rename all the functions and structures for the old VOP namespace API
[dragonfly.git] / sys / vfs / coda / coda_vnops.c
CommitLineData
984263bc
MD
1/*
2 *
3 * Coda: an Experimental Distributed File System
4 * Release 3.1
5 *
6 * Copyright (c) 1987-1998 Carnegie Mellon University
7 * All Rights Reserved
8 *
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
16 * derivatives.
17 *
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.
24 *
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.
28 *
29 * @(#) src/sys/coda/coda_vnops.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $FreeBSD: src/sys/coda/coda_vnops.c,v 1.22.2.1 2001/06/29 16:26:22 shafeeq Exp $
e62afb5f 31 * $DragonFly: src/sys/vfs/coda/Attic/coda_vnops.c,v 1.27 2005/09/14 01:13:23 dillon Exp $
984263bc
MD
32 *
33 */
34
35/*
36 * Mach Operating System
37 * Copyright (c) 1990 Carnegie-Mellon University
38 * Copyright (c) 1989 Carnegie-Mellon University
39 * All rights reserved. The CMU software License Agreement specifies
40 * the terms and conditions for use and redistribution.
41 */
42
43/*
44 * This code was written for the Coda file system at Carnegie Mellon
45 * University. Contributers include David Steere, James Kistler, and
46 * M. Satyanarayanan.
47 */
48
49#include <sys/param.h>
50#include <sys/systm.h>
51#include <sys/kernel.h>
52#include <sys/proc.h>
53#include <sys/malloc.h>
54#include <sys/mount.h>
55#include <sys/errno.h>
56#include <sys/acct.h>
57#include <sys/file.h>
58#include <sys/fcntl.h>
59#include <sys/uio.h>
fad57d0e 60#include <sys/nlookup.h>
984263bc
MD
61#include <sys/namei.h>
62#include <sys/ioccom.h>
63#include <sys/select.h>
64
65#include <vm/vm.h>
66#include <vm/vm_object.h>
67#include <vm/vm_extern.h>
68#include <vm/vm_zone.h>
69
1f2de5d4
MD
70#include "coda.h"
71#include "cnode.h"
72#include "coda_vnops.h"
73#include "coda_venus.h"
74#include "coda_opstats.h"
75#include "coda_subr.h"
76#include "coda_namecache.h"
77#include "coda_pioctl.h"
984263bc
MD
78
79/*
80 * These flags select various performance enhancements.
81 */
82int coda_attr_cache = 1; /* Set to cache attributes in the kernel */
83int coda_symlink_cache = 1; /* Set to cache symbolic link information */
84int coda_access_cache = 1; /* Set to handle some access checks directly */
85
86/* structure to keep track of vfs calls */
87
88struct coda_op_stats coda_vnodeopstats[CODA_VNODEOPS_SIZE];
89
90#define MARK_ENTRY(op) (coda_vnodeopstats[op].entries++)
91#define MARK_INT_SAT(op) (coda_vnodeopstats[op].sat_intrn++)
92#define MARK_INT_FAIL(op) (coda_vnodeopstats[op].unsat_intrn++)
93#define MARK_INT_GEN(op) (coda_vnodeopstats[op].gen_intrn++)
94
95/* What we are delaying for in printf */
96int coda_printf_delay = 0; /* in microseconds */
97int coda_vnop_print_entry = 0;
98static int coda_lockdebug = 0;
99
100/* Definition of the vfs operation vector */
101
102/*
103 * Some NetBSD details:
104 *
105 * coda_start is called at the end of the mount syscall.
106 * coda_init is called at boot time.
107 */
108
5e2195bf 109#define ENTRY if(coda_vnop_print_entry) myprintf(("Entered %s\n",__func__))
984263bc
MD
110
111/* Definition of the vnode operation vector */
112
113struct vnodeopv_entry_desc coda_vnodeop_entries[] = {
625ddaba 114 { &vop_default_desc, (vnodeopv_entry_t)coda_vop_error },
e62afb5f
MD
115 { &vop_old_lookup_desc, (vnodeopv_entry_t)coda_lookup }, /* lookup */
116 { &vop_old_create_desc, (vnodeopv_entry_t)coda_create }, /* create */
117 { &vop_old_mknod_desc, (vnodeopv_entry_t)coda_vop_error }, /* mknod */
625ddaba
JS
118 { &vop_open_desc, (vnodeopv_entry_t)coda_open }, /* open */
119 { &vop_close_desc, (vnodeopv_entry_t)coda_close }, /* close */
120 { &vop_access_desc, (vnodeopv_entry_t)coda_access }, /* access */
121 { &vop_getattr_desc, (vnodeopv_entry_t)coda_getattr }, /* getattr */
122 { &vop_setattr_desc, (vnodeopv_entry_t)coda_setattr }, /* setattr */
123 { &vop_read_desc, (vnodeopv_entry_t)coda_read }, /* read */
124 { &vop_write_desc, (vnodeopv_entry_t)coda_write }, /* write */
125 { &vop_ioctl_desc, (vnodeopv_entry_t)coda_ioctl }, /* ioctl */
126 { &vop_mmap_desc, (vnodeopv_entry_t)coda_vop_error }, /* mmap */
127 { &vop_fsync_desc, (vnodeopv_entry_t)coda_fsync }, /* fsync */
e62afb5f
MD
128 { &vop_old_remove_desc, (vnodeopv_entry_t)coda_remove }, /* remove */
129 { &vop_old_link_desc, (vnodeopv_entry_t)coda_link }, /* link */
130 { &vop_old_rename_desc, (vnodeopv_entry_t)coda_rename }, /* rename */
131 { &vop_old_mkdir_desc, (vnodeopv_entry_t)coda_mkdir }, /* mkdir */
132 { &vop_old_rmdir_desc, (vnodeopv_entry_t)coda_rmdir }, /* rmdir */
133 { &vop_old_symlink_desc, (vnodeopv_entry_t)coda_symlink }, /* symlink */
625ddaba
JS
134 { &vop_readdir_desc, (vnodeopv_entry_t)coda_readdir }, /* readdir */
135 { &vop_readlink_desc, (vnodeopv_entry_t)coda_readlink }, /* readlink */
136 { &vop_inactive_desc, (vnodeopv_entry_t)coda_inactive }, /* inactive */
137 { &vop_reclaim_desc, (vnodeopv_entry_t)coda_reclaim }, /* reclaim */
138 { &vop_lock_desc, (vnodeopv_entry_t)coda_lock }, /* lock */
139 { &vop_unlock_desc, (vnodeopv_entry_t)coda_unlock }, /* unlock */
140 { &vop_bmap_desc, (vnodeopv_entry_t)coda_bmap }, /* bmap */
141 { &vop_strategy_desc, (vnodeopv_entry_t)coda_strategy }, /* strategy */
142 { &vop_print_desc, (vnodeopv_entry_t)coda_vop_error }, /* print */
143 { &vop_islocked_desc, (vnodeopv_entry_t)coda_islocked }, /* islocked */
144 { &vop_pathconf_desc, (vnodeopv_entry_t)coda_vop_error }, /* pathconf */
145 { &vop_advlock_desc, (vnodeopv_entry_t)coda_vop_nop }, /* advlock */
146 { &vop_bwrite_desc, (vnodeopv_entry_t)coda_vop_error }, /* bwrite */
147 { &vop_lease_desc, (vnodeopv_entry_t)coda_vop_nop }, /* lease */
e62afb5f 148 { &vop_poll_desc, (vnodeopv_entry_t)vop_stdpoll }, /* poll */
625ddaba
JS
149 { &vop_getpages_desc, (vnodeopv_entry_t)coda_fbsd_getpages }, /* pager intf.*/
150 { &vop_putpages_desc, (vnodeopv_entry_t)coda_fbsd_putpages }, /* pager intf.*/
e62afb5f
MD
151 { &vop_createvobject_desc, (vnodeopv_entry_t)vop_stdcreatevobject },
152 { &vop_destroyvobject_desc, (vnodeopv_entry_t)vop_stddestroyvobject },
153 { &vop_getvobject_desc, (vnodeopv_entry_t)vop_stdgetvobject },
984263bc
MD
154
155#if 0
156
157 we need to define these someday
158#define UFS_BLKATOFF(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_blkatoff(aa, bb, cc, dd)
159#define UFS_VALLOC(aa, bb, cc, dd) VFSTOUFS((aa)->v_mount)->um_valloc(aa, bb, cc, dd)
160#define UFS_VFREE(aa, bb, cc) VFSTOUFS((aa)->v_mount)->um_vfree(aa, bb, cc)
161#define UFS_TRUNCATE(aa, bb, cc, dd, ee) VFSTOUFS((aa)->v_mount)->um_truncate(aa, bb, cc, dd, ee)
162#define UFS_UPDATE(aa, bb) VFSTOUFS((aa)->v_mount)->um_update(aa, bb)
163
164 missing
625ddaba 165 { &vop_reallocblks_desc, (vnodeopv_entry_t) ufs_missingop },
e62afb5f
MD
166 { &vop_old_lookup_desc, (vnodeopv_entry_t) ufs_lookup },
167 { &vop_old_whiteout_desc, (vnodeopv_entry_t) ufs_whiteout },
984263bc 168#endif
2d3e977e 169 { NULL, NULL }
984263bc
MD
170};
171
984263bc
MD
172/* A generic panic: we were called with something we didn't define yet */
173int
085d998b
CP
174coda_vop_error(void *anon)
175{
984263bc
MD
176 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
177
178 myprintf(("coda_vop_error: Vnode operation %s called, but not defined.\n",
179 (*desc)->vdesc_name));
180 /*
181 panic("coda_vop_error");
182 */
183 return EIO;
184}
185
186/* A generic do-nothing. For lease_check, advlock */
187int
085d998b
CP
188coda_vop_nop(void *anon)
189{
984263bc
MD
190 struct vnodeop_desc **desc = (struct vnodeop_desc **)anon;
191
192 if (codadebug) {
193 myprintf(("Vnode operation %s called, but unsupported\n",
194 (*desc)->vdesc_name));
195 }
196 return (0);
197}
198
199int
200coda_vnodeopstats_init(void)
201{
31a0fcd9 202 int i;
984263bc
MD
203
204 for(i=0;i<CODA_VNODEOPS_SIZE;i++) {
205 coda_vnodeopstats[i].opcode = i;
206 coda_vnodeopstats[i].entries = 0;
207 coda_vnodeopstats[i].sat_intrn = 0;
208 coda_vnodeopstats[i].unsat_intrn = 0;
209 coda_vnodeopstats[i].gen_intrn = 0;
210 }
211 return 0;
212}
213
214/*
215 * coda_open calls Venus to return the device, inode pair of the cache
216 * file holding the data. Using iget, coda_open finds the vnode of the
217 * cache file, and then opens it.
218 */
219int
085d998b 220coda_open(void *v)
984263bc
MD
221{
222 /*
223 * NetBSD can pass the O_EXCL flag in mode, even though the check
224 * has already happened. Venus defensively assumes that if open
225 * is passed the EXCL, it must be a bug. We strip the flag here.
226 */
227/* true args */
228 struct vop_open_args *ap = v;
31a0fcd9 229 struct vnode **vpp = &(ap->a_vp);
984263bc
MD
230 struct cnode *cp = VTOC(*vpp);
231 int flag = ap->a_mode & (~O_EXCL);
232 struct ucred *cred = ap->a_cred;
dadab5e9 233 struct thread *td = ap->a_td;
984263bc
MD
234/* locals */
235 int error;
236 struct vnode *vp;
237 dev_t dev;
238 ino_t inode;
239
240 MARK_ENTRY(CODA_OPEN_STATS);
241
242 /* Check for open of control file. */
243 if (IS_CTL_VP(*vpp)) {
244 /* XXX */
245 /* if (WRITEABLE(flag)) */
246 if (flag & (FWRITE | O_TRUNC | O_CREAT | O_EXCL)) {
247 MARK_INT_FAIL(CODA_OPEN_STATS);
248 return(EACCES);
249 }
250 MARK_INT_SAT(CODA_OPEN_STATS);
251 return(0);
252 }
253
dadab5e9 254 error = venus_open(vtomi((*vpp)), &cp->c_fid, flag, cred, td, &dev, &inode);
984263bc
MD
255 if (error)
256 return (error);
257 if (!error) {
258 CODADEBUG( CODA_OPEN,myprintf(("open: dev %#lx inode %lu result %d\n",
259 (u_long)dev2udev(dev), (u_long)inode,
260 error)); )
261 }
262
263 /* Translate the <device, inode> pair for the cache file into
264 an inode pointer. */
265 error = coda_grab_vnode(dev, inode, &vp);
266 if (error)
267 return (error);
268
269 /* We get the vnode back locked. Needs unlocked */
5fd012e0 270 VOP_UNLOCK(vp, 0, td);
984263bc
MD
271 /* Keep a reference until the close comes in. */
272 vref(*vpp);
273
274 /* Save the vnode pointer for the cache file. */
275 if (cp->c_ovp == NULL) {
276 cp->c_ovp = vp;
277 } else {
278 if (cp->c_ovp != vp)
279 panic("coda_open: cp->c_ovp != ITOV(ip)");
280 }
281 cp->c_ocount++;
282
283 /* Flush the attribute cached if writing the file. */
284 if (flag & FWRITE) {
285 cp->c_owrite++;
286 cp->c_flags &= ~C_VATTR;
287 }
288
289 /* Save the <device, inode> pair for the cache file to speed
290 up subsequent page_read's. */
291 cp->c_device = dev;
292 cp->c_inode = inode;
293
294 /* Open the cache file. */
fad57d0e 295 error = VOP_OPEN(vp, flag, cred, NULL, td);
984263bc
MD
296 if (error) {
297 printf("coda_open: VOP_OPEN on container failed %d\n", error);
298 return (error);
299 }
300/* grab (above) does this when it calls newvnode unless it's in the cache*/
301 if (vp->v_type == VREG) {
3b568787 302 error = vfs_object_create(vp, td);
984263bc
MD
303 if (error != 0) {
304 printf("coda_open: vfs_object_create() returns %d\n", error);
305 vput(vp);
306 }
307 }
308
309 return(error);
310}
311
312/*
313 * Close the cache file used for I/O and notify Venus.
314 */
315int
085d998b 316coda_close(void *v)
984263bc
MD
317{
318/* true args */
319 struct vop_close_args *ap = v;
320 struct vnode *vp = ap->a_vp;
321 struct cnode *cp = VTOC(vp);
322 int flag = ap->a_fflag;
dadab5e9 323 struct thread *td = ap->a_td;
984263bc
MD
324/* locals */
325 int error;
326
327 MARK_ENTRY(CODA_CLOSE_STATS);
328
329 /* Check for close of control file. */
330 if (IS_CTL_VP(vp)) {
331 MARK_INT_SAT(CODA_CLOSE_STATS);
332 return(0);
333 }
334
335 if (IS_UNMOUNTING(cp)) {
336 if (cp->c_ovp) {
337#ifdef CODA_VERBOSE
338 printf("coda_close: destroying container ref %d, ufs vp %p of vp %p/cp %p\n",
339 vp->v_usecount, cp->c_ovp, vp, cp);
340#endif
341#ifdef hmm
342 vgone(cp->c_ovp);
343#else
3b568787 344 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
984263bc
MD
345 vrele(cp->c_ovp);
346#endif
347 } else {
348#ifdef CODA_VERBOSE
349 printf("coda_close: NO container vp %p/cp %p\n", vp, cp);
350#endif
351 }
352 return ENODEV;
353 } else {
3b568787 354 VOP_CLOSE(cp->c_ovp, flag, td); /* Do errors matter here? */
984263bc
MD
355 vrele(cp->c_ovp);
356 }
357
358 if (--cp->c_ocount == 0)
359 cp->c_ovp = NULL;
360
361 if (flag & FWRITE) /* file was opened for write */
362 --cp->c_owrite;
363
3b568787 364 error = venus_close(vtomi(vp), &cp->c_fid, flag, proc0.p_ucred, td);
984263bc
MD
365 vrele(CTOV(cp));
366
367 CODADEBUG(CODA_CLOSE, myprintf(("close: result %d\n",error)); )
368 return(error);
369}
370
371int
085d998b 372coda_read(void *v)
984263bc
MD
373{
374 struct vop_read_args *ap = v;
375
376 ENTRY;
377 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_READ,
dadab5e9 378 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
984263bc
MD
379}
380
381int
085d998b 382coda_write(void *v)
984263bc
MD
383{
384 struct vop_write_args *ap = v;
385
386 ENTRY;
387 return(coda_rdwr(ap->a_vp, ap->a_uio, UIO_WRITE,
dadab5e9 388 ap->a_ioflag, ap->a_cred, ap->a_uio->uio_td));
984263bc
MD
389}
390
391int
085d998b
CP
392coda_rdwr(struct vnode *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
393 struct ucred *cred, struct thread *td)
984263bc
MD
394{
395/* upcall decl */
396 /* NOTE: container file operation!!! */
397/* locals */
398 struct cnode *cp = VTOC(vp);
399 struct vnode *cfvp = cp->c_ovp;
400 int igot_internally = 0;
401 int opened_internally = 0;
402 int error = 0;
403
404 MARK_ENTRY(CODA_RDWR_STATS);
405
406 CODADEBUG(CODA_RDWR, myprintf(("coda_rdwr(%d, %p, %d, %lld, %d)\n", rw,
407 (void *)uiop->uio_iov->iov_base, uiop->uio_resid,
408 (long long)uiop->uio_offset, uiop->uio_segflg)); )
409
410 /* Check for rdwr of control object. */
411 if (IS_CTL_VP(vp)) {
412 MARK_INT_FAIL(CODA_RDWR_STATS);
413 return(EINVAL);
414 }
415
416 /*
417 * If file is not already open this must be a page
418 * {read,write} request. Iget the cache file's inode
419 * pointer if we still have its <device, inode> pair.
420 * Otherwise, we must do an internal open to derive the
421 * pair.
422 */
423 if (cfvp == NULL) {
424 /*
425 * If we're dumping core, do the internal open. Otherwise
426 * venus won't have the correct size of the core when
427 * it's completely written.
428 */
908b5ff6 429 if (cp->c_inode != 0 && (ioflag & IO_CORE) == 0) {
984263bc
MD
430 igot_internally = 1;
431 error = coda_grab_vnode(cp->c_device, cp->c_inode, &cfvp);
432 if (error) {
433 MARK_INT_FAIL(CODA_RDWR_STATS);
434 return(error);
435 }
436 /*
437 * We get the vnode back locked in both Mach and
438 * NetBSD. Needs unlocked
439 */
5fd012e0 440 VOP_UNLOCK(cfvp, 0, td);
984263bc
MD
441 }
442 else {
443 opened_internally = 1;
444 MARK_INT_GEN(CODA_OPEN_STATS);
445 error = VOP_OPEN(vp, (rw == UIO_READ ? FREAD : FWRITE),
fad57d0e 446 cred, NULL, td);
984263bc
MD
447printf("coda_rdwr: Internally Opening %p\n", vp);
448 if (error) {
449 printf("coda_rdwr: VOP_OPEN on container failed %d\n", error);
450 return (error);
451 }
452 if (vp->v_type == VREG) {
3b568787 453 error = vfs_object_create(vp, td);
984263bc
MD
454 if (error != 0) {
455 printf("coda_rdwr: vfs_object_create() returns %d\n", error);
456 vput(vp);
457 }
458 }
459 if (error) {
460 MARK_INT_FAIL(CODA_RDWR_STATS);
461 return(error);
462 }
463 cfvp = cp->c_ovp;
464 }
465 }
466
467 /* Have UFS handle the call. */
468 CODADEBUG(CODA_RDWR, myprintf(("indirect rdwr: fid = (%lx.%lx.%lx), refcnt = %d\n",
469 cp->c_fid.Volume, cp->c_fid.Vnode,
470 cp->c_fid.Unique, CTOV(cp)->v_usecount)); )
471
472
473 if (rw == UIO_READ) {
474 error = VOP_READ(cfvp, uiop, ioflag, cred);
475 } else {
476 error = VOP_WRITE(cfvp, uiop, ioflag, cred);
477 /* ufs_write updates the vnode_pager_setsize for the vnode/object */
478
479 { struct vattr attr;
480
3b568787 481 if (VOP_GETATTR(cfvp, &attr, td) == 0) {
984263bc
MD
482 vnode_pager_setsize(vp, attr.va_size);
483 }
484 }
485 }
486
487 if (error)
488 MARK_INT_FAIL(CODA_RDWR_STATS);
489 else
490 MARK_INT_SAT(CODA_RDWR_STATS);
491
492 /* Do an internal close if necessary. */
493 if (opened_internally) {
494 MARK_INT_GEN(CODA_CLOSE_STATS);
3b568787 495 (void)VOP_CLOSE(vp, (rw == UIO_READ ? FREAD : FWRITE), td);
984263bc
MD
496 }
497
498 /* Invalidate cached attributes if writing. */
499 if (rw == UIO_WRITE)
500 cp->c_flags &= ~C_VATTR;
501 return(error);
502}
503
504int
085d998b 505coda_ioctl(void *v)
984263bc
MD
506{
507/* true args */
508 struct vop_ioctl_args *ap = v;
509 struct vnode *vp = ap->a_vp;
510 int com = ap->a_command;
511 caddr_t data = ap->a_data;
512 int flag = ap->a_fflag;
513 struct ucred *cred = ap->a_cred;
dadab5e9 514 struct thread *td = ap->a_td;
984263bc
MD
515/* locals */
516 int error;
517 struct vnode *tvp;
fad57d0e 518 struct nlookupdata nd;
984263bc
MD
519 struct PioctlData *iap = (struct PioctlData *)data;
520
521 MARK_ENTRY(CODA_IOCTL_STATS);
522
523 CODADEBUG(CODA_IOCTL, myprintf(("in coda_ioctl on %s\n", iap->path));)
524
525 /* Don't check for operation on a dying object, for ctlvp it
526 shouldn't matter */
527
528 /* Must be control object to succeed. */
529 if (!IS_CTL_VP(vp)) {
530 MARK_INT_FAIL(CODA_IOCTL_STATS);
531 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: vp != ctlvp"));)
532 return (EOPNOTSUPP);
533 }
534 /* Look up the pathname. */
535
536 /* Should we use the name cache here? It would get it from
537 lookupname sooner or later anyway, right? */
538
fad57d0e
MD
539 tvp = NULL;
540 error = nlookup_init(&nd, iap->path, UIO_USERSPACE,
541 (iap->follow ? NLC_FOLLOW : 0));
542 if (error == 0)
543 error = nlookup(&nd);
544 if (error == 0)
545 error = cache_vref(nd.nl_ncp, nd.nl_cred, &tvp);
546 nlookup_done(&nd);
984263bc
MD
547
548 if (error) {
549 MARK_INT_FAIL(CODA_IOCTL_STATS);
550 CODADEBUG(CODA_IOCTL, myprintf(("coda_ioctl error: lookup returns %d\n",
551 error));)
552 return(error);
553 }
554
555 /*
556 * Make sure this is a coda style cnode, but it may be a
557 * different vfsp
558 */
0961aa92 559 if (tvp->v_tag != VT_CODA) {
984263bc 560 vrele(tvp);
984263bc
MD
561 MARK_INT_FAIL(CODA_IOCTL_STATS);
562 CODADEBUG(CODA_IOCTL,
563 myprintf(("coda_ioctl error: %s not a coda object\n",
564 iap->path));)
565 return(EINVAL);
566 }
567
568 if (iap->vi.in_size > VC_MAXDATASIZE) {
fad57d0e 569 vrele(tvp);
984263bc
MD
570 return(EINVAL);
571 }
dadab5e9 572 error = venus_ioctl(vtomi(tvp), &((VTOC(tvp))->c_fid), com, flag, data, cred, td);
984263bc
MD
573
574 if (error)
575 MARK_INT_FAIL(CODA_IOCTL_STATS);
576 else
577 CODADEBUG(CODA_IOCTL, myprintf(("Ioctl returns %d \n", error)); )
578
579 vrele(tvp);
984263bc
MD
580 return(error);
581}
582
583/*
584 * To reduce the cost of a user-level venus;we cache attributes in
585 * the kernel. Each cnode has storage allocated for an attribute. If
586 * c_vattr is valid, return a reference to it. Otherwise, get the
587 * attributes from venus and store them in the cnode. There is some
588 * question if this method is a security leak. But I think that in
589 * order to make this call, the user must have done a lookup and
590 * opened the file, and therefore should already have access.
591 */
592int
085d998b 593coda_getattr(void *v)
984263bc
MD
594{
595/* true args */
596 struct vop_getattr_args *ap = v;
597 struct vnode *vp = ap->a_vp;
598 struct cnode *cp = VTOC(vp);
599 struct vattr *vap = ap->a_vap;
dadab5e9 600 struct thread *td = ap->a_td;
984263bc
MD
601/* locals */
602 int error;
603
604 MARK_ENTRY(CODA_GETATTR_STATS);
605
606 if (IS_UNMOUNTING(cp))
607 return ENODEV;
608
609 /* Check for getattr of control object. */
610 if (IS_CTL_VP(vp)) {
611 MARK_INT_FAIL(CODA_GETATTR_STATS);
612 return(ENOENT);
613 }
614
615 /* Check to see if the attributes have already been cached */
616 if (VALID_VATTR(cp)) {
617 CODADEBUG(CODA_GETATTR, { myprintf(("attr cache hit: (%lx.%lx.%lx)\n",
618 cp->c_fid.Volume,
619 cp->c_fid.Vnode,
620 cp->c_fid.Unique));});
621 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
622 print_vattr(&cp->c_vattr); );
623
624 *vap = cp->c_vattr;
625 MARK_INT_SAT(CODA_GETATTR_STATS);
626 return(0);
627 }
628
3b568787 629 error = venus_getattr(vtomi(vp), &cp->c_fid, proc0.p_ucred, td, vap);
984263bc
MD
630
631 if (!error) {
632 CODADEBUG(CODA_GETATTR, myprintf(("getattr miss (%lx.%lx.%lx): result %d\n",
633 cp->c_fid.Volume,
634 cp->c_fid.Vnode,
635 cp->c_fid.Unique,
636 error)); )
637
638 CODADEBUG(CODA_GETATTR, if (!(codadebug & ~CODA_GETATTR))
639 print_vattr(vap); );
640
641 { int size = vap->va_size;
642 struct vnode *convp = cp->c_ovp;
643 if (convp != (struct vnode *)0) {
644 vnode_pager_setsize(convp, size);
645 }
646 }
647 /* If not open for write, store attributes in cnode */
648 if ((cp->c_owrite == 0) && (coda_attr_cache)) {
649 cp->c_vattr = *vap;
650 cp->c_flags |= C_VATTR;
651 }
652
653 }
654 return(error);
655}
656
657int
085d998b 658coda_setattr(void *v)
984263bc
MD
659{
660/* true args */
661 struct vop_setattr_args *ap = v;
31a0fcd9 662 struct vnode *vp = ap->a_vp;
984263bc 663 struct cnode *cp = VTOC(vp);
31a0fcd9 664 struct vattr *vap = ap->a_vap;
984263bc 665 struct ucred *cred = ap->a_cred;
dadab5e9 666 struct thread *td = ap->a_td;
984263bc
MD
667/* locals */
668 int error;
669
670 MARK_ENTRY(CODA_SETATTR_STATS);
671
672 /* Check for setattr of control object. */
673 if (IS_CTL_VP(vp)) {
674 MARK_INT_FAIL(CODA_SETATTR_STATS);
675 return(ENOENT);
676 }
677
678 if (codadebug & CODADBGMSK(CODA_SETATTR)) {
679 print_vattr(vap);
680 }
dadab5e9 681 error = venus_setattr(vtomi(vp), &cp->c_fid, vap, cred, td);
984263bc
MD
682
683 if (!error)
684 cp->c_flags &= ~C_VATTR;
685
686 { int size = vap->va_size;
687 struct vnode *convp = cp->c_ovp;
688 if (size != VNOVAL && convp != (struct vnode *)0) {
689 vnode_pager_setsize(convp, size);
690 }
691 }
692 CODADEBUG(CODA_SETATTR, myprintf(("setattr %d\n", error)); )
693 return(error);
694}
695
696int
085d998b 697coda_access(void *v)
984263bc
MD
698{
699/* true args */
700 struct vop_access_args *ap = v;
701 struct vnode *vp = ap->a_vp;
702 struct cnode *cp = VTOC(vp);
703 int mode = ap->a_mode;
704 struct ucred *cred = ap->a_cred;
dadab5e9 705 struct thread *td = ap->a_td;
984263bc
MD
706/* locals */
707 int error;
708
709 MARK_ENTRY(CODA_ACCESS_STATS);
710
711 /* Check for access of control object. Only read access is
712 allowed on it. */
713 if (IS_CTL_VP(vp)) {
714 /* bogus hack - all will be marked as successes */
715 MARK_INT_SAT(CODA_ACCESS_STATS);
716 return(((mode & VREAD) && !(mode & (VWRITE | VEXEC)))
717 ? 0 : EACCES);
718 }
719
720 /*
721 * if the file is a directory, and we are checking exec (eg lookup)
722 * access, and the file is in the namecache, then the user must have
723 * lookup access to it.
724 */
725 if (coda_access_cache) {
726 if ((vp->v_type == VDIR) && (mode & VEXEC)) {
727 if (coda_nc_lookup(cp, ".", 1, cred)) {
728 MARK_INT_SAT(CODA_ACCESS_STATS);
729 return(0); /* it was in the cache */
730 }
731 }
732 }
733
dadab5e9 734 error = venus_access(vtomi(vp), &cp->c_fid, mode, cred, td);
984263bc
MD
735
736 return(error);
737}
738
739int
085d998b 740coda_readlink(void *v)
984263bc
MD
741{
742/* true args */
743 struct vop_readlink_args *ap = v;
744 struct vnode *vp = ap->a_vp;
745 struct cnode *cp = VTOC(vp);
746 struct uio *uiop = ap->a_uio;
747 struct ucred *cred = ap->a_cred;
dadab5e9 748 struct thread *td = ap->a_uio->uio_td;
984263bc
MD
749/* locals */
750 int error;
751 char *str;
752 int len;
753
754 MARK_ENTRY(CODA_READLINK_STATS);
755
756 /* Check for readlink of control object. */
757 if (IS_CTL_VP(vp)) {
758 MARK_INT_FAIL(CODA_READLINK_STATS);
759 return(ENOENT);
760 }
761
762 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) { /* symlink was cached */
763 uiop->uio_rw = UIO_READ;
764 error = uiomove(cp->c_symlink, (int)cp->c_symlen, uiop);
765 if (error)
766 MARK_INT_FAIL(CODA_READLINK_STATS);
767 else
768 MARK_INT_SAT(CODA_READLINK_STATS);
769 return(error);
770 }
771
dadab5e9 772 error = venus_readlink(vtomi(vp), &cp->c_fid, cred, td, &str, &len);
984263bc
MD
773
774 if (!error) {
775 uiop->uio_rw = UIO_READ;
776 error = uiomove(str, len, uiop);
777
778 if (coda_symlink_cache) {
779 cp->c_symlink = str;
780 cp->c_symlen = len;
781 cp->c_flags |= C_SYMLINK;
782 } else
783 CODA_FREE(str, len);
784 }
785
786 CODADEBUG(CODA_READLINK, myprintf(("in readlink result %d\n",error));)
787 return(error);
788}
789
790int
085d998b 791coda_fsync(void *v)
984263bc
MD
792{
793/* true args */
794 struct vop_fsync_args *ap = v;
795 struct vnode *vp = ap->a_vp;
796 struct cnode *cp = VTOC(vp);
dadab5e9 797 struct thread *td = ap->a_td;
984263bc
MD
798/* locals */
799 struct vnode *convp = cp->c_ovp;
800 int error;
801
802 MARK_ENTRY(CODA_FSYNC_STATS);
803
804 /* Check for fsync on an unmounting object */
805 /* The NetBSD kernel, in it's infinite wisdom, can try to fsync
806 * after an unmount has been initiated. This is a Bad Thing,
807 * which we have to avoid. Not a legitimate failure for stats.
808 */
809 if (IS_UNMOUNTING(cp)) {
810 return(ENODEV);
811 }
812
813 /* Check for fsync of control object. */
814 if (IS_CTL_VP(vp)) {
815 MARK_INT_SAT(CODA_FSYNC_STATS);
816 return(0);
817 }
818
819 if (convp)
3b568787 820 VOP_FSYNC(convp, MNT_WAIT, td);
984263bc
MD
821
822 /*
823 * We see fsyncs with usecount == 1 then usecount == 0.
824 * For now we ignore them.
825 */
826 /*
827 if (!vp->v_usecount) {
828 printf("coda_fsync on vnode %p with %d usecount. c_flags = %x (%x)\n",
829 vp, vp->v_usecount, cp->c_flags, cp->c_flags&C_PURGING);
830 }
831 */
832
833 /*
834 * We can expect fsync on any vnode at all if venus is pruging it.
835 * Venus can't very well answer the fsync request, now can it?
836 * Hopefully, it won't have to, because hopefully, venus preserves
837 * the (possibly untrue) invariant that it never purges an open
838 * vnode. Hopefully.
839 */
840 if (cp->c_flags & C_PURGING) {
841 return(0);
842 }
843
844 /* needs research */
845 return 0;
3b568787 846 error = venus_fsync(vtomi(vp), &cp->c_fid, proc0.p_ucred, td);
984263bc
MD
847
848 CODADEBUG(CODA_FSYNC, myprintf(("in fsync result %d\n",error)); );
849 return(error);
850}
851
852int
085d998b 853coda_inactive(void *v)
984263bc
MD
854{
855 /* XXX - at the moment, inactive doesn't look at cred, and doesn't
856 have a proc pointer. Oops. */
857/* true args */
858 struct vop_inactive_args *ap = v;
859 struct vnode *vp = ap->a_vp;
860 struct cnode *cp = VTOC(vp);
861 struct ucred *cred __attribute__((unused)) = NULL;
5fd012e0 862 /*struct thread *td = curthread;*/
984263bc
MD
863/* upcall decl */
864/* locals */
865
866 /* We don't need to send inactive to venus - DCS */
867 MARK_ENTRY(CODA_INACTIVE_STATS);
868
869 if (IS_CTL_VP(vp)) {
870 MARK_INT_SAT(CODA_INACTIVE_STATS);
871 return 0;
872 }
873
874 CODADEBUG(CODA_INACTIVE, myprintf(("in inactive, %lx.%lx.%lx. vfsp %p\n",
875 cp->c_fid.Volume, cp->c_fid.Vnode,
876 cp->c_fid.Unique, vp->v_mount));)
877
878 /* If an array has been allocated to hold the symlink, deallocate it */
879 if ((coda_symlink_cache) && (VALID_SYMLINK(cp))) {
880 if (cp->c_symlink == NULL)
881 panic("coda_inactive: null symlink pointer in cnode");
882
883 CODA_FREE(cp->c_symlink, cp->c_symlen);
884 cp->c_flags &= ~C_SYMLINK;
885 cp->c_symlen = 0;
886 }
887
888 /* Remove it from the table so it can't be found. */
889 coda_unsave(cp);
890 if ((struct coda_mntinfo *)(vp->v_mount->mnt_data) == NULL) {
891 myprintf(("Help! vfsp->vfs_data was NULL, but vnode %p wasn't dying\n", vp));
892 panic("badness in coda_inactive\n");
893 }
894
895 if (IS_UNMOUNTING(cp)) {
896#ifdef DEBUG
897 printf("coda_inactive: IS_UNMOUNTING use %d: vp %p, cp %p\n", vp->v_usecount, vp, cp);
898 if (cp->c_ovp != NULL)
899 printf("coda_inactive: cp->ovp != NULL use %d: vp %p, cp %p\n",
900 vp->v_usecount, vp, cp);
901#endif
984263bc
MD
902 } else {
903#ifdef OLD_DIAGNOSTIC
904 if (CTOV(cp)->v_usecount) {
905 panic("coda_inactive: nonzero reference count");
906 }
907 if (cp->c_ovp != NULL) {
908 panic("coda_inactive: cp->ovp != NULL");
909 }
910#endif
984263bc
MD
911 vgone(vp);
912 }
913
914 MARK_INT_SAT(CODA_INACTIVE_STATS);
915 return(0);
916}
917
918/*
919 * Remote file system operations having to do with directory manipulation.
920 */
921
922/*
923 * It appears that in NetBSD, lookup is supposed to return the vnode locked
924 */
925int
085d998b 926coda_lookup(void *v)
984263bc
MD
927{
928/* true args */
e62afb5f 929 struct vop_old_lookup_args *ap = v;
984263bc
MD
930 struct vnode *dvp = ap->a_dvp;
931 struct cnode *dcp = VTOC(dvp);
932 struct vnode **vpp = ap->a_vpp;
933 /*
934 * It looks as though ap->a_cnp->ni_cnd->cn_nameptr holds the rest
935 * of the string to xlate, and that we must try to get at least
936 * ap->a_cnp->ni_cnd->cn_namelen of those characters to macth. I
937 * could be wrong.
938 */
939 struct componentname *cnp = ap->a_cnp;
940 struct ucred *cred = cnp->cn_cred;
dadab5e9 941 struct thread *td = cnp->cn_td;
984263bc
MD
942/* locals */
943 struct cnode *cp;
944 const char *nm = cnp->cn_nameptr;
945 int len = cnp->cn_namelen;
946 ViceFid VFid;
947 int vtype;
948 int error = 0;
949
950 MARK_ENTRY(CODA_LOOKUP_STATS);
951
952 CODADEBUG(CODA_LOOKUP, myprintf(("lookup: %s in %lx.%lx.%lx\n",
953 nm, dcp->c_fid.Volume,
954 dcp->c_fid.Vnode, dcp->c_fid.Unique)););
955
956 /* Check for lookup of control object. */
957 if (IS_CTL_NAME(dvp, nm, len)) {
958 *vpp = coda_ctlvp;
959 vref(*vpp);
960 MARK_INT_SAT(CODA_LOOKUP_STATS);
961 goto exit;
962 }
963
964 if (len+1 > CODA_MAXNAMLEN) {
965 MARK_INT_FAIL(CODA_LOOKUP_STATS);
966 CODADEBUG(CODA_LOOKUP, myprintf(("name too long: lookup, %lx.%lx.%lx(%s)\n",
967 dcp->c_fid.Volume, dcp->c_fid.Vnode,
968 dcp->c_fid.Unique, nm)););
969 *vpp = (struct vnode *)0;
970 error = EINVAL;
971 goto exit;
972 }
973 /* First try to look the file up in the cfs name cache */
974 /* lock the parent vnode? */
975 cp = coda_nc_lookup(dcp, nm, len, cred);
976 if (cp) {
977 *vpp = CTOV(cp);
978 vref(*vpp);
979 CODADEBUG(CODA_LOOKUP,
980 myprintf(("lookup result %d vpp %p\n",error,*vpp));)
981 } else {
982
983 /* The name wasn't cached, so we need to contact Venus */
dadab5e9 984 error = venus_lookup(vtomi(dvp), &dcp->c_fid, nm, len, cred, td, &VFid, &vtype);
984263bc
MD
985
986 if (error) {
987 MARK_INT_FAIL(CODA_LOOKUP_STATS);
988 CODADEBUG(CODA_LOOKUP, myprintf(("lookup error on %lx.%lx.%lx(%s)%d\n",
989 dcp->c_fid.Volume, dcp->c_fid.Vnode, dcp->c_fid.Unique, nm, error));)
990 *vpp = (struct vnode *)0;
991 } else {
992 MARK_INT_SAT(CODA_LOOKUP_STATS);
993 CODADEBUG(CODA_LOOKUP,
994 myprintf(("lookup: vol %lx vno %lx uni %lx type %o result %d\n",
995 VFid.Volume, VFid.Vnode, VFid.Unique, vtype,
996 error)); )
997
998 cp = make_coda_node(&VFid, dvp->v_mount, vtype);
999 *vpp = CTOV(cp);
1000
1001 /* enter the new vnode in the Name Cache only if the top bit isn't set */
1002 /* And don't enter a new vnode for an invalid one! */
1003 if (!(vtype & CODA_NOCACHE))
1004 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1005 }
1006 }
1007
1008 exit:
1009 /*
1010 * If we are creating, and this was the last name to be looked up,
1011 * and the error was ENOENT, then there really shouldn't be an
1012 * error and we can make the leaf NULL and return success. Since
1013 * this is supposed to work under Mach as well as NetBSD, we're
1014 * leaving this fn wrapped. We also must tell lookup/namei that
1015 * we need to save the last component of the name. (Create will
1016 * have to free the name buffer later...lucky us...)
1017 */
fad57d0e
MD
1018 if ((cnp->cn_nameiop == NAMEI_CREATE || cnp->cn_nameiop == NAMEI_RENAME)
1019 && error == ENOENT)
984263bc
MD
1020 {
1021 error = EJUSTRETURN;
984263bc
MD
1022 *ap->a_vpp = NULL;
1023 }
1024
984263bc
MD
1025 /*
1026 * If the lookup went well, we need to (potentially?) unlock the
1027 * parent, and lock the child. We are only responsible for
1028 * checking to see if the parent is supposed to be unlocked before
1029 * we return. We must always lock the child (provided there is
1030 * one, and (the parent isn't locked or it isn't the same as the
1031 * parent.) Simple, huh? We can never leave the parent locked unless
1032 * we are ISLASTCN
1033 */
1034 if (!error || (error == EJUSTRETURN)) {
fad57d0e 1035 if ((cnp->cn_flags & CNP_LOCKPARENT) == 0) {
5fd012e0 1036 if ((error = VOP_UNLOCK(dvp, 0, td))) {
984263bc
MD
1037 return error;
1038 }
1039 /*
1040 * The parent is unlocked. As long as there is a child,
1041 * lock it without bothering to check anything else.
1042 */
1043 if (*ap->a_vpp) {
5fd012e0 1044 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
984263bc
MD
1045 printf("coda_lookup: ");
1046 panic("unlocked parent but couldn't lock child");
1047 }
1048 }
1049 } else {
1050 /* The parent is locked, and may be the same as the child */
1051 if (*ap->a_vpp && (*ap->a_vpp != dvp)) {
1052 /* Different, go ahead and lock it. */
5fd012e0 1053 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
984263bc
MD
1054 printf("coda_lookup: ");
1055 panic("unlocked parent but couldn't lock child");
1056 }
1057 }
1058 }
1059 } else {
1060 /* If the lookup failed, we need to ensure that the leaf is NULL */
1061 /* Don't change any locking? */
1062 *ap->a_vpp = NULL;
1063 }
1064 return(error);
1065}
1066
1067/*ARGSUSED*/
1068int
085d998b 1069coda_create(void *v)
984263bc
MD
1070{
1071/* true args */
e62afb5f 1072 struct vop_old_create_args *ap = v;
984263bc
MD
1073 struct vnode *dvp = ap->a_dvp;
1074 struct cnode *dcp = VTOC(dvp);
1075 struct vattr *va = ap->a_vap;
1076 int exclusive = 1;
1077 int mode = ap->a_vap->va_mode;
1078 struct vnode **vpp = ap->a_vpp;
1079 struct componentname *cnp = ap->a_cnp;
1080 struct ucred *cred = cnp->cn_cred;
dadab5e9 1081 struct thread *td = cnp->cn_td;
984263bc
MD
1082/* locals */
1083 int error;
1084 struct cnode *cp;
1085 const char *nm = cnp->cn_nameptr;
1086 int len = cnp->cn_namelen;
1087 ViceFid VFid;
1088 struct vattr attr;
1089
1090 MARK_ENTRY(CODA_CREATE_STATS);
1091
1092 /* All creates are exclusive XXX */
1093 /* I'm assuming the 'mode' argument is the file mode bits XXX */
1094
1095 /* Check for create of control object. */
1096 if (IS_CTL_NAME(dvp, nm, len)) {
1097 *vpp = (struct vnode *)0;
1098 MARK_INT_FAIL(CODA_CREATE_STATS);
1099 return(EACCES);
1100 }
1101
dadab5e9 1102 error = venus_create(vtomi(dvp), &dcp->c_fid, nm, len, exclusive, mode, va, cred, td, &VFid, &attr);
984263bc
MD
1103
1104 if (!error) {
1105
1106 /* If this is an exclusive create, panic if the file already exists. */
1107 /* Venus should have detected the file and reported EEXIST. */
1108
1109 if ((exclusive == 1) &&
1110 (coda_find(&VFid) != NULL))
1111 panic("cnode existed for newly created file!");
1112
1113 cp = make_coda_node(&VFid, dvp->v_mount, attr.va_type);
1114 *vpp = CTOV(cp);
1115
1116 /* Update va to reflect the new attributes. */
1117 (*va) = attr;
1118
1119 /* Update the attribute cache and mark it as valid */
1120 if (coda_attr_cache) {
1121 VTOC(*vpp)->c_vattr = attr;
1122 VTOC(*vpp)->c_flags |= C_VATTR;
1123 }
1124
1125 /* Invalidate the parent's attr cache, the modification time has changed */
1126 VTOC(dvp)->c_flags &= ~C_VATTR;
1127
1128 /* enter the new vnode in the Name Cache */
1129 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1130
1131 CODADEBUG(CODA_CREATE,
1132 myprintf(("create: (%lx.%lx.%lx), result %d\n",
1133 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1134 } else {
1135 *vpp = (struct vnode *)0;
1136 CODADEBUG(CODA_CREATE, myprintf(("create error %d\n", error));)
1137 }
1138
1139 if (!error) {
fad57d0e
MD
1140 if ((error = VOP_LOCK(*ap->a_vpp, LK_EXCLUSIVE, td))) {
1141 printf("coda_create: ");
1142 panic("unlocked parent but couldn't lock child");
984263bc 1143 }
984263bc
MD
1144 }
1145 return(error);
1146}
1147
1148int
085d998b 1149coda_remove(void *v)
984263bc
MD
1150{
1151/* true args */
e62afb5f 1152 struct vop_old_remove_args *ap = v;
984263bc
MD
1153 struct vnode *dvp = ap->a_dvp;
1154 struct cnode *cp = VTOC(dvp);
1155 struct componentname *cnp = ap->a_cnp;
1156 struct ucred *cred = cnp->cn_cred;
dadab5e9 1157 struct thread *td = cnp->cn_td;
984263bc
MD
1158/* locals */
1159 int error;
1160 const char *nm = cnp->cn_nameptr;
1161 int len = cnp->cn_namelen;
1162 struct cnode *tp;
1163
1164 MARK_ENTRY(CODA_REMOVE_STATS);
1165
1166 CODADEBUG(CODA_REMOVE, myprintf(("remove: %s in %lx.%lx.%lx\n",
1167 nm, cp->c_fid.Volume, cp->c_fid.Vnode,
1168 cp->c_fid.Unique)););
1169
1170 /* Remove the file's entry from the CODA Name Cache */
1171 /* We're being conservative here, it might be that this person
1172 * doesn't really have sufficient access to delete the file
1173 * but we feel zapping the entry won't really hurt anyone -- dcs
1174 */
1175 /* I'm gonna go out on a limb here. If a file and a hardlink to it
1176 * exist, and one is removed, the link count on the other will be
1177 * off by 1. We could either invalidate the attrs if cached, or
1178 * fix them. I'll try to fix them. DCS 11/8/94
1179 */
1180 tp = coda_nc_lookup(VTOC(dvp), nm, len, cred);
1181 if (tp) {
1182 if (VALID_VATTR(tp)) { /* If attrs are cached */
1183 if (tp->c_vattr.va_nlink > 1) { /* If it's a hard link */
1184 tp->c_vattr.va_nlink--;
1185 }
1186 }
1187
1188 coda_nc_zapfile(VTOC(dvp), nm, len);
1189 /* No need to flush it if it doesn't exist! */
1190 }
1191 /* Invalidate the parent's attr cache, the modification time has changed */
1192 VTOC(dvp)->c_flags &= ~C_VATTR;
1193
1194 /* Check for remove of control object. */
1195 if (IS_CTL_NAME(dvp, nm, len)) {
1196 MARK_INT_FAIL(CODA_REMOVE_STATS);
1197 return(ENOENT);
1198 }
1199
dadab5e9 1200 error = venus_remove(vtomi(dvp), &cp->c_fid, nm, len, cred, td);
984263bc
MD
1201
1202 CODADEBUG(CODA_REMOVE, myprintf(("in remove result %d\n",error)); )
1203
1204 return(error);
1205}
1206
1207int
085d998b 1208coda_link(void *v)
984263bc
MD
1209{
1210/* true args */
e62afb5f 1211 struct vop_old_link_args *ap = v;
984263bc
MD
1212 struct vnode *vp = ap->a_vp;
1213 struct cnode *cp = VTOC(vp);
1214 struct vnode *tdvp = ap->a_tdvp;
1215 struct cnode *tdcp = VTOC(tdvp);
1216 struct componentname *cnp = ap->a_cnp;
1217 struct ucred *cred = cnp->cn_cred;
dadab5e9 1218 struct thread *td = cnp->cn_td;
984263bc
MD
1219/* locals */
1220 int error;
1221 const char *nm = cnp->cn_nameptr;
1222 int len = cnp->cn_namelen;
1223
1224 MARK_ENTRY(CODA_LINK_STATS);
1225
1226 if (codadebug & CODADBGMSK(CODA_LINK)) {
1227
1228 myprintf(("nb_link: vp fid: (%lx.%lx.%lx)\n",
1229 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1230 myprintf(("nb_link: tdvp fid: (%lx.%lx.%lx)\n",
1231 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1232
1233 }
1234 if (codadebug & CODADBGMSK(CODA_LINK)) {
1235 myprintf(("link: vp fid: (%lx.%lx.%lx)\n",
1236 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1237 myprintf(("link: tdvp fid: (%lx.%lx.%lx)\n",
1238 tdcp->c_fid.Volume, tdcp->c_fid.Vnode, tdcp->c_fid.Unique));
1239
1240 }
1241
1242 /* Check for link to/from control object. */
1243 if (IS_CTL_NAME(tdvp, nm, len) || IS_CTL_VP(vp)) {
1244 MARK_INT_FAIL(CODA_LINK_STATS);
1245 return(EACCES);
1246 }
1247
dadab5e9 1248 error = venus_link(vtomi(vp), &cp->c_fid, &tdcp->c_fid, nm, len, cred, td);
984263bc
MD
1249
1250 /* Invalidate the parent's attr cache, the modification time has changed */
1251 VTOC(tdvp)->c_flags &= ~C_VATTR;
1252 VTOC(vp)->c_flags &= ~C_VATTR;
1253
1254 CODADEBUG(CODA_LINK, myprintf(("in link result %d\n",error)); )
1255
1256 return(error);
1257}
1258
1259int
085d998b 1260coda_rename(void *v)
984263bc
MD
1261{
1262/* true args */
e62afb5f 1263 struct vop_old_rename_args *ap = v;
984263bc
MD
1264 struct vnode *odvp = ap->a_fdvp;
1265 struct cnode *odcp = VTOC(odvp);
1266 struct componentname *fcnp = ap->a_fcnp;
1267 struct vnode *ndvp = ap->a_tdvp;
1268 struct cnode *ndcp = VTOC(ndvp);
1269 struct componentname *tcnp = ap->a_tcnp;
1270 struct ucred *cred = fcnp->cn_cred;
dadab5e9 1271 struct thread *td = fcnp->cn_td;
984263bc
MD
1272/* true args */
1273 int error;
1274 const char *fnm = fcnp->cn_nameptr;
1275 int flen = fcnp->cn_namelen;
1276 const char *tnm = tcnp->cn_nameptr;
1277 int tlen = tcnp->cn_namelen;
1278
1279 MARK_ENTRY(CODA_RENAME_STATS);
1280
1281 /* Hmmm. The vnodes are already looked up. Perhaps they are locked?
1282 This could be Bad. XXX */
1283#ifdef OLD_DIAGNOSTIC
dadab5e9 1284 if ((fcnp->cn_cred != tcnp->cn_cred) || (fcnp->cn_td != tcnp->cn_td))
984263bc
MD
1285 {
1286 panic("coda_rename: component names don't agree");
1287 }
1288#endif
1289
1290 /* Check for rename involving control object. */
1291 if (IS_CTL_NAME(odvp, fnm, flen) || IS_CTL_NAME(ndvp, tnm, tlen)) {
1292 MARK_INT_FAIL(CODA_RENAME_STATS);
1293 return(EACCES);
1294 }
1295
1296 /* Problem with moving directories -- need to flush entry for .. */
1297 if (odvp != ndvp) {
1298 struct cnode *ovcp = coda_nc_lookup(VTOC(odvp), fnm, flen, cred);
1299 if (ovcp) {
1300 struct vnode *ovp = CTOV(ovcp);
1301 if ((ovp) &&
1302 (ovp->v_type == VDIR)) /* If it's a directory */
1303 coda_nc_zapfile(VTOC(ovp),"..", 2);
1304 }
1305 }
1306
1307 /* Remove the entries for both source and target files */
1308 coda_nc_zapfile(VTOC(odvp), fnm, flen);
1309 coda_nc_zapfile(VTOC(ndvp), tnm, tlen);
1310
1311 /* Invalidate the parent's attr cache, the modification time has changed */
1312 VTOC(odvp)->c_flags &= ~C_VATTR;
1313 VTOC(ndvp)->c_flags &= ~C_VATTR;
1314
1315 if (flen+1 > CODA_MAXNAMLEN) {
1316 MARK_INT_FAIL(CODA_RENAME_STATS);
1317 error = EINVAL;
1318 goto exit;
1319 }
1320
1321 if (tlen+1 > CODA_MAXNAMLEN) {
1322 MARK_INT_FAIL(CODA_RENAME_STATS);
1323 error = EINVAL;
1324 goto exit;
1325 }
1326
dadab5e9 1327 error = venus_rename(vtomi(odvp), &odcp->c_fid, &ndcp->c_fid, fnm, flen, tnm, tlen, cred, td);
984263bc
MD
1328
1329 exit:
1330 CODADEBUG(CODA_RENAME, myprintf(("in rename result %d\n",error));)
984263bc
MD
1331
1332 /* It seems to be incumbent on us to drop locks on all four vnodes */
1333 /* From-vnodes are not locked, only ref'd. To-vnodes are locked. */
1334
1335 vrele(ap->a_fvp);
1336 vrele(odvp);
1337
1338 if (ap->a_tvp) {
1339 if (ap->a_tvp == ndvp) {
1340 vrele(ap->a_tvp);
1341 } else {
1342 vput(ap->a_tvp);
1343 }
1344 }
1345
1346 vput(ndvp);
1347 return(error);
1348}
1349
1350int
085d998b 1351coda_mkdir(void *v)
984263bc
MD
1352{
1353/* true args */
e62afb5f 1354 struct vop_old_mkdir_args *ap = v;
984263bc
MD
1355 struct vnode *dvp = ap->a_dvp;
1356 struct cnode *dcp = VTOC(dvp);
1357 struct componentname *cnp = ap->a_cnp;
31a0fcd9 1358 struct vattr *va = ap->a_vap;
984263bc
MD
1359 struct vnode **vpp = ap->a_vpp;
1360 struct ucred *cred = cnp->cn_cred;
dadab5e9 1361 struct thread *td = cnp->cn_td;
984263bc
MD
1362/* locals */
1363 int error;
1364 const char *nm = cnp->cn_nameptr;
1365 int len = cnp->cn_namelen;
1366 struct cnode *cp;
1367 ViceFid VFid;
1368 struct vattr ova;
1369
1370 MARK_ENTRY(CODA_MKDIR_STATS);
1371
1372 /* Check for mkdir of target object. */
1373 if (IS_CTL_NAME(dvp, nm, len)) {
1374 *vpp = (struct vnode *)0;
1375 MARK_INT_FAIL(CODA_MKDIR_STATS);
1376 return(EACCES);
1377 }
1378
1379 if (len+1 > CODA_MAXNAMLEN) {
1380 *vpp = (struct vnode *)0;
1381 MARK_INT_FAIL(CODA_MKDIR_STATS);
1382 return(EACCES);
1383 }
1384
dadab5e9 1385 error = venus_mkdir(vtomi(dvp), &dcp->c_fid, nm, len, va, cred, td, &VFid, &ova);
984263bc
MD
1386
1387 if (!error) {
1388 if (coda_find(&VFid) != NULL)
1389 panic("cnode existed for newly created directory!");
1390
1391
1392 cp = make_coda_node(&VFid, dvp->v_mount, va->va_type);
1393 *vpp = CTOV(cp);
1394
1395 /* enter the new vnode in the Name Cache */
1396 coda_nc_enter(VTOC(dvp), nm, len, cred, VTOC(*vpp));
1397
1398 /* as a side effect, enter "." and ".." for the directory */
1399 coda_nc_enter(VTOC(*vpp), ".", 1, cred, VTOC(*vpp));
1400 coda_nc_enter(VTOC(*vpp), "..", 2, cred, VTOC(dvp));
1401
1402 if (coda_attr_cache) {
1403 VTOC(*vpp)->c_vattr = ova; /* update the attr cache */
1404 VTOC(*vpp)->c_flags |= C_VATTR; /* Valid attributes in cnode */
1405 }
1406
1407 /* Invalidate the parent's attr cache, the modification time has changed */
1408 VTOC(dvp)->c_flags &= ~C_VATTR;
1409
1410 CODADEBUG( CODA_MKDIR, myprintf(("mkdir: (%lx.%lx.%lx) result %d\n",
1411 VFid.Volume, VFid.Vnode, VFid.Unique, error)); )
1412 } else {
1413 *vpp = (struct vnode *)0;
1414 CODADEBUG(CODA_MKDIR, myprintf(("mkdir error %d\n",error));)
1415 }
1416
1417 return(error);
1418}
1419
1420int
085d998b 1421coda_rmdir(void *v)
984263bc
MD
1422{
1423/* true args */
e62afb5f 1424 struct vop_old_rmdir_args *ap = v;
984263bc
MD
1425 struct vnode *dvp = ap->a_dvp;
1426 struct cnode *dcp = VTOC(dvp);
1427 struct componentname *cnp = ap->a_cnp;
1428 struct ucred *cred = cnp->cn_cred;
dadab5e9 1429 struct thread *td = cnp->cn_td;
984263bc
MD
1430/* true args */
1431 int error;
1432 const char *nm = cnp->cn_nameptr;
1433 int len = cnp->cn_namelen;
1434 struct cnode *cp;
1435
1436 MARK_ENTRY(CODA_RMDIR_STATS);
1437
1438 /* Check for rmdir of control object. */
1439 if (IS_CTL_NAME(dvp, nm, len)) {
1440 MARK_INT_FAIL(CODA_RMDIR_STATS);
1441 return(ENOENT);
1442 }
1443
1444 /* We're being conservative here, it might be that this person
1445 * doesn't really have sufficient access to delete the file
1446 * but we feel zapping the entry won't really hurt anyone -- dcs
1447 */
1448 /*
1449 * As a side effect of the rmdir, remove any entries for children of
1450 * the directory, especially "." and "..".
1451 */
1452 cp = coda_nc_lookup(dcp, nm, len, cred);
1453 if (cp) coda_nc_zapParentfid(&(cp->c_fid), NOT_DOWNCALL);
1454
1455 /* Remove the file's entry from the CODA Name Cache */
1456 coda_nc_zapfile(dcp, nm, len);
1457
1458 /* Invalidate the parent's attr cache, the modification time has changed */
1459 dcp->c_flags &= ~C_VATTR;
1460
dadab5e9 1461 error = venus_rmdir(vtomi(dvp), &dcp->c_fid, nm, len, cred, td);
984263bc
MD
1462
1463 CODADEBUG(CODA_RMDIR, myprintf(("in rmdir result %d\n", error)); )
1464
1465 return(error);
1466}
1467
1468int
085d998b 1469coda_symlink(void *v)
984263bc
MD
1470{
1471/* true args */
e62afb5f 1472 struct vop_old_symlink_args *ap = v;
984263bc
MD
1473 struct vnode *tdvp = ap->a_dvp;
1474 struct cnode *tdcp = VTOC(tdvp);
1475 struct componentname *cnp = ap->a_cnp;
1476 struct vattr *tva = ap->a_vap;
1477 char *path = ap->a_target;
1478 struct ucred *cred = cnp->cn_cred;
dadab5e9 1479 struct thread *td = cnp->cn_td;
984263bc
MD
1480 struct vnode **vpp = ap->a_vpp;
1481/* locals */
1482 int error;
1483 /*
1484 * XXX I'm assuming the following things about coda_symlink's
1485 * arguments:
1486 * t(foo) is the new name/parent/etc being created.
1487 * lname is the contents of the new symlink.
1488 */
1489 char *nm = cnp->cn_nameptr;
1490 int len = cnp->cn_namelen;
1491 int plen = strlen(path);
1492
1493 /*
1494 * Here's the strategy for the moment: perform the symlink, then
1495 * do a lookup to grab the resulting vnode. I know this requires
1496 * two communications with Venus for a new sybolic link, but
1497 * that's the way the ball bounces. I don't yet want to change
1498 * the way the Mach symlink works. When Mach support is
1499 * deprecated, we should change symlink so that the common case
1500 * returns the resultant vnode in a vpp argument.
1501 */
1502
1503 MARK_ENTRY(CODA_SYMLINK_STATS);
1504
1505 /* Check for symlink of control object. */
1506 if (IS_CTL_NAME(tdvp, nm, len)) {
1507 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1508 return(EACCES);
1509 }
1510
1511 if (plen+1 > CODA_MAXPATHLEN) {
1512 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1513 return(EINVAL);
1514 }
1515
1516 if (len+1 > CODA_MAXNAMLEN) {
1517 MARK_INT_FAIL(CODA_SYMLINK_STATS);
1518 error = EINVAL;
1519 goto exit;
1520 }
1521
dadab5e9 1522 error = venus_symlink(vtomi(tdvp), &tdcp->c_fid, path, plen, nm, len, tva, cred, td);
984263bc
MD
1523
1524 /* Invalidate the parent's attr cache, the modification time has changed */
1525 tdcp->c_flags &= ~C_VATTR;
1526
1527 if (error == 0)
e62afb5f 1528 error = VOP_OLD_LOOKUP(tdvp, vpp, cnp);
984263bc
MD
1529
1530 exit:
1531 CODADEBUG(CODA_SYMLINK, myprintf(("in symlink result %d\n",error)); )
1532 return(error);
1533}
1534
1535/*
1536 * Read directory entries.
1537 */
1538int
085d998b 1539coda_readdir(void *v)
984263bc
MD
1540{
1541/* true args */
1542 struct vop_readdir_args *ap = v;
1543 struct vnode *vp = ap->a_vp;
1544 struct cnode *cp = VTOC(vp);
31a0fcd9 1545 struct uio *uiop = ap->a_uio;
984263bc
MD
1546 struct ucred *cred = ap->a_cred;
1547 int *eofflag = ap->a_eofflag;
1548 u_long **cookies = ap->a_cookies;
1549 int *ncookies = ap->a_ncookies;
dadab5e9 1550 struct thread *td = ap->a_uio->uio_td;
984263bc
MD
1551/* upcall decl */
1552/* locals */
1553 int error = 0;
1554
1555 MARK_ENTRY(CODA_READDIR_STATS);
1556
1557 CODADEBUG(CODA_READDIR, myprintf(("coda_readdir(%p, %d, %lld, %d)\n",
1558 (void *)uiop->uio_iov->iov_base,
1559 uiop->uio_resid,
1560 (long long)uiop->uio_offset,
1561 uiop->uio_segflg)); )
1562
1563 /* Check for readdir of control object. */
1564 if (IS_CTL_VP(vp)) {
1565 MARK_INT_FAIL(CODA_READDIR_STATS);
1566 return(ENOENT);
1567 }
1568
1569 {
1570 /* If directory is not already open do an "internal open" on it. */
1571 int opened_internally = 0;
1572 if (cp->c_ovp == NULL) {
1573 opened_internally = 1;
1574 MARK_INT_GEN(CODA_OPEN_STATS);
fad57d0e 1575 error = VOP_OPEN(vp, FREAD, cred, NULL, td);
984263bc
MD
1576printf("coda_readdir: Internally Opening %p\n", vp);
1577 if (error) {
1578 printf("coda_readdir: VOP_OPEN on container failed %d\n", error);
1579 return (error);
1580 }
1581 if (vp->v_type == VREG) {
3b568787 1582 error = vfs_object_create(vp, td);
984263bc
MD
1583 if (error != 0) {
1584 printf("coda_readdir: vfs_object_create() returns %d\n", error);
1585 vput(vp);
1586 }
1587 }
1588 if (error) return(error);
1589 }
1590
1591 /* Have UFS handle the call. */
1592 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)); )
1593 error = VOP_READDIR(cp->c_ovp, uiop, cred, eofflag, ncookies,
1594 cookies);
1595
1596 if (error)
1597 MARK_INT_FAIL(CODA_READDIR_STATS);
1598 else
1599 MARK_INT_SAT(CODA_READDIR_STATS);
1600
1601 /* Do an "internal close" if necessary. */
1602 if (opened_internally) {
1603 MARK_INT_GEN(CODA_CLOSE_STATS);
3b568787 1604 (void)VOP_CLOSE(vp, FREAD, td);
984263bc
MD
1605 }
1606 }
1607
1608 return(error);
1609}
1610
1611/*
1612 * Convert from file system blocks to device blocks
1613 */
1614int
085d998b 1615coda_bmap(void *v)
984263bc
MD
1616{
1617 /* XXX on the global proc */
1618/* true args */
1619 struct vop_bmap_args *ap = v;
1620 struct vnode *vp __attribute__((unused)) = ap->a_vp; /* file's vnode */
1621 daddr_t bn __attribute__((unused)) = ap->a_bn; /* fs block number */
1622 struct vnode **vpp = ap->a_vpp; /* RETURN vp of device */
1623 daddr_t *bnp __attribute__((unused)) = ap->a_bnp; /* RETURN device block number */
984263bc
MD
1624/* upcall decl */
1625/* locals */
1626
1627 int ret = 0;
1628 struct cnode *cp;
1629
1630 cp = VTOC(vp);
1631 if (cp->c_ovp) {
1632 return EINVAL;
1633 ret = VOP_BMAP(cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb);
1634#if 0
1635 printf("VOP_BMAP(cp->c_ovp %p, bn %p, vpp %p, bnp %p, ap->a_runp %p, ap->a_runb %p) = %d\n",
1636 cp->c_ovp, bn, vpp, bnp, ap->a_runp, ap->a_runb, ret);
1637#endif
1638 return ret;
1639 } else {
1640#if 0
1641 printf("coda_bmap: no container\n");
1642#endif
1643 return(EOPNOTSUPP);
1644 }
1645}
1646
1647/*
1648 * I don't think the following two things are used anywhere, so I've
1649 * commented them out
1650 *
1651 * struct buf *async_bufhead;
1652 * int async_daemon_count;
1653 */
1654int
085d998b 1655coda_strategy(void *v)
984263bc
MD
1656{
1657/* true args */
1658 struct vop_strategy_args *ap = v;
31a0fcd9 1659 struct buf *bp __attribute__((unused)) = ap->a_bp;
984263bc
MD
1660/* upcall decl */
1661/* locals */
1662
1663 printf("coda_strategy: called ???\n");
1664 return(EOPNOTSUPP);
1665}
1666
1667int
085d998b 1668coda_reclaim(void *v)
984263bc
MD
1669{
1670/* true args */
1671 struct vop_reclaim_args *ap = v;
1672 struct vnode *vp = ap->a_vp;
1673 struct cnode *cp = VTOC(vp);
1674/* upcall decl */
1675/* locals */
1676
1677/*
1678 * Forced unmount/flush will let vnodes with non zero use be destroyed!
1679 */
1680 ENTRY;
1681
1682 if (IS_UNMOUNTING(cp)) {
1683#ifdef DEBUG
1684 if (VTOC(vp)->c_ovp) {
1685 if (IS_UNMOUNTING(cp))
1686 printf("coda_reclaim: c_ovp not void: vp %p, cp %p\n", vp, cp);
1687 }
1688#endif
1689 } else {
1690#ifdef OLD_DIAGNOSTIC
1691 if (vp->v_usecount != 0)
1692 print("coda_reclaim: pushing active %p\n", vp);
1693 if (VTOC(vp)->c_ovp) {
1694 panic("coda_reclaim: c_ovp not void");
1695 }
1696#endif
1697 }
984263bc 1698 coda_free(VTOC(vp));
c5e74646 1699 vp->v_data = NULL;
984263bc
MD
1700 return (0);
1701}
1702
1703int
085d998b 1704coda_lock(void *v)
984263bc
MD
1705{
1706/* true args */
1707 struct vop_lock_args *ap = v;
1708 struct vnode *vp = ap->a_vp;
1709 struct cnode *cp = VTOC(vp);
dadab5e9 1710 struct thread *td = ap->a_td;
984263bc
MD
1711/* upcall decl */
1712/* locals */
1713
1714 ENTRY;
1715
1716 if (coda_lockdebug) {
1717 myprintf(("Attempting lock on %lx.%lx.%lx\n",
1718 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1719 }
1720
1721#ifndef DEBUG_LOCKS
5fd012e0 1722 return (lockmgr(&vp->v_lock, ap->a_flags, NULL, td));
984263bc 1723#else
5fd012e0 1724 return (debuglockmgr(&vp->v_lock, ap->a_flags, NULL, td,
984263bc
MD
1725 "coda_lock", vp->filename, vp->line));
1726#endif
1727}
1728
1729int
085d998b 1730coda_unlock(void *v)
984263bc
MD
1731{
1732/* true args */
1733 struct vop_unlock_args *ap = v;
1734 struct vnode *vp = ap->a_vp;
1735 struct cnode *cp = VTOC(vp);
dadab5e9 1736 struct thread *td = ap->a_td;
984263bc
MD
1737/* upcall decl */
1738/* locals */
1739
1740 ENTRY;
1741 if (coda_lockdebug) {
1742 myprintf(("Attempting unlock on %lx.%lx.%lx\n",
1743 cp->c_fid.Volume, cp->c_fid.Vnode, cp->c_fid.Unique));
1744 }
1745
5fd012e0 1746 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, NULL, td));
984263bc
MD
1747}
1748
1749int
085d998b 1750coda_islocked(void *v)
984263bc
MD
1751{
1752/* true args */
1753 struct vop_islocked_args *ap = v;
984263bc
MD
1754 ENTRY;
1755
3446c007 1756 return (lockstatus(&ap->a_vp->v_lock, ap->a_td));
984263bc
MD
1757}
1758
1759/* How one looks up a vnode given a device/inode pair: */
1760int
1761coda_grab_vnode(dev_t dev, ino_t ino, struct vnode **vpp)
1762{
1763 /* This is like VFS_VGET() or igetinode()! */
1764 int error;
1765 struct mount *mp;
1766
1767 if (!(mp = devtomp(dev))) {
1768 myprintf(("coda_grab_vnode: devtomp(%#lx) returns NULL\n",
1769 (u_long)dev2udev(dev)));
1770 return(ENXIO);
1771 }
1772
1773 /* XXX - ensure that nonzero-return means failure */
1774 error = VFS_VGET(mp,ino,vpp);
1775 if (error) {
1776 myprintf(("coda_grab_vnode: iget/vget(%lx, %lu) returns %p, err %d\n",
1777 (u_long)dev2udev(dev), (u_long)ino, (void *)*vpp, error));
1778 return(ENOENT);
1779 }
1780 return(0);
1781}
1782
1783void
085d998b 1784print_vattr(struct vattr *attr)
984263bc
MD
1785{
1786 char *typestr;
1787
1788 switch (attr->va_type) {
1789 case VNON:
1790 typestr = "VNON";
1791 break;
1792 case VREG:
1793 typestr = "VREG";
1794 break;
1795 case VDIR:
1796 typestr = "VDIR";
1797 break;
1798 case VBLK:
1799 typestr = "VBLK";
1800 break;
1801 case VCHR:
1802 typestr = "VCHR";
1803 break;
1804 case VLNK:
1805 typestr = "VLNK";
1806 break;
1807 case VSOCK:
1808 typestr = "VSCK";
1809 break;
1810 case VFIFO:
1811 typestr = "VFFO";
1812 break;
1813 case VBAD:
1814 typestr = "VBAD";
1815 break;
1816 default:
1817 typestr = "????";
1818 break;
1819 }
1820
1821
1822 myprintf(("attr: type %s mode %d uid %d gid %d fsid %d rdev %d\n",
1823 typestr, (int)attr->va_mode, (int)attr->va_uid,
1824 (int)attr->va_gid, (int)attr->va_fsid, (int)attr->va_rdev));
1825
1826 myprintf((" fileid %d nlink %d size %d blocksize %d bytes %d\n",
1827 (int)attr->va_fileid, (int)attr->va_nlink,
1828 (int)attr->va_size,
1829 (int)attr->va_blocksize,(int)attr->va_bytes));
1830 myprintf((" gen %ld flags %ld vaflags %d\n",
1831 attr->va_gen, attr->va_flags, attr->va_vaflags));
1832 myprintf((" atime sec %d nsec %d\n",
1833 (int)attr->va_atime.tv_sec, (int)attr->va_atime.tv_nsec));
1834 myprintf((" mtime sec %d nsec %d\n",
1835 (int)attr->va_mtime.tv_sec, (int)attr->va_mtime.tv_nsec));
1836 myprintf((" ctime sec %d nsec %d\n",
1837 (int)attr->va_ctime.tv_sec, (int)attr->va_ctime.tv_nsec));
1838}
1839
1840/* How to print a ucred */
1841void
085d998b 1842print_cred(struct ucred *cred)
984263bc
MD
1843{
1844
1845 int i;
1846
1847 myprintf(("ref %d\tuid %d\n",cred->cr_ref,cred->cr_uid));
1848
1849 for (i=0; i < cred->cr_ngroups; i++)
1850 myprintf(("\tgroup %d: (%d)\n",i,cred->cr_groups[i]));
1851 myprintf(("\n"));
1852
1853}
1854
1855/*
1856 * Return a vnode for the given fid.
1857 * If no cnode exists for this fid create one and put it
1858 * in a table hashed by fid.Volume and fid.Vnode. If the cnode for
1859 * this fid is already in the table return it (ref count is
1860 * incremented by coda_find. The cnode will be flushed from the
1861 * table when coda_inactive calls coda_unsave.
1862 */
1863struct cnode *
085d998b 1864make_coda_node(ViceFid *fid, struct mount *vfsp, short type)
984263bc
MD
1865{
1866 struct cnode *cp;
1867 int err;
1868
1869 if ((cp = coda_find(fid)) == NULL) {
1870 struct vnode *vp;
1871
1872 cp = coda_alloc();
984263bc
MD
1873 cp->c_fid = *fid;
1874
6ddb7618 1875 err = getnewvnode(VT_CODA, vfsp, &vp, 0, 0);
984263bc
MD
1876 if (err) {
1877 panic("coda: getnewvnode returned error %d\n", err);
1878 }
1879 vp->v_data = cp;
1880 vp->v_type = type;
1881 cp->c_vnode = vp;
1882 coda_save(cp);
5fd012e0 1883 vx_unlock(vp);
984263bc
MD
1884 } else {
1885 vref(CTOV(cp));
1886 }
1887
1888 return cp;
1889}