Merge pull request #1096 from gaul/pthread/lock-checking

Expand error checking to all pthread_mutex_t
This commit is contained in:
Takeshi Nakatani 2019-07-15 11:43:56 +09:00 committed by GitHub
commit 543aed2a32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 10 deletions

View File

@ -236,7 +236,12 @@ const char* BodyData::str() const
//-------------------------------------------------------------------
bool CurlHandlerPool::Init()
{
if (0 != pthread_mutex_init(&mLock, NULL)) {
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
if (0 != pthread_mutex_init(&mLock, &attr)) {
S3FS_PRN_ERR("Init curl handlers lock failed");
return false;
}
@ -388,13 +393,18 @@ bool S3fsCurl::is_use_session_token = false; // default
//-------------------------------------------------------------------
bool S3fsCurl::InitS3fsCurl(const char* MimeFile)
{
if(0 != pthread_mutex_init(&S3fsCurl::curl_handles_lock, NULL)){
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
if(0 != pthread_mutex_init(&S3fsCurl::curl_handles_lock, &attr)){
return false;
}
if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_DNS], NULL)){
if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_DNS], &attr)){
return false;
}
if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_SSL_SESSION], NULL)){
if(0 != pthread_mutex_init(&S3fsCurl::curl_share_lock[SHARE_MUTEX_SSL_SESSION], &attr)){
return false;
}
if(!S3fsCurl::InitMimeType(MimeFile)){
@ -3982,7 +3992,12 @@ S3fsMultiCurl::S3fsMultiCurl(int maxParallelism)
, RetryCallback(NULL)
{
int res;
if (0 != (res = pthread_mutex_init(&completed_tids_lock, NULL))) {
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
if (0 != (res = pthread_mutex_init(&completed_tids_lock, &attr))) {
S3FS_PRN_ERR("could not initialize completed_tids_lock: %i", res);
}
}

View File

@ -2046,10 +2046,15 @@ bool FdManager::IsSafeDiskSpace(const char* path, off_t size)
FdManager::FdManager()
{
if(this == FdManager::get()){
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
try{
pthread_mutex_init(&FdManager::fd_manager_lock, NULL);
pthread_mutex_init(&FdManager::cache_cleanup_lock, NULL);
pthread_mutex_init(&FdManager::reserved_diskspace_lock, NULL);
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;

View File

@ -106,7 +106,12 @@ static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int l
static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int line)
{
struct CRYPTO_dynlock_value* dyndata = new CRYPTO_dynlock_value();
pthread_mutex_init(&(dyndata->dyn_mutex), NULL);
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
pthread_mutex_init(&(dyndata->dyn_mutex), &attr);
return dyndata;
}
@ -141,8 +146,13 @@ bool s3fs_init_crypt_mutex()
}
}
s3fs_crypt_mutex = new pthread_mutex_t[CRYPTO_num_locks()];
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if S3FS_PTHREAD_ERRORCHECK
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#endif
for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){
pthread_mutex_init(&s3fs_crypt_mutex[cnt], NULL);
pthread_mutex_init(&s3fs_crypt_mutex[cnt], &attr);
}
// static lock
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);