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