linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-ext4@vger.kernel.org
Cc: jack@suse.cz, Dmitry Monakhov <dmonakhov@openvz.org>
Subject: [PATCH 1/2] ext3: fix inode bitmaps manipulation in free_inode
Date: Wed, 14 Apr 2010 15:23:03 +0400	[thread overview]
Message-ID: <1271244184-8693-1-git-send-email-dmonakhov@openvz.org> (raw)
In-Reply-To: <87pr2246y4.fsf@openvz.org>

- Reorganize locking scheme to batch two atomic operation in to one.
- Fix possible undefined pointer deference.
- Even if group descriptor stats aren't assessable we have to update
  inode bitmaps.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 fs/ext3/ialloc.c |   62 +++++++++++++++++++++++++++--------------------------
 1 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index ef9008b..8352a68 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -98,7 +98,7 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
 	struct ext3_group_desc * gdp;
 	struct ext3_super_block * es;
 	struct ext3_sb_info *sbi;
-	int fatal = 0, err;
+	int fatal = 0, err, cleared = 0;
 
 	if (atomic_read(&inode->i_count) > 1) {
 		printk ("ext3_free_inode: inode has count=%d\n",
@@ -150,38 +150,40 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
 	if (fatal)
 		goto error_return;
 
-	/* Ok, now we can actually update the inode bitmaps.. */
-	if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
-					bit, bitmap_bh->b_data))
-		ext3_error (sb, "ext3_free_inode",
-			      "bit already cleared for inode %lu", ino);
-	else {
-		gdp = ext3_get_group_desc (sb, block_group, &bh2);
-
+	fatal = -ESRCH;
+	gdp = ext3_get_group_desc (sb, block_group, &bh2);
+	if (gdp) {
 		BUFFER_TRACE(bh2, "get_write_access");
 		fatal = ext3_journal_get_write_access(handle, bh2);
-		if (fatal) goto error_return;
-
-		if (gdp) {
-			spin_lock(sb_bgl_lock(sbi, block_group));
-			le16_add_cpu(&gdp->bg_free_inodes_count, 1);
-			if (is_directory)
-				le16_add_cpu(&gdp->bg_used_dirs_count, -1);
-			spin_unlock(sb_bgl_lock(sbi, block_group));
-			percpu_counter_inc(&sbi->s_freeinodes_counter);
-			if (is_directory)
-				percpu_counter_dec(&sbi->s_dirs_counter);
-
-		}
-		BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
-		err = ext3_journal_dirty_metadata(handle, bh2);
-		if (!fatal) fatal = err;
 	}
-	BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata");
-	err = ext3_journal_dirty_metadata(handle, bitmap_bh);
-	if (!fatal)
-		fatal = err;
+	spin_lock(sb_bgl_lock(sbi, block_group));
+	if (fatal) {
+		/* Skip group descriptor update, update only inode bitmaps */
+		cleared = ext3_clear_bit(bit, bitmap_bh->b_data);
+		spin_unlock(sb_bgl_lock(sbi, block_group));
+		goto out;
+	}
+	/* Ok, now we can actually update the inode bitmaps.. */
+	cleared = ext3_clear_bit(bit, bitmap_bh->b_data);
+	if (!cleared) {
+		spin_unlock(sb_bgl_lock(sbi, block_group));
+		goto out;
+	}
+	le16_add_cpu(&gdp->bg_free_inodes_count, 1);
+	if (is_directory)
+		le16_add_cpu(&gdp->bg_used_dirs_count, -1);
+	spin_unlock(sb_bgl_lock(sbi, block_group));
+	percpu_counter_inc(&sbi->s_freeinodes_counter);
+	if (is_directory)
+		percpu_counter_dec(&sbi->s_dirs_counter);
 
+	BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
+	err = ext3_journal_dirty_metadata(handle, bh2);
+out:
+	if (cleared) {
+		BUFFER_TRACE(bitmap_bh, "call ext3_journal_dirty_metadata");
+		fatal = ext3_journal_dirty_metadata(handle, bitmap_bh);
+	}
 error_return:
 	brelse(bitmap_bh);
 	ext3_std_error(sb, fatal);
-- 
1.6.6.1


  reply	other threads:[~2010-04-14 11:23 UTC|newest]

Thread overview: 16+ 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 ` Dmitry Monakhov [this message]
2010-04-14 11:23   ` [PATCH 2/2] ext4: fix inode bitmaps manipulation in free_inode Dmitry Monakhov
2010-04-15  0:12     ` tytso
2010-04-16  1:06       ` tytso
2010-04-17 10:57         ` Dmitry Monakhov
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: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=1271244184-8693-1-git-send-email-dmonakhov@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=jack@suse.cz \
    --cc=linux-ext4@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;
as well as URLs for NNTP newsgroup(s).