ext4: check free inode count before allocating an inode
authorYongqiang Yang <xiaoqiangnk@gmail.com>
Mon, 24 Sep 2012 03:16:03 +0000 (23:16 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 24 Sep 2012 03:16:03 +0000 (23:16 -0400)
Recently, I ecountered some corrupted filesystems in which some
groups' free inode counts were 65535, it seemed that free inode
count was overflow.  This patch teaches ext4 to check free inode
count before allocaing an inode.

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/ialloc.c

index 26154b81b83679aaf711f52477f2d048d6078d5a..fa36372f3fdf827ed2557a3ecf5ccceab9e2cfe1 100644 (file)
@@ -697,6 +697,15 @@ got_group:
                if (!gdp)
                        goto fail;
 
+               /*
+                * Check free inodes count before loading bitmap.
+                */
+               if (ext4_free_inodes_count(sb, gdp) == 0) {
+                       if (++group == ngroups)
+                               group = 0;
+                       continue;
+               }
+
                brelse(inode_bitmap_bh);
                inode_bitmap_bh = ext4_read_inode_bitmap(sb, group);
                if (!inode_bitmap_bh)