From: Dan Carpenter <dan.carpenter@oracle.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [bug report] btrfs: get rid of trivial __btrfs_lookup_bio_sums() wrappers
Date: Tue, 7 Jan 2020 19:52:43 +0300 [thread overview]
Message-ID: <20200107165243.GE27042@kadam> (raw)
In-Reply-To: <20200107164108.GB3929@twin.jikos.cz>
On Tue, Jan 07, 2020 at 05:41:09PM +0100, David Sterba wrote:
> On Tue, Jan 07, 2020 at 05:10:46PM +0100, David Sterba wrote:
> > On Tue, Jan 07, 2020 at 11:10:58AM +0300, Dan Carpenter wrote:
> > > 276 diff = diff * csum_size;
> > > 277 count = min_t(int, nblocks, (item_last_offset - disk_bytenr) >>
> > > 278 inode->i_sb->s_blocksize_bits);
> > > 279 read_extent_buffer(path->nodes[0], csum,
> > > 280 ((unsigned long)item) + diff,
> > > 281 csum_size * count);
> > > 282 found:
> > > 283 csum += count * csum_size;
> > > 284 nblocks -= count;
> > > 285 next:
> > > 286 while (count--) {
> > > ^^^^^^^
> > > This loop exits with count set to -1.
> > >
> > > 287 disk_bytenr += fs_info->sectorsize;
> > > 288 offset += fs_info->sectorsize;
> > > 289 page_bytes_left -= fs_info->sectorsize;
> > > 290 if (!page_bytes_left)
> > > 291 break; /* move to next bio */
> > > 292 }
> > > 293 }
> > > 294
> > > 295 WARN_ON_ONCE(count);
> > > ^^^^^
> > > Originally this warning was next to the line 291 so it should probably
> > > be "WARN_ON_ONCE(count >= 0);" This WARN is two years old now and no
> > > one has complained about it at run time. That's very surprising to me
> > > because I would have expected count to -1 in the common case.
> >
> > Possible explanation I see is that the "if (!page_bytes_left)" does not
> > let the count go from 0 -> -1 and exits just in time. I'm runing a test
> > to see if it's true.
>
> It is. It's not very clear from the context, count is set up so that it
> matches page_bytes_left decrements. So using "count--" is not completely
> wrong, but it is confusing and relying on other subtle behaviour. It
> should be either --count or the decrement moved to out of the condition.
>
> I can write the patch and add you as reporter or you can send the patch
> as you did the analysis in the first place.
Could you add me as the reporter? I'd feel uncomfortable changing the
code here when I don't really understand it.
regards,
dan carpenter
prev parent reply other threads:[~2020-01-07 16:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 8:10 [bug report] btrfs: get rid of trivial __btrfs_lookup_bio_sums() wrappers Dan Carpenter
2020-01-07 16:10 ` David Sterba
2020-01-07 16:41 ` David Sterba
2020-01-07 16:52 ` Dan Carpenter [this message]
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=20200107165243.GE27042@kadam \
--to=dan.carpenter@oracle.com \
--cc=dsterba@suse.cz \
--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