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;
78 struct vcache *vc, *nvc;
79 extern struct vcache *afs_vhashT[VCSIZE];
86 #if defined(AFS_SUN58_ENV)
88 afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
91 afs_unmount(struct vfs *afsp, afs_ucred_t *credp)
94 struct vcache *rootvp = NULL;
97 AFS_STATCNT(afs_unmount);
99 #if defined(AFS_SUN510_ENV)
100 if (secpolicy_fs_unmount(credp, afsp) != 0) {
102 if (!afs_osi_suser(credp)) {
109 if (flag & MS_FORCE) {
114 /* We should have one reference from the caller, and one reference for the
115 * root vnode; any more and someone is still referencing something */
116 if (afsp->vfs_count > 2) {
121 /* The root vnode should have one ref for the mount; any more, and someone
122 * else is using the root vnode */
123 if (afs_globalVp && VREFCOUNT_GT(afs_globalVp, 1)) {
128 afsp->vfs_flag |= VFS_UNMOUNTED;
129 #endif /* AFS_SUN58_ENV */
131 /* release the root vnode, which should be the last reference to us
132 * besides the caller of afs_unmount */
133 rootvp = afs_globalVp;
137 #ifndef AFS_SUN58_ENV
138 /* shutdown now, since gafs_freevfs() will not be called */
140 #endif /* !AFS_SUN58_ENV */
148 gafs_freevfs(struct vfs *afsp)
156 #endif /* AFS_SUN58_ENV */
159 afs_root(struct vfs *afsp, struct vnode **avpp)
162 struct vrequest treq;
163 struct vcache *tvp = 0;
165 struct proc *proc = ttoproc(curthread);
166 struct vnode *vp = afsp->vfs_vnodecovered;
169 /* Potential deadlock:
170 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
171 * and drop the v_lock if we need to make an RPC to complete this
172 * request. There used to be a deadlock on the global lock until
173 * we stopped calling iget while holding the global lock.
178 AFS_STATCNT(afs_root);
181 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
184 if (MUTEX_HELD(&vp->v_lock)) {
185 vp->v_flag |= VVFSLOCK;
187 mutex_exit(&vp->v_lock);
196 if (!(code = afs_InitReq(&treq, proc->p_cred))
197 && !(code = afs_CheckInit())) {
198 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
199 /* we really want this to stay around */
202 /* someone else got there before us! */
214 mutex_enter(&AFSTOV(tvp)->v_lock);
215 AFSTOV(tvp)->v_flag |= VROOT;
216 mutex_exit(&AFSTOV(tvp)->v_lock);
218 afs_globalVFS = afsp;
222 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
223 ICL_TYPE_INT32, code);
227 mutex_enter(&vp->v_lock);
228 vp->v_flag &= ~VVFSLOCK;
229 if (vp->v_flag & VVFSWAIT) {
230 vp->v_flag &= ~VVFSWAIT;
231 cv_broadcast(&vp->v_cv);
240 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
243 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
248 AFS_STATCNT(afs_statfs);
250 abp->f_frsize = 1024;
251 abp->f_favail = 9000000;
252 abp->f_bsize = afsp->vfs_bsize;
253 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
254 abp->f_ffree = 9000000;
255 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
262 afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
268 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
270 cred_t *credp = CRED();
271 struct vrequest treq;
276 AFS_STATCNT(afs_vget);
279 if (!(code = afs_InitReq(&treq, credp))) {
280 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
283 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
284 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
285 code = afs_CheckCode(code, &treq, 42);
291 /* This is only called by vfs_mount when afs is going to be mounted as root.
292 * Since we don't support diskless clients we shouldn't come here.
294 int afsmountroot = 0;
295 afs_mountroot(struct vfs *afsp, whymountroot_t why)
298 AFS_STATCNT(afs_mountroot);
304 /* afs_swapvp is called to setup swapping over the net for diskless clients.
308 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
311 AFS_STATCNT(afs_swapvp);
318 #if defined(AFS_SUN511_ENV)
319 /* The following list must always be NULL-terminated */
320 static const fs_operation_def_t afs_vfsops_template[] = {
321 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
322 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
323 VFSNAME_ROOT, { .vfs_root = afs_root },
324 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
325 VFSNAME_SYNC, { .vfs_sync = afs_sync },
326 VFSNAME_VGET, { .vfs_vget = afs_vget },
327 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
328 VFSNAME_FREEVFS, { .vfs_freevfs = gafs_freevfs },
331 struct vfsops *afs_vfsopsp;
332 #elif defined(AFS_SUN510_ENV)
333 /* The following list must always be NULL-terminated */
334 const fs_operation_def_t afs_vfsops_template[] = {
335 VFSNAME_MOUNT, afs_mount,
336 VFSNAME_UNMOUNT, afs_unmount,
337 VFSNAME_ROOT, afs_root,
338 VFSNAME_STATVFS, afs_statvfs,
339 VFSNAME_SYNC, afs_sync,
340 VFSNAME_VGET, afs_vget,
341 VFSNAME_MOUNTROOT, afs_mountroot,
342 VFSNAME_FREEVFS, gafs_freevfs,
345 struct vfsops *afs_vfsopsp;
347 struct vfsops Afs_vfsops = {
356 #if defined(AFS_SUN58_ENV)
364 * afsinit - intialize VFS
366 int (*ufs_iallocp) ();
367 void (*ufs_iupdatp) ();
369 void (*ufs_itimes_nolockp) ();
371 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
372 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
374 #ifndef AFS_SUN510_ENV
375 struct ill_s *ill_g_headp = 0;
380 extern struct fs_operation_def afs_vnodeops_template[];
382 #if !defined(AFS_NONFSTRANS)
383 int (*nfs_rfsdisptab_v2) ();
384 int (*nfs_rfsdisptab_v3) ();
385 int (*nfs_acldisptab_v2) ();
386 int (*nfs_acldisptab_v3) ();
388 int (*nfs_checkauth) ();
391 extern Afs_syscall();
394 do_mod_lookup(const char * mod, const char * sym)
398 ptr = modlookup(mod, sym);
400 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
407 #ifdef AFS_SUN510_ENV
408 afsinit(int fstype, char *dummy)
410 afsinit(struct vfssw *vfsswp, int fstype)
413 extern int afs_xioctl();
414 extern int afs_xsetgroups();
416 AFS_STATCNT(afsinit);
418 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
419 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
420 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
421 sysent[SYS_ioctl].sy_call = afs_xioctl;
423 #if defined(AFS_SUN57_64BIT_ENV)
424 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
425 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
426 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
427 sysent32[SYS_ioctl].sy_call = afs_xioctl;
428 #endif /* AFS_SUN57_64BIT_ENV */
430 #ifdef AFS_SUN510_ENV
431 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
433 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
434 #else /* !AFS_SUN510_ENV */
435 vfsswp->vsw_vfsops = &Afs_vfsops;
437 #endif /* !AFS_SUN510_ENV */
440 #if !defined(AFS_NONFSTRANS)
441 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
442 if (nfs_rfsdisptab_v2 != NULL) {
443 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
444 if (nfs_acldisptab_v2 != NULL) {
445 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
448 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
449 if (nfs_rfsdisptab_v3 != NULL) {
450 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
451 if (nfs_acldisptab_v3 != NULL) {
452 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
456 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
457 #endif /* !AFS_NONFSTRANS */
459 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
460 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
461 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
462 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
464 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
465 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
468 #if !defined(AFS_SUN510_ENV)
469 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
470 #endif /* !AFS_SUN510_ENV */
477 #ifdef AFS_SUN510_ENV
478 #ifdef AFS_SUN511_ENV
479 static vfsdef_t afs_vfsdef = {
487 static struct vfsdef_v3 afs_vfsdef = {
495 static struct vfssw afs_vfw = {
503 #ifndef AFS_SUN511_ENV
504 static struct sysent afssysent = {
509 #endif /* AFS_SUN511_ENV */
511 /* inter-module dependencies */
512 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
515 * Info/Structs to link the afs module into the kernel
517 extern struct mod_ops mod_fsops;
519 static struct modlfs afsmodlfs = {
522 #ifdef AFS_SUN510_ENV
529 #ifdef AFS_SUN511_ENV
531 extern struct modldrv afs_modldrv;
533 #else /* AFS_SUN511_ENV */
535 extern struct mod_ops mod_syscallops;
536 static struct modlsys afsmodlsys = {
538 "afs syscall interface",
542 /** The two structures afssysent32 and afsmodlsys32 are being added
543 * for supporting 32 bit syscalls. In Solaris 7 there are two system
544 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
545 * Since most of our user space binaries are going to be 32 bit
546 * we need to attach to sysent32 also. Note that the entry into AFS
547 * land still happens through Afs_syscall irrespective of whether we
548 * land here from sysent or sysent32
551 # if defined(AFS_SUN57_64BIT_ENV)
552 extern struct mod_ops mod_syscallops32;
554 static struct modlsys afsmodlsys32 = {
556 "afs syscall interface(32 bit)",
560 #endif /* !AFS_SUN511_ENV */
563 static struct modlinkage afs_modlinkage = {
566 #ifdef AFS_SUN511_ENV
567 (void *)&afs_modldrv,
570 # ifdef AFS_SUN57_64BIT_ENV
571 (void *)&afsmodlsys32,
573 #endif /* !AFS_SUN511_ENV */
577 /** This is the function that modload calls when loading the afs kernel
578 * extensions. The solaris modload program searches for the _init
579 * function in a module and calls it when modloading
584 char *sysn, *mod_getsysname();
586 extern char *sysbind;
587 extern struct bind *sb_hashtab[];
588 struct modctl *mp = 0;
593 if ((!(mp = mod_find_by_filename("fs", "ufs"))
594 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
595 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
600 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
603 #ifndef AFS_NONFSTRANS
604 #if defined(AFS_SUN55_ENV)
605 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
606 && !(mp = mod_find_by_filename(NULL, NFSSRV))
607 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))
608 && !(mp = mod_find_by_filename(NULL, NFSSRV_AMD64))) || (mp
613 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
616 #else /* !AFS_SUN55_ENV */
617 #if defined(AFS_SUN52_ENV)
618 if ((!(mp = mod_find_by_filename("fs", "nfs"))
619 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
620 && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
625 ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
628 #endif /* AFS_SUN52_ENV */
629 #endif /* AFS_SUN55_ENV */
630 #endif /* !AFS_NONFSTRANS */
632 #ifndef AFS_SUN511_ENV
633 /* syscall initialization stff */
635 # if !defined(AFS_SUN58_ENV)
637 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
638 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
639 * unfortunately in Solaris 2.2 it became a local function so we have to do
640 * the read_binding_file() direct call with the appropriate text file and
641 * system call hashtable. make_syscallname actually copies "afs" to the
642 * proper slot entry and we also actually have to properly initialize the
643 * global sysent[AFS_SYSCALL] entry!
645 # ifdef AFS_SUN53_ENV
647 # define SYSBINDFILE "/etc/name_to_sysnum"
648 # endif /* SYSBINDFILE */
649 read_binding_file(SYSBINDFILE, sb_hashtab);
650 # else /* !AFS_SUN53_ENV */
651 read_binding_file(sysbind, sb_hashtab);
652 # endif /* AFS_SUN53_ENV */
653 make_syscallname("afs", AFS_SYSCALL);
655 if (sysent[AFS_SYSCALL].sy_call == nosys) {
656 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
657 sysent[AFS_SYSCALL].sy_lock =
658 (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
659 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
660 # ifdef AFS_SUN57_ENV
662 # else /* !AFS_SUN57_ENV */
663 RW_DEFAULT, DEFAULT_WT);
664 # endif /* AFS_SUN57_ENV */
667 # endif /* !AFS_SUN58_ENV */
668 #endif /* !AFS_SUN511_ENV */
670 osi_Init(); /* initialize global lock, etc */
672 code = mod_install(&afs_modlinkage);
677 struct modinfo *modp;
681 code = mod_info(&afs_modlinkage, modp);
693 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
694 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
695 #if defined(AFS_SUN57_64BIT_ENV)
696 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
697 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
700 code = mod_remove(&afs_modlinkage);