From: Theodore Ts'o Date: Tue, 8 Jul 2003 22:03:48 +0000 (-0400) Subject: In mke2fs and resize2fs, round the default size of the filesystem to X-Git-Tag: E2FSPROGS-1_34~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7ccdff8e128c24564011d760a996496b0a981b3;p=thirdparty%2Fe2fsprogs.git In mke2fs and resize2fs, round the default size of the filesystem to be an even multiple of the pagesize to work around a potential Linux kernel bug. Use the testio manager in mke2fs if CONFIG_TESTIO_DEBUG is set. --- diff --git a/misc/ChangeLog b/misc/ChangeLog index 5df33e860..d56c20d4d 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,12 @@ 2003-07-06 Theodore Ts'o + * mke2fs.c (PRS, main): If CONFIG_TESTIO_DEBUG, then use the + testio manager. + + * mke2fs.c (PRS): Round down the default filesystem size so that + it is an even multiple of the page size, to work around + buffer cache kernel bug. + * badblocks.c: Fix gcc -Wall nitpicks (signed/unsigned type issues) * blkid.c: Fix gcc -Wall nitpicks (missing #include ) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 545ec96c5..eddf95976 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1082,10 +1082,17 @@ static void PRS(int argc, char *argv[]) */ if (blocksize <= 0 && journal_device) { ext2_filsys jfs; + io_manager io_ptr; +#ifdef CONFIG_TESTIO_DEBUG + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; +#else + io_ptr = unix_io_manager; +#endif retval = ext2fs_open(journal_device, EXT2_FLAG_JOURNAL_DEV_OK, 0, - 0, unix_io_manager, &jfs); + 0, io_ptr, &jfs); if (retval) { com_err(program_name, retval, _("while trying to open journal device %s\n"), @@ -1169,6 +1176,9 @@ static void PRS(int argc, char *argv[]) exit(1); } param.s_blocks_count = dev_size; + if (sys_page_size > EXT2_BLOCK_SIZE(¶m)) + param.s_blocks_count &= ~((sys_page_size / + EXT2_BLOCK_SIZE(¶m))-1); } } else if (!force && (param.s_blocks_count > dev_size)) { @@ -1249,6 +1259,7 @@ int main (int argc, char *argv[]) badblocks_list bb_list = 0; int journal_blocks; int i, val; + io_manager io_ptr; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); @@ -1258,11 +1269,18 @@ int main (int argc, char *argv[]) #endif PRS(argc, argv); +#ifdef CONFIG_TESTIO_DEBUG + io_ptr = test_io_manager; + test_io_backing_manager = unix_io_manager; +#else + io_ptr = unix_io_manager; +#endif + /* * Initialize the superblock.... */ retval = ext2fs_initialize(device_name, 0, ¶m, - unix_io_manager, &fs); + io_ptr, &fs); if (retval) { com_err(device_name, retval, _("while setting up superblock")); exit(1); diff --git a/resize/ChangeLog b/resize/ChangeLog index b05987381..a7e63c9f2 100644 --- a/resize/ChangeLog +++ b/resize/ChangeLog @@ -1,3 +1,9 @@ +2003-07-08 Theodore Ts'o + + * main.c (main): Round the default size of the filesystem to be an + even multiple of the pagesize to work around a potential + Linux kernel bug. + 2003-06-24 * resize2fs.c (block_mover): Don't move blocks associated with the diff --git a/resize/main.c b/resize/main.c index 7aade6d2f..649105aab 100644 --- a/resize/main.c +++ b/resize/main.c @@ -138,6 +138,8 @@ int main (int argc, char ** argv) io_manager io_ptr; char *tmp; struct stat st_buf; + int sys_page_size = 4096; + long sysval; #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); @@ -238,6 +240,18 @@ int main (int argc, char ** argv) exit(1); } + /* Determine the system page size if possible */ +#ifdef HAVE_SYSCONF +#if (!defined(_SC_PAGESIZE) && defined(_SC_PAGE_SIZE)) +#define _SC_PAGESIZE _SC_PAGE_SIZE +#endif +#ifdef _SC_PAGESIZE + sysval = sysconf(_SC_PAGESIZE); + if (sysval > 0) + sys_page_size = sysval; +#endif /* _SC_PAGESIZE */ +#endif /* HAVE_SYSCONF */ + /* * Get the size of the containing partition, and use this for * defaults and for making sure the new filesystme doesn't @@ -256,8 +270,12 @@ int main (int argc, char ** argv) else if (units > fs->blocksize) new_size = new_size * (units / fs->blocksize); } - if (!new_size) + if (!new_size) { new_size = max_size; + /* Round down to an even multiple of a pagesize */ + if (sys_page_size > fs->blocksize) + new_size &= ~((sys_page_size / fs->blocksize)-1); + } /* * If we are resizing a plain file, and it's not big enough,