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 osi_FlushPages(vc, ap->a_cred);
445 struct vop_close_args /* {
446 * struct vnode *a_vp;
448 * struct ucred *a_cred;
453 struct vcache *avc = VTOAFS(ap->a_vp);
456 code = afs_close(avc, ap->a_fflag, ap->a_cred);
458 code = afs_close(avc, ap->a_fflag, afs_osi_credp);
459 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
466 struct vop_access_args /* {
467 * struct vnode *a_vp;
469 * struct ucred *a_cred;
475 code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
482 struct vop_getattr_args /* {
483 * struct vnode *a_vp;
484 * struct vattr *a_vap;
485 * struct ucred *a_cred;
491 code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
498 struct vop_setattr_args /* {
499 * struct vnode *a_vp;
500 * struct vattr *a_vap;
501 * struct ucred *a_cred;
507 code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
514 struct vop_read_args /* {
515 * struct vnode *a_vp;
518 * struct ucred *a_cred;
523 struct vcache *avc = VTOAFS(ap->a_vp);
525 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
526 code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
531 /* struct vop_getpages_args {
532 * struct vnode *a_vp;
536 * vm_oofset_t a_offset;
540 afs_vop_getpages(struct vop_getpages_args *ap)
543 int i, nextoff, size, toff, npages;
552 #ifdef AFS_FBSD50_ENV
557 if ((object = vp->v_object) == NULL) {
558 printf("afs_getpages: called with non-merged cache vnode??\n");
559 return VM_PAGER_ERROR;
561 npages = btoc(ap->a_count);
563 * If the requested page is partially valid, just return it and
564 * allow the pager to zero-out the blanks. Partially valid pages
565 * can only occur at the file EOF.
569 vm_page_t m = ap->a_m[ap->a_reqpage];
571 #ifdef AFS_FBSD50_ENV
572 VM_OBJECT_LOCK(object);
573 vm_page_lock_queues();
576 /* handled by vm_fault now */
577 /* vm_page_zero_invalid(m, TRUE); */
578 for (i = 0; i < npages; ++i) {
579 if (i != ap->a_reqpage)
580 vm_page_free(ap->a_m[i]);
582 #ifdef AFS_FBSD50_ENV
583 vm_page_unlock_queues();
584 VM_OBJECT_UNLOCK(object);
588 #ifdef AFS_FBSD50_ENV
589 vm_page_unlock_queues();
590 VM_OBJECT_UNLOCK(object);
593 bp = getpbuf(&afs_pbuf_freecnt);
595 kva = (vm_offset_t) bp->b_data;
596 pmap_qenter(kva, ap->a_m, npages);
597 #ifdef AFS_FBSD50_ENV
599 cnt.v_vnodepgsin += npages;
602 iov.iov_base = (caddr_t) kva;
603 iov.iov_len = ap->a_count;
606 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
607 uio.uio_resid = ap->a_count;
608 uio.uio_segflg = UIO_SYSSPACE;
609 uio.uio_rw = UIO_READ;
610 #ifdef AFS_FBSD50_ENV
611 uio.uio_td = curthread;
613 uio.uio_procp = curproc;
617 osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
618 code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
620 pmap_qremove(kva, npages);
622 relpbuf(bp, &afs_pbuf_freecnt);
624 if (code && (uio.uio_resid == ap->a_count)) {
625 #ifdef AFS_FBSD50_ENV
626 VM_OBJECT_LOCK(object);
627 vm_page_lock_queues();
629 for (i = 0; i < npages; ++i) {
630 if (i != ap->a_reqpage)
631 vm_page_free(ap->a_m[i]);
633 #ifdef AFS_FBSD50_ENV
634 vm_page_unlock_queues();
635 VM_OBJECT_UNLOCK(object);
637 return VM_PAGER_ERROR;
640 size = ap->a_count - uio.uio_resid;
641 #ifdef AFS_FBSD50_ENV
642 VM_OBJECT_LOCK(object);
643 vm_page_lock_queues();
645 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
647 nextoff = toff + PAGE_SIZE;
650 m->flags &= ~PG_ZERO;
652 if (nextoff <= size) {
654 * Read operation filled an entire page
656 m->valid = VM_PAGE_BITS_ALL;
658 } else if (size > toff) {
660 * Read operation filled a partial page.
663 vm_page_set_validclean(m, 0, size - toff);
664 /* handled by vm_fault now */
665 /* vm_page_zero_invalid(m, TRUE); */
668 if (i != ap->a_reqpage) {
670 * Whether or not to leave the page activated is up in
671 * the air, but we should put the page on a page queue
672 * somewhere (it already is in the object). Result:
673 * It appears that emperical results show that
674 * deactivating pages is best.
678 * Just in case someone was asking for this page we
679 * now tell them that it is ok to use.
682 if (m->flags & PG_WANTED)
685 vm_page_deactivate(m);
692 #ifdef AFS_FBSD50_ENV
693 vm_page_unlock_queues();
694 VM_OBJECT_UNLOCK(object);
701 struct vop_write_args /* {
702 * struct vnode *a_vp;
705 * struct ucred *a_cred;
709 struct vcache *avc = VTOAFS(ap->a_vp);
711 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
713 afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
719 * struct vop_putpages_args {
720 * struct vnode *a_vp;
725 * vm_oofset_t a_offset;
729 * All of the pages passed to us in ap->a_m[] are already marked as busy,
730 * so there is no additional locking required to set their flags. -GAW
733 afs_vop_putpages(struct vop_putpages_args *ap)
736 int i, size, npages, sync;
744 #ifdef AFS_FBSD50_ENV
750 /* Perhaps these two checks should just be KASSERTs instead... */
751 if (vp->v_object == NULL) {
752 printf("afs_putpages: called with non-merged cache vnode??\n");
753 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
755 if (vType(avc) != VREG) {
756 printf("afs_putpages: not VREG");
757 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
759 npages = btoc(ap->a_count);
760 for (i = 0; i < npages; i++)
761 ap->a_rtvals[i] = VM_PAGER_AGAIN;
762 bp = getpbuf(&afs_pbuf_freecnt);
764 kva = (vm_offset_t) bp->b_data;
765 pmap_qenter(kva, ap->a_m, npages);
766 #ifdef AFS_FBSD50_ENV
768 cnt.v_vnodepgsout += ap->a_count;
771 iov.iov_base = (caddr_t) kva;
772 iov.iov_len = ap->a_count;
775 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
776 uio.uio_resid = ap->a_count;
777 uio.uio_segflg = UIO_SYSSPACE;
778 uio.uio_rw = UIO_WRITE;
779 #ifdef AFS_FBSD50_ENV
780 uio.uio_td = curthread;
782 uio.uio_procp = curproc;
785 if (ap->a_sync & VM_PAGER_PUT_SYNC)
787 /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
788 * sync |= IO_INVAL; */
791 code = afs_write(avc, &uio, sync, osi_curcred(), 0);
794 pmap_qremove(kva, npages);
795 relpbuf(bp, &afs_pbuf_freecnt);
798 size = ap->a_count - uio.uio_resid;
799 for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
800 ap->a_rtvals[i] = VM_PAGER_OK;
801 vm_page_undirty(ap->a_m[i]);
804 return ap->a_rtvals[0];
809 struct vop_ioctl_args /* {
810 * struct vnode *a_vp;
814 * struct ucred *a_cred;
818 struct vcache *tvc = VTOAFS(ap->a_vp);
821 /* in case we ever get in here... */
823 AFS_STATCNT(afs_ioctl);
824 if (((ap->a_command >> 8) & 0xff) == 'V') {
825 /* This is a VICEIOCTL call */
827 error = HandleIoctl(tvc, NULL /*Not used */ ,
828 ap->a_command, ap->a_data);
832 /* No-op call; just return. */
840 struct vop_poll_args /* {
841 * struct vnode *a_vp;
843 * struct ucred *a_cred;
848 * We should really check to see if I/O is possible.
856 * NB Currently unsupported.
861 struct vop_mmap_args /* {
862 * struct vnode *a_vp;
864 * struct ucred *a_cred;
873 struct vop_fsync_args /* {
874 * struct vnode *a_vp;
875 * struct ucred *a_cred;
881 register struct vnode *vp = ap->a_vp;
884 /*vflushbuf(vp, wait); */
886 error = afs_fsync(VTOAFS(vp), ap->a_cred);
888 error = afs_fsync(VTOAFS(vp), afs_osi_credp);
895 struct vop_remove_args /* {
896 * struct vnode *a_dvp;
897 * struct vnode *a_vp;
898 * struct componentname *a_cnp;
902 register struct vnode *vp = ap->a_vp;
903 register struct vnode *dvp = ap->a_dvp;
907 error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
916 struct vop_link_args /* {
917 * struct vnode *a_vp;
918 * struct vnode *a_tdvp;
919 * struct componentname *a_cnp;
923 register struct vnode *dvp = ap->a_tdvp;
924 register struct vnode *vp = ap->a_vp;
925 #ifdef AFS_FBSD50_ENV
926 struct thread *p = ap->a_cnp->cn_thread;
928 struct proc *p = ap->a_cnp->cn_proc;
932 if (dvp->v_mount != vp->v_mount) {
936 if (vp->v_type == VDIR) {
940 if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
944 error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
947 VOP_UNLOCK(vp, 0, p);
955 struct vop_rename_args /* {
956 * struct vnode *a_fdvp;
957 * struct vnode *a_fvp;
958 * struct componentname *a_fcnp;
959 * struct vnode *a_tdvp;
960 * struct vnode *a_tvp;
961 * struct componentname *a_tcnp;
965 struct componentname *fcnp = ap->a_fcnp;
967 struct componentname *tcnp = ap->a_tcnp;
969 struct vnode *tvp = ap->a_tvp;
970 register struct vnode *tdvp = ap->a_tdvp;
971 struct vnode *fvp = ap->a_fvp;
972 register struct vnode *fdvp = ap->a_fdvp;
973 #ifdef AFS_FBSD50_ENV
974 struct thread *p = fcnp->cn_thread;
976 struct proc *p = fcnp->cn_proc;
980 * Check for cross-device rename.
982 if ((fvp->v_mount != tdvp->v_mount)
983 || (tvp && (fvp->v_mount != tvp->v_mount))) {
997 * if fvp == tvp, we're just removing one name of a pair of
998 * directory entries for the same element. convert call into rename.
999 ( (pinched from FreeBSD 4.4's ufs_rename())
1003 if (fvp->v_type == VDIR) {
1008 /* Release destination completely. */
1012 /* Delete source. */
1015 fcnp->cn_flags &= ~MODMASK;
1016 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1017 if ((fcnp->cn_flags & SAVESTART) == 0)
1018 panic("afs_rename: lost from startdir");
1019 fcnp->cn_nameiop = DELETE;
1021 error = relookup(fdvp, &fvp, fcnp);
1028 error = VOP_REMOVE(fdvp, fvp, fcnp);
1036 if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1039 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1040 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1041 fname[fcnp->cn_namelen] = '\0';
1042 MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1043 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1044 tname[tcnp->cn_namelen] = '\0';
1048 /* XXX use "from" or "to" creds? NFS uses "to" creds */
1050 afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1053 FREE(fname, M_TEMP);
1054 FREE(tname, M_TEMP);
1068 struct vop_mkdir_args /* {
1069 * struct vnode *a_dvp;
1070 * struct vnode **a_vpp;
1071 * struct componentname *a_cnp;
1072 * struct vattr *a_vap;
1075 register struct vnode *dvp = ap->a_dvp;
1076 register struct vattr *vap = ap->a_vap;
1079 #ifdef AFS_FBSD50_ENV
1080 struct thread *p = ap->a_cnp->cn_thread;
1082 struct proc *p = ap->a_cnp->cn_proc;
1087 if ((cnp->cn_flags & HASBUF) == 0)
1088 panic("afs_vop_mkdir: no name");
1091 error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1098 *ap->a_vpp = AFSTOV(vcp);
1099 vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1108 struct vop_rmdir_args /* {
1109 * struct vnode *a_dvp;
1110 * struct vnode *a_vp;
1111 * struct componentname *a_cnp;
1115 register struct vnode *dvp = ap->a_dvp;
1119 error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1125 /* struct vop_symlink_args {
1126 * struct vnode *a_dvp;
1127 * struct vnode **a_vpp;
1128 * struct componentname *a_cnp;
1129 * struct vattr *a_vap;
1134 afs_vop_symlink(struct vop_symlink_args *ap)
1137 struct vnode *newvp;
1148 afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1150 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1152 newvp = AFSTOV(vcp);
1153 #ifdef AFS_FBSD50_ENV
1154 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1156 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc);
1162 *(ap->a_vpp) = newvp;
1168 struct vop_readdir_args /* {
1169 * struct vnode *a_vp;
1170 * struct uio *a_uio;
1171 * struct ucred *a_cred;
1173 * u_long *a_cookies;
1179 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1181 off = ap->a_uio->uio_offset;
1184 afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1186 if (!error && ap->a_ncookies != NULL) {
1187 struct uio *uio = ap->a_uio;
1188 const struct dirent *dp, *dp_start, *dp_end;
1190 u_long *cookies, *cookiep;
1192 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1193 panic("afs_readdir: burned cookies");
1194 dp = (const struct dirent *)
1195 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1197 dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1198 for (dp_start = dp, ncookies = 0; dp < dp_end;
1199 dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1202 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1204 for (dp = dp_start, cookiep = cookies; dp < dp_end;
1205 dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1206 off += dp->d_reclen;
1209 *ap->a_cookies = cookies;
1210 *ap->a_ncookies = ncookies;
1217 afs_vop_readlink(ap)
1218 struct vop_readlink_args /* {
1219 * struct vnode *a_vp;
1220 * struct uio *a_uio;
1221 * struct ucred *a_cred;
1225 /* printf("readlink %x\n", ap->a_vp);*/
1227 error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1232 extern int prtactive;
1235 afs_vop_inactive(ap)
1236 struct vop_inactive_args /* {
1237 * struct vnode *a_vp;
1241 register struct vnode *vp = ap->a_vp;
1243 if (prtactive && vp->v_usecount != 0)
1244 vprint("afs_vop_inactive(): pushing active", vp);
1247 afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */
1249 VOP_UNLOCK(vp, 0, ap->a_p);
1254 * struct vop_reclaim_args {
1255 * struct vnode *a_vp;
1259 afs_vop_reclaim(struct vop_reclaim_args *ap)
1261 /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1263 struct vnode *vp = ap->a_vp;
1264 struct vcache *avc = VTOAFS(vp);
1265 int haveGlock = ISAFS_GLOCK();
1266 int haveVlock = CheckLock(&afs_xvcache);
1271 ObtainWriteLock(&afs_xvcache, 901);
1272 #ifndef AFS_DISCON_ENV
1273 code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */
1275 /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1276 code = afs_FlushVS(avc);
1279 ReleaseWriteLock(&afs_xvcache);
1284 * XXX Pretend it worked, to prevent panic on shutdown
1285 * Garrett, please fix - Jim Rees
1288 printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1294 struct vop_bmap_args /* {
1295 * struct vnode *a_vp;
1297 * struct vnode **a_vpp;
1304 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1307 *ap->a_vpp = ap->a_vp;
1309 if (ap->a_runp != NULL)
1311 if (ap->a_runb != NULL)
1318 afs_vop_strategy(ap)
1319 struct vop_strategy_args /* {
1325 error = afs_ustrategy(ap->a_bp);
1332 struct vop_print_args /* {
1333 * struct vnode *a_vp;
1336 register struct vnode *vp = ap->a_vp;
1337 register struct vcache *vc = VTOAFS(ap->a_vp);
1340 #ifdef AFS_FBSD50_ENV
1341 printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1342 (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1343 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1344 vc->execsOrWriters);
1346 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1347 vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1348 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1349 vc->execsOrWriters);
1351 printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1352 (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1353 (s & CMAPPED) ? " mapped" : "",
1354 (s & CVFlushed) ? " flush in progress" : "");
1360 * Advisory record locking support (fcntl() POSIX style)
1364 struct vop_advlock_args /* {
1365 * struct vnode *a_vp;
1368 * struct flock *a_fl;
1373 struct ucred cr = *osi_curcred();
1377 afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);