2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * osi_vfsops.c for SOLARIS
13 #include <afsconfig.h>
14 #include "afs/param.h"
17 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "afsincludes.h" /* Afs-based standard headers */
19 #include "afs/afs_stats.h" /* statistics stuff */
21 #include "h/syscall.h"
22 #if defined(AFS_SUN511_ENV)
23 #include <sys/vfs_opreg.h>
27 #include <sys/mount.h>
29 struct vfs *afs_globalVFS = 0;
30 struct vcache *afs_globalVp = 0;
32 #if defined(AFS_SUN5_64BIT_ENV)
33 extern struct sysent sysent32[];
39 afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
45 AFS_STATCNT(afs_mount);
47 #if defined(AFS_SUN510_ENV)
48 if (secpolicy_fs_mount(credp, amvp, afsp) != 0) {
50 if (!afs_osi_suser(credp)) {
55 afsp->vfs_fstype = afsfstype;
57 if (afs_globalVFS) { /* Don't allow remounts. */
63 afsp->vfs_bsize = 8192;
64 afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
65 afsp->vfs_fsid.val[1] = AFS_VFSFSID;
66 afsp->vfs_dev = AFS_VFSMAGIC;
76 struct vcache *vc, *nvc;
77 extern struct vcache *afs_vhashT[VCSIZE];
85 afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
87 struct vcache *rootvp = NULL;
90 AFS_STATCNT(afs_unmount);
92 #if defined(AFS_SUN510_ENV)
93 if (secpolicy_fs_unmount(credp, afsp) != 0) {
95 if (!afs_osi_suser(credp)) {
101 if (flag & MS_FORCE) {
106 /* We should have one reference from the caller, and one reference for the
107 * root vnode; any more and someone is still referencing something */
108 if (afsp->vfs_count > 2) {
113 /* The root vnode should have one ref for the mount; any more, and someone
114 * else is using the root vnode */
115 if (afs_globalVp && VREFCOUNT_GT(afs_globalVp, 1)) {
120 afsp->vfs_flag |= VFS_UNMOUNTED;
122 /* release the root vnode, which should be the last reference to us
123 * besides the caller of afs_unmount */
124 rootvp = afs_globalVp;
133 gafs_freevfs(struct vfs *afsp)
143 afs_root(struct vfs *afsp, struct vnode **avpp)
146 struct vrequest treq;
147 struct vcache *tvp = 0;
149 struct proc *proc = ttoproc(curthread);
150 struct vnode *vp = afsp->vfs_vnodecovered;
153 /* Potential deadlock:
154 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
155 * and drop the v_lock if we need to make an RPC to complete this
156 * request. There used to be a deadlock on the global lock until
157 * we stopped calling iget while holding the global lock.
162 AFS_STATCNT(afs_root);
165 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
168 if (MUTEX_HELD(&vp->v_lock)) {
169 vp->v_flag |= VVFSLOCK;
171 mutex_exit(&vp->v_lock);
180 if (!(code = afs_InitReq(&treq, proc->p_cred))
181 && !(code = afs_CheckInit())) {
182 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
183 /* we really want this to stay around */
186 /* someone else got there before us! */
198 mutex_enter(&AFSTOV(tvp)->v_lock);
199 AFSTOV(tvp)->v_flag |= VROOT;
200 mutex_exit(&AFSTOV(tvp)->v_lock);
202 afs_globalVFS = afsp;
206 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
207 ICL_TYPE_INT32, code);
211 mutex_enter(&vp->v_lock);
212 vp->v_flag &= ~VVFSLOCK;
213 if (vp->v_flag & VVFSWAIT) {
214 vp->v_flag &= ~VVFSWAIT;
215 cv_broadcast(&vp->v_cv);
223 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
227 AFS_STATCNT(afs_statfs);
229 abp->f_frsize = 1024;
230 abp->f_favail = 9000000;
231 abp->f_bsize = afsp->vfs_bsize;
232 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
233 abp->f_ffree = 9000000;
234 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
241 afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
247 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
249 cred_t *credp = CRED();
250 struct vrequest treq;
255 AFS_STATCNT(afs_vget);
258 if (!(code = afs_InitReq(&treq, credp))) {
259 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
262 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
263 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
264 code = afs_CheckCode(code, &treq, 42);
270 /* This is only called by vfs_mount when afs is going to be mounted as root.
271 * Since we don't support diskless clients we shouldn't come here.
273 int afsmountroot = 0;
274 afs_mountroot(struct vfs *afsp, whymountroot_t why)
277 AFS_STATCNT(afs_mountroot);
283 /* afs_swapvp is called to setup swapping over the net for diskless clients.
287 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
290 AFS_STATCNT(afs_swapvp);
297 #if defined(AFS_SUN511_ENV)
298 /* The following list must always be NULL-terminated */
299 static const fs_operation_def_t afs_vfsops_template[] = {
300 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
301 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
302 VFSNAME_ROOT, { .vfs_root = afs_root },
303 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
304 VFSNAME_SYNC, { .vfs_sync = afs_sync },
305 VFSNAME_VGET, { .vfs_vget = afs_vget },
306 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
307 VFSNAME_FREEVFS, { .vfs_freevfs = gafs_freevfs },
310 struct vfsops *afs_vfsopsp;
311 #elif defined(AFS_SUN510_ENV)
312 /* The following list must always be NULL-terminated */
313 const fs_operation_def_t afs_vfsops_template[] = {
314 VFSNAME_MOUNT, afs_mount,
315 VFSNAME_UNMOUNT, afs_unmount,
316 VFSNAME_ROOT, afs_root,
317 VFSNAME_STATVFS, afs_statvfs,
318 VFSNAME_SYNC, afs_sync,
319 VFSNAME_VGET, afs_vget,
320 VFSNAME_MOUNTROOT, afs_mountroot,
321 VFSNAME_FREEVFS, gafs_freevfs,
324 struct vfsops *afs_vfsopsp;
326 struct vfsops Afs_vfsops = {
341 * afsinit - intialize VFS
343 int (*ufs_iallocp) ();
344 void (*ufs_iupdatp) ();
346 void (*ufs_itimes_nolockp) ();
348 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
349 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
351 #ifndef AFS_SUN510_ENV
352 struct ill_s *ill_g_headp = 0;
357 extern struct fs_operation_def afs_vnodeops_template[];
359 #if !defined(AFS_NONFSTRANS)
360 int (*nfs_rfsdisptab_v2) ();
361 int (*nfs_rfsdisptab_v3) ();
362 int (*nfs_acldisptab_v2) ();
363 int (*nfs_acldisptab_v3) ();
365 int (*nfs_checkauth) ();
368 extern Afs_syscall();
371 do_mod_lookup(const char * mod, const char * sym)
375 ptr = modlookup(mod, sym);
377 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
384 #ifdef AFS_SUN510_ENV
385 afsinit(int fstype, char *dummy)
387 afsinit(struct vfssw *vfsswp, int fstype)
390 extern int afs_xioctl();
391 extern int afs_xsetgroups();
393 AFS_STATCNT(afsinit);
395 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
396 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
397 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
398 sysent[SYS_ioctl].sy_call = afs_xioctl;
400 #if defined(AFS_SUN5_64BIT_ENV)
401 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
402 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
403 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
404 sysent32[SYS_ioctl].sy_call = afs_xioctl;
405 #endif /* AFS_SUN5_64BIT_ENV */
407 #ifdef AFS_SUN510_ENV
408 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
410 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
411 #else /* !AFS_SUN510_ENV */
412 vfsswp->vsw_vfsops = &Afs_vfsops;
414 #endif /* !AFS_SUN510_ENV */
417 #if !defined(AFS_NONFSTRANS)
418 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
419 if (nfs_rfsdisptab_v2 != NULL) {
420 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
421 if (nfs_acldisptab_v2 != NULL) {
422 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
425 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
426 if (nfs_rfsdisptab_v3 != NULL) {
427 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
428 if (nfs_acldisptab_v3 != NULL) {
429 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
433 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
434 #endif /* !AFS_NONFSTRANS */
436 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
437 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
438 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
439 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
441 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
442 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
445 #if !defined(AFS_SUN510_ENV)
446 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
447 #endif /* !AFS_SUN510_ENV */
454 #ifdef AFS_SUN510_ENV
455 #ifdef AFS_SUN511_ENV
456 static vfsdef_t afs_vfsdef = {
464 static struct vfsdef_v3 afs_vfsdef = {
472 static struct vfssw afs_vfw = {
480 #ifndef AFS_SUN511_ENV
481 static struct sysent afssysent = {
486 #endif /* AFS_SUN511_ENV */
488 /* inter-module dependencies */
489 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
492 * Info/Structs to link the afs module into the kernel
494 extern struct mod_ops mod_fsops;
496 static struct modlfs afsmodlfs = {
499 #ifdef AFS_SUN510_ENV
506 #ifdef AFS_SUN511_ENV
508 extern struct modldrv afs_modldrv;
510 #else /* AFS_SUN511_ENV */
512 extern struct mod_ops mod_syscallops;
513 static struct modlsys afsmodlsys = {
515 "afs syscall interface",
519 /** The two structures afssysent32 and afsmodlsys32 are being added
520 * for supporting 32 bit syscalls. In Solaris 7 there are two system
521 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
522 * Since most of our user space binaries are going to be 32 bit
523 * we need to attach to sysent32 also. Note that the entry into AFS
524 * land still happens through Afs_syscall irrespective of whether we
525 * land here from sysent or sysent32
528 # if defined(AFS_SUN5_64BIT_ENV)
529 extern struct mod_ops mod_syscallops32;
531 static struct modlsys afsmodlsys32 = {
533 "afs syscall interface(32 bit)",
537 #endif /* !AFS_SUN511_ENV */
540 static struct modlinkage afs_modlinkage = {
543 #ifdef AFS_SUN511_ENV
544 (void *)&afs_modldrv,
547 # ifdef AFS_SUN5_64BIT_ENV
548 (void *)&afsmodlsys32,
550 #endif /* !AFS_SUN511_ENV */
558 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
559 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
560 #if defined(AFS_SUN5_64BIT_ENV)
561 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
562 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
567 /** This is the function that modload calls when loading the afs kernel
568 * extensions. The solaris modload program searches for the _init
569 * function in a module and calls it when modloading
574 char *sysn, *mod_getsysname();
576 extern char *sysbind;
577 extern struct bind *sb_hashtab[];
578 struct modctl *mp = 0;
583 if ((!(mp = mod_find_by_filename("fs", "ufs"))
584 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
585 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
590 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
593 #ifndef AFS_NONFSTRANS
594 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
595 && !(mp = mod_find_by_filename(NULL, NFSSRV))
596 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))
597 && !(mp = mod_find_by_filename(NULL, NFSSRV_AMD64))) || (mp
602 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
605 #endif /* !AFS_NONFSTRANS */
608 osi_Init(); /* initialize global lock, etc */
610 code = mod_install(&afs_modlinkage);
612 /* we failed to load, so make sure we don't leave behind any
613 * references to our syscall handlers */
620 struct modinfo *modp;
624 code = mod_info(&afs_modlinkage, modp);
636 code = mod_remove(&afs_modlinkage);