All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: dsterba@suse.cz, Damien Le Moal <Damien.LeMoal@wdc.com>,
	Qu Wenruo <quwenruo.btrfs@gmx.com>,
	Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	"13145886936@163.com" <13145886936@163.com>,
	"clm@fb.com" <clm@fb.com>,
	"josef@toxicpanda.com" <josef@toxicpanda.com>,
	"dsterba@suse.com" <dsterba@suse.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	gushengxian <gushengxian@yulong.com>
Subject: Re: [PATCH] btrfs: remove unneeded variable: "ret"
Date: Mon, 28 Jun 2021 14:51:29 +0200	[thread overview]
Message-ID: <20210628125129.GD2610@twin.jikos.cz> (raw)
In-Reply-To: <ce9083c7-ed1c-1248-484b-3b8650734f52@suse.com>

On Mon, Jun 28, 2021 at 08:19:28PM +0800, Qu Wenruo wrote:
> On 2021/6/28 下午8:04, David Sterba wrote:
> > On Mon, Jun 28, 2021 at 09:48:40AM +0000, Damien Le Moal wrote:
> >> This one is actually a good fix :)
> > 
> > It's not a good fix and has been posted several times already. What
> > needs to be done in this function is to propagate error codes from the
> > whole call tree starting in that function. Removing code triggering a
> > warning is perhaps the simplest thing to make the warning go away but
> > the right fix needs some understanding of the function and context.
> > 
> > The patch also comes without any explanation so that does not help to
> > back the intentions to remove it. Reveiew of such path is "Please
> > explain".
> > 
> > Replying to patches attempting to fix the warning (and not the code)
> > does not seem to help, it's just pointing to the previous iterations.
> 
> But in this particular patch, it's really doing proper cleanup.
> 
> The truth is, the whole function, btrfs_destroy_delayed_refs(), only get 
> called when a transaction is aborted, and to cleanup all pending delayed 
> refs.
> 
> Thus in this particular function, there is nothing to return an error, 
> since we're already erroring out.
> 
> And in fact we should use void for btrfs_destroy_delayed_refs().
> 
> Thus opposite to my initial thought, it's in fact OK for the cleanup.
> Just one step left to change the function to return void.
> 
> And obviously, with all these comment above added to commit message.

The logic about making a function void and removing the return value has
some assumptions:

- no BUG/BUG_ON inside the function itself
- all called functions are return-value clean and either handle
  everything transparently or return a value
- the above applies recursively to the whole call chain

btrfs_destroy_delayed_refs itself contains one BUG, so that needs to be
fixed. The whole problem of making it void is in the pinned rage, see
eg. btrfs_error_unpin_extent_range. Nikolay did some cleanups there but
there are still some BUGs left in place of error handling, namely in
unpin_extent_range and I did not check completely.

I understand that it's tempting to just turn the function to void,
because there's nothing obviously wrong, but that's only on first sight.
A proper review must follow the code and once there's unhandled error
deeper in the callchain, it has to be solved first.

IIRC we've cleaned most of if not all the easy cases so it may not be
that easy to identify something we haven't seen yet. I'll put something
to the wiki in case people are interested. There's
https://btrfs.wiki.kernel.org/index.php/Project_ideas#Cleanup_projects
it hasn't been up to date but it is the place where to look for such
things.

  parent reply	other threads:[~2021-06-28 12:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  8:30 [PATCH] btrfs: remove unneeded variable: "ret" 13145886936
2021-06-28  9:21 ` Qu Wenruo
2021-06-28  9:34   ` Damien Le Moal
2021-06-28  9:38     ` Johannes Thumshirn
2021-06-28  9:44       ` Qu Wenruo
2021-06-28  9:48         ` Damien Le Moal
2021-06-28  9:52           ` Qu Wenruo
2021-06-28 12:04           ` David Sterba
2021-06-28 12:13             ` Damien Le Moal
2021-06-28 12:19             ` Qu Wenruo
2021-06-28 12:43               ` Nikolay Borisov
2021-06-28 12:51               ` David Sterba [this message]
2021-06-28 11:38 ` Qu Wenruo

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=20210628125129.GD2610@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=13145886936@163.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=gushengxian@yulong.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    --cc=wqu@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.