linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>,
	dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/6] btrfs: Simplify extent type check
Date: Thu, 22 Aug 2019 08:58:51 +0300	[thread overview]
Message-ID: <93cab3f5-6ad2-395c-516c-7150191427ae@suse.com> (raw)
In-Reply-To: <bb544b37-ed4c-f3f1-bf2a-df7b9a3b4479@gmx.com>



On 22.08.19 г. 2:47 ч., Qu Wenruo wrote:
> 
> 
> On 2019/8/21 下午11:40, David Sterba wrote:
>> On Mon, Aug 05, 2019 at 05:47:07PM +0300, Nikolay Borisov wrote:
>>> Extent type can only be regular/prealloc/inline. The main branch of the
>>> 'if' already handles the first two, leaving the 'else' to handle inline.
>>> Furthermore, tree-checker ensures that leaf items are correct.
>>>
>>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>>> ---
>>>  fs/btrfs/inode.c | 10 +++-------
>>>  1 file changed, 3 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
>>> index 8e24b7641247..6c3f9f3a7ed1 100644
>>> --- a/fs/btrfs/inode.c
>>> +++ b/fs/btrfs/inode.c
>>> @@ -1502,18 +1502,14 @@ static noinline int run_delalloc_nocow(struct inode *inode,
>>>  			if (!btrfs_inc_nocow_writers(fs_info, disk_bytenr))
>>>  				goto out_check;
>>>  			nocow = true;
>>> -		} else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
>>> -			extent_end = found_key.offset +
>>> -				btrfs_file_extent_ram_bytes(leaf, fi);
>>> -			extent_end = ALIGN(extent_end,
>>> -					   fs_info->sectorsize);
>>> +		} else {
>>> +			extent_end = found_key.offset + ram_bytes;
>>> +			extent_end = ALIGN(extent_end, fs_info->sectorsize);
>>>  			/* Skip extents outside of our requested range */
>>>  			if (extent_end <= start) {
>>>  				path->slots[0]++;
>>>  				goto next_slot;
>>>  			}
>>> -		} else {
>>> -			BUG();
>>
>> I am not sure if we should delete this or leave it (with a message what
>> happened). There are other places that switch value from a known set and
>> have a catch-all branch.
> 
> We can just delete it IHMO.
> 
> That's why we have tree-checker, we have ensured at least EXTENT_DATA
> item read from disk doesn't contain invalid type.
> So removing the BUG() here should be OK.
> 
> Although converting it to a better error handler won't hurt.
> In that case it can catch runtime memory corruption earlier.

IMO it's counter productive to have duplicated checks. That's just more
code that someone needs to grok down the line when they need to
understand the code. If the tree-checker was an optional feature - then
perhaps it makes sense. But since the tree-checker is, so to speak, the
outer layer of protection, ensuring the btrfs shouldn't work with
invalid data then I'd rather remove the check.

> 
> Thanks,
> Qu
> 
>>
>> With your change the 'catch-all' is the inline extent type. It's true
>> that the checker should not let an unknown type appear in this code,
>> however I'd rather make it explicit that something is seriously wrong if
>> there's an unexpected type rather than silently continuing.
>>
>> The BUG can be turned to actual error handling so we don't need to crash
>> at least.
>>
> 

  reply	other threads:[~2019-08-22  5:58 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-05 14:47 [PATCH 0/6] Refactor nocow path Nikolay Borisov
2019-08-05 14:47 ` [PATCH 1/6] btrfs: Refactor run_delalloc_nocow Nikolay Borisov
2019-08-21  7:42   ` [PATCH v2 1/2] " Nikolay Borisov
2019-08-21 15:03     ` David Sterba
2019-08-05 14:47 ` [PATCH 2/6] btrfs: Improve comments around nocow path Nikolay Borisov
2019-08-06 10:09   ` Filipe Manana
2019-08-07  8:16     ` Nikolay Borisov
2019-08-07  8:26       ` Filipe Manana
2019-08-21  7:42   ` [PATCH v2 2/2] " Nikolay Borisov
2019-08-21 15:10     ` David Sterba
2019-08-05 14:47 ` [PATCH 3/6] btrfs: Simplify run_delalloc_nocow Nikolay Borisov
2019-08-06  9:01   ` Johannes Thumshirn
2019-08-05 14:47 ` [PATCH 4/6] btrfs: Streamline code in run_delalloc_nocow in case of inline extents Nikolay Borisov
2019-08-21 15:17   ` David Sterba
2019-08-05 14:47 ` [PATCH 5/6] btrfs: Simplify extent type check Nikolay Borisov
2019-08-06 10:14   ` Filipe Manana
2019-08-21 15:40   ` David Sterba
2019-08-21 23:47     ` Qu Wenruo
2019-08-22  5:58       ` Nikolay Borisov [this message]
2019-08-22 14:25     ` [PATCH] btrfs: Streamline code in run_delalloc_nocow Nikolay Borisov
2019-08-23 17:27       ` David Sterba
2019-08-05 14:47 ` [PATCH 6/6] btrfs: Remove BUG_ON from run_delalloc_nocow Nikolay Borisov
2019-08-06 10:34   ` Filipe Manana
2019-08-07  8:18     ` Nikolay Borisov
2019-08-21 15:55       ` David Sterba
2019-08-22 14:24         ` [PATCH v2] " Nikolay Borisov
2019-08-23 17:28           ` David Sterba
2019-08-19 16:42 ` [PATCH 0/6] Refactor nocow path David Sterba
2019-08-21 15:59 ` 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=93cab3f5-6ad2-395c-516c-7150191427ae@suse.com \
    --to=nborisov@suse.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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 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).