From 54a006573f20877eb87f0467fd68f0164c4c0993 Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Mon, 10 Jun 2002 11:48:35 +0000 Subject: [PATCH] This commit was generated by cvs2svn to compensate for changes in r489, which included commits to RCS files with non-trunk default branches. --- NEWS | 8 + acinclude.m4 | 3 + configure-libafs.in | 2 +- src/afs/VNOPS/afs_vnop_attrs.c | 4 +- src/afs/VNOPS/afs_vnop_remove.c | 4 +- src/afs/afs_callback.c | 30 ++-- src/afs/afs_segments.c | 32 ++-- src/afs/sysincludes.h | 4 +- src/afsd/afsd.c | 8 +- src/des/crypt.c | 9 +- src/dir/buffer.c | 12 +- src/fsint/afsaux.c | 7 +- src/fsint/afsint.xg | 2 +- src/fsint/common.xg | 2 +- src/libafs/MakefileProto.AIX.in | 13 +- src/libafs/MakefileProto.DARWIN.in | 13 +- src/libafs/MakefileProto.FBSD.in | 5 +- src/libafs/MakefileProto.HPUX.in | 5 +- src/libafs/MakefileProto.IRIX.in | 5 +- src/libafs/MakefileProto.OBSD.in | 5 +- src/libafs/MakefileProto.SOLARIS.in | 5 +- src/rx/rx_kcommon.c | 29 +++- src/rx/rx_kcommon.h | 4 +- src/rx/xdr.h | 27 +++ src/rx/xdr_rx.c | 4 +- src/rxgen/rpc_main.c | 23 +-- src/rxkad/rxkad_client.c | 4 +- src/rxkad/rxkad_common.c | 4 +- src/util/NTMakefile | 2 +- src/viced/host.c | 45 +++-- src/vlserver/vldbint.xg | 2 +- src/vol/ihandle.c | 261 ++++++++++++---------------- 32 files changed, 281 insertions(+), 302 deletions(-) diff --git a/NEWS b/NEWS index 61bda66ad..999ef8761 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,13 @@ OpenAFS News -- history of user-visible changes. October 19, 2001 +* Changes incorporated in OpenAFS 1.2.5 + +** A remote denial of service attack in the AIX and IRIX clients has + been fixed. Users of those platforms are strongly encouraged to + upgrade. + +** Fixed race conditions in fileserver that could result in crash. + * Changes incorporated in OpenAFS 1.2.4 ** Server logfiles now more consistant about format in which hosts are diff --git a/acinclude.m4 b/acinclude.m4 index e72a8885f..665688692 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -251,6 +251,9 @@ else powerpc-apple-darwin5.4*) AFS_SYSNAME="ppc_darwin_14" ;; + powerpc-apple-darwin5.5*) + AFS_SYSNAME="ppc_darwin_14" + ;; sparc-sun-solaris2.5*) AFS_SYSNAME="sun4x_55" ;; diff --git a/configure-libafs.in b/configure-libafs.in index f64440e31..f70787657 100644 --- a/configure-libafs.in +++ b/configure-libafs.in @@ -1,5 +1,5 @@ AC_INIT(Makefile.common) -AM_INIT_AUTOMAKE(openafs-libafs,1.2.4) +AM_INIT_AUTOMAKE(openafs-libafs,1.2.5) AC_CONFIG_HEADER(config/afsconfig.h) define(OPENAFS_CONFIGURE_LIBAFS) diff --git a/src/afs/VNOPS/afs_vnop_attrs.c b/src/afs/VNOPS/afs_vnop_attrs.c index cc4b9af22..f19091435 100644 --- a/src/afs/VNOPS/afs_vnop_attrs.c +++ b/src/afs/VNOPS/afs_vnop_attrs.c @@ -21,7 +21,7 @@ #include #include "../afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_attrs.c,v 1.1.1.8 2002/05/10 23:44:19 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_attrs.c,v 1.1.1.9 2002/06/10 11:40:12 hartmans Exp $"); #include "../afs/sysincludes.h" /* Standard vendor system headers */ #include "../afs/afsincludes.h" /* Afs-based standard headers */ @@ -93,7 +93,7 @@ afs_CopyOutAttrs(avc, attrs) attrs->va_nlink = avc->m.LinkCount; attrs->va_size = avc->m.Length; attrs->va_atime.tv_sec = attrs->va_mtime.tv_sec = attrs->va_ctime.tv_sec = - avc->m.Date; + (int)avc->m.Date; /* set microseconds to be dataversion # so that we approximate NFS-style * use of mtime as a dataversion #. We take it mod 512K because * microseconds *must* be less than a million, and 512K is the biggest diff --git a/src/afs/VNOPS/afs_vnop_remove.c b/src/afs/VNOPS/afs_vnop_remove.c index 29ad5b267..467083c5d 100644 --- a/src/afs/VNOPS/afs_vnop_remove.c +++ b/src/afs/VNOPS/afs_vnop_remove.c @@ -22,7 +22,7 @@ #include #include "../afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_remove.c,v 1.1.1.7 2002/05/10 23:44:24 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/afs/VNOPS/afs_vnop_remove.c,v 1.1.1.8 2002/06/10 11:40:14 hartmans Exp $"); #include "../afs/sysincludes.h" /* Standard vendor system headers */ #include "../afs/afsincludes.h" /* Afs-based standard headers */ @@ -356,7 +356,7 @@ tagain: char *unlname = newname(); ReleaseWriteLock(&adp->lock); - code = afsrename(adp, aname, adp, unlname, acred); + code = afsrename(adp, aname, adp, unlname, acred, &treq); Tnam1 = unlname; if (!code) { tvc->mvid = (struct VenusFid *)unlname; diff --git a/src/afs/afs_callback.c b/src/afs/afs_callback.c index f33062b8f..6eb2d4e0d 100644 --- a/src/afs/afs_callback.c +++ b/src/afs/afs_callback.c @@ -16,7 +16,7 @@ #include #include "../afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_callback.c,v 1.1.1.8 2002/05/10 23:43:09 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_callback.c,v 1.1.1.9 2002/06/10 11:39:52 hartmans Exp $"); #include "../afs/sysincludes.h" /*Standard vendor system headers*/ #include "../afs/afsincludes.h" /*AFS-based standard headers*/ @@ -1125,7 +1125,7 @@ int SRXAFSCB_GetCellServDB( struct rx_call *a_call, afs_int32 a_index, char **a_name, - afs_int32 *a_hosts) + serverList *a_hosts) { afs_int32 i, j; struct cell *tcell; @@ -1137,27 +1137,27 @@ int SRXAFSCB_GetCellServDB( #endif /* RX_ENABLE_LOCKS */ AFS_STATCNT(SRXAFSCB_GetCellServDB); - memset(a_hosts, 0, AFSMAXCELLHOSTS * sizeof(afs_int32)); - - /* search the list for the cell with this index */ - ObtainReadLock(&afs_xcell); - tcell = afs_GetCellByIndex(a_index, READ_LOCK, 0); if (!tcell) { i = 0; + a_hosts->serverList_val = 0; + a_hosts->serverList_len = 0; } else { p_name = tcell->cellName; - for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) { - a_hosts[j] = ntohl(tcell->cellHosts[j]->addr->sa_ip); - } + for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) + ; i = strlen(p_name); + a_hosts->serverList_val = (afs_int32 *)afs_osi_Alloc(j*sizeof(afs_int32)); + a_hosts->serverList_len = j; + for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) + a_hosts->serverList_val[j] = ntohl(tcell->cellHosts[j]->addr->sa_ip); afs_PutCell(tcell, READ_LOCK); } - t_name = (char *)rxi_Alloc(i+1); + t_name = (char *)afs_osi_Alloc(i+1); if (t_name == NULL) { - ReleaseReadLock(&afs_xcell); + afs_osi_Free(a_hosts->serverList_val, (j*sizeof(afs_int32))); #ifdef RX_ENABLE_LOCKS AFS_GUNLOCK(); #endif /* RX_ENABLE_LOCKS */ @@ -1168,8 +1168,6 @@ int SRXAFSCB_GetCellServDB( if (p_name) memcpy(t_name, p_name, i); - ReleaseReadLock(&afs_xcell); - #ifdef RX_ENABLE_LOCKS AFS_GUNLOCK(); #endif /* RX_ENABLE_LOCKS */ @@ -1234,7 +1232,7 @@ int SRXAFSCB_GetLocalCell( plen = strlen(p_name); else plen = 0; - t_name = (char *)rxi_Alloc(plen+1); + t_name = (char *)afs_osi_Alloc(plen+1); if (t_name == NULL) { ReleaseReadLock(&afs_xcell); #ifdef RX_ENABLE_LOCKS @@ -1340,7 +1338,7 @@ int SRXAFSCB_GetCacheConfig( * Currently only support version 1 */ allocsize = sizeof(cm_initparams_v1); - t_config = (afs_uint32 *)rxi_Alloc(allocsize); + t_config = (afs_uint32 *)afs_osi_Alloc(allocsize); if (t_config == NULL) { #ifdef RX_ENABLE_LOCKS AFS_GUNLOCK(); diff --git a/src/afs/afs_segments.c b/src/afs/afs_segments.c index a5e80cabe..3c05d4fef 100644 --- a/src/afs/afs_segments.c +++ b/src/afs/afs_segments.c @@ -13,7 +13,7 @@ #include #include "../afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_segments.c,v 1.1.1.6 2002/01/22 19:48:00 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/afs/afs_segments.c,v 1.1.1.7 2002/06/10 11:39:56 hartmans Exp $"); #include "../afs/sysincludes.h" /*Standard vendor system headers*/ #include "../afs/afsincludes.h" /*AFS-based standard headers*/ @@ -284,6 +284,8 @@ afs_StoreAllSegments(avc, areq, sync) if (j) { static afs_uint32 lp1 = 10000, lp2 = 10000; struct AFSStoreStatus InStatus; + struct AFSFetchStatus OutStatus; + int doProcessFS = 0; afs_uint32 base, bytes, nchunks; int nomore; unsigned int first; @@ -475,7 +477,6 @@ afs_StoreAllSegments(avc, areq, sync) * one which has the writing bit turned on. */ } if (!code) { - struct AFSFetchStatus OutStatus; struct AFSVolSync tsync; #ifdef RX_ENABLE_LOCKS AFS_GUNLOCK(); @@ -486,19 +487,7 @@ afs_StoreAllSegments(avc, areq, sync) #endif /* RX_ENABLE_LOCKS */ hadd32(newDV, 1); XSTATS_END_TIME; - - /* Now copy out return params */ - UpgradeSToWLock(&avc->lock,28); /* keep out others for a while */ - if (!code) { /* must wait til RPC completes to be sure of this info */ - afs_ProcessFS(avc, &OutStatus, areq); - /* Keep last (max) size of file on server to see if - * we need to call afs_StoreMini to extend the file. - */ - if (!moredata) - maxStoredLength = OutStatus.Length; - - } - ConvertWToSLock(&avc->lock); + if (!code) doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */ } if (tcall) { #ifdef RX_ENABLE_LOCKS @@ -538,6 +527,19 @@ afs_StoreAllSegments(avc, areq, sync) lockedPutDCache(tdc); } + if (doProcessFS) { + /* Now copy out return params */ + UpgradeSToWLock(&avc->lock,28); /* keep out others for a while */ + afs_ProcessFS(avc, &OutStatus, areq); + /* Keep last (max) size of file on server to see if + * we need to call afs_StoreMini to extend the file. + */ + if (!moredata) + maxStoredLength = OutStatus.Length; + ConvertWToSLock(&avc->lock); + doProcessFS = 0; + } + if (code) { for (j++; j<=high; j++) if ( dcList[j] ) diff --git a/src/afs/sysincludes.h b/src/afs/sysincludes.h index 14c42fbd7..197f68dcc 100644 --- a/src/afs/sysincludes.h +++ b/src/afs/sysincludes.h @@ -268,7 +268,7 @@ struct vfspage; /* for vnode.h compiler warnings */ #endif /* AFS_SUN5_ENV */ #include "../rpc/types.h" -#include "../rpc/xdr.h" +#include "../rx/xdr.h" #ifdef AFS_AIX32_ENV # include "net/spl.h" @@ -363,7 +363,7 @@ struct vfspage; /* for vnode.h compiler warnings */ #undef register #endif /* AFS_ALPHA_ENV */ -#include +#include #include #include diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index f644cbfc2..247fe25c2 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -55,7 +55,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/afsd/afsd.c,v 1.1.1.12 2002/01/22 19:52:07 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/afsd/afsd.c,v 1.1.1.13 2002/06/10 11:44:53 hartmans Exp $"); #define VFS 1 @@ -1290,7 +1290,11 @@ mainproc(as, arock) * Cold shutdown is the default */ printf("afsd: Shutting down all afs processes and afs state\n"); - call_syscall(AFSOP_SHUTDOWN, 1); + code = call_syscall(AFSOP_SHUTDOWN, 1); + if (code) { + printf("afsd: AFS still mounted; Not shutting down\n"); + exit(1); + } exit(0); } if (as->parms[21].items) { diff --git a/src/des/crypt.c b/src/des/crypt.c index aae130848..a0fce5955 100644 --- a/src/des/crypt.c +++ b/src/des/crypt.c @@ -37,7 +37,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/des/crypt.c,v 1.1.1.5 2001/09/11 14:32:29 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/des/crypt.c,v 1.1.1.6 2002/06/10 11:45:53 hartmans Exp $"); #ifdef AFS_NT40_ENV #include @@ -88,7 +88,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/des/crypt.c,v 1.1.1.5 2001/09/11 14:32: * define "LONG_IS_32_BITS" only if sizeof(long)==4. * This avoids use of bit fields (your compiler may be sloppy with them). */ -#if !defined(cray) +#if !defined(cray) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) #define LONG_IS_32_BITS #endif @@ -249,13 +249,8 @@ typedef union { struct { #if defined(LONG_IS_32_BITS) /* long is often faster than a 32-bit bit field */ -#if defined(AFS_IA64_LINUX20_ENV) - int i0; - int i1; -#else long i0; long i1; -#endif #else long i0: 32; long i1: 32; diff --git a/src/dir/buffer.c b/src/dir/buffer.c index 1ad93832c..3198e4fd8 100644 --- a/src/dir/buffer.c +++ b/src/dir/buffer.c @@ -10,7 +10,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/dir/buffer.c,v 1.1.1.8 2002/05/10 23:58:41 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/dir/buffer.c,v 1.1.1.9 2002/06/10 11:45:57 hartmans Exp $"); #include #include @@ -132,8 +132,8 @@ char *DRead(fid,page) if ( tb = phTable[pHash(fid)] ) { /* ASSMT HERE */ if (bufmatch(tb)) { ObtainWriteLock(&tb->lock); - ReleaseWriteLock(&afs_bufferLock); tb->lockers++; + ReleaseWriteLock(&afs_bufferLock); tb->accesstime = ++timecounter; ReleaseWriteLock(&tb->lock); return tb->data; @@ -144,8 +144,8 @@ char *DRead(fid,page) if (bufmatch(tb2)) { buf_Front(bufhead,tb,tb2); ObtainWriteLock(&tb2->lock); - ReleaseWriteLock(&afs_bufferLock); tb2->lockers++; + ReleaseWriteLock(&afs_bufferLock); tb2->accesstime = ++timecounter; ReleaseWriteLock(&tb2->lock); return tb2->data; @@ -154,8 +154,8 @@ char *DRead(fid,page) if (bufmatch(tb)) { buf_Front(bufhead,tb2,tb); ObtainWriteLock(&tb->lock); - ReleaseWriteLock(&afs_bufferLock); tb->lockers++; + ReleaseWriteLock(&afs_bufferLock); tb->accesstime = ++timecounter; ReleaseWriteLock(&tb->lock); return tb->data; @@ -175,8 +175,8 @@ char *DRead(fid,page) tb = newslot(fid, page, (tb ? tb : tb2)); ios++; ObtainWriteLock(&tb->lock); - ReleaseWriteLock(&afs_bufferLock); tb->lockers++; + ReleaseWriteLock(&afs_bufferLock); if (ReallyRead(tb->fid,tb->page,tb->data)) { tb->lockers--; FidZap(tb->fid); /* disaster */ @@ -396,8 +396,8 @@ char *DNew (fid,page) ObtainWriteLock(&afs_bufferLock); tb = newslot(fid,page,0); ObtainWriteLock(&tb->lock); - ReleaseWriteLock(&afs_bufferLock); tb->lockers++; + ReleaseWriteLock(&afs_bufferLock); ReleaseWriteLock(&tb->lock); return tb->data; } diff --git a/src/fsint/afsaux.c b/src/fsint/afsaux.c index 31c39a212..8a5f354f1 100644 --- a/src/fsint/afsaux.c +++ b/src/fsint/afsaux.c @@ -14,7 +14,7 @@ #include #endif -RCSID("$Header: /tmp/cvstemp/openafs/src/fsint/afsaux.c,v 1.1.1.5 2001/07/14 22:21:55 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/fsint/afsaux.c,v 1.1.1.6 2002/06/10 11:45:59 hartmans Exp $"); #ifdef KERNEL #if defined(UKERNEL) @@ -28,7 +28,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/fsint/afsaux.c,v 1.1.1.5 2001/07/14 22: #else #include "../h/types.h" #include "../rpc/types.h" -#include "../rpc/xdr.h" +#include "../rx/xdr.h" #endif #if !defined(AFS_ALPHA_ENV) #ifndef XDR_GETINT32 @@ -38,9 +38,6 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/fsint/afsaux.c,v 1.1.1.5 2001/07/14 22: #define XDR_PUTINT32 XDR_PUTLONG #endif #endif -#ifndef AFS_LINUX22_ENV -#include "../rpc/auth.h" -#endif #endif /* defined(UKERNEL) */ #include "../afsint/afsint.h" #else /* KERNEL */ diff --git a/src/fsint/afsint.xg b/src/fsint/afsint.xg index 549b5badf..76fd54c4e 100644 --- a/src/fsint/afsint.xg +++ b/src/fsint/afsint.xg @@ -45,7 +45,7 @@ typedef afs_int32 ViceDataType; %#define SymbolicLink 3 %#ifdef KERNEL -%#define xdr_array(a,b,c,d,e,f) xdr_arrayN(a,b,c,d,e,f) +%#define afs_xdr_array(a,b,c,d,e,f) afs_xdr_arrayN(a,b,c,d,e,f) %#endif struct BD { diff --git a/src/fsint/common.xg b/src/fsint/common.xg index c658b6dfe..5215be4ab 100644 --- a/src/fsint/common.xg +++ b/src/fsint/common.xg @@ -136,7 +136,7 @@ struct interfaceAddr { /* for multihomed clients */ }; const AFSMAXCELLHOSTS = 8; /*Max VLDB servers per cell*/ -typedef afs_int32 serverList[AFSMAXCELLHOSTS]; +typedef afs_int32 serverList; typedef afs_uint32 cacheConfig<>; diff --git a/src/libafs/MakefileProto.AIX.in b/src/libafs/MakefileProto.AIX.in index 0d7c3ab4e..21d2e702f 100644 --- a/src/libafs/MakefileProto.AIX.in +++ b/src/libafs/MakefileProto.AIX.in @@ -37,10 +37,7 @@ AFS_OS_OBJS = \ osi_misc.o \ osi_sleep.o \ osi_timeout.o \ - osi_vm.o \ - xdr.o \ - xdr_array.o \ - xdr_int64.o + osi_vm.o AFSNOIAUTHOBJS = \ afs_call.o \ @@ -157,14 +154,6 @@ dest_libafs: $(DEST_LIBAFS) $(DEST_LIBAFSIAUTH) # Object build rules: # Common objects -xdr.o: $(RX)/xdr.c - $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) - -xdr_array.o: $(RX)/xdr_array.c - $(CRULE1) - osi_assem.o: ${AFS}/osi_assem.s ${AS} -o osi_assem.o ${AFS}/osi_assem.s osi_config.o: $(AFS)/osi_config.c diff --git a/src/libafs/MakefileProto.DARWIN.in b/src/libafs/MakefileProto.DARWIN.in index 9b4080876..45b4a87cb 100644 --- a/src/libafs/MakefileProto.DARWIN.in +++ b/src/libafs/MakefileProto.DARWIN.in @@ -1,5 +1,5 @@ #/* Copyright (C) 1995, 1989 Transarc Corporation - All rights reserved */ -# $Header: /tmp/cvstemp/openafs/src/libafs/MakefileProto.DARWIN.in,v 1.1.1.4 2001/10/14 18:05:40 hartmans Exp $ +# $Header: /tmp/cvstemp/openafs/src/libafs/MakefileProto.DARWIN.in,v 1.1.1.5 2002/06/10 11:46:33 hartmans Exp $ # # MakefileProto for Digital Unix systems # @@ -34,10 +34,7 @@ AFS_OS_OBJS = \ osi_sleep.o \ osi_vm.o \ osi_vnodeops.o \ - osi_module.o \ - xdr.o \ - xdr_array.o \ - xdr_int64.o + osi_module.o #AFS_OS_NFSOBJS = osi_vfsops_nfs.o @@ -136,9 +133,3 @@ osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) osi_module.o: $(AFS)/osi_module.c $(CRULE1) -xdr.o: $(RX)/xdr.c - $(CRULE1) -xdr_array.o: $(RX)/xdr_array.c - $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) diff --git a/src/libafs/MakefileProto.FBSD.in b/src/libafs/MakefileProto.FBSD.in index ef84b2263..8f74f1a16 100644 --- a/src/libafs/MakefileProto.FBSD.in +++ b/src/libafs/MakefileProto.FBSD.in @@ -30,8 +30,7 @@ AFS_OS_OBJS = \ osi_misc.o \ osi_sleep.o \ osi_vm.o \ - osi_vnodeops.o \ - xdr_int64.o + osi_vnodeops.o AFS_OS_NFSOBJS = \ osi_vfsops_nfs.o @@ -148,5 +147,3 @@ osi_vm.o: $(AFS)/osi_vm.c $(CRULE1) osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) diff --git a/src/libafs/MakefileProto.HPUX.in b/src/libafs/MakefileProto.HPUX.in index ab50ceb3c..6562701d6 100644 --- a/src/libafs/MakefileProto.HPUX.in +++ b/src/libafs/MakefileProto.HPUX.in @@ -36,8 +36,7 @@ AFS_OS_OBJS = \ osi_misc.o \ osi_sleep.o \ osi_vnodeops.o \ - osi_vm.o \ - xdr_int64.o + osi_vm.o AFS_OS_NFSOBJS = \ osi_vfsops_nfs.o @@ -196,8 +195,6 @@ osi_vm.o: $(AFS)/osi_vm.c $(CRULE1) osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) # This is a list of header files compiled with the -g option. It allows # examination of AFS structures in a dump. diff --git a/src/libafs/MakefileProto.IRIX.in b/src/libafs/MakefileProto.IRIX.in index 1d9c6b1a8..a3709806c 100644 --- a/src/libafs/MakefileProto.IRIX.in +++ b/src/libafs/MakefileProto.IRIX.in @@ -37,8 +37,7 @@ AFS_OS_OBJS = \ osi_misc.o \ osi_sleep.o \ osi_vm.o \ - osi_vnodeops.o \ - xdr_int64.o + osi_vnodeops.o AFS_OS_NFSOBJS = \ osi_vfsops_nfs.o @@ -506,5 +505,3 @@ osi_vm.o: $(AFS)/osi_vm.c $(CRULE1) osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) diff --git a/src/libafs/MakefileProto.OBSD.in b/src/libafs/MakefileProto.OBSD.in index 31e172c9e..157b4439d 100644 --- a/src/libafs/MakefileProto.OBSD.in +++ b/src/libafs/MakefileProto.OBSD.in @@ -30,8 +30,7 @@ AFS_OS_OBJS = \ osi_misc.o \ osi_sleep.o \ osi_vm.o \ - osi_vnodeops.o \ - xdr_int64.o + osi_vnodeops.o AFS_OS_NFSOBJS = \ osi_vfsops_nfs.o @@ -148,5 +147,3 @@ osi_vm.o: $(AFS)/osi_vm.c $(CRULE1) osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) diff --git a/src/libafs/MakefileProto.SOLARIS.in b/src/libafs/MakefileProto.SOLARIS.in index afc4dbb59..fac745683 100644 --- a/src/libafs/MakefileProto.SOLARIS.in +++ b/src/libafs/MakefileProto.SOLARIS.in @@ -34,8 +34,7 @@ AFS_OS_OBJS = \ osi_file.o \ osi_sleep.o \ osi_vm.o \ - osi_vnodeops.o \ - xdr_int64.o + osi_vnodeops.o AFS_OS_NFSOBJS = \ osi_vfsops_nfs.o @@ -198,5 +197,3 @@ osi_vm.o: $(AFS)/osi_vm.c $(CRULE1) osi_vnodeops.o: $(AFS)/osi_vnodeops.c $(CRULE1) -xdr_int64.o: $(RX)/xdr_int64.c - $(CRULE1) diff --git a/src/rx/rx_kcommon.c b/src/rx/rx_kcommon.c index 13cf96757..cc6e73d4e 100644 --- a/src/rx/rx_kcommon.c +++ b/src/rx/rx_kcommon.c @@ -14,7 +14,7 @@ #include #include "../afs/param.h" -RCSID("$Header: /tmp/cvstemp/openafs/src/rx/rx_kcommon.c,v 1.1.1.11 2002/05/11 00:01:27 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/rx/rx_kcommon.c,v 1.1.1.12 2002/06/10 11:47:11 hartmans Exp $"); #include "../rx/rx_kcommon.h" @@ -998,7 +998,22 @@ int rxk_ReadPacket(osi_socket so, struct rx_packet *p, int *host, int *port) */ int rxk_ListenerPid; /* Used to signal process to wakeup at shutdown */ +#ifdef AFS_SUN5_ENV +/* + * Run the listener as a kernel process. + */ +void rxk_Listener(void) +{ + extern id_t syscid; + void rxk_ListenerProc(void); + if (newproc(rxk_ListenerProc, syscid, 59)) + osi_Panic("rxk_Listener: failed to fork listener process!\n"); +} + +void rxk_ListenerProc(void) +#else /* AFS_SUN5_ENV */ void rxk_Listener(void) +#endif /* AFS_SUN5_ENV */ { struct rx_packet *rxp = NULL; int code; @@ -1013,9 +1028,9 @@ void rxk_Listener(void) #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) rxk_ListenerPid = current_proc()->p_pid; #endif -#if defined(RX_ENABLE_LOCKS) +#if defined(RX_ENABLE_LOCKS) && !defined(AFS_SUN5_ENV) AFS_GUNLOCK(); -#endif /* RX_ENABLE_LOCKS */ +#endif /* RX_ENABLE_LOCKS && !AFS_SUN5_ENV */ while (afs_termState != AFSOP_STOP_RXK_LISTENER) { if (rxp) { @@ -1047,6 +1062,14 @@ void rxk_Listener(void) #if defined(AFS_LINUX22_ENV) || defined(AFS_SUN5_ENV) afs_osi_Wakeup(&rxk_ListenerPid); #endif +#ifdef AFS_SUN5_ENV + AFS_GUNLOCK(); +#ifdef HAVE_P_COREFILE + if (!curproc->p_corefile) /* newproc doesn't set it, but exit frees it */ + curproc->p_corefile = refstr_alloc("core"); +#endif + exit(CLD_EXITED, 0); +#endif /* AFS_SUN5_ENV */ } #if !defined(AFS_LINUX20_ENV) && !defined(AFS_SUN5_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) diff --git a/src/rx/rx_kcommon.h b/src/rx/rx_kcommon.h index 92b2bc332..23d48adf1 100644 --- a/src/rx/rx_kcommon.h +++ b/src/rx/rx_kcommon.h @@ -90,9 +90,7 @@ struct coda_inode_info {}; #include "../afs/afs_osi.h" #include "../rx/rx_kmutex.h" #include "../afs/lock.h" -#ifndef AFS_LINUX22_ENV -#include "../rpc/xdr.h" -#endif +#include "../rx/xdr.h" #include "../rx/rx.h" #include "../rx/rx_globals.h" #include "../afs/longc_procs.h" diff --git a/src/rx/xdr.h b/src/rx/xdr.h index c74a8f0f7..686974509 100644 --- a/src/rx/xdr.h +++ b/src/rx/xdr.h @@ -65,6 +65,33 @@ void *afs_osi_Alloc(); #define osi_alloc afs_osi_Alloc #define osi_free afs_osi_Free + +#ifndef UKERNEL +#define xdr_void afs_xdr_void +#define xdr_int afs_xdr_int +#define xdr_u_int afs_xdr_u_int +#define xdr_short afs_xdr_short +#define xdr_u_short afs_xdr_u_short +#define xdr_long afs_xdr_long +#define xdr_u_long afs_xdr_u_long +#define xdr_char afs_xdr_char +#define xdr_u_char afs_xdr_u_char +#define xdr_bool afs_xdr_bool +#define xdr_enum afs_xdr_enum +#define xdr_array afs_xdr_array +#define xdr_arrayN afs_xdr_arrayN +#define xdr_bytes afs_xdr_bytes +#define xdr_opaque afs_xdr_opaque +#define xdr_string afs_xdr_string +#define xdr_union afs_xdr_union +#define xdr_float afs_xdr_float +#define xdr_double afs_xdr_double +#define xdr_reference afs_xdr_reference +#define xdr_wrapstring afs_xdr_wrapstring +#define xdr_vector afs_xdr_vector +#define xdr_int64 afs_xdr_int64 +#define xdr_uint64 afs_xdr_uint64 +#endif #endif #ifndef major /* ouch! */ #include diff --git a/src/rx/xdr_rx.c b/src/rx/xdr_rx.c index 8c640e725..56682216d 100644 --- a/src/rx/xdr_rx.c +++ b/src/rx/xdr_rx.c @@ -18,7 +18,7 @@ #endif #include -RCSID("$Header: /tmp/cvstemp/openafs/src/rx/xdr_rx.c,v 1.1.1.4 2001/07/11 03:10:58 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/rx/xdr_rx.c,v 1.1.1.5 2002/06/10 11:47:16 hartmans Exp $"); #ifdef KERNEL #ifndef UKERNEL @@ -45,7 +45,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/rx/xdr_rx.c,v 1.1.1.4 2001/07/11 03:10: #define u_quad_t __u_quad_t #endif #endif -#include "../rpc/xdr.h" +#include "../rx/xdr.h" #include "../netinet/in.h" #else /* !UKERNEL */ #include "../afs/sysincludes.h" diff --git a/src/rxgen/rpc_main.c b/src/rxgen/rpc_main.c index 04ffaf4ed..d88b03581 100644 --- a/src/rxgen/rpc_main.c +++ b/src/rxgen/rpc_main.c @@ -36,7 +36,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/rxgen/rpc_main.c,v 1.1.1.9 2001/10/14 18:06:33 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/rxgen/rpc_main.c,v 1.1.1.10 2002/06/10 11:47:26 hartmans Exp $"); #include #include @@ -436,14 +436,7 @@ c_output(infile, define, extend, outfile, append) f_print(fout, "#include \"../h/stat.h\"\n"); f_print(fout, "#include \"../netinet/in.h\"\n"); f_print(fout, "#include \"../h/time.h\"\n"); - f_print(fout, "#ifndef AFS_LINUX22_ENV\n"); - f_print(fout, "#include \"../rpc/types.h\"\n"); - f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); - f_print(fout, "#ifdef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"../rx/xdr.h\"\n"); - f_print(fout, "#else /* AFS_LINUX22_ENV */\n"); - f_print(fout, "#include \"../rpc/xdr.h\"\n"); - f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); f_print(fout, "#include \"../afsint/rxgen_consts.h\"\n"); } else { f_print(fout, "#include \n"); @@ -570,13 +563,7 @@ h_output(infile, define, extend, outfile, append) f_print(fout, "#define u_quad_t __u_quad_t\n"); f_print(fout, "#endif\n"); f_print(fout, "#endif\n"); - f_print(fout, "#ifdef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"../rx/xdr.h\"\n"); - f_print(fout, "#else /* AFS_LINUX22_ENV */\n"); - f_print(fout, "extern bool_t xdr_int64();\n"); - f_print(fout, "extern bool_t xdr_uint64();\n"); - f_print(fout, "#include \"../rpc/xdr.h\"\n"); - f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); f_print(fout, "#endif /* XDR_GETLONG */\n"); f_print(fout, "#endif /* UKERNEL */\n"); f_print(fout, "#include \"../afsint/rxgen_consts.h\"\n"); @@ -752,11 +739,7 @@ int append; f_print(fout, "#include \"../netinet/in.h\"\n"); f_print(fout, "#include \"../h/time.h\"\n"); f_print(fout, "#include \"../rpc/types.h\"\n"); - f_print(fout, "#ifdef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"../rx/xdr.h\"\n"); - f_print(fout, "#else /* AFS_LINUX22_ENV */\n"); - f_print(fout, "#include \"../rpc/xdr.h\"\n"); - f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); f_print(fout, "#include \"../afsint/rxgen_consts.h\"\n"); f_print(fout, "#include \"../afs/afs_osi.h\"\n"); f_print(fout, "#include \"../rx/rx.h\"\n"); @@ -827,11 +810,7 @@ int append; f_print(fout, "#include \"../netinet/in.h\"\n"); f_print(fout, "#include \"../h/time.h\"\n"); f_print(fout, "#include \"../rpc/types.h\"\n"); - f_print(fout, "#ifdef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"../rx/xdr.h\"\n"); - f_print(fout, "#else /* AFS_LINUX22_ENV */\n"); - f_print(fout, "#include \"../rpc/xdr.h\"\n"); - f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); f_print(fout, "#include \"../afsint/rxgen_consts.h\"\n"); f_print(fout, "#include \"../afs/afs_osi.h\"\n"); f_print(fout, "#include \"../rx/rx.h\"\n"); diff --git a/src/rxkad/rxkad_client.c b/src/rxkad/rxkad_client.c index 6cb76f7fa..23a926a6d 100644 --- a/src/rxkad/rxkad_client.c +++ b/src/rxkad/rxkad_client.c @@ -18,7 +18,7 @@ #include #endif -RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_client.c,v 1.1.1.7 2001/10/14 18:06:35 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_client.c,v 1.1.1.8 2002/06/10 11:47:28 hartmans Exp $"); #ifdef KERNEL #include "../afs/stds.h" @@ -34,7 +34,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_client.c,v 1.1.1.7 2001/10/ #endif /* !UKERNEL */ #ifndef AFS_LINUX22_ENV #include "../rpc/types.h" -#include "../rpc/xdr.h" +#include "../rx/xdr.h" #endif #include "../rx/rx.h" #else /* ! KERNEL */ diff --git a/src/rxkad/rxkad_common.c b/src/rxkad/rxkad_common.c index 7261e0af7..e5cb6884e 100644 --- a/src/rxkad/rxkad_common.c +++ b/src/rxkad/rxkad_common.c @@ -16,7 +16,7 @@ #include #endif -RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_common.c,v 1.1.1.8 2002/05/11 00:01:51 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_common.c,v 1.1.1.9 2002/06/10 11:47:28 hartmans Exp $"); #ifdef KERNEL #ifndef UKERNEL @@ -29,7 +29,7 @@ RCSID("$Header: /tmp/cvstemp/openafs/src/rxkad/rxkad_common.c,v 1.1.1.8 2002/05/ #include "../h/time.h" #ifndef AFS_LINUX22_ENV #include "../rpc/types.h" -#include "../rpc/xdr.h" +#include "../rx/xdr.h" #endif /* AFS_LINUX22_ENV */ #else /* !UKERNEL */ #include "../afs/sysincludes.h" diff --git a/src/util/NTMakefile b/src/util/NTMakefile index 174691f29..7d95c7a81 100644 --- a/src/util/NTMakefile +++ b/src/util/NTMakefile @@ -29,7 +29,7 @@ INCFILES =\ $(DESTDIR)\include\afs\dirent.h: dirent_nt.h $(COPY) $** $@ -$(DESTDIR)\include\afs\dirpath.h: dirpath.hin +$(DESTDIR)\include\afs\dirpath.h: dirpath_nt.h $(COPY) $** $@ LIBFILE = $(DESTDIR)\lib\afs\afsutil.lib diff --git a/src/viced/host.c b/src/viced/host.c index d6f97e895..6133ae29b 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -10,7 +10,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/viced/host.c,v 1.1.1.9 2002/05/11 00:03:28 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/viced/host.c,v 1.1.1.10 2002/06/10 11:48:32 hartmans Exp $"); #include #include @@ -534,12 +534,15 @@ void h_flushhostcps(hostaddr, hport) register afs_uint32 hostaddr, hport; /* net byte order */ { register struct host *host; + int held; H_LOCK - host = h_Lookup_r(hostaddr, hport); + host = h_Lookup_r(hostaddr, hport, &held); if (host) { host->hcpsfailed = 1; } + if (!held) + h_Release_r(host); H_UNLOCK return; @@ -635,18 +638,21 @@ struct host *h_Alloc_r(r_con) /* Lookup a host given an IP address and UDP port number. */ -struct host *h_Lookup(hostaddr, hport) +struct host *h_Lookup(hostaddr, hport, heldp) afs_uint32 hostaddr, hport; /* network byte order */ + int *heldp; { struct host *retVal; H_LOCK - retVal = h_Lookup_r(hostaddr, hport); + retVal = h_Lookup_r(hostaddr, hport, heldp); H_UNLOCK return retVal; } -struct host *h_Lookup_r(hostaddr, hport) +/* Note: host should be released by caller if 0 == *heldp and non-null */ +struct host *h_Lookup_r(hostaddr, hport, heldp) afs_uint32 hostaddr, hport; /* network byte order */ + int *heldp; { register afs_int32 now; register struct host *host=0; @@ -654,17 +660,30 @@ struct host *h_Lookup_r(hostaddr, hport) register index = h_HashIndex(hostaddr); extern int hostaclRefresh; +restart: for (chain=hostHashTable[index]; chain; chain=chain->next) { host = chain->hostPtr; assert(host); if (!(host->hostFlags & HOSTDELETED) && chain->addr == hostaddr && host->port == hport) { + *heldp = h_Held_r(host); + if (!*heldp) + h_Hold_r(host); + h_Lock_r(host); + if (host->hostFlags & HOSTDELETED) { + h_Unlock_r(host); + if (!*heldp) + h_Release_r(host); + goto restart; + } + h_Unlock_r(host); now = FT_ApproxTime(); /* always evaluate "now" */ if (host->hcpsfailed || (host->cpsCall+hostaclRefresh < now )) { /* - * Every hostaclRefresh period (def 2 hrs) get the new membership list for the host. - * Note this could be the first time that the host is added to a group. - * Also here we also retry on previous legitimate hcps failures + * Every hostaclRefresh period (def 2 hrs) get the new + * membership list for the host. Note this could be the + * first time that the host is added to a group. Also + * here we also retry on previous legitimate hcps failures. */ h_gethostcps_r(host,now); } @@ -947,14 +966,12 @@ struct host *h_GetHost_r(tcon) retry: code = 0; identP = (struct Identity *)rx_GetSpecific(tcon, rxcon_ident_key); - host = h_Lookup_r(haddr, hport); + host = h_Lookup_r(haddr, hport, &held); if (host && !identP && !(host->Console&1)) { /* This is a new connection, and we already have a host * structure for this address. Verify that the identity * of the caller matches the identity in the host structure. */ - if (!(held = h_Held_r(host))) - h_Hold_r(host); h_Lock_r(host); if ( !(host->hostFlags & ALTADDR) ) { @@ -970,7 +987,7 @@ retry: code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf); H_LOCK if ( code == RXGEN_OPCODE ) { - identP = (struct Identity *)malloc(1); + identP = (struct Identity *)malloc(sizeof(struct Identity)); identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); /* The host on this connection was unable to respond to @@ -1016,8 +1033,6 @@ retry: host->hostFlags |= ALTADDR; h_Unlock_r(host); } else if (host) { - if (!(held = h_Held_r(host))) - h_Hold_r(host); if ( ! (host->hostFlags & ALTADDR) ) { /* another thread is doing the initialisation */ @@ -1057,7 +1072,7 @@ retry: code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf); H_LOCK if ( code == RXGEN_OPCODE ) { - identP = (struct Identity *)malloc(1); + identP = (struct Identity *)malloc(sizeof(struct Identity)); identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); ViceLog(25, diff --git a/src/vlserver/vldbint.xg b/src/vlserver/vldbint.xg index 6b54cfbe6..9c175a57b 100644 --- a/src/vlserver/vldbint.xg +++ b/src/vlserver/vldbint.xg @@ -15,7 +15,7 @@ statindex 15 %#include "vl_opcodes.h" /* directly to other places */ %#ifdef KERNEL -%#define xdr_array(a,b,c,d,e,f) xdr_arrayN(a,b,c,d,e,f) +%#define afs_xdr_array(a,b,c,d,e,f) afs_xdr_arrayN(a,b,c,d,e,f) %#include "../afs/longc_procs.h" %#endif diff --git a/src/vol/ihandle.c b/src/vol/ihandle.c index 69733637f..a7a8b6f07 100644 --- a/src/vol/ihandle.c +++ b/src/vol/ihandle.c @@ -14,7 +14,7 @@ #include #include -RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ihandle.c,v 1.1.1.6 2002/05/11 00:03:40 hartmans Exp $"); +RCSID("$Header: /tmp/cvstemp/openafs/src/vol/ihandle.c,v 1.1.1.7 2002/06/10 11:48:24 hartmans Exp $"); #include #include @@ -259,10 +259,6 @@ FdHandle_t *ih_open(IHandle_t *ihP) IH_LOCK - if (!ih_Inited) { - ih_Initialize(); - } - /* Do we already have an open file handle for this Inode? */ for (fdP = ihP->ih_fdtail ; fdP != NULL ; fdP = fdP->fd_ihprev) { if (fdP->fd_status != FD_HANDLE_INUSE) { @@ -298,7 +294,7 @@ FdHandle_t *ih_open(IHandle_t *ihP) assert(fdP->fd_status == FD_HANDLE_OPEN); DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail, - fd_ihnext, fd_ihprev); + fd_ihnext, fd_ihprev); closeFd = fdP->fd_fd; } else { if (fdAvailHead == NULL) { @@ -313,6 +309,9 @@ FdHandle_t *ih_open(IHandle_t *ihP) fdP->fd_status = FD_HANDLE_INUSE; fdP->fd_fd = fd; fdP->fd_ih = ihP; + + ihP->ih_refcnt++; + /* Add this handle to the Inode's list of open descriptors */ DLL_INSERT_TAIL(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev); @@ -323,7 +322,6 @@ FdHandle_t *ih_open(IHandle_t *ihP) fdInUseCount -= 1; } - ihP->ih_refcnt++; IH_UNLOCK return fdP; } @@ -340,41 +338,21 @@ int fd_close(FdHandle_t *fdP) return 0; IH_LOCK + assert(ih_Inited); assert(fdInUseCount > 0); assert(fdP->fd_status == FD_HANDLE_INUSE); ihP = fdP->fd_ih; - /* If a previous attempt to close ( ih_reallyclose() ) - * all fd handles failed, then the IH_REALLY_CLOSED flag is set in - * the Inode handle so we call fd_reallyclose + /* Call fd_reallyclose to really close the unused file handles if + * the previous attempt to close (ih_reallyclose()) all file handles + * failed (this is determined by checking the ihandle for the flag + * IH_REALLY_CLOSED) or we have too many open files. */ - - if ( ihP->ih_flags & IH_REALLY_CLOSED ) { - IH_UNLOCK - return (fd_reallyclose(fdP)); - } - - /* If we have too many open files then close the descriptor. If we - * hold the last reference to the Inode handle then wait and let - * ih_release do the work. */ - if (fdInUseCount > fdCacheSize && ihP->ih_refcnt > 1) { - assert(fdInUseCount > 0); - closeFd = fdP->fd_fd; - DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail, - fd_ihnext, fd_ihprev); - DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev); - fdP->fd_status = FD_HANDLE_AVAIL; - fdP->fd_ih = NULL; - fdP->fd_fd = INVALID_FD; - ihP->ih_refcnt--; + if (ihP->ih_flags & IH_REALLY_CLOSED || fdInUseCount > fdCacheSize) { IH_UNLOCK - OS_CLOSE(closeFd); - IH_LOCK - fdInUseCount -= 1; - IH_UNLOCK - return 0; + return fd_reallyclose(fdP); } /* Put this descriptor back into the cache */ @@ -382,7 +360,8 @@ int fd_close(FdHandle_t *fdP) DLL_INSERT_TAIL(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); /* If this is not the only reference to the Inode then we can decrement - * the reference count, otherwise we need to call ih_release. */ + * the reference count, otherwise we need to call ih_release. + */ if (ihP->ih_refcnt > 1) { ihP->ih_refcnt--; IH_UNLOCK @@ -395,7 +374,8 @@ int fd_close(FdHandle_t *fdP) } /* - * Return a file descriptor handle to the cache + * Actually close the file descriptor handle and return it to + * the free list. */ int fd_reallyclose(FdHandle_t *fdP) { @@ -406,6 +386,7 @@ int fd_reallyclose(FdHandle_t *fdP) return 0; IH_LOCK + assert(ih_Inited); assert(fdInUseCount > 0); assert(fdP->fd_status == FD_HANDLE_INUSE); @@ -413,15 +394,25 @@ int fd_reallyclose(FdHandle_t *fdP) ihP = fdP->fd_ih; closeFd = fdP->fd_fd; - DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail, - fd_ihnext, fd_ihprev); + DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, fd_ihprev); DLL_INSERT_TAIL(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev); + fdP->fd_status = FD_HANDLE_AVAIL; fdP->fd_ih = NULL; fdP->fd_fd = INVALID_FD; + + /* All the file descriptor handles have been closed; reset + * the IH_REALLY_CLOSED flag indicating that ih_reallyclose + * has completed its job. + */ + if (!ihP->ih_fdhead) { + ihP->ih_flags &= ~IH_REALLY_CLOSED; + } + IH_UNLOCK OS_CLOSE(closeFd); IH_LOCK + fdInUseCount -= 1; /* If this is not the only reference to the Inode then we can decrement @@ -433,6 +424,7 @@ int fd_reallyclose(FdHandle_t *fdP) IH_UNLOCK ih_release(ihP); } + return 0; } @@ -658,163 +650,136 @@ int stream_close(StreamHandle_t *streamP, int reallyClose) return retval; } -/* Close all cached file descriptors for this inode. */ -int ih_reallyclose(IHandle_t *ihP) +/* Close all unused file descriptors associated with the inode + * handle. Called with IH_LOCK held. May drop and reacquire + * IH_LOCK. Sets the IH_REALLY_CLOSED flag in the inode handle + * if it fails to close all file handles. + */ +static int ih_fdclose(IHandle_t *ihP) { - int closeCount; - FdHandle_t *fdP; - FdHandle_t *head, *tail; - - if (!ihP) - return 0; - - IH_LOCK + int closeCount, closedAll; + FdHandle_t *fdP, *head, *tail, *next; assert(ihP->ih_refcnt > 0); + closedAll = 1; + DLL_INIT_LIST(head, tail); + ihP->ih_flags &= ~IH_REALLY_CLOSED; + /* * Remove the file descriptors for this Inode from the LRU queue - * and put them on a temporary queue so we drop the lock before - * we close the files. + * and the IHandle queue and put them on a temporary queue so we + * can drop the lock before we close the files. */ - DLL_INIT_LIST(head, tail); - for (fdP = ihP->ih_fdhead ; fdP != NULL ; fdP = fdP->fd_ihnext) { - if (fdP->fd_status == FD_HANDLE_OPEN) { - assert(fdP->fd_ih == ihP); - DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); - DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev); - } else { - ihP->ih_flags |= IH_REALLY_CLOSED; - } - } - - /* - * If we found any file descriptors in use, then we dont zero out - * fdhead and fdtail, since ih_reallyclose() will be called again on this - * Inode handle + for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) { + next = fdP->fd_ihnext; + assert(fdP->fd_ih == ihP); + assert(fdP->fd_status == FD_HANDLE_OPEN || + fdP->fd_status == FD_HANDLE_INUSE); + if (fdP->fd_status == FD_HANDLE_OPEN) { + DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, + fd_ihnext, fd_ihprev); + DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); + DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev); + } else { + closedAll = 0; + ihP->ih_flags |= IH_REALLY_CLOSED; + } + } + + /* If the ihandle reference count is 1, we should have + * closed all file descriptors. */ - - if ( ! (ihP->ih_flags & IH_REALLY_CLOSED) ) - DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail); + if (ihP->ih_refcnt == 1 || closedAll) { + assert(closedAll); + assert(!ihP->ih_fdhead); + assert(!ihP->ih_fdtail); + } if (head == NULL) { - IH_UNLOCK - return 0; + return 0; /* No file descriptors closed */ } + IH_UNLOCK + /* * Close the file descriptors */ closeCount = 0; - for (fdP = head ; fdP != NULL ; fdP = fdP->fd_ihnext) { - IH_UNLOCK - OS_CLOSE(fdP->fd_fd); - IH_LOCK - assert(fdInUseCount > 0); - fdInUseCount -= 1; - fdP->fd_status = FD_HANDLE_AVAIL; - fdP->fd_fd = INVALID_FD; - fdP->fd_ih = NULL; - closeCount++; + for (fdP = head; fdP != NULL; fdP = fdP->fd_next) { + OS_CLOSE(fdP->fd_fd); + fdP->fd_status = FD_HANDLE_AVAIL; + fdP->fd_fd = INVALID_FD; + fdP->fd_ih = NULL; + closeCount++; } + IH_LOCK + + assert(fdInUseCount >= closeCount); + fdInUseCount -= closeCount; + /* * Append the temporary queue to the list of available descriptors */ if (fdAvailHead == NULL) { - fdAvailHead = head; - fdAvailTail = tail; + fdAvailHead = head; + fdAvailTail = tail; } else { - fdAvailTail->fd_next = head; - head->fd_prev = fdAvailTail; - fdAvailTail = tail; + fdAvailTail->fd_next = head; + head->fd_prev = fdAvailTail; + fdAvailTail = tail; } + + return 0; +} + +/* Close all cached file descriptors for this inode. */ +int ih_reallyclose(IHandle_t *ihP) +{ + if (!ihP) + return 0; + + IH_LOCK + + assert(ihP->ih_refcnt > 0); + ih_fdclose(ihP); + IH_UNLOCK return 0; } /* Release an Inode handle. All cached file descriptors for this - * inode are closed when the last reference to this handle is released */ + * inode are closed when the last reference to this handle is released + */ int ih_release(IHandle_t *ihP) { - int closeCount; - FdHandle_t *fdP; - FdHandle_t *head, *tail; int ihash; if (!ihP) - return 0; + return 0; IH_LOCK - /** - * If the IH_REALLY_CLOSED flag is set then clear it here before adding - * the Inode handle to the available queue - */ - if ( ihP->ih_flags & IH_REALLY_CLOSED ) - ihP->ih_flags &= ~IH_REALLY_CLOSED; + assert(ihP->ih_refcnt > 0); - ihP->ih_refcnt--; - if (ihP->ih_refcnt > 0) { - IH_UNLOCK - return 0; + if (ihP->ih_refcnt > 1) { + ihP->ih_refcnt--; + IH_UNLOCK + return 0; } - assert(ihP->ih_refcnt == 0); - ihash = IH_HASH(ihP->ih_dev, ihP->ih_vid, ihP->ih_ino); DLL_DELETE(ihP, ihashTable[ihash].ihash_head, - ihashTable[ihash].ihash_tail, ih_next, ih_prev); - - /* - * Remove the file descriptors for this Inode from the LRU queue - * and put them on a temporary queue so we drop the lock before - * we close the files. - */ - DLL_INIT_LIST(head, tail); - for (fdP = ihP->ih_fdhead ; fdP != NULL ; fdP = fdP->fd_ihnext) { - assert(fdP->fd_status == FD_HANDLE_OPEN); - assert(fdP->fd_ih == ihP); - DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); - DLL_INSERT_TAIL(fdP, head, tail, fd_next, fd_prev); - } - DLL_INIT_LIST(ihP->ih_fdhead, ihP->ih_fdtail); + ihashTable[ihash].ihash_tail, ih_next, ih_prev); - if (head == NULL) { - DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev); - IH_UNLOCK - return 0; - } + ih_fdclose(ihP); - /* - * Close the file descriptors - */ - closeCount = 0; - for (fdP = head ; fdP != NULL ; fdP = fdP->fd_ihnext) { - IH_UNLOCK - OS_CLOSE(fdP->fd_fd); - IH_LOCK - assert(fdInUseCount > 0); - fdInUseCount -= 1; - fdP->fd_status = FD_HANDLE_AVAIL; - fdP->fd_fd = INVALID_FD; - fdP->fd_ih = NULL; - closeCount++; - } + ihP->ih_refcnt--; - /* - * Append the temporary queue to the list of available descriptors - */ - if (fdAvailHead == NULL) { - fdAvailHead = head; - fdAvailTail = tail; - } else { - fdAvailTail->fd_next = head; - head->fd_prev = fdAvailTail; - fdAvailTail = tail; - } DLL_INSERT_TAIL(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev); + IH_UNLOCK return 0; -- 2.39.5