Fixed Issue 304

1) s3fs should cache DNS lookups?(Issue 304)
   Changes that s3fs always uses own dns cache, and adds "nodnscache" option.
   If "nodnscache" is specified, s3fs does not use dns cache as before.
   s3fs keeps DNS cache for 60 senconds by libcurl's default.



git-svn-id: http://s3fs.googlecode.com/svn/trunk@429 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
ggtakec@gmail.com 2013-05-22 08:49:23 +00:00
parent be5fa78032
commit 7477224d02
5 changed files with 88 additions and 2 deletions

View File

@ -86,6 +86,9 @@ s3fs always has to check whether file(or sub directory) exists under object(path
It increases ListBucket request and makes performance bad.
You can specify this option for performance, s3fs memorizes in stat cache that the object(file or directory) does not exist.
.TP
\fB\-o\fR nodnscache - disable dns cache.
s3fs is always using dns cache, this option make dns cache disable.
.TP
\fB\-o\fR url (default="http://s3.amazonaws.com")
sets the url to use to access Amazon S3. If you want to use HTTPS, then you can set url=https://s3.amazonaws.com
.TP

View File

@ -62,6 +62,8 @@ typedef pair<double, double> progress_t;
// Static valiables
//-------------------------------------------------------------------
static pthread_mutex_t curl_handles_lock;
static pthread_mutex_t curl_share_lock;
static CURLSH* hCurlShare = NULL;
static const EVP_MD* evp_md = EVP_sha1();
static map<CURL*, time_t> curl_times;
static map<CURL*, progress_t> curl_progress;
@ -151,6 +153,71 @@ int destroy_curl_handles_mutex(void)
return pthread_mutex_destroy(&curl_handles_lock);
}
static void lock_curl_share(CURL* handle, curl_lock_data nLockData, curl_lock_access laccess, void* useptr)
{
if(hCurlShare && CURL_LOCK_DATA_DNS == nLockData){
pthread_mutex_lock(&curl_share_lock);
}
}
static void unlock_curl_share(CURL* handle, curl_lock_data nLockData, curl_lock_access laccess, void* useptr)
{
if(hCurlShare && CURL_LOCK_DATA_DNS == nLockData){
pthread_mutex_unlock(&curl_share_lock);
}
}
int init_curl_share(bool isCache)
{
CURLSHcode nSHCode;
if(!isCache){
return 0;
}
if(NULL == (hCurlShare = curl_share_init())){
FGPRINT(" init_curl_share: curl_share_init failed\n");
SYSLOGERR("init_curl_share: curl_share_init failed\n");
return -1;
}
if(CURLSHE_OK != (nSHCode = curl_share_setopt(hCurlShare, CURLSHOPT_LOCKFUNC, lock_curl_share))){
FGPRINT(" init_curl_share: curl_share_setopt returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
SYSLOGERR("init_curl_share: %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
return nSHCode;
}
if(CURLSHE_OK != (nSHCode = curl_share_setopt(hCurlShare, CURLSHOPT_UNLOCKFUNC, unlock_curl_share))){
FGPRINT(" init_curl_share: curl_share_setopt returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
SYSLOGERR("init_curl_share: %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
return nSHCode;
}
if(CURLSHE_OK != (nSHCode = curl_share_setopt(hCurlShare, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS))){
FGPRINT(" init_curl_share: curl_share_setopt returns %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
SYSLOGERR("init_curl_share: %d(%s)\n", nSHCode, curl_share_strerror(nSHCode));
return nSHCode;
}
return pthread_mutex_init(&curl_share_lock, NULL);
}
int destroy_curl_share(bool isCache)
{
int result = 0;
if(!isCache){
return result;
}
result = pthread_mutex_destroy(&curl_share_lock);
if(hCurlShare && CURLSHE_OK != curl_share_cleanup(hCurlShare) && 0 == result){
result = -1;
}
return result;
}
void my_set_curl_share(CURL* curl)
{
if(curl && hCurlShare){
curl_easy_setopt(curl, CURLOPT_SHARE, hCurlShare);
}
}
size_t header_callback(void *data, size_t blockSize, size_t numBlocks, void *userPtr)
{
headers_t* headers = reinterpret_cast<headers_t*>(userPtr);
@ -364,6 +431,8 @@ int my_curl_easy_perform(CURL* curl, BodyData* body, BodyData* head, FILE* f)
if(curl_ca_bundle.size() != 0){
curl_easy_setopt(curl, CURLOPT_CAINFO, curl_ca_bundle.c_str());
}
// set dns cache
my_set_curl_share(curl);
long responseCode;

View File

@ -110,6 +110,9 @@ class auto_head {
//
int init_curl_handles_mutex(void);
int destroy_curl_handles_mutex(void);
int init_curl_share(bool isCache);
int destroy_curl_share(bool isCache);
void my_set_curl_share(CURL* curl);
size_t header_callback(void *data, size_t blockSize, size_t numBlocks, void *userPtr);
CURL *create_curl_handle(void);
int curl_delete(const char *path);

View File

@ -108,8 +108,9 @@ static bool norenameapi = false;
static bool nonempty = false;
static bool content_md5 = false;
static bool allow_other = false;
static uid_t s3fs_uid = 0; // default = root.
static gid_t s3fs_gid = 0; // default = root.
static uid_t s3fs_uid = 0; // default = root.
static gid_t s3fs_gid = 0; // default = root.
static bool dns_cache = true; // default = true
// if .size()==0 then local file cache is disabled
static std::string use_cache;
@ -2961,6 +2962,7 @@ static int s3fs_readdir(
head_data request_data;
request_data.path = fullorg;
CURL* curl_handle = create_head_handle(&request_data);
my_set_curl_share(curl_handle); // set dns cache
request_data.path = fullpath; // Notice: replace org to normalized for cache key.
curl_map.get()[curl_handle] = request_data;
@ -3452,6 +3454,7 @@ static void* s3fs_init(struct fuse_conn_info *conn)
pthread_mutex_init(&s3fs_descriptors_lock, NULL);
init_curl_handles_mutex();
InitMimeType("/etc/mime.types");
init_curl_share(dns_cache);
// Investigate system capabilities
if((unsigned int)conn->capable & FUSE_CAP_ATOMIC_O_TRUNC){
@ -3473,6 +3476,7 @@ static void s3fs_destroy(void*)
}
free(mutex_buf);
mutex_buf = NULL;
destroy_curl_share(dns_cache);
curl_global_cleanup();
pthread_mutex_destroy(&s3fs_descriptors_lock);
destroy_curl_handles_mutex();
@ -4224,6 +4228,10 @@ static int my_fuse_opt_proc(void *data, const char *arg, int key, struct fuse_ar
StatCache::getStatCacheData()->EnableCacheNoObject();
return 0;
}
if(strstr(arg, "nodnscache") != 0) {
dns_cache = false;
return 0;
}
if(strstr(arg, "noxmlns") != 0) {
noxmlns = true;
return 0;

View File

@ -704,6 +704,9 @@ void show_help (void)
" You can specify this option for performance, s3fs memorizes \n"
" in stat cache that the object(file or directory) does not exist.\n"
"\n"
" nodnscache - disable dns cache\n"
" - s3fs is always using dns cache, this option make dns cache disable.\n"
"\n"
" url (default=\"http://s3.amazonaws.com\")\n"
" - sets the url to use to access amazon s3\n"
"\n"