Committing patch contributed by Ben LeMasurier to cache directory attributes. Details and tests on Issue 150.

git-svn-id: http://s3fs.googlecode.com/svn/trunk@309 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
apetresc 2011-02-08 18:23:38 +00:00
parent 0a233011a5
commit fd2a6c120a
2 changed files with 19 additions and 6 deletions

View File

@ -2029,7 +2029,6 @@ static int s3fs_getattr(const char *path, struct stat *stbuf) {
stat_cache_t::iterator iter = stat_cache.find(path); stat_cache_t::iterator iter = stat_cache.find(path);
if (iter != stat_cache.end()) { if (iter != stat_cache.end()) {
*stbuf = (*iter).second; *stbuf = (*iter).second;
stat_cache.erase(path);
pthread_mutex_unlock( &stat_cache_lock ); pthread_mutex_unlock( &stat_cache_lock );
return 0; return 0;
} }
@ -2107,6 +2106,11 @@ static int s3fs_getattr(const char *path, struct stat *stbuf) {
} }
destroy_curl_handle(curl); destroy_curl_handle(curl);
// update stat cache
pthread_mutex_lock(&stat_cache_lock);
stat_cache[path] = *stbuf;
pthread_mutex_unlock(&stat_cache_lock);
return 0; return 0;
} }
@ -2476,6 +2480,7 @@ static int s3fs_rmdir(const char *path) {
return -ENOTEMPTY; return -ENOTEMPTY;
} }
} }
// delete the directory // delete the directory
string resource = urlEncode(service_path + bucket + path); string resource = urlEncode(service_path + bucket + path);
string url = host + resource; string url = host + resource;
@ -2510,6 +2515,9 @@ static int s3fs_rmdir(const char *path) {
return result; return result;
} }
// delete cache entry
delete_stat_cache_entry(path);
return 0; return 0;
} }
@ -2674,11 +2682,9 @@ static int rename_directory( const char *from, const char *to) {
string Key; string Key;
bool is_dir; bool is_dir;
body.text = (char *)malloc(1); body.text = (char *)malloc(1);
body.size = 0; body.size = 0;
// create the head/tail of the linked list // create the head/tail of the linked list
from_path.assign(from); from_path.assign(from);
to_path.assign(to); to_path.assign(to);
@ -2925,9 +2931,6 @@ static int rename_directory( const char *from, const char *to) {
return 0; return 0;
} }
static int s3fs_rename(const char *from, const char *to) { static int s3fs_rename(const char *from, const char *to) {
if(foreground) if(foreground)
cout << "rename[from=" << from << "][to=" << to << "]" << endl; cout << "rename[from=" << from << "][to=" << to << "]" << endl;
@ -2960,6 +2963,8 @@ static int s3fs_rename(const char *from, const char *to) {
result = rename_object(from, to); result = rename_object(from, to);
} }
delete_stat_cache_entry(from);
return result; return result;
} }
@ -3465,6 +3470,12 @@ static int s3fs_readdir(
return 0; return 0;
} }
static void delete_stat_cache_entry(const char *path) {
pthread_mutex_lock(&stat_cache_lock);
stat_cache.erase(stat_cache.find(path));
pthread_mutex_unlock(&stat_cache_lock);
}
/** /**
* OpenSSL locking function. * OpenSSL locking function.
* *

View File

@ -84,6 +84,8 @@ static struct fuse_operations s3fs_oper;
string urlEncode(const string &s); string urlEncode(const string &s);
string lookupMimeType(string); string lookupMimeType(string);
static void delete_stat_cache_entry(const char *path);
static int s3fs_getattr(const char *path, struct stat *stbuf); static int s3fs_getattr(const char *path, struct stat *stbuf);
static int s3fs_readlink(const char *path, char *buf, size_t size); static int s3fs_readlink(const char *path, char *buf, size_t size);
static int s3fs_mknod(const char* path, mode_t mode, dev_t rdev); static int s3fs_mknod(const char* path, mode_t mode, dev_t rdev);