From 38136f03cf9043ec98d83653f4fddf5a02e48a2a Mon Sep 17 00:00:00 2001 From: Jim Rees Date: Tue, 19 Nov 2002 18:28:01 +0000 Subject: [PATCH] openbsd-20021119 Implement AFS_GLOCK() Other minor cleanups --- src/afs/OBSD/osi_machdep.h | 34 ++++-- src/afs/OBSD/osi_sleep.c | 9 ++ src/afs/OBSD/osi_vfsops.c | 35 ++---- src/afs/OBSD/osi_vnodeops.c | 204 +++++++++++++++++++++---------- src/afs/VNOPS/afs_vnop_symlink.c | 4 +- src/afs/afs_call.c | 4 +- src/afs/afs_osi_alloc.c | 4 +- src/afs/afs_pioctl.c | 38 +++--- src/config/param.i386_obsd31.h | 1 + src/fsint/afsaux.c | 5 +- src/rx/OBSD/rx_kmutex.h | 63 +++++++++- src/rx/rx.c | 4 +- src/rx/rx_event.c | 3 + 13 files changed, 283 insertions(+), 125 deletions(-) diff --git a/src/afs/OBSD/osi_machdep.h b/src/afs/OBSD/osi_machdep.h index 5450bab05..a969d445d 100644 --- a/src/afs/OBSD/osi_machdep.h +++ b/src/afs/OBSD/osi_machdep.h @@ -104,24 +104,42 @@ extern int afs_vget(); #ifdef KERNEL extern int (**afs_vnodeop_p)(); -extern struct simplelock afs_global_lock; -#ifndef AFS_GLOBAL_SUNLOCK -#define AFS_ASSERT_GLOCK() -#endif +#ifdef AFS_GLOBAL_SUNLOCK +extern struct proc * afs_global_owner; +extern struct lock afs_global_lock; +#define AFS_GLOCK() \ + do { \ + osi_Assert(curproc); \ + lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \ + osi_Assert(afs_global_owner == NULL); \ + afs_global_owner = curproc; \ + } while (0) +#define AFS_GUNLOCK() \ + do { \ + osi_Assert(curproc); \ + osi_Assert(afs_global_owner == curproc); \ + afs_global_owner = NULL; \ + lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \ + } while(0) +#define ISAFS_GLOCK() (afs_global_owner == curproc && curproc) +#else +extern struct simplelock afs_global_lock; #define AFS_GLOCK() #define AFS_GUNLOCK() +#define AFS_ASSERT_GLOCK() +#define ISAFS_GLOCK() 1 +#endif #define AFS_RXGLOCK() #define AFS_RXGUNLOCK() #define ISAFS_RXGLOCK() 1 -#define ISAFS_GLOCK() 1 #undef SPLVAR -#define SPLVAR +#define SPLVAR int splvar #undef NETPRI -#define NETPRI +#define NETPRI splvar=splnet() #undef USERPRI -#define USERPRI +#define USERPRI splx(splvar) #endif /* KERNEL */ #endif /* _OSI_MACHDEP_H_ */ diff --git a/src/afs/OBSD/osi_sleep.c b/src/afs/OBSD/osi_sleep.c index c41144348..f22922f80 100644 --- a/src/afs/OBSD/osi_sleep.c +++ b/src/afs/OBSD/osi_sleep.c @@ -86,6 +86,8 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) endTime = osi_Time() + (ams / 1000); if (ahandle) ahandle->proc = (caddr_t) curproc; + AFS_ASSERT_GLOCK(); + AFS_GUNLOCK(); do { if (aintok) { code = tsleep(&waitV, PCATCH | (PZERO+8), "afs_osi_Wait", timo); @@ -100,17 +102,24 @@ int afs_osi_Wait(afs_int32 ams, struct afs_osi_WaitHandle *ahandle, int aintok) break; } } while (osi_Time() < endTime); + AFS_GLOCK(); return code; } void afs_osi_Sleep(void *event) { + AFS_ASSERT_GLOCK(); + AFS_GUNLOCK(); tsleep(event, PVFS, "afs", 0); + AFS_GLOCK(); } int afs_osi_SleepSig(void *event) { + AFS_ASSERT_GLOCK(); + AFS_GUNLOCK(); tsleep(event, PVFS, "afs", 0); + AFS_GLOCK(); return 0; } diff --git a/src/afs/OBSD/osi_vfsops.c b/src/afs/OBSD/osi_vfsops.c index 6d85df2f0..5dcabf17e 100644 --- a/src/afs/OBSD/osi_vfsops.c +++ b/src/afs/OBSD/osi_vfsops.c @@ -247,7 +247,6 @@ struct proc *p; return EBUSY; } - AFS_GLOCK(); AFS_STATCNT(afs_mount); #ifdef AFS_DISCON_ENV @@ -261,8 +260,6 @@ struct proc *p; mp->osi_vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */ mp->osi_vfs_fsid.val[1] = (int) AFS_VFSFSID; - AFS_GUNLOCK(); - (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size); bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); bzero(mp->mnt_stat.f_mntfromname, MNAMELEN); @@ -296,15 +293,11 @@ struct proc *p; vflush(afsp, NULLVP, 0); /* don't support forced */ afsp->mnt_data = NULL; -#ifdef AFS_GLOBAL_SUNLOCK - mutex_enter(&afs_global_lock); -#endif + AFS_GLOCK(); afs_globalVFS = 0; afs_cold_shutdown = 1; afs_shutdown(); /* XXX */ -#ifdef AFS_GLOBAL_SUNLOCK - mutex_exit(&afs_global_lock); -#endif + AFS_GUNLOCK(); /* give up syscall entries for ioctl & setgroups, which we've stolen */ sysent[SYS_ioctl].sy_call = sys_ioctl; @@ -344,9 +337,7 @@ afs_root(struct mount *mp, AFS_STATCNT(afs_root); -#ifdef AFS_GLOBAL_SUNLOCK - mutex_enter(&afs_global_lock); -#endif + AFS_GLOCK(); if (!(code = afs_InitReq(&treq, osi_curcred())) && !(code = afs_CheckInit())) { tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); @@ -367,9 +358,7 @@ afs_root(struct mount *mp, } else code = ENOENT; } -#ifdef AFS_GLOBAL_SUNLOCK - mutex_exit(&afs_global_lock); -#endif + AFS_GUNLOCK(); if (!code) vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curproc); /* return it locked */ @@ -380,17 +369,17 @@ int afs_statfs(struct osi_vfs *afsp, struct statfs *abp) { AFS_STATCNT(afs_statfs); -#ifdef AFS_GLOBAL_SUNLOCK - mutex_enter(&afs_global_lock); -#endif abp->f_bsize = afsp->osi_vfs_bsize; - /* Fake a high number below to satisfy programs that use the ustat (for AIX), or statfs (for the rest) call to make sure that there's enough space in the device partition before storing something there (like ed(1)) */ - abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = abp->f_ffree = 9000000; /* XXX */ + + /* + * Fake a high number below to satisfy programs that use the ustat (for + * * AIX), or statfs (for the rest) call to make sure that there's + * enough * space in the device partition before storing something there + * (like * ed(1)) + */ + abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = abp->f_ffree = 9000000; abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */ abp->f_fsid.val[1] = (int) AFS_VFSFSID; -#ifdef AFS_GLOBAL_SUNLOCK - mutex_exit(&afs_global_lock); -#endif return 0; } diff --git a/src/afs/OBSD/osi_vnodeops.c b/src/afs/OBSD/osi_vnodeops.c index 14411f9f1..7a78fe83b 100644 --- a/src/afs/OBSD/osi_vnodeops.c +++ b/src/afs/OBSD/osi_vnodeops.c @@ -236,7 +236,7 @@ struct vop_lookup_args /* { struct componentname *a_cnp; } */ *ap; { - int error; + int code; struct vcache *vcp; struct vnode *vp, *dvp; int flags = ap->a_cnp->cn_flags; @@ -255,16 +255,18 @@ struct vop_lookup_args /* { dvp = ap->a_dvp; if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_flag & VROOT)) printf("nbsd_lookup dvp %p flags %x name %s cnt %d\n", dvp, flags, name, dvp->v_usecount); - error = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); - if (error) { + AFS_GLOCK(); + code = afs_lookup(VTOAFS(dvp), name, &vcp, cnp->cn_cred); + AFS_GUNLOCK(); + if (code) { if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) && - (flags & ISLASTCN) && error == ENOENT) - error = EJUSTRETURN; + (flags & ISLASTCN) && code == ENOENT) + code = EJUSTRETURN; if (cnp->cn_nameiop != LOOKUP && (flags & ISLASTCN)) cnp->cn_flags |= SAVENAME; DROPNAME(); *ap->a_vpp = 0; - return (error); + return (code); } vp = AFSTOV(vcp); /* always get a node if no error */ @@ -293,7 +295,7 @@ struct vop_lookup_args /* { DROPNAME(); if (afs_debug & AFSDEB_VNLAYER && !(dvp->v_flag & VROOT)) printf("nbsd_lookup done dvp %p cnt %d\n", dvp, dvp->v_usecount); - return error; + return code; } int @@ -305,7 +307,7 @@ afs_nbsd_create(ap) struct vattr *a_vap; } */ *ap; { - int error = 0; + int code = 0; struct vcache *vcp; struct vnode *dvp = ap->a_dvp; GETNAME(); @@ -315,14 +317,16 @@ afs_nbsd_create(ap) /* vnode layer handles excl/nonexcl */ - error = afs_create(VTOAFS(dvp), name, ap->a_vap, NONEXCL, + AFS_GLOCK(); + code = afs_create(VTOAFS(dvp), name, ap->a_vap, NONEXCL, ap->a_vap->va_mode, &vcp, cnp->cn_cred); - if (error) { + AFS_GUNLOCK(); + if (code) { VOP_ABORTOP(dvp, cnp); vput(dvp); DROPNAME(); - return(error); + return(code); } if (vcp) { @@ -337,7 +341,7 @@ afs_nbsd_create(ap) DROPNAME(); if (afs_debug & AFSDEB_VNLAYER) printf("nbsd_create done dvp %p cnt %d\n", dvp, dvp->v_usecount); - return error; + return code; } int @@ -363,15 +367,17 @@ afs_nbsd_open(ap) struct proc *a_p; } */ *ap; { - int error; + int code; struct vcache *vc = VTOAFS(ap->a_vp); - error = afs_open(&vc, ap->a_mode, ap->a_cred); + AFS_GLOCK(); + code = afs_open(&vc, ap->a_mode, ap->a_cred); #ifdef DIAGNOSTIC if (AFSTOV(vc) != ap->a_vp) panic("AFS open changed vnode!"); #endif - return error; + AFS_GUNLOCK(); + return code; } int @@ -383,7 +389,12 @@ afs_nbsd_close(ap) struct proc *a_p; } */ *ap; { - return afs_close(VTOAFS(ap->a_vp), ap->a_fflag, ap->a_cred); + int code; + + AFS_GLOCK(); + code = afs_close(VTOAFS(ap->a_vp), ap->a_fflag, ap->a_cred); + AFS_GUNLOCK(); + return code; } int @@ -395,8 +406,14 @@ afs_nbsd_access(ap) struct proc *a_p; } */ *ap; { - return afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); + int code; + + AFS_GLOCK(); + code = afs_access(VTOAFS(ap->a_vp), ap->a_mode, ap->a_cred); + AFS_GUNLOCK(); + return code; } + int afs_nbsd_getattr(ap) struct vop_getattr_args /* { @@ -406,8 +423,14 @@ afs_nbsd_getattr(ap) struct proc *a_p; } */ *ap; { - return afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + int code; + + AFS_GLOCK(); + code = afs_getattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + AFS_GUNLOCK(); + return code; } + int afs_nbsd_setattr(ap) struct vop_setattr_args /* { @@ -417,8 +440,14 @@ afs_nbsd_setattr(ap) struct proc *a_p; } */ *ap; { - return afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + int code; + + AFS_GLOCK(); + code = afs_setattr(VTOAFS(ap->a_vp), ap->a_vap, ap->a_cred); + AFS_GUNLOCK(); + return code; } + int afs_nbsd_read(ap) struct vop_read_args /* { @@ -428,8 +457,14 @@ afs_nbsd_read(ap) struct ucred *a_cred; } */ *ap; { - return afs_read(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, 0, 0, 0); + int code; + + AFS_GLOCK(); + code = afs_read(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, 0, 0, 0); + AFS_GUNLOCK(); + return code; } + int afs_nbsd_write(ap) struct vop_write_args /* { @@ -439,13 +474,19 @@ afs_nbsd_write(ap) struct ucred *a_cred; } */ *ap; { + int code; + #ifdef UVM (void) uvm_vnp_uncache(ap->a_vp); /* toss stale pages */ #else vnode_pager_uncache(ap->a_vp); #endif - return afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); + AFS_GLOCK(); + code = afs_write(VTOAFS(ap->a_vp), ap->a_uio, ap->a_ioflag, ap->a_cred, 0); + AFS_GUNLOCK(); + return code; } + int afs_nbsd_ioctl(ap) struct vop_ioctl_args /* { @@ -457,15 +498,20 @@ afs_nbsd_ioctl(ap) struct proc *a_p; } */ *ap; { + int code; + /* in case we ever get in here... */ AFS_STATCNT(afs_ioctl); + AFS_GLOCK(); if (((ap->a_command >> 8) & 0xff) == 'V') /* This is a VICEIOCTL call */ - return HandleIoctl(VTOAFS(ap->a_vp), ap->a_command, (struct afs_ioctl *) ap->a_data); + code = HandleIoctl(VTOAFS(ap->a_vp), ap->a_command, (struct afs_ioctl *) ap->a_data); else /* No-op call; just return. */ - return ENOTTY; + code = ENOTTY; + AFS_GUNLOCK(); + return code; } /* ARGSUSED */ @@ -496,9 +542,13 @@ afs_nbsd_fsync(ap) { int wait = ap->a_waitfor == MNT_WAIT; struct vnode *vp = ap->a_vp; + int code; + AFS_GLOCK(); vflushbuf(vp, wait); - return afs_fsync(VTOAFS(vp), ap->a_cred); + code = afs_fsync(VTOAFS(vp), ap->a_cred); + AFS_GUNLOCK(); + return code; } int @@ -509,12 +559,14 @@ afs_nbsd_remove(ap) struct componentname *a_cnp; } */ *ap; { - int error = 0; + int code; struct vnode *vp = ap->a_vp; struct vnode *dvp = ap->a_dvp; GETNAME(); - error = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); + AFS_GLOCK(); + code = afs_remove(VTOAFS(dvp), name, cnp->cn_cred); + AFS_GUNLOCK(); if (dvp == vp) vrele(vp); else @@ -522,7 +574,7 @@ afs_nbsd_remove(ap) vput(dvp); FREE(cnp->cn_pnbuf, M_NAMEI); DROPNAME(); - return error; + return code; } int @@ -533,27 +585,29 @@ afs_nbsd_link(ap) struct componentname *a_cnp; } */ *ap; { - int error = 0; + int code; struct vnode *dvp = ap->a_dvp; struct vnode *vp = ap->a_vp; GETNAME(); if (dvp->v_mount != vp->v_mount) { VOP_ABORTOP(vp, cnp); - error = EXDEV; + code = EXDEV; goto out; } if (vp->v_type == VDIR) { VOP_ABORTOP(vp, cnp); - error = EISDIR; + code = EISDIR; goto out; } - if ((error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc))) { + if ((code = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc))) { VOP_ABORTOP(dvp, cnp); goto out; } - error = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred); + AFS_GLOCK(); + code = afs_link(VTOAFS(vp), VTOAFS(dvp), name, cnp->cn_cred); + AFS_GUNLOCK(); FREE(cnp->cn_pnbuf, M_NAMEI); if (dvp != vp) VOP_UNLOCK(vp, 0, curproc); @@ -561,7 +615,7 @@ afs_nbsd_link(ap) out: vput(dvp); DROPNAME(); - return error; + return code; } int @@ -575,7 +629,7 @@ afs_nbsd_rename(ap) struct componentname *a_tcnp; } */ *ap; { - int error = 0; + int code = 0; struct componentname *fcnp = ap->a_fcnp; char *fname; struct componentname *tcnp = ap->a_tcnp; @@ -590,7 +644,7 @@ afs_nbsd_rename(ap) */ if ((fvp->v_mount != tdvp->v_mount) || (tvp && (fvp->v_mount != tvp->v_mount))) { - error = EXDEV; + code = EXDEV; abortit: VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */ if (tdvp == tvp) @@ -602,7 +656,7 @@ abortit: VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */ vrele(fdvp); vrele(fvp); - return (error); + return (code); } /* * if fvp == tvp, we're just removing one name of a pair of @@ -611,7 +665,7 @@ abortit: */ if (fvp == tvp) { if (fvp->v_type == VDIR) { - error = EINVAL; + code = EINVAL; goto abortit; } @@ -632,7 +686,7 @@ abortit: return (VOP_REMOVE(fdvp, fvp, fcnp)); } - if ((error = vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, curproc))) + if ((code = vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY, curproc))) goto abortit; MALLOC(fname, char *, fcnp->cn_namelen+1, M_TEMP, M_WAITOK); @@ -643,13 +697,15 @@ abortit: tname[tcnp->cn_namelen] = '\0'; + AFS_GLOCK(); /* XXX use "from" or "to" creds? NFS uses "to" creds */ - error = afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); + code = afs_rename(VTOAFS(fdvp), fname, VTOAFS(tdvp), tname, tcnp->cn_cred); + AFS_GUNLOCK(); VOP_UNLOCK(fvp, 0, curproc); FREE(fname, M_TEMP); FREE(tname, M_TEMP); - if (error) + if (code) goto abortit; /* XXX */ if (tdvp == tvp) vrele(tdvp); @@ -659,7 +715,7 @@ abortit: vput(tvp); vrele(fdvp); vrele(fvp); - return error; + return code; } int @@ -673,7 +729,7 @@ afs_nbsd_mkdir(ap) { struct vnode *dvp = ap->a_dvp; struct vattr *vap = ap->a_vap; - int error = 0; + int code; struct vcache *vcp; GETNAME(); @@ -681,12 +737,14 @@ afs_nbsd_mkdir(ap) if ((cnp->cn_flags & HASBUF) == 0) panic("afs_nbsd_mkdir: no name"); #endif - error = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred); - if (error) { + AFS_GLOCK(); + code = afs_mkdir(VTOAFS(dvp), name, vap, &vcp, cnp->cn_cred); + AFS_GUNLOCK(); + if (code) { VOP_ABORTOP(dvp, cnp); vput(dvp); DROPNAME(); - return(error); + return(code); } if (vcp) { *ap->a_vpp = AFSTOV(vcp); @@ -696,7 +754,7 @@ afs_nbsd_mkdir(ap) DROPNAME(); FREE(cnp->cn_pnbuf, M_NAMEI); vput(dvp); - return error; + return code; } int @@ -707,7 +765,7 @@ afs_nbsd_rmdir(ap) struct componentname *a_cnp; } */ *ap; { - int error = 0; + int code; struct vnode *vp = ap->a_vp; struct vnode *dvp = ap->a_dvp; @@ -720,11 +778,13 @@ afs_nbsd_rmdir(ap) return (EINVAL); } - error = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred); + AFS_GLOCK(); + code = afs_rmdir(VTOAFS(dvp), name, cnp->cn_cred); + AFS_GUNLOCK(); DROPNAME(); vput(dvp); vput(vp); - return error; + return code; } int @@ -738,16 +798,18 @@ afs_nbsd_symlink(ap) } */ *ap; { struct vnode *dvp = ap->a_dvp; - int error = 0; + int code; /* NFS ignores a_vpp; so do we. */ GETNAME(); - error = afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, + AFS_GLOCK(); + code = afs_symlink(VTOAFS(dvp), name, ap->a_vap, ap->a_target, cnp->cn_cred); + AFS_GUNLOCK(); DROPNAME(); FREE(cnp->cn_pnbuf, M_NAMEI); vput(dvp); - return error; + return code; } int @@ -761,14 +823,19 @@ afs_nbsd_readdir(ap) u_long **a_cookies; } */ *ap; { + int code; + + AFS_GLOCK(); #ifdef AFS_HAVE_COOKIES printf("readdir %p cookies %p ncookies %d\n", ap->a_vp, ap->a_cookies, ap->a_ncookies); - return afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, + code = afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag, ap->a_ncookies, ap->a_cookies); #else - return afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag); + code = afs_readdir(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred, ap->a_eofflag); #endif + AFS_GUNLOCK(); + return code; } int @@ -779,8 +846,12 @@ afs_nbsd_readlink(ap) struct ucred *a_cred; } */ *ap; { -/* printf("readlink %p\n", ap->a_vp);*/ - return afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); + int code; + + AFS_GLOCK(); + code = afs_readlink(VTOAFS(ap->a_vp), ap->a_uio, ap->a_cred); + AFS_GUNLOCK(); + return code; } extern int prtactive; @@ -812,7 +883,7 @@ afs_nbsd_reclaim(ap) struct vnode *a_vp; } */ *ap; { - int error, slept; + int code, slept; struct vnode *vp = ap->a_vp; struct vcache *avc = VTOAFS(vp); @@ -823,15 +894,17 @@ afs_nbsd_reclaim(ap) vnode_pager_uncache(vp); #endif + AFS_GLOCK(); #ifndef AFS_DISCON_ENV - error = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */ + code = afs_FlushVCache(avc, &slept); /* tosses our stuff from vnode */ #else /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */ - error = afs_FlushVS(avc); + code = afs_FlushVS(avc); #endif - if (!error && vp->v_data) + AFS_GUNLOCK(); + if (!code && vp->v_data) panic("afs_reclaim: vnode not cleaned"); - return error; + return code; } int @@ -913,12 +986,14 @@ afs_nbsd_strategy(ap) tiovec[0].iov_base = abp->b_un.b_addr; tiovec[0].iov_len = len; + AFS_GLOCK(); if ((abp->b_flags & B_READ) == B_READ) { code = afs_rdwr(tvc, &tuio, UIO_READ, 0, credp); if (code == 0 && tuio.afsio_resid > 0) bzero(abp->b_un.b_addr + len - tuio.afsio_resid, tuio.afsio_resid); } else code = afs_rdwr(tvc, &tuio, UIO_WRITE, 0, credp); + AFS_GUNLOCK(); ReleaseWriteLock(&tvc->lock); AFS_RELE(AFSTOV(tvc)); @@ -1003,6 +1078,11 @@ afs_nbsd_advlock(ap) int a_flags; } */ *ap; { - return afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, osi_curcred(), + int code; + + AFS_GLOCK(); + code = afs_lockctl(VTOAFS(ap->a_vp), ap->a_fl, ap->a_op, osi_curcred(), (int) ap->a_id); + AFS_GUNLOCK(); + return code; } diff --git a/src/afs/VNOPS/afs_vnop_symlink.c b/src/afs/VNOPS/afs_vnop_symlink.c index 4f4cbc9db..5e9e5977e 100644 --- a/src/afs/VNOPS/afs_vnop_symlink.c +++ b/src/afs/VNOPS/afs_vnop_symlink.c @@ -40,6 +40,7 @@ extern afs_rwlock_t afs_xcbhash; /* don't set CDirty in here because RPC is called synchronously */ +int afs_symlink #ifdef AFS_OSF_ENV (ndp, attrs, atargetName) @@ -57,7 +58,7 @@ afs_symlink struct vattr *attrs; struct AFS_UCRED *acred; { #endif - afs_uint32 now; + afs_uint32 now = 0; struct vrequest treq; afs_int32 code; struct conn *tc; @@ -329,6 +330,7 @@ int afs_UFSHandleLink(register struct vcache *avc, struct vrequest *areq) return 0; } +int afs_readlink(OSI_VC_ARG(avc), auio, acred) OSI_VC_DECL(avc); struct uio *auio; diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index f3d626886..4117ef318 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -63,7 +63,7 @@ simple_lock_data_t afs_global_lock; struct lock__bsd__ afs_global_lock; #endif -#if defined(AFS_FBSD_ENV) +#if defined(AFS_XBSD_ENV) struct lock afs_global_lock; struct proc *afs_global_owner; #endif @@ -1458,7 +1458,7 @@ void afs_shutdown(void) #endif #if defined(AFS_SUN5_ENV) || defined(RXK_LISTENER_ENV) afs_warn("RxEvent... "); - /* cancel rx event deamon */ + /* cancel rx event daemon */ while (afs_termState == AFSOP_STOP_RXEVENT) afs_osi_Sleep(&afs_termState); #if defined(RXK_LISTENER_ENV) diff --git a/src/afs/afs_osi_alloc.c b/src/afs/afs_osi_alloc.c index 9fcc118c1..f5ab69774 100644 --- a/src/afs/afs_osi_alloc.c +++ b/src/afs/afs_osi_alloc.c @@ -32,7 +32,7 @@ afs_lock_t osi_fsplock; static struct osi_packet { struct osi_packet *next; -} *freePacketList = 0, *freeSmallList, *freeMediumList; +} *freePacketList = NULL, *freeSmallList; afs_lock_t osi_flplock; @@ -103,6 +103,8 @@ void osi_FreeSmallSpace(void *adata) } #if defined(AFS_AIX32_ENV) || defined(AFS_HPUX_ENV) +static struct osi_packet *freeMediumList; + osi_AllocMoreMSpace(register afs_int32 preallocs) { register int i; diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c index f1b59bc86..a344e1f29 100644 --- a/src/afs/afs_pioctl.c +++ b/src/afs/afs_pioctl.c @@ -1247,7 +1247,7 @@ DECL_PIOCTL(PGetWSCell) struct cell *tcell = NULL; AFS_STATCNT(PGetWSCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ tcell = afs_GetPrimaryCell(READ_LOCK); @@ -1266,7 +1266,7 @@ DECL_PIOCTL(PGetUserCell) register struct cell *tcell; AFS_STATCNT(PGetUserCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ /* return the cell name of the primary cell for this user */ @@ -1637,7 +1637,7 @@ DECL_PIOCTL(PGetTokens) int newStyle; AFS_STATCNT(PGetTokens); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ /* weird interface. If input parameter is present, it is an integer and @@ -1717,7 +1717,7 @@ DECL_PIOCTL(PUnlog) register struct unixuser *tu; AFS_STATCNT(PUnlog); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ i = UHash(areq->uid); @@ -1790,7 +1790,7 @@ DECL_PIOCTL(PCheckServers) AFS_STATCNT(PCheckServers); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if (*lp == 0x12345678) { /* For afs3.3 version */ @@ -1856,7 +1856,7 @@ DECL_PIOCTL(PCheckServers) DECL_PIOCTL(PCheckVolNames) { AFS_STATCNT(PCheckVolNames); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ afs_CheckRootVolume(); @@ -1876,7 +1876,7 @@ DECL_PIOCTL(PCheckAuth) afs_int32 retValue; AFS_STATCNT(PCheckAuth); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ retValue = 0; @@ -2078,7 +2078,7 @@ DECL_PIOCTL(PNewCell) afs_int32 scount; AFS_STATCNT(PNewCell); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if (!afs_osi_suser(*acred)) @@ -2126,7 +2126,7 @@ DECL_PIOCTL(PNewAlias) register afs_int32 code; char *realName, *aliasName; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if (!afs_osi_suser(*acred)) @@ -2149,7 +2149,7 @@ DECL_PIOCTL(PListCells) register char *cp, *tp = ain; AFS_STATCNT(PListCells); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ memcpy((char *)&whichCell, tp, sizeof(afs_int32)); @@ -2179,7 +2179,7 @@ DECL_PIOCTL(PListAliases) register struct cell_alias *tcalias=0; register char *cp, *tp = ain; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if (ainSize < sizeof(afs_int32)) return EINVAL; @@ -2327,7 +2327,7 @@ DECL_PIOCTL(PGetCellStatus) afs_int32 temp; AFS_STATCNT(PGetCellStatus); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ tcell = afs_GetCellByName(ain, READ_LOCK); @@ -2346,7 +2346,7 @@ DECL_PIOCTL(PSetCellStatus) if (!afs_osi_suser(*acred)) return EACCES; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ tcell = afs_GetCellByName(ain+2*sizeof(afs_int32), WRITE_LOCK); @@ -2371,7 +2371,7 @@ DECL_PIOCTL(PFlushVolumeData) AFS_STATCNT(PFlushVolumeData); if (!avc) return EINVAL; - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ volume = avc->fid.Fid.Volume; /* who to zap */ @@ -2768,7 +2768,7 @@ DECL_PIOCTL(PSetSPrefs) struct setspref *ssp; AFS_STATCNT(PSetSPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if (!afs_osi_suser(*acred)) @@ -2790,7 +2790,7 @@ DECL_PIOCTL(PSetSPrefs33) { struct spref *sp; AFS_STATCNT(PSetSPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ @@ -2821,7 +2821,7 @@ DECL_PIOCTL(PGetSPrefs) int isfs; AFS_STATCNT(PGetSPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ @@ -3228,7 +3228,7 @@ DECL_PIOCTL(PGetCPrefs) int i,j; AFS_STATCNT(PGetCPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ if ( ainSize < sizeof (struct sprefrequest )) @@ -3267,7 +3267,7 @@ DECL_PIOCTL(PSetCPrefs) int i; AFS_STATCNT(PSetCPrefs); - if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */ + if ( !afs_resourceinit_flag ) /* afs daemons haven't started yet */ return EIO; /* Inappropriate ioctl for device */ sin = (struct setspref *)ain; diff --git a/src/config/param.i386_obsd31.h b/src/config/param.i386_obsd31.h index 29b14a130..ad72476bc 100644 --- a/src/config/param.i386_obsd31.h +++ b/src/config/param.i386_obsd31.h @@ -41,6 +41,7 @@ /* Extra kernel definitions (from kdefs file) */ #ifdef _KERNEL +#define AFS_GLOBAL_SUNLOCK 1 #define AFS_SHORTGID 0 /* are group id's short? */ #if !defined(ASSEMBLER) && !defined(__LANGUAGE_ASSEMBLY__) diff --git a/src/fsint/afsaux.c b/src/fsint/afsaux.c index bde2f4a75..1f6473b27 100644 --- a/src/fsint/afsaux.c +++ b/src/fsint/afsaux.c @@ -45,13 +45,12 @@ RCSID("$Header$"); # include "afsint.h" #endif /* KERNEL */ -#define MAXBS 2048 /* try to avoid horrible allocs */ -static afs_int32 bslosers = 0; - #ifdef KERNEL #define NVALLOC(a) osi_Alloc(a) #define NVFREE(a,b) osi_Free(a,b) #else /* KERNEL */ +#define MAXBS 2048 /* try to avoid horrible allocs */ +static afs_int32 bslosers = 0; #define NVALLOC(a) malloc(a) #define NVFREE(a,b) free(a) #endif /* KERNEL */ diff --git a/src/rx/OBSD/rx_kmutex.h b/src/rx/OBSD/rx_kmutex.h index b8ab7c557..06ecb39da 100644 --- a/src/rx/OBSD/rx_kmutex.h +++ b/src/rx/OBSD/rx_kmutex.h @@ -18,18 +18,71 @@ #include -/* Remind me to fix this later... */ +/* You can't have AFS_GLOBAL_SUNLOCK and not RX_ENABLE_LOCKS */ +#define RX_ENABLE_LOCKS 1 +#define AFS_GLOBAL_RXLOCK_KERNEL -#define MUTEX_ISMINE(a) -#define osirx_AssertMine(addr, msg) +/* This is incomplete and probably wouldn't work with NCPUS > 1 */ +typedef int afs_kcondvar_t; + +#define CV_WAIT(cv, lck) { \ + int isGlockOwner = ISAFS_GLOCK(); \ + if (isGlockOwner) AFS_GUNLOCK(); \ + MUTEX_EXIT(lck); \ + tsleep(cv, PSOCK, "afs_rx_cv_wait", 0); \ + if (isGlockOwner) AFS_GLOCK(); \ + MUTEX_ENTER(lck); \ + } +#define CV_SIGNAL(cv) wakeup_one(cv) +#define CV_BROADCAST(cv) wakeup(cv) + +typedef struct { + struct lock lock; + struct proc *owner; +} afs_kmutex_t; + +#define MUTEX_DEFAULT 0 + +#ifdef USE_REAL_MUTEX +/* This doesn't seem to work yet */ +#define MUTEX_ISMINE(a) (((afs_kmutex_t *)(a))->owner == curproc) +#define MUTEX_INIT(a,b,c,d) \ + do { \ + lockinit(&(a)->lock,PSOCK, "afs rx mutex", 0, 0); \ + (a)->owner = 0; \ + } while(0); +#define MUTEX_DESTROY(a) \ + do { \ + (a)->owner = (struct proc *)-1; \ + } while(0); +#define MUTEX_ENTER(a) \ + do { \ + lockmgr(&(a)->lock, LK_EXCLUSIVE, 0, curproc); \ + osi_Assert((a)->owner == 0); \ + (a)->owner = curproc; \ + } while(0); +#define MUTEX_TRYENTER(a) \ + ( lockmgr(&(a)->lock, LK_EXCLUSIVE|LK_NOWAIT, 0, curproc) ? 0 : ((a)->owner = curproc, 1) ) +#define MUTEX_EXIT(a) \ + do { \ + osi_Assert((a)->owner == curproc); \ + (a)->owner = 0; \ + lockmgr(&(a)->lock, LK_RELEASE, 0, curproc); \ + } while(0); +#else /* USE_REAL_MUTEX */ +#define MUTEX_ISMINE(a) 1 +#define MUTEX_INIT(a,b,c,d) #define MUTEX_DESTROY(a) #define MUTEX_ENTER(a) #define MUTEX_TRYENTER(a) 1 -#define MUTEX_EXIT(a) -#define MUTEX_INIT(a,b,c,d) +#define MUTEX_EXIT(a) +#endif /* USE_REAL_MUTEX */ + #define CV_INIT(a,b,c,d) #define CV_DESTROY(a) +#ifndef AFS_GLOBAL_SUNLOCK #define AFS_ASSERT_RXGLOCK() +#endif #endif /* _RX_KMUTEX_H_ */ diff --git a/src/rx/rx.c b/src/rx/rx.c index 4ef315f68..4b71a6aca 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -432,7 +432,7 @@ int rx_Init(u_int port) rx_sleepLock = alloc_spinlock(LAST_HELD_ORDER-10, "rx_sleepLock"); #endif /* KERNEL && AFS_HPUX110_ENV */ #else /* RX_ENABLE_LOCKS */ -#if defined(KERNEL) && defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) +#if defined(KERNEL) && defined(AFS_GLOBAL_SUNLOCK) && !defined(AFS_HPUX_ENV) && !defined(AFS_OBSD_ENV) mutex_init(&afs_rxglobal_lock, "afs_rxglobal_lock", MUTEX_DEFAULT, NULL); #endif /* AFS_GLOBAL_SUNLOCK */ #endif /* RX_ENABLE_LOCKS */ @@ -6322,8 +6322,10 @@ void shutdown_rx(void) { struct rx_serverQueueEntry *np; register int i, j; +#ifndef KERNEL register struct rx_call *call; register struct rx_serverQueueEntry *sq; +#endif /* KERNEL */ LOCK_RX_INIT if (rxinit_status == 1) { diff --git a/src/rx/rx_event.c b/src/rx/rx_event.c index 994fb9ce0..7c719f56f 100644 --- a/src/rx/rx_event.c +++ b/src/rx/rx_event.c @@ -45,6 +45,9 @@ RCSID("$Header$"); #endif extern void *osi_Alloc(); #endif +#if defined(AFS_OBSD_ENV) +#include "h/proc.h" +#endif #else /* KERNEL */ #include #include "rx_clock.h" -- 2.39.5