Whamcloud - gitweb
In mke2fs and resize2fs, round the default size of the filesystem to
authorTheodore Ts'o <tytso@mit.edu>
Tue, 8 Jul 2003 22:03:48 +0000 (18:03 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 8 Jul 2003 22:03:48 +0000 (18:03 -0400)
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.

misc/ChangeLog
misc/mke2fs.c
resize/ChangeLog
resize/main.c

index 5df33e8..d56c20d 100644 (file)
@@ -1,5 +1,12 @@
 2003-07-06  Theodore Ts'o  <tytso@mit.edu>
 
+       * 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 <string.h>)
index 545ec96..eddf959 100644 (file)
@@ -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(&param))
+                               param.s_blocks_count &= ~((sys_page_size /
+                                                          EXT2_BLOCK_SIZE(&param))-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, &param,
-                                  unix_io_manager, &fs);
+                                  io_ptr, &fs);
        if (retval) {
                com_err(device_name, retval, _("while setting up superblock"));
                exit(1);
index b059873..a7e63c9 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-08  Theodore Ts'o  <tytso@mit.edu>
+
+       * 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    <tytso@snap.thunk.org>
 
        * resize2fs.c (block_mover): Don't move blocks associated with the
index 7aade6d..649105a 100644 (file)
@@ -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,