diff options
Diffstat (limited to 'fs/coda/cache.c')
-rw-r--r-- | fs/coda/cache.c | 155 |
1 files changed, 46 insertions, 109 deletions
diff --git a/fs/coda/cache.c b/fs/coda/cache.c index 68be7a69d..eff2da6cd 100644 --- a/fs/coda/cache.c +++ b/fs/coda/cache.c @@ -24,82 +24,48 @@ #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 ; + + if ( !sbi || !cii ) { + printk("coda_cache_create: NULL sbi or cii!\n"); + return NULL; } - list_add(&el->cc_cclist, &sbi->sbi_cchead); -} + CODA_ALLOC(cc, struct coda_cache *, sizeof(*cc)); -/* 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 ; + 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 +73,11 @@ static void coda_cache_create(struct inode *inode, int mask) 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 ) { + list_for_each(le, &cii->c_cnhead) + { /* compare name and creds */ cc = list_entry(le, struct coda_cache, cc_cnlist); if ( !coda_cred_ok(&cc->cc_cred) ) @@ -119,7 +85,7 @@ static struct coda_cache * coda_cache_find(struct inode *inode) 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 +95,10 @@ void coda_cache_enter(struct inode *inode, int mask) cc = coda_cache_find(inode); - if ( cc ) { + if (!cc) + 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 +119,7 @@ void coda_cache_clear_inode(struct inode *inode) 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 +135,11 @@ void coda_cache_clear_all(struct super_block *sb) 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 +155,12 @@ void coda_cache_clear_cred(struct super_block *sb, struct coda_cred *cred) 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 +170,11 @@ void coda_cache_clear_cred(struct super_block *sb, struct coda_cred *cred) 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 ) { + list_for_each(le, &cii->c_cnhead) + { /* compare name and creds */ cc = list_entry(le, struct coda_cache, cc_cnlist); if ( (cc->cc_mask & mask) != mask ) @@ -232,8 +184,8 @@ int coda_cache_check(struct inode *inode, int mask) 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; } @@ -276,10 +228,9 @@ static void coda_flag_children(struct dentry *parent, int flag) struct list_head *child; struct dentry *de; - child = parent->d_subdirs.next; - while ( child != &parent->d_subdirs ) { + list_for_each(child, &parent->d_subdirs) + { 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; @@ -307,17 +258,3 @@ void coda_flag_inode_children(struct inode *inode, int flag) dput(alias_de); } -/* 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); - cii->c_flags |= flag; -} - |