Whamcloud - gitweb
Transfer responsibility of setting the *_UNINIT flags to libext2fs
authorTheodore Ts'o <tytso@mit.edu>
Mon, 21 Apr 2008 05:29:01 +0000 (01:29 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 21 Apr 2008 05:39:23 +0000 (01:39 -0400)
Mke2fs used to have special case, ugly code in
setup_lazy_bg/setup_uninit_bg flag which set the flags based on all
sorts of special cases.  Change it so that it is done in libext2fs,
and fix mke2fs to use alloc_stats functions which will take care of
clearing the *_UNINIT flags automatically as needed.

This is preparatory work to make the flex_bg allocation patch much
cleaner.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/alloc_sb.c
lib/ext2fs/alloc_stats.c
lib/ext2fs/csum.c
lib/ext2fs/initialize.c
misc/mke2fs.c

index 5bf2db7..200ce5c 100644 (file)
@@ -60,6 +60,8 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
                ext2fs_mark_block_bitmap(bmap, super_blk);
 
        if (old_desc_blk) {
+               if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap)
+                       fs->group_desc[group].bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
                for (j=0; j < old_desc_blocks; j++)
                        ext2fs_mark_block_bitmap(bmap, old_desc_blk + j);
        }
index 725f28d..3956528 100644 (file)
@@ -28,10 +28,9 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
        if (isdir)
                fs->group_desc[group].bg_used_dirs_count += inuse;
 
-       /* We don't strictly need to be clearing these if inuse < 0
+       /* We don't strictly need to be clearing the uninit flag if inuse < 0
         * (i.e. freeing inodes) but it also means something is bad. */
-       fs->group_desc[group].bg_flags &= ~(EXT2_BG_INODE_UNINIT |
-                                           EXT2_BG_BLOCK_UNINIT);
+       fs->group_desc[group].bg_flags &= ~EXT2_BG_INODE_UNINIT;
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
                ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group -
@@ -42,7 +41,6 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
                        fs->group_desc[group].bg_itable_unused =
                                group * fs->super->s_inodes_per_group +
                                fs->super->s_inodes_per_group - ino;
-
                ext2fs_group_desc_csum_set(fs, group);
        }
 
index 20b235a..1091d73 100644 (file)
@@ -69,7 +69,10 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group)
 
 void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group)
 {
-       fs->group_desc[group].bg_checksum = ext2fs_group_desc_csum(fs, group);
+       if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                      EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
+               fs->group_desc[group].bg_checksum =
+                       ext2fs_group_desc_csum(fs, group);
 }
 
 static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap,
index 2125912..09e1008 100644 (file)
@@ -103,6 +103,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
        dgrp_t          i;
        blk_t           numblocks;
        int             rsv_gdt;
+       int             csum_flag;
        int             io_flags;
        char            *buf;
        char            c;
@@ -375,7 +376,19 @@ ipg_retry:
         * by this routine), they are accounted for nevertheless.
         */
        super->s_free_blocks_count = 0;
+       csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                              EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
        for (i = 0; i < fs->group_desc_count; i++) {
+               /*
+                * Don't set the BLOCK_UNINIT group for the last group
+                * because the block bitmap needs to be padded.
+                */
+               if (csum_flag) {
+                       if (i != fs->group_desc_count - 1)
+                               fs->group_desc[i].bg_flags |=
+                                       EXT2_BG_BLOCK_UNINIT;
+                       fs->group_desc[i].bg_flags |= EXT2_BG_INODE_UNINIT;
+               }
                numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
 
                super->s_free_blocks_count += numblocks;
index ff45af8..61f45aa 100644 (file)
@@ -265,6 +265,7 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
                                group_bad++;
                                group = ext2fs_group_of_blk(fs, group_block+j);
                                fs->group_desc[group].bg_free_blocks_count++;
+                               ext2fs_group_desc_csum_set(fs, group);
                                fs->super->s_free_blocks_count++;
                        }
                }
@@ -431,6 +432,7 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
                        }
                        /* The kernel doesn't need to zero the itable blocks */
                        fs->group_desc[i].bg_flags |= EXT2_BG_INODE_ZEROED;
+                       ext2fs_group_desc_csum_set(fs, i);
                }
                if (sync_kludge) {
                        if (sync_kludge == 1)
@@ -443,38 +445,6 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
        progress_close(&progress);
 }
 
-static void setup_uninit_bg(ext2_filsys fs)
-{
-       dgrp_t i;
-       int blks;
-       struct ext2_super_block *sb = fs->super;
-       struct ext2_group_desc *bg = fs->group_desc;
-
-       if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
-                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
-               return;
-
-       for (i = 0; i < fs->group_desc_count; i++, bg++) {
-               if (i == 0)
-                       continue;
-               if (bg->bg_free_inodes_count == sb->s_inodes_per_group)
-                       bg->bg_flags |= EXT2_BG_INODE_UNINIT;
-
-               /* Skip groups with GDT backups because the resize
-                * inode has blocks allocated in them, and the last
-                * group because it needs block bitmap padding. */
-               if ((ext2fs_bg_has_super(fs, i) && 
-                    sb->s_reserved_gdt_blocks) ||
-                   (i == fs->group_desc_count - 1))
-                       continue;
-
-               blks = ext2fs_super_and_bgd_loc(fs, i, 0, 0, 0, 0);
-               if (bg->bg_free_blocks_count == blks &&
-                   bg->bg_flags & EXT2_BG_INODE_UNINIT)
-                       bg->bg_flags |= EXT2_BG_BLOCK_UNINIT;
-       }
-}
-
 static void create_root_dir(ext2_filsys fs)
 {
        errcode_t               retval;
@@ -553,8 +523,7 @@ static void create_bad_block_inode(ext2_filsys fs, badblocks_list bb_list)
        errcode_t       retval;
        
        ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_BAD_INO);
-       fs->group_desc[0].bg_free_inodes_count--;
-       fs->super->s_free_inodes_count--;
+       ext2fs_inode_alloc_stats2(fs, EXT2_BAD_INO, +1, 0);
        retval = ext2fs_update_bb_inode(fs, bb_list);
        if (retval) {
                com_err("ext2fs_update_bb_inode", retval,
@@ -569,12 +538,8 @@ static void reserve_inodes(ext2_filsys fs)
        ext2_ino_t      i;
        int             group;
 
-       for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++) {
-               ext2fs_mark_inode_bitmap(fs->inode_map, i);
-               group = ext2fs_group_of_ino(fs, i);
-               fs->group_desc[group].bg_free_inodes_count--;
-               fs->super->s_free_inodes_count--;
-       }
+       for (i = EXT2_ROOT_INO + 1; i < EXT2_FIRST_INODE(fs->super); i++)
+               ext2fs_inode_alloc_stats2(fs, i, +1, 0);
        ext2fs_mark_ib_dirty(fs);
 }
 
@@ -1887,7 +1852,6 @@ int main (int argc, char *argv[])
                                _("while zeroing block %u at end of filesystem"),
                                ret_blk);
                }
-               setup_uninit_bg(fs);
                write_inode_tables(fs, lazy_itable_init);
                create_root_dir(fs);
                create_lost_and_found(fs);
@@ -1963,14 +1927,6 @@ int main (int argc, char *argv[])
        }
 no_journal:
 
-       if (!super_only) {
-               retval = ext2fs_set_gdt_csum(fs);
-               if (retval) {
-                       com_err(program_name, retval, 
-                               _("\n\twhile setting block group checksum info"));
-                       exit(1);
-               }
-       }
        if (!quiet)
                printf(_("Writing superblocks and "
                       "filesystem accounting information: "));