Commit 96dd8d25 authored by David Woodhouse's avatar David Woodhouse

[JFFS2] Remove broken insert_point optimisation in jffs2_add_tn_to_tree()

The original code would remember, during the first pass over the tree,
a suitable place to start the insertion from when we eventually come
to add a new node.

The optimisation was broken, and we sometimes ended up inserting a new
node in the wrong place because we started the insertion from the wrong
point.

Just ditch the optimisation and start the insertion from the root of the
tree, for now. I'll try it again when I'm feeling cleverer.
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 1123e2a8
...@@ -219,7 +219,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -219,7 +219,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
struct jffs2_tmp_dnode_info *tn) struct jffs2_tmp_dnode_info *tn)
{ {
uint32_t fn_end = tn->fn->ofs + tn->fn->size; uint32_t fn_end = tn->fn->ofs + tn->fn->size;
struct jffs2_tmp_dnode_info *insert_point = NULL, *this; struct jffs2_tmp_dnode_info *this;
dbg_readinode("insert fragment %#04x-%#04x, ver %u\n", tn->fn->ofs, fn_end, tn->version); dbg_readinode("insert fragment %#04x-%#04x, ver %u\n", tn->fn->ofs, fn_end, tn->version);
...@@ -248,9 +248,6 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -248,9 +248,6 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
return 0; return 0;
} }
/* If we add a new node it'll be somewhere under here. */
insert_point = this;
/* If the node is coincident with another at a lower address, /* If the node is coincident with another at a lower address,
back up until the other node is found. It may be relevant */ back up until the other node is found. It may be relevant */
while (tn->overlapped) while (tn->overlapped)
...@@ -325,24 +322,16 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -325,24 +322,16 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
jffs2_kill_tn(c, this); jffs2_kill_tn(c, this);
return 0; return 0;
} }
/* We want to be inserted under the last node which is
either at a lower offset _or_ has a smaller range */
if (this->fn->ofs < tn->fn->ofs ||
(this->fn->ofs == tn->fn->ofs &&
this->fn->size <= tn->fn->size))
insert_point = this;
this = tn_next(this); this = tn_next(this);
} }
dbg_readinode("insert_point %p, ver %d, 0x%x-0x%x, ov %d\n",
insert_point, insert_point->version, insert_point->fn->ofs,
insert_point->fn->ofs+insert_point->fn->size,
insert_point->overlapped);
/* We neither completely obsoleted nor were completely /* We neither completely obsoleted nor were completely
obsoleted by an earlier node. Insert under insert_point */ obsoleted by an earlier node. Insert into the tree */
{ {
struct rb_node *parent = &insert_point->rb; struct rb_node *parent;
struct rb_node **link = &parent; struct rb_node **link = &rii->tn_root.rb_node;
struct jffs2_tmp_dnode_info *insert_point;
while (*link) { while (*link) {
parent = *link; parent = *link;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment