Compare commits

...

2 Commits

Author SHA1 Message Date
Takeshi Nakatani a5cdd05c25 Added ipresolve option 2024-03-13 22:29:17 +09:00
Andrew Gaul 31676f6201
Convert thpoolman_param to value (#2430)
This simplifies memory management.
2024-03-13 21:27:12 +09:00
8 changed files with 72 additions and 38 deletions

View File

@ -418,6 +418,12 @@ Username and passphrase are valid only for HTTP schema.
If the HTTP proxy does not require authentication, this option is not required.
Separate the username and passphrase with a ':' character and specify each as a URL-encoded string.
.TP
\fB\-o\fR ipresolve (default="whatever")
Select what type of IP addresses to use when establishing a connection.
Default('whatever') can use addresses of all IP versions(IPv4 and IPv6) that your system allows.
If you specify 'IPv4', only IPv4 addresses are used.
And when 'IPv6' is specified, only IPv6 addresses will be used.
.TP
\fB\-o\fR logfile - specify the log output file.
s3fs outputs the log file to syslog. Alternatively, if s3fs is started with the "-f" option specified, the log will be output to the stdout/stderr.
You can use this option to specify the log file that s3fs outputs.

View File

@ -130,6 +130,7 @@ bool S3fsCurl::requester_pays = false; // default
std::string S3fsCurl::proxy_url;
bool S3fsCurl::proxy_http = false;
std::string S3fsCurl::proxy_userpwd;
long S3fsCurl::ipresolve_type = CURL_IPRESOLVE_WHATEVER;
//-------------------------------------------------------------------
// Class methods for S3fsCurl
@ -1174,6 +1175,23 @@ bool S3fsCurl::SetProxyUserPwd(const char* file)
return true;
}
bool S3fsCurl::SetIPResolveType(const char* value)
{
if(!value){
return false;
}
if(0 == strcasecmp(value, "ipv4")){
S3fsCurl::ipresolve_type = CURL_IPRESOLVE_V4;
}else if(0 == strcasecmp(value, "ipv6")){
S3fsCurl::ipresolve_type = CURL_IPRESOLVE_V6;
}else if(0 == strcasecmp(value, "whatever")){ // = default type
S3fsCurl::ipresolve_type = CURL_IPRESOLVE_WHATEVER;
}else{
return false;
}
return true;
}
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress constParameter
// cppcheck-suppress constParameterCallback
@ -1949,7 +1967,11 @@ bool S3fsCurl::ResetHandle(AutoLock::Type locktype)
if(CURLE_OK != curl_easy_setopt(hCurl, S3FS_CURLOPT_KEEP_SENDING_ON_ERROR, 1) && !run_once){
S3FS_PRN_WARN("The S3FS_CURLOPT_KEEP_SENDING_ON_ERROR option could not be set. For maximize performance you need to enable this option and you should use libcurl 7.51.0 or later.");
}
if(CURL_IPRESOLVE_WHATEVER != S3fsCurl::ipresolve_type){ // CURL_IPRESOLVE_WHATEVER is default, so not need to set.
if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_IPRESOLVE, S3fsCurl::ipresolve_type)){
return false;
}
}
if(type != REQTYPE::IAMCRED && type != REQTYPE::IAMROLE){
// REQTYPE::IAMCRED and REQTYPE::IAMROLE are always HTTP
if(0 == S3fsCurl::ssl_verify_hostname){

View File

@ -156,6 +156,7 @@ class S3fsCurl
static std::string proxy_url;
static bool proxy_http;
static std::string proxy_userpwd; // load from file(<username>:<passphrase>)
static long ipresolve_type; // this value is a libcurl symbol.
// variables
CURL* hCurl;
@ -340,6 +341,7 @@ class S3fsCurl
static bool IsRequesterPays() { return S3fsCurl::requester_pays; }
static bool SetProxy(const char* url);
static bool SetProxyUserPwd(const char* userpwd);
static bool SetIPResolveType(const char* value);
// methods
bool CreateCurlHandle(bool only_pool = false, bool remake = false);

View File

@ -449,13 +449,13 @@ bool PseudoFdInfo::ParallelMultipartUpload(const char* path, const mp_part_list_
thargs->petag = petag;
// make parameter for thread pool
std::unique_ptr<thpoolman_param> ppoolparam(new thpoolman_param);
ppoolparam->args = thargs;
ppoolparam->psem = &uploaded_sem;
ppoolparam->pfunc = PseudoFdInfo::MultipartUploadThreadWorker;
thpoolman_param ppoolparam;
ppoolparam.args = thargs;
ppoolparam.psem = &uploaded_sem;
ppoolparam.pfunc = PseudoFdInfo::MultipartUploadThreadWorker;
// setup instruction
if(!ThreadPoolMan::Instruct(std::move(ppoolparam))){
if(!ThreadPoolMan::Instruct(ppoolparam)){
S3FS_PRN_ERR("failed setup instruction for uploading.");
delete thargs;
return false;

View File

@ -5434,6 +5434,14 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
}
return 0;
}
else if(is_prefix(arg, "ipresolve=")){
const char* pipresolve = &arg[strlen("ipresolve=")];
if(!S3fsCurl::SetIPResolveType(pipresolve)){
S3FS_PRN_EXIT("failed to ip resolve option value(%s).", pipresolve);
return -1;
}
return 0;
}
//
// log file option
//

View File

@ -527,6 +527,14 @@ static constexpr char help_string[] =
" Separate the username and passphrase with a ':' character and\n"
" specify each as a URL-encoded string.\n"
"\n"
" ipresolve (default=\"whatever\")\n"
" Select what type of IP addresses to use when establishing a\n"
" connection.\n"
" Default('whatever') can use addresses of all IP versions(IPv4 and\n"
" IPv6) that your system allows. If you specify 'IPv4', only IPv4\n"
" addresses are used. And when 'IPv6'is specified, only IPv6 addresses\n"
" will be used.\n"
"\n"
" logfile - specify the log output file.\n"
" s3fs outputs the log file to syslog. Alternatively, if s3fs is\n"
" started with the \"-f\" option specified, the log will be output\n"

View File

@ -53,13 +53,14 @@ void ThreadPoolMan::Destroy()
}
}
bool ThreadPoolMan::Instruct(std::unique_ptr<thpoolman_param> pparam)
bool ThreadPoolMan::Instruct(const thpoolman_param& param)
{
if(!ThreadPoolMan::singleton){
S3FS_PRN_WARN("The singleton object is not initialized yet.");
return false;
}
return ThreadPoolMan::singleton->SetInstruction(std::move(pparam));
ThreadPoolMan::singleton->SetInstruction(param);
return true;
}
//
@ -84,30 +85,25 @@ void* ThreadPoolMan::Worker(void* arg)
}
// get instruction
std::unique_ptr<thpoolman_param> pparam;
thpoolman_param param;
{
AutoLock auto_lock(&(psingleton->thread_list_lock));
if(!psingleton->instruction_list.empty()){
pparam = std::move(psingleton->instruction_list.front());
psingleton->instruction_list.pop_front();
if(!pparam){
S3FS_PRN_WARN("Got a semaphore, but the instruction is empty.");
}
if(psingleton->instruction_list.empty()){
S3FS_PRN_DBG("Got a semaphore, but the instruction is empty.");
continue;
}else{
S3FS_PRN_WARN("Got a semaphore, but there is no instruction.");
pparam = nullptr;
param = psingleton->instruction_list.front();
psingleton->instruction_list.pop_front();
}
}
if(pparam){
void* retval = pparam->pfunc(pparam->args);
if(nullptr != retval){
S3FS_PRN_WARN("The instruction function returned with somthign error code(%ld).", reinterpret_cast<long>(retval));
}
if(pparam->psem){
pparam->psem->post();
}
void* retval = param.pfunc(param.args);
if(nullptr != retval){
S3FS_PRN_WARN("The instruction function returned with somthign error code(%ld).", reinterpret_cast<long>(retval));
}
if(param.psem){
param.psem->post();
}
}
@ -235,23 +231,16 @@ bool ThreadPoolMan::StartThreads(int count)
return true;
}
bool ThreadPoolMan::SetInstruction(std::unique_ptr<thpoolman_param> pparam)
void ThreadPoolMan::SetInstruction(const thpoolman_param& param)
{
if(!pparam){
S3FS_PRN_ERR("The parameter value is nullptr.");
return false;
}
// set parameter to list
{
AutoLock auto_lock(&thread_list_lock);
instruction_list.push_back(std::move(pparam));
instruction_list.push_back(param);
}
// run thread
thpoolman_sem.post();
return true;
}
/*

View File

@ -23,7 +23,6 @@
#include <atomic>
#include <list>
#include <memory>
#include <vector>
#include "psemaphore.h"
@ -53,7 +52,7 @@ struct thpoolman_param
thpoolman_param() : args(nullptr), psem(nullptr), pfunc(nullptr) {}
};
typedef std::list<std::unique_ptr<thpoolman_param>> thpoolman_params_t;
typedef std::list<thpoolman_param> thpoolman_params_t;
typedef std::vector<pthread_t> thread_list_t;
@ -89,12 +88,12 @@ class ThreadPoolMan
bool StopThreads();
bool StartThreads(int count);
bool SetInstruction(std::unique_ptr<thpoolman_param> pparam);
void SetInstruction(const thpoolman_param& pparam);
public:
static bool Initialize(int count);
static void Destroy();
static bool Instruct(std::unique_ptr<thpoolman_param> pparam);
static bool Instruct(const thpoolman_param& pparam);
};
#endif // S3FS_THREADPOOLMAN_H_