From d1ddbbcae51f8004e38971fb3546ed5c98effd8b Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Wed, 27 Jan 2016 11:00:37 -0500 Subject: Qualify timeout identifiers with their unit All timeouts are in seconds, so add a suffix to the identifier names to clearly denote the unit. --- cache.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cache.c b/cache.c index 6e93157..86978c7 100644 --- a/cache.c +++ b/cache.c @@ -14,16 +14,16 @@ #include #include -#define DEFAULT_CACHE_TIMEOUT 20 +#define DEFAULT_CACHE_TIMEOUT_SECS 20 #define MAX_CACHE_SIZE 10000 #define MIN_CACHE_CLEAN_INTERVAL 5 #define CACHE_CLEAN_INTERVAL 60 struct cache { int on; - unsigned stat_timeout; - unsigned dir_timeout; - unsigned link_timeout; + unsigned stat_timeout_secs; + unsigned dir_timeout_secs; + unsigned link_timeout_secs; struct fuse_cache_operations *next_oper; GHashTable *table; pthread_mutex_t lock; @@ -172,7 +172,7 @@ void cache_add_attr(const char *path, const struct stat *stbuf, uint64_t wrctr) if (wrctr == cache.write_ctr) { node = cache_get(path); node->stat = *stbuf; - node->stat_valid = time(NULL) + cache.stat_timeout; + node->stat_valid = time(NULL) + cache.stat_timeout_secs; if (node->stat_valid > node->valid) node->valid = node->stat_valid; cache_clean(); @@ -188,7 +188,7 @@ static void cache_add_dir(const char *path, char **dir) node = cache_get(path); g_strfreev(node->dir); node->dir = dir; - node->dir_valid = time(NULL) + cache.dir_timeout; + node->dir_valid = time(NULL) + cache.dir_timeout_secs; if (node->dir_valid > node->valid) node->valid = node->dir_valid; cache_clean(); @@ -210,7 +210,7 @@ static void cache_add_link(const char *path, const char *link, size_t size) node = cache_get(path); g_free(node->link); node->link = g_strndup(link, my_strnlen(link, size-1)); - node->link_valid = time(NULL) + cache.link_timeout; + node->link_valid = time(NULL) + cache.link_timeout_secs; if (node->link_valid > node->valid) node->valid = node->link_valid; cache_clean(); @@ -570,20 +570,20 @@ struct fuse_operations *cache_init(struct fuse_cache_operations *oper) static const struct fuse_opt cache_opts[] = { { "cache=yes", offsetof(struct cache, on), 1 }, { "cache=no", offsetof(struct cache, on), 0 }, - { "cache_timeout=%u", offsetof(struct cache, stat_timeout), 0 }, - { "cache_timeout=%u", offsetof(struct cache, dir_timeout), 0 }, - { "cache_timeout=%u", offsetof(struct cache, link_timeout), 0 }, - { "cache_stat_timeout=%u", offsetof(struct cache, stat_timeout), 0 }, - { "cache_dir_timeout=%u", offsetof(struct cache, dir_timeout), 0 }, - { "cache_link_timeout=%u", offsetof(struct cache, link_timeout), 0 }, + { "cache_timeout=%u", offsetof(struct cache, stat_timeout_secs), 0 }, + { "cache_timeout=%u", offsetof(struct cache, dir_timeout_secs), 0 }, + { "cache_timeout=%u", offsetof(struct cache, link_timeout_secs), 0 }, + { "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 }, FUSE_OPT_END }; int cache_parse_options(struct fuse_args *args) { - cache.stat_timeout = DEFAULT_CACHE_TIMEOUT; - cache.dir_timeout = DEFAULT_CACHE_TIMEOUT; - cache.link_timeout = DEFAULT_CACHE_TIMEOUT; + 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.on = 1; return fuse_opt_parse(args, &cache, cache_opts, NULL); -- cgit v1.2.3 From ebfeebd468551fa5e024b36dd218042cc5b7597e Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Wed, 27 Jan 2016 11:07:19 -0500 Subject: 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. --- ChangeLog | 2 ++ cache.c | 7 +++++-- sshfs.c | 1 + 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 #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" -- cgit v1.2.3 From c1e799b4da8418d907f45f5cf3928afe491040ac Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Wed, 27 Jan 2016 11:17:15 -0500 Subject: Expose the cache clean interval settings as flags Allow the user to customize the cache regular and minimum clean intervals as flags via the new cache_clean_interval and cache_min_clean_interval options. While doing this, rename the internal variables and constants to suffix them with their unit (seconds). --- ChangeLog | 2 ++ cache.c | 16 ++++++++++++---- sshfs.c | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 066f553..f788ade 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ Draft notes for upcoming release 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. +* Added -o cache_clean_interval=N and -o cache_min_clean_interval=N + options to let users tune the cleaning behavior of the cache. Release 2.7 (2015-01-28) ------------------------ diff --git a/cache.c b/cache.c index 5a5af89..96f7603 100644 --- a/cache.c +++ b/cache.c @@ -16,8 +16,8 @@ #define DEFAULT_CACHE_TIMEOUT_SECS 20 #define DEFAULT_MAX_CACHE_SIZE 10000 -#define MIN_CACHE_CLEAN_INTERVAL 5 -#define CACHE_CLEAN_INTERVAL 60 +#define DEFAULT_CACHE_CLEAN_INTERVAL_SECS 60 +#define DEFAULT_MIN_CACHE_CLEAN_INTERVAL_SECS 5 struct cache { int on; @@ -25,6 +25,8 @@ struct cache { unsigned dir_timeout_secs; unsigned link_timeout_secs; unsigned max_size; + unsigned clean_interval_secs; + unsigned min_clean_interval_secs; struct fuse_cache_operations *next_oper; GHashTable *table; pthread_mutex_t lock; @@ -71,9 +73,9 @@ static int cache_clean_entry(void *key_, struct node *node, time_t *now) static void cache_clean(void) { time_t now = time(NULL); - if (now > cache.last_cleaned + MIN_CACHE_CLEAN_INTERVAL && + if (now > cache.last_cleaned + cache.min_clean_interval_secs && (g_hash_table_size(cache.table) > cache.max_size || - now > cache.last_cleaned + CACHE_CLEAN_INTERVAL)) { + now > cache.last_cleaned + cache.clean_interval_secs)) { g_hash_table_foreach_remove(cache.table, (GHRFunc) cache_clean_entry, &now); cache.last_cleaned = now; @@ -578,6 +580,10 @@ static const struct fuse_opt cache_opts[] = { { "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 }, + { "cache_clean_interval=%u", offsetof(struct cache, + clean_interval_secs), 0 }, + { "cache_min_clean_interval=%u", offsetof(struct cache, + min_clean_interval_secs), 0 }, FUSE_OPT_END }; @@ -587,6 +593,8 @@ int cache_parse_options(struct fuse_args *args) cache.dir_timeout_secs = DEFAULT_CACHE_TIMEOUT_SECS; cache.link_timeout_secs = DEFAULT_CACHE_TIMEOUT_SECS; cache.max_size = DEFAULT_MAX_CACHE_SIZE; + cache.clean_interval_secs = DEFAULT_CACHE_CLEAN_INTERVAL_SECS; + cache.min_clean_interval_secs = DEFAULT_MIN_CACHE_CLEAN_INTERVAL_SECS; cache.on = 1; return fuse_opt_parse(args, &cache, cache_opts, NULL); diff --git a/sshfs.c b/sshfs.c index b010828..ce30a0f 100644 --- a/sshfs.c +++ b/sshfs.c @@ -3380,6 +3380,12 @@ static void usage(const char *progname) " -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 cache_clean_interval=N\n" +" sets the interval for automatic cleaning of the\n" +" cache (default: 60)\n" +" -o cache_min_clean_interval=N\n" +" sets the interval for forced cleaning of the\n" +" cache if full (default: 5)\n" " -o workaround=LIST colon separated list of workarounds\n" " none no workarounds enabled\n" " all all workarounds enabled\n" -- cgit v1.2.3 From 391f6767050cce2d34e7d556566c0abd02510854 Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Wed, 27 Jan 2016 15:47:54 -0500 Subject: Explicitly qualify unsigned as unsigned int --- cache.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cache.c b/cache.c index 96f7603..aeb14ec 100644 --- a/cache.c +++ b/cache.c @@ -21,12 +21,12 @@ struct cache { int on; - unsigned stat_timeout_secs; - unsigned dir_timeout_secs; - unsigned link_timeout_secs; - unsigned max_size; - unsigned clean_interval_secs; - unsigned min_clean_interval_secs; + unsigned int stat_timeout_secs; + unsigned int dir_timeout_secs; + unsigned int link_timeout_secs; + unsigned int max_size; + unsigned int clean_interval_secs; + unsigned int min_clean_interval_secs; struct fuse_cache_operations *next_oper; GHashTable *table; pthread_mutex_t lock; -- cgit v1.2.3