From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Roman Mamedov <rm@romanrm.net>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: Move loop termination condition in while()
Date: Wed, 1 Nov 2017 19:00:39 +0100 [thread overview]
Message-ID: <20171101180039.GH3521@twin.jikos.cz> (raw)
In-Reply-To: <5cfe8dab-eadf-069a-4abf-bbb0d696d214@suse.com>
On Wed, Nov 01, 2017 at 12:42:18PM +0200, Nikolay Borisov wrote:
>
>
> On 1.11.2017 11:46, Roman Mamedov wrote:
> > On Wed, 1 Nov 2017 11:32:18 +0200
> > Nikolay Borisov <nborisov@suse.com> wrote:
> >
> >> Fallocating a file in btrfs goes through several stages. The one before actually
> >> inserting the fallocated extents is to create a qgroup reservation, covering
> >> the desired range. To this end there is a loop in btrfs_fallocate which checks
> >> to see if there are holes in the fallocated range or !PREALLOC extents past EOF
> >> and if so create qgroup reservations for them. Unfortunately, the main condition
> >> of the loop is burried right at the end of its body rather than in the actual
> >> while statement which makes it non-obvious. Fix this by moving the condition
> >> in the while statement where it belongs. No functional changes.
> >
> > If it turns out that "cur_offset >= alloc_end" from the get go, previously the
> > loop body would be entered and executed once. With this change, it will not
> > anymore.
>
> Good point, however this cannot happen, because for this to happen then
> the following 2 expression need to be equal:
>
> alloc_start = round_down(offset, blocksize);
> alloc_end = round_up(offset + len, blocksize);
>
> However, len is guaranteed to be > 0 due to a check in vfs_fallocate so
> those can't really be equal.
Agreed, and
Reviewed-by: David Sterba <dsterba@suse.com>
prev parent reply other threads:[~2017-11-01 18:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-01 9:32 [PATCH] btrfs: Move loop termination condition in while() Nikolay Borisov
2017-11-01 9:46 ` Roman Mamedov
2017-11-01 10:42 ` Nikolay Borisov
2017-11-01 18:00 ` David Sterba [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=20171101180039.GH3521@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=rm@romanrm.net \
/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).