mirror of
https://github.com/vgough/encfs.git
synced 2025-06-20 19:57:52 +02:00
Get idle counters at once (#294)
to avoid a race with usage==0 & openCount>0
This commit is contained in:
parent
efbdd29716
commit
618db2374c
@ -74,20 +74,15 @@ void EncFS_Context::setRoot(const std::shared_ptr<DirNode> &r) {
|
|||||||
|
|
||||||
bool EncFS_Context::isMounted() { return root.get() != nullptr; }
|
bool EncFS_Context::isMounted() { return root.get() != nullptr; }
|
||||||
|
|
||||||
int EncFS_Context::getAndResetUsageCounter() {
|
void EncFS_Context::getAndResetUsageCounter(int *usage, int *openCount) {
|
||||||
Lock lock(contextMutex);
|
Lock lock(contextMutex);
|
||||||
|
|
||||||
int count = usageCount;
|
*usage = usageCount;
|
||||||
usageCount = 0;
|
usageCount = 0;
|
||||||
|
|
||||||
return count;
|
*openCount = openFiles.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncFS_Context::openFileCount() const {
|
|
||||||
Lock lock(contextMutex);
|
|
||||||
|
|
||||||
return openFiles.size();
|
|
||||||
}
|
|
||||||
std::shared_ptr<FileNode> EncFS_Context::lookupNode(const char *path) {
|
std::shared_ptr<FileNode> EncFS_Context::lookupNode(const char *path) {
|
||||||
Lock lock(contextMutex);
|
Lock lock(contextMutex);
|
||||||
|
|
||||||
|
@ -44,9 +44,8 @@ class EncFS_Context {
|
|||||||
|
|
||||||
std::shared_ptr<FileNode> lookupNode(const char *path);
|
std::shared_ptr<FileNode> lookupNode(const char *path);
|
||||||
|
|
||||||
int getAndResetUsageCounter();
|
void getAndResetUsageCounter(int *usage, int *openCount);
|
||||||
int openFileCount() const;
|
|
||||||
|
|
||||||
FileNode *putNode(const char *path, std::shared_ptr<FileNode> &&node);
|
FileNode *putNode(const char *path, std::shared_ptr<FileNode> &&node);
|
||||||
|
|
||||||
void eraseNode(const char *path, FileNode *fnode);
|
void eraseNode(const char *path, FileNode *fnode);
|
||||||
|
@ -718,15 +718,19 @@ static void *idleMonitor(void *_arg) {
|
|||||||
pthread_mutex_lock(&ctx->wakeupMutex);
|
pthread_mutex_lock(&ctx->wakeupMutex);
|
||||||
|
|
||||||
while (ctx->running) {
|
while (ctx->running) {
|
||||||
int usage = ctx->getAndResetUsageCounter();
|
int usage, openCount;
|
||||||
|
ctx->getAndResetUsageCounter(&usage, &openCount);
|
||||||
|
|
||||||
if (usage == 0 && ctx->isMounted())
|
if (usage == 0 && ctx->isMounted())
|
||||||
++idleCycles;
|
++idleCycles;
|
||||||
else
|
else {
|
||||||
|
if (idleCycles >= timeoutCycles)
|
||||||
|
RLOG(INFO) << "Filesystem no longer inactive: "
|
||||||
|
<< arg->opts->mountPoint;
|
||||||
idleCycles = 0;
|
idleCycles = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (idleCycles >= timeoutCycles) {
|
if (idleCycles >= timeoutCycles) {
|
||||||
int openCount = ctx->openFileCount();
|
|
||||||
if (openCount == 0) {
|
if (openCount == 0) {
|
||||||
if (unmountFS(ctx)) {
|
if (unmountFS(ctx)) {
|
||||||
// wait for main thread to wake us up
|
// wait for main thread to wake us up
|
||||||
|
Loading…
x
Reference in New Issue
Block a user