patch-2.2.17 linux/fs/coda/cache.c

Next file: linux/fs/coda/cnode.c
Previous file: linux/fs/buffer.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.2.16/fs/coda/cache.c linux/fs/coda/cache.c
@@ -24,82 +24,49 @@
 #include <linux/coda_fs_i.h>
 #include <linux/coda_cache.h>
 
-static void coda_ccinsert(struct coda_cache *el, struct super_block *sb);
-static void coda_cninsert(struct coda_cache *el, struct coda_inode_info *cii);
-static void coda_ccremove(struct coda_cache *el);
-static void coda_cnremove(struct coda_cache *el);
-static void coda_cache_create(struct inode *inode, int mask);
-static struct coda_cache * coda_cache_find(struct inode *inode);
-
-
-/* insert a acl-cache entry in sb list */
-static void coda_ccinsert(struct coda_cache *el, struct super_block *sb)
+/* create a new acl cache entry and enlist it */
+static struct coda_cache *coda_cache_create(struct inode *inode)
 {
-	struct coda_sb_info *sbi = coda_sbp(sb);
+	struct coda_inode_info *cii = ITOC(inode);
+	struct coda_sb_info *sbi = coda_sbp(inode->i_sb);
+	struct coda_cache *cc = NULL;
 	ENTRY;
-	/* third test verifies cc was initialized before adding it 
-	   to the sblist. Probably superfluous */
-	if ( !sbi || !el || !list_empty(&el->cc_cclist) ) {
-		printk("coda_ccinsert: NULL sbi or el->cc_cclist not empty!\n");
-		return ;
-	}
 
-	list_add(&el->cc_cclist, &sbi->sbi_cchead);
-}
+	if ( !sbi || !cii ) {
+		printk("coda_cache_create: NULL sbi or cii!\n");
+		return NULL;
+	}
 
-/* insert a acl-cache entry in the inode list */
-static void coda_cninsert(struct coda_cache *el, struct coda_inode_info *cii)
-{
-	ENTRY;
-	if ( !cii ||  !el || ! list_empty(&el->cc_cnlist)) {
-		printk("coda_cninsert: NULL cii or el->cc_cnlist not empty!\n");
-		return ;
+	CODA_ALLOC(cc, struct coda_cache *, sizeof(struct coda_cache));
+	if ( !cc ) {
+		printk("Out of memory in coda_cache_create!\n");
+		return NULL;
 	}
-	list_add(&el->cc_cnlist, &cii->c_cnhead);
-}
 
-/* remove a cache entry from the superblock list */
-static void coda_ccremove(struct coda_cache *el)
-{
-	ENTRY;
-        if ( ! list_empty(&el->cc_cclist) )
-	        list_del(&el->cc_cclist);
-	else
-		printk("coda_ccremove: loose cc entry!");
-}
+	coda_load_creds(&cc->cc_cred);
+	cc->cc_mask = 0;
 
-/* remove a cache entry from the inode's list */
-static void coda_cnremove(struct coda_cache *el)
-{
-	ENTRY;
-	if ( ! list_empty(&el->cc_cnlist) )
-		list_del(&el->cc_cnlist);
-	else
-		printk("coda_cnremove: loose cn entry!");
+	INIT_LIST_HEAD(&cc->cc_cclist);
+	INIT_LIST_HEAD(&cc->cc_cnlist);
+	list_add(&cc->cc_cclist, &sbi->sbi_cchead);
+	list_add(&cc->cc_cnlist, &cii->c_cnhead);
+
+	return cc;
 }
 
-/* create a new cache entry and enlist it */
-static void coda_cache_create(struct inode *inode, int mask)
+/* destroy an acl cache entry */
+static void coda_cache_destroy(struct coda_cache *el)
 {
-	struct coda_inode_info *cii = ITOC(inode);
-	struct super_block *sb = inode->i_sb;
-	struct coda_cache *cc = NULL;
 	ENTRY;
 
-	CODA_ALLOC(cc, struct coda_cache *, sizeof(*cc));
-
-	if ( !cc ) {
-		printk("Out of memory in coda_cache_enter!\n");
+	if (list_empty(&el->cc_cclist) || list_empty(&el->cc_cnlist)) {
+		printk("coda_cache_destroy: loose entry!");
 		return;
 	}
 
-	INIT_LIST_HEAD(&cc->cc_cclist);
-	INIT_LIST_HEAD(&cc->cc_cnlist);
-
-	coda_load_creds(&cc->cc_cred);
-	cc->cc_mask = mask;
-	coda_cninsert(cc, cii);
-	coda_ccinsert(cc, sb);
+	list_del(&el->cc_cclist);
+	list_del(&el->cc_cnlist);
+	CODA_FREE(el, sizeof(struct coda_cache));
 }
 
 /* see if there is a match for the current 
@@ -107,11 +74,11 @@
 static struct coda_cache * coda_cache_find(struct inode *inode)
 {
 	struct coda_inode_info *cii = ITOC(inode);
-	struct list_head *lh, *le;
+	struct list_head *le;
 	struct coda_cache *cc = NULL;
 	
-	le = lh = &cii->c_cnhead;
-	while( (le = le->next ) != lh )  {
+	for(le = cii->c_cnhead.next; le != &cii->c_cnhead; le = le->next)
+	{
 		/* compare name and creds */
 		cc = list_entry(le, struct coda_cache, cc_cnlist);
 		if ( !coda_cred_ok(&cc->cc_cred) )
@@ -119,7 +86,7 @@
 		CDEBUG(D_CACHE, "HIT for ino %ld\n", inode->i_ino );
 		return cc; /* cache hit */
 	}
-		return NULL;
+	return NULL;
 }
 
 /* create or extend an acl cache hit */
@@ -129,11 +96,11 @@
 
 	cc = coda_cache_find(inode);
 
-	if ( cc ) {
+	if (!cc)
+		coda_cache_create(inode);
+
+	if (cc)
 		cc->cc_mask |= mask;
-	} else {
-		coda_cache_create(inode, mask);
-	}
 }
 
 /* remove all cached acl matches from an inode */
@@ -154,9 +121,7 @@
 	while ( le != &cii->c_cnhead ) {
 		cc = list_entry(le, struct coda_cache, cc_cnlist);
 		le = le->next;
-		coda_cnremove(cc);
-		coda_ccremove(cc);
-		CODA_FREE(cc, sizeof(*cc));
+		coda_cache_destroy(cc);
 	}
 }
 
@@ -172,16 +137,11 @@
 		return;
 	}
 	
-	if ( list_empty(&sbi->sbi_cchead) )
-		return;
-
 	le = sbi->sbi_cchead.next;
 	while ( le != &sbi->sbi_cchead ) {
 		cc = list_entry(le, struct coda_cache, cc_cclist);
 		le = le->next;
-		coda_cnremove(cc);
-		coda_ccremove(cc);
-		CODA_FREE(cc, sizeof(*cc));
+		coda_cache_destroy(cc);
 	}
 }
 
@@ -197,18 +157,12 @@
 		return;
 	}
 	
-	if (list_empty(&sbi->sbi_cchead))
-		return;
-
 	le = sbi->sbi_cchead.next;
 	while ( le != &sbi->sbi_cchead ) {
 		cc = list_entry(le, struct coda_cache, cc_cclist);
 		le = le->next;
-		if ( coda_cred_eq(&cc->cc_cred, cred)) {
-			coda_cnremove(cc);
-			coda_ccremove(cc);
-			CODA_FREE(cc, sizeof(*cc));
-		}
+		if (coda_cred_eq(&cc->cc_cred, cred))
+			coda_cache_destroy(cc);
 	}
 }
 
@@ -218,11 +172,11 @@
 int coda_cache_check(struct inode *inode, int mask)
 {
 	struct coda_inode_info *cii = ITOC(inode);
-	struct list_head *lh, *le;
+	struct list_head *le;
 	struct coda_cache *cc = NULL;
 	
-	le = lh = &cii->c_cnhead;
-	while( (le = le->next ) != lh )  {
+	for(le = cii->c_cnhead.next; le != &cii->c_cnhead; le = le->next)
+	{
 		/* compare name and creds */
 		cc = list_entry(le, struct coda_cache, cc_cnlist);
 		if ( (cc->cc_mask & mask) != mask ) 
@@ -232,8 +186,8 @@
 		CDEBUG(D_CACHE, "HIT for ino %ld\n", inode->i_ino );
 		return 1; /* cache hit */
 	}
-		CDEBUG(D_CACHE, "MISS for ino %ld\n", inode->i_ino );
-		return 0;
+	CDEBUG(D_CACHE, "MISS for ino %ld\n", inode->i_ino );
+	return 0;
 }
 
 
@@ -294,10 +248,10 @@
 	struct list_head *child;
 	struct dentry *de;
 
-	child = parent->d_subdirs.next;
-	while ( child != &parent->d_subdirs ) {
+	for(child = parent->d_subdirs.next; child != &parent->d_subdirs;
+	    child = child->next)
+	{
 		de = list_entry(child, struct dentry, d_child);
-		child = child->next;
 		/* don't know what to do with negative dentries */
 		if ( ! de->d_inode ) 
 			continue;
@@ -315,7 +269,7 @@
 	struct dentry *alias_de;
 
 	ENTRY;
-	if ( !inode ) 
+	if ( !inode || !S_ISDIR(inode->i_mode)) 
 		return; 
 
 	if (list_empty(&inode->i_dentry))
@@ -338,14 +292,7 @@
 /* this will not zap the inode away */
 void coda_flag_inode(struct inode *inode, int flag)
 {
-	struct coda_inode_info *cii;
-
-	if ( !inode ) {
-		CDEBUG(D_CACHE, " no inode!\n");
-		return;
-	}
-
-	cii = ITOC(inode);
+	struct coda_inode_info *cii = ITOC(inode);
 	cii->c_flags |= flag;
 }		
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)