mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-14 08:24:07 +00:00
Merge pull request #1301 from gaul/pthread-result
Check results from pthread mutex calls
This commit is contained in:
commit
94e67c9c58
@ -169,7 +169,11 @@ StatCache::StatCache() : IsExpireTime(false), IsExpireIntervalType(false), Expir
|
||||
#if S3FS_PTHREAD_ERRORCHECK
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
pthread_mutex_init(&StatCache::stat_cache_lock, &attr);
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_init(&StatCache::stat_cache_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init stat_cache_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else{
|
||||
abort();
|
||||
}
|
||||
@ -179,7 +183,11 @@ StatCache::~StatCache()
|
||||
{
|
||||
if(this == StatCache::getStatCacheData()){
|
||||
Clear();
|
||||
pthread_mutex_destroy(&StatCache::stat_cache_lock);
|
||||
int res = pthread_mutex_destroy(&StatCache::stat_cache_lock);
|
||||
if(res != 0){
|
||||
S3FS_PRN_CRIT("failed to destroy stat_cache_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else{
|
||||
abort();
|
||||
}
|
||||
|
22
src/curl.cpp
22
src/curl.cpp
@ -596,11 +596,18 @@ void S3fsCurl::LockCurlShare(CURL* handle, curl_lock_data nLockData, curl_lock_a
|
||||
if(!hCurlShare){
|
||||
return;
|
||||
}
|
||||
int res;
|
||||
pthread_mutex_t* lockmutex = static_cast<pthread_mutex_t*>(useptr);
|
||||
if(CURL_LOCK_DATA_DNS == nLockData){
|
||||
pthread_mutex_lock(&lockmutex[SHARE_MUTEX_DNS]);
|
||||
if(0 != (res = pthread_mutex_lock(&lockmutex[SHARE_MUTEX_DNS]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_lock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else if(CURL_LOCK_DATA_SSL_SESSION == nLockData){
|
||||
pthread_mutex_lock(&lockmutex[SHARE_MUTEX_SSL_SESSION]);
|
||||
if(0 != (res = pthread_mutex_lock(&lockmutex[SHARE_MUTEX_SSL_SESSION]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_lock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -609,11 +616,18 @@ void S3fsCurl::UnlockCurlShare(CURL* handle, curl_lock_data nLockData, void* use
|
||||
if(!hCurlShare){
|
||||
return;
|
||||
}
|
||||
int res;
|
||||
pthread_mutex_t* lockmutex = static_cast<pthread_mutex_t*>(useptr);
|
||||
if(CURL_LOCK_DATA_DNS == nLockData){
|
||||
pthread_mutex_unlock(&lockmutex[SHARE_MUTEX_DNS]);
|
||||
if(0 != (res = pthread_mutex_unlock(&lockmutex[SHARE_MUTEX_DNS]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_unlock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else if(CURL_LOCK_DATA_SSL_SESSION == nLockData){
|
||||
pthread_mutex_unlock(&lockmutex[SHARE_MUTEX_SSL_SESSION]);
|
||||
if(0 != (res = pthread_mutex_unlock(&lockmutex[SHARE_MUTEX_SSL_SESSION]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_unlock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1045,18 +1045,21 @@ FdEntity::FdEntity(const char* tpath, const char* cpath)
|
||||
fd(-1), pfile(NULL), inode(0), size_orgmeta(0), upload_id(""), mp_start(0), mp_size(0),
|
||||
cachepath(SAFESTRPTR(cpath)), mirrorpath("")
|
||||
{
|
||||
try{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
#if S3FS_PTHREAD_ERRORCHECK
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
pthread_mutex_init(&fdent_lock, &attr);
|
||||
pthread_mutex_init(&fdent_data_lock, &attr);
|
||||
is_lock_init = true;
|
||||
}catch(exception& e){
|
||||
S3FS_PRN_CRIT("failed to init mutex");
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_init(&fdent_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init fdent_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_init(&fdent_data_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init fdent_data_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
is_lock_init = true;
|
||||
}
|
||||
|
||||
FdEntity::~FdEntity()
|
||||
@ -1064,11 +1067,14 @@ FdEntity::~FdEntity()
|
||||
Clear();
|
||||
|
||||
if(is_lock_init){
|
||||
try{
|
||||
pthread_mutex_destroy(&fdent_data_lock);
|
||||
pthread_mutex_destroy(&fdent_lock);
|
||||
}catch(exception& e){
|
||||
S3FS_PRN_CRIT("failed to destroy mutex");
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_destroy(&fdent_data_lock))){
|
||||
S3FS_PRN_CRIT("failed to destroy fdent_data_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_destroy(&fdent_lock))){
|
||||
S3FS_PRN_CRIT("failed to destroy fdent_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
is_lock_init = false;
|
||||
}
|
||||
@ -2580,15 +2586,20 @@ FdManager::FdManager()
|
||||
#if S3FS_PTHREAD_ERRORCHECK
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
try{
|
||||
pthread_mutex_init(&FdManager::fd_manager_lock, &attr);
|
||||
pthread_mutex_init(&FdManager::cache_cleanup_lock, &attr);
|
||||
pthread_mutex_init(&FdManager::reserved_diskspace_lock, &attr);
|
||||
FdManager::is_lock_init = true;
|
||||
}catch(exception& e){
|
||||
FdManager::is_lock_init = false;
|
||||
S3FS_PRN_CRIT("failed to init mutex");
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_init(&FdManager::fd_manager_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init fd_manager_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_init(&FdManager::cache_cleanup_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init cache_cleanup_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_init(&FdManager::reserved_diskspace_lock, &attr))){
|
||||
S3FS_PRN_CRIT("failed to init reserved_diskspace_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
FdManager::is_lock_init = true;
|
||||
}else{
|
||||
abort();
|
||||
}
|
||||
@ -2604,12 +2615,18 @@ FdManager::~FdManager()
|
||||
fent.clear();
|
||||
|
||||
if(FdManager::is_lock_init){
|
||||
try{
|
||||
pthread_mutex_destroy(&FdManager::fd_manager_lock);
|
||||
pthread_mutex_destroy(&FdManager::cache_cleanup_lock);
|
||||
pthread_mutex_destroy(&FdManager::reserved_diskspace_lock);
|
||||
}catch(exception& e){
|
||||
S3FS_PRN_CRIT("failed to init mutex");
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_destroy(&FdManager::fd_manager_lock))){
|
||||
S3FS_PRN_CRIT("failed to destroy fd_manager_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_destroy(&FdManager::cache_cleanup_lock))){
|
||||
S3FS_PRN_CRIT("failed to destroy cache_cleanup_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
if(0 != (res = pthread_mutex_destroy(&FdManager::reserved_diskspace_lock))){
|
||||
S3FS_PRN_CRIT("failed to destroy reserved_diskspace_lock: %d", res);
|
||||
abort();
|
||||
}
|
||||
FdManager::is_lock_init = false;
|
||||
}
|
||||
|
@ -86,10 +86,17 @@ static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line)
|
||||
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line)
|
||||
{
|
||||
if(s3fs_crypt_mutex){
|
||||
int res;
|
||||
if(mode & CRYPTO_LOCK){
|
||||
pthread_mutex_lock(&s3fs_crypt_mutex[pos]);
|
||||
if(0 != (res = pthread_mutex_lock(&s3fs_crypt_mutex[pos]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_lock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else{
|
||||
pthread_mutex_unlock(&s3fs_crypt_mutex[pos]);
|
||||
if(0 != (res = pthread_mutex_unlock(&s3fs_crypt_mutex[pos]))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_unlock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,7 +118,11 @@ static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int l
|
||||
#if S3FS_PTHREAD_ERRORCHECK
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
pthread_mutex_init(&(dyndata->dyn_mutex), &attr);
|
||||
int res;
|
||||
if(0 != (res = pthread_mutex_init(&(dyndata->dyn_mutex), &attr))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_init returned: %d", res);
|
||||
return NULL;
|
||||
}
|
||||
return dyndata;
|
||||
}
|
||||
|
||||
@ -119,10 +130,17 @@ static void s3fs_dyn_crypt_mutex_lock(int mode, struct CRYPTO_dynlock_value* dyn
|
||||
static void s3fs_dyn_crypt_mutex_lock(int mode, struct CRYPTO_dynlock_value* dyndata, const char* file, int line)
|
||||
{
|
||||
if(dyndata){
|
||||
int res;
|
||||
if(mode & CRYPTO_LOCK){
|
||||
pthread_mutex_lock(&(dyndata->dyn_mutex));
|
||||
if(0 != (res = pthread_mutex_lock(&(dyndata->dyn_mutex)))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_lock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}else{
|
||||
pthread_mutex_unlock(&(dyndata->dyn_mutex));
|
||||
if(0 != (res = pthread_mutex_unlock(&(dyndata->dyn_mutex)))){
|
||||
S3FS_PRN_CRIT("pthread_mutex_unlock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +149,11 @@ static void s3fs_destroy_dyn_crypt_mutex(struct CRYPTO_dynlock_value* dyndata, c
|
||||
static void s3fs_destroy_dyn_crypt_mutex(struct CRYPTO_dynlock_value* dyndata, const char* file, int line)
|
||||
{
|
||||
if(dyndata){
|
||||
pthread_mutex_destroy(&(dyndata->dyn_mutex));
|
||||
int res = pthread_mutex_destroy(&(dyndata->dyn_mutex));
|
||||
if(res != 0){
|
||||
S3FS_PRN_CRIT("failed to destroy dyn_mutex");
|
||||
abort();
|
||||
}
|
||||
delete dyndata;
|
||||
}
|
||||
}
|
||||
@ -152,7 +174,11 @@ bool s3fs_init_crypt_mutex()
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||
#endif
|
||||
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
|
||||
pthread_mutex_init(&s3fs_crypt_mutex[cnt], &attr);
|
||||
int res = pthread_mutex_init(&s3fs_crypt_mutex[cnt], &attr);
|
||||
if(res != 0){
|
||||
S3FS_PRN_CRIT("pthread_mutex_init returned: %d", res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// static lock
|
||||
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);
|
||||
@ -178,7 +204,11 @@ bool s3fs_destroy_crypt_mutex()
|
||||
CRYPTO_set_locking_callback(NULL);
|
||||
|
||||
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
|
||||
pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]);
|
||||
int res = pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]);
|
||||
if(res != 0){
|
||||
S3FS_PRN_CRIT("failed to destroy s3fs_crypt_mutex[%d]", cnt);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
CRYPTO_cleanup_all_ex_data();
|
||||
delete[] s3fs_crypt_mutex;
|
||||
|
@ -459,7 +459,11 @@ bool AutoLock::isLockAcquired() const
|
||||
AutoLock::~AutoLock()
|
||||
{
|
||||
if (is_lock_acquired) {
|
||||
pthread_mutex_unlock(auto_mutex);
|
||||
int res = pthread_mutex_unlock(auto_mutex);
|
||||
if(res != 0){
|
||||
S3FS_PRN_CRIT("pthread_mutex_lock returned: %d", res);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user