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"
19 #include "afs/sysincludes.h" /* Standard vendor system headers */
20 #include "afsincludes.h" /* Afs-based standard headers */
21 #include "afs/afs_stats.h" /* statistics stuff */
23 #include "h/syscall.h"
24 #if defined(AFS_SUN511_ENV)
25 #include <sys/vfs_opreg.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,
42 struct AFS_UCRED *credp)
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, struct AFS_UCRED *credp)
79 afs_unmount(struct vfs *afsp, struct AFS_UCRED *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)) {
101 afs_root(struct vfs *afsp, struct vnode **avpp)
103 register afs_int32 code = 0;
104 struct vrequest treq;
105 register struct vcache *tvp = 0;
106 struct proc *proc = ttoproc(curthread);
107 struct vnode *vp = afsp->vfs_vnodecovered;
110 /* Potential deadlock:
111 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
112 * and drop the v_lock if we need to make an RPC to complete this
113 * request. There used to be a deadlock on the global lock until
114 * we stopped calling iget while holding the global lock.
119 AFS_STATCNT(afs_root);
121 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
124 if (MUTEX_HELD(&vp->v_lock)) {
125 vp->v_flag |= VVFSLOCK;
127 mutex_exit(&vp->v_lock);
131 afs_PutVCache(afs_globalVp);
135 if (!(code = afs_InitReq(&treq, proc->p_cred))
136 && !(code = afs_CheckInit())) {
137 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
138 /* we really want this to stay around */
146 VN_HOLD(AFSTOV(tvp));
147 mutex_enter(&AFSTOV(tvp)->v_lock);
148 AFSTOV(tvp)->v_flag |= VROOT;
149 mutex_exit(&AFSTOV(tvp)->v_lock);
151 afs_globalVFS = afsp;
155 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
156 ICL_TYPE_INT32, code);
160 mutex_enter(&vp->v_lock);
161 vp->v_flag &= ~VVFSLOCK;
162 if (vp->v_flag & VVFSWAIT) {
163 vp->v_flag &= ~VVFSWAIT;
164 cv_broadcast(&vp->v_cv);
173 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
176 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
181 AFS_STATCNT(afs_statfs);
183 abp->f_frsize = 1024;
184 abp->f_favail = 9000000;
185 abp->f_bsize = afsp->vfs_bsize;
186 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
187 abp->f_ffree = 9000000;
188 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
195 afs_sync(struct vfs *afsp, short flags, struct AFS_UCRED *credp)
201 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
203 cred_t *credp = CRED();
204 struct vrequest treq;
209 AFS_STATCNT(afs_vget);
212 if (!(code = afs_InitReq(&treq, credp))) {
213 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
216 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
217 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
218 code = afs_CheckCode(code, &treq, 42);
224 /* This is only called by vfs_mount when afs is going to be mounted as root.
225 * Since we don't support diskless clients we shouldn't come here.
227 int afsmountroot = 0;
228 afs_mountroot(struct vfs *afsp, whymountroot_t why)
231 AFS_STATCNT(afs_mountroot);
237 /* afs_swapvp is called to setup swapping over the net for diskless clients.
241 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
244 AFS_STATCNT(afs_swapvp);
251 #if defined(AFS_SUN511_ENV)
252 /* The following list must always be NULL-terminated */
253 static const fs_operation_def_t afs_vfsops_template[] = {
254 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
255 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
256 VFSNAME_ROOT, { .vfs_root = afs_root },
257 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
258 VFSNAME_SYNC, { .vfs_sync = afs_sync },
259 VFSNAME_VGET, { .vfs_vget = afs_vget },
260 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
261 VFSNAME_FREEVFS, { .vfs_freevfs = fs_freevfs },
264 struct vfsops *afs_vfsopsp;
265 #elif defined(AFS_SUN510_ENV)
266 /* The following list must always be NULL-terminated */
267 const fs_operation_def_t afs_vfsops_template[] = {
268 VFSNAME_MOUNT, afs_mount,
269 VFSNAME_UNMOUNT, afs_unmount,
270 VFSNAME_ROOT, afs_root,
271 VFSNAME_STATVFS, afs_statvfs,
272 VFSNAME_SYNC, afs_sync,
273 VFSNAME_VGET, afs_vget,
274 VFSNAME_MOUNTROOT, afs_mountroot,
275 VFSNAME_FREEVFS, fs_freevfs,
278 struct vfsops *afs_vfsopsp;
280 struct vfsops Afs_vfsops = {
289 #if defined(AFS_SUN58_ENV)
297 * afsinit - intialize VFS
299 int (*ufs_iallocp) ();
300 void (*ufs_iupdatp) ();
302 void (*ufs_itimes_nolockp) ();
304 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
305 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
307 #ifndef AFS_SUN510_ENV
308 struct ill_s *ill_g_headp = 0;
313 extern struct fs_operation_def afs_vnodeops_template[];
315 #if !defined(AFS_NONFSTRANS)
316 int (*nfs_rfsdisptab_v2) ();
317 int (*nfs_rfsdisptab_v3) ();
318 int (*nfs_acldisptab_v2) ();
319 int (*nfs_acldisptab_v3) ();
321 int (*nfs_checkauth) ();
324 extern Afs_syscall();
327 do_mod_lookup(const char * mod, const char * sym)
331 ptr = modlookup(mod, sym);
333 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
340 #ifdef AFS_SUN510_ENV
341 afsinit(int fstype, char *dummy)
343 afsinit(struct vfssw *vfsswp, int fstype)
346 extern int afs_xioctl();
347 extern int afs_xsetgroups();
349 AFS_STATCNT(afsinit);
351 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
352 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
353 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
354 sysent[SYS_ioctl].sy_call = afs_xioctl;
356 #if defined(AFS_SUN57_64BIT_ENV)
357 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
358 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
359 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
360 sysent32[SYS_ioctl].sy_call = afs_xioctl;
361 #endif /* AFS_SUN57_64BIT_ENV */
363 #ifdef AFS_SUN510_ENV
364 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
366 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
367 #else /* !AFS_SUN510_ENV */
368 vfsswp->vsw_vfsops = &Afs_vfsops;
370 #endif /* !AFS_SUN510_ENV */
373 #if !defined(AFS_NONFSTRANS)
374 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
375 if (nfs_rfsdisptab_v2 != NULL) {
376 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
377 if (nfs_acldisptab_v2 != NULL) {
378 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
381 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
382 if (nfs_rfsdisptab_v3 != NULL) {
383 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
384 if (nfs_acldisptab_v3 != NULL) {
385 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
389 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
390 #endif /* !AFS_NONFSTRANS */
392 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
393 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
394 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
395 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
397 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
398 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
401 #if !defined(AFS_SUN510_ENV)
402 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
403 #endif /* !AFS_SUN510_ENV */
410 #ifdef AFS_SUN510_ENV
411 static struct vfsdef_v3 afs_vfsdef = {
418 static struct vfssw afs_vfw = {
426 static struct sysent afssysent = {
432 /* inter-module dependencies */
433 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
436 * Info/Structs to link the afs module into the kernel
438 extern struct mod_ops mod_fsops;
439 extern struct mod_ops mod_syscallops;
441 static struct modlfs afsmodlfs = {
444 #ifdef AFS_SUN510_ENV
451 static struct modlsys afsmodlsys = {
453 "afs syscall interface",
457 /** The two structures afssysent32 and afsmodlsys32 are being added
458 * for supporting 32 bit syscalls. In Solaris 7 there are two system
459 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
460 * Since most of our user space binaries are going to be 32 bit
461 * we need to attach to sysent32 also. Note that the entry into AFS
462 * land still happens through Afs_syscall irrespective of whether we
463 * land here from sysent or sysent32
466 #if defined(AFS_SUN57_64BIT_ENV)
467 extern struct mod_ops mod_syscallops32;
469 static struct modlsys afsmodlsys32 = {
471 "afs syscall interface(32 bit)",
477 static struct modlinkage afs_modlinkage = {
480 #ifdef AFS_SUN57_64BIT_ENV
481 (void *)&afsmodlsys32,
487 /** This is the function that modload calls when loading the afs kernel
488 * extensions. The solaris modload program searches for the _init
489 * function in a module and calls it when modloading
494 char *sysn, *mod_getsysname();
496 extern char *sysbind;
497 extern struct bind *sb_hashtab[];
498 struct modctl *mp = 0;
503 if ((!(mp = mod_find_by_filename("fs", "ufs"))
504 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
505 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
510 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
513 #ifndef AFS_NONFSTRANS
514 #if defined(AFS_SUN55_ENV)
515 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
516 && !(mp = mod_find_by_filename(NULL, NFSSRV))
517 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || (mp
522 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
525 #else /* !AFS_SUN55_ENV */
526 #if defined(AFS_SUN52_ENV)
527 if ((!(mp = mod_find_by_filename("fs", "nfs"))
528 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
529 && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
534 ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
537 #endif /* AFS_SUN52_ENV */
538 #endif /* AFS_SUN55_ENV */
539 #endif /* !AFS_NONFSTRANS */
540 #if !defined(AFS_SUN58_ENV)
542 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
543 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
544 * unfortunately in Solaris 2.2 it became a local function so we have to do
545 * the read_binding_file() direct call with the appropriate text file and
546 * system call hashtable. make_syscallname actually copies "afs" to the
547 * proper slot entry and we also actually have to properly initialize the
548 * global sysent[AFS_SYSCALL] entry!
552 #define SYSBINDFILE "/etc/name_to_sysnum"
553 #endif /* SYSBINDFILE */
554 read_binding_file(SYSBINDFILE, sb_hashtab);
555 #else /* !AFS_SUN53_ENV */
556 read_binding_file(sysbind, sb_hashtab);
557 #endif /* AFS_SUN53_ENV */
558 make_syscallname("afs", AFS_SYSCALL);
560 if (sysent[AFS_SYSCALL].sy_call == nosys) {
561 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
562 sysent[AFS_SYSCALL].sy_lock =
563 (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
564 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
567 #else /* !AFS_SUN57_ENV */
568 RW_DEFAULT, DEFAULT_WT);
569 #endif /* AFS_SUN57_ENV */
572 #endif /* !AFS_SUN58_ENV */
574 osi_Init(); /* initialize global lock, etc */
576 code = mod_install(&afs_modlinkage);
581 struct modinfo *modp;
585 code = mod_info(&afs_modlinkage, modp);
597 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
598 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
599 #if defined(AFS_SUN57_64BIT_ENV)
600 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
601 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
604 code = mod_remove(&afs_modlinkage);