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>
29 struct vfs *afs_globalVFS = 0;
30 struct vcache *afs_globalVp = 0;
32 #if defined(AFS_SUN57_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;
72 #if defined(AFS_SUN58_ENV)
74 afs_unmount(struct vfs *afsp, int flag, afs_ucred_t *credp)
77 afs_unmount(struct vfs *afsp, afs_ucred_t *credp)
81 AFS_STATCNT(afs_unmount);
83 #if defined(AFS_SUN510_ENV)
84 if (secpolicy_fs_unmount(credp, afsp) != 0) {
86 if (!afs_osi_suser(credp)) {
99 afs_root(struct vfs *afsp, struct vnode **avpp)
101 register afs_int32 code = 0;
102 struct vrequest treq;
103 register struct vcache *tvp = 0;
105 struct proc *proc = ttoproc(curthread);
106 struct vnode *vp = afsp->vfs_vnodecovered;
109 /* Potential deadlock:
110 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
111 * and drop the v_lock if we need to make an RPC to complete this
112 * request. There used to be a deadlock on the global lock until
113 * we stopped calling iget while holding the global lock.
118 AFS_STATCNT(afs_root);
121 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
124 if (MUTEX_HELD(&vp->v_lock)) {
125 vp->v_flag |= VVFSLOCK;
127 mutex_exit(&vp->v_lock);
136 if (!(code = afs_InitReq(&treq, proc->p_cred))
137 && !(code = afs_CheckInit())) {
138 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
139 /* we really want this to stay around */
142 /* someone else got there before us! */
153 VN_HOLD(AFSTOV(tvp));
154 mutex_enter(&AFSTOV(tvp)->v_lock);
155 AFSTOV(tvp)->v_flag |= VROOT;
156 mutex_exit(&AFSTOV(tvp)->v_lock);
158 afs_globalVFS = afsp;
162 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
163 ICL_TYPE_INT32, code);
167 mutex_enter(&vp->v_lock);
168 vp->v_flag &= ~VVFSLOCK;
169 if (vp->v_flag & VVFSWAIT) {
170 vp->v_flag &= ~VVFSWAIT;
171 cv_broadcast(&vp->v_cv);
180 afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
183 afs_statvfs(struct vfs *afsp, struct statvfs *abp)
188 AFS_STATCNT(afs_statfs);
190 abp->f_frsize = 1024;
191 abp->f_favail = 9000000;
192 abp->f_bsize = afsp->vfs_bsize;
193 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
194 abp->f_ffree = 9000000;
195 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
202 afs_sync(struct vfs *afsp, short flags, afs_ucred_t *credp)
208 afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
210 cred_t *credp = CRED();
211 struct vrequest treq;
216 AFS_STATCNT(afs_vget);
219 if (!(code = afs_InitReq(&treq, credp))) {
220 code = afs_osi_vget((struct vcache **)avcp, fidp, &treq);
223 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
224 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
225 code = afs_CheckCode(code, &treq, 42);
231 /* This is only called by vfs_mount when afs is going to be mounted as root.
232 * Since we don't support diskless clients we shouldn't come here.
234 int afsmountroot = 0;
235 afs_mountroot(struct vfs *afsp, whymountroot_t why)
238 AFS_STATCNT(afs_mountroot);
244 /* afs_swapvp is called to setup swapping over the net for diskless clients.
248 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
251 AFS_STATCNT(afs_swapvp);
258 #if defined(AFS_SUN511_ENV)
259 /* The following list must always be NULL-terminated */
260 static const fs_operation_def_t afs_vfsops_template[] = {
261 VFSNAME_MOUNT, { .vfs_mount = afs_mount },
262 VFSNAME_UNMOUNT, { .vfs_unmount = afs_unmount },
263 VFSNAME_ROOT, { .vfs_root = afs_root },
264 VFSNAME_STATVFS, { .vfs_statvfs = afs_statvfs },
265 VFSNAME_SYNC, { .vfs_sync = afs_sync },
266 VFSNAME_VGET, { .vfs_vget = afs_vget },
267 VFSNAME_MOUNTROOT, { .vfs_mountroot = afs_mountroot },
268 VFSNAME_FREEVFS, { .vfs_freevfs = fs_freevfs },
271 struct vfsops *afs_vfsopsp;
272 #elif defined(AFS_SUN510_ENV)
273 /* The following list must always be NULL-terminated */
274 const fs_operation_def_t afs_vfsops_template[] = {
275 VFSNAME_MOUNT, afs_mount,
276 VFSNAME_UNMOUNT, afs_unmount,
277 VFSNAME_ROOT, afs_root,
278 VFSNAME_STATVFS, afs_statvfs,
279 VFSNAME_SYNC, afs_sync,
280 VFSNAME_VGET, afs_vget,
281 VFSNAME_MOUNTROOT, afs_mountroot,
282 VFSNAME_FREEVFS, fs_freevfs,
285 struct vfsops *afs_vfsopsp;
287 struct vfsops Afs_vfsops = {
296 #if defined(AFS_SUN58_ENV)
304 * afsinit - intialize VFS
306 int (*ufs_iallocp) ();
307 void (*ufs_iupdatp) ();
309 void (*ufs_itimes_nolockp) ();
311 int (*afs_orig_ioctl) (), (*afs_orig_ioctl32) ();
312 int (*afs_orig_setgroups) (), (*afs_orig_setgroups32) ();
314 #ifndef AFS_SUN510_ENV
315 struct ill_s *ill_g_headp = 0;
320 extern struct fs_operation_def afs_vnodeops_template[];
322 #if !defined(AFS_NONFSTRANS)
323 int (*nfs_rfsdisptab_v2) ();
324 int (*nfs_rfsdisptab_v3) ();
325 int (*nfs_acldisptab_v2) ();
326 int (*nfs_acldisptab_v3) ();
328 int (*nfs_checkauth) ();
331 extern Afs_syscall();
334 do_mod_lookup(const char * mod, const char * sym)
338 ptr = modlookup(mod, sym);
340 afs_warn("modlookup failed for symbol '%s' in module '%s'\n",
347 #ifdef AFS_SUN510_ENV
348 afsinit(int fstype, char *dummy)
350 afsinit(struct vfssw *vfsswp, int fstype)
353 extern int afs_xioctl();
354 extern int afs_xsetgroups();
356 AFS_STATCNT(afsinit);
358 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
359 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
360 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
361 sysent[SYS_ioctl].sy_call = afs_xioctl;
363 #if defined(AFS_SUN57_64BIT_ENV)
364 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
365 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
366 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
367 sysent32[SYS_ioctl].sy_call = afs_xioctl;
368 #endif /* AFS_SUN57_64BIT_ENV */
370 #ifdef AFS_SUN510_ENV
371 vfs_setfsops(fstype, afs_vfsops_template, &afs_vfsopsp);
373 vn_make_ops("afs", afs_vnodeops_template, &afs_ops);
374 #else /* !AFS_SUN510_ENV */
375 vfsswp->vsw_vfsops = &Afs_vfsops;
377 #endif /* !AFS_SUN510_ENV */
380 #if !defined(AFS_NONFSTRANS)
381 nfs_rfsdisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v2");
382 if (nfs_rfsdisptab_v2 != NULL) {
383 nfs_acldisptab_v2 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v2");
384 if (nfs_acldisptab_v2 != NULL) {
385 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
388 nfs_rfsdisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "rfsdisptab_v3");
389 if (nfs_rfsdisptab_v3 != NULL) {
390 nfs_acldisptab_v3 = (int (*)()) do_mod_lookup("nfssrv", "acldisptab_v3");
391 if (nfs_acldisptab_v3 != NULL) {
392 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
396 nfs_checkauth = (int (*)()) do_mod_lookup("nfssrv", "checkauth");
397 #endif /* !AFS_NONFSTRANS */
399 ufs_iallocp = (int (*)()) do_mod_lookup("ufs", "ufs_ialloc");
400 ufs_iupdatp = (void (*)()) do_mod_lookup("ufs", "ufs_iupdat");
401 ufs_igetp = (int (*)()) do_mod_lookup("ufs", "ufs_iget");
402 ufs_itimes_nolockp = (void (*)()) do_mod_lookup("ufs", "ufs_itimes_nolock");
404 if (!ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp || !ufs_igetp) {
405 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
408 #if !defined(AFS_SUN510_ENV)
409 ill_g_headp = (struct ill_s *) do_mod_lookup("ip", "ill_g_head");
410 #endif /* !AFS_SUN510_ENV */
417 #ifdef AFS_SUN510_ENV
418 #ifdef AFS_SUN511_ENV
419 static vfsdef_t afs_vfsdef = {
427 static struct vfsdef_v3 afs_vfsdef = {
435 static struct vfssw afs_vfw = {
443 static struct sysent afssysent = {
449 /* inter-module dependencies */
450 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
453 * Info/Structs to link the afs module into the kernel
455 extern struct mod_ops mod_fsops;
456 extern struct mod_ops mod_syscallops;
458 static struct modlfs afsmodlfs = {
461 #ifdef AFS_SUN510_ENV
468 static struct modlsys afsmodlsys = {
470 "afs syscall interface",
474 /** The two structures afssysent32 and afsmodlsys32 are being added
475 * for supporting 32 bit syscalls. In Solaris 7 there are two system
476 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
477 * Since most of our user space binaries are going to be 32 bit
478 * we need to attach to sysent32 also. Note that the entry into AFS
479 * land still happens through Afs_syscall irrespective of whether we
480 * land here from sysent or sysent32
483 #if defined(AFS_SUN57_64BIT_ENV)
484 extern struct mod_ops mod_syscallops32;
486 static struct modlsys afsmodlsys32 = {
488 "afs syscall interface(32 bit)",
494 static struct modlinkage afs_modlinkage = {
497 #ifdef AFS_SUN57_64BIT_ENV
498 (void *)&afsmodlsys32,
504 /** This is the function that modload calls when loading the afs kernel
505 * extensions. The solaris modload program searches for the _init
506 * function in a module and calls it when modloading
511 char *sysn, *mod_getsysname();
513 extern char *sysbind;
514 extern struct bind *sb_hashtab[];
515 struct modctl *mp = 0;
520 if ((!(mp = mod_find_by_filename("fs", "ufs"))
521 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs"))
522 && !(mp = mod_find_by_filename(NULL, "sys/ufs"))) || (mp
527 ("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
530 #ifndef AFS_NONFSTRANS
531 #if defined(AFS_SUN55_ENV)
532 if ((!(mp = mod_find_by_filename("misc", "nfssrv"))
533 && !(mp = mod_find_by_filename(NULL, NFSSRV))
534 && !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) || (mp
539 ("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
542 #else /* !AFS_SUN55_ENV */
543 #if defined(AFS_SUN52_ENV)
544 if ((!(mp = mod_find_by_filename("fs", "nfs"))
545 && !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs"))
546 && !(mp = mod_find_by_filename(NULL, "sys/nfs"))) || (mp
551 ("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
554 #endif /* AFS_SUN52_ENV */
555 #endif /* AFS_SUN55_ENV */
556 #endif /* !AFS_NONFSTRANS */
557 #if !defined(AFS_SUN58_ENV)
559 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
560 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
561 * unfortunately in Solaris 2.2 it became a local function so we have to do
562 * the read_binding_file() direct call with the appropriate text file and
563 * system call hashtable. make_syscallname actually copies "afs" to the
564 * proper slot entry and we also actually have to properly initialize the
565 * global sysent[AFS_SYSCALL] entry!
569 #define SYSBINDFILE "/etc/name_to_sysnum"
570 #endif /* SYSBINDFILE */
571 read_binding_file(SYSBINDFILE, sb_hashtab);
572 #else /* !AFS_SUN53_ENV */
573 read_binding_file(sysbind, sb_hashtab);
574 #endif /* AFS_SUN53_ENV */
575 make_syscallname("afs", AFS_SYSCALL);
577 if (sysent[AFS_SYSCALL].sy_call == nosys) {
578 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
579 sysent[AFS_SYSCALL].sy_lock =
580 (krwlock_t *) kobj_zalloc(sizeof(krwlock_t), KM_SLEEP);
581 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
584 #else /* !AFS_SUN57_ENV */
585 RW_DEFAULT, DEFAULT_WT);
586 #endif /* AFS_SUN57_ENV */
589 #endif /* !AFS_SUN58_ENV */
591 osi_Init(); /* initialize global lock, etc */
593 code = mod_install(&afs_modlinkage);
598 struct modinfo *modp;
602 code = mod_info(&afs_modlinkage, modp);
614 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
615 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
616 #if defined(AFS_SUN57_64BIT_ENV)
617 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
618 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
621 code = mod_remove(&afs_modlinkage);