[Tux3] Patch: use cursor_redirect in various places
Daniel Phillips
phillips at phunq.net
Mon Jan 26 23:00:38 PST 2009
This is supposed to cover all changes to metadata blocks. The
cursor_redirects occur inside change_begin/end markers.
Truncate (leaf_chop) is problematic for three reasons:
* We don't know if a particular leaf should be redirected until
calling the leaf chop method, and by that time the leaf has been
changed
* Btree leaf methods do not know anything about btrees or cursors
* Multiple leaf nodes might need to be redirected by the chop, so
there has to be something like an 'advance and redirect
So the interface to leaf methods needs to be rethought. But we will
push ahead with implementing the node redirects for writing, inode
creation, and inode purge while thinking about the interface for
truncate.
Compilation with atomic commit code is controlled by #ifdef ATOMIC for
now, to avoid breaking the code too much before all the pieces are in
place. To enable the atomic commit code:
make UCFLAGS=-DATOMIC
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 22:48:27 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 22:48:27 2009 -0800
@@ -332,8 +332,8 @@ int cursor_redirect(struct cursor *curso
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 +682,14 @@ 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;
+#ifdef ATOMIC
+ int err = cursor_redirect(cursor);
+ if (err)
+ return NULL; // ERR_PTR me!!!
+#endif
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 22:48:27 2009 -0800
@@ -162,7 +162,12 @@ static int map_region(struct inode *inod
if (!create)
goto out_release;
-
+#ifdef ATOMIC
+ if ((err = cursor_redirect(cursor))) {
+ segs = err;
+ goto out_release;
+ }
+#endif
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 22:48:27 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,10 @@ static int purge_inum(struct sb *sb, inu
int err = -ENOENT;
if (!(err = probe(itable, inum, cursor))) {
+#ifdef ATOMIC
+ if ((err = cursor_redirect(cursor)))
+ return err;
+#endif
/* 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