Whamcloud - gitweb
mke2fs: add support for hugefiles_align
authorTheodore Ts'o <tytso@mit.edu>
Tue, 4 Feb 2014 17:30:00 +0000 (12:30 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 4 Feb 2014 17:34:17 +0000 (12:34 -0500)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/mk_hugefiles.c
misc/mke2fs.conf.5.in

index 12420af..eb91f0c 100644 (file)
@@ -310,12 +310,25 @@ static blk64_t get_start_block(ext2_filsys fs, blk64_t slack)
        return blk;
 }
 
+static blk64_t round_up_align(blk64_t b, unsigned long align)
+{
+       unsigned long m;
+
+       if (align == 0)
+               return b;
+       m = b % align;
+       if (m)
+               b += align - m;
+       return b;
+}
+
 errcode_t mk_hugefiles(ext2_filsys fs)
 {
        unsigned long   i;
        ext2_ino_t      dir;
        errcode_t       retval;
        blk64_t         fs_blocks;
+       unsigned long   align;
        int             d, dsize;
        char            *t;
 
@@ -332,6 +345,10 @@ errcode_t mk_hugefiles(ext2_filsys fs)
        t = get_string_from_profile(fs_types, "hugefiles_size", "0");
        num_blocks = parse_num_blocks2(t, fs->super->s_log_block_size);
        free(t);
+       t = get_string_from_profile(fs_types, "hugefiles_align", "0");
+       align = parse_num_blocks2(t, fs->super->s_log_block_size);
+       free(t);
+       num_blocks = round_up_align(num_blocks, align);
        zero_hugefile = get_int_from_profile(fs_types, "zero_hugefiles",
                                             zero_hugefile);
 
@@ -357,7 +374,12 @@ errcode_t mk_hugefiles(ext2_filsys fs)
        fn_numbuf = fn_buf + strlen(fn_prefix);
        free(fn_prefix);
 
-       fs_blocks = ext2fs_free_blocks_count(fs->super) -num_slack;
+       fs_blocks = ext2fs_free_blocks_count(fs->super);
+       if (fs_blocks < num_slack + align)
+               return ENOMEM;
+       fs_blocks -= num_slack + align;
+       if (num_blocks && num_blocks > fs_blocks)
+               return ENOMEM;
        if (num_blocks == 0 && num_files == 0)
                num_files = 1;
 
@@ -378,6 +400,7 @@ errcode_t mk_hugefiles(ext2_filsys fs)
        num_slack += calc_overhead(fs, num_blocks) * num_files;
        num_slack += (num_files / 16) + 1; /* space for dir entries */
        goal = get_start_block(fs, num_slack);
+       goal = round_up_align(goal, align);
 
        if (!quiet) {
                if (zero_hugefile && verbose)
index 39a1a40..02efdce 100644 (file)
@@ -457,7 +457,13 @@ files.
 .TP
 .I hugefiles_size
 This relation specifies the size of the huge files.  If this relation is
-not specified, the default is to fill th efile system.
+not specified, the default is to fill the entire file system.
+.TP
+.I hugefiles_align
+This relation specifies the alignment for the start block of the huge
+files.  It also forces the size of huge files to be a multiple of the
+requested alignment.  If this relation is not specified, no alignment
+requirement will be imposed on the huge files.
 .TP
 .I hugefiles_name
 This relation specifies the base file name for the huge files.