Suggested fix?  It just advances next pointers in two places, and
tries to set the correct next pointer for new root.  Gets rid of
the cached "next" pointer and operates directly on the cursor.

diff -r 382ff76199ac user/kernel/btree.c
--- a/user/kernel/btree.c       Wed Dec 24 22:43:08 2008 -0800
+++ b/user/kernel/btree.c       Thu Dec 25 00:08:37 2008 -0800
@@ -492,13 +492,13 @@ int insert_node(struct btree *btree, u64
        trace("insert node 0x%Lx key 0x%Lx into node 0x%Lx", (L)childblock, 
(L)childkey, (L)btree->root.block);
        int depth = btree->root.depth;
        while (depth--) {
-               struct index_entry *next = cursor->path[depth].next;
-               struct buffer_head *parentbuf = cursor->path[depth].buffer;
+               struct path_level *at = cursor->path + depth;
+               struct buffer_head *parentbuf = at->buffer;
                struct bnode *parent = bufdata(parentbuf);
 
                /* insert and exit if not full */
                if (bcount(parent) < btree->sb->entries_per_node) {
-                       add_child(parent, next, childblock, childkey);
+                       add_child(parent, at->next++, childblock, childkey);
                        mark_buffer_dirty(parentbuf);
                        return 0;
                }
@@ -515,14 +515,14 @@ int insert_node(struct btree *btree, u64
                parent->count = to_be_u32(half);
 
                /* if the cursor is in the new node, use that as the parent */
-               if (next > parent->entries + half) {
-                       next = next - &parent->entries[half] + newnode->entries;
+               if (at->next > parent->entries + half) {
+                       at->next = at->next - &parent->entries[half] + 
newnode->entries;
                        mark_buffer_dirty(parentbuf);
                        parentbuf = newbuf;
                        parent = newnode;
                } else
                        mark_buffer_dirty(newbuf);
-               add_child(parent, next, childblock, childkey);
+               add_child(parent, at->next++, childblock, childkey);
                mark_buffer_dirty(parentbuf);
                childkey = newkey;
                childblock = bufindex(newbuf);
@@ -539,7 +539,7 @@ int insert_node(struct btree *btree, u64
        newroot->entries[1].block = to_be_u64(childblock);
        btree->root.block = bufindex(newbuf);
        btree->root.depth++;
-       level_root_add(cursor, newbuf, NULL); // .next = ???
+       level_root_add(cursor, newbuf, newroot->entries + 2);
        //set_sb_dirty(sb);
        mark_buffer_dirty(newbuf);
        return 0;

_______________________________________________
Tux3 mailing list
[email protected]
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3

Reply via email to