Skip to content

Commit d26d16a

Browse files
fdmananakdave
authored andcommitted
btrfs: simplify cow only root list extraction during transaction commit
There's no need to keep a local variable to extract the first member of the list and then do a list_entry() call, we can use list_first_entry() instead, removing the need for the temporary variable and extracting the first element in a single step. Also, there's no need to do a list_del_init() followed by list_add_tail(), instead we can use list_move_tail(). We are in transaction commit critical section where we don't need to worry about concurrency and that's why we don't take any locks and can use list_move_tail() (we do assert early at commit_cowonly_roots() that we are in the critical section, that the transaction's state is TRANS_STATE_COMMIT_DOING). Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a20f732 commit d26d16a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fs/btrfs/transaction.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,6 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans)
13271327
struct btrfs_fs_info *fs_info = trans->fs_info;
13281328
struct list_head *dirty_bgs = &trans->transaction->dirty_bgs;
13291329
struct list_head *io_bgs = &trans->transaction->io_bgs;
1330-
struct list_head *next;
13311330
struct extent_buffer *eb;
13321331
int ret;
13331332

@@ -1363,13 +1362,13 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans)
13631362
again:
13641363
while (!list_empty(&fs_info->dirty_cowonly_roots)) {
13651364
struct btrfs_root *root;
1366-
next = fs_info->dirty_cowonly_roots.next;
1367-
list_del_init(next);
1368-
root = list_entry(next, struct btrfs_root, dirty_list);
1365+
1366+
root = list_first_entry(&fs_info->dirty_cowonly_roots,
1367+
struct btrfs_root, dirty_list);
13691368
clear_bit(BTRFS_ROOT_DIRTY, &root->state);
1369+
list_move_tail(&root->dirty_list,
1370+
&trans->transaction->switch_commits);
13701371

1371-
list_add_tail(&root->dirty_list,
1372-
&trans->transaction->switch_commits);
13731372
ret = update_cowonly_root(trans, root);
13741373
if (ret)
13751374
return ret;

0 commit comments

Comments
 (0)