aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sunrpc/cache.h
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2010-08-12 02:55:22 -0400
committerJ. Bruce Fields <bfields@redhat.com>2010-09-07 19:21:20 -0400
commitc5b29f885afe890f953f7f23424045cdad31d3e4 (patch)
treecc2016f256da966974b4ed7a24ff9378a77facb2 /include/linux/sunrpc/cache.h
parent17cebf658e088935d4bdebfc7ad9800e9fc4a0b2 (diff)
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.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 0e1febf4e5b..ece432b7f87 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)
218 return 0; 218 return 0;
219} 219}
220 220
221/*
222 * timestamps kept in the cache are expressed in seconds
223 * since boot. This is the best for measuring differences in
224 * real time.
225 */
226static inline time_t seconds_since_boot(void)
227{
228 struct timespec boot;
229 getboottime(&boot);
230 return get_seconds() - boot.tv_sec;
231}
232
233static inline time_t convert_to_wallclock(time_t sinceboot)
234{
235 struct timespec boot;
236 getboottime(&boot);
237 return boot.tv_sec + sinceboot;
238}
239
221static inline time_t get_expiry(char **bpp) 240static inline time_t get_expiry(char **bpp)
222{ 241{
223 int rv; 242 int rv;
243 struct timespec boot;
244
224 if (get_int(bpp, &rv)) 245 if (get_int(bpp, &rv))
225 return 0; 246 return 0;
226 if (rv < 0) 247 if (rv < 0)
227 return 0; 248 return 0;
228 return rv; 249 getboottime(&boot);
250 return rv - boot.tv_sec;
229} 251}
230 252
231static inline void sunrpc_invalidate(struct cache_head *h, 253static inline void sunrpc_invalidate(struct cache_head *h,
232 struct cache_detail *detail) 254 struct cache_detail *detail)
233{ 255{
234 h->expiry_time = get_seconds() - 1; 256 h->expiry_time = seconds_since_boot() - 1;
235 detail->nextcheck = get_seconds(); 257 detail->nextcheck = seconds_since_boot();
236} 258}
237#endif /* _LINUX_SUNRPC_CACHE_H_ */ 259#endif /* _LINUX_SUNRPC_CACHE_H_ */