From 3f8b428d52feb45e6d2dc3577c7c38306c98e0d8 Mon Sep 17 00:00:00 2001 From: Jim Rees Date: Tue, 1 Jul 2003 23:41:22 +0000 Subject: [PATCH] freebsd-50-creds-20030701 freebsd 5.0 module now loads and runs! init creds in osi_Init don't call crhold on afs_osi_cred, because the mutex is invalid afs_xioctl takes a thread, not a proc --- src/afs/FBSD/osi_module.c | 135 +++++++++++++++++++++----------------- src/afs/OBSD/osi_file.c | 6 -- src/afs/OBSD/osi_vfsops.c | 1 + src/afs/afs_osi.c | 15 ++++- src/afs/afs_pioctl.c | 43 ++++++------ 5 files changed, 111 insertions(+), 89 deletions(-) diff --git a/src/afs/FBSD/osi_module.c b/src/afs/FBSD/osi_module.c index 97551eafb..f12dc22a9 100644 --- a/src/afs/FBSD/osi_module.c +++ b/src/afs/FBSD/osi_module.c @@ -1,6 +1,18 @@ +/* + * Copyright 2000, International Business Machines Corporation and others. + * All Rights Reserved. + * + * This software has been released under the terms of the IBM Public + * License. For details, see the LICENSE file in the top-level source + * directory or online at http://www.openafs.org/dl/license10.html + */ +#include #include + +RCSID("$Header$"); + #include #include #include @@ -19,73 +31,74 @@ extern int afs3_syscall(); extern int Afs_xsetgroups(); extern int afs_xioctl(); -int afs_module_handler(module_t mod, int what, void *arg) { - static sy_call_t *old_handler; - static int inited=0; - int error; - error=0; - switch (what) { - case MOD_LOAD: - if (inited) { - printf ("afs cannot be MOD_LOAD'd more than once\n"); - error=-1; - break; - } - if (sysent[AFS_SYSCALL].sy_call != nosys && - sysent[AFS_SYSCALL].sy_call != lkmnosys) { - printf("AFS_SYSCALL in use. aborting\n"); - error=-1; - break; - } - memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); - strcpy(afs_vfsconf.vfc_name, "AFS"); - afs_vfsconf.vfc_vfsops=&afs_vfsops; - afs_vfsconf.vfc_typenum=-1; /* set by vfs_register */ - afs_vfsconf.vfc_flags=VFCF_NETWORK; - vfs_register(&afs_vfsconf); /* doesn't fail */ - vfs_add_vnodeops(&afs_vnodeop_opv_desc); - osi_Init(); - sysent[SYS_setgroups].sy_call=Afs_xsetgroups; - sysent[SYS_ioctl].sy_call=afs_xioctl; - old_handler=sysent[AFS_SYSCALL].sy_call; - sysent[AFS_SYSCALL].sy_call=afs3_syscall; - sysent[AFS_SYSCALL].sy_narg = 5; - inited=1; - break; - case MOD_UNLOAD: +int +afs_module_handler(module_t mod, int what, void *arg) +{ + static sy_call_t *old_handler; + static int inited = 0; + int error; + error = 0; + switch (what) { + case MOD_LOAD: + if (inited) { + printf("afs cannot be MOD_LOAD'd more than once\n"); + error = -1; + break; + } + if (sysent[AFS_SYSCALL].sy_call != nosys && + sysent[AFS_SYSCALL].sy_call != lkmnosys) { + printf("AFS_SYSCALL in use. aborting\n"); + error = -1; + break; + } + memset(&afs_vfsconf, 0, sizeof(struct vfsconf)); + strcpy(afs_vfsconf.vfc_name, "AFS"); + afs_vfsconf.vfc_vfsops = &afs_vfsops; + afs_vfsconf.vfc_typenum = -1; /* set by vfs_register */ + afs_vfsconf.vfc_flags = VFCF_NETWORK; + vfs_register(&afs_vfsconf); /* doesn't fail */ + vfs_add_vnodeops(&afs_vnodeop_opv_desc); + osi_Init(); + sysent[SYS_setgroups].sy_call = Afs_xsetgroups; + sysent[SYS_ioctl].sy_call = afs_xioctl; + old_handler = sysent[AFS_SYSCALL].sy_call; + sysent[AFS_SYSCALL].sy_call = afs3_syscall; + sysent[AFS_SYSCALL].sy_narg = 5; + inited = 1; + break; + case MOD_UNLOAD: #ifndef RXK_LISTENER_ENV - /* shutdown is incomplete unless RXK_LISTENER_ENV */ - printf("afs: I can't be unloaded yet\n"); - return -1; + /* shutdown is incomplete unless RXK_LISTENER_ENV */ + printf("afs: I can't be unloaded yet\n"); + return -1; #endif - if (! inited) { - error=0; - break; - } - if (afs_globalVFS) { - error=-1; - break; - } - if (vfs_unregister(&afs_vfsconf)) { - error=-1; - break; - } - vfs_rm_vnodeops(&afs_vnodeop_opv_desc); - sysent[SYS_ioctl].sy_call = ioctl; - sysent[SYS_setgroups].sy_call = setgroups; - sysent[AFS_SYSCALL].sy_narg = 0; - sysent[AFS_SYSCALL].sy_call = old_handler; - break; - } + if (!inited) { + error = 0; + break; + } + if (afs_globalVFS) { + error = -1; + break; + } + if (vfs_unregister(&afs_vfsconf)) { + error = -1; + break; + } + vfs_rm_vnodeops(&afs_vnodeop_opv_desc); + sysent[SYS_ioctl].sy_call = ioctl; + sysent[SYS_setgroups].sy_call = setgroups; + sysent[AFS_SYSCALL].sy_narg = 0; + sysent[AFS_SYSCALL].sy_call = old_handler; + break; + } - return (error); + return (error); } static moduledata_t afs_mod = { - "afs", - afs_module_handler, - &afs_mod + "afs", + afs_module_handler, + &afs_mod }; DECLARE_MODULE(afs, afs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE); - diff --git a/src/afs/OBSD/osi_file.c b/src/afs/OBSD/osi_file.c index 39a889462..07eb87301 100644 --- a/src/afs/OBSD/osi_file.c +++ b/src/afs/OBSD/osi_file.c @@ -34,12 +34,6 @@ void *osi_UFSOpen(afs_int32 ainode) AFS_STATCNT(osi_UFSOpen); if (cacheDiskType != AFS_FCACHE_TYPE_UFS) osi_Panic("UFSOpen called for non-UFS cache\n"); - if (!afs_osicred_initialized) { - /* valid for alpha_osf, SunOS, Ultrix */ - memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); - crhold(&afs_osi_cred); - afs_osicred_initialized = 1; - } afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file)); code = VFS_VGET(cacheDev.mp, (ino_t) ainode, &vp); if (code) { diff --git a/src/afs/OBSD/osi_vfsops.c b/src/afs/OBSD/osi_vfsops.c index d0c1f46e9..3bfca8139 100644 --- a/src/afs/OBSD/osi_vfsops.c +++ b/src/afs/OBSD/osi_vfsops.c @@ -461,6 +461,7 @@ afsinit() sysent[AFS_SYSCALL].sy_argsize = 6 * sizeof(long); sysent[54].sy_call = afs_xioctl; sysent[80].sy_call = Afs_xsetgroups; + osi_Init(); return 0; } diff --git a/src/afs/afs_osi.c b/src/afs/afs_osi.c index aadf18fcc..ea334f63f 100644 --- a/src/afs/afs_osi.c +++ b/src/afs/afs_osi.c @@ -67,11 +67,22 @@ void osi_Init(void) #endif /* AFS_GLOBAL_SUNLOCK */ #endif /* AFS_HPUX_ENV */ - if ( !afs_osicred_initialized ) { - memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); + if (!afs_osicred_initialized) { + memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); +#ifdef AFS_FBSD50_ENV + /* + * We don't init the mutex. + * This will be trouble if anyone tries to use change the refcount. + * Proper fix would be to make afs_osi_cred into a pointer, + * and crdup() it from curthread. + */ + afs_osi_cred.cr_ref = 1; +#else crhold(&afs_osi_cred); /* don't let it evaporate */ +#endif afs_osicred_initialized = 1; } + #ifdef AFS_SGI64_ENV osi_flid.fl_pid = osi_flid.fl_sysid = 0; #endif diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c index 01cc42aad..57602593f 100644 --- a/src/afs/afs_pioctl.c +++ b/src/afs/afs_pioctl.c @@ -16,6 +16,9 @@ RCSID("$Header$"); #ifdef AFS_OBSD_ENV #include "h/syscallargs.h" #endif +#ifdef AFS_FBSD50_ENV +#include "h/sysproto.h" +#endif #include "afsincludes.h" /* Afs-based standard headers */ #include "afs/afs_stats.h" /* afs statistics */ #include "afs/vice.h" @@ -446,6 +449,15 @@ afs_xioctl (p, args, retval) u_long com; caddr_t arg; } *uap = (struct a *)args; +#elif defined(AFS_FBSD50_ENV) +#define arg data +int +afs_xioctl(td, uap, retval) + struct thread *td; + register struct ioctl_args *uap; + register_t *retval; +{ + struct proc *p = td->td_proc; #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) struct ioctl_args { int fd; @@ -497,16 +509,13 @@ int afs_xioctl (void) return EBADF; if ((fd->f_flag & (FREAD | FWRITE)) == 0) return EBADF; -#else -#if defined(AFS_DARWIN_ENV) +#elif defined(AFS_DARWIN_ENV) if ((code=fdgetf(p, uap->fd, &fd))) return code; -#else -#ifdef AFS_LINUX22_ENV +#elif defined(AFS_LINUX22_ENV) ua.com = com; ua.arg = arg; -#else -#ifdef AFS_AIX32_ENV +#elif defined(AFS_AIX32_ENV) uap->fd = fdes; uap->com = com; uap->arg = arg; @@ -514,36 +523,28 @@ int afs_xioctl (void) uap->arg2 = arg2; uap->arg3 = arg3; #endif - if (setuerror(getf(uap->fd, &fd))) { return -1; } -#else -#ifdef AFS_OSF_ENV +#elif defined(AFS_OSF_ENV) fd = NULL; if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state)) return code; -#else /* AFS_OSF_ENV */ -#ifdef AFS_SUN5_ENV -#if defined(AFS_SUN57_ENV) +#elif defined(AFS_SUN5_ENV) +# if defined(AFS_SUN57_ENV) fd = getf(uap->fd); if (!fd) return(EBADF); -#elif defined(AFS_SUN54_ENV) +# elif defined(AFS_SUN54_ENV) fd = GETF(uap->fd); if (!fd) return(EBADF); -#else +# else if (code = getf(uap->fd, &fd)) { return (code); } -#endif +# endif /* AFS_SUN57_ENV */ #else fd = getf(uap->fd); if (!fd) return(EBADF); -#endif -#endif -#endif -#endif -#endif #endif /* first determine whether this is any sort of vnode */ #if defined(AFS_LINUX22_ENV) @@ -661,6 +662,8 @@ int afs_xioctl (void) releasef(fd); #endif code = ioctl(uap, rvp); +#elif defined(AFS_FBSD50_ENV) + return ioctl(td, uap); #elif defined(AFS_FBSD_ENV) return ioctl(p, uap); #elif defined(AFS_OBSD_ENV) -- 2.39.5