0676fe85e2cd33a08a3df1de2f1c47f71c24cb35
[openafs.git] / src / afs / FBSD / osi_vnodeops.c
1 /*
2  * A large chunk of this file appears to be copied directly from
3  * sys/nfsclient/nfs_bio.c, which has the following license:
4  */
5 /*
6  * Copyright (c) 1989, 1993
7  *      The Regents of the University of California.  All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Rick Macklem at The University of Guelph.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
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.
27  *
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
38  * SUCH DAMAGE.
39  *
40  *      @(#)nfs_bio.c   8.9 (Berkeley) 3/30/95
41  */
42 /*
43  * Pursuant to a statement of U.C. Berkeley dated 1999-07-22, this license
44  * is amended to drop clause (3) above.
45  */
46
47 #include <afsconfig.h>
48 #include <afs/param.h>
49
50 RCSID
51     ("$Header$");
52
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>
61 #endif
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;
67
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 *);
85 #endif
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 *);
104
105
106
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},
116 #endif
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 */
134 #endif
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 */
152     {NULL, NULL}
153 };
154 struct vnodeopv_desc afs_vnodeop_opv_desc =
155     { &afs_vnodeop_p, afs_vnodeop_entries };
156
157 #define GETNAME()       \
158     struct componentname *cnp = ap->a_cnp; \
159     char *name; \
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'
163
164 #define DROPNAME() FREE(name, M_TEMP)
165
166 /* This is a bit of a cheat... */
167 #ifdef AFS_FBSD50_ENV
168 #define a_p a_td
169 #endif
170
171 /*
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.
176  */
177 static int
178 afs_vop_pathconf(struct vop_pathconf_args *ap)
179 {
180         int error;
181
182         error = 0;
183         switch (ap->a_name) {
184         case _PC_LINK_MAX:
185                 *ap->a_retval = LINK_MAX;
186                 break;
187         case _PC_NAME_MAX:
188                 *ap->a_retval = NAME_MAX;
189                 break;
190         case _PC_PATH_MAX:
191                 *ap->a_retval = PATH_MAX;
192                 break;
193         case _PC_PIPE_BUF:
194                 *ap->a_retval = PIPE_BUF;
195                 break;
196         case _PC_CHOWN_RESTRICTED:
197                 *ap->a_retval = 1;
198                 break;
199         case _PC_NO_TRUNC:
200                 *ap->a_retval = 1;
201                 break;
202 #ifdef _PC_ACL_EXTENDED
203         case _PC_ACL_EXTENDED:
204                 *ap->a_retval = 0;
205                 break;
206         case _PC_ACL_PATH_MAX:
207                 *ap->a_retval = 3;
208                 break;
209 #endif
210 #ifdef _PC_MAC_PRESENT
211         case _PC_MAC_PRESENT:
212                 *ap->a_retval = 0;
213                 break;
214 #endif
215 #ifdef _PC_ASYNC_IO
216         case _PC_ASYNC_IO:
217                 /* _PC_ASYNC_IO should have been handled by upper layers. */
218                 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
219                 error = EINVAL;
220                 break;
221         case _PC_PRIO_IO:
222                 *ap->a_retval = 0;
223                 break;
224         case _PC_SYNC_IO:
225                 *ap->a_retval = 0;
226                 break;
227 #endif
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;
231                 break;
232 #endif
233 #ifdef _PC_FILESIZEBITS
234         case _PC_FILESIZEBITS:
235                 *ap->a_retval = 32; /* XXX */
236                 break;
237 #endif
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;
241                 break;
242         case _PC_REC_MAX_XFER_SIZE:
243                 *ap->a_retval = -1; /* means ``unlimited'' */
244                 break;
245         case _PC_REC_MIN_XFER_SIZE:
246                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
247                 break;
248         case _PC_REC_XFER_ALIGN:
249                 *ap->a_retval = PAGE_SIZE;
250                 break;
251 #endif
252 #ifdef _PC_SYMLINK_MAX
253         case _PC_SYMLINK_MAX:
254                 *ap->a_retval = MAXPATHLEN;
255                 break;
256 #endif
257         default:
258                 error = EINVAL;
259                 break;
260         }
261         return (error);
262 }
263
264 int
265 afs_vop_lookup(ap)
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;
271                                  * } */ *ap;
272 {
273     int error;
274     struct vcache *vcp;
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;
281 #else
282     struct proc *p = ap->a_cnp->cn_proc;
283 #endif
284     GETNAME();
285
286     lockparent = flags & LOCKPARENT;
287     wantparent = flags & (LOCKPARENT | WANTPARENT);
288
289     if (ap->a_dvp->v_type != VDIR) {
290         *ap->a_vpp = 0;
291         DROPNAME();
292         return ENOTDIR;
293     }
294     dvp = ap->a_dvp;
295     if (flags & ISDOTDOT)
296         VOP_UNLOCK(dvp, 0, p);
297     AFS_GLOCK();
298     error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
299     AFS_GUNLOCK();
300     if (error) {
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)
305             error = EJUSTRETURN;
306         if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
307             cnp->cn_flags |= SAVENAME;
308         DROPNAME();
309         *ap->a_vpp = 0;
310         return (error);
311     }
312     vp = AFSTOV(vcp);           /* always get a node if no error */
313
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. */
317
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))) {
323             vput(vp);
324             DROPNAME();
325             return (error);
326         }
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 */
330     } else {
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 */
335     }
336     *ap->a_vpp = vp;
337
338     if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
339         || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
340         cnp->cn_flags |= SAVENAME;
341
342     DROPNAME();
343     return error;
344 }
345
346 int
347 afs_vop_create(ap)
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;
353                                  * } */ *ap;
354 {
355     int error = 0;
356     struct vcache *vcp;
357     register struct vnode *dvp = ap->a_dvp;
358 #ifdef AFS_FBSD50_ENV
359     struct thread *p = ap->a_cnp->cn_thread;
360 #else
361     struct proc *p = ap->a_cnp->cn_proc;
362 #endif
363     GETNAME();
364
365     AFS_GLOCK();
366     error =
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);
370     AFS_GUNLOCK();
371     if (error) {
372         DROPNAME();
373         return (error);
374     }
375
376     if (vcp) {
377         *ap->a_vpp = AFSTOV(vcp);
378         vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
379     } else
380         *ap->a_vpp = 0;
381
382     DROPNAME();
383     return error;
384 }
385
386 int
387 afs_vop_mknod(ap)
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;
393                                  * } */ *ap;
394 {
395     return (ENODEV);
396 }
397
398 #if 0
399 static int
400 validate_vops(struct vnode *vp, int after)
401 {
402     int ret = 0;
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) {
406             if (!ret) {
407                 printf("v_op %d ", after);
408                 vprint("check", vp);
409             }
410             ret = 1;
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);
414         }
415     }
416     return ret;
417 }
418 #endif
419 int
420 afs_vop_open(ap)
421      struct vop_open_args       /* {
422                                  * struct vnode *a_vp;
423                                  * int  a_mode;
424                                  * struct ucred *a_cred;
425                                  * struct proc *a_p;
426                                  * } */ *ap;
427 {
428     int error;
429     int bad;
430     struct vcache *vc = VTOAFS(ap->a_vp);
431     bad = 0;
432     AFS_GLOCK();
433     error = afs_open(&vc, ap->a_mode, ap->a_cred);
434 #ifdef DIAGNOSTIC
435     if (AFSTOV(vc) != ap->a_vp)
436         panic("AFS open changed vnode!");
437 #endif
438     afs_BozonLock(&vc->pvnLock, vc);
439     osi_FlushPages(vc, ap->a_cred);
440     afs_BozonUnlock(&vc->pvnLock, vc);
441     AFS_GUNLOCK();
442     return error;
443 }
444
445 int
446 afs_vop_close(ap)
447      struct vop_close_args      /* {
448                                  * struct vnode *a_vp;
449                                  * int  a_fflag;
450                                  * struct ucred *a_cred;
451                                  * struct proc *a_p;
452                                  * } */ *ap;
453 {
454     int code;
455     struct vcache *avc = VTOAFS(ap->a_vp);
456     AFS_GLOCK();
457     if (ap->a_cred)
458         code = afs_close(avc, ap->a_fflag, ap->a_cred);
459     else
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);
464     AFS_GUNLOCK();
465     return code;
466 }
467
468 int
469 afs_vop_access(ap)
470      struct vop_access_args     /* {
471                                  * struct vnode *a_vp;
472                                  * int  a_mode;
473                                  * struct ucred *a_cred;
474                                  * struct proc *a_p;
475                                  * } */ *ap;
476 {
477     int code;
478     AFS_GLOCK();
479     code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
480     AFS_GUNLOCK();
481     return code;
482 }
483
484 int
485 afs_vop_getattr(ap)
486      struct vop_getattr_args    /* {
487                                  * struct vnode *a_vp;
488                                  * struct vattr *a_vap;
489                                  * struct ucred *a_cred;
490                                  * struct proc *a_p;
491                                  * } */ *ap;
492 {
493     int code;
494     AFS_GLOCK();
495     code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
496     AFS_GUNLOCK();
497     return code;
498 }
499
500 int
501 afs_vop_setattr(ap)
502      struct vop_setattr_args    /* {
503                                  * struct vnode *a_vp;
504                                  * struct vattr *a_vap;
505                                  * struct ucred *a_cred;
506                                  * struct proc *a_p;
507                                  * } */ *ap;
508 {
509     int code;
510     AFS_GLOCK();
511     code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
512     AFS_GUNLOCK();
513     return code;
514 }
515
516 int
517 afs_vop_read(ap)
518      struct vop_read_args       /* {
519                                  * struct vnode *a_vp;
520                                  * struct uio *a_uio;
521                                  * int a_ioflag;
522                                  * struct ucred *a_cred;
523                                  * 
524                                  * } */ *ap;
525 {
526     int code;
527     struct vcache *avc = VTOAFS(ap->a_vp);
528     AFS_GLOCK();
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);
533     AFS_GUNLOCK();
534     return code;
535 }
536
537 /* struct vop_getpages_args {
538  *      struct vnode *a_vp;
539  *      vm_page_t *a_m;
540  *      int a_count;
541  *      int a_reqpage;
542  *      vm_oofset_t a_offset;
543  * };
544  */
545 int
546 afs_vop_getpages(struct vop_getpages_args *ap)
547 {
548     int code;
549     int i, nextoff, size, toff, npages;
550     struct uio uio;
551     struct iovec iov;
552     struct buf *bp;
553     vm_offset_t kva;
554     vm_object_t object;
555     struct vnode *vp;
556     struct vcache *avc;
557
558 #ifdef AFS_FBSD50_ENV
559     GIANT_REQUIRED;
560 #endif
561     vp = ap->a_vp;
562     avc = VTOAFS(vp);
563     if ((object = vp->v_object) == NULL) {
564         printf("afs_getpages: called with non-merged cache vnode??\n");
565         return VM_PAGER_ERROR;
566     }
567     npages = btoc(ap->a_count);
568     /*
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.
572      */
573
574     {
575         vm_page_t m = ap->a_m[ap->a_reqpage];
576
577 #ifdef AFS_FBSD50_ENV
578         VM_OBJECT_LOCK(object);
579         vm_page_lock_queues();
580 #endif
581         if (m->valid != 0) {
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]);
587             }
588 #ifdef AFS_FBSD50_ENV
589             vm_page_unlock_queues();
590             VM_OBJECT_UNLOCK(object);
591 #endif
592             return (0);
593         }
594 #ifdef AFS_FBSD50_ENV
595         vm_page_unlock_queues();
596         VM_OBJECT_UNLOCK(object);
597 #endif
598     }
599     bp = getpbuf(&afs_pbuf_freecnt);
600
601     kva = (vm_offset_t) bp->b_data;
602     pmap_qenter(kva, ap->a_m, npages);
603 #ifdef AFS_FBSD50_ENV
604     cnt.v_vnodein++;
605     cnt.v_vnodepgsin += npages;
606 #endif
607
608     iov.iov_base = (caddr_t) kva;
609     iov.iov_len = ap->a_count;
610     uio.uio_iov = &iov;
611     uio.uio_iovcnt = 1;
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;
618 #else
619     uio.uio_procp = curproc;
620 #endif
621
622     AFS_GLOCK();
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);
627     AFS_GUNLOCK();
628     pmap_qremove(kva, npages);
629
630     relpbuf(bp, &afs_pbuf_freecnt);
631
632     if (code && (uio.uio_resid == ap->a_count)) {
633 #ifdef AFS_FBSD50_ENV
634         VM_OBJECT_LOCK(object);
635         vm_page_lock_queues();
636 #endif
637         for (i = 0; i < npages; ++i) {
638             if (i != ap->a_reqpage)
639                 vm_page_free(ap->a_m[i]);
640         }
641 #ifdef AFS_FBSD50_ENV
642         vm_page_unlock_queues();
643         VM_OBJECT_UNLOCK(object);
644 #endif
645         return VM_PAGER_ERROR;
646     }
647
648     size = ap->a_count - uio.uio_resid;
649 #ifdef AFS_FBSD50_ENV
650     VM_OBJECT_LOCK(object);
651     vm_page_lock_queues();
652 #endif
653     for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
654         vm_page_t m;
655         nextoff = toff + PAGE_SIZE;
656         m = ap->a_m[i];
657
658         m->flags &= ~PG_ZERO;
659
660         if (nextoff <= size) {
661             /*
662              * Read operation filled an entire page
663              */
664             m->valid = VM_PAGE_BITS_ALL;
665             vm_page_undirty(m);
666         } else if (size > toff) {
667             /*
668              * Read operation filled a partial page.
669              */
670             m->valid = 0;
671             vm_page_set_validclean(m, 0, size - toff);
672             /* handled by vm_fault now        */
673             /* vm_page_zero_invalid(m, TRUE); */
674         }
675
676         if (i != ap->a_reqpage) {
677             /*
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.
683              */
684
685             /*
686              * Just in case someone was asking for this page we
687              * now tell them that it is ok to use.
688              */
689             if (!code) {
690                 if (m->flags & PG_WANTED)
691                     vm_page_activate(m);
692                 else
693                     vm_page_deactivate(m);
694                 vm_page_wakeup(m);
695             } else {
696                 vm_page_free(m);
697             }
698         }
699     }
700 #ifdef AFS_FBSD50_ENV
701     vm_page_unlock_queues();
702     VM_OBJECT_UNLOCK(object);
703 #endif
704     return 0;
705 }
706
707 int
708 afs_vop_write(ap)
709      struct vop_write_args      /* {
710                                  * struct vnode *a_vp;
711                                  * struct uio *a_uio;
712                                  * int a_ioflag;
713                                  * struct ucred *a_cred;
714                                  * } */ *ap;
715 {
716     int code;
717     struct vcache *avc = VTOAFS(ap->a_vp);
718     AFS_GLOCK();
719     afs_BozonLock(&avc->pvnLock, avc);
720     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
721     code =
722         afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
723     afs_BozonUnlock(&avc->pvnLock, avc);
724     AFS_GUNLOCK();
725     return code;
726 }
727
728 /*-
729  * struct vop_putpages_args {
730  *      struct vnode *a_vp;
731  *      vm_page_t *a_m;
732  *      int a_count;
733  *      int a_sync;
734  *      int *a_rtvals;
735  *      vm_oofset_t a_offset;
736  * };
737  */
738 /*
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
741  */
742 int
743 afs_vop_putpages(struct vop_putpages_args *ap)
744 {
745     int code;
746     int i, size, npages, sync;
747     struct uio uio;
748     struct iovec iov;
749     struct buf *bp;
750     vm_offset_t kva;
751     struct vnode *vp;
752     struct vcache *avc;
753
754 #ifdef AFS_FBSD50_ENV
755     GIANT_REQUIRED;
756 #endif
757
758     vp = ap->a_vp;
759     avc = VTOAFS(vp);
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 */
764     }
765     if (vType(avc) != VREG) {
766         printf("afs_putpages: not VREG");
767         return VM_PAGER_ERROR;  /* XXX I think this is insufficient */
768     }
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);
773
774     kva = (vm_offset_t) bp->b_data;
775     pmap_qenter(kva, ap->a_m, npages);
776 #ifdef AFS_FBSD50_ENV
777     cnt.v_vnodeout++;
778     cnt.v_vnodepgsout += ap->a_count;
779 #endif
780
781     iov.iov_base = (caddr_t) kva;
782     iov.iov_len = ap->a_count;
783     uio.uio_iov = &iov;
784     uio.uio_iovcnt = 1;
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;
791 #else
792     uio.uio_procp = curproc;
793 #endif
794     sync = IO_VMIO;
795     if (ap->a_sync & VM_PAGER_PUT_SYNC)
796         sync |= IO_SYNC;
797     /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
798      * sync |= IO_INVAL; */
799
800     AFS_GLOCK();
801     afs_BozonLock(&avc->pvnLock, avc);
802     code = afs_write(avc, &uio, sync, osi_curcred(), 0);
803     afs_BozonUnlock(&avc->pvnLock, avc);
804     AFS_GUNLOCK();
805
806     pmap_qremove(kva, npages);
807     relpbuf(bp, &afs_pbuf_freecnt);
808
809     if (!code) {
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]);
814         }
815     }
816     return ap->a_rtvals[0];
817 }
818
819 int
820 afs_vop_ioctl(ap)
821      struct vop_ioctl_args      /* {
822                                  * struct vnode *a_vp;
823                                  * int  a_command;
824                                  * caddr_t  a_data;
825                                  * int  a_fflag;
826                                  * struct ucred *a_cred;
827                                  * struct proc *a_p;
828                                  * } */ *ap;
829 {
830     struct vcache *tvc = VTOAFS(ap->a_vp);
831     int error = 0;
832
833     /* in case we ever get in here... */
834
835     AFS_STATCNT(afs_ioctl);
836     if (((ap->a_command >> 8) & 0xff) == 'V') {
837         /* This is a VICEIOCTL call */
838         AFS_GLOCK();
839         error = HandleIoctl(tvc, NULL /*Not used */ ,
840                             ap->a_command, ap->a_data);
841         AFS_GUNLOCK();
842         return (error);
843     } else {
844         /* No-op call; just return. */
845         return (ENOTTY);
846     }
847 }
848
849 /* ARGSUSED */
850 int
851 afs_vop_poll(ap)
852      struct vop_poll_args       /* {
853                                  * struct vnode *a_vp;
854                                  * int  a_events;
855                                  * struct ucred *a_cred;
856                                  * struct proc *a_p;
857                                  * } */ *ap;
858 {
859     /*
860      * We should really check to see if I/O is possible.
861      */
862     return (1);
863 }
864
865 /*
866  * Mmap a file
867  *
868  * NB Currently unsupported.
869  */
870 /* ARGSUSED */
871 int
872 afs_vop_mmap(ap)
873      struct vop_mmap_args       /* {
874                                  * struct vnode *a_vp;
875                                  * int  a_fflags;
876                                  * struct ucred *a_cred;
877                                  * struct proc *a_p;
878                                  * } */ *ap;
879 {
880     return (EINVAL);
881 }
882
883 int
884 afs_vop_fsync(ap)
885      struct vop_fsync_args      /* {
886                                  * struct vnode *a_vp;
887                                  * struct ucred *a_cred;
888                                  * int a_waitfor;
889                                  * struct proc *a_p;
890                                  * } */ *ap;
891 {
892     int error;
893     register struct vnode *vp = ap->a_vp;
894
895     AFS_GLOCK();
896     /*vflushbuf(vp, wait); */
897     if (ap->a_cred)
898         error = afs_fsync(VTOAFS(vp), ap->a_cred);
899     else
900         error = afs_fsync(VTOAFS(vp), afs_osi_credp);
901     AFS_GUNLOCK();
902     return error;
903 }
904
905 int
906 afs_vop_remove(ap)
907      struct vop_remove_args     /* {
908                                  * struct vnode *a_dvp;
909                                  * struct vnode *a_vp;
910                                  * struct componentname *a_cnp;
911                                  * } */ *ap;
912 {
913     int error = 0;
914     register struct vnode *vp = ap->a_vp;
915     register struct vnode *dvp = ap->a_dvp;
916
917     GETNAME();
918     AFS_GLOCK();
919     error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
920     AFS_GUNLOCK();
921     cache_purge(vp);
922     DROPNAME();
923     return error;
924 }
925
926 int
927 afs_vop_link(ap)
928      struct vop_link_args       /* {
929                                  * struct vnode *a_vp;
930                                  * struct vnode *a_tdvp;
931                                  * struct componentname *a_cnp;
932                                  * } */ *ap;
933 {
934     int error = 0;
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;
939 #else
940     struct proc *p = ap->a_cnp->cn_proc;
941 #endif
942
943     GETNAME();
944     if (dvp->v_mount != vp->v_mount) {
945         error = EXDEV;
946         goto out;
947     }
948     if (vp->v_type == VDIR) {
949         error = EISDIR;
950         goto out;
951     }
952     if ((error = vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
953         goto out;
954     }
955     AFS_GLOCK();
956     error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
957     AFS_GUNLOCK();
958     if (dvp != vp)
959         VOP_UNLOCK(vp, 0, p);
960   out:
961     DROPNAME();
962     return error;
963 }
964
965 int
966 afs_vop_rename(ap)
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;
974                                  * } */ *ap;
975 {
976     int error = 0;
977     struct componentname *fcnp = ap->a_fcnp;
978     char *fname;
979     struct componentname *tcnp = ap->a_tcnp;
980     char *tname;
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;
987 #else
988     struct proc *p = fcnp->cn_proc;
989 #endif
990
991     /*
992      * Check for cross-device rename.
993      */
994     if ((fvp->v_mount != tdvp->v_mount)
995         || (tvp && (fvp->v_mount != tvp->v_mount))) {
996         error = EXDEV;
997       abortit:
998         if (tdvp == tvp)
999             vrele(tdvp);
1000         else
1001             vput(tdvp);
1002         if (tvp)
1003             vput(tvp);
1004         vrele(fdvp);
1005         vrele(fvp);
1006         return (error);
1007     }
1008     /*
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())
1012      
1013      */
1014     if (fvp == tvp) {
1015         if (fvp->v_type == VDIR) {
1016             error = EINVAL;
1017             goto abortit;
1018         }
1019
1020         /* Release destination completely. */
1021         vput(tdvp);
1022         vput(tvp);
1023
1024         /* Delete source. */
1025         vrele(fdvp);
1026         vrele(fvp);
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;
1032         VREF(fdvp);
1033         error = relookup(fdvp, &fvp, fcnp);
1034         if (error == 0)
1035             vrele(fdvp);
1036         if (fvp == NULL) {
1037             return (ENOENT);
1038         }
1039
1040         error = VOP_REMOVE(fdvp, fvp, fcnp);
1041         if (fdvp == fvp)
1042             vrele(fdvp);
1043         else
1044             vput(fdvp);
1045         vput(fvp);
1046         return (error);
1047     }
1048     if ((error = vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1049         goto abortit;
1050
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';
1057
1058
1059     AFS_GLOCK();
1060     /* XXX use "from" or "to" creds? NFS uses "to" creds */
1061     error =
1062         afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1063     AFS_GUNLOCK();
1064
1065     FREE(fname, M_TEMP);
1066     FREE(tname, M_TEMP);
1067     if (tdvp == tvp)
1068         vrele(tdvp);
1069     else
1070         vput(tdvp);
1071     if (tvp)
1072         vput(tvp);
1073     vrele(fdvp);
1074     vput(fvp);
1075     return error;
1076 }
1077
1078 int
1079 afs_vop_mkdir(ap)
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;
1085                                  * } */ *ap;
1086 {
1087     register struct vnode *dvp = ap->a_dvp;
1088     register struct vattr *vap = ap->a_vap;
1089     int error = 0;
1090     struct vcache *vcp;
1091 #ifdef AFS_FBSD50_ENV
1092     struct thread *p = ap->a_cnp->cn_thread;
1093 #else
1094     struct proc *p = ap->a_cnp->cn_proc;
1095 #endif
1096
1097     GETNAME();
1098 #ifdef DIAGNOSTIC
1099     if ((cnp->cn_flags & HASBUF) == 0)
1100         panic("afs_vop_mkdir: no name");
1101 #endif
1102     AFS_GLOCK();
1103     error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1104     AFS_GUNLOCK();
1105     if (error) {
1106         DROPNAME();
1107         return (error);
1108     }
1109     if (vcp) {
1110         *ap->a_vpp = AFSTOV(vcp);
1111         vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1112     } else
1113         *ap->a_vpp = 0;
1114     DROPNAME();
1115     return error;
1116 }
1117
1118 int
1119 afs_vop_rmdir(ap)
1120      struct vop_rmdir_args      /* {
1121                                  * struct vnode *a_dvp;
1122                                  * struct vnode *a_vp;
1123                                  * struct componentname *a_cnp;
1124                                  * } */ *ap;
1125 {
1126     int error = 0;
1127     register struct vnode *dvp = ap->a_dvp;
1128
1129     GETNAME();
1130     AFS_GLOCK();
1131     error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1132     AFS_GUNLOCK();
1133     DROPNAME();
1134     return error;
1135 }
1136
1137 /* struct vop_symlink_args {
1138  *      struct vnode *a_dvp;
1139  *      struct vnode **a_vpp;
1140  *      struct componentname *a_cnp;
1141  *      struct vattr *a_vap;
1142  *      char *a_target;
1143  * };
1144  */
1145 int
1146 afs_vop_symlink(struct vop_symlink_args *ap)
1147 {
1148     struct vnode *dvp;
1149     struct vnode *newvp;
1150     struct vcache *vcp;
1151     int error;
1152
1153     GETNAME();
1154     AFS_GLOCK();
1155
1156     dvp = ap->a_dvp;
1157     newvp = NULL;
1158
1159     error =
1160         afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1161     if (error == 0) {
1162         error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1163         if (error == 0) {
1164             newvp = AFSTOV(vcp);
1165 #ifdef AFS_FBSD50_ENV
1166             vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1167 #else
1168             vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_proc);
1169 #endif
1170         }
1171     }
1172     AFS_GUNLOCK();
1173     DROPNAME();
1174     *(ap->a_vpp) = newvp;
1175     return error;
1176 }
1177
1178 int
1179 afs_vop_readdir(ap)
1180      struct vop_readdir_args    /* {
1181                                  * struct vnode *a_vp;
1182                                  * struct uio *a_uio;
1183                                  * struct ucred *a_cred;
1184                                  * int *a_eofflag;
1185                                  * u_long *a_cookies;
1186                                  * int ncookies;
1187                                  * } */ *ap;
1188 {
1189     int error;
1190     off_t off;
1191 /*    printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1192            ap->a_ncookies); */
1193     off = ap->a_uio->uio_offset;
1194     AFS_GLOCK();
1195     error =
1196         afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1197     AFS_GUNLOCK();
1198     if (!error && ap->a_ncookies != NULL) {
1199         struct uio *uio = ap->a_uio;
1200         const struct dirent *dp, *dp_start, *dp_end;
1201         int ncookies;
1202         u_long *cookies, *cookiep;
1203
1204         if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1205             panic("afs_readdir: burned cookies");
1206         dp = (const struct dirent *)
1207             ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1208
1209         dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1210         for (dp_start = dp, ncookies = 0; dp < dp_end;
1211              dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1212             ncookies++;
1213
1214         MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1215                M_WAITOK);
1216         for (dp = dp_start, cookiep = cookies; dp < dp_end;
1217              dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1218             off += dp->d_reclen;
1219             *cookiep++ = off;
1220         }
1221         *ap->a_cookies = cookies;
1222         *ap->a_ncookies = ncookies;
1223     }
1224
1225     return error;
1226 }
1227
1228 int
1229 afs_vop_readlink(ap)
1230      struct vop_readlink_args   /* {
1231                                  * struct vnode *a_vp;
1232                                  * struct uio *a_uio;
1233                                  * struct ucred *a_cred;
1234                                  * } */ *ap;
1235 {
1236     int error;
1237 /*    printf("readlink %x\n", ap->a_vp);*/
1238     AFS_GLOCK();
1239     error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1240     AFS_GUNLOCK();
1241     return error;
1242 }
1243
1244 extern int prtactive;
1245
1246 int
1247 afs_vop_inactive(ap)
1248      struct vop_inactive_args   /* {
1249                                  * struct vnode *a_vp;
1250                                  * struct proc *a_p;
1251                                  * } */ *ap;
1252 {
1253     register struct vnode *vp = ap->a_vp;
1254
1255     if (prtactive && vp->v_usecount != 0)
1256         vprint("afs_vop_inactive(): pushing active", vp);
1257
1258     AFS_GLOCK();
1259     afs_InactiveVCache(VTOAFS(vp), 0);  /* decrs ref counts */
1260     AFS_GUNLOCK();
1261     VOP_UNLOCK(vp, 0, ap->a_p);
1262     return 0;
1263 }
1264
1265 /*
1266  * struct vop_reclaim_args {
1267  *      struct vnode *a_vp;
1268  * };
1269  */
1270 int
1271 afs_vop_reclaim(struct vop_reclaim_args *ap)
1272 {
1273     /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1274     int code, slept;
1275     struct vnode *vp = ap->a_vp;
1276     struct vcache *avc = VTOAFS(vp);
1277     int haveGlock = ISAFS_GLOCK();
1278     int haveVlock = CheckLock(&afs_xvcache);
1279
1280     if (!haveGlock)
1281         AFS_GLOCK();
1282     if (!haveVlock)
1283         ObtainWriteLock(&afs_xvcache, 901);
1284 #ifndef AFS_DISCON_ENV
1285     code = afs_FlushVCache(avc, &slept);        /* tosses our stuff from vnode */
1286 #else
1287     /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1288     code = afs_FlushVS(avc);
1289 #endif
1290     if (!haveVlock)
1291         ReleaseWriteLock(&afs_xvcache);
1292     if (!haveGlock)
1293         AFS_GUNLOCK();
1294
1295     /*
1296      * XXX Pretend it worked, to prevent panic on shutdown
1297      * Garrett, please fix - Jim Rees
1298      */
1299     if (code)
1300         printf("afs_vop_reclaim: afs_FlushVCache failed code %d\n", code);
1301     return 0;
1302 }
1303
1304 int
1305 afs_vop_bmap(ap)
1306      struct vop_bmap_args       /* {
1307                                  * struct vnode *a_vp;
1308                                  * daddr_t  a_bn;
1309                                  * struct vnode **a_vpp;
1310                                  * daddr_t *a_bnp;
1311                                  * int *a_runp;
1312                                  * int *a_runb;
1313                                  * } */ *ap;
1314 {
1315     if (ap->a_bnp) {
1316         *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1317     }
1318     if (ap->a_vpp) {
1319         *ap->a_vpp = ap->a_vp;
1320     }
1321     if (ap->a_runp != NULL)
1322         *ap->a_runp = 0;
1323     if (ap->a_runb != NULL)
1324         *ap->a_runb = 0;
1325
1326     return 0;
1327 }
1328
1329 int
1330 afs_vop_strategy(ap)
1331      struct vop_strategy_args   /* {
1332                                  * struct buf *a_bp;
1333                                  * } */ *ap;
1334 {
1335     int error;
1336     AFS_GLOCK();
1337     error = afs_ustrategy(ap->a_bp);
1338     AFS_GUNLOCK();
1339     return error;
1340 }
1341
1342 int
1343 afs_vop_print(ap)
1344      struct vop_print_args      /* {
1345                                  * struct vnode *a_vp;
1346                                  * } */ *ap;
1347 {
1348     register struct vnode *vp = ap->a_vp;
1349     register struct vcache *vc = VTOAFS(ap->a_vp);
1350     int s = vc->states;
1351
1352 #ifdef AFS_FBSD50_ENV
1353     printf("tag %s, fid: %d.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1354            (int)vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1355            (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1356            vc->execsOrWriters);
1357 #else
1358     printf("tag %d, fid: %ld.%x.%x.%x, opens %d, writers %d", vp->v_tag,
1359            vc->fid.Cell, (u_int) vc->fid.Fid.Volume,
1360            (u_int) vc->fid.Fid.Vnode, (u_int) vc->fid.Fid.Unique, vc->opens,
1361            vc->execsOrWriters);
1362 #endif
1363     printf("\n  states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1364            (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1365            (s & CMAPPED) ? " mapped" : "",
1366            (s & CVFlushed) ? " flush in progress" : "");
1367     printf("\n");
1368     return 0;
1369 }
1370
1371 /*
1372  * Advisory record locking support (fcntl() POSIX style)
1373  */
1374 int
1375 afs_vop_advlock(ap)
1376      struct vop_advlock_args    /* {
1377                                  * struct vnode *a_vp;
1378                                  * caddr_t  a_id;
1379                                  * int  a_op;
1380                                  * struct flock *a_fl;
1381                                  * int  a_flags;
1382                                  * } */ *ap;
1383 {
1384     int error;
1385     struct ucred cr = *osi_curcred();
1386
1387     AFS_GLOCK();
1388     error =
1389         afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);
1390     AFS_GUNLOCK();
1391     return error;
1392 }