Replace uses of lock_already_held flag with AutoLock::Type

This commit is contained in:
Takeshi Nakatani 2022-07-30 06:33:37 +00:00 committed by Andrew Gaul
parent e654e8ec8a
commit c491fbeabc
8 changed files with 70 additions and 69 deletions

View File

@ -234,7 +234,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
if(ent->noobjcache){
if(!IsCacheNoObject){
// need to delete this cache.
DelStat(strpath, /*lock_already_held=*/ true);
DelStat(strpath, AutoLock::ALREADY_LOCKED);
}else{
// noobjcache = true means no object.
}
@ -288,7 +288,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
}
if(is_delete_cache){
DelStat(strpath, /*lock_already_held=*/ true);
DelStat(strpath, AutoLock::ALREADY_LOCKED);
}
return false;
}
@ -329,7 +329,7 @@ bool StatCache::IsNoObjectCache(const std::string& key, bool overcheck)
}
if(is_delete_cache){
DelStat(strpath, /*lock_already_held=*/ true);
DelStat(strpath, AutoLock::ALREADY_LOCKED);
}
return false;
}
@ -401,7 +401,7 @@ bool StatCache::AddStat(const std::string& key, headers_t& meta, bool forcedir,
if(!S_ISLNK(ent->stbuf.st_mode)){
if(symlink_cache.end() != symlink_cache.find(key)){
// if symbolic link cache has key, thus remove it.
DelSymlink(key.c_str(), true);
DelSymlink(key.c_str(), AutoLock::ALREADY_LOCKED);
}
}
return true;
@ -504,7 +504,7 @@ bool StatCache::AddNoObjectCache(const std::string& key)
// check symbolic link cache
if(symlink_cache.end() != symlink_cache.find(key)){
// if symbolic link cache has key, thus remove it.
DelSymlink(key.c_str(), true);
DelSymlink(key.c_str(), AutoLock::ALREADY_LOCKED);
}
return true;
}
@ -588,14 +588,14 @@ bool StatCache::TruncateCache()
return true;
}
bool StatCache::DelStat(const char* key, bool lock_already_held)
bool StatCache::DelStat(const char* key, AutoLock::Type locktype)
{
if(!key){
return false;
}
S3FS_PRN_INFO3("delete stat cache entry[path=%s]", key);
AutoLock lock(&StatCache::stat_cache_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock lock(&StatCache::stat_cache_lock, locktype);
stat_cache_t::iterator iter;
if(stat_cache.end() != (iter = stat_cache.find(std::string(key)))){
@ -650,7 +650,7 @@ bool StatCache::GetSymlink(const std::string& key, std::string& value)
}
if(is_delete_cache){
DelSymlink(strpath.c_str(), /*lock_already_held=*/ true);
DelSymlink(strpath.c_str(), AutoLock::ALREADY_LOCKED);
}
return false;
}
@ -746,14 +746,14 @@ bool StatCache::TruncateSymlink()
return true;
}
bool StatCache::DelSymlink(const char* key, bool lock_already_held)
bool StatCache::DelSymlink(const char* key, AutoLock::Type locktype)
{
if(!key){
return false;
}
S3FS_PRN_INFO3("delete symbolic link cache entry[path=%s]", key);
AutoLock lock(&StatCache::stat_cache_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock lock(&StatCache::stat_cache_lock, locktype);
symlink_cache_t::iterator iter;
if(symlink_cache.end() != (iter = symlink_cache.find(std::string(key)))){

View File

@ -23,6 +23,7 @@
#include <cstring>
#include "autolock.h"
#include "metaheader.h"
//-------------------------------------------------------------------
@ -171,16 +172,16 @@ class StatCache
void ChangeNoTruncateFlag(const std::string& key, bool no_truncate);
// Delete stat cache
bool DelStat(const char* key, bool lock_already_held = false);
bool DelStat(const std::string& key, bool lock_already_held = false)
bool DelStat(const char* key, AutoLock::Type locktype = AutoLock::NONE);
bool DelStat(const std::string& key, AutoLock::Type locktype = AutoLock::NONE)
{
return DelStat(key.c_str(), lock_already_held);
return DelStat(key.c_str(), locktype);
}
// Cache for symbolic link
bool GetSymlink(const std::string& key, std::string& value);
bool AddSymlink(const std::string& key, const std::string& value);
bool DelSymlink(const char* key, bool lock_already_held = false);
bool DelSymlink(const char* key, AutoLock::Type locktype = AutoLock::NONE);
};
//-------------------------------------------------------------------

View File

@ -1834,7 +1834,7 @@ S3fsCurl::~S3fsCurl()
DestroyCurlHandle();
}
bool S3fsCurl::ResetHandle(bool lock_already_held)
bool S3fsCurl::ResetHandle(AutoLock::Type locktype)
{
bool run_once;
{
@ -1912,7 +1912,7 @@ bool S3fsCurl::ResetHandle(bool lock_already_held)
}
}
AutoLock lock(&S3fsCurl::curl_handles_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock lock(&S3fsCurl::curl_handles_lock, locktype);
S3fsCurl::curl_times[hCurl] = time(0);
S3fsCurl::curl_progress[hCurl] = progress_t(-1, -1);
@ -1944,7 +1944,7 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake)
}
}
}
ResetHandle(/*lock_already_held=*/ true);
ResetHandle(AutoLock::ALREADY_LOCKED);
return true;
}

View File

@ -243,7 +243,7 @@ class S3fsCurl
static int RawCurlDebugFunc(const CURL* hcurl, curl_infotype type, char* data, size_t size, void* userptr, curl_infotype datatype);
// methods
bool ResetHandle(bool lock_already_held = false);
bool ResetHandle(AutoLock::Type locktype = AutoLock::NONE);
bool RemakeHandle();
bool ClearInternalData();
void insertV4Headers(const std::string& access_key_id, const std::string& secret_access_key, const std::string& access_token);

View File

@ -402,7 +402,7 @@ bool FdManager::HasOpenEntityFd(const char* path)
FdEntity* ent;
int fd = -1;
if(NULL == (ent = FdManager::singleton.GetFdEntity(path, fd, false, true))){
if(NULL == (ent = FdManager::singleton.GetFdEntity(path, fd, false, AutoLock::ALREADY_LOCKED))){
return false;
}
return (0 < ent->GetOpenCount());
@ -479,14 +479,14 @@ FdManager::~FdManager()
}
}
FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, bool lock_already_held)
FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, AutoLock::Type locktype)
{
S3FS_PRN_INFO3("[path=%s][pseudo_fd=%d]", SAFESTRPTR(path), existfd);
if(!path || '\0' == path[0]){
return NULL;
}
AutoLock auto_lock(&FdManager::fd_manager_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&FdManager::fd_manager_lock, locktype);
fdent_map_t::iterator iter = fent.find(std::string(path));
if(fent.end() != iter && iter->second){

View File

@ -86,7 +86,7 @@ class FdManager
static FILE* MakeTempFile();
// Return FdEntity associated with path, returning NULL on error. This operation increments the reference count; callers must decrement via Close after use.
FdEntity* GetFdEntity(const char* path, int& existfd, bool newfd = true, bool lock_already_held = false);
FdEntity* GetFdEntity(const char* path, int& existfd, bool newfd = true, AutoLock::Type locktype = AutoLock::NONE);
FdEntity* Open(int& fd, const char* path, headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags, bool force_tmpfile, bool is_create, bool ignore_modify, AutoLock::Type type);
FdEntity* GetExistFdEntity(const char* path, int existfd = -1);
FdEntity* OpenExistFdEntity(const char* path, int& fd, int flags = O_RDONLY);

View File

@ -228,7 +228,7 @@ void FdEntity::Close(int fd)
}
// check pseudo fd count
if(-1 != physical_fd && 0 == GetOpenCount(true)){
if(-1 != physical_fd && 0 == GetOpenCount(AutoLock::ALREADY_LOCKED)){
AutoLock auto_data_lock(&fdent_data_lock);
if(!cachepath.empty()){
// [NOTE]
@ -260,9 +260,9 @@ void FdEntity::Close(int fd)
}
}
int FdEntity::Dup(int fd, bool lock_already_held)
int FdEntity::Dup(int fd, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_DBG("[path=%s][pseudo_fd=%d][physical_fd=%d][pseudo fd count=%zu]", path.c_str(), fd, physical_fd, pseudo_fd_map.size());
@ -282,9 +282,9 @@ int FdEntity::Dup(int fd, bool lock_already_held)
return pseudo_fd;
}
int FdEntity::OpenPseudoFd(int flags, bool lock_already_held)
int FdEntity::OpenPseudoFd(int flags, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_DBG("[path=%s][physical_fd=%d][pseudo fd count=%zu]", path.c_str(), physical_fd, pseudo_fd_map.size());
@ -298,9 +298,9 @@ int FdEntity::OpenPseudoFd(int flags, bool lock_already_held)
return pseudo_fd;
}
int FdEntity::GetOpenCount(bool lock_already_held)
int FdEntity::GetOpenCount(AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
return static_cast<int>(pseudo_fd_map.size());
}
@ -362,9 +362,9 @@ int FdEntity::OpenMirrorFile()
return mirrorfd;
}
bool FdEntity::FindPseudoFd(int fd, bool lock_already_held)
bool FdEntity::FindPseudoFd(int fd, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
if(-1 == fd){
return false;
@ -375,9 +375,9 @@ bool FdEntity::FindPseudoFd(int fd, bool lock_already_held)
return true;
}
PseudoFdInfo* FdEntity::CheckPseudoFdFlags(int fd, bool writable, bool lock_already_held)
PseudoFdInfo* FdEntity::CheckPseudoFdFlags(int fd, bool writable, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
if(-1 == fd){
return NULL;
@ -398,9 +398,9 @@ PseudoFdInfo* FdEntity::CheckPseudoFdFlags(int fd, bool writable, bool lock_alre
return iter->second;
}
bool FdEntity::IsUploading(bool lock_already_held)
bool FdEntity::IsUploading(AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
for(fdinfo_map_t::const_iterator iter = pseudo_fd_map.begin(); iter != pseudo_fd_map.end(); ++iter){
PseudoFdInfo* ppseudoinfo = iter->second;
@ -655,7 +655,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts
// set mtime and ctime(set "x-amz-meta-mtime" and "x-amz-meta-ctime" in orgmeta)
if(UTIME_OMIT != ts_mctime.tv_nsec){
if(0 != SetMCtime(ts_mctime, ts_mctime, /*lock_already_held=*/ true)){
if(0 != SetMCtime(ts_mctime, ts_mctime, AutoLock::ALREADY_LOCKED)){
S3FS_PRN_ERR("failed to set mtime/ctime. errno(%d)", errno);
fclose(pfile);
pfile = NULL;
@ -697,7 +697,7 @@ bool FdEntity::LoadAll(int fd, headers_t* pmeta, off_t* size, bool force_load)
S3FS_PRN_INFO3("[path=%s][pseudo_fd=%d][physical_fd=%d]", path.c_str(), fd, physical_fd);
if(-1 == physical_fd || !FindPseudoFd(fd, true)){
if(-1 == physical_fd || !FindPseudoFd(fd, AutoLock::ALREADY_LOCKED)){
S3FS_PRN_ERR("pseudo_fd(%d) and physical_fd(%d) for path(%s) is not opened yet", fd, physical_fd, path.c_str());
return false;
}
@ -777,9 +777,9 @@ bool FdEntity::IsModified() const
return pagelist.IsModified();
}
bool FdEntity::GetStats(struct stat& st, bool lock_already_held)
bool FdEntity::GetStats(struct stat& st, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
if(-1 == physical_fd){
return false;
}
@ -792,9 +792,9 @@ bool FdEntity::GetStats(struct stat& st, bool lock_already_held)
return true;
}
int FdEntity::SetCtime(struct timespec time, bool lock_already_held)
int FdEntity::SetCtime(struct timespec time, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_INFO3("[path=%s][physical_fd=%d][time=%s]", path.c_str(), physical_fd, str(time).c_str());
@ -805,9 +805,9 @@ int FdEntity::SetCtime(struct timespec time, bool lock_already_held)
return 0;
}
int FdEntity::SetAtime(struct timespec time, bool lock_already_held)
int FdEntity::SetAtime(struct timespec time, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_INFO3("[path=%s][physical_fd=%d][time=%s]", path.c_str(), physical_fd, str(time).c_str());
@ -821,9 +821,9 @@ int FdEntity::SetAtime(struct timespec time, bool lock_already_held)
// [NOTE]
// This method updates mtime as well as ctime.
//
int FdEntity::SetMCtime(struct timespec mtime, struct timespec ctime, bool lock_already_held)
int FdEntity::SetMCtime(struct timespec mtime, struct timespec ctime, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_INFO3("[path=%s][physical_fd=%d][mtime=%s][ctime=%s]", path.c_str(), physical_fd, str(mtime).c_str(), str(ctime).c_str());
@ -864,7 +864,7 @@ bool FdEntity::UpdateCtime()
{
AutoLock auto_lock(&fdent_lock);
struct stat st;
if(!GetStats(st, /*lock_already_held=*/ true)){
if(!GetStats(st, AutoLock::ALREADY_LOCKED)){
return false;
}
@ -877,7 +877,7 @@ bool FdEntity::UpdateAtime()
{
AutoLock auto_lock(&fdent_lock);
struct stat st;
if(!GetStats(st, /*lock_already_held=*/ true)){
if(!GetStats(st, AutoLock::ALREADY_LOCKED)){
return false;
}
@ -901,13 +901,13 @@ bool FdEntity::UpdateMtime(bool clear_holding_mtime)
// overwritten.
//
if(clear_holding_mtime){
if(!ClearHoldingMtime(true)){
if(!ClearHoldingMtime(AutoLock::ALREADY_LOCKED)){
return false;
}
}
}else{
struct stat st;
if(!GetStats(st, /*lock_already_held=*/ true)){
if(!GetStats(st, AutoLock::ALREADY_LOCKED)){
return false;
}
orgmeta["x-amz-meta-mtime"] = str_stat_time(st, ST_TYPE_MTIME);
@ -915,9 +915,9 @@ bool FdEntity::UpdateMtime(bool clear_holding_mtime)
return true;
}
bool FdEntity::SetHoldingMtime(struct timespec mtime, bool lock_already_held)
bool FdEntity::SetHoldingMtime(struct timespec mtime, AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
S3FS_PRN_INFO3("[path=%s][physical_fd=%d][mtime=%s]", path.c_str(), physical_fd, str(mtime).c_str());
@ -928,15 +928,15 @@ bool FdEntity::SetHoldingMtime(struct timespec mtime, bool lock_already_held)
return true;
}
bool FdEntity::ClearHoldingMtime(bool lock_already_held)
bool FdEntity::ClearHoldingMtime(AutoLock::Type locktype)
{
AutoLock auto_lock(&fdent_lock, lock_already_held ? AutoLock::ALREADY_LOCKED : AutoLock::NONE);
AutoLock auto_lock(&fdent_lock, locktype);
if(holding_mtime.tv_sec < 0){
return false;
}
struct stat st;
if(!GetStats(st, true)){
if(!GetStats(st, AutoLock::ALREADY_LOCKED)){
return false;
}
if(-1 != physical_fd){
@ -2383,13 +2383,13 @@ bool FdEntity::MergeOrgMeta(headers_t& updatemeta)
struct timespec ctime = get_ctime(updatemeta, false); // not overcheck
struct timespec atime = get_atime(updatemeta, false); // not overcheck
if(0 <= mtime.tv_sec){
SetMCtime(mtime, (ctime.tv_sec < 0 ? mtime : ctime), true);
SetMCtime(mtime, (ctime.tv_sec < 0 ? mtime : ctime), AutoLock::ALREADY_LOCKED);
}
if(0 <= atime.tv_sec){
SetAtime(atime, true);
SetAtime(atime, AutoLock::ALREADY_LOCKED);
}
if(NO_UPDATE_PENDING == pending_status && (IsUploading(true) || pagelist.IsModified())){
if(NO_UPDATE_PENDING == pending_status && (IsUploading(AutoLock::ALREADY_LOCKED) || pagelist.IsModified())){
pending_status = UPDATE_META_PENDING;
}

View File

@ -76,8 +76,8 @@ class FdEntity
ino_t GetInode();
int OpenMirrorFile();
int NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start = 0, off_t size = 0); // size=0 means loading to end
PseudoFdInfo* CheckPseudoFdFlags(int fd, bool writable, bool lock_already_held = false);
bool IsUploading(bool lock_already_held = false);
PseudoFdInfo* CheckPseudoFdFlags(int fd, bool writable, AutoLock::Type locktype = AutoLock::NONE);
bool IsUploading(AutoLock::Type locktype = AutoLock::NONE);
bool SetAllStatus(bool is_loaded); // [NOTE] not locking
bool SetAllStatusUnloaded() { return SetAllStatus(false); }
int NoCachePreMultipartPost(PseudoFdInfo* pseudo_obj);
@ -105,12 +105,12 @@ class FdEntity
void Close(int fd);
bool IsOpen() const { return (-1 != physical_fd); }
bool FindPseudoFd(int fd, bool lock_already_held = false);
bool FindPseudoFd(int fd, AutoLock::Type locktype = AutoLock::NONE);
int Open(const headers_t* pmeta, off_t size, const struct timespec& ts_mctime, int flags, AutoLock::Type type);
bool LoadAll(int fd, headers_t* pmeta = NULL, off_t* size = NULL, bool force_load = false);
int Dup(int fd, bool lock_already_held = false);
int OpenPseudoFd(int flags = O_RDONLY, bool lock_already_held = false);
int GetOpenCount(bool lock_already_held = false);
int Dup(int fd, AutoLock::Type locktype = AutoLock::NONE);
int OpenPseudoFd(int flags = O_RDONLY, AutoLock::Type locktype = AutoLock::NONE);
int GetOpenCount(AutoLock::Type locktype = AutoLock::NONE);
const char* GetPath() const { return path.c_str(); }
bool RenamePath(const std::string& newpath, std::string& fentmapkey);
int GetPhysicalFd() const { return physical_fd; }
@ -118,16 +118,16 @@ class FdEntity
bool MergeOrgMeta(headers_t& updatemeta);
int UploadPending(int fd, AutoLock::Type type);
bool GetStats(struct stat& st, bool lock_already_held = false);
int SetCtime(struct timespec time, bool lock_already_held = false);
int SetAtime(struct timespec time, bool lock_already_held = false);
int SetMCtime(struct timespec mtime, struct timespec ctime, bool lock_already_held = false);
bool GetStats(struct stat& st, AutoLock::Type locktype = AutoLock::NONE);
int SetCtime(struct timespec time, AutoLock::Type locktype = AutoLock::NONE);
int SetAtime(struct timespec time, AutoLock::Type locktype = AutoLock::NONE);
int SetMCtime(struct timespec mtime, struct timespec ctime, AutoLock::Type locktype = AutoLock::NONE);
bool UpdateCtime();
bool UpdateAtime();
bool UpdateMtime(bool clear_holding_mtime = false);
bool UpdateMCtime();
bool SetHoldingMtime(struct timespec mtime, bool lock_already_held = false);
bool ClearHoldingMtime(bool lock_already_held = false);
bool SetHoldingMtime(struct timespec mtime, AutoLock::Type locktype = AutoLock::NONE);
bool ClearHoldingMtime(AutoLock::Type locktype = AutoLock::NONE);
bool GetSize(off_t& size);
bool GetXattr(std::string& xattr);
bool SetXattr(const std::string& xattr);