8d88aef29113651de2f07124be53ed9438dd3caf
[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
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 #include <vm/vm_page.h>
58 #include <vm/vm_object.h>
59 #include <vm/vm_pager.h>
60 #include <vm/vnode_pager.h>
61 extern int afs_pbuf_freecnt;
62
63 #ifdef AFS_FBSD60_ENV
64 static vop_access_t     afs_vop_access;
65 static vop_advlock_t    afs_vop_advlock;
66 static vop_close_t      afs_vop_close;
67 static vop_create_t     afs_vop_create;
68 static vop_fsync_t      afs_vop_fsync;
69 static vop_getattr_t    afs_vop_getattr;
70 static vop_getpages_t   afs_vop_getpages;
71 static vop_inactive_t   afs_vop_inactive;
72 static vop_ioctl_t      afs_vop_ioctl;
73 static vop_link_t       afs_vop_link;
74 static vop_lookup_t     afs_vop_lookup;
75 static vop_mkdir_t      afs_vop_mkdir;
76 static vop_mknod_t      afs_vop_mknod;
77 static vop_open_t       afs_vop_open;
78 static vop_pathconf_t   afs_vop_pathconf;
79 static vop_poll_t       afs_vop_poll;
80 static vop_print_t      afs_vop_print;
81 static vop_putpages_t   afs_vop_putpages;
82 static vop_read_t       afs_vop_read;
83 static vop_readdir_t    afs_vop_readdir;
84 static vop_readlink_t   afs_vop_readlink;
85 static vop_reclaim_t    afs_vop_reclaim;
86 static vop_remove_t     afs_vop_remove;
87 static vop_rename_t     afs_vop_rename;
88 static vop_rmdir_t      afs_vop_rmdir;
89 static vop_setattr_t    afs_vop_setattr;
90 static vop_strategy_t   afs_vop_strategy;
91 static vop_symlink_t    afs_vop_symlink;
92 static vop_write_t      afs_vop_write;
93 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD80_ENV)
94 static vop_lock1_t      afs_vop_lock;
95 static vop_unlock_t     afs_vop_unlock;
96 static vop_islocked_t   afs_vop_islocked;
97 #endif
98
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 #if !defined(AFS_FBSD80_ENV)
111         /* removed at least temporarily (NFSv4 flux) */
112         .vop_lease =            VOP_NULL,
113 #endif
114         .vop_link =             afs_vop_link,
115         .vop_lookup =           afs_vop_lookup,
116         .vop_mkdir =            afs_vop_mkdir,
117         .vop_mknod =            afs_vop_mknod,
118         .vop_open =             afs_vop_open,
119         .vop_pathconf =         afs_vop_pathconf,
120         .vop_poll =             afs_vop_poll,
121         .vop_print =            afs_vop_print,
122         .vop_putpages =         afs_vop_putpages,
123         .vop_read =             afs_vop_read,
124         .vop_readdir =          afs_vop_readdir,
125         .vop_readlink =         afs_vop_readlink,
126         .vop_reclaim =          afs_vop_reclaim,
127         .vop_remove =           afs_vop_remove,
128         .vop_rename =           afs_vop_rename,
129         .vop_rmdir =            afs_vop_rmdir,
130         .vop_setattr =          afs_vop_setattr,
131         .vop_strategy =         afs_vop_strategy,
132         .vop_symlink =          afs_vop_symlink,
133         .vop_write =            afs_vop_write,
134 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD80_ENV)
135         .vop_lock1 =            afs_vop_lock,
136         .vop_unlock =           afs_vop_unlock,
137         .vop_islocked =         afs_vop_islocked,
138 #endif
139 };
140
141 #else /* AFS_FBSD60_ENV */
142
143 int afs_vop_lookup(struct vop_lookup_args *);
144 int afs_vop_create(struct vop_create_args *);
145 int afs_vop_mknod(struct vop_mknod_args *);
146 int afs_vop_open(struct vop_open_args *);
147 int afs_vop_close(struct vop_close_args *);
148 int afs_vop_access(struct vop_access_args *);
149 int afs_vop_getattr(struct vop_getattr_args *);
150 int afs_vop_setattr(struct vop_setattr_args *);
151 int afs_vop_read(struct vop_read_args *);
152 int afs_vop_write(struct vop_write_args *);
153 int afs_vop_getpages(struct vop_getpages_args *);
154 int afs_vop_putpages(struct vop_putpages_args *);
155 int afs_vop_ioctl(struct vop_ioctl_args *);
156 static int afs_vop_pathconf(struct vop_pathconf_args *);
157 int afs_vop_poll(struct vop_poll_args *);
158 int afs_vop_fsync(struct vop_fsync_args *);
159 int afs_vop_remove(struct vop_remove_args *);
160 int afs_vop_link(struct vop_link_args *);
161 int afs_vop_rename(struct vop_rename_args *);
162 int afs_vop_mkdir(struct vop_mkdir_args *);
163 int afs_vop_rmdir(struct vop_rmdir_args *);
164 int afs_vop_symlink(struct vop_symlink_args *);
165 int afs_vop_readdir(struct vop_readdir_args *);
166 int afs_vop_readlink(struct vop_readlink_args *);
167 int afs_vop_inactive(struct vop_inactive_args *);
168 int afs_vop_reclaim(struct vop_reclaim_args *);
169 int afs_vop_bmap(struct vop_bmap_args *);
170 int afs_vop_strategy(struct vop_strategy_args *);
171 int afs_vop_print(struct vop_print_args *);
172 int afs_vop_advlock(struct vop_advlock_args *);
173
174
175
176 /* Global vfs data structures for AFS. */
177 vop_t **afs_vnodeop_p;
178 struct vnodeopv_entry_desc afs_vnodeop_entries[] = {
179     {&vop_default_desc, (vop_t *) vop_defaultop},
180     {&vop_access_desc, (vop_t *) afs_vop_access},       /* access */
181     {&vop_advlock_desc, (vop_t *) afs_vop_advlock},     /* advlock */
182     {&vop_bmap_desc, (vop_t *) afs_vop_bmap},   /* bmap */
183     {&vop_close_desc, (vop_t *) afs_vop_close}, /* close */
184     {&vop_createvobject_desc, (vop_t *) vop_stdcreatevobject},
185     {&vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject},
186     {&vop_create_desc, (vop_t *) afs_vop_create},       /* create */
187     {&vop_fsync_desc, (vop_t *) afs_vop_fsync}, /* fsync */
188     {&vop_getattr_desc, (vop_t *) afs_vop_getattr},     /* getattr */
189     {&vop_getpages_desc, (vop_t *) afs_vop_getpages},   /* read */
190     {&vop_getvobject_desc, (vop_t *) vop_stdgetvobject},
191     {&vop_putpages_desc, (vop_t *) afs_vop_putpages},   /* write */
192     {&vop_inactive_desc, (vop_t *) afs_vop_inactive},   /* inactive */
193     {&vop_lease_desc, (vop_t *) vop_null},
194     {&vop_link_desc, (vop_t *) afs_vop_link},   /* link */
195     {&vop_lookup_desc, (vop_t *) afs_vop_lookup},       /* lookup */
196     {&vop_mkdir_desc, (vop_t *) afs_vop_mkdir}, /* mkdir */
197     {&vop_mknod_desc, (vop_t *) afs_vop_mknod}, /* mknod */
198     {&vop_open_desc, (vop_t *) afs_vop_open},   /* open */
199     {&vop_pathconf_desc, (vop_t *) afs_vop_pathconf},   /* pathconf */
200     {&vop_poll_desc, (vop_t *) afs_vop_poll},   /* select */
201     {&vop_print_desc, (vop_t *) afs_vop_print}, /* print */
202     {&vop_read_desc, (vop_t *) afs_vop_read},   /* read */
203     {&vop_readdir_desc, (vop_t *) afs_vop_readdir},     /* readdir */
204     {&vop_readlink_desc, (vop_t *) afs_vop_readlink},   /* readlink */
205     {&vop_reclaim_desc, (vop_t *) afs_vop_reclaim},     /* reclaim */
206     {&vop_remove_desc, (vop_t *) afs_vop_remove},       /* remove */
207     {&vop_rename_desc, (vop_t *) afs_vop_rename},       /* rename */
208     {&vop_rmdir_desc, (vop_t *) afs_vop_rmdir}, /* rmdir */
209     {&vop_setattr_desc, (vop_t *) afs_vop_setattr},     /* setattr */
210     {&vop_strategy_desc, (vop_t *) afs_vop_strategy},   /* strategy */
211     {&vop_symlink_desc, (vop_t *) afs_vop_symlink},     /* symlink */
212     {&vop_write_desc, (vop_t *) afs_vop_write}, /* write */
213     {&vop_ioctl_desc, (vop_t *) afs_vop_ioctl}, /* XXX ioctl */
214     /*{ &vop_seek_desc, afs_vop_seek }, *//* seek */
215 #if defined(AFS_FBSD70_ENV) && !defined(AFS_FBSD90_ENV)
216     {&vop_lock1_desc, (vop_t *) afs_vop_lock}, /* lock */
217     {&vop_unlock_desc, (vop_t *) afs_vop_unlock}, /* unlock */
218     {&vop_islocked_desc, (vop_t *) afs_vop_islocked}, /* islocked */
219 #endif
220     {NULL, NULL}
221 };
222 struct vnodeopv_desc afs_vnodeop_opv_desc =
223     { &afs_vnodeop_p, afs_vnodeop_entries };
224 #endif /* AFS_FBSD60_ENV */
225
226 #define GETNAME()       \
227     struct componentname *cnp = ap->a_cnp; \
228     char *name; \
229     MALLOC(name, char *, cnp->cn_namelen+1, M_TEMP, M_WAITOK); \
230     memcpy(name, cnp->cn_nameptr, cnp->cn_namelen); \
231     name[cnp->cn_namelen] = '\0'
232
233 #define DROPNAME() FREE(name, M_TEMP)
234
235 #if defined(AFS_FBSD80_ENV)
236 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags))
237 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags))
238 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags))
239 #else
240 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags, p))
241 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags, p))
242 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags, p))
243 #endif
244
245 #ifdef AFS_FBSD70_ENV
246 #ifndef AFS_FBSD80_ENV
247 /* From kern_lock.c */
248 #define COUNT(td, x)    if ((td)) (td)->td_locks += (x)
249 #define LK_ALL (LK_HAVE_EXCL | LK_WANT_EXCL | LK_WANT_UPGRADE | \
250         LK_SHARE_NONZERO | LK_WAIT_NONZERO)
251
252 static __inline void
253 sharelock(struct thread *td, struct lock *lkp, int incr) {
254         lkp->lk_flags |= LK_SHARE_NONZERO;
255         lkp->lk_sharecount += incr;
256         COUNT(td, incr);
257 }
258 #endif
259
260 /*
261  * Standard lock, unlock and islocked functions.
262  */
263 int
264 afs_vop_lock(ap)
265     struct vop_lock1_args /* {
266                              struct vnode *a_vp;
267                              int a_flags;
268                              struct thread *a_td;
269                              char *file;
270                              int line;
271                              } */ *ap;
272 {
273     struct vnode *vp = ap->a_vp;
274     struct lock *lkp = vp->v_vnlock;
275
276 #if 0 && defined(AFS_FBSD80_ENV) && !defined(UKERNEL)
277     afs_warn("afs_vop_lock: tid %d pid %d \"%s\"\n", curthread->td_tid,
278              curthread->td_proc->p_pid, curthread->td_name);
279     kdb_backtrace();
280 #endif
281
282 #ifdef AFS_FBSD80_ENV
283     return (_lockmgr_args(lkp, ap->a_flags, VI_MTX(vp),
284                           LK_WMESG_DEFAULT, LK_PRIO_DEFAULT, LK_TIMO_DEFAULT,
285                           ap->a_file, ap->a_line));
286 #else
287     return (_lockmgr(lkp, ap->a_flags, VI_MTX(vp), ap->a_td, ap->a_file, ap->a_line));
288 #endif
289 }
290
291 /* See above. */
292 int
293 afs_vop_unlock(ap)
294     struct vop_unlock_args /* {
295                               struct vnode *a_vp;
296                               int a_flags;
297                               struct thread *a_td;
298                               } */ *ap;
299 {
300     struct vnode *vp = ap->a_vp;
301     struct lock *lkp = vp->v_vnlock;
302
303 #ifdef AFS_FBSD80_ENV
304     int code = 0;
305     u_int op;
306     op = ((ap->a_flags) | LK_RELEASE) & LK_TYPE_MASK;
307     int glocked = ISAFS_GLOCK();
308     if (glocked)
309         AFS_GUNLOCK();
310     if ((op & (op - 1)) != 0) {
311       afs_warn("afs_vop_unlock: Shit.\n");
312       goto done;
313     }
314     code = lockmgr(lkp, ap->a_flags | LK_RELEASE, VI_MTX(vp));
315  done:
316     if (glocked)
317         AFS_GLOCK();
318     return(code);
319 #else
320     /* possibly in current code path where this
321      * forces trace, we should have had a (shared? not
322      * necessarily, see _lockmgr in kern_lock.c) lock
323      * and that's the real bug.  but. 
324      */
325     critical_enter();
326     if ((lkp->lk_exclusivecount == 0) &&
327         (!(lkp->lk_flags & LK_SHARE_NONZERO))) {
328         sharelock(ap->a_td, lkp, 1);
329     }
330     critical_exit();
331     return (lockmgr(lkp, ap->a_flags | LK_RELEASE, VI_MTX(vp),
332                     ap->a_td));
333 #endif
334 }
335
336 /* See above. */
337 int
338 afs_vop_islocked(ap)
339     struct vop_islocked_args /* {
340                                 struct vnode *a_vp;
341                                 struct thread *a_td; (not in 80)
342                                 } */ *ap;
343 {
344 #ifdef AFS_FBSD80_ENV
345     return (lockstatus(ap->a_vp->v_vnlock));
346 #else
347     return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
348 #endif
349 }
350 #endif /* 70 */
351
352 /*
353  * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf().
354  * We should know the correct answers to these questions with
355  * respect to the AFS protocol (which may differ from the UFS
356  * values) but for the moment this will do.
357  */
358 static int
359 afs_vop_pathconf(struct vop_pathconf_args *ap)
360 {
361         int error;
362
363         error = 0;
364         switch (ap->a_name) {
365         case _PC_LINK_MAX:
366                 *ap->a_retval = LINK_MAX;
367                 break;
368         case _PC_NAME_MAX:
369                 *ap->a_retval = NAME_MAX;
370                 break;
371         case _PC_PATH_MAX:
372                 *ap->a_retval = PATH_MAX;
373                 break;
374         case _PC_PIPE_BUF:
375                 *ap->a_retval = PIPE_BUF;
376                 break;
377         case _PC_CHOWN_RESTRICTED:
378                 *ap->a_retval = 1;
379                 break;
380         case _PC_NO_TRUNC:
381                 *ap->a_retval = 1;
382                 break;
383 #ifdef _PC_ACL_EXTENDED
384         case _PC_ACL_EXTENDED:
385                 *ap->a_retval = 0;
386                 break;
387         case _PC_ACL_PATH_MAX:
388                 *ap->a_retval = 3;
389                 break;
390 #endif
391 #ifdef _PC_MAC_PRESENT
392         case _PC_MAC_PRESENT:
393                 *ap->a_retval = 0;
394                 break;
395 #endif
396 #ifdef _PC_ASYNC_IO
397         case _PC_ASYNC_IO:
398                 /* _PC_ASYNC_IO should have been handled by upper layers. */
399                 KASSERT(0, ("_PC_ASYNC_IO should not get here"));
400                 error = EINVAL;
401                 break;
402         case _PC_PRIO_IO:
403                 *ap->a_retval = 0;
404                 break;
405         case _PC_SYNC_IO:
406                 *ap->a_retval = 0;
407                 break;
408 #endif
409 #ifdef _PC_ALLOC_SIZE_MIN
410         case _PC_ALLOC_SIZE_MIN:
411                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_bsize;
412                 break;
413 #endif
414 #ifdef _PC_FILESIZEBITS
415         case _PC_FILESIZEBITS:
416                 *ap->a_retval = 32; /* XXX */
417                 break;
418 #endif
419 #ifdef _PC_REC_INCR_XFER_SIZE
420         case _PC_REC_INCR_XFER_SIZE:
421                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
422                 break;
423         case _PC_REC_MAX_XFER_SIZE:
424                 *ap->a_retval = -1; /* means ``unlimited'' */
425                 break;
426         case _PC_REC_MIN_XFER_SIZE:
427                 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_iosize;
428                 break;
429         case _PC_REC_XFER_ALIGN:
430                 *ap->a_retval = PAGE_SIZE;
431                 break;
432 #endif
433 #ifdef _PC_SYMLINK_MAX
434         case _PC_SYMLINK_MAX:
435                 *ap->a_retval = MAXPATHLEN;
436                 break;
437 #endif
438         default:
439                 error = EINVAL;
440                 break;
441         }
442         return (error);
443 }
444
445 int
446 afs_vop_lookup(ap)
447      struct vop_lookup_args     /* {
448                                  * struct vnodeop_desc * a_desc;
449                                  * struct vnode *a_dvp;
450                                  * struct vnode **a_vpp;
451                                  * struct componentname *a_cnp;
452                                  * } */ *ap;
453 {
454     int error;
455     struct vcache *vcp;
456     struct vnode *vp, *dvp;
457     register int flags = ap->a_cnp->cn_flags;
458     int lockparent;             /* 1 => lockparent flag is set */
459     int wantparent;             /* 1 => wantparent or lockparent flag */
460     struct thread *p = ap->a_cnp->cn_thread;
461
462     dvp = ap->a_dvp;
463     if (dvp->v_type != VDIR) {
464 #ifndef AFS_FBSD70_ENV
465         *ap->a_vpp = 0;
466 #endif
467         return ENOTDIR;
468     }
469
470     if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT))
471         return EIO;
472
473     GETNAME();
474
475     lockparent = flags & LOCKPARENT;
476     wantparent = flags & (LOCKPARENT | WANTPARENT);
477
478 #ifdef AFS_FBSD80_ENV
479     cnp->cn_flags |= MPSAFE; /* steel */
480 #endif
481
482 #ifndef AFS_FBSD70_ENV
483     if (flags & ISDOTDOT)
484         VOP_UNLOCK(dvp, 0, p);
485 #endif
486
487     AFS_GLOCK();
488     error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
489     AFS_GUNLOCK();
490
491     if (error) {
492         if (flags & ISDOTDOT)
493             MA_VOP_LOCK(dvp, LK_EXCLUSIVE | LK_RETRY, p);
494         if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)
495             && (flags & ISLASTCN) && error == ENOENT)
496             error = EJUSTRETURN;
497         if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN))
498             cnp->cn_flags |= SAVENAME;
499         DROPNAME();
500         *ap->a_vpp = 0;
501         return (error);
502     }
503     vp = AFSTOV(vcp);           /* always get a node if no error */
504
505     /* The parent directory comes in locked.  We unlock it on return
506      * unless the caller wants it left locked.
507      * we also always return the vnode locked. */
508
509     if (flags & ISDOTDOT) {
510         ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
511         /* always return the child locked */
512         if (lockparent && (flags & ISLASTCN)
513             && (error = ma_vn_lock(dvp, LK_EXCLUSIVE, p))) {
514             vput(vp);
515             DROPNAME();
516             return (error);
517         }
518     } else if (vp == dvp) {
519         /* they're the same; afs_lookup() already ref'ed the leaf.
520          * It came in locked, so we don't need to ref OR lock it */
521     } else {
522         if (!lockparent || !(flags & ISLASTCN)) {
523 #ifndef AFS_FBSD70_ENV /* 6 too? */
524             MA_VOP_UNLOCK(dvp, 0, p);   /* done with parent. */
525 #endif
526         }
527         ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
528         /* always return the child locked */
529     }
530     *ap->a_vpp = vp;
531
532     if ((cnp->cn_nameiop == RENAME && wantparent && (flags & ISLASTCN))
533         || (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)))
534         cnp->cn_flags |= SAVENAME;
535
536     DROPNAME();
537     return error;
538 }
539
540 int
541 afs_vop_create(ap)
542      struct vop_create_args     /* {
543                                  * struct vnode *a_dvp;
544                                  * struct vnode **a_vpp;
545                                  * struct componentname *a_cnp;
546                                  * struct vattr *a_vap;
547                                  * } */ *ap;
548 {
549     int error = 0;
550     struct vcache *vcp;
551     register struct vnode *dvp = ap->a_dvp;
552     struct thread *p = ap->a_cnp->cn_thread;
553     GETNAME();
554
555     AFS_GLOCK();
556     error =
557         afs_create(VTOAFS(dvp), name, ap->a_vap,
558                    ap->a_vap->va_vaflags & VA_EXCLUSIVE ? EXCL : NONEXCL,
559                    ap->a_vap->va_mode, &vcp, cnp->cn_cred);
560     AFS_GUNLOCK();
561     if (error) {
562         DROPNAME();
563         return (error);
564     }
565
566     if (vcp) {
567         *ap->a_vpp = AFSTOV(vcp);
568         ma_vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
569     } else
570         *ap->a_vpp = 0;
571
572     DROPNAME();
573     return error;
574 }
575
576 int
577 afs_vop_mknod(ap)
578      struct vop_mknod_args      /* {
579                                  * struct vnode *a_dvp;
580                                  * struct vnode **a_vpp;
581                                  * struct componentname *a_cnp;
582                                  * struct vattr *a_vap;
583                                  * } */ *ap;
584 {
585     return (ENODEV);
586 }
587
588 #if 0
589 static int
590 validate_vops(struct vnode *vp, int after)
591 {
592     int ret = 0;
593     struct vnodeopv_entry_desc *this;
594     for (this = afs_vnodeop_entries; this->opve_op; this++) {
595         if (vp->v_op[this->opve_op->vdesc_offset] != this->opve_impl) {
596             if (!ret) {
597                 printf("v_op %d ", after);
598                 vprint("check", vp);
599             }
600             ret = 1;
601             printf("For oper %d (%s), func is %p, not %p",
602                    this->opve_op->vdesc_offset, this->opve_op->vdesc_name,
603                    vp->v_op[this->opve_op->vdesc_offset], this->opve_impl);
604         }
605     }
606     return ret;
607 }
608 #endif
609 int
610 afs_vop_open(ap)
611      struct vop_open_args       /* {
612                                  * struct vnode *a_vp;
613                                  * int  a_mode;
614                                  * struct ucred *a_cred;
615                                  * struct thread *a_td;
616                                  * struct file *a_fp;
617                                  * } */ *ap;
618 {
619     int error;
620     struct vcache *vc = VTOAFS(ap->a_vp);
621
622     AFS_GLOCK();
623     error = afs_open(&vc, ap->a_mode, ap->a_cred);
624 #ifdef DIAGNOSTIC
625     if (AFSTOV(vc) != ap->a_vp)
626         panic("AFS open changed vnode!");
627 #endif
628     AFS_GUNLOCK();
629 #ifdef AFS_FBSD60_ENV
630     vnode_create_vobject(ap->a_vp, vc->f.m.Length, ap->a_td);
631 #endif
632     osi_FlushPages(vc, ap->a_cred);
633     return error;
634 }
635
636 int
637 afs_vop_close(ap)
638      struct vop_close_args      /* {
639                                  * struct vnode *a_vp;
640                                  * int  a_fflag;
641                                  * struct ucred *a_cred;
642                                  * struct thread *a_td;
643                                  * } */ *ap;
644 {
645     int code;
646     struct vcache *avc = VTOAFS(ap->a_vp);
647     AFS_GLOCK();
648     if (ap->a_cred)
649         code = afs_close(avc, ap->a_fflag, ap->a_cred);
650     else
651         code = afs_close(avc, ap->a_fflag, afs_osi_credp);
652     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
653     AFS_GUNLOCK();
654     return code;
655 }
656
657 int
658 afs_vop_access(ap)
659      struct vop_access_args     /* {
660                                  * struct vnode *a_vp;
661                                  * accmode_t a_accmode;
662                                  * struct ucred *a_cred;
663                                  * struct thread *a_td;
664                                  * } */ *ap;
665 {
666     int code;
667     AFS_GLOCK();
668 #if defined(AFS_FBSD80_ENV)
669     code = afs_access(VTOAFS(ap->a_vp), ap->a_accmode, ap->a_cred);
670 #else
671     code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred);
672 #endif
673     AFS_GUNLOCK();
674     return code;
675 }
676
677 int
678 afs_vop_getattr(ap)
679      struct vop_getattr_args    /* {
680                                  * struct vnode *a_vp;
681                                  * struct vattr *a_vap;
682                                  * struct ucred *a_cred;
683                                  * } */ *ap;
684 {
685     int code;
686     AFS_GLOCK();
687     code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
688     AFS_GUNLOCK();
689     return code;
690 }
691
692 int
693 afs_vop_setattr(ap)
694      struct vop_setattr_args    /* {
695                                  * struct vnode *a_vp;
696                                  * struct vattr *a_vap;
697                                  * struct ucred *a_cred;
698                                  * } */ *ap;
699 {
700     int code;
701     AFS_GLOCK();
702     code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred);
703     AFS_GUNLOCK();
704     return code;
705 }
706
707 int
708 afs_vop_read(ap)
709      struct vop_read_args       /* {
710                                  * struct vnode *a_vp;
711                                  * struct uio *a_uio;
712                                  * int a_ioflag;
713                                  * struct ucred *a_cred;
714                                  * 
715                                  * } */ *ap;
716 {
717     int code;
718     struct vcache *avc = VTOAFS(ap->a_vp);
719     AFS_GLOCK();
720     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
721     code = afs_read(avc, ap->a_uio, ap->a_cred, 0, 0, 0);
722     AFS_GUNLOCK();
723     return code;
724 }
725
726 /* struct vop_getpages_args {
727  *      struct vnode *a_vp;
728  *      vm_page_t *a_m;
729  *      int a_count;
730  *      int a_reqpage;
731  *      vm_oofset_t a_offset;
732  * };
733  */
734 int
735 afs_vop_getpages(struct vop_getpages_args *ap)
736 {
737     int code;
738     int i, nextoff, size, toff, npages;
739     struct uio uio;
740     struct iovec iov;
741     struct buf *bp;
742     vm_offset_t kva;
743     vm_object_t object;
744     struct vnode *vp;
745     struct vcache *avc;
746
747     vp = ap->a_vp;
748     avc = VTOAFS(vp);
749     if ((object = vp->v_object) == NULL) {
750         printf("afs_getpages: called with non-merged cache vnode??\n");
751         return VM_PAGER_ERROR;
752     }
753     npages = btoc(ap->a_count);
754     /*
755      * If the requested page is partially valid, just return it and
756      * allow the pager to zero-out the blanks.  Partially valid pages
757      * can only occur at the file EOF.
758      */
759
760     {
761         vm_page_t m = ap->a_m[ap->a_reqpage];
762
763         VM_OBJECT_LOCK(object);
764         vm_page_lock_queues();
765         if (m->valid != 0) {
766             /* handled by vm_fault now        */
767             /* vm_page_zero_invalid(m, TRUE); */
768             for (i = 0; i < npages; ++i) {
769                 if (i != ap->a_reqpage)
770                     vm_page_free(ap->a_m[i]);
771             }
772             vm_page_unlock_queues();
773             VM_OBJECT_UNLOCK(object);
774             return (0);
775         }
776         vm_page_unlock_queues();
777         VM_OBJECT_UNLOCK(object);
778     }
779     bp = getpbuf(&afs_pbuf_freecnt);
780
781     kva = (vm_offset_t) bp->b_data;
782     pmap_qenter(kva, ap->a_m, npages);
783     cnt.v_vnodein++;
784     cnt.v_vnodepgsin += npages;
785
786     iov.iov_base = (caddr_t) kva;
787     iov.iov_len = ap->a_count;
788     uio.uio_iov = &iov;
789     uio.uio_iovcnt = 1;
790     uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
791     uio.uio_resid = ap->a_count;
792     uio.uio_segflg = UIO_SYSSPACE;
793     uio.uio_rw = UIO_READ;
794     uio.uio_td = curthread;
795
796     AFS_GLOCK();
797     osi_FlushPages(avc, osi_curcred()); /* hold bozon lock, but not basic vnode lock */
798     code = afs_read(avc, &uio, osi_curcred(), 0, 0, 0);
799     AFS_GUNLOCK();
800     pmap_qremove(kva, npages);
801
802     relpbuf(bp, &afs_pbuf_freecnt);
803
804     if (code && (uio.uio_resid == ap->a_count)) {
805         VM_OBJECT_LOCK(object);
806         vm_page_lock_queues();
807         for (i = 0; i < npages; ++i) {
808             if (i != ap->a_reqpage)
809                 vm_page_free(ap->a_m[i]);
810         }
811         vm_page_unlock_queues();
812         VM_OBJECT_UNLOCK(object);
813         return VM_PAGER_ERROR;
814     }
815
816     size = ap->a_count - uio.uio_resid;
817     VM_OBJECT_LOCK(object);
818     vm_page_lock_queues();
819     for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
820         vm_page_t m;
821         nextoff = toff + PAGE_SIZE;
822         m = ap->a_m[i];
823
824         m->flags &= ~PG_ZERO;
825
826         if (nextoff <= size) {
827             /*
828              * Read operation filled an entire page
829              */
830             m->valid = VM_PAGE_BITS_ALL;
831             vm_page_undirty(m);
832         } else if (size > toff) {
833             /*
834              * Read operation filled a partial page.
835              */
836             m->valid = 0;
837             vm_page_set_validclean(m, 0, size - toff);
838             /* handled by vm_fault now        */
839             /* vm_page_zero_invalid(m, TRUE); */
840         }
841
842         if (i != ap->a_reqpage) {
843             /*
844              * Whether or not to leave the page activated is up in
845              * the air, but we should put the page on a page queue
846              * somewhere (it already is in the object).  Result:
847              * It appears that emperical results show that
848              * deactivating pages is best.
849              */
850
851             /*
852              * Just in case someone was asking for this page we
853              * now tell them that it is ok to use.
854              */
855             if (!code) {
856 #if defined(AFS_FBSD70_ENV)
857                 if (m->oflags & VPO_WANTED)
858 #else
859                 if (m->flags & PG_WANTED)
860 #endif
861                     vm_page_activate(m);
862                 else
863                     vm_page_deactivate(m);
864                 vm_page_wakeup(m);
865             } else {
866                 vm_page_free(m);
867             }
868         }
869     }
870     vm_page_unlock_queues();
871     VM_OBJECT_UNLOCK(object);
872     return 0;
873 }
874
875 int
876 afs_vop_write(ap)
877      struct vop_write_args      /* {
878                                  * struct vnode *a_vp;
879                                  * struct uio *a_uio;
880                                  * int a_ioflag;
881                                  * struct ucred *a_cred;
882                                  * } */ *ap;
883 {
884     int code;
885     struct vcache *avc = VTOAFS(ap->a_vp);
886     AFS_GLOCK();
887     osi_FlushPages(avc, ap->a_cred);    /* hold bozon lock, but not basic vnode lock */
888     code =
889         afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0);
890     AFS_GUNLOCK();
891     return code;
892 }
893
894 /*-
895  * struct vop_putpages_args {
896  *      struct vnode *a_vp;
897  *      vm_page_t *a_m;
898  *      int a_count;
899  *      int a_sync;
900  *      int *a_rtvals;
901  *      vm_oofset_t a_offset;
902  * };
903  */
904 /*
905  * All of the pages passed to us in ap->a_m[] are already marked as busy,
906  * so there is no additional locking required to set their flags.  -GAW
907  */
908 int
909 afs_vop_putpages(struct vop_putpages_args *ap)
910 {
911     int code;
912     int i, size, npages, sync;
913     struct uio uio;
914     struct iovec iov;
915     struct buf *bp;
916     vm_offset_t kva;
917     struct vnode *vp;
918     struct vcache *avc;
919
920     vp = ap->a_vp;
921     avc = VTOAFS(vp);
922     /* Perhaps these two checks should just be KASSERTs instead... */
923     if (vp->v_object == NULL) {
924         printf("afs_putpages: called with non-merged cache vnode??\n");
925         return VM_PAGER_ERROR;  /* XXX I think this is insufficient */
926     }
927     if (vType(avc) != VREG) {
928         printf("afs_putpages: not VREG");
929         return VM_PAGER_ERROR;  /* XXX I think this is insufficient */
930     }
931     npages = btoc(ap->a_count);
932     for (i = 0; i < npages; i++)
933         ap->a_rtvals[i] = VM_PAGER_AGAIN;
934     bp = getpbuf(&afs_pbuf_freecnt);
935
936     kva = (vm_offset_t) bp->b_data;
937     pmap_qenter(kva, ap->a_m, npages);
938     cnt.v_vnodeout++;
939     cnt.v_vnodepgsout += ap->a_count;
940
941     iov.iov_base = (caddr_t) kva;
942     iov.iov_len = ap->a_count;
943     uio.uio_iov = &iov;
944     uio.uio_iovcnt = 1;
945     uio.uio_offset = IDX_TO_OFF(ap->a_m[0]->pindex);
946     uio.uio_resid = ap->a_count;
947     uio.uio_segflg = UIO_SYSSPACE;
948     uio.uio_rw = UIO_WRITE;
949     uio.uio_td = curthread;
950     sync = IO_VMIO;
951     if (ap->a_sync & VM_PAGER_PUT_SYNC)
952         sync |= IO_SYNC;
953     /*if (ap->a_sync & VM_PAGER_PUT_INVAL)
954      * sync |= IO_INVAL; */
955
956     AFS_GLOCK();
957     code = afs_write(avc, &uio, sync, osi_curcred(), 0);
958     AFS_GUNLOCK();
959
960     pmap_qremove(kva, npages);
961     relpbuf(bp, &afs_pbuf_freecnt);
962
963     if (!code) {
964         size = ap->a_count - uio.uio_resid;
965         for (i = 0; i < round_page(size) / PAGE_SIZE; i++) {
966             ap->a_rtvals[i] = VM_PAGER_OK;
967             vm_page_undirty(ap->a_m[i]);
968         }
969     }
970     return ap->a_rtvals[0];
971 }
972
973 int
974 afs_vop_ioctl(ap)
975      struct vop_ioctl_args      /* {
976                                  * struct vnode *a_vp;
977                                  * u_long a_command;
978                                  * void *a_data;
979                                  * int  a_fflag;
980                                  * struct ucred *a_cred;
981                                  * struct thread *a_td;
982                                  * } */ *ap;
983 {
984     struct vcache *tvc = VTOAFS(ap->a_vp);
985     int error = 0;
986
987     /* in case we ever get in here... */
988
989     AFS_STATCNT(afs_ioctl);
990     if (((ap->a_command >> 8) & 0xff) == 'V') {
991         /* This is a VICEIOCTL call */
992         AFS_GLOCK();
993         error = HandleIoctl(tvc, ap->a_command, ap->a_data);
994         AFS_GUNLOCK();
995         return (error);
996     } else {
997         /* No-op call; just return. */
998         return (ENOTTY);
999     }
1000 }
1001
1002 /* ARGSUSED */
1003 int
1004 afs_vop_poll(ap)
1005      struct vop_poll_args       /* {
1006                                  * struct vnode *a_vp;
1007                                  * int  a_events;
1008                                  * struct ucred *a_cred;
1009                                  * struct thread *td;
1010                                  * } */ *ap;
1011 {
1012     /*
1013      * We should really check to see if I/O is possible.
1014      */
1015     return (1);
1016 }
1017
1018 /*
1019  * Mmap a file
1020  *
1021  * NB Currently unsupported.
1022  */
1023 /* ARGSUSED */
1024 int
1025 afs_vop_mmap(ap)
1026      struct vop_mmap_args       /* {
1027                                  * struct vnode *a_vp;
1028                                  * int  a_fflags;
1029                                  * struct ucred *a_cred;
1030                                  * struct thread *td;
1031                                  * } */ *ap;
1032 {
1033     return (EINVAL);
1034 }
1035
1036 int
1037 afs_vop_fsync(ap)
1038      struct vop_fsync_args      /* {
1039                                  * struct vnode *a_vp;
1040                                  * int a_waitfor;
1041                                  * struct thread *td;
1042                                  * } */ *ap;
1043 {
1044     int error;
1045     register struct vnode *vp = ap->a_vp;
1046
1047     AFS_GLOCK();
1048     /*vflushbuf(vp, wait); */
1049 #ifdef AFS_FBSD60_ENV
1050     error = afs_fsync(VTOAFS(vp), ap->a_td->td_ucred);
1051 #else
1052     if (ap->a_cred)
1053         error = afs_fsync(VTOAFS(vp), ap->a_cred);
1054     else
1055         error = afs_fsync(VTOAFS(vp), afs_osi_credp);
1056 #endif
1057     AFS_GUNLOCK();
1058     return error;
1059 }
1060
1061 int
1062 afs_vop_remove(ap)
1063      struct vop_remove_args     /* {
1064                                  * struct vnode *a_dvp;
1065                                  * struct vnode *a_vp;
1066                                  * struct componentname *a_cnp;
1067                                  * } */ *ap;
1068 {
1069     int error = 0;
1070     register struct vnode *vp = ap->a_vp;
1071     register struct vnode *dvp = ap->a_dvp;
1072
1073     GETNAME();
1074     AFS_GLOCK();
1075     error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred);
1076     AFS_GUNLOCK();
1077     cache_purge(vp);
1078     DROPNAME();
1079     return error;
1080 }
1081
1082 int
1083 afs_vop_link(ap)
1084      struct vop_link_args       /* {
1085                                  * struct vnode *a_vp;
1086                                  * struct vnode *a_tdvp;
1087                                  * struct componentname *a_cnp;
1088                                  * } */ *ap;
1089 {
1090     int error = 0;
1091     register struct vnode *dvp = ap->a_tdvp;
1092     register struct vnode *vp = ap->a_vp;
1093     struct thread *p = ap->a_cnp->cn_thread;
1094
1095     GETNAME();
1096     if (dvp->v_mount != vp->v_mount) {
1097         error = EXDEV;
1098         goto out;
1099     }
1100     if (vp->v_type == VDIR) {
1101         error = EISDIR;
1102         goto out;
1103     }
1104     if ((error = ma_vn_lock(vp, LK_EXCLUSIVE, p)) != 0) {
1105         goto out;
1106     }
1107     AFS_GLOCK();
1108     error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred);
1109     AFS_GUNLOCK();
1110     if (dvp != vp)
1111         MA_VOP_UNLOCK(vp, 0, p);
1112   out:
1113     DROPNAME();
1114     return error;
1115 }
1116
1117 int
1118 afs_vop_rename(ap)
1119      struct vop_rename_args     /* {
1120                                  * struct vnode *a_fdvp;
1121                                  * struct vnode *a_fvp;
1122                                  * struct componentname *a_fcnp;
1123                                  * struct vnode *a_tdvp;
1124                                  * struct vnode *a_tvp;
1125                                  * struct componentname *a_tcnp;
1126                                  * } */ *ap;
1127 {
1128     int error = 0;
1129     struct componentname *fcnp = ap->a_fcnp;
1130     char *fname;
1131     struct componentname *tcnp = ap->a_tcnp;
1132     char *tname;
1133     struct vnode *tvp = ap->a_tvp;
1134     register struct vnode *tdvp = ap->a_tdvp;
1135     struct vnode *fvp = ap->a_fvp;
1136     register struct vnode *fdvp = ap->a_fdvp;
1137     struct thread *p = fcnp->cn_thread;
1138
1139     /*
1140      * Check for cross-device rename.
1141      */
1142     if ((fvp->v_mount != tdvp->v_mount)
1143         || (tvp && (fvp->v_mount != tvp->v_mount))) {
1144         error = EXDEV;
1145       abortit:
1146         if (tdvp == tvp)
1147             vrele(tdvp);
1148         else
1149             vput(tdvp);
1150         if (tvp)
1151             vput(tvp);
1152         vrele(fdvp);
1153         vrele(fvp);
1154         return (error);
1155     }
1156     /*
1157      * if fvp == tvp, we're just removing one name of a pair of
1158      * directory entries for the same element.  convert call into rename.
1159      ( (pinched from FreeBSD 4.4's ufs_rename())
1160      
1161      */
1162     if (fvp == tvp) {
1163         if (fvp->v_type == VDIR) {
1164             error = EINVAL;
1165             goto abortit;
1166         }
1167
1168         /* Release destination completely. */
1169         vput(tdvp);
1170         vput(tvp);
1171
1172         /* Delete source. */
1173         vrele(fdvp);
1174         vrele(fvp);
1175         fcnp->cn_flags &= ~MODMASK;
1176         fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1177         if ((fcnp->cn_flags & SAVESTART) == 0)
1178             panic("afs_rename: lost from startdir");
1179         fcnp->cn_nameiop = DELETE;
1180         VREF(fdvp);
1181         error = relookup(fdvp, &fvp, fcnp);
1182         if (error == 0)
1183             vrele(fdvp);
1184         if (fvp == NULL) {
1185             return (ENOENT);
1186         }
1187
1188         error = VOP_REMOVE(fdvp, fvp, fcnp);
1189         if (fdvp == fvp)
1190             vrele(fdvp);
1191         else
1192             vput(fdvp);
1193         vput(fvp);
1194         return (error);
1195     }
1196     if ((error = ma_vn_lock(fvp, LK_EXCLUSIVE, p)) != 0)
1197         goto abortit;
1198
1199     MALLOC(fname, char *, fcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1200     memcpy(fname, fcnp->cn_nameptr, fcnp->cn_namelen);
1201     fname[fcnp->cn_namelen] = '\0';
1202     MALLOC(tname, char *, tcnp->cn_namelen + 1, M_TEMP, M_WAITOK);
1203     memcpy(tname, tcnp->cn_nameptr, tcnp->cn_namelen);
1204     tname[tcnp->cn_namelen] = '\0';
1205
1206
1207     AFS_GLOCK();
1208     /* XXX use "from" or "to" creds? NFS uses "to" creds */
1209     error =
1210         afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred);
1211     AFS_GUNLOCK();
1212
1213     FREE(fname, M_TEMP);
1214     FREE(tname, M_TEMP);
1215     if (tdvp == tvp)
1216         vrele(tdvp);
1217     else
1218         vput(tdvp);
1219     if (tvp)
1220         vput(tvp);
1221     vrele(fdvp);
1222     vput(fvp);
1223     return error;
1224 }
1225
1226 int
1227 afs_vop_mkdir(ap)
1228      struct vop_mkdir_args      /* {
1229                                  * struct vnode *a_dvp;
1230                                  * struct vnode **a_vpp;
1231                                  * struct componentname *a_cnp;
1232                                  * struct vattr *a_vap;
1233                                  * } */ *ap;
1234 {
1235     register struct vnode *dvp = ap->a_dvp;
1236     register struct vattr *vap = ap->a_vap;
1237     int error = 0;
1238     struct vcache *vcp;
1239     struct thread *p = ap->a_cnp->cn_thread;
1240
1241     GETNAME();
1242 #ifdef DIAGNOSTIC
1243     if ((cnp->cn_flags & HASBUF) == 0)
1244         panic("afs_vop_mkdir: no name");
1245 #endif
1246     AFS_GLOCK();
1247     error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred);
1248     AFS_GUNLOCK();
1249     if (error) {
1250         DROPNAME();
1251         return (error);
1252     }
1253     if (vcp) {
1254         *ap->a_vpp = AFSTOV(vcp);
1255         ma_vn_lock(AFSTOV(vcp), LK_EXCLUSIVE | LK_RETRY, p);
1256     } else
1257         *ap->a_vpp = 0;
1258     DROPNAME();
1259     return error;
1260 }
1261
1262 int
1263 afs_vop_rmdir(ap)
1264      struct vop_rmdir_args      /* {
1265                                  * struct vnode *a_dvp;
1266                                  * struct vnode *a_vp;
1267                                  * struct componentname *a_cnp;
1268                                  * } */ *ap;
1269 {
1270     int error = 0;
1271     register struct vnode *dvp = ap->a_dvp;
1272
1273     GETNAME();
1274     AFS_GLOCK();
1275     error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred);
1276     AFS_GUNLOCK();
1277     DROPNAME();
1278     return error;
1279 }
1280
1281 /* struct vop_symlink_args {
1282  *      struct vnode *a_dvp;
1283  *      struct vnode **a_vpp;
1284  *      struct componentname *a_cnp;
1285  *      struct vattr *a_vap;
1286  *      char *a_target;
1287  * };
1288  */
1289 int
1290 afs_vop_symlink(struct vop_symlink_args *ap)
1291 {
1292     struct vnode *dvp;
1293     struct vnode *newvp;
1294     struct vcache *vcp;
1295     int error;
1296
1297     GETNAME();
1298     AFS_GLOCK();
1299
1300     dvp = ap->a_dvp;
1301     newvp = NULL;
1302
1303     error =
1304         afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred);
1305     if (error == 0) {
1306         error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred);
1307         if (error == 0) {
1308             newvp = AFSTOV(vcp);
1309             ma_vn_lock(newvp, LK_EXCLUSIVE | LK_RETRY, cnp->cn_thread);
1310         }
1311     }
1312     AFS_GUNLOCK();
1313     DROPNAME();
1314     *(ap->a_vpp) = newvp;
1315     return error;
1316 }
1317
1318 int
1319 afs_vop_readdir(ap)
1320      struct vop_readdir_args    /* {
1321                                  * struct vnode *a_vp;
1322                                  * struct uio *a_uio;
1323                                  * struct ucred *a_cred;
1324                                  * int *a_eofflag;
1325                                  * u_long *a_cookies;
1326                                  * int ncookies;
1327                                  * } */ *ap;
1328 {
1329     int error;
1330     off_t off;
1331 /*    printf("readdir %x cookies %x ncookies %d\n", ap->a_vp, ap->a_cookies,
1332            ap->a_ncookies); */
1333     off = ap->a_uio->uio_offset;
1334     AFS_GLOCK();
1335     error =
1336         afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag);
1337     AFS_GUNLOCK();
1338     if (!error && ap->a_ncookies != NULL) {
1339         struct uio *uio = ap->a_uio;
1340         const struct dirent *dp, *dp_start, *dp_end;
1341         int ncookies;
1342         u_long *cookies, *cookiep;
1343
1344         if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
1345             panic("afs_readdir: burned cookies");
1346         dp = (const struct dirent *)
1347             ((const char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
1348
1349         dp_end = (const struct dirent *)uio->uio_iov->iov_base;
1350         for (dp_start = dp, ncookies = 0; dp < dp_end;
1351              dp = (const struct dirent *)((const char *)dp + dp->d_reclen))
1352             ncookies++;
1353
1354         MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1355                M_WAITOK);
1356         for (dp = dp_start, cookiep = cookies; dp < dp_end;
1357              dp = (const struct dirent *)((const char *)dp + dp->d_reclen)) {
1358             off += dp->d_reclen;
1359             *cookiep++ = off;
1360         }
1361         *ap->a_cookies = cookies;
1362         *ap->a_ncookies = ncookies;
1363     }
1364
1365     return error;
1366 }
1367
1368 int
1369 afs_vop_readlink(ap)
1370      struct vop_readlink_args   /* {
1371                                  * struct vnode *a_vp;
1372                                  * struct uio *a_uio;
1373                                  * struct ucred *a_cred;
1374                                  * } */ *ap;
1375 {
1376     int error;
1377 /*    printf("readlink %x\n", ap->a_vp);*/
1378     AFS_GLOCK();
1379     error = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred);
1380     AFS_GUNLOCK();
1381     return error;
1382 }
1383
1384 extern int prtactive;
1385
1386 int
1387 afs_vop_inactive(ap)
1388      struct vop_inactive_args   /* {
1389                                  * struct vnode *a_vp;
1390                                  * struct thread *td;
1391                                  * } */ *ap;
1392 {
1393     register struct vnode *vp = ap->a_vp;
1394
1395     if (prtactive && vp->v_usecount != 0)
1396         vprint("afs_vop_inactive(): pushing active", vp);
1397
1398     AFS_GLOCK();
1399     afs_InactiveVCache(VTOAFS(vp), 0);  /* decrs ref counts */
1400     AFS_GUNLOCK();
1401 #ifndef AFS_FBSD60_ENV
1402     MA_VOP_UNLOCK(vp, 0, ap->a_td);
1403 #endif
1404     return 0;
1405 }
1406
1407 /*
1408  * struct vop_reclaim_args {
1409  *      struct vnode *a_vp;
1410  * };
1411  */
1412 int
1413 afs_vop_reclaim(struct vop_reclaim_args *ap)
1414 {
1415     /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
1416     int code, slept;
1417     struct vnode *vp = ap->a_vp;
1418     struct vcache *avc = VTOAFS(vp);
1419     int haveGlock = ISAFS_GLOCK();
1420     int haveVlock = CheckLock(&afs_xvcache);
1421
1422     if (!haveGlock)
1423         AFS_GLOCK();
1424     if (!haveVlock)
1425         ObtainWriteLock(&afs_xvcache, 901);
1426 #ifndef AFS_DISCON_ENV
1427     code = afs_FlushVCache(avc, &slept);        /* tosses our stuff from vnode */
1428 #else
1429     /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
1430     code = afs_FlushVS(avc);
1431 #endif
1432     if (!haveVlock)
1433         ReleaseWriteLock(&afs_xvcache);
1434     if (!haveGlock)
1435         AFS_GUNLOCK();
1436
1437     /*
1438      * XXX Pretend it worked, to prevent panic on shutdown
1439      * Garrett, please fix - Jim Rees
1440      */
1441     if (code) {
1442         printf("afs_vop_reclaim: afs_FlushVCache failed code %d vnode\n", code);
1443         VOP_PRINT(vp);
1444     }
1445
1446     /* basically, it must not fail */
1447     vnode_destroy_vobject(vp);
1448     vp->v_data = 0;
1449
1450     return 0;
1451 }
1452
1453 #ifndef AFS_FBSD60_ENV
1454 int
1455 afs_vop_bmap(ap)
1456      struct vop_bmap_args       /* {
1457                                  * struct vnode *a_vp;
1458                                  * daddr_t  a_bn;
1459                                  * struct vnode **a_vpp;
1460                                  * daddr_t *a_bnp;
1461                                  * int *a_runp;
1462                                  * int *a_runb;
1463                                  * } */ *ap;
1464 {
1465     if (ap->a_bnp) {
1466         *ap->a_bnp = ap->a_bn * (PAGE_SIZE / DEV_BSIZE);
1467     }
1468     if (ap->a_vpp) {
1469         *ap->a_vpp = ap->a_vp;
1470     }
1471     if (ap->a_runp != NULL)
1472         *ap->a_runp = 0;
1473     if (ap->a_runb != NULL)
1474         *ap->a_runb = 0;
1475
1476     return 0;
1477 }
1478 #endif
1479
1480 int
1481 afs_vop_strategy(ap)
1482      struct vop_strategy_args   /* {
1483                                  * struct buf *a_bp;
1484                                  * } */ *ap;
1485 {
1486     int error;
1487     AFS_GLOCK();
1488     error = afs_ustrategy(ap->a_bp, osi_curcred());
1489     AFS_GUNLOCK();
1490     return error;
1491 }
1492
1493 int
1494 afs_vop_print(ap)
1495      struct vop_print_args      /* {
1496                                  * struct vnode *a_vp;
1497                                  * } */ *ap;
1498 {
1499     register struct vnode *vp = ap->a_vp;
1500     register struct vcache *vc = VTOAFS(ap->a_vp);
1501     int s = vc->f.states;
1502
1503     printf("tag %s, fid: %d.%d.%d.%d, opens %d, writers %d", vp->v_tag,
1504            (int)vc->f.fid.Cell, (u_int) vc->f.fid.Fid.Volume,
1505            (u_int) vc->f.fid.Fid.Vnode, (u_int) vc->f.fid.Fid.Unique, vc->opens,
1506            vc->execsOrWriters);
1507     printf("\n  states%s%s%s%s%s", (s & CStatd) ? " statd" : "",
1508            (s & CRO) ? " readonly" : "", (s & CDirty) ? " dirty" : "",
1509            (s & CMAPPED) ? " mapped" : "",
1510            (s & CVFlushed) ? " flush in progress" : "");
1511     printf("\n");
1512     return 0;
1513 }
1514
1515 /*
1516  * Advisory record locking support (fcntl() POSIX style)
1517  */
1518 int
1519 afs_vop_advlock(ap)
1520      struct vop_advlock_args    /* {
1521                                  * struct vnode *a_vp;
1522                                  * caddr_t  a_id;
1523                                  * int  a_op;
1524                                  * struct flock *a_fl;
1525                                  * int  a_flags;
1526                                  * } */ *ap;
1527 {
1528     int error;
1529     struct ucred cr = *osi_curcred();
1530
1531     AFS_GLOCK();
1532     error =
1533         afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, &cr, (int)ap->a_id);
1534     AFS_GUNLOCK();
1535     return error;
1536 }