osi-credp-20030827

Use a pointer for afs_osi_cred, and crget() instead of just inventing one.
Required for FreeBSD, which puts a mutex in the cred.
Not strictly required for other BSDs, but it's more correct.
This commit is contained in:
Jim Rees 2003-08-27 22:43:16 +00:00
parent 3d50a78236
commit f40f466c7f
13 changed files with 55 additions and 72 deletions

View File

@ -34,15 +34,8 @@ osi_UFSOpen(afs_int32 ainode)
afs_int32 code = 0;
int dummy;
AFS_STATCNT(osi_UFSOpen);
if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
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((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
afs_osi_cred.cr_ref++;
afs_osicred_initialized = 1;
}
afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
AFS_GUNLOCK();
code =
@ -61,7 +54,7 @@ osi_UFSOpen(afs_int32 ainode)
#endif
afile->size = VTOI(afile->vnode)->i_size;
afile->offset = 0;
afile->proc = (int (*)())0;
afile->proc = NULL;
afile->inum = ainode; /* for hint validity checking */
return (void *)afile;
}
@ -75,9 +68,9 @@ afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
MObtainWriteLock(&afs_xosi, 320);
AFS_GUNLOCK();
#if defined(AFS_FBSD50_ENV)
code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
#else
code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
#endif
AFS_GLOCK();
if (code == 0) {
@ -122,9 +115,9 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
tvattr.va_size = asize;
AFS_GUNLOCK();
#if defined(AFS_FBSD50_ENV)
code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
#else
code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
#endif
AFS_GLOCK();
MReleaseWriteLock(&afs_xosi);
@ -164,7 +157,7 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
AFS_GUNLOCK();
code =
gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
AFS_GLOCK();
if (code == 0) {
code = asize - resid;
@ -194,7 +187,7 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
AFS_GUNLOCK();
code =
gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred,
afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
&resid);
AFS_GLOCK();
}

View File

@ -320,7 +320,7 @@ afs_vop_close(ap)
if (ap->a_cred)
code = afs_close(avc, ap->a_fflag, ap->a_cred);
else
code = afs_close(avc, ap->a_fflag, &afs_osi_cred);
code = afs_close(avc, ap->a_fflag, afs_osi_credp);
afs_BozonLock(&avc->pvnLock, avc);
osi_FlushPages(avc, ap->a_cred); /* hold bozon lock, but not basic vnode lock */
afs_BozonUnlock(&avc->pvnLock, avc);
@ -695,7 +695,7 @@ afs_vop_fsync(ap)
if (ap->a_cred)
error = afs_fsync(VTOAFS(vp), ap->a_cred);
else
error = afs_fsync(VTOAFS(vp), &afs_osi_cred);
error = afs_fsync(VTOAFS(vp), afs_osi_credp);
AFS_GUNLOCK();
return error;
}

View File

@ -34,15 +34,8 @@ osi_UFSOpen(afs_int32 ainode)
afs_int32 code = 0;
int dummy;
AFS_STATCNT(osi_UFSOpen);
if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
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((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
afs_osi_cred.cr_ref++;
afs_osicred_initialized = 1;
}
afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
AFS_GUNLOCK();
code =
@ -70,7 +63,7 @@ afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
AFS_STATCNT(osi_Stat);
MObtainWriteLock(&afs_xosi, 320);
AFS_GUNLOCK();
VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
AFS_GLOCK();
if (code == 0) {
astat->size = tvattr.va_size;
@ -116,11 +109,11 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
* of ufs's references directly to cred instead of to
* credentials parameter. Probably should fix ufs some day. */
oldCred = curproc->p_cred->pc_ucred; /* remember old credentials pointer */
curproc->p_cred->pc_ucred = &afs_osi_cred;
curproc->p_cred->pc_ucred = afs_osi_credp;
/* temporarily use superuser credentials */
tvattr.va_size = asize;
AFS_GUNLOCK();
VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
AFS_GLOCK();
curproc->p_cred->pc_ucred = oldCred; /* restore */
MReleaseWriteLock(&afs_xosi);
@ -162,7 +155,7 @@ afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
AFS_GUNLOCK();
code =
gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
AFS_GLOCK();
if (code == 0) {
code = asize - resid;
@ -191,11 +184,11 @@ afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
afile->offset = offset;
{
struct ucred *tmpcred = curproc->p_cred->pc_ucred;
curproc->p_cred->pc_ucred = &afs_osi_cred;
curproc->p_cred->pc_ucred = afs_osi_credp;
AFS_GUNLOCK();
code =
gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred,
afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
&resid);
AFS_GLOCK();
curproc->p_cred->pc_ucred = tmpcred;

View File

@ -60,7 +60,7 @@ afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
AFS_STATCNT(osi_Stat);
MObtainWriteLock(&afs_xosi, 320);
AFS_GUNLOCK();
code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
AFS_GLOCK();
if (code == 0) {
astat->size = afile->size = tvattr.va_size;
@ -107,7 +107,7 @@ osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
tvattr.va_size = asize;
AFS_GUNLOCK();
VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
VOP_UNLOCK(afile->vnode, 0, curproc);
AFS_GLOCK();
if (code == 0)
@ -150,7 +150,7 @@ afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
AFS_GUNLOCK();
code =
vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid, curproc);
AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
AFS_GLOCK();
if (code == 0) {
code = asize - resid;
@ -182,7 +182,7 @@ afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
code =
vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid, curproc);
AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
VOP_UNLOCK(afile->vnode, 0, curproc);
AFS_GLOCK();

View File

@ -720,7 +720,7 @@ afs_UFSRead(register struct vcache *avc, struct uio *auio,
AFS_GUNLOCK();
code =
VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL,
NULL, &afs_osi_cred);
NULL, afs_osi_credp);
AFS_GLOCK();
#elif defined(AFS_AIX32_ENV)
code =
@ -756,26 +756,26 @@ afs_UFSRead(register struct vcache *avc, struct uio *auio,
#elif defined(AFS_SUN5_ENV)
AFS_GUNLOCK();
VOP_RWLOCK(tfile->vnode, 0);
code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_RWUNLOCK(tfile->vnode, 0);
AFS_GLOCK();
#elif defined(AFS_SGI_ENV)
AFS_GUNLOCK();
AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_READ);
AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, &afs_osi_cred,
AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp,
code);
AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_READ);
AFS_GLOCK();
#elif defined(AFS_OSF_ENV)
tuio.uio_rw = UIO_READ;
AFS_GUNLOCK();
VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred, code);
VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, code);
AFS_GLOCK();
#elif defined(AFS_SUN_ENV)
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred);
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
#elif defined(AFS_HPUX100_ENV)
AFS_GUNLOCK();
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred);
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
AFS_GLOCK();
#elif defined(AFS_LINUX20_ENV)
AFS_GUNLOCK();
@ -784,23 +784,23 @@ afs_UFSRead(register struct vcache *avc, struct uio *auio,
#elif defined(AFS_DARWIN_ENV)
AFS_GUNLOCK();
VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc());
code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_UNLOCK(tfile->vnode, 0, current_proc());
AFS_GLOCK();
#elif defined(AFS_FBSD50_ENV)
AFS_GUNLOCK();
VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curthread);
code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_UNLOCK(tfile->vnode, 0, curthread);
AFS_GLOCK();
#elif defined(AFS_XBSD_ENV)
AFS_GUNLOCK();
VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
code = VOP_READ(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_UNLOCK(tfile->vnode, 0, curproc);
AFS_GLOCK();
#else
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, &afs_osi_cred);
code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
#endif
#ifdef IHINT

View File

@ -521,7 +521,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
AFS_GUNLOCK();
code =
VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, &tuio, NULL, NULL,
NULL, &afs_osi_cred);
NULL, afs_osi_credp);
AFS_GLOCK();
#else
#ifdef AFS_AIX32_ENV
@ -536,7 +536,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
#ifdef AFS_SUN5_ENV
AFS_GUNLOCK();
VOP_RWLOCK(tfile->vnode, 1);
code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_RWUNLOCK(tfile->vnode, 1);
AFS_GLOCK();
if (code == ENOSPC)
@ -547,7 +547,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
AFS_GUNLOCK();
avc->states |= CWritingUFS;
AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_WRITE);
AFS_VOP_WRITE(tfile->vnode, &tuio, IO_ISLOCKED, &afs_osi_cred, code);
AFS_VOP_WRITE(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp, code);
AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_WRITE);
avc->states &= ~CWritingUFS;
AFS_GLOCK();
@ -555,10 +555,10 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
#ifdef AFS_OSF_ENV
{
struct ucred *tmpcred = u.u_cred;
u.u_cred = &afs_osi_cred;
u.u_cred = afs_osi_credp;
tuio.uio_rw = UIO_WRITE;
AFS_GUNLOCK();
VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred, code);
VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp, code);
AFS_GLOCK();
u.u_cred = tmpcred;
}
@ -566,7 +566,7 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
#if defined(AFS_HPUX100_ENV)
{
AFS_GUNLOCK();
code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, &afs_osi_cred);
code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, afs_osi_credp);
AFS_GLOCK();
}
#else
@ -581,18 +581,18 @@ afs_UFSWrite(register struct vcache *avc, struct uio *auio, int aio,
#if defined(AFS_DARWIN_ENV)
AFS_GUNLOCK();
VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc());
code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_UNLOCK(tfile->vnode, 0, current_proc());
AFS_GLOCK();
#else
#if defined(AFS_XBSD_ENV)
AFS_GUNLOCK();
VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
code = VOP_WRITE(tfile->vnode, &tuio, 0, &afs_osi_cred);
code = VOP_WRITE(tfile->vnode, &tuio, 0, afs_osi_credp);
VOP_UNLOCK(tfile->vnode, 0, curproc);
AFS_GLOCK();
#else
code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, &afs_osi_cred);
code = VOP_RDWR(tfile->vnode, &tuio, UIO_WRITE, 0, afs_osi_credp);
#endif /* AFS_XBSD_ENV */
#endif /* AFS_DARWIN_ENV */
#endif /* AFS_LINUX20_ENV */

View File

@ -323,7 +323,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
AFS_STATCNT(CheckVLDB);
afs_FinalizeReq(areq);
if ((i = afs_InitReq(&treq, &afs_osi_cred)))
if ((i = afs_InitReq(&treq, afs_osi_credp)))
return DUNNO;
v = afs_osi_Alloc(sizeof(*v));
tcell = afs_GetCell(afid->Cell, READ_LOCK);

View File

@ -40,6 +40,8 @@ lock_t afs_event_lock;
flid_t osi_flid;
#endif
struct AFS_UCRED *afs_osi_credp;
void
osi_Init(void)
{
@ -70,17 +72,13 @@ osi_Init(void)
#endif /* AFS_HPUX_ENV */
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;
#ifdef AFS_XBSD_ENV
/* Can't just invent one, must use crget() because of mutex */
afs_osi_credp = crdup(osi_curcred());
#else
memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
crhold(&afs_osi_cred); /* don't let it evaporate */
afs_osi_credp = &afs_osi_cred;
#endif
afs_osicred_initialized = 1;
}

View File

@ -396,7 +396,7 @@ typedef struct timeval osi_timeval_t;
/* Declare any structures which use these macros after the OSI implementation
* has had the opportunity to redefine them.
*/
extern struct AFS_UCRED afs_osi_cred;
extern struct AFS_UCRED afs_osi_cred, *afs_osi_credp;
#ifndef osi_curcred
#define osi_curcred() (u.u_cred)

View File

@ -507,7 +507,7 @@ afs_CheckServers(int adown, struct cell *acellp)
XSTATS_DECLS;
AFS_STATCNT(afs_CheckServers);
if ((code = afs_InitReq(&treq, &afs_osi_cred)))
if ((code = afs_InitReq(&treq, afs_osi_credp)))
return;
ObtainReadLock(&afs_xserver); /* Necessary? */
ObtainReadLock(&afs_xsrvAddr);

View File

@ -335,7 +335,7 @@ afs_FlushVCBs(afs_int32 lockit)
struct vrequest treq;
struct conn *tc;
int safety1, safety2, safety3;
XSTATS_DECLS if ((code = afs_InitReq(&treq, &afs_osi_cred)))
XSTATS_DECLS if ((code = afs_InitReq(&treq, afs_osi_credp)))
return code;
treq.flags |= O_NONBLOCK;
tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
@ -1199,7 +1199,7 @@ afs_FlushActiveVcaches(register afs_int32 doflocks)
ReleaseReadLock(&afs_xvcache);
ObtainWriteLock(&tvc->lock, 51);
do {
afs_InitReq(&treq, &afs_osi_cred);
afs_InitReq(&treq, afs_osi_credp);
treq.flags |= O_NONBLOCK;
tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);

View File

@ -603,7 +603,7 @@ afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
tve = (struct vldbentry *)(tbuffer + 1024);
ntve = (struct nvldbentry *)tve;
utve = (struct uvldbentry *)tve;
afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
do {
tconn =
afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,

View File

@ -786,9 +786,8 @@ rxk_NewSocket(short aport)
#elif defined(AFS_SGI65_ENV) || defined(AFS_OBSD_ENV)
code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP);
#elif defined(AFS_FBSD50_ENV)
code =
socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP, &afs_osi_cred,
curthread);
code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP,
afs_osi_credp, curthread);
#elif defined(AFS_FBSD40_ENV)
code = socreate(AF_INET, &newSocket, SOCK_DGRAM, IPPROTO_UDP, curproc);
#else