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>
51 #include <afs/sysincludes.h> /* Standard vendor system headers */
52 #include <afsincludes.h> /* Afs-based standard headers */
53 #include <afs/afs_stats.h> /* statistics */
54 #include <sys/malloc.h>
55 #include <sys/namei.h>
56 #include <sys/unistd.h>
57 #ifndef AFS_FBSD50_ENV
58 #include <vm/vm_zone.h>
60 #include <vm/vm_page.h>
61 #include <vm/vm_object.h>
62 #include <vm/vm_pager.h>
63 #include <vm/vnode_pager.h>
64 extern int afs_pbuf_freecnt;
67 static vop_access_t afs_vop_access;
68 static vop_advlock_t afs_vop_advlock;
69 static vop_close_t afs_vop_close;
70 static vop_create_t afs_vop_create;
71 static vop_fsync_t afs_vop_fsync;
72 static vop_getattr_t afs_vop_getattr;
73 static vop_getpages_t afs_vop_getpages;
74 static vop_inactive_t afs_vop_inactive;
75 static vop_ioctl_t afs_vop_ioctl;
76 static vop_link_t afs_vop_link;
77 static vop_lookup_t afs_vop_lookup;
78 static vop_mkdir_t afs_vop_mkdir;
79 static vop_mknod_t afs_vop_mknod;
80 static vop_open_t afs_vop_open;
81 static vop_pathconf_t afs_vop_pathconf;
82 static vop_poll_t afs_vop_poll;
83 static vop_print_t afs_vop_print;
84 static vop_putpages_t afs_vop_putpages;
85 static vop_read_t afs_vop_read;
86 static vop_readdir_t afs_vop_readdir;
87 static vop_readlink_t afs_vop_readlink;
88 static vop_reclaim_t afs_vop_reclaim;
89 static vop_remove_t afs_vop_remove;
90 static vop_rename_t afs_vop_rename;
91 static vop_rmdir_t afs_vop_rmdir;
92 static vop_setattr_t afs_vop_setattr;
93 static vop_strategy_t afs_vop_strategy;
94 static vop_symlink_t afs_vop_symlink;
95 static vop_write_t afs_vop_write;
96 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD80_ENV)
97 static vop_lock1_t afs_vop_lock;
98 static vop_unlock_t afs_vop_unlock;
99 static vop_islocked_t afs_vop_islocked;
102 struct vop_vector afs_vnodeops = {
103 .vop_default = &default_vnodeops,
104 .vop_access = afs_vop_access,
105 .vop_advlock = afs_vop_advlock,
106 .vop_close = afs_vop_close,
107 .vop_create = afs_vop_create,
108 .vop_fsync = afs_vop_fsync,
109 .vop_getattr = afs_vop_getattr,
110 .vop_getpages = afs_vop_getpages,
111 .vop_inactive = afs_vop_inactive,
112 .vop_ioctl = afs_vop_ioctl,
113 #if !defined(AFS_FBSD80_ENV)
114 /* removed at least temporarily (NFSv4 flux) */
115 .vop_lease = VOP_NULL,
117 .vop_link = afs_vop_link,
118 .vop_lookup = afs_vop_lookup,
119 .vop_mkdir = afs_vop_mkdir,
120 .vop_mknod = afs_vop_mknod,
121 .vop_open = afs_vop_open,
122 .vop_pathconf = afs_vop_pathconf,
123 .vop_poll = afs_vop_poll,
124 .vop_print = afs_vop_print,
125 .vop_putpages = afs_vop_putpages,
126 .vop_read = afs_vop_read,
127 .vop_readdir = afs_vop_readdir,
128 .vop_readlink = afs_vop_readlink,
129 .vop_reclaim = afs_vop_reclaim,
130 .vop_remove = afs_vop_remove,
131 .vop_rename = afs_vop_rename,
132 .vop_rmdir = afs_vop_rmdir,
133 .vop_setattr = afs_vop_setattr,
134 .vop_strategy = afs_vop_strategy,
135 .vop_symlink = afs_vop_symlink,
136 .vop_write = afs_vop_write,
137 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD80_ENV)
138 .vop_lock1 = afs_vop_lock,
139 .vop_unlock = afs_vop_unlock,
140 .vop_islocked = afs_vop_islocked,
144 #else /* AFS_FBSD60_ENV */
146 int afs_vop_lookup(struct vop_lookup_args *);
147 int afs_vop_create(struct vop_create_args *);
148 int afs_vop_mknod(struct vop_mknod_args *);
149 int afs_vop_open(struct vop_open_args *);
150 int afs_vop_close(struct vop_close_args *);
151 int afs_vop_access(struct vop_access_args *);
152 int afs_vop_getattr(struct vop_getattr_args *);
153 int afs_vop_setattr(struct vop_setattr_args *);
154 int afs_vop_read(struct vop_read_args *);
155 int afs_vop_write(struct vop_write_args *);
156 int afs_vop_getpages(struct vop_getpages_args *);
157 int afs_vop_putpages(struct vop_putpages_args *);
158 int afs_vop_ioctl(struct vop_ioctl_args *);
159 static int afs_vop_pathconf(struct vop_pathconf_args *);
160 int afs_vop_poll(struct vop_poll_args *);
161 #ifndef AFS_FBSD50_ENV
162 int afs_vop_mmap(struct vop_mmap_args *);
164 int afs_vop_fsync(struct vop_fsync_args *);
165 int afs_vop_remove(struct vop_remove_args *);
166 int afs_vop_link(struct vop_link_args *);
167 int afs_vop_rename(struct vop_rename_args *);
168 int afs_vop_mkdir(struct vop_mkdir_args *);
169 int afs_vop_rmdir(struct vop_rmdir_args *);
170 int afs_vop_symlink(struct vop_symlink_args *);
171 int afs_vop_readdir(struct vop_readdir_args *);
172 int afs_vop_readlink(struct vop_readlink_args *);
173 int afs_vop_inactive(struct vop_inactive_args *);
174 int afs_vop_reclaim(struct vop_reclaim_args *);
175 int afs_vop_bmap(struct vop_bmap_args *);
176 int afs_vop_strategy(struct vop_strategy_args *);
177 int afs_vop_print(struct vop_print_args *);
178 int afs_vop_advlock(struct vop_advlock_args *);
182 /* Global vfs data structures for AFS. */
183 vop_t **afs_vnodeop_p;
184 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
185 {&vop_default_desc, (vop_t *) vop_defaultop},
186 {&vop_access_desc, (vop_t *) afs_vop_access}, /* access */
187 {&vop_advlock_desc, (vop_t *) afs_vop_advlock}, /* advlock */
188 {&vop_bmap_desc, (vop_t *) afs_vop_bmap}, /* bmap */
189 #ifndef AFS_FBSD50_ENV
190 {&vop_bwrite_desc, (vop_t *) vop_stdbwrite},
192 {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */
193 {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject},
194 {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject},
195 {&vop_create_desc, (vop_t *) afs_vop_create}, /* create */
196 {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */
197 {&vop_getattr_desc, (vop_t *) afs_vop_getattr}, /* getattr */
198 {&vop_getpages_desc, (vop_t *) afs_vop_getpages}, /* read */
199 {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject},
200 {&vop_putpages_desc, (vop_t *) afs_vop_putpages}, /* write */
201 {&vop_inactive_desc, (vop_t *) afs_vop_inactive}, /* inactive */
202 {&vop_lease_desc, (vop_t *) vop_null},
203 {&vop_link_desc, (vop_t *) afs_vop_link}, /* link */
204 {&vop_lookup_desc, (vop_t *) afs_vop_lookup}, /* lookup */
205 {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */
206 {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */
207 #ifndef AFS_FBSD50_ENV
208 {&vop_mmap_desc, (vop_t *) afs_vop_mmap}, /* mmap */
210 {&vop_open_desc, (vop_t *) afs_vop_open}, /* open */
211 {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf}, /* pathconf */
212 {&vop_poll_desc, (vop_t *) afs_vop_poll}, /* select */
213 {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */
214 {&vop_read_desc, (vop_t *) afs_vop_read}, /* read */
215 {&vop_readdir_desc, (vop_t *) afs_vop_readdir}, /* readdir */
216 {&vop_readlink_desc, (vop_t *) afs_vop_readlink}, /* readlink */
217 {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim}, /* reclaim */
218 {&vop_remove_desc, (vop_t *) afs_vop_remove}, /* remove */
219 {&vop_rename_desc, (vop_t *) afs_vop_rename}, /* rename */
220 {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */
221 {&vop_setattr_desc, (vop_t *) afs_vop_setattr}, /* setattr */
222 {&vop_strategy_desc, (vop_t *) afs_vop_strategy}, /* strategy */
223 {&vop_symlink_desc, (vop_t *) afs_vop_symlink}, /* symlink */
224 {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */
225 {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */
226 /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */
227 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD90_ENV)
228 {&vop_lock1_desc, (vop_t *) afs_vop_lock}, /* lock */
229 {&vop_unlock_desc, (vop_t *) afs_vop_unlock}, /* unlock */
230 {&vop_islocked_desc, (vop_t *) afs_vop_islocked}, /* islocked */
234 struct vnodeopv_desc afs_vnodeop_opv_desc =
235 { &afs_vnodeop_p, afs_vnodeop_entries };
236 #endif /* AFS_FBSD60_ENV */
239 struct componentname *cnp = ap->a_cnp; \
241 MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
242 memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
243 name[cnp->cn_namelen] = '\0'
245 #define DROPNAME() FREE(name, M_TEMP)
247 /* This is a bit of a cheat... */
248 #ifdef AFS_FBSD50_ENV
252 #if defined(AFS_FBSD80_ENV)
253 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags))
254 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags))
255 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags))
257 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags, p))
258 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags, p))
259 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags, p))
262 #ifdef AFS_FBSD70_ENV
263 #ifndef AFS_FBSD80_ENV
264 /* From kern_lock.c */
265 #define COUNT(td, x) if ((td)) (td)->td_locks += (x)
266 #define LK_ALL (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE | \
267 LK_SHARE_NONZERO | LK_WAIT_NONZERO)
270 sharelock(struct thread *td, struct lock *lkp, int incr) {
271 lkp->lk_flags |= LK_SHARE_NONZERO;
272 lkp->lk_sharecount += incr;
278 * Standard lock, unlock and islocked functions.
282 struct vop_lock1_args /* {
290 struct vnode *vp = ap->a_vp;
291 struct lock *lkp = vp->v_vnlock;
293 #if 0 && defined(AFS_FBSD80_ENV) && !defined(UKERNEL)
294 afs_warn("afs_vop_lock: tid %d pid %d \"%s\"\n", curthread->td_tid,
295 curthread->td_proc->p_pid, curthread->td_name);
299 #ifdef AFS_FBSD80_ENV
300 return (_lockmgr_args(lkp, ap->a_flags, VI_MTX(vp),
301 LK_WMESG_DEFAULT, LK_PRIO_DEFAULT, LK_TIMO_DEFAULT,
302 ap->a_file, ap->a_line));
304 return (_lockmgr(lkp, ap->a_flags, VI_MTX(vp), ap->a_td, ap->a_file, ap->a_line));
311 struct vop_unlock_args /* {
317 struct vnode *vp = ap->a_vp;
318 struct lock *lkp = vp->v_vnlock;
320 #ifdef AFS_FBSD80_ENV
323 op = ((ap->a_flags) | LK_RELEASE) & LK_TYPE_MASK;
324 int glocked = ISAFS_GLOCK();
327 if ((op & (op - 1)) != 0) {
328 afs_warn("afs_vop_unlock: Shit.\n");
331 code = lockmgr(lkp, ap->a_flags | LK_RELEASE, VI_MTX(vp));
337 /* possibly in current code path where this
338 * forces trace, we should have had a (shared? not
339 * necessarily, see _lockmgr in kern_lock.c) lock
340 * and that's the real bug. but.
343 if ((lkp->lk_exclusivecount == 0) &&
344 (!(lkp->lk_flags & LK_SHARE_NONZERO))) {
345 sharelock(ap->a_td, lkp, 1);
348 return (lockmgr(lkp, ap->a_flags | LK_RELEASE, VI_MTX(vp),
356 struct vop_islocked_args /* {
358 struct thread *a_td; (not in 80)
361 #ifdef AFS_FBSD80_ENV
362 return (lockstatus(ap->a_vp->v_vnlock));
364 return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
370 * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf().
371 * We should know the correct answers to these questions with
372 * respect to the AFS protocol (which may differ from the UFS
373 * values) but for the moment this will do.
376 afs_vop_pathconf(struct vop_pathconf_args *ap)
381 switch (ap->a_name) {
383 *ap->a_retval = LINK_MAX;
386 *ap->a_retval = NAME_MAX;
389 *ap->a_retval = PATH_MAX;
392 *ap->a_retval = PIPE_BUF;
394 case _PC_CHOWN_RESTRICTED:
400 #ifdef _PC_ACL_EXTENDED
401 case _PC_ACL_EXTENDED:
404 case _PC_ACL_PATH_MAX:
408 #ifdef _PC_MAC_PRESENT
409 case _PC_MAC_PRESENT:
415 /* _PC_ASYNC_IO should have been handled by upper layers. */
416 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
426 #ifdef _PC_ALLOC_SIZE_MIN
427 case _PC_ALLOC_SIZE_MIN:
428 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
431 #ifdef _PC_FILESIZEBITS
432 case _PC_FILESIZEBITS:
433 *ap->a_retval = 32; /* XXX */
436 #ifdef _PC_REC_INCR_XFER_SIZE
437 case _PC_REC_INCR_XFER_SIZE:
438 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
440 case _PC_REC_MAX_XFER_SIZE:
441 *ap->a_retval = -1; /* means ``unlimited'' */
443 case _PC_REC_MIN_XFER_SIZE:
444 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
446 case _PC_REC_XFER_ALIGN:
447 *ap->a_retval = PAGE_SIZE;
450 #ifdef _PC_SYMLINK_MAX
451 case _PC_SYMLINK_MAX:
452 *ap->a_retval = MAXPATHLEN;
464 struct vop_lookup_args /* {
465 * struct vnodeop_desc * a_desc;
466 * struct vnode *a_dvp;
467 * struct vnode **a_vpp;
468 * struct componentname *a_cnp;
473 struct vnode *vp, *dvp;
474 register int flags = ap->a_cnp->cn_flags;
475 int lockparent; /* 1 => lockparent flag is set */
476 int wantparent; /* 1 => wantparent or lockparent flag */
477 struct thread *p = ap->a_cnp->cn_thread;
480 if (dvp->v_type != VDIR) {
481 #ifndef AFS_FBSD70_ENV
487 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT))
492 lockparent = flags & LOCKPARENT;
493 wantparent = flags & (LOCKPARENT | WANTPARENT);
495 #ifdef AFS_FBSD80_ENV
496 cnp->cn_flags |= MPSAFE; /* steel */
499 #ifndef AFS_FBSD70_ENV
500 if (flags & ISDOTDOT)
501 VOP_UNLOCK(dvp, 0, p);
505 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
509 if (flags & ISDOTDOT)
510 MA_VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
511 if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
512 && (flags & ISLASTCN) && error == ENOENT)
514 if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
515 cnp->cn_flags |= SAVENAME;
520 vp = AFSTOV(vcp); /* always get a node if no error */
522 /* The parent directory comes in locked. We unlock it on return
523 * unless the caller wants it left locked.
524 * we also always return the vnode locked. */
526 if (flags & ISDOTDOT) {
527 ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
528 /* always return the child locked */
529 if (lockparent && (flags & ISLASTCN)
530 && (error = ma_vn_lock(dvp, LK_EXCLUSIVE, p))) {
535 } else if (vp == dvp) {
536 /* they're the same; afs_lookup() already ref'ed the leaf.
537 * It came in locked, so we don't need to ref OR lock it */
539 if (!lockparent || !(flags & ISLASTCN)) {
540 #ifndef AFS_FBSD70_ENV /* 6 too? */
541 MA_VOP_UNLOCK(dvp, 0, p); /* done with parent. */
544 ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
545 /* always return the child locked */
549 if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
550 || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
551 cnp->cn_flags |= SAVENAME;
559 struct vop_create_args /* {
560 * struct vnode *a_dvp;
561 * struct vnode **a_vpp;
562 * struct componentname *a_cnp;
563 * struct vattr *a_vap;
568 register struct vnode *dvp = ap->a_dvp;
569 struct thread *p = ap->a_cnp->cn_thread;
574 afs_create(VTOAFS(dvp), name, ap->a_vap,
575 ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL,
576 ap->a_vap->va_mode, &vcp, cnp->cn_cred);
584 *ap->a_vpp = AFSTOV(vcp);
585 ma_vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
595 struct vop_mknod_args /* {
596 * struct vnode *a_dvp;
597 * struct vnode **a_vpp;
598 * struct componentname *a_cnp;
599 * struct vattr *a_vap;
607 validate_vops(struct vnode *vp, int after)
610 struct vnodeopv_entry_desc *this;
611 for (this = afs_vnodeop_entries; this->opve_op; this++) {
612 if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) {
614 printf("v_op %d ", after);
618 printf("For oper %d (%s), func is %p, not %p",
619 this->opve_op->vdesc_offset, this->opve_op->vdesc_name,
620 vp->v_op[this->opve_op->vdesc_offset], this->opve_impl);
628 struct vop_open_args /* {
629 * struct vnode *a_vp;
631 * struct ucred *a_cred;
632 * struct thread *a_td;
637 struct vcache *vc = VTOAFS(ap->a_vp);
640 error = afs_open(&vc, ap->a_mode, ap->a_cred);
642 if (AFSTOV(vc) != ap->a_vp)
643 panic("AFS open changed vnode!");
646 #ifdef AFS_FBSD60_ENV
647 vnode_create_vobject(ap->a_vp, vc->f.m.Length, ap->a_td);
649 osi_FlushPages(vc, ap->a_cred);
655 struct vop_close_args /* {
656 * struct vnode *a_vp;
658 * struct ucred *a_cred;
659 * struct thread *a_td;
663 struct vcache *avc = VTOAFS(ap->a_vp);
666 code = afs_close(avc, ap->a_fflag, ap->a_cred);
668 code = afs_close(avc, ap->a_fflag, afs_osi_credp);
669 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
676 struct vop_access_args /* {
677 * struct vnode *a_vp;
678 * accmode_t a_accmode;
679 * struct ucred *a_cred;
680 * struct thread *a_td;
685 #if defined(AFS_FBSD80_ENV)
686 code = afs_access(VTOAFS(ap->a_vp), ap->a_accmode, ap->a_cred);
688 code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
696 struct vop_getattr_args /* {
697 * struct vnode *a_vp;
698 * struct vattr *a_vap;
699 * struct ucred *a_cred;
704 code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
711 struct vop_setattr_args /* {
712 * struct vnode *a_vp;
713 * struct vattr *a_vap;
714 * struct ucred *a_cred;
719 code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
726 struct vop_read_args /* {
727 * struct vnode *a_vp;
730 * struct ucred *a_cred;
735 struct vcache *avc = VTOAFS(ap->a_vp);
737 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
738 code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
743 /* struct vop_getpages_args {
744 * struct vnode *a_vp;
748 * vm_oofset_t a_offset;
752 afs_vop_getpages(struct vop_getpages_args *ap)
755 int i, nextoff, size, toff, npages;
764 #ifdef AFS_FBSD50_ENV
769 if ((object = vp->v_object) == NULL) {
770 printf("afs_getpages: called with non-merged cache vnode??\n");
771 return VM_PAGER_ERROR;
773 npages = btoc(ap->a_count);
775 * If the requested page is partially valid, just return it and
776 * allow the pager to zero-out the blanks. Partially valid pages
777 * can only occur at the file EOF.
781 vm_page_t m = ap->a_m[ap->a_reqpage];
783 #ifdef AFS_FBSD50_ENV
784 VM_OBJECT_LOCK(object);
785 vm_page_lock_queues();
788 /* handled by vm_fault now */
789 /* vm_page_zero_invalid(m, TRUE); */
790 for (i = 0; i < npages; ++i) {
791 if (i != ap->a_reqpage)
792 vm_page_free(ap->a_m[i]);
794 #ifdef AFS_FBSD50_ENV
795 vm_page_unlock_queues();
796 VM_OBJECT_UNLOCK(object);
800 #ifdef AFS_FBSD50_ENV
801 vm_page_unlock_queues();
802 VM_OBJECT_UNLOCK(object);
805 bp = getpbuf(&afs_pbuf_freecnt);
807 kva = (vm_offset_t) bp->b_data;
808 pmap_qenter(kva, ap->a_m, npages);
809 #ifdef AFS_FBSD50_ENV
811 cnt.v_vnodepgsin += npages;
814 iov.iov_base = (caddr_t) kva;
815 iov.iov_len = ap->a_count;
818 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
819 uio.uio_resid = ap->a_count;
820 uio.uio_segflg = UIO_SYSSPACE;
821 uio.uio_rw = UIO_READ;
822 uio.uio_td = curthread;
825 osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
826 code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
828 pmap_qremove(kva, npages);
830 relpbuf(bp, &afs_pbuf_freecnt);
832 if (code && (uio.uio_resid == ap->a_count)) {
833 #ifdef AFS_FBSD50_ENV
834 VM_OBJECT_LOCK(object);
835 vm_page_lock_queues();
837 for (i = 0; i < npages; ++i) {
838 if (i != ap->a_reqpage)
839 vm_page_free(ap->a_m[i]);
841 #ifdef AFS_FBSD50_ENV
842 vm_page_unlock_queues();
843 VM_OBJECT_UNLOCK(object);
845 return VM_PAGER_ERROR;
848 size = ap->a_count - uio.uio_resid;
849 #ifdef AFS_FBSD50_ENV
850 VM_OBJECT_LOCK(object);
851 vm_page_lock_queues();
853 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
855 nextoff = toff + PAGE_SIZE;
858 m->flags &= ~PG_ZERO;
860 if (nextoff <= size) {
862 * Read operation filled an entire page
864 m->valid = VM_PAGE_BITS_ALL;
866 } else if (size > toff) {
868 * Read operation filled a partial page.
871 vm_page_set_validclean(m, 0, size - toff);
872 /* handled by vm_fault now */
873 /* vm_page_zero_invalid(m, TRUE); */
876 if (i != ap->a_reqpage) {
878 * Whether or not to leave the page activated is up in
879 * the air, but we should put the page on a page queue
880 * somewhere (it already is in the object). Result:
881 * It appears that emperical results show that
882 * deactivating pages is best.
886 * Just in case someone was asking for this page we
887 * now tell them that it is ok to use.
890 #if defined(AFS_FBSD70_ENV)
891 if (m->oflags & VPO_WANTED)
893 if (m->flags & PG_WANTED)
897 vm_page_deactivate(m);
904 #ifdef AFS_FBSD50_ENV
905 vm_page_unlock_queues();
906 VM_OBJECT_UNLOCK(object);
913 struct vop_write_args /* {
914 * struct vnode *a_vp;
917 * struct ucred *a_cred;
921 struct vcache *avc = VTOAFS(ap->a_vp);
923 osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
925 afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
931 * struct vop_putpages_args {
932 * struct vnode *a_vp;
937 * vm_oofset_t a_offset;
941 * All of the pages passed to us in ap->a_m[] are already marked as busy,
942 * so there is no additional locking required to set their flags. -GAW
945 afs_vop_putpages(struct vop_putpages_args *ap)
948 int i, size, npages, sync;
956 #ifdef AFS_FBSD50_ENV
962 /* Perhaps these two checks should just be KASSERTs instead... */
963 if (vp->v_object == NULL) {
964 printf("afs_putpages: called with non-merged cache vnode??\n");
965 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
967 if (vType(avc) != VREG) {
968 printf("afs_putpages: not VREG");
969 return VM_PAGER_ERROR; /* XXX I think this is insufficient */
971 npages = btoc(ap->a_count);
972 for (i = 0; i < npages; i++)
973 ap->a_rtvals[i] = VM_PAGER_AGAIN;
974 bp = getpbuf(&afs_pbuf_freecnt);
976 kva = (vm_offset_t) bp->b_data;
977 pmap_qenter(kva, ap->a_m, npages);
978 #ifdef AFS_FBSD50_ENV
980 cnt.v_vnodepgsout += ap->a_count;
983 iov.iov_base = (caddr_t) kva;
984 iov.iov_len = ap->a_count;
987 uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
988 uio.uio_resid = ap->a_count;
989 uio.uio_segflg = UIO_SYSSPACE;
990 uio.uio_rw = UIO_WRITE;
991 uio.uio_td = curthread;
993 if (ap->a_sync & VM_PAGER_PUT_SYNC)
995 /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
996 * sync |= IO_INVAL; */
999 code = afs_write(avc, &uio, sync, osi_curcred(), 0);
1002 pmap_qremove(kva, npages);
1003 relpbuf(bp, &afs_pbuf_freecnt);
1006 size = ap->a_count - uio.uio_resid;
1007 for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
1008 ap->a_rtvals[i] = VM_PAGER_OK;
1009 vm_page_undirty(ap->a_m[i]);
1012 return ap->a_rtvals[0];
1017 struct vop_ioctl_args /* {
1018 * struct vnode *a_vp;
1022 * struct ucred *a_cred;
1023 * struct thread *a_td;
1026 struct vcache *tvc = VTOAFS(ap->a_vp);
1029 /* in case we ever get in here... */
1031 AFS_STATCNT(afs_ioctl);
1032 if (((ap->a_command >> 8) & 0xff) == 'V') {
1033 /* This is a VICEIOCTL call */
1035 error = HandleIoctl(tvc, ap->a_command, ap->a_data);
1039 /* No-op call; just return. */
1047 struct vop_poll_args /* {
1048 * struct vnode *a_vp;
1050 * struct ucred *a_cred;
1051 * struct thread *td;
1055 * We should really check to see if I/O is possible.
1063 * NB Currently unsupported.
1068 struct vop_mmap_args /* {
1069 * struct vnode *a_vp;
1071 * struct ucred *a_cred;
1072 * struct thread *td;
1080 struct vop_fsync_args /* {
1081 * struct vnode *a_vp;
1083 * struct thread *td;
1087 register struct vnode *vp = ap->a_vp;
1090 /*vflushbuf(vp, wait); */
1091 #ifdef AFS_FBSD60_ENV
1092 error = afs_fsync(VTOAFS(vp), ap->a_td->td_ucred);
1095 error = afs_fsync(VTOAFS(vp), ap->a_cred);
1097 error = afs_fsync(VTOAFS(vp), afs_osi_credp);
1105 struct vop_remove_args /* {
1106 * struct vnode *a_dvp;
1107 * struct vnode *a_vp;
1108 * struct componentname *a_cnp;
1112 register struct vnode *vp = ap->a_vp;
1113 register struct vnode *dvp = ap->a_dvp;
1117 error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
1126 struct vop_link_args /* {
1127 * struct vnode *a_vp;
1128 * struct vnode *a_tdvp;
1129 * struct componentname *a_cnp;
1133 register struct vnode *dvp = ap->a_tdvp;
1134 register struct vnode *vp = ap->a_vp;
1135 struct thread *p = ap->a_cnp->cn_thread;
1138 if (dvp->v_mount != vp->v_mount) {
1142 if (vp->v_type == VDIR) {
1146 if ((error = ma_vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
1150 error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
1153 MA_VOP_UNLOCK(vp, 0, p);
1161 struct vop_rename_args /* {
1162 * struct vnode *a_fdvp;
1163 * struct vnode *a_fvp;
1164 * struct componentname *a_fcnp;
1165 * struct vnode *a_tdvp;
1166 * struct vnode *a_tvp;
1167 * struct componentname *a_tcnp;
1171 struct componentname *fcnp = ap->a_fcnp;
1173 struct componentname *tcnp = ap->a_tcnp;
1175 struct vnode *tvp = ap->a_tvp;
1176 register struct vnode *tdvp = ap->a_tdvp;
1177 struct vnode *fvp = ap->a_fvp;
1178 register struct vnode *fdvp = ap->a_fdvp;
1179 struct thread *p = fcnp->cn_thread;
1182 * Check for cross-device rename.
1184 if ((fvp->v_mount != tdvp->v_mount)
1185 || (tvp && (fvp->v_mount != tvp->v_mount))) {
1199 * if fvp == tvp, we're just removing one name of a pair of
1200 * directory entries for the same element. convert call into rename.
1201 ( (pinched from FreeBSD 4.4's ufs_rename())
1205 if (fvp->v_type == VDIR) {
1210 /* Release destination completely. */
1214 /* Delete source. */
1217 fcnp->cn_flags &= ~MODMASK;
1218 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1219 if ((fcnp->cn_flags & SAVESTART) == 0)
1220 panic("afs_rename: lost from startdir");
1221 fcnp->cn_nameiop = DELETE;
1223 error = relookup(fdvp, &fvp, fcnp);
1230 error = VOP_REMOVE(fdvp, fvp, fcnp);
1238 if ((error = ma_vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1241 MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1242 memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1243 fname[fcnp->cn_namelen] = '\0';
1244 MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1245 memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1246 tname[tcnp->cn_namelen] = '\0';
1250 /* XXX use "from" or "to" creds? NFS uses "to" creds */
1252 afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1255 FREE(fname, M_TEMP);
1256 FREE(tname, M_TEMP);
1270 struct vop_mkdir_args /* {
1271 * struct vnode *a_dvp;
1272 * struct vnode **a_vpp;
1273 * struct componentname *a_cnp;
1274 * struct vattr *a_vap;
1277 register struct vnode *dvp = ap->a_dvp;
1278 register struct vattr *vap = ap->a_vap;
1281 struct thread *p = ap->a_cnp->cn_thread;
1285 if ((cnp->cn_flags & HASBUF) == 0)
1286 panic("afs_vop_mkdir: no name");
1289 error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1296 *ap->a_vpp = AFSTOV(vcp);
1297 ma_vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1306 struct vop_rmdir_args /* {
1307 * struct vnode *a_dvp;
1308 * struct vnode *a_vp;
1309 * struct componentname *a_cnp;
1313 register struct vnode *dvp = ap->a_dvp;
1317 error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1323 /* struct vop_symlink_args {
1324 * struct vnode *a_dvp;
1325 * struct vnode **a_vpp;
1326 * struct componentname *a_cnp;
1327 * struct vattr *a_vap;
1332 afs_vop_symlink(struct vop_symlink_args *ap)
1335 struct vnode *newvp;
1346 afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1348 error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1350 newvp = AFSTOV(vcp);
1351 ma_vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1356 *(ap->a_vpp) = newvp;
1362 struct vop_readdir_args /* {
1363 * struct vnode *a_vp;
1364 * struct uio *a_uio;
1365 * struct ucred *a_cred;
1367 * u_long *a_cookies;
1373 /* printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1375 off = ap->a_uio->uio_offset;
1378 afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1380 if (!error && ap->a_ncookies != NULL) {
1381 struct uio *uio = ap->a_uio;
1382 const struct dirent *dp, *dp_start, *dp_end;
1384 u_long *cookies, *cookiep;
1386 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1387 panic("afs_readdir: burned cookies");
1388 dp = (const struct dirent *)
1389 ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1391 dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1392 for (dp_start = dp, ncookies = 0; dp < dp_end;
1393 dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1396 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1398 for (dp = dp_start, cookiep = cookies; dp < dp_end;
1399 dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1400 off += dp->d_reclen;
1403 *ap->a_cookies = cookies;
1404 *ap->a_ncookies = ncookies;
1411 afs_vop_readlink(ap)
1412 struct vop_readlink_args /* {
1413 * struct vnode *a_vp;
1414 * struct uio *a_uio;
1415 * struct ucred *a_cred;
1419 /* printf("readlink %x\n", ap->a_vp);*/
1421 error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1426 extern int prtactive;
1429 afs_vop_inactive(ap)
1430 struct vop_inactive_args /* {
1431 * struct vnode *a_vp;
1432 * struct thread *td;
1435 register struct vnode *vp = ap->a_vp;
1437 if (prtactive && vp->v_usecount != 0)
1438 vprint("afs_vop_inactive(): pushing active", vp);
1441 afs_InactiveVCache(VTOAFS(vp), 0); /* decrs ref counts */
1443 #ifndef AFS_FBSD80_ENV
1444 MA_VOP_UNLOCK(vp, 0, ap->a_p);
1450 * struct vop_reclaim_args {
1451 * struct vnode *a_vp;
1455 afs_vop_reclaim(struct vop_reclaim_args *ap)
1457 /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1459 struct vnode *vp = ap->a_vp;
1460 struct vcache *avc = VTOAFS(vp);
1461 int haveGlock = ISAFS_GLOCK();
1462 int haveVlock = CheckLock(&afs_xvcache);
1467 ObtainWriteLock(&afs_xvcache, 901);
1468 #ifndef AFS_DISCON_ENV
1469 code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */
1471 /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1472 code = afs_FlushVS(avc);
1475 ReleaseWriteLock(&afs_xvcache);
1480 * XXX Pretend it worked, to prevent panic on shutdown
1481 * Garrett, please fix - Jim Rees
1484 printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1486 /* basically, it must not fail */
1487 vnode_destroy_vobject(vp);
1493 #ifndef AFS_FBSD60_ENV
1496 struct vop_bmap_args /* {
1497 * struct vnode *a_vp;
1499 * struct vnode **a_vpp;
1506 *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1509 *ap->a_vpp = ap->a_vp;
1511 if (ap->a_runp != NULL)
1513 if (ap->a_runb != NULL)
1521 afs_vop_strategy(ap)
1522 struct vop_strategy_args /* {
1528 error = afs_ustrategy(ap->a_bp, osi_curcred());
1535 struct vop_print_args /* {
1536 * struct vnode *a_vp;
1539 register struct vnode *vp = ap->a_vp;
1540 register struct vcache *vc = VTOAFS(ap->a_vp);
1541 int s = vc->f.states;
1543 printf("tag %s, fid: %d.%d.%d.%d, opens %d, writers %d", vp->v_tag,
1544 (int)vc->f.fid.Cell, (u_int) vc->f.fid.Fid.Volume,
1545 (u_int) vc->f.fid.Fid.Vnode, (u_int) vc->f.fid.Fid.Unique, vc->opens,
1546 vc->execsOrWriters);
1547 printf("\n states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1548 (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1549 (s & CMAPPED) ? " mapped" : "",
1550 (s & CVFlushed) ? " flush in progress" : "");
1556 * Advisory record locking support (fcntl() POSIX style)
1560 struct vop_advlock_args /* {
1561 * struct vnode *a_vp;
1564 * struct flock *a_fl;
1569 struct ucred cr = *osi_curcred();
1573 afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);