public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: nfs@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [PATCH 013 of 14] knfsd: Unexport cache_fresh and fix a small race.
Date: Thu, 9 Mar 2006 17:52:29 +1100	[thread overview]
Message-ID: <1060309065229.24678@suse.de> (raw)
In-Reply-To: 20060309174755.24381.patches@notabene


Cache_fresh is now only used in cache.c, so unexport it.

Part of cache_fresh (setting CACHE_VALID) should really be done under the
lock, while part (calling cache_revisit_request etc) must be done outside
the lock.  So we split it up appropriately.

Signed-off-by: Neil Brown <neilb@suse.de>

### Diffstat output
 ./include/linux/sunrpc/cache.h |    2 -
 ./net/sunrpc/cache.c           |   51 ++++++++++++++++++++++++-----------------
 ./net/sunrpc/sunrpc_syms.c     |    1 
 3 files changed, 30 insertions(+), 24 deletions(-)

diff ./include/linux/sunrpc/cache.h~current~ ./include/linux/sunrpc/cache.h
--- ./include/linux/sunrpc/cache.h~current~	2006-03-09 17:41:52.000000000 +1100
+++ ./include/linux/sunrpc/cache.h	2006-03-09 17:33:29.000000000 +1100
@@ -165,8 +165,6 @@ static inline int cache_put(struct cache
 }
 
 extern void cache_init(struct cache_head *h);
-extern void cache_fresh(struct cache_detail *detail,
-			struct cache_head *head, time_t expiry);
 extern int cache_check(struct cache_detail *detail,
 		       struct cache_head *h, struct cache_req *rqstp);
 extern void cache_flush(void);

diff ./net/sunrpc/cache.c~current~ ./net/sunrpc/cache.c
--- ./net/sunrpc/cache.c~current~	2006-03-09 17:41:52.000000000 +1100
+++ ./net/sunrpc/cache.c	2006-03-09 17:45:46.000000000 +1100
@@ -96,6 +96,27 @@ struct cache_head *sunrpc_cache_lookup(s
 }
 EXPORT_SYMBOL(sunrpc_cache_lookup);
 
+
+static void queue_loose(struct cache_detail *detail, struct cache_head *ch);
+
+static int cache_fresh_locked(struct cache_head *head, time_t expiry)
+{
+	head->expiry_time = expiry;
+	head->last_refresh = get_seconds();
+	return !test_and_set_bit(CACHE_VALID, &head->flags);
+}
+
+static void cache_fresh_unlocked(struct cache_head *head,
+			struct cache_detail *detail, int new)
+{
+	if (new)
+		cache_revisit_request(head);
+	if (test_and_clear_bit(CACHE_PENDING, &head->flags)) {
+		cache_revisit_request(head);
+		queue_loose(detail, head);
+	}
+}
+
 struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
 				       struct cache_head *new, struct cache_head *old, int hash)
 {
@@ -105,6 +126,7 @@ struct cache_head *sunrpc_cache_update(s
 	 */
 	struct cache_head **head;
 	struct cache_head *tmp;
+	int is_new;
 
 	if (!test_bit(CACHE_VALID, &old->flags)) {
 		write_lock(&detail->hash_lock);
@@ -113,9 +135,9 @@ struct cache_head *sunrpc_cache_update(s
 				set_bit(CACHE_NEGATIVE, &old->flags);
 			else
 				detail->update(old, new);
-			/* FIXME cache_fresh should come first */
+			is_new = cache_fresh_locked(old, new->expiry_time);
 			write_unlock(&detail->hash_lock);
-			cache_fresh(detail, old, new->expiry_time);
+			cache_fresh_unlocked(old, detail, is_new);
 			return old;
 		}
 		write_unlock(&detail->hash_lock);
@@ -138,9 +160,11 @@ struct cache_head *sunrpc_cache_update(s
 	tmp->next = *head;
 	*head = tmp;
 	cache_get(tmp);
+	is_new = cache_fresh_locked(tmp, new->expiry_time);
+	cache_fresh_locked(old, 0);
 	write_unlock(&detail->hash_lock);
-	cache_fresh(detail, tmp, new->expiry_time);
-	cache_fresh(detail, old, 0);
+	cache_fresh_unlocked(tmp, detail, is_new);
+	cache_fresh_unlocked(old, detail, 0);
 	detail->cache_put(old, detail);
 	return tmp;
 }
@@ -192,7 +216,8 @@ int cache_check(struct cache_detail *det
 				clear_bit(CACHE_PENDING, &h->flags);
 				if (rv == -EAGAIN) {
 					set_bit(CACHE_NEGATIVE, &h->flags);
-					cache_fresh(detail, h, get_seconds()+CACHE_NEW_EXPIRY);
+					cache_fresh_unlocked(h, detail,
+					     cache_fresh_locked(h, get_seconds()+CACHE_NEW_EXPIRY));
 					rv = -ENOENT;
 				}
 				break;
@@ -213,22 +238,6 @@ int cache_check(struct cache_detail *det
 	return rv;
 }
 
-static void queue_loose(struct cache_detail *detail, struct cache_head *ch);
-
-void cache_fresh(struct cache_detail *detail,
-		 struct cache_head *head, time_t expiry)
-{
-
-	head->expiry_time = expiry;
-	head->last_refresh = get_seconds();
-	if (!test_and_set_bit(CACHE_VALID, &head->flags))
-		cache_revisit_request(head);
-	if (test_and_clear_bit(CACHE_PENDING, &head->flags)) {
-		cache_revisit_request(head);
-		queue_loose(detail, head);
-	}
-}
-
 /*
  * caches need to be periodically cleaned.
  * For this we maintain a list of cache_detail and

diff ./net/sunrpc/sunrpc_syms.c~current~ ./net/sunrpc/sunrpc_syms.c
--- ./net/sunrpc/sunrpc_syms.c~current~	2006-03-09 17:41:52.000000000 +1100
+++ ./net/sunrpc/sunrpc_syms.c	2006-03-09 17:33:47.000000000 +1100
@@ -105,7 +105,6 @@ EXPORT_SYMBOL(auth_unix_lookup);
 EXPORT_SYMBOL(cache_check);
 EXPORT_SYMBOL(cache_flush);
 EXPORT_SYMBOL(cache_purge);
-EXPORT_SYMBOL(cache_fresh);
 EXPORT_SYMBOL(cache_init);
 EXPORT_SYMBOL(cache_register);
 EXPORT_SYMBOL(cache_unregister);

  parent reply	other threads:[~2006-03-09  6:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-09  6:51 [PATCH 000 of 14] knfsd: Introduction NeilBrown
2006-03-09  6:51 ` [PATCH 001 of 14] knfsd: Change the store of auth_domains to not be a 'cache' NeilBrown
2006-03-09 16:26   ` Paul Dickson
2006-03-09  6:51 ` [PATCH 002 of 14] knfsd: Break the hard linkage from svc_expkey to svc_export NeilBrown
2006-03-09  6:51 ` [PATCH 003 of 14] knfsd: Get rid of 'inplace' sunrpc caches NeilBrown
2006-03-09  6:51 ` [PATCH 004 of 14] knfsd: Create cache_lookup function instead of using a macro to declare one NeilBrown
2006-03-09  6:51 ` [PATCH 005 of 14] knfsd: Convert ip_map cache to use the new lookup routine NeilBrown
2006-03-09  6:51 ` [PATCH 006 of 14] knfsd: Use new cache_lookup for svc_export NeilBrown
2006-03-09  6:51 ` [PATCH 007 of 14] knfsd: Use new cache_lookup for svc_expkey cache NeilBrown
2006-03-09  6:52 ` [PATCH 008 of 14] knfsd: Use new sunrpc cache for rsi cache NeilBrown
2006-03-09  6:52 ` [PATCH 009 of 14] knfsd: Use new cache code for rsc cache NeilBrown
2006-03-09  6:52 ` [PATCH 010 of 14] knfsd: Use new cache code for name/id lookup caches NeilBrown
2006-03-09  6:52 ` [PATCH 011 of 14] knfsd: An assortment of little fixes to the sunrpc cache code NeilBrown
2006-03-09  6:52 ` [PATCH 012 of 14] knfsd: Remove DefineCacheLookup NeilBrown
2006-03-09  6:52 ` NeilBrown [this message]
2006-03-09  6:52 ` [PATCH 014 of 14] knfsd: Convert sunrpc_cache to use krefs NeilBrown
2006-03-09 17:10 ` [PATCH 000 of 14] knfsd: Introduction Trond Myklebust
2006-03-10  0:54   ` Neil Brown
2006-03-13 11:41 ` [NFS] " Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1060309065229.24678@suse.de \
    --to=neilb@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nfs@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox