All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kNFSd - 5 of 4 - Allow sunrpc/svc cache init function to modify the "key"
@ 2003-11-21  4:07 NeilBrown
  0 siblings, 0 replies; only message in thread
From: NeilBrown @ 2003-11-21  4:07 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: nfs

This patch contains the 'infrastructure' that goes with patch 3 to fix the
'kmalloc failure not checked for' bug.

NeilBroown

### Comments for ChangeSet

When adding a item to a sunrpc/svc cache that contains kmalloced
data it is usefully to move the malloced data out of the key object
into the new cache object rather than copying (as then we would need to
cope with kmalloc failure and such).  This means modifying the original.

If the kmalloced data forms part of the key, then we must not move the data out until 
after the key isn't needed any more.  So this patch moves the call to "INIT" on a
new item (which fills in the key) to *after* the item has been found (or not), and
also makes sure we only call the HASH function once.
Thanks to  "J. Bruce Fields" <bfields@fieldses.org>

also

 1/ remove unnecessary assignment
 2/ fix comments that lag behind implementation.

 ----------- Diffstat output ------------
 ./include/linux/sunrpc/cache.h |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff ./include/linux/sunrpc/cache.h~current~ ./include/linux/sunrpc/cache.h
--- ./include/linux/sunrpc/cache.h~current~	2003-11-21 15:01:48.000000000 +1100
+++ ./include/linux/sunrpc/cache.h	2003-11-21 15:04:44.000000000 +1100
@@ -130,12 +130,14 @@ struct cache_deferred_req {
  * If "set" == 0 :
  *    If an entry is found, it is returned
  *    If no entry is found, a new non-VALID entry is created.
- * If "set" == 1 :
+ * If "set" == 1 and INPLACE == 0 :
  *    If no entry is found a new one is inserted with data from "template"
  *    If a non-CACHE_VALID entry is found, it is updated from template using UPDATE
  *    If a CACHE_VALID entry is found, a new entry is swapped in with data
  *       from "template"
- * If set == 2, we UPDATE, but don't swap. i.e. update in place
+ * If set == 1, and INPLACE == 1 :
+ *    As above, except that if a CACHE_VALID entry is found, we UPDATE in place
+ *       instead of swapping in a new entry.
  *
  * If the passed handle has the CACHE_NEGATIVE flag set, then UPDATE is not
  * run but insteead CACHE_NEGATIVE is set in any new item.
@@ -162,8 +164,8 @@ RTN *FNAME ARGS										\
 	RTN *tmp, *new=NULL;								\
 	struct cache_head **hp, **head;							\
 	SETUP;										\
- retry:											\
 	head = &(DETAIL)->hash_table[HASHFN];						\
+ retry:											\
 	if (set||new) write_lock(&(DETAIL)->hash_lock);					\
 	else read_lock(&(DETAIL)->hash_lock);						\
 	for(hp=head; *hp != NULL; hp = &tmp->MEMBER.next) {				\
@@ -173,6 +175,8 @@ RTN *FNAME ARGS										\
 			if (set && !INPLACE && test_bit(CACHE_VALID, &tmp->MEMBER.flags) && !new) \
 				break;							\
 											\
+			if (new)							\
+				 {INIT;}						\
 			cache_get(&tmp->MEMBER);					\
 			if (set) {							\
 				if (!INPLACE && test_bit(CACHE_VALID, &tmp->MEMBER.flags))\
@@ -201,6 +205,7 @@ RTN *FNAME ARGS										\
 	}										\
 	/* Didn't find anything */							\
 	if (new) {									\
+		INIT;									\
 		new->MEMBER.next = *head;						\
 		*head = &new->MEMBER;							\
 		(DETAIL)->entries ++;							\
@@ -222,8 +227,6 @@ RTN *FNAME ARGS										\
 	if (new) {									\
 		cache_init(&new->MEMBER);						\
 		cache_get(&new->MEMBER);						\
-		INIT;									\
-		tmp = new;								\
 		goto retry;								\
 	}										\
 	return NULL;									\


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-11-21  4:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-21  4:07 [PATCH] kNFSd - 5 of 4 - Allow sunrpc/svc cache init function to modify the "key" NeilBrown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.