From c73395ec0761b11d9ab8d3cb56d1c6a4c726eabd Mon Sep 17 00:00:00 2001 From: Rainer Toebbicke Date: Mon, 26 Nov 2007 21:47:29 +0000 Subject: [PATCH] DEVEL15-namei-avoid-spurious-emfile-20071126 FIXES 77531 before we did not handle the fd cache runnign dry. "oops" (cherry picked from commit 48bcb88ddc8fe7baa7a2b0f8decee7e704ad32ef) --- src/vol/ihandle.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/vol/ihandle.c b/src/vol/ihandle.c index fa235fdda..3f2a9871c 100644 --- a/src/vol/ihandle.c +++ b/src/vol/ihandle.c @@ -320,9 +320,10 @@ ih_open(IHandle_t * ihP) */ fdInUseCount += 1; IH_UNLOCK; +ih_open_retry: fd = OS_IOPEN(ihP); IH_LOCK; - if (fd == INVALID_FD) { + if (fd == INVALID_FD && (errno != EMFILE || fdLruHead == NULL) ) { fdInUseCount -= 1; IH_UNLOCK; return NULL; @@ -332,13 +333,23 @@ ih_open(IHandle_t * ihP) * we permit the number of open files to exceed fdCacheSize. * We only recycle open file descriptors when the number * of open files reaches the size of the cache */ - if (fdInUseCount > fdCacheSize && fdLruHead != NULL) { + if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) { fdP = fdLruHead; 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); closeFd = fdP->fd_fd; + if (fd == INVALID_FD) { + fdCacheSize--; /* reduce in order to not run into here too often */ + 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; + IH_UNLOCK; + OS_CLOSE(closeFd); + goto ih_open_retry; + } } else { if (fdAvailHead == NULL) { fdHandleAllocateChunk(); -- 2.39.5