Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve auto unmount #267

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions encfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
#include "i18n.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
* not have a short version */
#define LONG_OPT_ANNOTATE 513
Expand Down Expand Up @@ -715,6 +710,11 @@ static void *idleMonitor(void *_arg) {
const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
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);

while (ctx->running) {
Expand All @@ -728,15 +728,15 @@ static void *idleMonitor(void *_arg) {
if (idleCycles >= timeoutCycles) {
int openCount = ctx->openFileCount();
if (openCount == 0) {
if (unmountFS(ctx)) {
unmountres = unmountFS(ctx);
if (unmountres) {
// wait for main thread to wake us up
pthread_cond_wait(&ctx->wakeupCond, &ctx->wakeupMutex);
break;
}
} else {
RLOG(WARNING) << "Filesystem " << arg->opts->mountPoint
<< " inactivity detected, but still " << openCount
<< " opened files";
RLOG(WARNING) << "Filesystem inactive, but " << openCount
<< " files opened: " << arg->opts->mountPoint;
}
}

Expand All @@ -753,6 +753,10 @@ static void *idleMonitor(void *_arg) {

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";

return 0;
Expand All @@ -768,9 +772,18 @@ static bool unmountFS(EncFS_Context *ctx) {
return false;
} else {
// Time to unmount!
RLOG(WARNING) << "Unmounting filesystem due to inactivity: "
<< arg->opts->mountPoint;
fuse_unmount(arg->opts->mountPoint.c_str());
return true;
int rc=1;
if (access("/bin/umount", F_OK) != -1)
rc = system(("/bin/umount "+std::string(arg->opts->mountPoint)).c_str());
else
rc = system(("/sbin/umount "+std::string(arg->opts->mountPoint)).c_str());
if (!rc) {
RLOG(INFO) << "Filesystem inactive, unmounted: " << arg->opts->mountPoint;
return true;
}
else {
RLOG(ERROR) << "Filesystem inactive, but unmount failed: " << arg->opts->mountPoint;
return false;
}
}
}