From: Dmitry Monakhov <dmonakhov@openvz.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, jack@suse.cz
Subject: Re: [PATCH 2/2] ext4: fix inode bitmaps manipulation in free_inode
Date: Sat, 17 Apr 2010 14:57:22 +0400 [thread overview]
Message-ID: <8739yu73e5.fsf@openvz.org> (raw)
In-Reply-To: <20100416010649.GA31409@thunk.org> (tytso@mit.edu's message of "Thu, 15 Apr 2010 21:06:50 -0400")
tytso@mit.edu writes:
> Here's my -V3 respin of this patch, which further cleans up the code
> and removes some duplicated code by only calling ext4_clear_bit() from
> one call site.
>
> I think I'm about done for this, so if you agree with my improvements
> as improvements, it might be useful to port this back to ext3 version
> of this patch.
Ok, agree that's looks better.
>
> - Ted
>
> ext4: clean up inode bitmaps manipulation in ext4_free_inode
>
> From: Dmitry Monakhov <dmonakhov@openvz.org>
>
> - Reorganize locking scheme to batch two atomic operation in to one.
> This also allow us to state what healthy group must obey following rule
> ext4_free_inodes_count(sb, gdp) == ext4_count_free(inode_bitmap, NUM);
> - Fix possible undefined pointer dereference.
> - Even if group descriptor stats aren't accessible we have to update
> inode bitmaps.
> - Move non-group members update out of group_lock.
>
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
> fs/ext4/ialloc.c | 81 ++++++++++++++++++++++++-----------------------------
> 1 files changed, 37 insertions(+), 44 deletions(-)
>
> diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
> index 57f6eef..52618d5 100644
> --- a/fs/ext4/ialloc.c
> +++ b/fs/ext4/ialloc.c
> @@ -240,56 +240,49 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
> if (fatal)
> goto error_return;
>
> - /* Ok, now we can actually update the inode bitmaps.. */
> - cleared = ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group),
> - bit, bitmap_bh->b_data);
> - if (!cleared)
> - ext4_error(sb, "bit already cleared for inode %lu", ino);
> - else {
> - gdp = ext4_get_group_desc(sb, block_group, &bh2);
> -
> + fatal = -ESRCH;
> + gdp = ext4_get_group_desc(sb, block_group, &bh2);
> + if (gdp) {
> BUFFER_TRACE(bh2, "get_write_access");
> fatal = ext4_journal_get_write_access(handle, bh2);
> - if (fatal) goto error_return;
> -
> - if (gdp) {
> - ext4_lock_group(sb, block_group);
> - count = ext4_free_inodes_count(sb, gdp) + 1;
> - ext4_free_inodes_set(sb, gdp, count);
> - if (is_directory) {
> - count = ext4_used_dirs_count(sb, gdp) - 1;
> - ext4_used_dirs_set(sb, gdp, count);
> - if (sbi->s_log_groups_per_flex) {
> - ext4_group_t f;
> -
> - f = ext4_flex_group(sbi, block_group);
> - atomic_dec(&sbi->s_flex_groups[f].used_dirs);
> - }
> + }
> + ext4_lock_group(sb, block_group);
> + cleared = ext4_clear_bit(bit, bitmap_bh->b_data);
> + if (fatal || !cleared) {
> + ext4_unlock_group(sb, block_group);
> + goto out;
> + }
>
> - }
> - gdp->bg_checksum = ext4_group_desc_csum(sbi,
> - block_group, gdp);
> - ext4_unlock_group(sb, block_group);
> - percpu_counter_inc(&sbi->s_freeinodes_counter);
> - if (is_directory)
> - percpu_counter_dec(&sbi->s_dirs_counter);
> -
> - if (sbi->s_log_groups_per_flex) {
> - ext4_group_t f;
> -
> - f = ext4_flex_group(sbi, block_group);
> - atomic_inc(&sbi->s_flex_groups[f].free_inodes);
> - }
> - }
> - BUFFER_TRACE(bh2, "call ext4_handle_dirty_metadata");
> - err = ext4_handle_dirty_metadata(handle, NULL, bh2);
> - if (!fatal) fatal = err;
> + count = ext4_free_inodes_count(sb, gdp) + 1;
> + ext4_free_inodes_set(sb, gdp, count);
> + if (is_directory) {
> + count = ext4_used_dirs_count(sb, gdp) - 1;
> + ext4_used_dirs_set(sb, gdp, count);
> + percpu_counter_dec(&sbi->s_dirs_counter);
> }
> - BUFFER_TRACE(bitmap_bh, "call ext4_handle_dirty_metadata");
> - err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
> - if (!fatal)
> - fatal = err;
> - sb->s_dirt = 1;
> + gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp);
> + ext4_unlock_group(sb, block_group);
> +
> + percpu_counter_inc(&sbi->s_freeinodes_counter);
> + if (sbi->s_log_groups_per_flex) {
> + ext4_group_t f = ext4_flex_group(sbi, block_group);
> +
> + atomic_inc(&sbi->s_flex_groups[f].free_inodes);
> + if (is_directory)
> + atomic_dec(&sbi->s_flex_groups[f].used_dirs);
> + }
> + BUFFER_TRACE(bh2, "call ext4_handle_dirty_metadata");
> + fatal = ext4_handle_dirty_metadata(handle, NULL, bh2);
> +out:
> + if (cleared) {
> + BUFFER_TRACE(bitmap_bh, "call ext4_handle_dirty_metadata");
> + err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
> + if (!fatal)
> + fatal = err;
> + sb->s_dirt = 1;
> + } else
> + ext4_error(sb, "bit already cleared for inode %lu", ino);
> +
> error_return:
> brelse(bitmap_bh);
> ext4_std_error(sb, fatal);
next prev parent reply other threads:[~2010-04-17 10:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-14 11:19 ext34_free_inode's mess Dmitry Monakhov
2010-04-14 11:23 ` [PATCH 1/2] ext3: fix inode bitmaps manipulation in free_inode Dmitry Monakhov
2010-04-14 11:23 ` [PATCH 2/2] ext4: " Dmitry Monakhov
2010-04-15 0:12 ` tytso
2010-04-16 1:06 ` tytso
2010-04-17 10:57 ` Dmitry Monakhov [this message]
2010-04-14 11:35 ` ext34_free_inode's mess Dmitry Monakhov
2010-04-14 13:34 ` Jan Kara
2010-04-14 14:33 ` Dmitry Monakhov
2010-04-15 21:39 ` Jan Kara
2010-04-15 22:01 ` Dmitry Monakhov
2010-04-16 13:33 ` tytso
2010-04-14 16:03 ` Eric Sandeen
2010-04-14 16:01 ` Eric Sandeen
2010-04-14 16:01 ` Eric Sandeen
2010-04-14 16:56 ` Dmitry Monakhov
2010-04-14 23:47 ` Dave Chinner
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=8739yu73e5.fsf@openvz.org \
--to=dmonakhov@openvz.org \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.