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;
69 static vop_access_t afs_vop_access;
70 static vop_advlock_t afs_vop_advlock;
71 static vop_close_t afs_vop_close;
72 static vop_create_t afs_vop_create;
73 static vop_fsync_t afs_vop_fsync;
74 static vop_getattr_t afs_vop_getattr;
75 static vop_getpages_t afs_vop_getpages;
76 static vop_inactive_t afs_vop_inactive;
77 static vop_ioctl_t afs_vop_ioctl;
78 static vop_link_t afs_vop_link;
79 static vop_lookup_t afs_vop_lookup;
80 static vop_mkdir_t afs_vop_mkdir;
81 static vop_mknod_t afs_vop_mknod;
82 static vop_open_t afs_vop_open;
83 static vop_pathconf_t afs_vop_pathconf;
84 static vop_poll_t afs_vop_poll;
85 static vop_print_t afs_vop_print;
86 static vop_putpages_t afs_vop_putpages;
87 static vop_read_t afs_vop_read;
88 static vop_readdir_t afs_vop_readdir;
89 static vop_readlink_t afs_vop_readlink;
90 static vop_reclaim_t afs_vop_reclaim;
91 static vop_remove_t afs_vop_remove;
92 static vop_rename_t afs_vop_rename;
93 static vop_rmdir_t afs_vop_rmdir;
94 static vop_setattr_t afs_vop_setattr;
95 static vop_strategy_t afs_vop_strategy;
96 static vop_symlink_t afs_vop_symlink;
97 static vop_write_t afs_vop_write;
99 struct vop_vector afs_vnodeops = {
100 .vop_default = &default_vnodeops,
101 .vop_access = afs_vop_access,
102 .vop_advlock = afs_vop_advlock,
103 .vop_close = afs_vop_close,
104 .vop_create = afs_vop_create,
105 .vop_fsync = afs_vop_fsync,
106 .vop_getattr = afs_vop_getattr,
107 .vop_getpages = afs_vop_getpages,
108 .vop_inactive = afs_vop_inactive,
109 .vop_ioctl = afs_vop_ioctl,
110 .vop_lease = VOP_NULL,
111 .vop_link = afs_vop_link,
112 .vop_lookup = afs_vop_lookup,
113 .vop_mkdir = afs_vop_mkdir,
114 .vop_mknod = afs_vop_mknod,
115 .vop_open = afs_vop_open,
116 .vop_pathconf = afs_vop_pathconf,
117 .vop_poll = afs_vop_poll,
118 .vop_print = afs_vop_print,
119 .vop_putpages = afs_vop_putpages,
120 .vop_read = afs_vop_read,
121 .vop_readdir = afs_vop_readdir,
122 .vop_readlink = afs_vop_readlink,
123 .vop_reclaim = afs_vop_reclaim,
124 .vop_remove = afs_vop_remove,
125 .vop_rename = afs_vop_rename,
126 .vop_rmdir = afs_vop_rmdir,
127 .vop_setattr = afs_vop_setattr,
128 .vop_strategy = afs_vop_strategy,
129 .vop_symlink = afs_vop_symlink,
130 .vop_write = afs_vop_write,
133 #else /* AFS_FBSD60_ENV */
135 int afs_vop_lookup(struct vop_lookup_args *);
136 int afs_vop_create(struct vop_create_args *);
137 int afs_vop_mknod(struct vop_mknod_args *);
138 int afs_vop_open(struct vop_open_args *);
139 int afs_vop_close(struct vop_close_args *);
140 int afs_vop_access(struct vop_access_args *);
141 int afs_vop_getattr(struct vop_getattr_args *);
142 int afs_vop_setattr(struct vop_setattr_args *);
143 int afs_vop_read(struct vop_read_args *);
144 int afs_vop_write(struct vop_write_args *);
145 int afs_vop_getpages(struct vop_getpages_args *);
146 int afs_vop_putpages(struct vop_putpages_args *);
147 int afs_vop_ioctl(struct vop_ioctl_args *);
148 static int afs_vop_pathconf(struct vop_pathconf_args *);
149 int afs_vop_poll(struct vop_poll_args *);
150 #ifndef AFS_FBSD50_ENV
151 int afs_vop_mmap(struct vop_mmap_args *);
153 int afs_vop_fsync(struct vop_fsync_args *);
154 int afs_vop_remove(struct vop_remove_args *);
155 int afs_vop_link(struct vop_link_args *);
156 int afs_vop_rename(struct vop_rename_args *);
157 int afs_vop_mkdir(struct vop_mkdir_args *);
158 int afs_vop_rmdir(struct vop_rmdir_args *);
159 int afs_vop_symlink(struct vop_symlink_args *);
160 int afs_vop_readdir(struct vop_readdir_args *);
161 int afs_vop_readlink(struct vop_readlink_args *);
162 int afs_vop_inactive(struct vop_inactive_args *);
163 int afs_vop_reclaim(struct vop_reclaim_args *);
164 int afs_vop_bmap(struct vop_bmap_args *);
165 int afs_vop_strategy(struct vop_strategy_args *);
166 int afs_vop_print(struct vop_print_args *);
167 int afs_vop_advlock(struct vop_advlock_args *);
171 /* Global vfs data structures for AFS. */
172 vop_t **afs_vnodeop_p;
173 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
174 {&vop_default_desc, (vop_t *) vop_defaultop},
175 {&vop_access_desc, (vop_t *) afs_vop_access}, /* access */
176 {&vop_advlock_desc, (vop_t *) afs_vop_advlock}, /* advlock */
177 {&vop_bmap_desc, (vop_t *) afs_vop_bmap}, /* bmap */
178 #ifndef AFS_FBSD50_ENV
179 {&vop_bwrite_desc, (vop_t *) vop_stdbwrite},
181 {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */
182 {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject},
183 {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject},
184 {&vop_create_desc, (vop_t *) afs_vop_create}, /* create */
185 {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */
186 {&vop_getattr_desc, (vop_t *) afs_vop_getattr}, /* getattr */
187 {&vop_getpages_desc, (vop_t *) afs_vop_getpages}, /* read */
188 {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject},
189 {&vop_putpages_desc, (vop_t *) afs_vop_putpages}, /* write */
190 {&vop_inactive_desc, (vop_t *) afs_vop_inactive}, /* inactive */
191 {&vop_lease_desc, (vop_t *) vop_null},
192 {&vop_link_desc, (vop_t *) afs_vop_link}, /* link */
193 {&vop_lookup_desc, (vop_t *) afs_vop_lookup}, /* lookup */
194 {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */
195 {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */
196 #ifndef AFS_FBSD50_ENV
197 {&vop_mmap_desc, (vop_t *) afs_vop_mmap}, /* mmap */
199 {&vop_open_desc, (vop_t *) afs_vop_open}, /* open */
200 {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf}, /* pathconf */
201 {&vop_poll_desc, (vop_t *) afs_vop_poll}, /* select */
202 {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */
203 {&vop_read_desc, (vop_t *) afs_vop_read}, /* read */
204 {&vop_readdir_desc, (vop_t *) afs_vop_readdir}, /* readdir */
205 {&vop_readlink_desc, (vop_t *) afs_vop_readlink}, /* readlink */
206 {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim}, /* reclaim */
207 {&vop_remove_desc, (vop_t *) afs_vop_remove}, /* remove */
208 {&vop_rename_desc, (vop_t *) afs_vop_rename}, /* rename */
209 {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */
210 {&vop_setattr_desc, (vop_t *) afs_vop_setattr}, /* setattr */
211 {&vop_strategy_desc, (vop_t *) afs_vop_strategy}, /* strategy */
212 {&vop_symlink_desc, (vop_t *) afs_vop_symlink}, /* symlink */
213 {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */
214 {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */
215 /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */
218 struct vnodeopv_desc afs_vnodeop_opv_desc =
219 { &afs_vnodeop_p, afs_vnodeop_entries };
220 #endif /* AFS_FBSD60_ENV */
223 struct componentname *cnp = ap->a_cnp; \
225 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
226 memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
227 name[cnp->cn_namelen] = '\0'
229 #define DROPNAME() FREE(name, M_TEMP)
231 /* This is a bit of a cheat... */
232 #ifdef AFS_FBSD50_ENV
237 * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf().
238 * We should know the correct answers to these questions with
239 * respect to the AFS protocol (which may differ from the UFS
240 * values) but for the moment this will do.
243 afs_vop_pathconf(struct vop_pathconf_args *ap)
248 switch (ap->a_name) {
250 *ap->a_retval = LINK_MAX;
253 *ap->a_retval = NAME_MAX;
256 *ap->a_retval = PATH_MAX;
259 *ap->a_retval = PIPE_BUF;
261 case _PC_CHOWN_RESTRICTED:
267 #ifdef _PC_ACL_EXTENDED
268 case _PC_ACL_EXTENDED:
271 case _PC_ACL_PATH_MAX:
275 #ifdef _PC_MAC_PRESENT
276 case _PC_MAC_PRESENT:
282 /* _PC_ASYNC_IO should have been handled by upper layers. */
283 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
293 #ifdef _PC_ALLOC_SIZE_MIN
294 case _PC_ALLOC_SIZE_MIN:
295 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
298 #ifdef _PC_FILESIZEBITS
299 case _PC_FILESIZEBITS:
300 *ap->a_retval = 32; /* XXX */
303 #ifdef _PC_REC_INCR_XFER_SIZE
304 case _PC_REC_INCR_XFER_SIZE:
305 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
307 case _PC_REC_MAX_XFER_SIZE:
308 *ap->a_retval = -1; /* means ``unlimited'' */
310 case _PC_REC_MIN_XFER_SIZE:
311 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
313 case _PC_REC_XFER_ALIGN:
314 *ap->a_retval = PAGE_SIZE;
317 #ifdef _PC_SYMLINK_MAX
318 case _PC_SYMLINK_MAX:
319 *ap->a_retval = MAXPATHLEN;
331 struct vop_lookup_args /* {
332 * struct vnodeop_desc * a_desc;
333 * struct vnode *a_dvp;
334 * struct vnode **a_vpp;
335 * struct componentname *a_cnp;
340 struct vnode *vp, *dvp;
341 register int flags = ap->a_cnp->cn_flags;
342 int lockparent; /* 1 => lockparent flag is set */
343 int wantparent; /* 1 => wantparent or lockparent flag */
344 #ifdef AFS_FBSD50_ENV
345 struct thread *p = ap->a_cnp->cn_thread;
347 struct proc *p = ap->a_cnp->cn_proc;
351 lockparent = flags & LOCKPARENT;
352 wantparent = flags & (LOCKPARENT | WANTPARENT);
354 if (ap->a_dvp->v_type != VDIR) {
360 if (flags & ISDOTDOT)
361 VOP_UNLOCK(dvp, 0, p);
363 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
366 if (flags & ISDOTDOT)
367 VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
368 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
369 && (flags & ISLASTCN) && error == ENOENT)
371 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
372 cnp->cn_flags |= SAVENAME;
377 vp = AFSTOV(vcp); /* always get a node if no error */
379 /* The parent directory comes in locked. We unlock it on return
380 * unless the caller wants it left locked.
381 * we also always return the vnode locked. */
383 if (flags & ISDOTDOT) {
384 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
385 /* always return the child locked */
386 if (lockparent && (flags & ISLASTCN)
387 && (error = vn_lock(dvp, LK_EXCLUSIVE, p))) {
392 } else if (vp == dvp) {
393 /* they're the same; afs_lookup() already ref'ed the leaf.
394 * It came in locked, so we don't need to ref OR lock it */
396 if (!lockparent || !(flags & ISLASTCN))
397 VOP_UNLOCK(dvp, 0, p); /* done with parent. */
398 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
399 /* always return the child locked */
403 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
404 || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
405 cnp->cn_flags |= SAVENAME;
413 struct vop_create_args /* {
414 * struct vnode *a_dvp;
415 * struct vnode **a_vpp;
416 * struct componentname *a_cnp;
417 * struct vattr *a_vap;
422 register struct vnode *dvp = ap->a_dvp;
423 #ifdef AFS_FBSD50_ENV
424 struct thread *p = ap->a_cnp->cn_thread;
426 struct proc *p = ap->a_cnp->cn_proc;
432 afs_create(VTOAFS(dvp), name, ap->a_vap,
433 ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL,
434 ap->a_vap->va_mode, &vcp, cnp->cn_cred);
442 *ap->a_vpp = AFSTOV(vcp);
443 vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
453 struct vop_mknod_args /* {
454 * struct vnode *a_dvp;
455 * struct vnode **a_vpp;
456 * struct componentname *a_cnp;
457 * struct vattr *a_vap;
465 validate_vops(struct vnode *vp, int after)
468 struct vnodeopv_entry_desc *this;
469 for (this = afs_vnodeop_entries; this->opve_op; this++) {
470 if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) {
472 printf("v_op %d ", after);
476 printf("For oper %d (%s), func is %p, not %p",
477 this->opve_op->vdesc_offset, this->opve_op->vdesc_name,
478 vp->v_op[this->opve_op->vdesc_offset], this->opve_impl);
486 struct vop_open_args /* {
487 * struct vnode *a_vp;
489 * struct ucred *a_cred;
494 struct vcache *vc = VTOAFS(ap->a_vp);
497 error = afs_open(&vc, ap->a_mode, ap->a_cred);
499 if (AFSTOV(vc) != ap->a_vp)
500 panic("AFS open changed vnode!");
503 #ifdef AFS_FBSD60_ENV
504 vnode_create_vobject(ap->a_vp, vc->m.Length, ap->a_td);
506 osi_FlushPages(vc, ap->a_cred);
512 struct vop_close_args /* {
513 * struct vnode *a_vp;
515 * struct ucred *a_cred;
520 struct vcache *avc = VTOAFS(ap->a_vp);
523 code = afs_close(avc, ap->a_fflag, ap->a_cred);
525 code = afs_close(avc, ap->a_fflag, afs_osi_credp);
526 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
533 struct vop_access_args /* {
534 * struct vnode *a_vp;
536 * struct ucred *a_cred;
542 code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
549 struct vop_getattr_args /* {
550 * struct vnode *a_vp;
551 * struct vattr *a_vap;
552 * struct ucred *a_cred;
558 code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
565 struct vop_setattr_args /* {
566 * struct vnode *a_vp;
567 * struct vattr *a_vap;
568 * struct ucred *a_cred;
574 code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
581 struct vop_read_args /* {
582 * struct vnode *a_vp;
585 * struct ucred *a_cred;
590 struct vcache *avc = VTOAFS(ap->a_vp);
592 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
593 code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
598 /* struct vop_getpages_args {
599 * struct vnode *a_vp;
603 * vm_oofset_t a_offset;
607 afs_vop_getpages(struct vop_getpages_args *ap)
610 int i, nextoff, size, toff, npages;
619 #ifdef AFS_FBSD50_ENV
624 if ((object = vp->v_object) == NULL) {
625 printf("afs_getpages: called with non-merged cache vnode??\n");
626 return VM_PAGER_ERROR;
628 npages = btoc(ap->a_count);
630 * If the requested page is partially valid, just return it and
631 * allow the pager to zero-out the blanks. Partially valid pages
632 * can only occur at the file EOF.
636 vm_page_t m = ap->a_m[ap->a_reqpage];
638 #ifdef AFS_FBSD50_ENV
639 VM_OBJECT_LOCK(object);
640 vm_page_lock_queues();
643 /* handled by vm_fault now */
644 /* vm_page_zero_invalid(m, TRUE); */
645 for (i = 0; i < npages; ++i) {
646 if (i != ap->a_reqpage)
647 vm_page_free(ap->a_m[i]);
649 #ifdef AFS_FBSD50_ENV
650 vm_page_unlock_queues();
651 VM_OBJECT_UNLOCK(object);
655 #ifdef AFS_FBSD50_ENV
656 vm_page_unlock_queues();
657 VM_OBJECT_UNLOCK(object);
660 bp = getpbuf(&afs_pbuf_freecnt);
662 kva = (vm_offset_t) bp->b_data;
663 pmap_qenter(kva, ap->a_m, npages);
664 #ifdef AFS_FBSD50_ENV
666 cnt.v_vnodepgsin += npages;
669 iov.iov_base = (caddr_t) kva;
670 iov.iov_len = ap->a_count;
673 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
674 uio.uio_resid = ap->a_count;
675 uio.uio_segflg = UIO_SYSSPACE;
676 uio.uio_rw = UIO_READ;
677 #ifdef AFS_FBSD50_ENV
678 uio.uio_td = curthread;
680 uio.uio_procp = curproc;
684 osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
685 code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
687 pmap_qremove(kva, npages);
689 relpbuf(bp, &afs_pbuf_freecnt);
691 if (code && (uio.uio_resid == ap->a_count)) {
692 #ifdef AFS_FBSD50_ENV
693 VM_OBJECT_LOCK(object);
694 vm_page_lock_queues();
696 for (i = 0; i < npages; ++i) {
697 if (i != ap->a_reqpage)
698 vm_page_free(ap->a_m[i]);
700 #ifdef AFS_FBSD50_ENV
701 vm_page_unlock_queues();
702 VM_OBJECT_UNLOCK(object);
704 return VM_PAGER_ERROR;
707 size = ap->a_count - uio.uio_resid;
708 #ifdef AFS_FBSD50_ENV
709 VM_OBJECT_LOCK(object);
710 vm_page_lock_queues();
712 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
714 nextoff = toff + PAGE_SIZE;
717 m->flags &= ~PG_ZERO;
719 if (nextoff <= size) {
721 * Read operation filled an entire page
723 m->valid = VM_PAGE_BITS_ALL;
725 } else if (size > toff) {
727 * Read operation filled a partial page.
730 vm_page_set_validclean(m, 0, size - toff);
731 /* handled by vm_fault now */
732 /* vm_page_zero_invalid(m, TRUE); */
735 if (i != ap->a_reqpage) {
737 * Whether or not to leave the page activated is up in
738 * the air, but we should put the page on a page queue
739 * somewhere (it already is in the object). Result:
740 * It appears that emperical results show that
741 * deactivating pages is best.
745 * Just in case someone was asking for this page we
746 * now tell them that it is ok to use.
749 #if defined(AFS_FBSD70_ENV)
750 if(0) /* XXXX fixme for 7.0 */
752 if (m->flags & PG_WANTED)
756 vm_page_deactivate(m);
763 #ifdef AFS_FBSD50_ENV
764 vm_page_unlock_queues();
765 VM_OBJECT_UNLOCK(object);
772 struct vop_write_args /* {
773 * struct vnode *a_vp;
776 * struct ucred *a_cred;
780 struct vcache *avc = VTOAFS(ap->a_vp);
782 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
784 afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
790 * struct vop_putpages_args {
791 * struct vnode *a_vp;
796 * vm_oofset_t a_offset;
800 * All of the pages passed to us in ap->a_m[] are already marked as busy,
801 * so there is no additional locking required to set their flags. -GAW
804 afs_vop_putpages(struct vop_putpages_args *ap)
807 int i, size, npages, sync;
815 #ifdef AFS_FBSD50_ENV
821 /* Perhaps these two checks should just be KASSERTs instead... */
822 if (vp->v_object == NULL) {
823 printf("afs_putpages: called with non-merged cache vnode??\n");
824 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
826 if (vType(avc) != VREG) {
827 printf("afs_putpages: not VREG");
828 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
830 npages = btoc(ap->a_count);
831 for (i = 0; i < npages; i++)
832 ap->a_rtvals[i] = VM_PAGER_AGAIN;
833 bp = getpbuf(&afs_pbuf_freecnt);
835 kva = (vm_offset_t) bp->b_data;
836 pmap_qenter(kva, ap->a_m, npages);
837 #ifdef AFS_FBSD50_ENV
839 cnt.v_vnodepgsout += ap->a_count;
842 iov.iov_base = (caddr_t) kva;
843 iov.iov_len = ap->a_count;
846 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
847 uio.uio_resid = ap->a_count;
848 uio.uio_segflg = UIO_SYSSPACE;
849 uio.uio_rw = UIO_WRITE;
850 #ifdef AFS_FBSD50_ENV
851 uio.uio_td = curthread;
853 uio.uio_procp = curproc;
856 if (ap->a_sync & VM_PAGER_PUT_SYNC)
858 /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
859 * sync |= IO_INVAL; */
862 code = afs_write(avc, &uio, sync, osi_curcred(), 0);
865 pmap_qremove(kva, npages);
866 relpbuf(bp, &afs_pbuf_freecnt);
869 size = ap->a_count - uio.uio_resid;
870 for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
871 ap->a_rtvals[i] = VM_PAGER_OK;
872 vm_page_undirty(ap->a_m[i]);
875 return ap->a_rtvals[0];
880 struct vop_ioctl_args /* {
881 * struct vnode *a_vp;
885 * struct ucred *a_cred;
889 struct vcache *tvc = VTOAFS(ap->a_vp);
892 /* in case we ever get in here... */
894 AFS_STATCNT(afs_ioctl);
895 if (((ap->a_command >> 8) & 0xff) == 'V') {
896 /* This is a VICEIOCTL call */
898 error = HandleIoctl(tvc, NULL /*Not used */ ,
899 ap->a_command, ap->a_data);
903 /* No-op call; just return. */
911 struct vop_poll_args /* {
912 * struct vnode *a_vp;
914 * struct ucred *a_cred;
919 * We should really check to see if I/O is possible.
927 * NB Currently unsupported.
932 struct vop_mmap_args /* {
933 * struct vnode *a_vp;
935 * struct ucred *a_cred;
944 struct vop_fsync_args /* {
945 * struct vnode *a_vp;
946 * struct ucred *a_cred;
952 register struct vnode *vp = ap->a_vp;
955 /*vflushbuf(vp, wait); */
956 #ifdef AFS_FBSD60_ENV
957 error = afs_fsync(VTOAFS(vp), ap->a_td->td_ucred);
960 error = afs_fsync(VTOAFS(vp), ap->a_cred);
962 error = afs_fsync(VTOAFS(vp), afs_osi_credp);
970 struct vop_remove_args /* {
971 * struct vnode *a_dvp;
972 * struct vnode *a_vp;
973 * struct componentname *a_cnp;
977 register struct vnode *vp = ap->a_vp;
978 register struct vnode *dvp = ap->a_dvp;
982 error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
991 struct vop_link_args /* {
992 * struct vnode *a_vp;
993 * struct vnode *a_tdvp;
994 * struct componentname *a_cnp;
998 register struct vnode *dvp = ap->a_tdvp;
999 register struct vnode *vp = ap->a_vp;
1000 #ifdef AFS_FBSD50_ENV
1001 struct thread *p = ap->a_cnp->cn_thread;
1003 struct proc *p = ap->a_cnp->cn_proc;
1007 if (dvp->v_mount != vp->v_mount) {
1011 if (vp->v_type == VDIR) {
1015 if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
1019 error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
1022 VOP_UNLOCK(vp, 0, p);
1030 struct vop_rename_args /* {
1031 * struct vnode *a_fdvp;
1032 * struct vnode *a_fvp;
1033 * struct componentname *a_fcnp;
1034 * struct vnode *a_tdvp;
1035 * struct vnode *a_tvp;
1036 * struct componentname *a_tcnp;
1040 struct componentname *fcnp = ap->a_fcnp;
1042 struct componentname *tcnp = ap->a_tcnp;
1044 struct vnode *tvp = ap->a_tvp;
1045 register struct vnode *tdvp = ap->a_tdvp;
1046 struct vnode *fvp = ap->a_fvp;
1047 register struct vnode *fdvp = ap->a_fdvp;
1048 #ifdef AFS_FBSD50_ENV
1049 struct thread *p = fcnp->cn_thread;
1051 struct proc *p = fcnp->cn_proc;
1055 * Check for cross-device rename.
1057 if ((fvp->v_mount != tdvp->v_mount)
1058 || (tvp && (fvp->v_mount != tvp->v_mount))) {
1072 * if fvp == tvp, we're just removing one name of a pair of
1073 * directory entries for the same element. convert call into rename.
1074 ( (pinched from FreeBSD 4.4's ufs_rename())
1078 if (fvp->v_type == VDIR) {
1083 /* Release destination completely. */
1087 /* Delete source. */
1090 fcnp->cn_flags &= ~MODMASK;
1091 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1092 if ((fcnp->cn_flags & SAVESTART) == 0)
1093 panic("afs_rename: lost from startdir");
1094 fcnp->cn_nameiop = DELETE;
1096 error = relookup(fdvp, &fvp, fcnp);
1103 error = VOP_REMOVE(fdvp, fvp, fcnp);
1111 if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1114 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1115 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1116 fname[fcnp->cn_namelen] = '\0';
1117 MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1118 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1119 tname[tcnp->cn_namelen] = '\0';
1123 /* XXX use "from" or "to" creds? NFS uses "to" creds */
1125 afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1128 FREE(fname, M_TEMP);
1129 FREE(tname, M_TEMP);
1143 struct vop_mkdir_args /* {
1144 * struct vnode *a_dvp;
1145 * struct vnode **a_vpp;
1146 * struct componentname *a_cnp;
1147 * struct vattr *a_vap;
1150 register struct vnode *dvp = ap->a_dvp;
1151 register struct vattr *vap = ap->a_vap;
1154 #ifdef AFS_FBSD50_ENV
1155 struct thread *p = ap->a_cnp->cn_thread;
1157 struct proc *p = ap->a_cnp->cn_proc;
1162 if ((cnp->cn_flags & HASBUF) == 0)
1163 panic("afs_vop_mkdir: no name");
1166 error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1173 *ap->a_vpp = AFSTOV(vcp);
1174 vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1183 struct vop_rmdir_args /* {
1184 * struct vnode *a_dvp;
1185 * struct vnode *a_vp;
1186 * struct componentname *a_cnp;
1190 register struct vnode *dvp = ap->a_dvp;
1194 error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1200 /* struct vop_symlink_args {
1201 * struct vnode *a_dvp;
1202 * struct vnode **a_vpp;
1203 * struct componentname *a_cnp;
1204 * struct vattr *a_vap;
1209 afs_vop_symlink(struct vop_symlink_args *ap)
1212 struct vnode *newvp;
1223 afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1225 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1227 newvp = AFSTOV(vcp);
1228 #ifdef AFS_FBSD50_ENV
1229 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1231 vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc);
1237 *(ap->a_vpp) = newvp;
1243 struct vop_readdir_args /* {
1244 * struct vnode *a_vp;
1245 * struct uio *a_uio;
1246 * struct ucred *a_cred;
1248 * u_long *a_cookies;
1254 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1256 off = ap->a_uio->uio_offset;
1259 afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1261 if (!error && ap->a_ncookies != NULL) {
1262 struct uio *uio = ap->a_uio;
1263 const struct dirent *dp, *dp_start, *dp_end;
1265 u_long *cookies, *cookiep;
1267 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1268 panic("afs_readdir: burned cookies");
1269 dp = (const struct dirent *)
1270 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1272 dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1273 for (dp_start = dp, ncookies = 0; dp < dp_end;
1274 dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1277 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1279 for (dp = dp_start, cookiep = cookies; dp < dp_end;
1280 dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1281 off += dp->d_reclen;
1284 *ap->a_cookies = cookies;
1285 *ap->a_ncookies = ncookies;
1292 afs_vop_readlink(ap)
1293 struct vop_readlink_args /* {
1294 * struct vnode *a_vp;
1295 * struct uio *a_uio;
1296 * struct ucred *a_cred;
1300 /* printf("readlink %x\n", ap->a_vp);*/
1302 error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1307 extern int prtactive;
1310 afs_vop_inactive(ap)
1311 struct vop_inactive_args /* {
1312 * struct vnode *a_vp;
1316 register struct vnode *vp = ap->a_vp;
1318 if (prtactive && vp->v_usecount != 0)
1319 vprint("afs_vop_inactive(): pushing active", vp);
1322 afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */
1324 VOP_UNLOCK(vp, 0, ap->a_p);
1329 * struct vop_reclaim_args {
1330 * struct vnode *a_vp;
1334 afs_vop_reclaim(struct vop_reclaim_args *ap)
1336 /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1338 struct vnode *vp = ap->a_vp;
1339 struct vcache *avc = VTOAFS(vp);
1340 int haveGlock = ISAFS_GLOCK();
1341 int haveVlock = CheckLock(&afs_xvcache);
1346 ObtainWriteLock(&afs_xvcache, 901);
1347 #ifndef AFS_DISCON_ENV
1348 code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */
1350 /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1351 code = afs_FlushVS(avc);
1354 ReleaseWriteLock(&afs_xvcache);
1359 * XXX Pretend it worked, to prevent panic on shutdown
1360 * Garrett, please fix - Jim Rees
1363 printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1364 #ifdef AFS_FBSD60_ENV
1366 vnode_destroy_vobject(vp);
1371 #ifndef AFS_FBSD60_ENV
1374 struct vop_bmap_args /* {
1375 * struct vnode *a_vp;
1377 * struct vnode **a_vpp;
1384 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1387 *ap->a_vpp = ap->a_vp;
1389 if (ap->a_runp != NULL)
1391 if (ap->a_runb != NULL)
1399 afs_vop_strategy(ap)
1400 struct vop_strategy_args /* {
1406 error = afs_ustrategy(ap->a_bp);
1413 struct vop_print_args /* {
1414 * struct vnode *a_vp;
1417 register struct vnode *vp = ap->a_vp;
1418 register struct vcache *vc = VTOAFS(ap->a_vp);
1421 #ifdef AFS_FBSD50_ENV
1422 printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1423 (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1424 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1425 vc->execsOrWriters);
1427 printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1428 vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1429 (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1430 vc->execsOrWriters);
1432 printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1433 (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1434 (s & CMAPPED) ? " mapped" : "",
1435 (s & CVFlushed) ? " flush in progress" : "");
1441 * Advisory record locking support (fcntl() POSIX style)
1445 struct vop_advlock_args /* {
1446 * struct vnode *a_vp;
1449 * struct flock *a_fl;
1454 struct ucred cr = *osi_curcred();
1458 afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);