Skip to content

Commit a20f732

Browse files
fdmananakdave
authored andcommitted
btrfs: simplify getting and extracting previous transaction at clean_pinned_extents()
Instead of detecting if there is a previous transaction by comparing the current transaction's list prev member to the head of the transaction list (fs_info->trans_list), use the list_is_first() helper which contains that logic and the naming makes sense since a new transaction is always added to the end of the list fs_info->trans_list with list_add_tail(). We are also extracting the previous transaction with list_last_entry() against the transaction, which is correct but confusing because that function is usually meant to be used against a pointer to the start of a list and not a member of a list. It is easier to reason by either calling list_first_entry() against the list fs_info->trans_list, since we can never have more than two transactions in the list, or by calling list_prev_entry() against the transaction. So change that to use the later method. 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 d887f03 commit a20f732

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

fs/btrfs/block-group.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,9 +1418,8 @@ static bool clean_pinned_extents(struct btrfs_trans_handle *trans,
14181418
int ret;
14191419

14201420
spin_lock(&fs_info->trans_lock);
1421-
if (trans->transaction->list.prev != &fs_info->trans_list) {
1422-
prev_trans = list_last_entry(&trans->transaction->list,
1423-
struct btrfs_transaction, list);
1421+
if (!list_is_first(&trans->transaction->list, &fs_info->trans_list)) {
1422+
prev_trans = list_prev_entry(trans->transaction, list);
14241423
refcount_inc(&prev_trans->use_count);
14251424
}
14261425
spin_unlock(&fs_info->trans_lock);

0 commit comments

Comments
 (0)