[Libsysio-commit] HEAD: libsysio/src inode.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2007-09-24 18:04:06
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv8912 Modified Files: inode.c Log Message: The path base node disconnect routine was passing the wrong pointer to the tree deletion routine. Fixed this by abstracting the name cache manipulation everywhere and crafting the necessary routines. Added ncache_insert, ncache_delete, and ncache_lookup. Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -w -b -B -p -r1.30 -r1.31 --- inode.c 21 Sep 2007 20:12:55 -0000 1.30 +++ inode.c 24 Sep 2007 17:33:00 -0000 1.31 @@ -58,7 +58,7 @@ #include "inode.h" #include "dev.h" -/* #define I_STATS */ +#define I_STATS /* * Support for path and index nodes. @@ -83,6 +83,18 @@ static size_t n_inodes = 0; static struct tree_node *names[NAMES_TABLE_LEN]; /* + * Return slot index in names table given pointer to path base key. + */ +#define ncache_key_index(pbk) \ + ((pbk)->pbk_name.hashval % NAMES_TABLE_LEN) + +/* + * Return ptr to slot in names table given hash value. + */ +#define ncache_slot(h) \ + (names[(h)] % NAMES_TABLE_LEN) + +/* * Number of names tracked by the system. */ static size_t n_names = 0; @@ -411,6 +423,52 @@ compar_pb_key(const struct pnode_base_ke } /* + * Insert a path base node into the system name cache. + */ +static void +ncache_insert(struct pnode_base *pb) +{ + + if (_sysio_tree_search(&pb->pb_tentry, + &names[ncache_key_index(&pb->pb_key)], + (int (*)(const void *, + const void *))compar_pb_key) != + &pb->pb_tentry) + abort(); +} + +/* + * Delete path base node from the system name cache. + */ +static void +ncache_delete(struct pnode_base *pb) +{ + + if (_sysio_tree_delete(&pb->pb_key, + &names[ncache_key_index(&pb->pb_key)], + (int (*)(const void *, + const void *))compar_pb_key) != + &pb->pb_tentry) + abort(); +} + +/* + * Lookup path base node in the system name cache given key info. + */ +static struct pnode_base * +ncache_lookup(struct pnode_base_key *pbk) +{ + struct tree_node *tn; + + tn = + _sysio_tree_find(pbk, + &names[ncache_key_index(pbk)], + (int (*)(const void *, + const void *))compar_pb_key); + return tn ? TREE_ENTRY(tn, pnode_base, pb_tentry) : NULL; +} + +/* * Allocate and initialize a new base path node. */ struct pnode_base * @@ -446,13 +504,7 @@ _sysio_pb_new(struct qstr *name, struct (void )strncpy(cp, name->name, name->len); pb->pb_key.pbk_name.name = cp; pb->pb_key.pbk_name.hashval = name->hashval; - if (_sysio_tree_search(&pb->pb_tentry, - &names[pb->pb_key.pbk_name.hashval % - NAMES_TABLE_LEN], - (int (*)(const void *, - const void *))compar_pb_key) != - &pb->pb_tentry) - abort(); + ncache_insert(pb); } pb->pb_ino = ino; @@ -475,7 +527,6 @@ _sysio_pb_new(struct qstr *name, struct static void pb_destroy(struct pnode_base *pb) { - struct tree_node *tn; assert(n_names); n_names--; @@ -483,16 +534,8 @@ pb_destroy(struct pnode_base *pb) assert(!pb->pb_aliases.lh_first); assert(!pb->pb_children.lh_first); assert(!pb->pb_ino); - if (pb->pb_key.pbk_name.len) { - tn = - _sysio_tree_delete(&pb->pb_key, - &names[pb->pb_key.pbk_name.hashval % - NAMES_TABLE_LEN], - (int (*)(const void *, - const void *))compar_pb_key); - if (TREE_ENTRY(tn, pnode_base, pb_tentry) != pb) - abort(); - } + if (pb->pb_key.pbk_name.len) + ncache_delete(pb); if (pb->pb_key.pbk_parent) LIST_REMOVE(pb, pb_sibs); @@ -523,7 +566,6 @@ static void _sysio_pb_disconnect(struct pnode_base *pb) { struct pnode *pno; - struct tree_node *tn; /* * Disconnect all aliases associated with the referenced base node. @@ -536,16 +578,10 @@ _sysio_pb_disconnect(struct pnode_base * * Remove name from the names cache so that it can't * be found anymore. */ - if (pb->pb_key.pbk_name.len) { - tn = - _sysio_tree_delete(&pb->pb_tentry, - &names[pb->pb_key.pbk_name.hashval % - NAMES_TABLE_LEN], - (int (*)(const void *, - const void *))compar_pb_key); - if (TREE_ENTRY(tn, pnode_base, pb_tentry) != pb) + if (pb->pb_key.pbk_name.len) + ncache_delete(pb); + else abort(); - } pb->pb_key.pbk_name.len = 0; } @@ -557,6 +593,12 @@ void _sysio_i_shutdown() { +#ifdef I_STATS + _sysio_cprintf("inode: probe %lu, hit %lu\n", i_probes, i_hits); + _sysio_cprintf("pbnode: probe %lu, hit %lu\n", pb_probes, pb_hits); + _sysio_cprintf("pnode: reclaims %lu, examined %lu dismissed %lu\n", + p_reclaims, p_examined, p_dismissed); +#endif max_names = desired_names; return; @@ -649,7 +691,6 @@ _sysio_p_find_alias(struct pnode *parent { struct pnode_base *pb; struct pnode_base_key key; - struct tree_node *tn; int err; struct pnode *pno; @@ -669,19 +710,12 @@ _sysio_p_find_alias(struct pnode *parent #endif key.pbk_name = *name; key.pbk_parent = parent->p_base; - tn = - _sysio_tree_find(&key, - &names[key.pbk_name.hashval % - NAMES_TABLE_LEN], - (int (*)(const void *, - const void *))compar_pb_key); - if (tn) { - pb = TREE_ENTRY(tn, pnode_base, pb_tentry); + pb = ncache_lookup(&key); #ifdef I_STATS + if (pb) pb_hits++; #endif } - } if (!pb) { /* * None found, create new child. |