Fix existing item insertion

Inserting an item over an existing key was super broken.  Now that we're
not replacing we can't stop descent if we find an existing item.  We
need to keep descending and then insert.  And the caller needs to, you
know, actually remove the existing item when it's found -- not the item
it just inserted :P.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-12-08 09:10:55 -08:00
parent 5eb388ae6e
commit fbd12b4dda

View File

@@ -122,17 +122,19 @@ static struct cached_item *insert_item(struct rb_root *root,
item = container_of(*node, struct cached_item, node);
cmp = scoutfs_kvec_memcmp(ins->key, item->key);
if (cmp == 0) {
BUG_ON(existing);
existing = item;
}
if (cmp < 0) {
if (ins->dirty)
item->dirty |= LEFT_DIRTY;
node = &(*node)->rb_left;
} else if (cmp > 0) {
} else {
if (ins->dirty)
item->dirty |= RIGHT_DIRTY;
node = &(*node)->rb_right;
} else {
existing = item;
break;
}
}
@@ -376,7 +378,7 @@ static int add_item(struct super_block *sb, struct kvec *key, struct kvec *val,
existing = insert_item(&cac->root, item);
if (existing) {
clear_item_dirty(cac, existing);
rb_erase_augmented(&item->node, &cac->root,
rb_erase_augmented(&existing->node, &cac->root,
&scoutfs_item_rb_cb);
}
mark_item_dirty(cac, item);