From fd2a6c120ac4b6eb942aa0111bd4e4b3ee4485f1 Mon Sep 17 00:00:00 2001 From: apetresc Date: Tue, 8 Feb 2011 18:23:38 +0000 Subject: [PATCH] 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 --- src/s3fs.cpp | 23 +++++++++++++++++------ src/s3fs.h | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index ae5dc26..79a9797 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -2029,7 +2029,6 @@ static int s3fs_getattr(const char *path, struct stat *stbuf) { stat_cache_t::iterator iter = stat_cache.find(path); if (iter != stat_cache.end()) { *stbuf = (*iter).second; - stat_cache.erase(path); pthread_mutex_unlock( &stat_cache_lock ); return 0; } @@ -2107,6 +2106,11 @@ static int s3fs_getattr(const char *path, struct stat *stbuf) { } 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; } @@ -2476,6 +2480,7 @@ static int s3fs_rmdir(const char *path) { return -ENOTEMPTY; } } + // delete the directory string resource = urlEncode(service_path + bucket + path); string url = host + resource; @@ -2510,6 +2515,9 @@ static int s3fs_rmdir(const char *path) { return result; } + // delete cache entry + delete_stat_cache_entry(path); + return 0; } @@ -2674,11 +2682,9 @@ static int rename_directory( const char *from, const char *to) { string Key; bool is_dir; - body.text = (char *)malloc(1); body.size = 0; - // create the head/tail of the linked list from_path.assign(from); to_path.assign(to); @@ -2925,9 +2931,6 @@ static int rename_directory( const char *from, const char *to) { return 0; } - - - static int s3fs_rename(const char *from, const char *to) { if(foreground) 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); } + delete_stat_cache_entry(from); + return result; } @@ -3465,6 +3470,12 @@ static int s3fs_readdir( 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. * diff --git a/src/s3fs.h b/src/s3fs.h index 8f86c86..26b2073 100644 --- a/src/s3fs.h +++ b/src/s3fs.h @@ -84,6 +84,8 @@ static struct fuse_operations s3fs_oper; string urlEncode(const string &s); 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_readlink(const char *path, char *buf, size_t size); static int s3fs_mknod(const char* path, mode_t mode, dev_t rdev);