[Tux3] Patch: Improve new_btree interface, fix lock init

Daniel Phillips phillips at phunq.net
Wed Dec 24 16:14:26 PST 2008


On Wednesday 24 December 2008 10:34, OGAWA Hirofumi wrote:
> Daniel Phillips <phillips at phunq.net> writes:
> 
> > The new_btree function was a piece of prototype code that escaped and
> > finally started causing problems now, when we decided to add a new lock
> > and realized it had to be initialized in several places.  Its primary
> > purpose is to create the persistent form of a btree, not to initialize
> > the cache object.  So with this patch new_btree takes an existing btree
> > object as a parameter and returns an error code as is proper.
> >
> > But the patch is not quite ready to apply, we still have destructive
> > initialization of the btree cache object in unpack_sb and decode_attrs,
> > which needs a clean fix I am not quite prepared to tackle at this time
> > of night, so see you all tomorrow.
> 
> This is incremental patch of this patch.
> 
> This adds init_btree() to initialize btree. And it calls new
> ->btree_init() method to initialize per btree fields (it is only
> ->entries_per_leaf currently).
> 
> Then, this uses it except btree in main(). So, with this, new_btree()
> allocates new btree, and init_btree initialize ->btree with existing
> btree.

I applied both our patches, then took advantage of the opportunity to
simplify things a little.  Thinking ahead to when inodes do not always
have btrees, inode initialization does not do any btree initialization,
except set the entire embedded btree to zero.  The semaphore init that
started this whole chase is now done in your new init_btree, and btrees
are initialized only when the persistent object is created or loaded
from disk.  Now, ops is never NULL: the initialization is always done
at a point where we know what the ops should be.

Regards,

Daniel

diff -r 48404918e404 user/inode.c
--- a/user/inode.c	Wed Dec 24 13:49:54 2008 -0800
+++ b/user/inode.c	Wed Dec 24 15:49:12 2008 -0800
@@ -27,7 +27,6 @@ struct inode *new_inode(struct sb *sb)
 	if (!inode)
 		goto eek;
 	*inode = (struct inode){ .i_sb = sb, .map = map, .i_version = 1, .i_nlink = 1, };
-	init_btree(&tux_inode(inode)->btree, NULL, (struct root){}, NULL);
 	return inode->map->inode = inode;
 eek:
 	if (map)
diff -r 48404918e404 user/kernel/btree.c
--- a/user/kernel/btree.c	Wed Dec 24 13:49:54 2008 -0800
+++ b/user/kernel/btree.c	Wed Dec 24 15:49:12 2008 -0800
@@ -591,9 +591,8 @@ void init_btree(struct btree *btree, str
 	btree->sb = sb;
 	btree->ops = ops;
 	btree->root = root;
-	btree->entries_per_leaf = 0;
-	if (ops)
-		ops->btree_init(btree);
+	init_rwsem(&btree->lock);
+	ops->btree_init(btree);
 }
 
 int new_btree(struct btree *btree, struct sb *sb, struct btree_ops *ops)
@@ -612,8 +611,7 @@ int new_btree(struct btree *btree, struc
 	printf("leaf at %Lx\n", (L)bufindex(leafbuf));
 	brelse_dirty(rootbuf);
 	brelse_dirty(leafbuf);
-	struct root root = { .block = bufindex(rootbuf), .depth = 1 };
-	init_btree(btree, sb, root, ops);
+	btree->root = (struct root){ .block = bufindex(rootbuf), .depth = 1 };
 	return 0;
 eek:
 	if (rootbuf)
diff -r 48404918e404 user/kernel/super.c
--- a/user/kernel/super.c	Wed Dec 24 13:49:54 2008 -0800
+++ b/user/kernel/super.c	Wed Dec 24 15:49:12 2008 -0800
@@ -65,7 +65,6 @@ static void tux3_inode_init_once(struct 
 static void tux3_inode_init_once(struct kmem_cache *cachep, void *mem)
 {
 	inode_init_once(&((tuxnode_t *)mem)->vfs_inode);
-	init_rwsem(&((tuxnode_t *)mem)->btree.lock);
 }
 
 static int __init tux3_init_inodecache(void)
@@ -89,7 +88,6 @@ static struct inode *tux3_alloc_inode(st
 	tuxnode_t *tuxi = kmem_cache_alloc(tux_inode_cachep, GFP_KERNEL);
 	if (!tuxi)
 		return NULL;
-	init_btree(&tuxi->btree, NULL, (struct root){}, NULL);
 	tuxi->present = 0;
 	tuxi->xcache = NULL;
 

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list