@@ -382,6 +382,16 @@ static struct btrfs_delayed_item *__btrfs_lookup_delayed_insertion_item(
return item;
}
+static struct rb_root *get_ins_del_root(struct btrfs_delayed_node *delayed_node,
+ int ins_del)
+{
+ if (ins_del == BTRFS_DELAYED_INSERTION_ITEM)
+ return &delayed_node->ins_root;
+ if (ins_del == BTRFS_DELAYED_DELETION_ITEM)
+ return &delayed_node->del_root;
+ BUG();
+}
+
static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
struct btrfs_delayed_item *ins,
int action)
@@ -392,12 +402,7 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
struct btrfs_delayed_item *item;
int cmp;
- if (action == BTRFS_DELAYED_INSERTION_ITEM)
- root = &delayed_node->ins_root;
- else if (action == BTRFS_DELAYED_DELETION_ITEM)
- root = &delayed_node->del_root;
- else
- BUG();
+ root = get_ins_del_root(delayed_node, action);
p = &root->rb_node;
node = &ins->rb_node;
@@ -460,15 +465,8 @@ static void __btrfs_remove_delayed_item(struct btrfs_delayed_item *delayed_item)
delayed_root = delayed_item->delayed_node->root->fs_info->delayed_root;
- BUG_ON(!delayed_root);
- BUG_ON(delayed_item->ins_or_del != BTRFS_DELAYED_DELETION_ITEM &&
- delayed_item->ins_or_del != BTRFS_DELAYED_INSERTION_ITEM);
-
- if (delayed_item->ins_or_del == BTRFS_DELAYED_INSERTION_ITEM)
- root = &delayed_item->delayed_node->ins_root;
- else
- root = &delayed_item->delayed_node->del_root;
-
+ root = get_ins_del_root(delayed_item->delayed_node,
+ delayed_item->ins_or_del);
rb_erase(&delayed_item->rb_node, root);
delayed_item->delayed_node->count--;
This just moves some duplicated code into a helper. I couldn't bring myself to add another copy in an upcoming patch. The delayed_root BUG() in __btrfs_remove_delayed_item() wasn't needed. The pointer deref will oops later if its null. And now the remaining BUG() is in one place! :) Signed-off-by: Zach Brown <zab@redhat.com> --- fs/btrfs/delayed-inode.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)