linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH] e2fsck: update global free blocks/inodes count when truncating orphan inodes
Date: Mon, 11 Jun 2012 22:22:42 -0400	[thread overview]
Message-ID: <1339467762-5725-1-git-send-email-tytso@mit.edu> (raw)

By the time we start processing the orphan inode list, we have already
calculated the total expected number of free blocks and inodes in
ctx->free_{blocks,inodes}.  This is used to set the free blocks/inodes
count in the superblock in the case where we don't need to do a full
e2fsck.

We need to update these expected free block counts as we process the
orphan inode list so that superblock values are set correctly.
Otherwise we could have the following happen:

% e2fsck /tmp/test.img
e2fsck 1.42.3 (14-May-2012)
Truncating orphaned inode 12 (uid=0, gid=0, mode=0100644, size=0)
Setting free blocks count to 46 (was 79)
/tmp/test.img: clean, 12/16 files, 54/100 blocks

% e2fsck /tmp/test.img
e2fsck 1.42.3 (14-May-2012)
Setting free blocks count to 79 (was 46)
/tmp/test.img: clean, 12/16 files, 21/100 blocks

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 e2fsck/super.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/e2fsck/super.c b/e2fsck/super.c
index 6c18d0e..160991d 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -143,6 +143,7 @@ static int release_inode_block(ext2_filsys fs,
 	}
 
 	ext2fs_block_alloc_stats2(fs, blk, -1);
+	ctx->free_blocks++;
 	return retval;
 }
 
@@ -211,9 +212,11 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
 				ino);
 			return 1;
 		}
-		if (count == 0)
+		if (count == 0) {
 			ext2fs_block_alloc_stats2(fs,
 					ext2fs_file_acl_block(fs, inode), -1);
+			ctx->free_blocks++;
+		}
 		ext2fs_file_acl_block_set(fs, inode, 0);
 	}
 	return 0;
@@ -286,6 +289,7 @@ static int release_orphan_inodes(e2fsck_t ctx)
 		if (!inode.i_links_count) {
 			ext2fs_inode_alloc_stats2(fs, ino, -1,
 						  LINUX_S_ISDIR(inode.i_mode));
+			ctx->free_inodes++;
 			inode.i_dtime = ctx->now;
 		} else {
 			inode.i_dtime = 0;
-- 
1.7.10.2.552.gaa3bb87


             reply	other threads:[~2012-06-12  2:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-12  2:22 Theodore Ts'o [this message]
2012-06-12  5:45 ` [PATCH 1/2] libext2fs: fix block iterator for extents when truncating inodes Theodore Ts'o
2012-06-12  5:45   ` [PATCH 2/2] tests: add two more tests of orphaned inode handling Theodore Ts'o
2012-06-13  6:44     ` Andreas Dilger
2012-06-13 13:26       ` Ted Ts'o

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=1339467762-5725-1-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --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).