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)
83 AFS_STATCNT(afs_unmount);
85 #if defined(AFS_SUN510_ENV)
86 if (secpolicy_fs_unmount(credp, afsp) != 0) {
88 if (!afs_osi_suser(credp)) {
95 if (flag & MS_FORCE) {
100 /* We should have one reference from the caller, and one reference for the
101 * root vnode; any more and someone is still referencing something */
102 if (afsp->vfs_count > 2) {
107 /* The root vnode should have one ref for the mount; any more, and someone
108 * else is using the root vnode */
109 if (afs_globalVp && VREFCOUNT_GT(afs_globalVp, 1)) {
113 #endif /* AFS_SUN58_ENV */
123 afs_root(struct vfs *afsp, struct vnode **avpp)
125 register afs_int32 code = 0;
126 struct vrequest treq;
127 register struct vcache *tvp = 0;
129 struct proc *proc = ttoproc(curthread);
130 struct vnode *vp = afsp->vfs_vnodecovered;
133 /* Potential deadlock:
134 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
135 * and drop the v_lock if we need to make an RPC to complete this
136 * request. There used to be a deadlock on the global lock until
137 * we stopped calling iget while holding the global lock.
142 AFS_STATCNT(afs_root);
145 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
148 if (MUTEX_HELD(&vp->v_lock)) {
149 vp->v_flag |= VVFSLOCK;
151 mutex_exit(&vp->v_lock);
160 if (!(code = afs_InitReq(&treq, proc->p_cred))
161 && !(code = afs_CheckInit())) {
162 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
163 /* we really want this to stay around */
166 /* someone else got there before us! */
177 VN_HOLD(AFSTOV(tvp));
178 mutex_enter(&AFSTOV(tvp)->v_lock);
179 AFSTOV(tvp)->v_flag |= VROOT;
180 mutex_exit(&AFSTOV(tvp)->v_lock);
182 afs_globalVFS = afsp;
186 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
187 ICL_TYPE_INT32, code);
191 mutex_enter(&vp->v_lock);
192 vp->v_flag &= ~VVFSLOCK;
193 if (vp->v_flag & VVFSWAIT) {
194 vp->v_flag &= ~VVFSWAIT;
195 cv_broadcast(&vp->v_cv);
204 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
207 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
212 AFS_STATCNT(afs_statfs);
214 abp->f_frsize = 1024;
215 abp->f_favail = 9000000;
216 abp->f_bsize = afsp->vfs_bsize;
217 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
218 abp->f_ffree = 9000000;
219 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
226 afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
232 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
234 cred_t *credp = CRED();
235 struct vrequest treq;
240 AFS_STATCNT(afs_vget);
243 if (!(code = afs_InitReq(&treq, credp))) {
244 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
247 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
248 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
249 code = afs_CheckCode(code, &treq, 42);
255 /* This is only called by vfs_mount when afs is going to be mounted as root.
256 * Since we don't support diskless clients we shouldn't come here.
258 int afsmountroot = 0;
259 afs_mountroot(struct vfs *afsp, whymountroot_t why)
262 AFS_STATCNT(afs_mountroot);
268 /* afs_swapvp is called to setup swapping over the net for diskless clients.
272 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
275 AFS_STATCNT(afs_swapvp);
282 #if defined(AFS_SUN511_ENV)
283 /* The following list must always be NULL-terminated */
284 static const fs_operation_def_t afs_vfsops_template[] = {
285 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
286 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
287 VFSNAME_ROOT, { .vfs_root = afs_root },
288 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
289 VFSNAME_SYNC, { .vfs_sync = afs_sync },
290 VFSNAME_VGET, { .vfs_vget = afs_vget },
291 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
292 VFSNAME_FREEVFS, { .vfs_freevfs = fs_freevfs },
295 struct vfsops *afs_vfsopsp;
296 #elif defined(AFS_SUN510_ENV)
297 /* The following list must always be NULL-terminated */
298 const fs_operation_def_t afs_vfsops_template[] = {
299 VFSNAME_MOUNT, afs_mount,
300 VFSNAME_UNMOUNT, afs_unmount,
301 VFSNAME_ROOT, afs_root,
302 VFSNAME_STATVFS, afs_statvfs,
303 VFSNAME_SYNC, afs_sync,
304 VFSNAME_VGET, afs_vget,
305 VFSNAME_MOUNTROOT, afs_mountroot,
306 VFSNAME_FREEVFS, fs_freevfs,
309 struct vfsops *afs_vfsopsp;
311 struct vfsops Afs_vfsops = {
320 #if defined(AFS_SUN58_ENV)
328 * afsinit - intialize VFS
330 int (*ufs_iallocp) ();
331 void (*ufs_iupdatp) ();
333 void (*ufs_itimes_nolockp) ();
335 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
336 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
338 #ifndef AFS_SUN510_ENV
339 struct ill_s *ill_g_headp = 0;
344 extern struct fs_operation_def afs_vnodeops_template[];
346 #if !defined(AFS_NONFSTRANS)
347 int (*nfs_rfsdisptab_v2) ();
348 int (*nfs_rfsdisptab_v3) ();
349 int (*nfs_acldisptab_v2) ();
350 int (*nfs_acldisptab_v3) ();
352 int (*nfs_checkauth) ();
355 extern Afs_syscall();
358 do_mod_lookup(const char * mod, const char * sym)
362 ptr = modlookup(mod, sym);
364 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
371 #ifdef AFS_SUN510_ENV
372 afsinit(int fstype, char *dummy)
374 afsinit(struct vfssw *vfsswp, int fstype)
377 extern int afs_xioctl();
378 extern int afs_xsetgroups();
380 AFS_STATCNT(afsinit);
382 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
383 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
384 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
385 sysent[SYS_ioctl].sy_call = afs_xioctl;
387 #if defined(AFS_SUN57_64BIT_ENV)
388 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
389 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
390 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
391 sysent32[SYS_ioctl].sy_call = afs_xioctl;
392 #endif /* AFS_SUN57_64BIT_ENV */
394 #ifdef AFS_SUN510_ENV
395 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
397 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
398 #else /* !AFS_SUN510_ENV */
399 vfsswp->vsw_vfsops = &Afs_vfsops;
401 #endif /* !AFS_SUN510_ENV */
404 #if !defined(AFS_NONFSTRANS)
405 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
406 if (nfs_rfsdisptab_v2 != NULL) {
407 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
408 if (nfs_acldisptab_v2 != NULL) {
409 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
412 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
413 if (nfs_rfsdisptab_v3 != NULL) {
414 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
415 if (nfs_acldisptab_v3 != NULL) {
416 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
420 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
421 #endif /* !AFS_NONFSTRANS */
423 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
424 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
425 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
426 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
428 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
429 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
432 #if !defined(AFS_SUN510_ENV)
433 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
434 #endif /* !AFS_SUN510_ENV */
441 #ifdef AFS_SUN510_ENV
442 #ifdef AFS_SUN511_ENV
443 static vfsdef_t afs_vfsdef = {
451 static struct vfsdef_v3 afs_vfsdef = {
459 static struct vfssw afs_vfw = {
467 static struct sysent afssysent = {
473 /* inter-module dependencies */
474 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
477 * Info/Structs to link the afs module into the kernel
479 extern struct mod_ops mod_fsops;
480 extern struct mod_ops mod_syscallops;
482 static struct modlfs afsmodlfs = {
485 #ifdef AFS_SUN510_ENV
492 static struct modlsys afsmodlsys = {
494 "afs syscall interface",
498 /** The two structures afssysent32 and afsmodlsys32 are being added
499 * for supporting 32 bit syscalls. In Solaris 7 there are two system
500 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
501 * Since most of our user space binaries are going to be 32 bit
502 * we need to attach to sysent32 also. Note that the entry into AFS
503 * land still happens through Afs_syscall irrespective of whether we
504 * land here from sysent or sysent32
507 #if defined(AFS_SUN57_64BIT_ENV)
508 extern struct mod_ops mod_syscallops32;
510 static struct modlsys afsmodlsys32 = {
512 "afs syscall interface(32 bit)",
518 static struct modlinkage afs_modlinkage = {
521 #ifdef AFS_SUN57_64BIT_ENV
522 (void *)&afsmodlsys32,
528 /** This is the function that modload calls when loading the afs kernel
529 * extensions. The solaris modload program searches for the _init
530 * function in a module and calls it when modloading
535 char *sysn, *mod_getsysname();
537 extern char *sysbind;
538 extern struct bind *sb_hashtab[];
539 struct modctl *mp = 0;
544 if ((!(mp = mod_find_by_filename("fs", "ufs"))
545 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
546 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
551 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
554 #ifndef AFS_NONFSTRANS
555 #if defined(AFS_SUN55_ENV)
556 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
557 && !(mp = mod_find_by_filename(NULL, NFSSRV))
558 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || (mp
563 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
566 #else /* !AFS_SUN55_ENV */
567 #if defined(AFS_SUN52_ENV)
568 if ((!(mp = mod_find_by_filename("fs", "nfs"))
569 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
570 && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
575 ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
578 #endif /* AFS_SUN52_ENV */
579 #endif /* AFS_SUN55_ENV */
580 #endif /* !AFS_NONFSTRANS */
581 #if !defined(AFS_SUN58_ENV)
583 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
584 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
585 * unfortunately in Solaris 2.2 it became a local function so we have to do
586 * the read_binding_file() direct call with the appropriate text file and
587 * system call hashtable. make_syscallname actually copies "afs" to the
588 * proper slot entry and we also actually have to properly initialize the
589 * global sysent[AFS_SYSCALL] entry!
593 #define SYSBINDFILE "/etc/name_to_sysnum"
594 #endif /* SYSBINDFILE */
595 read_binding_file(SYSBINDFILE, sb_hashtab);
596 #else /* !AFS_SUN53_ENV */
597 read_binding_file(sysbind, sb_hashtab);
598 #endif /* AFS_SUN53_ENV */
599 make_syscallname("afs", AFS_SYSCALL);
601 if (sysent[AFS_SYSCALL].sy_call == nosys) {
602 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
603 sysent[AFS_SYSCALL].sy_lock =
604 (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
605 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
608 #else /* !AFS_SUN57_ENV */
609 RW_DEFAULT, DEFAULT_WT);
610 #endif /* AFS_SUN57_ENV */
613 #endif /* !AFS_SUN58_ENV */
615 osi_Init(); /* initialize global lock, etc */
617 code = mod_install(&afs_modlinkage);
622 struct modinfo *modp;
626 code = mod_info(&afs_modlinkage, modp);
638 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
639 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
640 #if defined(AFS_SUN57_64BIT_ENV)
641 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
642 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
645 code = mod_remove(&afs_modlinkage);