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"
18 #include "../afs/sysincludes.h" /* Standard vendor system headers */
19 #include "../afs/afsincludes.h" /* Afs-based standard headers */
20 #include "../afs/afs_stats.h" /* statistics stuff */
21 #include "../h/modctl.h"
22 #include "../h/syscall.h"
27 struct vfs *afs_globalVFS = 0;
28 struct vcache *afs_globalVp = 0;
30 #if defined(AFS_SUN57_64BIT_ENV)
31 extern struct sysent sysent32[];
36 int afs_mount(struct vfs *afsp, struct vnode *amvp, struct mounta *uap,
37 struct AFS_UCRED *credp)
42 AFS_STATCNT(afs_mount);
48 afsp->vfs_fstype = afsfstype;
50 if (afs_globalVFS) { /* Don't allow remounts. */
56 afsp->vfs_bsize = 8192;
57 afsp->vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
58 afsp->vfs_fsid.val[1] = AFS_VFSFSID;
59 afsp->vfs_dev = AFS_VFSMAGIC;
65 #if defined(AFS_SUN58_ENV)
66 int afs_unmount (struct vfs *afsp, int flag, struct AFS_UCRED *credp)
68 int afs_unmount (struct vfs *afsp, struct AFS_UCRED *credp)
72 AFS_STATCNT(afs_unmount);
85 int afs_root (struct vfs *afsp, struct vnode **avpp)
87 register afs_int32 code = 0;
89 register struct vcache *tvp=0;
90 struct proc *proc = ttoproc(curthread);
91 struct vnode *vp = afsp->vfs_vnodecovered;
94 /* Potential deadlock:
95 * afs_root is called with the Vnode's v_lock locked. Set VVFSLOCK
96 * and drop the v_lock if we need to make an RPC to complete this
97 * request. There used to be a deadlock on the global lock until
98 * we stopped calling iget while holding the global lock.
103 AFS_STATCNT(afs_root);
105 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
108 if (MUTEX_HELD(&vp->v_lock)) {
109 vp->v_flag |= VVFSLOCK;
111 mutex_exit(&vp->v_lock);
113 if (!(code = afs_InitReq(&treq, proc->p_cred)) &&
114 !(code = afs_CheckInit())) {
115 tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
116 (struct vcache*)0, WRITE_LOCK);
117 /* we really want this to stay around */
125 VN_HOLD(AFSTOV(tvp));
126 mutex_enter(&AFSTOV(tvp)->v_lock);
127 AFSTOV(tvp)->v_flag |= VROOT;
128 mutex_exit(&AFSTOV(tvp)->v_lock);
130 afs_globalVFS = afsp;
134 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
135 ICL_TYPE_INT32, code);
139 mutex_enter(&vp->v_lock);
140 vp->v_flag &= ~VVFSLOCK;
141 if (vp->v_flag & VVFSWAIT) {
142 vp->v_flag &= ~VVFSWAIT;
143 cv_broadcast(&vp->v_cv);
151 int afs_statvfs(struct vfs *afsp, struct statvfs64 *abp)
153 int afs_statvfs(struct vfs *afsp, struct statvfs *abp)
158 AFS_STATCNT(afs_statfs);
160 abp->f_frsize = 1024;
161 abp->f_favail = 9000000;
162 abp->f_bsize = afsp->vfs_bsize;
163 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
164 abp->f_ffree = 9000000;
165 abp->f_fsid = (AFS_VFSMAGIC << 16) || AFS_VFSFSID;
171 int afs_sync(struct vfs *afsp, short flags, struct AFS_UCRED *credp)
176 int afs_vget(struct vfs *afsp, struct vnode **avcp, struct fid *fidp)
178 cred_t *credp = CRED();
179 struct vrequest treq;
184 AFS_STATCNT(afs_vget);
187 if (!(code = afs_InitReq(&treq, credp))) {
188 code = afs_osi_vget((struct vcache**)avcp, fidp, &treq);
191 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
192 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
193 code = afs_CheckCode(code, &treq, 42);
199 /* This is only called by vfs_mount when afs is going to be mounted as root.
200 * Since we don't support diskless clients we shouldn't come here.
203 afs_mountroot(struct vfs *afsp, whymountroot_t why)
206 AFS_STATCNT(afs_mountroot);
212 /* afs_swapvp is called to setup swapping over the net for diskless clients.
216 afs_swapvp(struct vfs *afsp, struct vnode **avpp, char *nm)
219 AFS_STATCNT(afs_swapvp);
226 struct vfsops Afs_vfsops = {
235 #if defined(AFS_SUN58_ENV)
242 * afsinit - intialize VFS
244 int (*ufs_iallocp)();
245 void (*ufs_iupdatp)();
247 void (*ufs_itimes_nolockp)();
249 int (*afs_orig_ioctl)(), (*afs_orig_ioctl32)();
250 int (*afs_orig_setgroups)(), (*afs_orig_setgroups32)();
252 struct streamtab *udp_infop = 0;
253 struct ill_s *ill_g_headp = 0;
257 #if !defined(AFS_NONFSTRANS)
258 int (*nfs_rfsdisptab_v2)();
259 int (*nfs_rfsdisptab_v3)();
260 int (*nfs_acldisptab_v2)();
261 int (*nfs_acldisptab_v3)();
263 int (*nfs_checkauth)();
266 extern Afs_syscall();
268 afsinit(struct vfssw *vfsswp, int fstype)
270 extern int afs_xioctl();
271 extern int afs_xsetgroups();
273 AFS_STATCNT(afsinit);
275 afs_orig_setgroups = sysent[SYS_setgroups].sy_callc;
276 afs_orig_ioctl = sysent[SYS_ioctl].sy_call;
277 sysent[SYS_setgroups].sy_callc = afs_xsetgroups;
278 sysent[SYS_ioctl].sy_call = afs_xioctl;
280 #if defined(AFS_SUN57_64BIT_ENV)
281 afs_orig_setgroups32 = sysent32[SYS_setgroups].sy_callc;
282 afs_orig_ioctl32 = sysent32[SYS_ioctl].sy_call;
283 sysent32[SYS_setgroups].sy_callc = afs_xsetgroups;
284 sysent32[SYS_ioctl].sy_call = afs_xioctl;
287 vfsswp->vsw_vfsops = &Afs_vfsops;
291 #if !defined(AFS_NONFSTRANS)
292 nfs_rfsdisptab_v2 = (int (*)()) modlookup("nfssrv", "rfsdisptab_v2");
293 if ( !nfs_rfsdisptab_v2 ) {
294 afs_warn("warning : rfsdisptab_v2 NOT FOUND\n");
296 if (nfs_rfsdisptab_v2) {
297 nfs_acldisptab_v2 = (int (*)()) modlookup("nfssrv", "acldisptab_v2");
298 if ( !nfs_acldisptab_v2 ) {
299 afs_warn("warning : acldisptab_v2 NOT FOUND\n");
302 afs_xlatorinit_v2(nfs_rfsdisptab_v2, nfs_acldisptab_v2);
305 nfs_rfsdisptab_v3 = (int (*)()) modlookup("nfssrv", "rfsdisptab_v3");
306 if ( !nfs_rfsdisptab_v3 ) {
307 afs_warn("warning : rfsdisptab_v3 NOT FOUND\n");
309 if (nfs_rfsdisptab_v3) {
310 nfs_acldisptab_v3 = (int (*)()) modlookup("nfssrv", "acldisptab_v3");
311 if ( !nfs_acldisptab_v3 ) {
312 afs_warn("warning : acldisptab_v3 NOT FOUND\n");
315 afs_xlatorinit_v3(nfs_rfsdisptab_v3, nfs_acldisptab_v3);
319 nfs_checkauth = (int (*)()) modlookup("nfssrv", "checkauth");
320 if ( !nfs_checkauth ) afs_warn("nfs_checkauth not initialised");
322 ufs_iallocp = (int (*)()) modlookup("ufs", "ufs_ialloc");
323 ufs_iupdatp = (void (*)()) modlookup("ufs", "ufs_iupdat");
324 ufs_igetp = (int (*)()) modlookup("ufs", "ufs_iget");
325 ufs_itimes_nolockp = (void (*)()) modlookup("ufs", "ufs_itimes_nolock");
326 udp_infop = (struct streamtab *) modlookup("udp", "udpinfo");
327 ill_g_headp = (struct ill_s *) modlookup("ip", "ill_g_head");
329 if ( !ufs_iallocp || !ufs_iupdatp || !ufs_itimes_nolockp ||
330 !ufs_igetp || !udp_infop || !ill_g_headp )
331 afs_warn("AFS to UFS mapping cannot be fully initialised\n");
338 static struct vfssw afs_vfw = {
345 static struct sysent afssysent = {
351 /* inter-module dependencies */
352 char _depends_on[] = "drv/ip drv/udp strmod/rpcmod";
355 * Info/Structs to link the afs module into the kernel
357 extern struct mod_ops mod_fsops;
358 extern struct mod_ops mod_syscallops;
360 static struct modlfs afsmodlfs = {
366 static struct modlsys afsmodlsys = {
368 "afs syscall interface",
372 /** The two structures afssysent32 and afsmodlsys32 are being added
373 * for supporting 32 bit syscalls. In Solaris 7 there are two system
374 * tables viz. sysent ans sysent32. 32 bit applications use sysent32.
375 * Since most of our user space binaries are going to be 32 bit
376 * we need to attach to sysent32 also. Note that the entry into AFS
377 * land still happens through Afs_syscall irrespective of whether we
378 * land here from sysent or sysent32
381 #if defined(AFS_SUN57_64BIT_ENV)
382 extern struct mod_ops mod_syscallops32;
384 static struct modlsys afsmodlsys32 = {
386 "afs syscall interface(32 bit)",
392 static struct modlinkage afs_modlinkage = {
395 #ifdef AFS_SUN57_64BIT_ENV
396 (void *)&afsmodlsys32,
402 /** This is the function that modload calls when loading the afs kernel
403 * extensions. The solaris modload program searches for the _init
404 * function in a module and calls it when modloading
409 char *sysn, *mod_getsysname();
411 extern char *sysbind;
412 extern struct bind *sb_hashtab[];
413 struct modctl *mp = 0;
418 if ((!(mp = mod_find_by_filename("fs", "ufs")) &&
419 !(mp = mod_find_by_filename(NULL, "/kernel/fs/ufs")) &&
420 !(mp = mod_find_by_filename(NULL, "sys/ufs"))) ||
421 (mp && !mp->mod_installed)) {
422 printf("ufs module must be loaded before loading afs; use modload /kernel/fs/ufs\n");
425 #ifndef AFS_NONFSTRANS
426 #if defined(AFS_SUN55_ENV)
427 if ((!(mp = mod_find_by_filename("misc", "nfssrv")) &&
428 !(mp = mod_find_by_filename(NULL, NFSSRV)) &&
429 !(mp = mod_find_by_filename(NULL, NFSSRV_V9))) ||
430 (mp && !mp->mod_installed)) {
431 printf("misc/nfssrv module must be loaded before loading afs with nfs-xlator\n");
435 #if defined(AFS_SUN52_ENV)
436 if ((!(mp = mod_find_by_filename("fs", "nfs")) &&
437 !(mp = mod_find_by_filename(NULL, "/kernel/fs/nfs")) &&
438 !(mp = mod_find_by_filename(NULL, "sys/nfs"))) ||
439 (mp && !mp->mod_installed)) {
440 printf("fs/nfs module must be loaded before loading afs with nfs-xlator\n");
447 * Re-read the /etc/name_to_sysnum file to make sure afs isn't added after
448 * reboot. Ideally we would like to call modctl_read_sysbinding_file() but
449 * unfortunately in Solaris 2.2 it became a local function so we have to do
450 * the read_binding_file() direct call with the appropriate text file and
451 * system call hashtable. make_syscallname actually copies "afs" to the
452 * proper slot entry and we also actually have to properly initialize the
453 * global sysent[AFS_SYSCALL] entry!
457 #define SYSBINDFILE "/etc/name_to_sysnum"
459 read_binding_file(SYSBINDFILE, sb_hashtab);
461 read_binding_file(sysbind, sb_hashtab);
463 #if !defined(AFS_SUN58_ENV)
464 make_syscallname("afs", AFS_SYSCALL);
467 if (sysent[AFS_SYSCALL].sy_call == nosys) {
468 if ((sysn = mod_getsysname(AFS_SYSCALL)) != NULL) {
469 sysent[AFS_SYSCALL].sy_lock =
470 (krwlock_t *) kobj_zalloc(sizeof (krwlock_t), KM_SLEEP);
471 rw_init(sysent[AFS_SYSCALL].sy_lock, "afs_syscall",
475 RW_DEFAULT, DEFAULT_WT);
480 osi_Init(); /* initialize global lock, etc */
482 code = mod_install(&afs_modlinkage);
487 struct modinfo *modp;
491 code = mod_info(&afs_modlinkage, modp);
503 sysent[SYS_setgroups].sy_callc = afs_orig_setgroups;
504 sysent[SYS_ioctl].sy_call = afs_orig_ioctl;
505 #if defined(AFS_SUN57_64BIT_ENV)
506 sysent32[SYS_setgroups].sy_callc = afs_orig_setgroups32;
507 sysent32[SYS_ioctl].sy_call = afs_orig_ioctl32;
510 code = mod_remove(&afs_modlinkage);