2 * A large chunk of this file appears to be copied directly from
3 * sys/nfsclient/nfs_bio.c, which has the following license:
6 * Copyright (c) 1989, 1993
7 * The Regents of the University of California. All rights reserved.
9 * This code is derived from software contributed to Berkeley by
10 * Rick Macklem at The University of Guelph.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * @(#)nfs_bio.c 8.9 (Berkeley) 3/30/95
43 * Pursuant to a statement of U.C. Berkeley dated 1999-07-22, this license
44 * is amended to drop clause (3) above.
47 #include <afsconfig.h>
48 #include <afs/param.h>
53 #include <afs/sysincludes.h> /* Standard vendor system headers */
54 #include <afsincludes.h> /* Afs-based standard headers */
55 #include <afs/afs_stats.h> /* statistics */
56 #include <sys/malloc.h>
57 #include <sys/namei.h>
58 #include <sys/unistd.h>
59 #ifndef AFS_FBSD50_ENV
60 #include <vm/vm_zone.h>
62 #include <vm/vm_page.h>
63 #include <vm/vm_object.h>
64 #include <vm/vm_pager.h>
65 #include <vm/vnode_pager.h>
66 extern int afs_pbuf_freecnt;
68 int afs_vop_lookup(struct vop_lookup_args *);
69 int afs_vop_create(struct vop_create_args *);
70 int afs_vop_mknod(struct vop_mknod_args *);
71 int afs_vop_open(struct vop_open_args *);
72 int afs_vop_close(struct vop_close_args *);
73 int afs_vop_access(struct vop_access_args *);
74 int afs_vop_getattr(struct vop_getattr_args *);
75 int afs_vop_setattr(struct vop_setattr_args *);
76 int afs_vop_read(struct vop_read_args *);
77 int afs_vop_write(struct vop_write_args *);
78 int afs_vop_getpages(struct vop_getpages_args *);
79 int afs_vop_putpages(struct vop_putpages_args *);
80 int afs_vop_ioctl(struct vop_ioctl_args *);
81 static int afs_vop_pathconf(struct vop_pathconf_args *);
82 int afs_vop_poll(struct vop_poll_args *);
83 #ifndef AFS_FBSD50_ENV
84 int afs_vop_mmap(struct vop_mmap_args *);
86 int afs_vop_fsync(struct vop_fsync_args *);
87 int afs_vop_remove(struct vop_remove_args *);
88 int afs_vop_link(struct vop_link_args *);
89 int afs_vop_rename(struct vop_rename_args *);
90 int afs_vop_mkdir(struct vop_mkdir_args *);
91 int afs_vop_rmdir(struct vop_rmdir_args *);
92 int afs_vop_symlink(struct vop_symlink_args *);
93 int afs_vop_readdir(struct vop_readdir_args *);
94 int afs_vop_readlink(struct vop_readlink_args *);
95 int afs_vop_inactive(struct vop_inactive_args *);
96 int afs_vop_reclaim(struct vop_reclaim_args *);
97 int afs_vop_lock(struct vop_lock_args *);
98 int afs_vop_unlock(struct vop_unlock_args *);
99 int afs_vop_bmap(struct vop_bmap_args *);
100 int afs_vop_strategy(struct vop_strategy_args *);
101 int afs_vop_print(struct vop_print_args *);
102 int afs_vop_islocked(struct vop_islocked_args *);
103 int afs_vop_advlock(struct vop_advlock_args *);
107 /* Global vfs data structures for AFS. */
108 vop_t **afs_vnodeop_p;
109 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
110 {&vop_default_desc, (vop_t *) vop_defaultop},
111 {&vop_access_desc, (vop_t *) afs_vop_access}, /* access */
112 {&vop_advlock_desc, (vop_t *) afs_vop_advlock}, /* advlock */
113 {&vop_bmap_desc, (vop_t *) afs_vop_bmap}, /* bmap */
114 #ifndef AFS_FBSD50_ENV
115 {&vop_bwrite_desc, (vop_t *) vop_stdbwrite},
117 {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */
118 {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject},
119 {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject},
120 {&vop_create_desc, (vop_t *) afs_vop_create}, /* create */
121 {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */
122 {&vop_getattr_desc, (vop_t *) afs_vop_getattr}, /* getattr */
123 {&vop_getpages_desc, (vop_t *) afs_vop_getpages}, /* read */
124 {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject},
125 {&vop_putpages_desc, (vop_t *) afs_vop_putpages}, /* write */
126 {&vop_inactive_desc, (vop_t *) afs_vop_inactive}, /* inactive */
127 {&vop_lease_desc, (vop_t *) vop_null},
128 {&vop_link_desc, (vop_t *) afs_vop_link}, /* link */
129 {&vop_lookup_desc, (vop_t *) afs_vop_lookup}, /* lookup */
130 {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */
131 {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */
132 #ifndef AFS_FBSD50_ENV
133 {&vop_mmap_desc, (vop_t *) afs_vop_mmap}, /* mmap */
135 {&vop_open_desc, (vop_t *) afs_vop_open}, /* open */
136 {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf}, /* pathconf */
137 {&vop_poll_desc, (vop_t *) afs_vop_poll}, /* select */
138 {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */
139 {&vop_read_desc, (vop_t *) afs_vop_read}, /* read */
140 {&vop_readdir_desc, (vop_t *) afs_vop_readdir}, /* readdir */
141 {&vop_readlink_desc, (vop_t *) afs_vop_readlink}, /* readlink */
142 {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim}, /* reclaim */
143 {&vop_remove_desc, (vop_t *) afs_vop_remove}, /* remove */
144 {&vop_rename_desc, (vop_t *) afs_vop_rename}, /* rename */
145 {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */
146 {&vop_setattr_desc, (vop_t *) afs_vop_setattr}, /* setattr */
147 {&vop_strategy_desc, (vop_t *) afs_vop_strategy}, /* strategy */
148 {&vop_symlink_desc, (vop_t *) afs_vop_symlink}, /* symlink */
149 {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */
150 {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */
151 /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */
154 struct vnodeopv_desc afs_vnodeop_opv_desc =
155 { &afs_vnodeop_p, afs_vnodeop_entries };
158 struct componentname *cnp = ap->a_cnp; \
160 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
161 memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
162 name[cnp->cn_namelen] = '\0'
164 #define DROPNAME() FREE(name, M_TEMP)
166 /* This is a bit of a cheat... */
167 #ifdef AFS_FBSD50_ENV
172 * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf().
173 * We should know the correct answers to these questions with
174 * respect to the AFS protocol (which may differ from the UFS
175 * values) but for the moment this will do.
178 afs_vop_pathconf(struct vop_pathconf_args *ap)
183 switch (ap->a_name) {
185 *ap->a_retval = LINK_MAX;
188 *ap->a_retval = NAME_MAX;
191 *ap->a_retval = PATH_MAX;
194 *ap->a_retval = PIPE_BUF;
196 case _PC_CHOWN_RESTRICTED:
202 #ifdef _PC_ACL_EXTENDED
203 case _PC_ACL_EXTENDED:
206 case _PC_ACL_PATH_MAX:
210 #ifdef _PC_MAC_PRESENT
211 case _PC_MAC_PRESENT:
217 /* _PC_ASYNC_IO should have been handled by upper layers. */
218 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
228 #ifdef _PC_ALLOC_SIZE_MIN
229 case _PC_ALLOC_SIZE_MIN:
230 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
233 #ifdef _PC_FILESIZEBITS
234 case _PC_FILESIZEBITS:
235 *ap->a_retval = 32; /* XXX */
238 #ifdef _PC_REC_INCR_XFER_SIZE
239 case _PC_REC_INCR_XFER_SIZE:
240 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
242 case _PC_REC_MAX_XFER_SIZE:
243 *ap->a_retval = -1; /* means ``unlimited'' */
245 case _PC_REC_MIN_XFER_SIZE:
246 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
248 case _PC_REC_XFER_ALIGN:
249 *ap->a_retval = PAGE_SIZE;
252 #ifdef _PC_SYMLINK_MAX
253 case _PC_SYMLINK_MAX:
254 *ap->a_retval = MAXPATHLEN;
266 struct vop_lookup_args /* {
267 * struct vnodeop_desc * a_desc;
268 * struct vnode *a_dvp;
269 * struct vnode **a_vpp;
270 * struct componentname *a_cnp;
275 struct vnode *vp, *dvp;
276 register int flags = ap->a_cnp->cn_flags;
277 int lockparent; /* 1 => lockparent flag is set */
278 int wantparent; /* 1 => wantparent or lockparent flag */
279 #ifdef AFS_FBSD50_ENV
280 struct thread *p = ap->a_cnp->cn_thread;
282 struct proc *p = ap->a_cnp->cn_proc;
286 lockparent = flags & LOCKPARENT;
287 wantparent = flags & (LOCKPARENT | WANTPARENT);
289 if (ap->a_dvp->v_type != VDIR) {
295 if (flags & ISDOTDOT)
296 VOP_UNLOCK(dvp, 0, p);
298 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
301 if (flags & ISDOTDOT)
302 VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
303 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
304 && (flags & ISLASTCN) && error == ENOENT)
306 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
307 cnp->cn_flags |= SAVENAME;
312 vp = AFSTOV(vcp); /* always get a node if no error */
314 /* The parent directory comes in locked. We unlock it on return
315 * unless the caller wants it left locked.
316 * we also always return the vnode locked. */
318 if (flags & ISDOTDOT) {
319 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
320 /* always return the child locked */
321 if (lockparent && (flags & ISLASTCN)
322 && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
327 } else if (vp == dvp) {
328 /* they're the same; afs_lookup() already ref'ed the leaf.
329 * It came in locked, so we don't need to ref OR lock it */
331 if (!lockparent || !(flags & ISLASTCN))
332 VOP_UNLOCK(dvp, 0, p); /* done with parent. */
333 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
334 /* always return the child locked */
338 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
339 || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
340 cnp->cn_flags |= SAVENAME;
348 struct vop_create_args /* {
349 * struct vnode *a_dvp;
350 * struct vnode **a_vpp;
351 * struct componentname *a_cnp;
352 * struct vattr *a_vap;
357 register struct vnode *dvp = ap->a_dvp;
358 #ifdef AFS_FBSD50_ENV
359 struct thread *p = ap->a_cnp->cn_thread;
361 struct proc *p = ap->a_cnp->cn_proc;
367 afs_create(VTOAFS(dvp), name, ap->a_vap,
368 ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL,
369 ap->a_vap->va_mode, &vcp, cnp->cn_cred);
377 *ap->a_vpp = AFSTOV(vcp);
378 vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
388 struct vop_mknod_args /* {
389 * struct vnode *a_dvp;
390 * struct vnode **a_vpp;
391 * struct componentname *a_cnp;
392 * struct vattr *a_vap;
400 validate_vops(struct vnode *vp, int after)
403 struct vnodeopv_entry_desc *this;
404 for (this = afs_vnodeop_entries; this->opve_op; this++) {
405 if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) {
407 printf("v_op %d ", after);
411 printf("For oper %d (%s), func is %p, not %p",
412 this->opve_op->vdesc_offset, this->opve_op->vdesc_name,
413 vp->v_op[this->opve_op->vdesc_offset], this->opve_impl);
421 struct vop_open_args /* {
422 * struct vnode *a_vp;
424 * struct ucred *a_cred;
430 struct vcache *vc = VTOAFS(ap->a_vp);
433 error = afs_open(&vc, ap->a_mode, ap->a_cred);
435 if (AFSTOV(vc) != ap->a_vp)
436 panic("AFS open changed vnode!");
438 afs_BozonLock(&vc->pvnLock, vc);
439 osi_FlushPages(vc, ap->a_cred);
440 afs_BozonUnlock(&vc->pvnLock, vc);
447 struct vop_close_args /* {
448 * struct vnode *a_vp;
450 * struct ucred *a_cred;
455 struct vcache *avc = VTOAFS(ap->a_vp);
458 code = afs_close(avc, ap->a_fflag, ap->a_cred);
460 code = afs_close(avc, ap->a_fflag, afs_osi_credp);
461 afs_BozonLock(&avc->pvnLock, avc);
462 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
463 afs_BozonUnlock(&avc->pvnLock, avc);
470 struct vop_access_args /* {
471 * struct vnode *a_vp;
473 * struct ucred *a_cred;
479 code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
486 struct vop_getattr_args /* {
487 * struct vnode *a_vp;
488 * struct vattr *a_vap;
489 * struct ucred *a_cred;
495 code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
502 struct vop_setattr_args /* {
503 * struct vnode *a_vp;
504 * struct vattr *a_vap;
505 * struct ucred *a_cred;
511 code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
518 struct vop_read_args /* {
519 * struct vnode *a_vp;
522 * struct ucred *a_cred;
527 struct vcache *avc = VTOAFS(ap->a_vp);
529 afs_BozonLock(&avc->pvnLock, avc);
530 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
531 code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
532 afs_BozonUnlock(&avc->pvnLock, avc);
537 /* struct vop_getpages_args {
538 * struct vnode *a_vp;
542 * vm_oofset_t a_offset;
546 afs_vop_getpages(struct vop_getpages_args *ap)
549 int i, nextoff, size, toff, npages;
558 #ifdef AFS_FBSD50_ENV
563 if ((object = vp->v_object) == NULL) {
564 printf("afs_getpages: called with non-merged cache vnode??\n");
565 return VM_PAGER_ERROR;
567 npages = btoc(ap->a_count);
569 * If the requested page is partially valid, just return it and
570 * allow the pager to zero-out the blanks. Partially valid pages
571 * can only occur at the file EOF.
575 vm_page_t m = ap->a_m[ap->a_reqpage];
577 #ifdef AFS_FBSD50_ENV
578 VM_OBJECT_LOCK(object);
579 vm_page_lock_queues();
582 /* handled by vm_fault now */
583 /* vm_page_zero_invalid(m, TRUE); */
584 for (i = 0; i < npages; ++i) {
585 if (i != ap->a_reqpage)
586 vm_page_free(ap->a_m[i]);
588 #ifdef AFS_FBSD50_ENV
589 vm_page_unlock_queues();
590 VM_OBJECT_UNLOCK(object);
594 #ifdef AFS_FBSD50_ENV
595 vm_page_unlock_queues();
596 VM_OBJECT_UNLOCK(object);
599 bp = getpbuf(&afs_pbuf_freecnt);
601 kva = (vm_offset_t) bp->b_data;
602 pmap_qenter(kva, ap->a_m, npages);
603 #ifdef AFS_FBSD50_ENV
605 cnt.v_vnodepgsin += npages;
608 iov.iov_base = (caddr_t) kva;
609 iov.iov_len = ap->a_count;
612 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
613 uio.uio_resid = ap->a_count;
614 uio.uio_segflg = UIO_SYSSPACE;
615 uio.uio_rw = UIO_READ;
616 #ifdef AFS_FBSD50_ENV
617 uio.uio_td = curthread;
619 uio.uio_procp = curproc;
623 afs_BozonLock(&avc->pvnLock, avc);
624 osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
625 code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
626 afs_BozonUnlock(&avc->pvnLock, avc);
628 pmap_qremove(kva, npages);
630 relpbuf(bp, &afs_pbuf_freecnt);
632 if (code && (uio.uio_resid == ap->a_count)) {
633 #ifdef AFS_FBSD50_ENV
634 VM_OBJECT_LOCK(object);
635 vm_page_lock_queues();
637 for (i = 0; i < npages; ++i) {
638 if (i != ap->a_reqpage)
639 vm_page_free(ap->a_m[i]);
641 #ifdef AFS_FBSD50_ENV
642 vm_page_unlock_queues();
643 VM_OBJECT_UNLOCK(object);
645 return VM_PAGER_ERROR;
648 size = ap->a_count - uio.uio_resid;
649 #ifdef AFS_FBSD50_ENV
650 VM_OBJECT_LOCK(object);
651 vm_page_lock_queues();
653 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
655 nextoff = toff + PAGE_SIZE;
658 m->flags &= ~PG_ZERO;
660 if (nextoff <= size) {
662 * Read operation filled an entire page
664 m->valid = VM_PAGE_BITS_ALL;
666 } else if (size > toff) {
668 * Read operation filled a partial page.
671 vm_page_set_validclean(m, 0, size - toff);
672 /* handled by vm_fault now */
673 /* vm_page_zero_invalid(m, TRUE); */
676 if (i != ap->a_reqpage) {
678 * Whether or not to leave the page activated is up in
679 * the air, but we should put the page on a page queue
680 * somewhere (it already is in the object). Result:
681 * It appears that emperical results show that
682 * deactivating pages is best.
686 * Just in case someone was asking for this page we
687 * now tell them that it is ok to use.
690 if (m->flags & PG_WANTED)
693 vm_page_deactivate(m);
700 #ifdef AFS_FBSD50_ENV
701 vm_page_unlock_queues();
702 VM_OBJECT_UNLOCK(object);
709 struct vop_write_args /* {
710 * struct vnode *a_vp;
713 * struct ucred *a_cred;
717 struct vcache *avc = VTOAFS(ap->a_vp);
719 afs_BozonLock(&avc->pvnLock, avc);
720 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
722 afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
723 afs_BozonUnlock(&avc->pvnLock, avc);
729 * struct vop_putpages_args {
730 * struct vnode *a_vp;
735 * vm_oofset_t a_offset;
739 * All of the pages passed to us in ap->a_m[] are already marked as busy,
740 * so there is no additional locking required to set their flags. -GAW
743 afs_vop_putpages(struct vop_putpages_args *ap)
746 int i, size, npages, sync;
754 #ifdef AFS_FBSD50_ENV
760 /* Perhaps these two checks should just be KASSERTs instead... */
761 if (vp->v_object == NULL) {
762 printf("afs_putpages: called with non-merged cache vnode??\n");
763 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
765 if (vType(avc) != VREG) {
766 printf("afs_putpages: not VREG");
767 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
769 npages = btoc(ap->a_count);
770 for (i = 0; i < npages; i++)
771 ap->a_rtvals[i] = VM_PAGER_AGAIN;
772 bp = getpbuf(&afs_pbuf_freecnt);
774 kva = (vm_offset_t) bp->b_data;
775 pmap_qenter(kva, ap->a_m, npages);
776 #ifdef AFS_FBSD50_ENV
778 cnt.v_vnodepgsout += ap->a_count;
781 iov.iov_base = (caddr_t) kva;
782 iov.iov_len = ap->a_count;
785 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
786 uio.uio_resid = ap->a_count;
787 uio.uio_segflg = UIO_SYSSPACE;
788 uio.uio_rw = UIO_WRITE;
789 #ifdef AFS_FBSD50_ENV
790 uio.uio_td = curthread;
792 uio.uio_procp = curproc;
795 if (ap->a_sync & VM_PAGER_PUT_SYNC)
797 /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
798 * sync |= IO_INVAL; */
801 afs_BozonLock(&avc->pvnLock, avc);
802 code = afs_write(avc, &uio, sync, osi_curcred(), 0);
803 afs_BozonUnlock(&avc->pvnLock, avc);
806 pmap_qremove(kva, npages);
807 relpbuf(bp, &afs_pbuf_freecnt);
810 size = ap->a_count - uio.uio_resid;
811 for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
812 ap->a_rtvals[i] = VM_PAGER_OK;
813 vm_page_undirty(ap->a_m[i]);
816 return ap->a_rtvals[0];
821 struct vop_ioctl_args /* {
822 * struct vnode *a_vp;
826 * struct ucred *a_cred;
830 struct vcache *tvc = VTOAFS(ap->a_vp);
833 /* in case we ever get in here... */
835 AFS_STATCNT(afs_ioctl);
836 if (((ap->a_command >> 8) & 0xff) == 'V') {
837 /* This is a VICEIOCTL call */
839 error = HandleIoctl(tvc, NULL /*Not used */ ,
840 ap->a_command, ap->a_data);
844 /* No-op call; just return. */
852 struct vop_poll_args /* {
853 * struct vnode *a_vp;
855 * struct ucred *a_cred;
860 * We should really check to see if I/O is possible.
868 * NB Currently unsupported.
873 struct vop_mmap_args /* {
874 * struct vnode *a_vp;
876 * struct ucred *a_cred;
885 struct vop_fsync_args /* {
886 * struct vnode *a_vp;
887 * struct ucred *a_cred;
893 register struct vnode *vp = ap->a_vp;
896 /*vflushbuf(vp, wait); */
898 error = afs_fsync(VTOAFS(vp), ap->a_cred);
900 error = afs_fsync(VTOAFS(vp), afs_osi_credp);
907 struct vop_remove_args /* {
908 * struct vnode *a_dvp;
909 * struct vnode *a_vp;
910 * struct componentname *a_cnp;
914 register struct vnode *vp = ap->a_vp;
915 register struct vnode *dvp = ap->a_dvp;
919 error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
928 struct vop_link_args /* {
929 * struct vnode *a_vp;
930 * struct vnode *a_tdvp;
931 * struct componentname *a_cnp;
935 register struct vnode *dvp = ap->a_tdvp;
936 register struct vnode *vp = ap->a_vp;
937 #ifdef AFS_FBSD50_ENV
938 struct thread *p = ap->a_cnp->cn_thread;
940 struct proc *p = ap->a_cnp->cn_proc;
944 if (dvp->v_mount != vp->v_mount) {
948 if (vp->v_type == VDIR) {
952 if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
956 error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
959 VOP_UNLOCK(vp, 0, p);
967 struct vop_rename_args /* {
968 * struct vnode *a_fdvp;
969 * struct vnode *a_fvp;
970 * struct componentname *a_fcnp;
971 * struct vnode *a_tdvp;
972 * struct vnode *a_tvp;
973 * struct componentname *a_tcnp;
977 struct componentname *fcnp = ap->a_fcnp;
979 struct componentname *tcnp = ap->a_tcnp;
981 struct vnode *tvp = ap->a_tvp;
982 register struct vnode *tdvp = ap->a_tdvp;
983 struct vnode *fvp = ap->a_fvp;
984 register struct vnode *fdvp = ap->a_fdvp;
985 #ifdef AFS_FBSD50_ENV
986 struct thread *p = fcnp->cn_thread;
988 struct proc *p = fcnp->cn_proc;
992 * Check for cross-device rename.
994 if ((fvp->v_mount != tdvp->v_mount)
995 || (tvp && (fvp->v_mount != tvp->v_mount))) {
1009 * if fvp == tvp, we're just removing one name of a pair of
1010 * directory entries for the same element. convert call into rename.
1011 ( (pinched from FreeBSD 4.4's ufs_rename())
1015 if (fvp->v_type == VDIR) {
1020 /* Release destination completely. */
1024 /* Delete source. */
1027 fcnp->cn_flags &= ~MODMASK;
1028 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1029 if ((fcnp->cn_flags & SAVESTART) == 0)
1030 panic("afs_rename: lost from startdir");
1031 fcnp->cn_nameiop = DELETE;
1033 error = relookup(fdvp, &fvp, fcnp);
1040 error = VOP_REMOVE(fdvp, fvp, fcnp);
1048 if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1051 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1052 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1053 fname[fcnp->cn_namelen] = '\0';
1054 MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1055 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1056 tname[tcnp->cn_namelen] = '\0';
1060 /* XXX use "from" or "to" creds? NFS uses "to" creds */
1062 afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1065 FREE(fname, M_TEMP);
1066 FREE(tname, M_TEMP);
1080 struct vop_mkdir_args /* {
1081 * struct vnode *a_dvp;
1082 * struct vnode **a_vpp;
1083 * struct componentname *a_cnp;
1084 * struct vattr *a_vap;
1087 register struct vnode *dvp = ap->a_dvp;
1088 register struct vattr *vap = ap->a_vap;
1091 #ifdef AFS_FBSD50_ENV
1092 struct thread *p = ap->a_cnp->cn_thread;
1094 struct proc *p = ap->a_cnp->cn_proc;
1099 if ((cnp->cn_flags & HASBUF) == 0)
1100 panic("afs_vop_mkdir: no name");
1103 error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1111 *ap->a_vpp = AFSTOV(vcp);
1112 vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1121 struct vop_rmdir_args /* {
1122 * struct vnode *a_dvp;
1123 * struct vnode *a_vp;
1124 * struct componentname *a_cnp;
1128 register struct vnode *dvp = ap->a_dvp;
1132 error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1138 /* struct vop_symlink_args {
1139 * struct vnode *a_dvp;
1140 * struct vnode **a_vpp;
1141 * struct componentname *a_cnp;
1142 * struct vattr *a_vap;
1147 afs_vop_symlink(struct vop_symlink_args *ap)
1150 struct vnode *newvp;
1161 afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1163 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1165 newvp = AFSTOV(vcp);
1166 #ifdef AFS_FBSD50_ENV
1167 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1169 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc);
1175 *(ap->a_vpp) = newvp;
1181 struct vop_readdir_args /* {
1182 * struct vnode *a_vp;
1183 * struct uio *a_uio;
1184 * struct ucred *a_cred;
1186 * u_long *a_cookies;
1192 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1194 off = ap->a_uio->uio_offset;
1197 afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1199 if (!error && ap->a_ncookies != NULL) {
1200 struct uio *uio = ap->a_uio;
1201 const struct dirent *dp, *dp_start, *dp_end;
1203 u_long *cookies, *cookiep;
1205 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1206 panic("afs_readdir: burned cookies");
1207 dp = (const struct dirent *)
1208 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1210 dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1211 for (dp_start = dp, ncookies = 0; dp < dp_end;
1212 dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1215 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1217 for (dp = dp_start, cookiep = cookies; dp < dp_end;
1218 dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1219 off += dp->d_reclen;
1222 *ap->a_cookies = cookies;
1223 *ap->a_ncookies = ncookies;
1230 afs_vop_readlink(ap)
1231 struct vop_readlink_args /* {
1232 * struct vnode *a_vp;
1233 * struct uio *a_uio;
1234 * struct ucred *a_cred;
1238 /* printf("readlink %x\n", ap->a_vp);*/
1240 error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1245 extern int prtactive;
1248 afs_vop_inactive(ap)
1249 struct vop_inactive_args /* {
1250 * struct vnode *a_vp;
1254 register struct vnode *vp = ap->a_vp;
1256 if (prtactive && vp->v_usecount != 0)
1257 vprint("afs_vop_inactive(): pushing active", vp);
1260 afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */
1262 VOP_UNLOCK(vp, 0, ap->a_p);
1267 * struct vop_reclaim_args {
1268 * struct vnode *a_vp;
1272 afs_vop_reclaim(struct vop_reclaim_args *ap)
1274 /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1276 struct vnode *vp = ap->a_vp;
1277 struct vcache *avc = VTOAFS(vp);
1278 int haveGlock = ISAFS_GLOCK();
1279 int haveVlock = CheckLock(&afs_xvcache);
1284 ObtainWriteLock(&afs_xvcache, 901);
1285 #ifndef AFS_DISCON_ENV
1286 code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */
1288 /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1289 code = afs_FlushVS(avc);
1292 ReleaseWriteLock(&afs_xvcache);
1297 * XXX Pretend it worked, to prevent panic on shutdown
1298 * Garrett, please fix - Jim Rees
1301 printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1307 struct vop_bmap_args /* {
1308 * struct vnode *a_vp;
1310 * struct vnode **a_vpp;
1317 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1320 *ap->a_vpp = ap->a_vp;
1322 if (ap->a_runp != NULL)
1324 if (ap->a_runb != NULL)
1331 afs_vop_strategy(ap)
1332 struct vop_strategy_args /* {
1338 error = afs_ustrategy(ap->a_bp);
1345 struct vop_print_args /* {
1346 * struct vnode *a_vp;
1349 register struct vnode *vp = ap->a_vp;
1350 register struct vcache *vc = VTOAFS(ap->a_vp);
1353 #ifdef AFS_FBSD50_ENV
1354 printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1355 (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1356 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1357 vc->execsOrWriters);
1359 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1360 vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1361 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1362 vc->execsOrWriters);
1364 printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1365 (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1366 (s & CMAPPED) ? " mapped" : "",
1367 (s & CVFlushed) ? " flush in progress" : "");
1373 * Advisory record locking support (fcntl() POSIX style)
1377 struct vop_advlock_args /* {
1378 * struct vnode *a_vp;
1381 * struct flock *a_fl;
1386 struct ucred cr = *osi_curcred();
1390 afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);