aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulio Merino <jmmv@google.com>2016-01-27 11:07:19 -0500
committerJulio Merino <jmmv@meroh.net>2016-02-10 23:18:35 -0500
commitebfeebd468551fa5e024b36dd218042cc5b7597e (patch)
tree34aaeae7bce4713b677605137c2be79b788f6710
parentd1ddbbcae51f8004e38971fb3546ed5c98effd8b (diff)
downloadsshfs-ebfeebd468551fa5e024b36dd218042cc5b7597e.tar
sshfs-ebfeebd468551fa5e024b36dd218042cc5b7597e.tar.gz
sshfs-ebfeebd468551fa5e024b36dd218042cc5b7597e.tar.bz2
sshfs-ebfeebd468551fa5e024b36dd218042cc5b7597e.zip
Expose the maximum cache size setting as a flag
Allow the user to customize the size of the sshfs cache by adding a new max_cache_size flag and turning the hardcoded constant into a variable.
-rw-r--r--ChangeLog2
-rw-r--r--cache.c7
-rw-r--r--sshfs.c1
3 files changed, 8 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 02fee35..066f553 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@ Draft notes for upcoming release
* Integrated osxfuse's copy of sshfs, which means that sshfs now works
on OS X out of the box.
+* Added -o cache_max_size=N option to let users tune the maximum size of
+ the cache in number of entries.
Release 2.7 (2015-01-28)
------------------------
diff --git a/cache.c b/cache.c
index 86978c7..5a5af89 100644
--- a/cache.c
+++ b/cache.c
@@ -15,7 +15,7 @@
#include <pthread.h>
#define DEFAULT_CACHE_TIMEOUT_SECS 20
-#define MAX_CACHE_SIZE 10000
+#define DEFAULT_MAX_CACHE_SIZE 10000
#define MIN_CACHE_CLEAN_INTERVAL 5
#define CACHE_CLEAN_INTERVAL 60
@@ -24,6 +24,7 @@ struct cache {
unsigned stat_timeout_secs;
unsigned dir_timeout_secs;
unsigned link_timeout_secs;
+ unsigned max_size;
struct fuse_cache_operations *next_oper;
GHashTable *table;
pthread_mutex_t lock;
@@ -71,7 +72,7 @@ static void cache_clean(void)
{
time_t now = time(NULL);
if (now > cache.last_cleaned + MIN_CACHE_CLEAN_INTERVAL &&
- (g_hash_table_size(cache.table) > MAX_CACHE_SIZE ||
+ (g_hash_table_size(cache.table) > cache.max_size ||
now > cache.last_cleaned + CACHE_CLEAN_INTERVAL)) {
g_hash_table_foreach_remove(cache.table,
(GHRFunc) cache_clean_entry, &now);
@@ -576,6 +577,7 @@ static const struct fuse_opt cache_opts[] = {
{ "cache_stat_timeout=%u", offsetof(struct cache, stat_timeout_secs), 0 },
{ "cache_dir_timeout=%u", offsetof(struct cache, dir_timeout_secs), 0 },
{ "cache_link_timeout=%u", offsetof(struct cache, link_timeout_secs), 0 },
+ { "cache_max_size=%u", offsetof(struct cache, max_size), 0 },
FUSE_OPT_END
};
@@ -584,6 +586,7 @@ int cache_parse_options(struct fuse_args *args)
cache.stat_timeout_secs = DEFAULT_CACHE_TIMEOUT_SECS;
cache.dir_timeout_secs = DEFAULT_CACHE_TIMEOUT_SECS;
cache.link_timeout_secs = DEFAULT_CACHE_TIMEOUT_SECS;
+ cache.max_size = DEFAULT_MAX_CACHE_SIZE;
cache.on = 1;
return fuse_opt_parse(args, &cache, cache_opts, NULL);
diff --git a/sshfs.c b/sshfs.c
index 84b2359..b010828 100644
--- a/sshfs.c
+++ b/sshfs.c
@@ -3377,6 +3377,7 @@ static void usage(const char *progname)
" -o sync_readdir synchronous readdir\n"
" -o sshfs_debug print some debugging information\n"
" -o cache=BOOL enable caching {yes,no} (default: yes)\n"
+" -o cache_max_size=N sets the maximum size of the cache (default: 10000)\n"
" -o cache_timeout=N sets timeout for caches in seconds (default: 20)\n"
" -o cache_X_timeout=N sets timeout for {stat,dir,link} cache\n"
" -o workaround=LIST colon separated list of workarounds\n"