提交 b7a0365e 编写于 作者: D Daniel Dressler 提交者: David Sterba

Btrfs: ctree: reduce args where only fs_info used

This patch is part of a larger project to cleanup btrfs's internal usage
of struct btrfs_root. Many functions take btrfs_root only to grab a
pointer to fs_info.

This causes programmers to ponder which root can be passed. Since only
the fs_info is read affected functions can accept any root, except this
is only obvious upon inspection.

This patch reduces the specificty of such functions to accept the
fs_info directly.

This patch does not address the two functions in ctree.c (insert_ptr,
and split_item) which only use root for BUG_ONs in ctree.c

This patch affects the following functions:
  1) fixup_low_keys
  2) btrfs_set_item_key_safe
Signed-off-by: NDaniel Dressler <danieru.dressler@gmail.com>
Signed-off-by: NDavid Sterba <dsterba@suse.cz>
上级 a742994a
...@@ -3126,7 +3126,8 @@ int btrfs_search_slot_for_read(struct btrfs_root *root, ...@@ -3126,7 +3126,8 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
* higher levels * higher levels
* *
*/ */
static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, static void fixup_low_keys(struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
struct btrfs_disk_key *key, int level) struct btrfs_disk_key *key, int level)
{ {
int i; int i;
...@@ -3137,7 +3138,7 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, ...@@ -3137,7 +3138,7 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
if (!path->nodes[i]) if (!path->nodes[i])
break; break;
t = path->nodes[i]; t = path->nodes[i];
tree_mod_log_set_node_key(root->fs_info, t, tslot, 1); tree_mod_log_set_node_key(fs_info, t, tslot, 1);
btrfs_set_node_key(t, key, tslot); btrfs_set_node_key(t, key, tslot);
btrfs_mark_buffer_dirty(path->nodes[i]); btrfs_mark_buffer_dirty(path->nodes[i]);
if (tslot != 0) if (tslot != 0)
...@@ -3151,7 +3152,8 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path, ...@@ -3151,7 +3152,8 @@ static void fixup_low_keys(struct btrfs_root *root, struct btrfs_path *path,
* This function isn't completely safe. It's the caller's responsibility * This function isn't completely safe. It's the caller's responsibility
* that the new key won't break the order * that the new key won't break the order
*/ */
void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
struct btrfs_key *new_key) struct btrfs_key *new_key)
{ {
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
...@@ -3173,7 +3175,7 @@ void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, ...@@ -3173,7 +3175,7 @@ void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,
btrfs_set_item_key(eb, &disk_key, slot); btrfs_set_item_key(eb, &disk_key, slot);
btrfs_mark_buffer_dirty(eb); btrfs_mark_buffer_dirty(eb);
if (slot == 0) if (slot == 0)
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(fs_info, path, &disk_key, 1);
} }
/* /*
...@@ -3931,7 +3933,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, ...@@ -3931,7 +3933,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
clean_tree_block(trans, root, right); clean_tree_block(trans, root, right);
btrfs_item_key(right, &disk_key, 0); btrfs_item_key(right, &disk_key, 0);
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(root->fs_info, path, &disk_key, 1);
/* then fixup the leaf pointer in the path */ /* then fixup the leaf pointer in the path */
if (path->slots[0] < push_items) { if (path->slots[0] < push_items) {
...@@ -4168,6 +4170,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans, ...@@ -4168,6 +4170,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
int mid; int mid;
int slot; int slot;
struct extent_buffer *right; struct extent_buffer *right;
struct btrfs_fs_info *fs_info = root->fs_info;
int ret = 0; int ret = 0;
int wret; int wret;
int split; int split;
...@@ -4271,10 +4274,10 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans, ...@@ -4271,10 +4274,10 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV); btrfs_set_header_backref_rev(right, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(right, root->root_key.objectid); btrfs_set_header_owner(right, root->root_key.objectid);
btrfs_set_header_level(right, 0); btrfs_set_header_level(right, 0);
write_extent_buffer(right, root->fs_info->fsid, write_extent_buffer(right, fs_info->fsid,
btrfs_header_fsid(), BTRFS_FSID_SIZE); btrfs_header_fsid(), BTRFS_FSID_SIZE);
write_extent_buffer(right, root->fs_info->chunk_tree_uuid, write_extent_buffer(right, fs_info->chunk_tree_uuid,
btrfs_header_chunk_tree_uuid(right), btrfs_header_chunk_tree_uuid(right),
BTRFS_UUID_SIZE); BTRFS_UUID_SIZE);
...@@ -4297,7 +4300,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans, ...@@ -4297,7 +4300,7 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,
path->nodes[0] = right; path->nodes[0] = right;
path->slots[0] = 0; path->slots[0] = 0;
if (path->slots[1] == 0) if (path->slots[1] == 0)
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(fs_info, path, &disk_key, 1);
} }
btrfs_mark_buffer_dirty(right); btrfs_mark_buffer_dirty(right);
return ret; return ret;
...@@ -4615,7 +4618,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path, ...@@ -4615,7 +4618,7 @@ void btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,
btrfs_set_disk_key_offset(&disk_key, offset + size_diff); btrfs_set_disk_key_offset(&disk_key, offset + size_diff);
btrfs_set_item_key(leaf, &disk_key, slot); btrfs_set_item_key(leaf, &disk_key, slot);
if (slot == 0) if (slot == 0)
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(root->fs_info, path, &disk_key, 1);
} }
item = btrfs_item_nr(slot); item = btrfs_item_nr(slot);
...@@ -4716,7 +4719,7 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, ...@@ -4716,7 +4719,7 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
if (path->slots[0] == 0) { if (path->slots[0] == 0) {
btrfs_cpu_key_to_disk(&disk_key, cpu_key); btrfs_cpu_key_to_disk(&disk_key, cpu_key);
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(root->fs_info, path, &disk_key, 1);
} }
btrfs_unlock_up_safe(path, 1); btrfs_unlock_up_safe(path, 1);
...@@ -4888,7 +4891,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, ...@@ -4888,7 +4891,7 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
btrfs_node_key(parent, &disk_key, 0); btrfs_node_key(parent, &disk_key, 0);
fixup_low_keys(root, path, &disk_key, level + 1); fixup_low_keys(root->fs_info, path, &disk_key, level + 1);
} }
btrfs_mark_buffer_dirty(parent); btrfs_mark_buffer_dirty(parent);
} }
...@@ -4990,7 +4993,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -4990,7 +4993,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
btrfs_item_key(leaf, &disk_key, 0); btrfs_item_key(leaf, &disk_key, 0);
fixup_low_keys(root, path, &disk_key, 1); fixup_low_keys(root->fs_info, path, &disk_key, 1);
} }
/* delete the leaf if it is mostly empty */ /* delete the leaf if it is mostly empty */
......
...@@ -3483,7 +3483,8 @@ int btrfs_previous_item(struct btrfs_root *root, ...@@ -3483,7 +3483,8 @@ int btrfs_previous_item(struct btrfs_root *root,
int type); int type);
int btrfs_previous_extent_item(struct btrfs_root *root, int btrfs_previous_extent_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid); struct btrfs_path *path, u64 min_objectid);
void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
struct btrfs_path *path,
struct btrfs_key *new_key); struct btrfs_key *new_key);
struct extent_buffer *btrfs_root_node(struct btrfs_root *root); struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
......
...@@ -553,7 +553,7 @@ static noinline void truncate_one_csum(struct btrfs_root *root, ...@@ -553,7 +553,7 @@ static noinline void truncate_one_csum(struct btrfs_root *root,
btrfs_truncate_item(root, path, new_size, 0); btrfs_truncate_item(root, path, new_size, 0);
key->offset = end_byte; key->offset = end_byte;
btrfs_set_item_key_safe(root, path, key); btrfs_set_item_key_safe(root->fs_info, path, key);
} else { } else {
BUG(); BUG();
} }
......
...@@ -868,7 +868,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -868,7 +868,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
memcpy(&new_key, &key, sizeof(new_key)); memcpy(&new_key, &key, sizeof(new_key));
new_key.offset = end; new_key.offset = end;
btrfs_set_item_key_safe(root, path, &new_key); btrfs_set_item_key_safe(root->fs_info, path, &new_key);
extent_offset += end - key.offset; extent_offset += end - key.offset;
btrfs_set_file_extent_offset(leaf, fi, extent_offset); btrfs_set_file_extent_offset(leaf, fi, extent_offset);
...@@ -1126,7 +1126,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1126,7 +1126,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
new_key.offset = end; new_key.offset = end;
btrfs_set_item_key_safe(root, path, &new_key); btrfs_set_item_key_safe(root->fs_info, path, &new_key);
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
btrfs_set_file_extent_generation(leaf, fi, btrfs_set_file_extent_generation(leaf, fi,
...@@ -1160,7 +1160,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1160,7 +1160,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
trans->transid); trans->transid);
path->slots[0]++; path->slots[0]++;
new_key.offset = start; new_key.offset = start;
btrfs_set_item_key_safe(root, path, &new_key); btrfs_set_item_key_safe(root->fs_info, path, &new_key);
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
...@@ -2169,7 +2169,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2169,7 +2169,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
u64 num_bytes; u64 num_bytes;
key.offset = offset; key.offset = offset;
btrfs_set_item_key_safe(root, path, &key); btrfs_set_item_key_safe(root->fs_info, path, &key);
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end - num_bytes = btrfs_file_extent_num_bytes(leaf, fi) + end -
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册