Improve auto unmount

This commit is contained in:
benrubson 2017-06-03 12:32:07 +02:00 committed by rfjakob
parent 8cc6639f64
commit d216cc4208

View File

@ -43,11 +43,6 @@
#include "i18n.h" #include "i18n.h"
#include "openssl.h" #include "openssl.h"
// Fuse version >= 26 requires another argument to fuse_unmount, which we
// don't have. So use the backward compatible call instead..
extern "C" void fuse_unmount_compat22(const char *mountpoint);
#define fuse_unmount fuse_unmount_compat22
/* Arbitrary identifiers for long options that do /* Arbitrary identifiers for long options that do
* not have a short version */ * not have a short version */
#define LONG_OPT_ANNOTATE 513 #define LONG_OPT_ANNOTATE 513
@ -712,6 +707,11 @@ static void *idleMonitor(void *_arg) {
const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval; const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
int idleCycles = -1; int idleCycles = -1;
bool unmountres = false;
// We will notify when FS will be unmounted, so notify that it has just been mounted
RLOG(INFO) << "Filesystem mounted: " << arg->opts->mountPoint;
pthread_mutex_lock(&ctx->wakeupMutex); pthread_mutex_lock(&ctx->wakeupMutex);
while (ctx->running) { while (ctx->running) {
@ -729,15 +729,15 @@ static void *idleMonitor(void *_arg) {
if (idleCycles >= timeoutCycles) { if (idleCycles >= timeoutCycles) {
if (openCount == 0) { if (openCount == 0) {
if (unmountFS(ctx)) { unmountres = unmountFS(ctx);
if (unmountres) {
// wait for main thread to wake us up // wait for main thread to wake us up
pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex); pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex);
break; break;
} }
} else { } else {
RLOG(WARNING) << "Filesystem " << arg->opts->mountPoint RLOG(WARNING) << "Filesystem inactive, but " << openCount
<< " inactivity detected, but still " << openCount << " files opened: " << arg->opts->mountPoint;
<< " opened files";
} }
} }
@ -754,6 +754,10 @@ static void *idleMonitor(void *_arg) {
pthread_mutex_unlock(&ctx->wakeupMutex); pthread_mutex_unlock(&ctx->wakeupMutex);
// If we are here FS has been unmounted, so if we did not unmount ourselves (manual, kill...), notify
if (!unmountres)
RLOG(INFO) << "Filesystem unmounted: " << arg->opts->mountPoint;
VLOG(1) << "Idle monitoring thread exiting"; VLOG(1) << "Idle monitoring thread exiting";
return 0; return 0;
@ -769,9 +773,13 @@ static bool unmountFS(EncFS_Context *ctx) {
return false; return false;
} else { } else {
// Time to unmount! // Time to unmount!
RLOG(WARNING) << "Unmounting filesystem due to inactivity: " #if FUSE_USE_VERSION < 30
<< arg->opts->mountPoint; fuse_unmount(arg->opts->mountPoint.c_str(), NULL);
fuse_unmount(arg->opts->mountPoint.c_str()); #else
fuse_unmount(fuse_get_context()->fuse);
#endif
// fuse_unmount succeeds and returns void
RLOG(INFO) << "Filesystem inactive, unmounted: " << arg->opts->mountPoint;
return true; return true;
} }
} }