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>
28 # include <sys/mount.h>
31 struct vfs *afs_globalVFS = 0;
32 struct vcache *afs_globalVp = 0;
34 #if defined(AFS_SUN57_64BIT_ENV)
35 extern struct sysent sysent32[];
41 afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
47 AFS_STATCNT(afs_mount);
49 #if defined(AFS_SUN510_ENV)
50 if (secpolicy_fs_mount(credp, amvp, afsp) != 0) {
52 if (!afs_osi_suser(credp)) {
57 afsp->vfs_fstype = afsfstype;
59 if (afs_globalVFS) { /* Don't allow remounts. */
65 afsp->vfs_bsize = 8192;
66 afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
67 afsp->vfs_fsid.val[1] = AFS_VFSFSID;
68 afsp->vfs_dev = AFS_VFSMAGIC;
74 #if defined(AFS_SUN58_ENV)
76 afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
79 afs_unmount(struct vfs *afsp, afs_ucred_t *credp)
82 struct vcache *rootvp = NULL;
85 AFS_STATCNT(afs_unmount);
87 #if defined(AFS_SUN510_ENV)
88 if (secpolicy_fs_unmount(credp, afsp) != 0) {
90 if (!afs_osi_suser(credp)) {
97 if (flag & MS_FORCE) {
102 /* We should have one reference from the caller, and one reference for the
103 * root vnode; any more and someone is still referencing something */
104 if (afsp->vfs_count > 2) {
109 /* The root vnode should have one ref for the mount; any more, and someone
110 * else is using the root vnode */
111 if (afs_globalVp && VREFCOUNT_GT(afs_globalVp, 1)) {
116 afsp->vfs_flag |= VFS_UNMOUNTED;
117 #endif /* AFS_SUN58_ENV */
119 /* release the root vnode, which should be the last reference to us
120 * besides the caller of afs_unmount */
121 rootvp = afs_globalVp;
125 #ifndef AFS_SUN58_ENV
126 /* shutdown now, since afs_freevfs() will not be called */
129 #endif /* !AFS_SUN58_ENV */
137 afs_freevfs(struct vfs *afsp)
146 #endif /* AFS_SUN58_ENV */
149 afs_root(struct vfs *afsp, struct vnode **avpp)
152 struct vrequest treq;
153 struct vcache *tvp = 0;
155 struct proc *proc = ttoproc(curthread);
156 struct vnode *vp = afsp->vfs_vnodecovered;
159 /* Potential deadlock:
160 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
161 * and drop the v_lock if we need to make an RPC to complete this
162 * request. There used to be a deadlock on the global lock until
163 * we stopped calling iget while holding the global lock.
168 AFS_STATCNT(afs_root);
171 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
174 if (MUTEX_HELD(&vp->v_lock)) {
175 vp->v_flag |= VVFSLOCK;
177 mutex_exit(&vp->v_lock);
186 if (!(code = afs_InitReq(&treq, proc->p_cred))
187 && !(code = afs_CheckInit())) {
188 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
189 /* we really want this to stay around */
192 /* someone else got there before us! */
204 mutex_enter(&AFSTOV(tvp)->v_lock);
205 AFSTOV(tvp)->v_flag |= VROOT;
206 mutex_exit(&AFSTOV(tvp)->v_lock);
208 afs_globalVFS = afsp;
212 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
213 ICL_TYPE_INT32, code);
217 mutex_enter(&vp->v_lock);
218 vp->v_flag &= ~VVFSLOCK;
219 if (vp->v_flag & VVFSWAIT) {
220 vp->v_flag &= ~VVFSWAIT;
221 cv_broadcast(&vp->v_cv);
230 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
233 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
238 AFS_STATCNT(afs_statfs);
240 abp->f_frsize = 1024;
241 abp->f_favail = 9000000;
242 abp->f_bsize = afsp->vfs_bsize;
243 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
244 abp->f_ffree = 9000000;
245 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
252 afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
258 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
260 cred_t *credp = CRED();
261 struct vrequest treq;
266 AFS_STATCNT(afs_vget);
269 if (!(code = afs_InitReq(&treq, credp))) {
270 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
273 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
274 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
275 code = afs_CheckCode(code, &treq, 42);
281 /* This is only called by vfs_mount when afs is going to be mounted as root.
282 * Since we don't support diskless clients we shouldn't come here.
284 int afsmountroot = 0;
285 afs_mountroot(struct vfs *afsp, whymountroot_t why)
288 AFS_STATCNT(afs_mountroot);
294 /* afs_swapvp is called to setup swapping over the net for diskless clients.
298 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
301 AFS_STATCNT(afs_swapvp);
308 #if defined(AFS_SUN511_ENV)
309 /* The following list must always be NULL-terminated */
310 static const fs_operation_def_t afs_vfsops_template[] = {
311 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
312 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
313 VFSNAME_ROOT, { .vfs_root = afs_root },
314 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
315 VFSNAME_SYNC, { .vfs_sync = afs_sync },
316 VFSNAME_VGET, { .vfs_vget = afs_vget },
317 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
318 VFSNAME_FREEVFS, { .vfs_freevfs = afs_freevfs },
321 struct vfsops *afs_vfsopsp;
322 #elif defined(AFS_SUN510_ENV)
323 /* The following list must always be NULL-terminated */
324 const fs_operation_def_t afs_vfsops_template[] = {
325 VFSNAME_MOUNT, afs_mount,
326 VFSNAME_UNMOUNT, afs_unmount,
327 VFSNAME_ROOT, afs_root,
328 VFSNAME_STATVFS, afs_statvfs,
329 VFSNAME_SYNC, afs_sync,
330 VFSNAME_VGET, afs_vget,
331 VFSNAME_MOUNTROOT, afs_mountroot,
332 VFSNAME_FREEVFS, afs_freevfs,
335 struct vfsops *afs_vfsopsp;
337 struct vfsops Afs_vfsops = {
346 #if defined(AFS_SUN58_ENV)
354 * afsinit - intialize VFS
356 int (*ufs_iallocp) ();
357 void (*ufs_iupdatp) ();
359 void (*ufs_itimes_nolockp) ();
361 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
362 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
364 #ifndef AFS_SUN510_ENV
365 struct ill_s *ill_g_headp = 0;
370 extern struct fs_operation_def afs_vnodeops_template[];
372 #if !defined(AFS_NONFSTRANS)
373 int (*nfs_rfsdisptab_v2) ();
374 int (*nfs_rfsdisptab_v3) ();
375 int (*nfs_acldisptab_v2) ();
376 int (*nfs_acldisptab_v3) ();
378 int (*nfs_checkauth) ();
381 extern Afs_syscall();
384 do_mod_lookup(const char * mod, const char * sym)
388 ptr = modlookup(mod, sym);
390 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
397 #ifdef AFS_SUN510_ENV
398 afsinit(int fstype, char *dummy)
400 afsinit(struct vfssw *vfsswp, int fstype)
403 extern int afs_xioctl();
404 extern int afs_xsetgroups();
406 AFS_STATCNT(afsinit);
408 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
409 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
410 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
411 sysent[SYS_ioctl].sy_call = afs_xioctl;
413 #if defined(AFS_SUN57_64BIT_ENV)
414 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
415 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
416 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
417 sysent32[SYS_ioctl].sy_call = afs_xioctl;
418 #endif /* AFS_SUN57_64BIT_ENV */
420 #ifdef AFS_SUN510_ENV
421 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
423 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
424 #else /* !AFS_SUN510_ENV */
425 vfsswp->vsw_vfsops = &Afs_vfsops;
427 #endif /* !AFS_SUN510_ENV */
430 #if !defined(AFS_NONFSTRANS)
431 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
432 if (nfs_rfsdisptab_v2 != NULL) {
433 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
434 if (nfs_acldisptab_v2 != NULL) {
435 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
438 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
439 if (nfs_rfsdisptab_v3 != NULL) {
440 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
441 if (nfs_acldisptab_v3 != NULL) {
442 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
446 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
447 #endif /* !AFS_NONFSTRANS */
449 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
450 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
451 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
452 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
454 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
455 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
458 #if !defined(AFS_SUN510_ENV)
459 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
460 #endif /* !AFS_SUN510_ENV */
467 #ifdef AFS_SUN510_ENV
468 #ifdef AFS_SUN511_ENV
469 static vfsdef_t afs_vfsdef = {
477 static struct vfsdef_v3 afs_vfsdef = {
485 static struct vfssw afs_vfw = {
493 static struct sysent afssysent = {
499 /* inter-module dependencies */
500 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
503 * Info/Structs to link the afs module into the kernel
505 extern struct mod_ops mod_fsops;
506 extern struct mod_ops mod_syscallops;
508 static struct modlfs afsmodlfs = {
511 #ifdef AFS_SUN510_ENV
518 static struct modlsys afsmodlsys = {
520 "afs syscall interface",
524 /** The two structures afssysent32 and afsmodlsys32 are being added
525 * for supporting 32 bit syscalls. In Solaris 7 there are two system
526 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
527 * Since most of our user space binaries are going to be 32 bit
528 * we need to attach to sysent32 also. Note that the entry into AFS
529 * land still happens through Afs_syscall irrespective of whether we
530 * land here from sysent or sysent32
533 #if defined(AFS_SUN57_64BIT_ENV)
534 extern struct mod_ops mod_syscallops32;
536 static struct modlsys afsmodlsys32 = {
538 "afs syscall interface(32 bit)",
544 static struct modlinkage afs_modlinkage = {
547 #ifdef AFS_SUN57_64BIT_ENV
548 (void *)&afsmodlsys32,
554 /** This is the function that modload calls when loading the afs kernel
555 * extensions. The solaris modload program searches for the _init
556 * function in a module and calls it when modloading
561 char *sysn, *mod_getsysname();
563 extern char *sysbind;
564 extern struct bind *sb_hashtab[];
565 struct modctl *mp = 0;
570 if ((!(mp = mod_find_by_filename("fs", "ufs"))
571 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
572 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
577 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
580 #ifndef AFS_NONFSTRANS
581 #if defined(AFS_SUN55_ENV)
582 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
583 && !(mp = mod_find_by_filename(NULL, NFSSRV))
584 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))
585 && !(mp = mod_find_by_filename(NULL, NFSSRV_AMD64))) || (mp
590 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
593 #else /* !AFS_SUN55_ENV */
594 #if defined(AFS_SUN52_ENV)
595 if ((!(mp = mod_find_by_filename("fs", "nfs"))
596 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
597 && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
602 ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
605 #endif /* AFS_SUN52_ENV */
606 #endif /* AFS_SUN55_ENV */
607 #endif /* !AFS_NONFSTRANS */
608 #if !defined(AFS_SUN58_ENV)
610 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
611 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
612 * unfortunately in Solaris 2.2 it became a local function so we have to do
613 * the read_binding_file() direct call with the appropriate text file and
614 * system call hashtable. make_syscallname actually copies "afs" to the
615 * proper slot entry and we also actually have to properly initialize the
616 * global sysent[AFS_SYSCALL] entry!
620 #define SYSBINDFILE "/etc/name_to_sysnum"
621 #endif /* SYSBINDFILE */
622 read_binding_file(SYSBINDFILE, sb_hashtab);
623 #else /* !AFS_SUN53_ENV */
624 read_binding_file(sysbind, sb_hashtab);
625 #endif /* AFS_SUN53_ENV */
626 make_syscallname("afs", AFS_SYSCALL);
628 if (sysent[AFS_SYSCALL].sy_call == nosys) {
629 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
630 sysent[AFS_SYSCALL].sy_lock =
631 (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
632 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
635 #else /* !AFS_SUN57_ENV */
636 RW_DEFAULT, DEFAULT_WT);
637 #endif /* AFS_SUN57_ENV */
640 #endif /* !AFS_SUN58_ENV */
642 osi_Init(); /* initialize global lock, etc */
644 code = mod_install(&afs_modlinkage);
649 struct modinfo *modp;
653 code = mod_info(&afs_modlinkage, modp);
665 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
666 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
667 #if defined(AFS_SUN57_64BIT_ENV)
668 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
669 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
672 code = mod_remove(&afs_modlinkage);