commit 6aea7c4b5bf1c4da4630823a926e025fb7dbddd5 Author: Jose R. Santos Date: Thu Dec 6 14:00:48 2007 -0600 New bitmap and inode table allocation for FLEX_BG Change the way we allocate bitmaps and inode tables if the FLEX_BG feature is used at mke2fs time. The block and inode bitmaps are allocated as a one contiguous set for each flex block group. Due to the size of the inode tables, the inode table for each block group is allocate individually but packed close together at the beginning of a flex group. For now, this allow for the inode table to be packed close to the inode bitmaps in cases where we try to allocate a large group of inode tables right after the bitmaps and fail. Signed-off-by: Jose R. Santos diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index 4ad2ba9..ce81eaa 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -27,6 +27,124 @@ #include "ext2_fs.h" #include "ext2fs.h" +#define ALLOC_BLOCK_BITMAPS 1 +#define ALLOC_INODE_BITMAPS 2 +#define ALLOC_INODE_TABLES 3 + +errcode_t ext2fs_allocate_contiguous(ext2_filsys fs, dgrp_t group, + int type, blk_t start_blk, blk_t last_blk, + int count, ext2fs_block_bitmap bmap) +{ + errcode_t retval; + blk_t new_blk, blk; + int i, j; + + if (!bmap) + bmap = fs->block_map; + + switch (type) { + case ALLOC_BLOCK_BITMAPS: + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1 * count, bmap, &new_blk); + if (retval) + return retval; + for (i=0, blk=new_blk; i < count; i++, blk++) { + ext2fs_mark_block_bitmap(bmap, blk); + fs->group_desc[group+i].bg_block_bitmap = blk; + } + break; + + case ALLOC_INODE_BITMAPS: + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1 * count, bmap, &new_blk); + if (retval) + return retval; + for (i=0, blk=new_blk; i < count; i++, blk++) { + ext2fs_mark_block_bitmap(bmap, blk); + fs->group_desc[group+i].bg_inode_bitmap = blk; + } + break; + + case ALLOC_INODE_TABLES: + for (i=0; i < count; i++) { + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + fs->inode_blocks_per_group, + bmap, &new_blk); + if (retval) + return retval; + blk = new_blk; + for (j=0; j < fs->inode_blocks_per_group; j++, blk++) + ext2fs_mark_block_bitmap(bmap, blk); + fs->group_desc[group+i].bg_inode_table = new_blk; + } + break; + + } + return 0; +} + + + +errcode_t ext2fs_allocate_flex_groups(ext2_filsys fs) +{ + errcode_t retval; + blk_t start, last, j, blocks; + dgrp_t i, k; + int meta_bg_size; + + meta_bg_size = ext2fs_swab16(fs->super->s_flex_bg_size); + blocks = 0; + + for (i = 0; i < fs->group_desc_count; i=i+meta_bg_size) { + + start = ext2fs_group_first_block(fs, i); + + if (i+meta_bg_size >= fs->group_desc_count) { + last = ext2fs_group_last_block(fs, fs->group_desc_count); + meta_bg_size = fs->group_desc_count - i; + } + else + last = ext2fs_group_last_block(fs, i+meta_bg_size-1); + + retval = ext2fs_allocate_contiguous(fs, i, ALLOC_BLOCK_BITMAPS, + start, last, meta_bg_size, + fs->block_map); + if (retval) + return retval; + retval = ext2fs_allocate_contiguous(fs, i, ALLOC_INODE_BITMAPS, + start, last, meta_bg_size, + fs->block_map); + if (retval) + return retval; + retval = ext2fs_allocate_contiguous(fs, i, ALLOC_INODE_TABLES, + start, last, meta_bg_size, + fs->block_map); + if (retval) + return retval; + + /* + * The content of bg_free_blocks_count is previously + * assigned with out knowledge of the new allocation + * scheme. Need to update the number of free blocks + * per group descriptor or fsck will complain. + */ + + for (k=i; k fs->group_desc_count) + break; + start = ext2fs_group_first_block(fs, k); + last = ext2fs_group_last_block(fs, k); + for (j=start; j<=last; j++) { + if( !ext2fs_fast_test_block_bitmap(fs->block_map, j)) + blocks++; + } + fs->group_desc[k].bg_free_blocks_count = blocks; + blocks = 0; + } + } + return 0; +} + errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { @@ -107,10 +225,16 @@ errcode_t ext2fs_allocate_tables(ext2_filsys fs) errcode_t retval; dgrp_t i; - for (i = 0; i < fs->group_desc_count; i++) { - retval = ext2fs_allocate_group_table(fs, i, fs->block_map); - if (retval) - return retval; + if (EXT2_HAS_INCOMPAT_FEATURE (fs->super, + EXT4_FEATURE_INCOMPAT_FLEX_BG)) + ext2fs_allocate_flex_groups(fs); + + else { + for (i = 0; i < fs->group_desc_count; i++) { + retval = ext2fs_allocate_group_table(fs, i, fs->block_map); + if (retval) + return retval; + } } return 0; } diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index 2394857..7528707 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -577,7 +577,9 @@ struct ext2_super_block { __u16 s_mmp_interval; /* # seconds to wait in MMP checking */ __u64 s_mmp_block; /* Block for multi-mount protection */ __u32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ - __u32 s_reserved[163]; /* Padding to the end of the block */ + __u16 s_flex_bg_size; /* FLEX_BG group size */ + __u16 padding; /* Padding to next 32bits */ + __u32 s_reserved[162]; /* Padding to the end of the block */ }; /* diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index 16e9eaa..935a013 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -156,6 +156,7 @@ errcode_t ext2fs_initialize(const char *name, int flags, set_field(s_feature_incompat, 0); set_field(s_feature_ro_compat, 0); set_field(s_first_meta_bg, 0); + set_field(s_flex_bg_size, 0); if (super->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { retval = EXT2_ET_UNSUPP_FEATURE; goto cleanup; diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 9e2d7a8..7319832 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -96,7 +96,7 @@ static void usage(void) { fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] " "[-f fragment-size]\n\t[-i bytes-per-inode] [-I inode-size] " - "[-j] [-J journal-options]\n" + "[-j] [-J journal-options] [-G meta group size]\n" "\t[-N number-of-inodes] [-m reserved-blocks-percentage] " "[-o creator-os]\n\t[-g blocks-per-group] [-L volume-label] " "[-M last-mounted-directory]\n\t[-O feature[,...]] " @@ -912,6 +912,7 @@ static void PRS(int argc, char *argv[]) int blocksize = 0; int inode_ratio = 0; int inode_size = 0; + unsigned long flex_bg_size = 0; double reserved_ratio = 5.0; int sector_size = 0; int show_version_only = 0; @@ -994,7 +995,7 @@ static void PRS(int argc, char *argv[]) } while ((c = getopt (argc, argv, - "b:cf:g:i:jl:m:no:qr:s:tvE:FI:J:L:M:N:O:R:ST:V")) != EOF) { + "b:cf:g:G:i:jl:m:no:qr:s:tvE:FI:J:L:M:N:O:R:ST:V")) != EOF) { switch (c) { case 'b': blocksize = strtol(optarg, &tmp, 0); @@ -1045,6 +1046,19 @@ static void PRS(int argc, char *argv[]) exit(1); } break; + case 'G': + flex_bg_size = strtoul(optarg, &tmp, 0); + if (*tmp) { + com_err(program_name, 0, + _("Illegal number for Flex_BG size")); + exit(1); + } + if ((flex_bg_size & (flex_bg_size-1)) != 0) { + com_err(program_name, 0, + _("Flex_BG size must be a power of 2")); + exit(1); + } + break; case 'i': inode_ratio = strtoul(optarg, &tmp, 0); if (inode_ratio < EXT2_MIN_BLOCK_SIZE || @@ -1444,6 +1458,10 @@ static void PRS(int argc, char *argv[]) } } + if(flex_bg_size) { + fs_param.s_flex_bg_size = ext2fs_swab16(flex_bg_size); + } + if (!force && fs_param.s_blocks_count >= ((unsigned) 1 << 31)) { com_err(program_name, 0, _("Filesystem too large. No more than 2**31-1 blocks\n"