diff options
author | NeilBrown <neilb@suse.de> | 2010-08-12 16:55:22 +1000 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2010-09-07 19:21:20 -0400 |
commit | c5b29f885afe890f953f7f23424045cdad31d3e4 (patch) | |
tree | cc2016f256da966974b4ed7a24ff9378a77facb2 /include/linux/sunrpc/cache.h | |
parent | 17cebf658e088935d4bdebfc7ad9800e9fc4a0b2 (diff) | |
download | linux-c5b29f885afe890f953f7f23424045cdad31d3e4.tar.gz linux-c5b29f885afe890f953f7f23424045cdad31d3e4.tar.bz2 linux-c5b29f885afe890f953f7f23424045cdad31d3e4.zip |
sunrpc: use seconds since boot in expiry cache
This protects us from confusion when the wallclock time changes.
We convert to and from wallclock when setting or reading expiry
times.
Also use seconds since boot for last_clost time.
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'include/linux/sunrpc/cache.h')
-rw-r--r-- | include/linux/sunrpc/cache.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 0e1febf4e5bc..ece432b7f87f 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -218,20 +218,42 @@ static inline int get_int(char **bpp, int *anint) return 0; } +/* + * timestamps kept in the cache are expressed in seconds + * since boot. This is the best for measuring differences in + * real time. + */ +static inline time_t seconds_since_boot(void) +{ + struct timespec boot; + getboottime(&boot); + return get_seconds() - boot.tv_sec; +} + +static inline time_t convert_to_wallclock(time_t sinceboot) +{ + struct timespec boot; + getboottime(&boot); + return boot.tv_sec + sinceboot; +} + static inline time_t get_expiry(char **bpp) { int rv; + struct timespec boot; + if (get_int(bpp, &rv)) return 0; if (rv < 0) return 0; - return rv; + getboottime(&boot); + return rv - boot.tv_sec; } static inline void sunrpc_invalidate(struct cache_head *h, struct cache_detail *detail) { - h->expiry_time = get_seconds() - 1; - detail->nextcheck = get_seconds(); + h->expiry_time = seconds_since_boot() - 1; + detail->nextcheck = seconds_since_boot(); } #endif /* _LINUX_SUNRPC_CACHE_H_ */ |