Simplify condition

This commit is contained in:
benrubson 2017-11-02 10:15:54 +01:00
parent 64806bf3ac
commit e0b2ad8f66

View File

@ -766,7 +766,7 @@ static void *idleMonitor(void *_arg) {
pthread_mutex_lock(&ctx->wakeupMutex); pthread_mutex_lock(&ctx->wakeupMutex);
while (ctx->running) { while (ctx->running) {
int usage, openCount, fdlock; int usage, openCount;
ctx->getAndResetUsageCounter(&usage, &openCount); ctx->getAndResetUsageCounter(&usage, &openCount);
if (usage == 0 && ctx->isMounted()) { if (usage == 0 && ctx->isMounted()) {
@ -783,17 +783,23 @@ static void *idleMonitor(void *_arg) {
if (openCount != 0) { if (openCount != 0) {
RLOG(WARNING) << "Filesystem inactive, but " << openCount RLOG(WARNING) << "Filesystem inactive, but " << openCount
<< " files opened: " << arg->opts->mountPoint; << " files opened: " << arg->opts->mountPoint;
} else if ((fdlock = open(arg->opts->mountPoint.c_str(),O_RDONLY)) == -1 || flock(fdlock, LOCK_EX|LOCK_NB) == -1) {
RLOG(WARNING) << "Filesystem inactive, but "
<< "lock before unmount failed: " << arg->opts->mountPoint;
} else { } else {
unmountres = unmountFS(ctx); /* try to lock the mount point to give an oportunity to handle races
flock(fdlock, LOCK_UN); with an automated tool or script using --idle. */
close(fdlock); int fdlock = open(arg->opts->mountPoint.c_str(),O_RDONLY);
if (unmountres) { if (flock(fdlock, LOCK_EX|LOCK_NB) == -1) {
// wait for main thread to wake us up RLOG(WARNING) << "Filesystem inactive, but "
pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex); << "lock before unmount failed: " << arg->opts->mountPoint;
break; close(fdlock);
} else {
unmountres = unmountFS(ctx);
flock(fdlock, LOCK_UN);
close(fdlock);
if (unmountres) {
// wait for main thread to wake us up
pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex);
break;
}
} }
} }
} }