From fe0186dccd4e4d16c0610f211d454a90b0841a83 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Tue, 7 Oct 2008 18:43:57 +0000 Subject: [PATCH] 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. --- src/ubik/phys.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ubik/phys.c b/src/ubik/phys.c index b6d1def70..636a6a3d7 100644 --- a/src/ubik/phys.c +++ b/src/ubik/phys.c @@ -115,7 +115,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 */ @@ -137,10 +137,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); } @@ -300,8 +312,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; } } -- 2.39.5