diff --git a/src/Makefile.am b/src/Makefile.am index c0e46d2700..5c44482b4f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,6 @@ s3fs_SOURCES = \ metaheader.cpp \ mpu_util.cpp \ curl.cpp \ - curl_handlerpool.cpp \ curl_multi.cpp \ curl_util.cpp \ s3objlist.cpp \ diff --git a/src/curl.cpp b/src/curl.cpp index df68d9852c..209ffd8f8b 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -35,7 +35,6 @@ #include "curl_multi.h" #include "curl_util.h" #include "s3fs_auth.h" -#include "curl_handlerpool.h" #include "s3fs_cred.h" #include "s3fs_util.h" #include "string_util.h" @@ -97,8 +96,6 @@ std::mutex S3fsCurl::curl_warnings_lock; std::mutex S3fsCurl::curl_handles_lock; S3fsCurl::callback_locks_t S3fsCurl::callback_locks; bool S3fsCurl::is_initglobal_done = false; -CurlHandlerPool* S3fsCurl::sCurlPool = nullptr; -int S3fsCurl::sCurlPoolSize = 32; CURLSH* S3fsCurl::hCurlShare = nullptr; bool S3fsCurl::is_cert_check = true; // default bool S3fsCurl::is_dns_cache = true; // default @@ -161,14 +158,6 @@ bool S3fsCurl::InitS3fsCurl() if(!S3fsCurl::InitCryptMutex()){ return false; } - // [NOTE] - // sCurlPoolSize must be over parallel(or multireq) count. - // - sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()}); - sCurlPool = new CurlHandlerPool(sCurlPoolSize); - if (!sCurlPool->Init()) { - return false; - } return true; } @@ -179,11 +168,6 @@ bool S3fsCurl::DestroyS3fsCurl() if(!S3fsCurl::DestroyCryptMutex()){ result = false; } - if(!sCurlPool->Destroy()){ - result = false; - } - delete sCurlPool; - sCurlPool = nullptr; if(!S3fsCurl::DestroyShareCurl()){ result = false; } @@ -1975,7 +1959,7 @@ bool S3fsCurl::ResetHandle() curl_warnings_once = true; } - sCurlPool->ResetHandler(hCurl.get()); + curl_easy_reset(hCurl.get()); if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_NOSIGNAL, 1)){ return false; @@ -2098,12 +2082,12 @@ bool S3fsCurl::ResetHandle() return true; } -bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake) +bool S3fsCurl::CreateCurlHandle(bool remake) { const std::lock_guard lock(S3fsCurl::curl_handles_lock); if(hCurl && remake){ - if(!DestroyCurlHandleHasLock(false, true)){ + if(!DestroyCurlHandleHasLock(true)){ S3FS_PRN_ERR("could not destroy handle."); return false; } @@ -2111,16 +2095,10 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake) } if(!hCurl){ - if(nullptr == (hCurl = sCurlPool->GetHandler(only_pool))){ - if(!only_pool){ - S3FS_PRN_ERR("Failed to create handle."); - return false; - }else{ - // [NOTE] - // Further initialization processing is left to lazy processing to be executed later. - // (Currently we do not use only_pool=true, but this code is remained for the future) - return true; - } + hCurl.reset(curl_easy_init()); + if(!hCurl){ + S3FS_PRN_ERR("Failed to create handle."); + return false; } } ResetHandle(); @@ -2128,13 +2106,13 @@ bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake) return true; } -bool S3fsCurl::DestroyCurlHandle(bool restore_pool, bool clear_internal_data) +bool S3fsCurl::DestroyCurlHandle(bool clear_internal_data) { const std::lock_guard lock(S3fsCurl::curl_handles_lock); - return DestroyCurlHandleHasLock(restore_pool, clear_internal_data); + return DestroyCurlHandleHasLock(clear_internal_data); } -bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_data) +bool S3fsCurl::DestroyCurlHandleHasLock(bool clear_internal_data) { // [NOTE] // If type is REQTYPE::IAMCRED or REQTYPE::IAMROLE, do not clear type. @@ -2151,7 +2129,7 @@ bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_d if(hCurl){ S3fsCurl::curl_progress.erase(hCurl.get()); - sCurlPool->ReturnHandler(std::move(hCurl), restore_pool); + hCurl.reset(); }else{ return false; } diff --git a/src/curl.h b/src/curl.h index 042e45ebd1..dcad5223a3 100644 --- a/src/curl.h +++ b/src/curl.h @@ -130,8 +130,6 @@ class S3fsCurl std::mutex ssl_session; } callback_locks; static bool is_initglobal_done; - static CurlHandlerPool* sCurlPool; - static int sCurlPoolSize; static CURLSH* hCurlShare; static bool is_cert_check; static bool is_dns_cache; @@ -360,9 +358,9 @@ class S3fsCurl static bool SetIPResolveType(const char* value); // methods - bool CreateCurlHandle(bool only_pool = false, bool remake = false); - bool DestroyCurlHandle(bool restore_pool = true, bool clear_internal_data = true); - bool DestroyCurlHandleHasLock(bool restore_pool = true, bool clear_internal_data = true) REQUIRES(S3fsCurl::curl_handles_lock); + bool CreateCurlHandle(bool remake = false); + bool DestroyCurlHandle(bool clear_internal_data = true); + bool DestroyCurlHandleHasLock(bool clear_internal_data = true) REQUIRES(S3fsCurl::curl_handles_lock); bool GetIAMCredentials(const char* cred_url, const char* iam_v2_token, const char* ibm_secret_access_key, std::string& response); bool GetIAMRoleFromMetaData(const char* cred_url, const char* iam_v2_token, std::string& token); diff --git a/src/curl_handlerpool.cpp b/src/curl_handlerpool.cpp deleted file mode 100644 index b7cd96f717..0000000000 --- a/src/curl_handlerpool.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * s3fs - FUSE-based file system backed by Amazon S3 - * - * Copyright(C) 2007 Randy Rizun - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "s3fs_logger.h" -#include "curl_handlerpool.h" - -//------------------------------------------------------------------- -// Class CurlHandlerPool -//------------------------------------------------------------------- -bool CurlHandlerPool::Init() -{ - for(int cnt = 0; cnt < mMaxHandlers; ++cnt){ - CurlUniquePtr hCurl(curl_easy_init(), &curl_easy_cleanup); - if(!hCurl){ - S3FS_PRN_ERR("Init curl handlers pool failed"); - Destroy(); - return false; - } - mPool.push_back(std::move(hCurl)); - } - return true; -} - -bool CurlHandlerPool::Destroy() -{ - const std::lock_guard lock(mLock); - - while(!mPool.empty()){ - mPool.pop_back(); - } - return true; -} - -CurlUniquePtr CurlHandlerPool::GetHandler(bool only_pool) -{ - const std::lock_guard lock(mLock); - - CurlUniquePtr hCurl(nullptr, curl_easy_cleanup); - - if(!mPool.empty()){ - hCurl = std::move(mPool.back()); - mPool.pop_back(); - S3FS_PRN_DBG("Get handler from pool: rest = %d", static_cast(mPool.size())); - } - if(only_pool){ - return hCurl; - } - if(!hCurl){ - S3FS_PRN_INFO("Pool empty: force to create new handler"); - hCurl.reset(curl_easy_init()); - } - return hCurl; -} - -void CurlHandlerPool::ReturnHandler(CurlUniquePtr&& hCurl, bool restore_pool) -{ - if(!hCurl){ - return; - } - const std::lock_guard lock(mLock); - - if(restore_pool){ - S3FS_PRN_DBG("Return handler to pool"); - mPool.push_back(std::move(hCurl)); - - while(mMaxHandlers < static_cast(mPool.size())){ - S3FS_PRN_INFO("Pool full: destroy the oldest handler"); - mPool.pop_front(); - } - }else{ - S3FS_PRN_INFO("Pool full: destroy the handler"); - } -} - -void CurlHandlerPool::ResetHandler(CURL* hCurl) -{ - if(!hCurl){ - return; - } - const std::lock_guard lock(mLock); - - curl_easy_reset(hCurl); -} - -/* -* Local variables: -* tab-width: 4 -* c-basic-offset: 4 -* End: -* vim600: expandtab sw=4 ts=4 fdm=marker -* vim<600: expandtab sw=4 ts=4 -*/ diff --git a/src/curl_handlerpool.h b/src/curl_handlerpool.h deleted file mode 100644 index 84763417b0..0000000000 --- a/src/curl_handlerpool.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * s3fs - FUSE-based file system backed by Amazon S3 - * - * Copyright(C) 2007 Randy Rizun - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef S3FS_CURL_HANDLERPOOL_H_ -#define S3FS_CURL_HANDLERPOOL_H_ - -#include -#include -#include -#include -#include - -//---------------------------------------------- -// Typedefs -//---------------------------------------------- -typedef std::unique_ptr CurlUniquePtr; - -//---------------------------------------------- -// class CurlHandlerPool -//---------------------------------------------- -class CurlHandlerPool -{ - public: - explicit CurlHandlerPool(int maxHandlers) : mMaxHandlers(maxHandlers) - { - assert(maxHandlers > 0); - } - CurlHandlerPool(const CurlHandlerPool&) = delete; - CurlHandlerPool(CurlHandlerPool&&) = delete; - CurlHandlerPool& operator=(const CurlHandlerPool&) = delete; - CurlHandlerPool& operator=(CurlHandlerPool&&) = delete; - - bool Init(); - bool Destroy(); - - CurlUniquePtr GetHandler(bool only_pool); - void ReturnHandler(CurlUniquePtr&& hCurl, bool restore_pool); - void ResetHandler(CURL* hCurl); - - private: - int mMaxHandlers; - std::mutex mLock; - std::list mPool; -}; - -#endif // S3FS_CURL_HANDLERPOOL_H_ - -/* -* Local variables: -* tab-width: 4 -* c-basic-offset: 4 -* End: -* vim600: expandtab sw=4 ts=4 fdm=marker -* vim<600: expandtab sw=4 ts=4 -*/ diff --git a/src/curl_multi.cpp b/src/curl_multi.cpp index e2bee268cb..428bae36d2 100644 --- a/src/curl_multi.cpp +++ b/src/curl_multi.cpp @@ -348,7 +348,7 @@ void S3fsMultiCurl::RequestPerformWrapper(S3fsCurl* s3fscurl, std::promise if(!result){ result = s3fscurl->RequestPerform(); - s3fscurl->DestroyCurlHandle(true, false); + s3fscurl->DestroyCurlHandle(false); } const std::lock_guard lock(*s3fscurl->completed_tids_lock); diff --git a/src/fdcache_fdinfo.cpp b/src/fdcache_fdinfo.cpp index 500ed0011d..3abe050cc6 100644 --- a/src/fdcache_fdinfo.cpp +++ b/src/fdcache_fdinfo.cpp @@ -93,7 +93,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg) }else{ S3FS_PRN_ERR("failed uploading with error(%d) [path=%s][start=%lld][size=%lld][part=%d]", result, pthparam->path.c_str(), static_cast(pthparam->start), static_cast(pthparam->size), pthparam->part_num); } - s3fscurl->DestroyCurlHandle(true, false); + s3fscurl->DestroyCurlHandle(false); // set result const std::lock_guard lock(pthparam->ppseudofdinfo->upload_list_lock);