public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Boris Burkov <boris@bur.io>,
	linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 3/5] btrfs: free qgroup pertrans rsv on trans abort
Date: Tue, 5 Dec 2023 07:38:00 +1030	[thread overview]
Message-ID: <23711b4d-4190-41ef-b325-a11cfc752ff1@gmx.com> (raw)
In-Reply-To: <07934597eaee1e2204c204bfd34bc628708e3739.1701464169.git.boris@bur.io>



On 2023/12/2 07:30, Boris Burkov wrote:
> If we abort a transaction, we never run the code that frees the pertrans
> qgroup reservation. This results in warnings on unmount as that
> reservation has been leaked. The leak isn't a huge issue since the fs is
> read-only, but it's better to clean it up when we know we can/should. Do
> it during the cleanup_transaction step of aborting.
>
> Signed-off-by: Boris Burkov <boris@bur.io>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/disk-io.c | 28 ++++++++++++++++++++++++++++
>   fs/btrfs/qgroup.c  |  5 +++--
>   2 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 9317606017e2..a1f440cd6d45 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -4775,6 +4775,32 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
>   	}
>   }
>
> +static void btrfs_free_all_qgroup_pertrans(struct btrfs_fs_info *fs_info)
> +{
> +	struct btrfs_root *gang[8];
> +	int i;
> +	int ret;
> +
> +	spin_lock(&fs_info->fs_roots_radix_lock);
> +	while (1) {
> +		ret = radix_tree_gang_lookup_tag(&fs_info->fs_roots_radix,
> +						 (void **)gang, 0,
> +						 ARRAY_SIZE(gang),
> +						 0); // BTRFS_ROOT_TRANS_TAG
> +		if (ret == 0)
> +			break;
> +		for (i = 0; i < ret; i++) {
> +			struct btrfs_root *root = gang[i];
> +
> +			btrfs_qgroup_free_meta_all_pertrans(root);
> +			radix_tree_tag_clear(&fs_info->fs_roots_radix,
> +					(unsigned long)root->root_key.objectid,
> +					0); // BTRFS_ROOT_TRANS_TAG
> +		}
> +	}
> +	spin_unlock(&fs_info->fs_roots_radix_lock);
> +}
> +
>   void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
>   				   struct btrfs_fs_info *fs_info)
>   {
> @@ -4803,6 +4829,8 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
>   				     EXTENT_DIRTY);
>   	btrfs_destroy_pinned_extent(fs_info, &cur_trans->pinned_extents);
>
> +	btrfs_free_all_qgroup_pertrans(fs_info);
> +
>   	cur_trans->state =TRANS_STATE_COMPLETED;
>   	wake_up(&cur_trans->commit_wait);
>   }
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index a953c16c7eb8..daec90342dad 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -4337,8 +4337,9 @@ static void qgroup_convert_meta(struct btrfs_fs_info *fs_info, u64 ref_root,
>
>   		qgroup_rsv_release(fs_info, qgroup, num_bytes,
>   				BTRFS_QGROUP_RSV_META_PREALLOC);
> -		qgroup_rsv_add(fs_info, qgroup, num_bytes,
> -				BTRFS_QGROUP_RSV_META_PERTRANS);
> +		if (!sb_rdonly(fs_info->sb))
> +			qgroup_rsv_add(fs_info, qgroup, num_bytes,
> +				       BTRFS_QGROUP_RSV_META_PERTRANS);
>
>   		list_for_each_entry(glist, &qgroup->groups, next_group)
>   			qgroup_iterator_add(&qgroup_list, glist->group);

  reply	other threads:[~2023-12-04 21:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01 21:00 [PATCH 0/5] btrfs: qgroups rsv fixes Boris Burkov
2023-12-01 21:00 ` [PATCH 1/5] btrfs: free qgroup rsv on ioerr ordered_extent Boris Burkov
2023-12-04 21:04   ` Qu Wenruo
2023-12-05 19:42     ` Boris Burkov
2023-12-05 20:16       ` Qu Wenruo
2023-12-01 21:00 ` [PATCH 2/5] btrfs: fix qgroup_free_reserved_data int overflow Boris Burkov
2023-12-04 21:07   ` Qu Wenruo
2023-12-01 21:00 ` [PATCH 3/5] btrfs: free qgroup pertrans rsv on trans abort Boris Burkov
2023-12-04 21:08   ` Qu Wenruo [this message]
2023-12-05 14:27   ` David Sterba
2023-12-05 19:45     ` Boris Burkov
2023-12-05 22:39       ` David Sterba
2023-12-01 21:00 ` [PATCH 4/5] btrfs: dont clear qgroup rsv bit in release_folio Boris Burkov
2023-12-04 21:09   ` Qu Wenruo
2023-12-01 21:00 ` [PATCH 5/5] btrfs: ensure releasing squota rsv on head refs Boris Burkov
2023-12-05 17:09 ` [PATCH 0/5] btrfs: qgroups rsv fixes David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23711b4d-4190-41ef-b325-a11cfc752ff1@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=boris@bur.io \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox