2 * OpenBSD specific assistance routines & VFS ops
3 * Original NetBSD version for Transarc afs by John Kohl <jtk@MIT.EDU>
4 * OpenBSD version by Jim Rees <rees@umich.edu>
11 the regents of the university of michigan
14 permission is granted to use, copy, create derivative works
15 and redistribute this software and such derivative works
16 for any purpose, so long as the name of the university of
17 michigan is not used in any advertising or publicity
18 pertaining to the use or distribution of this software
19 without specific, written prior authorization. if the
20 above copyright notice or any other identification of the
21 university of michigan is included in any copy of any
22 portion of this software, then the disclaimer below must
25 this software is provided as is, without representation
26 from the university of michigan as to its fitness for any
27 purpose, and without warranty by the university of
28 michigan of any kind, either express or implied, including
29 without limitation the implied warranties of
30 merchantability and fitness for a particular purpose. the
31 regents of the university of michigan shall not be liable
32 for any damages, including special, indirect, incidental, or
33 consequential damages, with respect to any claim arising
34 out of or in connection with the use of the software, even
35 if it has been or is hereafter advised of the possibility of
40 Copyright 1995 Massachusetts Institute of Technology. All Rights
43 You are hereby granted a worldwide, irrevocable, paid-up, right and
44 license to use, execute, display, modify, copy and distribute MIT's
45 Modifications, provided that (i) you abide by the terms and conditions
46 of the OpenAFS License Agreement, and (ii) you do not use the name
47 of MIT in any advertising or publicity without the prior written consent
48 of MIT. MIT disclaims all liability for your use of MIT's
49 Modifications. MIT's Modifications are provided "AS IS" WITHOUT
50 WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,
51 ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
56 * Some code cribbed from ffs_vfsops and other NetBSD sources, which
60 * Copyright (c) 1989, 1991, 1993, 1994
61 * The Regents of the University of California. All rights reserved.
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
66 * 1. Redistributions of source code must retain the above copyright
67 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in the
70 * documentation and/or other materials provided with the distribution.
71 * 3. All advertising materials mentioning features or use of this software
72 * must display the following acknowledgement:
73 * This product includes software developed by the University of
74 * California, Berkeley and its contributors.
75 * 4. Neither the name of the University nor the names of its contributors
76 * may be used to endorse or promote products derived from this software
77 * without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
83 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93 #include <afsconfig.h>
94 #include "afs/param.h"
99 #include "afs/sysincludes.h" /* Standard vendor system headers */
100 #include "afs/afsincludes.h" /* Afs-based standard headers */
101 #include "afs/afs_stats.h" /* statistics */
103 #include <sys/conf.h>
104 #include <sys/exec.h>
106 #include <sys/namei.h>
107 #include <sys/syscall.h>
108 #include <sys/syscallargs.h>
110 /* from /usr/src/sys/kern/vfs_subr.c */
111 extern void insmntque(struct vnode *, struct mount *);
113 extern int sys_lkmnosys(), afs3_syscall(), afs_xioctl(), Afs_xsetgroups();
115 static int lkmid = -1;
116 static int afs_badcall(struct proc *p, void *xx, register_t * yy);
117 static struct sysent old_sysent;
119 char afs_NetBSD_osname[] = "OpenBSD";
120 struct osi_vfs *afs_globalVFS;
121 struct vcache *afs_globalVp;
137 struct vfsops afs_vfsops = {
154 afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg, int followlink,
155 struct vnode **dirvpp, struct vnode **compvpp)
162 * Lookup pathname "fnamep", returning parent directory in
163 * *dirvpp (if non-null) and leaf in *compvpp. segflg says whether the
164 * pathname is user or system space.
167 niflag = followlink ? FOLLOW : NOFOLLOW;
169 niflag |= WANTPARENT; /* XXX LOCKPARENT? */
170 NDINIT(&nd, LOOKUP, niflag, segflg, fnamep, osi_curproc());
171 if ((error = namei(&nd)))
198 afs_fhtovp(mp, fhp, vpp)
217 afs_start(mp, flags, p)
222 return (0); /* nothing to do. ? */
226 afs_mount(mp, path, data, ndp, p)
227 register struct mount *mp;
230 struct nameidata *ndp;
233 /* ndp contains the mounted-from device. Just ignore it.
234 * we also don't care about our proc struct. */
237 if (mp->mnt_flag & MNT_UPDATE)
241 /* Don't allow remounts */
245 AFS_STATCNT(afs_mount);
248 #ifdef AFS_DISCON_ENV
249 /* initialize the vcache entries before we start using them */
251 /* XXX find a better place for this if possible */
252 init_vcache_entries();
255 mp->osi_vfs_bsize = 8192;
256 mp->osi_vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
257 mp->osi_vfs_fsid.val[1] = (int)AFS_VFSFSID;
259 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
260 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
261 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
262 strcpy(mp->mnt_stat.f_mntfromname, "AFS");
263 /* null terminated string "AFS" will fit, just leave it be. */
264 strcpy(mp->mnt_stat.f_fstypename, MOUNT_AFS);
266 (void)afs_statfs(mp, &mp->mnt_stat);
272 afs_unmount(afsp, flags, p)
277 extern int sys_ioctl(), sys_setgroups();
279 AFS_STATCNT(afs_unmount);
280 #ifdef AFS_DISCON_ENV
283 if (afs_globalVFS == NULL) {
284 printf("afs already unmounted\n");
288 vrele(AFSTOV(afs_globalVp));
291 vflush(afsp, NULLVP, 0); /* don't support forced */
292 afsp->mnt_data = NULL;
295 afs_cold_shutdown = 1;
296 afs_shutdown(); /* XXX */
299 /* give up syscall entries for ioctl & setgroups, which we've stolen */
300 sysent[SYS_ioctl].sy_call = sys_ioctl;
301 sysent[SYS_setgroups].sy_call = sys_setgroups;
303 /* give up the stolen syscall entry */
304 sysent[AFS_SYSCALL].sy_narg = 0;
305 sysent[AFS_SYSCALL].sy_argsize = 0;
306 sysent[AFS_SYSCALL].sy_call = afs_badcall;
308 ("AFS unmounted--use `/sbin/modunload -i %d' to unload before restarting AFS\n",
314 afs_badcall(struct proc *p, void *xx, register_t * yy)
320 afs_nbsd_getnewvnode(struct vcache *tvc)
322 while (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &tvc->v)) {
323 /* no vnodes available, force an alloc (limits be damned)! */
326 tvc->v->v_data = (void *)tvc;
330 afs_root(struct mount *mp, struct vnode **vpp)
332 struct vrequest treq;
336 AFS_STATCNT(afs_root);
339 if (!(code = afs_InitReq(&treq, osi_curcred()))
340 && !(code = afs_CheckInit())) {
341 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
343 /* There is really no reason to over-hold this bugger--it's held
344 * by the root filesystem reference. */
345 if (afs_globalVp != tvp) {
346 #ifdef AFS_DONT_OVERHOLD_GLOBALVP
348 AFS_RELE(AFSTOV(afs_globalVp));
351 VREF(AFSTOV(afs_globalVp));
353 AFSTOV(tvp)->v_flag |= VROOT;
362 vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curproc); /* return it locked */
367 afs_statfs(struct osi_vfs *afsp, struct statfs *abp)
369 AFS_STATCNT(afs_statfs);
370 abp->f_bsize = afsp->osi_vfs_bsize;
373 * Fake a high number below to satisfy programs that use the ustat (for
374 * * AIX), or statfs (for the rest) call to make sure that there's
375 * enough * space in the device partition before storing something there
378 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
379 abp->f_ffree = 9000000;
380 abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */
381 abp->f_fsid.val[1] = (int)AFS_VFSFSID;
386 afs_sync(struct osi_vfs *afsp)
388 AFS_STATCNT(afs_sync);
389 #if defined(AFS_DISCON_ENV) && !defined(AFS_OBSD_ENV)
390 /* Can't do this in OpenBSD 2.7, it faults when called from apm_suspend() */
391 store_dirty_vcaches();
403 if (vp->v_usecount < 0) {
404 vprint("bad usecount", vp);
407 error = vget(vp, lfl, curproc);
409 insmntque(vp, afs_globalVFS); /* take off free list */
413 extern struct vfsops afs_vfsops;
414 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
416 static struct vfsconf afs_vfsconf = {
426 MOD_VFS("afs", 0, &afs_vfsconf);
428 static char afsgenmem[] = "afsgenmem";
429 static char afsfidmem[] = "afsfidmem";
430 static char afsbhdrmem[] = "afsbhdrmem";
431 static char afsbfrmem[] = "afsbfrmem";
436 old_sysent = sysent[AFS_SYSCALL];
438 sysent[AFS_SYSCALL].sy_call = afs3_syscall;
439 sysent[AFS_SYSCALL].sy_narg = 6;
440 sysent[AFS_SYSCALL].sy_argsize = 6 * sizeof(long);
441 sysent[SYS_ioctl].sy_call = afs_xioctl;
442 sysent[SYS_setgroups].sy_call = Afs_xsetgroups;
449 afs_vfs_load(struct lkm_table *lkmtp, int cmd)
451 extern char *memname[];
453 vfs_opv_init_explicit(&afs_vnodeop_opv_desc);
454 vfs_opv_init_default(&afs_vnodeop_opv_desc);
455 if (memname[M_AFSGENERIC] == NULL)
456 memname[M_AFSGENERIC] = afsgenmem;
457 if (memname[M_AFSFID] == NULL)
458 memname[M_AFSFID] = afsfidmem;
459 if (memname[M_AFSBUFHDR] == NULL)
460 memname[M_AFSBUFHDR] = afsbhdrmem;
461 if (memname[M_AFSBUFFER] == NULL)
462 memname[M_AFSBUFFER] = afsbfrmem;
464 printf("OpenAFS ($Revision$) lkm loaded\n");
469 afs_vfs_unload(struct lkm_table *lktmp, int cmd)
471 extern char *memname[];
475 if (sysent[SYS_ioctl].sy_call != sys_ioctl)
478 if (memname[M_AFSGENERIC] == afsgenmem)
479 memname[M_AFSGENERIC] = NULL;
480 if (memname[M_AFSFID] == afsfidmem)
481 memname[M_AFSFID] = NULL;
482 if (memname[M_AFSBUFHDR] == afsbhdrmem)
483 memname[M_AFSBUFHDR] = NULL;
484 if (memname[M_AFSBUFFER] == afsbfrmem)
485 memname[M_AFSBUFFER] = NULL;
487 sysent[AFS_SYSCALL] = old_sysent;
488 printf("OpenAFS unloaded\n");
493 libafs_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
495 if (cmd == LKM_E_LOAD) {
496 if (strcmp(ostype, afs_NetBSD_osname)) {
497 printf("This is %s version %s\n", ostype, osrelease);
498 printf("This version of AFS is only for %s\n", afs_NetBSD_osname);
499 return EPROGMISMATCH;
501 if (sysent[AFS_SYSCALL].sy_call == afs3_syscall
502 || sysent[AFS_SYSCALL].sy_call == afs_badcall) {
503 printf("AFS already loaded\n");
507 DISPATCH(lkmtp, cmd, ver, afs_vfs_load, afs_vfs_unload, lkm_nofunc);