From: Derrick Brashear Date: Tue, 7 Oct 2008 18:44:31 +0000 (+0000) Subject: STABLE14-ubik-notruncate-dont-pollute-fd-cache-20081007 X-Git-Tag: openafs-stable-1_4_8pre2~4 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=39ecc64e1d4d7e2275491bb18923f2f409ed6608;p=packages%2Fo%2Fopenafs.git STABLE14-ubik-notruncate-dont-pollute-fd-cache-20081007 LICENSE IPL10 issue suggested by Chaskiel Grundman; while it should not have been an issue we now behave usefully in the notruncate recovery code. (cherry picked from commit fe0186dccd4e4d16c0610f211d454a90b0841a83) --- diff --git a/src/ubik/phys.c b/src/ubik/phys.c index 5d6269073..917a91980 100644 --- a/src/ubik/phys.c +++ b/src/ubik/phys.c @@ -108,7 +108,7 @@ uphys_open(register struct ubik_dbase *adbase, afs_int32 afid) } if (bestfd) { /* found a usable slot */ tfd = bestfd; - if (tfd->fd >= 0) + if (tfd->fd >= 0) close(tfd->fd); tfd->fd = fd; tfd->refCount = 1; /* us */ @@ -130,10 +130,22 @@ uphys_close(register int afd) return EBADF; tfd = fdcache; for (i = 0; i < MAXFDCACHE; i++, tfd++) { - if (tfd->fd == afd && tfd->fileID != -10000) { - tfd->refCount--; - return 0; - } + if (tfd->fd == afd) + if (tfd->fileID != -10000) { + tfd->refCount--; + return 0; + } else { + if (tfd->refCount > 0) { + tfd->refCount--; + if (tfd->refCount == 0) { + close(tfd->fd); + tfd->fd = -1; + } + return 0; + } + tfd->fd = -1; + break; + } } return close(afd); } @@ -293,8 +305,10 @@ uphys_invalidate(register struct ubik_dbase *adbase, afs_int32 afid) for (tfd = fdcache, i = 0; i < MAXFDCACHE; i++, tfd++) { if (afid == tfd->fileID) { tfd->fileID = -10000; - if (tfd->fd >= 0 && tfd->refCount == 0) + if (tfd->fd >= 0 && tfd->refCount == 0) { close(tfd->fd); + tfd->fd = -1; + } return; } }