From: "Stephen C. Tweedie" <sct@redhat.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: ext4 development <linux-ext4@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
hooanon05@yahoo.co.jp, Andrew Morton <akpm@osdl.org>,
Stephen Tweedie <sct@redhat.com>
Subject: Re: [PATCH] ext34: ensure do_split leaves enough free space in both blocks
Date: Tue, 18 Sep 2007 18:41:11 +0100 [thread overview]
Message-ID: <1190137272.27889.19.camel@sisko.scot.redhat.com> (raw)
In-Reply-To: <46EEA5F4.3030806@redhat.com>
Hi,
On Mon, 2007-09-17 at 11:06 -0500, Eric Sandeen wrote:
> The do_split() function for htree dir blocks is intended to split a
> leaf block to make room for a new entry. It sorts the entries in the
> original block by hash value, then moves the last half of the entries to
> the new block - without accounting for how much space this actually moves.
Nasty.
> Also add a few comments to the functions involved.
A big improvement. :)
> + /* Split the existing block in the middle, size-wise */
> + size = 0;
> + move = 0;
> + for (i = count-1; i >= 0; i--) {
> + /* is more than half of this entry in 2nd half of the block? */
> + if (size + map[i].size/2 > blocksize/2)
> + break;
> + size += map[i].size;
> + move++;
> + }
> + /* map index at which we will split */
> + split = count - move;
This is the guts of it, and I spent a while looking just to convince
myself it was getting things right in the corner case and was splitting
at _exactly_ the right point. If we have large dirents and 1k
blocksize, even getting the split point off-by-one will still leave us
vulnerable to the bug.
But it all looks fine. My only other comment would be that "move" is
redundant, you could lose it completely and just do
split = i+1;
but I think the logic's easier to understand the way it is.
Nice catch.
--Stephen
prev parent reply other threads:[~2007-09-18 17:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-17 16:06 [PATCH] ext34: ensure do_split leaves enough free space in both blocks Eric Sandeen
2007-09-17 17:21 ` Eric Sandeen
2007-09-17 20:30 ` Andrew Morton
2007-09-17 20:57 ` Andreas Dilger
2007-09-18 0:16 ` hooanon05
2007-09-18 17:41 ` Stephen C. Tweedie [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=1190137272.27889.19.camel@sisko.scot.redhat.com \
--to=sct@redhat.com \
--cc=akpm@osdl.org \
--cc=hooanon05@yahoo.co.jp \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sandeen@redhat.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