linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Josef Bacik <josef@toxicpanda.com>,
	linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH 1/5] btrfs: drop log root for dropped roots
Date: Fri, 6 Dec 2019 17:03:36 +0200	[thread overview]
Message-ID: <5e60e26f-8993-ca16-2a93-48d5948ed961@suse.com> (raw)
In-Reply-To: <20191206143718.167998-2-josef@toxicpanda.com>



On 6.12.19 г. 16:37 ч., Josef Bacik wrote:
> If we fsync on a subvolume and create a log root for that volume, and
> then later delete that subvolume we'll never clean up its log root.  Fix
> this by making switch_commit_roots free the log for any dropped roots we
> encounter.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/transaction.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index cfc08ef9b876..55d8fd68775a 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -147,13 +147,14 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
>  	}
>  }
>  
> -static noinline void switch_commit_roots(struct btrfs_transaction *trans)
> +static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
>  {
> +	struct btrfs_transaction *cur_trans = trans->transaction;
>  	struct btrfs_fs_info *fs_info = trans->fs_info;
>  	struct btrfs_root *root, *tmp;
>  
>  	down_write(&fs_info->commit_root_sem);
> -	list_for_each_entry_safe(root, tmp, &trans->switch_commits,
> +	list_for_each_entry_safe(root, tmp, &cur_trans->switch_commits,
>  				 dirty_list) {
>  		list_del_init(&root->dirty_list);
>  		free_extent_buffer(root->commit_root);
> @@ -165,16 +166,17 @@ static noinline void switch_commit_roots(struct btrfs_transaction *trans)
>  	}
>  
>  	/* We can free old roots now. */
> -	spin_lock(&trans->dropped_roots_lock);
> -	while (!list_empty(&trans->dropped_roots)) {
> -		root = list_first_entry(&trans->dropped_roots,
> +	spin_lock(&cur_trans->dropped_roots_lock);
> +	while (!list_empty(&cur_trans->dropped_roots)) {
> +		root = list_first_entry(&cur_trans->dropped_roots,
>  					struct btrfs_root, root_list);
>  		list_del_init(&root->root_list);
> -		spin_unlock(&trans->dropped_roots_lock);
> +		spin_unlock(&cur_trans->dropped_roots_lock);
> +		btrfs_free_log(trans, root);

THis patch should really have been this line and converting
switch_commit_roots to taking a trans handle another patch. Otherwise
this is lost in the mechanical refactoring.

>  		btrfs_drop_and_free_fs_root(fs_info, root);
> -		spin_lock(&trans->dropped_roots_lock);
> +		spin_lock(&cur_trans->dropped_roots_lock);
>  	}
> -	spin_unlock(&trans->dropped_roots_lock);
> +	spin_unlock(&cur_trans->dropped_roots_lock);
>  	up_write(&fs_info->commit_root_sem);
>  }
>  
> @@ -1421,7 +1423,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
>  	ret = commit_cowonly_roots(trans);
>  	if (ret)
>  		goto out;
> -	switch_commit_roots(trans->transaction);
> +	switch_commit_roots(trans);
>  	ret = btrfs_write_and_wait_transaction(trans);
>  	if (ret)
>  		btrfs_handle_fs_error(fs_info, ret,
> @@ -2301,7 +2303,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
>  	list_add_tail(&fs_info->chunk_root->dirty_list,
>  		      &cur_trans->switch_commits);
>  
> -	switch_commit_roots(cur_trans);
> +	switch_commit_roots(trans);
>  
>  	ASSERT(list_empty(&cur_trans->dirty_bgs));
>  	ASSERT(list_empty(&cur_trans->io_bgs));
> 

  parent reply	other threads:[~2019-12-06 15:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 14:37 [PATCH 0/5] Various fixes Josef Bacik
2019-12-06 14:37 ` [PATCH 1/5] btrfs: drop log root for dropped roots Josef Bacik
2019-12-06 15:02   ` Filipe Manana
2019-12-06 15:03   ` Nikolay Borisov [this message]
2019-12-09 17:39     ` David Sterba
2019-12-10 20:05     ` Josef Bacik
2019-12-10 21:19       ` Nikolay Borisov
2019-12-10 21:28         ` Josef Bacik
2019-12-13 15:17           ` David Sterba
2019-12-06 14:37 ` [PATCH 2/5] btrfs: don't BUG_ON in create_subvol Josef Bacik
2019-12-06 15:03   ` Filipe Manana
2019-12-09 10:49   ` Johannes Thumshirn
2019-12-06 14:37 ` [PATCH 3/5] btrfs: handle ENOENT in btrfs_uuid_tree_iterate Josef Bacik
2019-12-06 15:13   ` Filipe Manana
2019-12-06 15:17     ` Josef Bacik
2019-12-06 16:39   ` [PATCH 3/5][v2] " Josef Bacik
2019-12-06 16:46     ` Filipe Manana
2019-12-09 10:52     ` Johannes Thumshirn
2019-12-06 14:37 ` [PATCH 4/5] btrfs: skip log replay on orphaned roots Josef Bacik
2019-12-06 15:23   ` Filipe Manana
2019-12-06 14:37 ` [PATCH 5/5] btrfs: do not leak reloc root if we fail to read the fs root Josef Bacik
2019-12-06 15:24   ` Filipe Manana
2019-12-09 10:58   ` Johannes Thumshirn
2019-12-09 18:16 ` [PATCH 0/5] Various 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=5e60e26f-8993-ca16-2a93-48d5948ed961@suse.com \
    --to=nborisov@suse.com \
    --cc=josef@toxicpanda.com \
    --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;
as well as URLs for NNTP newsgroup(s).