Whamcloud - gitweb
resize2fs: Clean up the resize inode properly if necessary
authorTheodore Ts'o <tytso@mit.edu>
Thu, 10 Jul 2008 18:18:41 +0000 (14:18 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 10 Jul 2008 18:18:41 +0000 (14:18 -0400)
If the filesystem is grown to the point where the resize_inode is no
longer needed, clean it up properly so e2fsck doesn't have to.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
resize/resize2fs.c

index 05650a8..84db121 100644 (file)
@@ -310,9 +310,6 @@ retry:
                if (new > (int) fs->blocksize/4)
                        new = fs->blocksize/4;
                fs->super->s_reserved_gdt_blocks = new;
-               if (new == 0)
-                       fs->super->s_feature_compat &= 
-                               ~EXT2_FEATURE_COMPAT_RESIZE_INODE;
        }
 
        /*
@@ -1536,6 +1533,7 @@ static errcode_t fix_resize_inode(ext2_filsys fs)
        struct ext2_inode       inode;
        errcode_t               retval;
        char *                  block_buf;
+       blk_t                   blk;
 
        if (!(fs->super->s_feature_compat & 
              EXT2_FEATURE_COMPAT_RESIZE_INODE))
@@ -1547,6 +1545,20 @@ static errcode_t fix_resize_inode(ext2_filsys fs)
        retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
        if (retval) goto errout;
 
+       if (fs->super->s_reserved_gdt_blocks == 0) {
+               fs->super->s_feature_compat &= 
+                       ~EXT2_FEATURE_COMPAT_RESIZE_INODE;
+               ext2fs_mark_super_dirty(fs);
+
+               if ((blk = inode.i_block[EXT2_DIND_BLOCK]) != 0)
+                       ext2fs_block_alloc_stats(fs, blk, -1);
+
+               memset(&inode, 0, sizeof(inode));
+
+               retval = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode);
+               goto errout;
+       }
+
        ext2fs_iblk_set(fs, &inode, 1);
 
        retval = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode);