From 8de6cb3504335de5cee9f670a171d01b63869643 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 15 Aug 2020 23:54:00 +0900 Subject: [PATCH] Lock fdent_data_lock before accessing pagelist Found via ThreadSanitizer. References #1353. References #1362. --- src/fdcache.cpp | 7 +++++++ src/fdcache.h | 2 +- src/s3fs_util.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 00ad46a..32b8f10 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -1788,6 +1788,12 @@ bool FdEntity::RenamePath(const string& newpath, string& fentmapkey) return true; } +bool FdEntity::IsModified(void) const +{ + AutoLock auto_data_lock(const_cast(&fdent_data_lock)); + return pagelist.IsModified(); +} + bool FdEntity::GetStats(struct stat& st, bool lock_already_held) { AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE); @@ -1882,6 +1888,7 @@ bool FdEntity::GetSize(off_t& size) return false; } + AutoLock auto_data_lock(&fdent_data_lock); size = pagelist.Size(); return true; } diff --git a/src/fdcache.h b/src/fdcache.h index f218eb8..ffd4c73 100644 --- a/src/fdcache.h +++ b/src/fdcache.h @@ -185,7 +185,7 @@ class FdEntity const char* GetPath(void) const { return path.c_str(); } bool RenamePath(const std::string& newpath, std::string& fentmapkey); int GetFd(void) const { return fd; } - bool IsModified(void) const { return pagelist.IsModified(); } + bool IsModified(void) const; bool MergeOrgMeta(headers_t& updatemeta); bool GetStats(struct stat& st, bool lock_already_held = false); diff --git a/src/s3fs_util.h b/src/s3fs_util.h index d13ae0d..d71f354 100644 --- a/src/s3fs_util.h +++ b/src/s3fs_util.h @@ -97,6 +97,7 @@ class AutoLock ~AutoLock(); private: + AutoLock(const AutoLock&); pthread_mutex_t* const auto_mutex; bool is_lock_acquired; };