[Tux3] Patch: use cursor_redirect in various places
Daniel Phillips
phillips at phunq.net
Mon Jan 26 23:17:32 PST 2009
Improved patch with fewer #ifdefs, and better because it compiles the
redirect code even when it is not active.
diff -r 41cb2bfda333 user/btree.c
--- a/user/btree.c Tue Jan 27 13:16:58 2009 +0900
+++ b/user/btree.c Mon Jan 26 23:15:43 2009 -0800
@@ -144,7 +144,7 @@ static void tree_expand_test(struct curs
struct btree *btree = cursor->btree;
if (probe(btree, key, cursor))
error("probe for %Lx failed", (L)key);
- struct uentry *entry = tree_expand(btree, key, 1, cursor);
+ struct uentry *entry = tree_expand(cursor, key, 1);
*entry = (struct uentry){ .key = key, .val = key + 0x100 };
mark_buffer_dirty(cursor_leafbuf(cursor));
cursor_redirect(cursor);
diff -r 41cb2bfda333 user/kernel/btree.c
--- a/user/kernel/btree.c Tue Jan 27 13:16:58 2009 +0900
+++ b/user/kernel/btree.c Mon Jan 26 23:15:43 2009 -0800
@@ -327,13 +327,16 @@ static void level_redirect_brelse(struct
int cursor_redirect(struct cursor *cursor)
{
+#ifndef ATOMIC
+ return 0;
+#endif
struct btree *btree = cursor->btree;
unsigned level = btree->root.depth;
struct sb *sb = btree->sb;
while (1) {
struct buffer_head *buffer = cursor->path[level].buffer;
-// if (buffer_dirty(buffer))
-// return 0;
+ if (buffer_dirty(buffer))
+ return 0;
struct buffer_head *clone = new_block(btree);
if (IS_ERR(clone))
@@ -682,8 +685,12 @@ int btree_leaf_split(struct btree *btree
return insert_leaf(cursor, newkey, newbuf, key < newkey);
}
-void *tree_expand(struct btree *btree, tuxkey_t key, unsigned newsize, struct cursor *cursor)
+void *tree_expand(struct cursor *cursor, tuxkey_t key, unsigned newsize)
{
+ struct btree *btree = cursor->btree;
+ int err = cursor_redirect(cursor);
+ if (err)
+ return NULL; // ERR_PTR me!!!
for (int i = 0; i < 2; i++) {
struct buffer_head *leafbuf = cursor_leafbuf(cursor);
void *space = (btree->ops->leaf_resize)(btree, key, bufdata(leafbuf), newsize);
diff -r 41cb2bfda333 user/kernel/filemap.c
--- a/user/kernel/filemap.c Tue Jan 27 13:16:58 2009 +0900
+++ b/user/kernel/filemap.c Mon Jan 26 23:15:43 2009 -0800
@@ -162,7 +162,10 @@ static int map_region(struct inode *inod
if (!create)
goto out_release;
-
+ if ((err = cursor_redirect(cursor))) {
+ segs = err;
+ goto out_release;
+ }
struct dleaf *tail = NULL;
tuxkey_t tailkey = 0; // probably can just use limit instead
diff -r 41cb2bfda333 user/kernel/inode.c
--- a/user/kernel/inode.c Tue Jan 27 13:16:58 2009 +0900
+++ b/user/kernel/inode.c Mon Jan 26 23:15:43 2009 -0800
@@ -142,7 +142,7 @@ static int store_attrs(struct inode *ino
static int store_attrs(struct inode *inode, struct cursor *cursor)
{
unsigned size = encode_asize(tux_inode(inode)->present) + encode_xsize(inode);
- void *base = tree_expand(itable_btree(tux_sb(inode->i_sb)), tux_inode(inode)->inum, size, cursor);
+ void *base = tree_expand(cursor, tux_inode(inode)->inum, size);
if (!base)
return -ENOMEM; // ERR_PTR me!!!
void *attr = encode_attrs(inode, base, size);
@@ -262,6 +262,8 @@ static int purge_inum(struct sb *sb, inu
int err = -ENOENT;
if (!(err = probe(itable, inum, cursor))) {
+ if ((err = cursor_redirect(cursor)))
+ return err;
/* FIXME: truncate the bnode and leaf if empty. */
struct buffer_head *ileafbuf = cursor_leafbuf(cursor);
struct ileaf *ileaf = to_ileaf(bufdata(ileafbuf));
_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3
More information about the Tux3
mailing list