提交 7715cde8 编写于 作者: N NeilBrown 提交者: J. Bruce Fields

net/sunrpc: xpt_auth_cache should be ignored when expired.

commit d202cce8
    sunrpc: never return expired entries in sunrpc_cache_lookup

moved the 'entry is expired' test from cache_check to
sunrpc_cache_lookup, so that it happened early and some races could
safely be ignored.

However the ip_map (in svcauth_unix.c) has a separate single-item
cache which allows quick lookup without locking.  An entry in this
case would not be subject to the expiry test and so could be used
well after it has expired.

This is not normally a big problem because the first time it is used
after it is expired an up-call will be scheduled to refresh the entry
(if it hasn't been scheduled already) and the old entry will then
be invalidated.  So on the second attempt to use it after it has
expired, ip_map_cached_get will discard it.

However that is subtle and not ideal, so replace the "!cache_valid"
test with "cache_is_expired".
In doing this we drop the test on the "CACHE_VALID" bit.  This is
unnecessary as the bit is never cleared, and an entry will only
be cached if the bit is set.
Reported-by: NBodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: NNeilBrown <neilb@suse.de>
Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
上级 013920eb
...@@ -149,6 +149,24 @@ struct cache_deferred_req { ...@@ -149,6 +149,24 @@ struct cache_deferred_req {
int too_many); int too_many);
}; };
/*
* 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;
}
extern const struct file_operations cache_file_operations_pipefs; extern const struct file_operations cache_file_operations_pipefs;
extern const struct file_operations content_file_operations_pipefs; extern const struct file_operations content_file_operations_pipefs;
...@@ -182,15 +200,10 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd) ...@@ -182,15 +200,10 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
kref_put(&h->ref, cd->cache_put); kref_put(&h->ref, cd->cache_put);
} }
static inline int cache_valid(struct cache_head *h) static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{ {
/* If an item has been unhashed pending removal when return (h->expiry_time < seconds_since_boot()) ||
* the refcount drops to 0, the expiry_time will be (detail->flush_time > h->last_refresh);
* set to 0. We don't want to consider such items
* valid in this context even though CACHE_VALID is
* set.
*/
return (h->expiry_time != 0 && test_bit(CACHE_VALID, &h->flags));
} }
extern int cache_check(struct cache_detail *detail, extern int cache_check(struct cache_detail *detail,
...@@ -251,25 +264,6 @@ static inline int get_uint(char **bpp, unsigned int *anint) ...@@ -251,25 +264,6 @@ static inline int get_uint(char **bpp, unsigned int *anint)
return 0; 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) static inline time_t get_expiry(char **bpp)
{ {
int rv; int rv;
......
...@@ -50,12 +50,6 @@ static void cache_init(struct cache_head *h) ...@@ -50,12 +50,6 @@ static void cache_init(struct cache_head *h)
h->last_refresh = now; h->last_refresh = now;
} }
static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{
return (h->expiry_time < seconds_since_boot()) ||
(detail->flush_time > h->last_refresh);
}
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash) struct cache_head *key, int hash)
{ {
......
...@@ -347,13 +347,13 @@ ip_map_cached_get(struct svc_xprt *xprt) ...@@ -347,13 +347,13 @@ ip_map_cached_get(struct svc_xprt *xprt)
spin_lock(&xprt->xpt_lock); spin_lock(&xprt->xpt_lock);
ipm = xprt->xpt_auth_cache; ipm = xprt->xpt_auth_cache;
if (ipm != NULL) { if (ipm != NULL) {
if (!cache_valid(&ipm->h)) { sn = net_generic(xprt->xpt_net, sunrpc_net_id);
if (cache_is_expired(sn->ip_map_cache, &ipm->h)) {
/* /*
* The entry has been invalidated since it was * The entry has been invalidated since it was
* remembered, e.g. by a second mount from the * remembered, e.g. by a second mount from the
* same IP address. * same IP address.
*/ */
sn = net_generic(xprt->xpt_net, sunrpc_net_id);
xprt->xpt_auth_cache = NULL; xprt->xpt_auth_cache = NULL;
spin_unlock(&xprt->xpt_lock); spin_unlock(&xprt->xpt_lock);
cache_put(&ipm->h, sn->ip_map_cache); cache_put(&ipm->h, sn->ip_map_cache);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册