Skip to contentSkip to conversation

kNFSd - 3 of 8 - Include update mode in declaration of RPC information caches.

PATCH New NeilBrown 1 participant 1 message Jun 24, 2003

Subsystems (3)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 kNFSd - 3 of 8 - Include update mode in declaration of RPC information caches.

### Comments for ChangeSet

The sunrpc/cache.c caches which store nfsd export information can be updated either "inplace" or by replacing the entry.

replacement is needed when an entry hold a reference to some other object, so the reference counts work properly.

"inplace" can be used when no such references are held, and should be used when the object could be refered to by another cache (as otherwise the other cache would have to be updated whenever this one is).

Previously the type of update (inplace or replace) was specified as an argument to the *_lookup operation. This too easily lead to inconsistancies.

With this patch, the update mode is specified when the cache is declared.

----------- Diffstat output ------------

 ./fs/nfsd/export.c             |    8 ++++----
 ./include/linux/sunrpc/cache.h |   13 +++++++------
 ./net/sunrpc/svcauth.c         |    3 ++-
 ./net/sunrpc/svcauth_unix.c    |    2 +-
 4 files changed, 14 insertions(+), 12 deletions(-)
fs/nfsd/export.c renamed from fs/nfsd/export.c~current~ +4 -4
diff ./fs/nfsd/export.c~current~ ./fs/nfsd/export.c
@@ -156,7 +156,7 @@ int expkey_parse(struct cache_detail *cd
 	if (len == 0) {
 		struct svc_expkey *ek;
 		set_bit(CACHE_NEGATIVE, &key.h.flags);
-		ek = svc_expkey_lookup(&key, 2);
+		ek = svc_expkey_lookup(&key, 1);
 		if (ek)
 			expkey_put(&ek->h, &svc_expkey_cache);
 	} else {
@@ -176,7 +176,7 @@ int expkey_parse(struct cache_detail *cd
 		key.ek_export = exp;
 		dprintk("And found export\n");
 		
-		ek = svc_expkey_lookup(&key, 2);
+		ek = svc_expkey_lookup(&key, 1);
 		if (ek)
 			expkey_put(&ek->h, &svc_expkey_cache);
 		exp_put(exp);
@@ -231,7 +231,7 @@ static inline void svc_expkey_update(str
 	new->ek_export = item->ek_export;
 }
 
-static DefineSimpleCacheLookup(svc_expkey)
+static DefineSimpleCacheLookup(svc_expkey,0) /* no inplace updates */
 
 #define	EXPORT_HASHBITS		8
 #define	EXPORT_HASHMAX		(1<< EXPORT_HASHBITS)
@@ -438,7 +438,7 @@ static inline void svc_export_update(str
 	new->ex_fsid = item->ex_fsid;
 }
 
-static DefineSimpleCacheLookup(svc_export)
+static DefineSimpleCacheLookup(svc_export,1) /* allow inplace updates */
 
 
 struct svc_expkey *
include/linux/sunrpc/cache.h renamed from include/linux/sunrpc/cache.h~current~ +7 -6
diff ./include/linux/sunrpc/cache.h~current~ ./include/linux/sunrpc/cache.h
@@ -155,8 +155,9 @@ struct cache_deferred_req {
  * TEST  tests if "tmp" matches "item"
  * INIT copies key information from "item" to "new"
  * UPDATE copies content information from "item" to "tmp"
+ * INPLACE is true if updates can happen inplace rather than allocating a new structure
  */
-#define DefineCacheLookup(RTN,MEMBER,FNAME,ARGS,SETUP,DETAIL,HASHFN,TEST,INIT,UPDATE)	\
+#define DefineCacheLookup(RTN,MEMBER,FNAME,ARGS,SETUP,DETAIL,HASHFN,TEST,INIT,UPDATE,INPLACE)	\
 RTN *FNAME ARGS										\
 {											\
 	RTN *tmp, *new=NULL;								\
@@ -170,12 +171,12 @@ RTN *FNAME ARGS										\
 		tmp = container_of(*hp, RTN, MEMBER);					\
 		if (TEST) { /* found a match */						\
 											\
-			if (set == 1 && test_bit(CACHE_VALID, &tmp->MEMBER.flags) && !new) \
+			if (set && !INPLACE && test_bit(CACHE_VALID, &tmp->MEMBER.flags) && !new) \
 				break;							\
 											\
 			atomic_inc(&tmp->MEMBER.refcnt);				\
 			if (set) {							\
-				if (set == 1 && test_bit(CACHE_VALID, &tmp->MEMBER.flags))\
+				if (!INPLACE && test_bit(CACHE_VALID, &tmp->MEMBER.flags))\
 				{ /* need to swap in new */				\
 					RTN *t2;					\
 											\
@@ -194,7 +195,7 @@ RTN *FNAME ARGS										\
 			else read_unlock(&(DETAIL)->hash_lock);				\
 			if (set)							\
 				cache_fresh(DETAIL, &tmp->MEMBER, item->MEMBER.expiry_time); \
-			if (set==1 && new) cache_fresh(DETAIL, &new->MEMBER, 0);	\
+			if (set && !INPLACE && new) cache_fresh(DETAIL, &new->MEMBER, 0);	\
 			if (new) (DETAIL)->cache_put(&new->MEMBER, DETAIL);		\
 			return tmp;							\
 		}									\
@@ -229,10 +230,10 @@ RTN *FNAME ARGS										\
 	return NULL;									\
 }
 
-#define DefineSimpleCacheLookup(STRUCT)	\
+#define DefineSimpleCacheLookup(STRUCT,INPLACE)	\
 	DefineCacheLookup(struct STRUCT, h, STRUCT##_lookup, (struct STRUCT *item, int set), /*no setup */,	\
 			  & STRUCT##_cache, STRUCT##_hash(item), STRUCT##_match(item, tmp),\
-			  STRUCT##_init(new, item), STRUCT##_update(tmp, item))
+			  STRUCT##_init(new, item), STRUCT##_update(tmp, item),INPLACE)
 
 #define cache_for_each(pos, detail, index, member) 						\
 	for (({read_lock(&(detail)->hash_lock); index = (detail)->hash_size;}) ;		\
net/sunrpc/svcauth.c renamed from net/sunrpc/svcauth.c~current~ +2 -1
diff ./net/sunrpc/svcauth.c~current~ ./net/sunrpc/svcauth.c
@@ -152,7 +152,8 @@ DefineCacheLookup(struct auth_domain,
 		  auth_domain_match(tmp, item),
 		  kfree(new); if(!set) return NULL;
 		  new=item; atomic_inc(&new->h.refcnt),
-		  /* no update */
+		  /* no update */,
+		  0 /* no inplace updates */
 		  )
 
 struct auth_domain *auth_domain_find(char *name)
net/sunrpc/svcauth_unix.c renamed from net/sunrpc/svcauth_unix.c~current~ +1 -1
diff ./net/sunrpc/svcauth_unix.c~current~ ./net/sunrpc/svcauth_unix.c
@@ -250,7 +250,7 @@ struct cache_detail ip_map_cache = {
 	.cache_show	= ip_map_show,
 };
 
-static DefineSimpleCacheLookup(ip_map)
+static DefineSimpleCacheLookup(ip_map, 0)
 
 
 int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)

-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs