From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org,
David Sterba <dsterba@suse.com>,
Jean-Christophe Guillain <jean-christophe@guillain.net>
Subject: Re: [PATCH v2] btrfs: zlib: handle page aligned compressed size correctly
Date: Wed, 18 Mar 2026 07:56:49 +1030 [thread overview]
Message-ID: <b44dfabe-32fc-4ced-a000-cd05893b00e8@gmx.com> (raw)
In-Reply-To: <20260317101157.GS5735@twin.jikos.cz>
在 2026/3/17 20:41, David Sterba 写道:
> On Fri, Mar 13, 2026 at 06:35:26PM +1030, Qu Wenruo wrote:
[...]
>> diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
>> index 1a5093525e32..147c92a4dd04 100644
>> --- a/fs/btrfs/zlib.c
>> +++ b/fs/btrfs/zlib.c
>> @@ -308,7 +308,9 @@ int zlib_compress_bio(struct list_head *ws, struct compressed_bio *cb)
>> }
>> /* Queue the remaining part of the folio. */
>
> Maybe update this comment with brief description of the tricky case.
To be honest, the tricky case is not tricky at all.
It's myself considering large folios and bs > ps cases too much.
The new code is in fact more straightforward, if there are new output,
total_out - bi_size is exactly the length of the new output.
And the output length is already limited by folio_size, there is no need
and shouldn't use offset_in_folio().
The offset_in_folio() looks sane on a quick glance, but if you put all
the corner values (0, and folio_size) into it, it only passes the 0 case
but not the folio_size case.
So there is no tricky case in the first place, it's all my fault making
things way too complex and shoot myself in the foot.
Thanks,
Qu
>
>> if (workspace->strm.total_out > bio->bi_iter.bi_size) {
>> - u32 cur_len = offset_in_folio(out_folio, workspace->strm.total_out);
>> + const u32 cur_len = workspace->strm.total_out - bio->bi_iter.bi_size;
>> +
>> + ASSERT(cur_len <= folio_size(out_folio));
>>
>> if (!bio_add_folio(bio, out_folio, cur_len, 0)) {
>> ret = -E2BIG;
>> --
>> 2.53.0
>>
>
prev parent reply other threads:[~2026-03-17 21:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 8:05 [PATCH v2] btrfs: zlib: handle page aligned compressed size correctly Qu Wenruo
2026-03-13 17:12 ` Jean-Christophe Guillain
2026-03-17 10:11 ` David Sterba
2026-03-17 21:26 ` Qu Wenruo [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=b44dfabe-32fc-4ced-a000-cd05893b00e8@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=jean-christophe@guillain.net \
--cc=linux-btrfs@vger.kernel.org \
--cc=stable@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox