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