Skip to content

Commit 3eb4234

Browse files
fdmananakdave
authored andcommitted
btrfs: remove outdated logic from overwrite_item() and add assertion
As of commit 193df62 ("btrfs: search for last logged dir index if it's not cached in the inode"), the overwrite_item() function is always called for a root that is from a fs/subvolume tree. In other words, now it's only used during log replay to modify a fs/subvolume tree. Therefore we can remove the logic that checks if we are dealing with a log tree at overwrite_item(). So remove that logic, replacing it with an assertion and document that if we ever need to support a log root there, we will need to clone the leaf from the fs/subvolume tree and then release it before modifying the log tree, which is needed to avoid a potential deadlock, similar to the one recently fixed by a patch with the subject: "btrfs: do not modify log tree while holding a leaf from fs tree locked" Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 3a8d1db commit 3eb4234

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

fs/btrfs/tree-log.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,16 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
391391
int save_old_i_size = 0;
392392
unsigned long src_ptr;
393393
unsigned long dst_ptr;
394-
int overwrite_root = 0;
395394
bool inode_item = key->type == BTRFS_INODE_ITEM_KEY;
396395

397-
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
398-
overwrite_root = 1;
396+
/*
397+
* This is only used during log replay, so the root is always from a
398+
* fs/subvolume tree. In case we ever need to support a log root, then
399+
* we'll have to clone the leaf in the path, release the path and use
400+
* the leaf before writing into the log tree. See the comments at
401+
* copy_items() for more details.
402+
*/
403+
ASSERT(root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID);
399404

400405
item_size = btrfs_item_size(eb, slot);
401406
src_ptr = btrfs_item_ptr_offset(eb, slot);
@@ -548,8 +553,7 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
548553
goto no_copy;
549554
}
550555

551-
if (overwrite_root &&
552-
S_ISDIR(btrfs_inode_mode(eb, src_item)) &&
556+
if (S_ISDIR(btrfs_inode_mode(eb, src_item)) &&
553557
S_ISDIR(btrfs_inode_mode(path->nodes[0], dst_item))) {
554558
save_old_i_size = 1;
555559
saved_i_size = btrfs_inode_size(path->nodes[0],

0 commit comments

Comments
 (0)