Commit c9d02ab4 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: set delayed item type when initializing it

Currently we set the type of a delayed item only after successfully
inserting it into its respective rbtree. This is fine, as the type
is not used anywhere before that point, but for the next patch in the
series, there will be the need to check the type of a delayed item
before inserting it into a rbtree.

So set the type of a delayed item immediately after allocating it.
This also makes the trivial wrappers for adding insertion and deletion
useless, so it removes them as well.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 3bae13e9
...@@ -386,8 +386,7 @@ static struct btrfs_delayed_item *__btrfs_lookup_delayed_insertion_item( ...@@ -386,8 +386,7 @@ static struct btrfs_delayed_item *__btrfs_lookup_delayed_insertion_item(
} }
static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
struct btrfs_delayed_item *ins, struct btrfs_delayed_item *ins)
int action)
{ {
struct rb_node **p, *node; struct rb_node **p, *node;
struct rb_node *parent_node = NULL; struct rb_node *parent_node = NULL;
...@@ -396,9 +395,9 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, ...@@ -396,9 +395,9 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
int cmp; int cmp;
bool leftmost = true; bool leftmost = true;
if (action == BTRFS_DELAYED_INSERTION_ITEM) if (ins->ins_or_del == BTRFS_DELAYED_INSERTION_ITEM)
root = &delayed_node->ins_root; root = &delayed_node->ins_root;
else if (action == BTRFS_DELAYED_DELETION_ITEM) else if (ins->ins_or_del == BTRFS_DELAYED_DELETION_ITEM)
root = &delayed_node->del_root; root = &delayed_node->del_root;
else else
BUG(); BUG();
...@@ -424,12 +423,11 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, ...@@ -424,12 +423,11 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
rb_link_node(node, parent_node, p); rb_link_node(node, parent_node, p);
rb_insert_color_cached(node, root, leftmost); rb_insert_color_cached(node, root, leftmost);
ins->delayed_node = delayed_node; ins->delayed_node = delayed_node;
ins->ins_or_del = action;
/* Delayed items are always for dir index items. */ /* Delayed items are always for dir index items. */
ASSERT(ins->key.type == BTRFS_DIR_INDEX_KEY); ASSERT(ins->key.type == BTRFS_DIR_INDEX_KEY);
if (action == BTRFS_DELAYED_INSERTION_ITEM && if (ins->ins_or_del == BTRFS_DELAYED_INSERTION_ITEM &&
ins->key.offset >= delayed_node->index_cnt) ins->key.offset >= delayed_node->index_cnt)
delayed_node->index_cnt = ins->key.offset + 1; delayed_node->index_cnt = ins->key.offset + 1;
...@@ -438,20 +436,6 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node, ...@@ -438,20 +436,6 @@ static int __btrfs_add_delayed_item(struct btrfs_delayed_node *delayed_node,
return 0; return 0;
} }
static int __btrfs_add_delayed_insertion_item(struct btrfs_delayed_node *node,
struct btrfs_delayed_item *item)
{
return __btrfs_add_delayed_item(node, item,
BTRFS_DELAYED_INSERTION_ITEM);
}
static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
struct btrfs_delayed_item *item)
{
return __btrfs_add_delayed_item(node, item,
BTRFS_DELAYED_DELETION_ITEM);
}
static void finish_one_item(struct btrfs_delayed_root *delayed_root) static void finish_one_item(struct btrfs_delayed_root *delayed_root)
{ {
int seq = atomic_inc_return(&delayed_root->items_seq); int seq = atomic_inc_return(&delayed_root->items_seq);
...@@ -1375,6 +1359,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, ...@@ -1375,6 +1359,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
delayed_item->key.objectid = btrfs_ino(dir); delayed_item->key.objectid = btrfs_ino(dir);
delayed_item->key.type = BTRFS_DIR_INDEX_KEY; delayed_item->key.type = BTRFS_DIR_INDEX_KEY;
delayed_item->key.offset = index; delayed_item->key.offset = index;
delayed_item->ins_or_del = BTRFS_DELAYED_INSERTION_ITEM;
dir_item = (struct btrfs_dir_item *)delayed_item->data; dir_item = (struct btrfs_dir_item *)delayed_item->data;
dir_item->location = *disk_key; dir_item->location = *disk_key;
...@@ -1395,7 +1380,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, ...@@ -1395,7 +1380,7 @@ int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
} }
mutex_lock(&delayed_node->mutex); mutex_lock(&delayed_node->mutex);
ret = __btrfs_add_delayed_insertion_item(delayed_node, delayed_item); ret = __btrfs_add_delayed_item(delayed_node, delayed_item);
if (unlikely(ret)) { if (unlikely(ret)) {
btrfs_err(trans->fs_info, btrfs_err(trans->fs_info,
"err add delayed dir index item(name: %.*s) into the insertion tree of the delayed node(root id: %llu, inode id: %llu, errno: %d)", "err add delayed dir index item(name: %.*s) into the insertion tree of the delayed node(root id: %llu, inode id: %llu, errno: %d)",
...@@ -1457,6 +1442,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, ...@@ -1457,6 +1442,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
} }
item->key = item_key; item->key = item_key;
item->ins_or_del = BTRFS_DELAYED_DELETION_ITEM;
ret = btrfs_delayed_item_reserve_metadata(trans, dir->root, item); ret = btrfs_delayed_item_reserve_metadata(trans, dir->root, item);
/* /*
...@@ -1471,7 +1457,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, ...@@ -1471,7 +1457,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
} }
mutex_lock(&node->mutex); mutex_lock(&node->mutex);
ret = __btrfs_add_delayed_deletion_item(node, item); ret = __btrfs_add_delayed_item(node, item);
if (unlikely(ret)) { if (unlikely(ret)) {
btrfs_err(trans->fs_info, btrfs_err(trans->fs_info,
"err add delayed dir index item(index: %llu) into the deletion tree of the delayed node(root id: %llu, inode id: %llu, errno: %d)", "err add delayed dir index item(index: %llu) into the deletion tree of the delayed node(root id: %llu, inode id: %llu, errno: %d)",
......
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