Whamcloud - gitweb
LU-12158 mke2fs: avoid too large stride and stripe_width
[tools/e2fsprogs.git] / misc / mke2fs.c
index 33242fe..0cb1112 100644 (file)
@@ -1503,6 +1503,9 @@ struct device_param {
        unsigned int dax:1;             /* supports dax? */
 };
 
+#define        OPTIMIZED_STRIPE_WIDTH  512
+#define        OPTIMIZED_STRIDE        512
+
 #ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
 /*
  * Sets the geometry of a device (stripe/stride), and returns the
@@ -1533,7 +1536,19 @@ static int get_device_geometry(const char *file,
                goto out;
 
        dev_param->min_io = blkid_topology_get_minimum_io_size(tp);
+       if (dev_param->min_io > OPTIMIZED_STRIDE) {
+               fprintf(stdout,
+                       "detected raid stride %lu too large, use optimum %u\n",
+                       dev_param->min_io, OPTIMIZED_STRIDE);
+               dev_param->min_io = OPTIMIZED_STRIDE;
+       }
        dev_param->opt_io = blkid_topology_get_optimal_io_size(tp);
+       if (dev_param->opt_io > OPTIMIZED_STRIPE_WIDTH) {
+               fprintf(stdout,
+                       "detected raid stripe width %lu too large, use optimum %u\n",
+                       dev_param->opt_io, OPTIMIZED_STRIPE_WIDTH);
+               dev_param->opt_io = OPTIMIZED_STRIPE_WIDTH;
+       }
        if ((dev_param->min_io == 0) && (psector_size > blocksize))
                dev_param->min_io = psector_size;
        if ((dev_param->opt_io == 0) && dev_param->min_io > 0)
@@ -2077,8 +2092,7 @@ profile_error:
         * be appropriately configured.
         */
        fs_types = parse_fs_type(fs_type, usage_types, &fs_param,
-                                fs_blocks_count ? fs_blocks_count : dev_size,
-                                argv[0]);
+                                fs_blocks_count, argv[0]);
        if (!fs_types) {
                fprintf(stderr, "%s", _("Failed to parse fs types list\n"));
                exit(1);
@@ -2228,24 +2242,25 @@ profile_error:
         * We now need to do a sanity check of fs_blocks_count for
         * 32-bit vs 64-bit block number support.
         */
-       if ((fs_blocks_count > MAX_32_NUM) &&
-           ext2fs_has_feature_64bit(&fs_param))
-               ext2fs_clear_feature_resize_inode(&fs_param);
-       if ((fs_blocks_count > MAX_32_NUM) &&
-           !ext2fs_has_feature_64bit(&fs_param) &&
-           get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) {
-               ext2fs_set_feature_64bit(&fs_param);
-               ext2fs_clear_feature_resize_inode(&fs_param);
-       }
-       if ((fs_blocks_count > MAX_32_NUM) &&
-           !ext2fs_has_feature_64bit(&fs_param)) {
-               fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
+       if (fs_blocks_count > MAX_32_NUM) {
+               if (!ext2fs_has_feature_64bit(&fs_param) &&
+                   get_bool_from_profile(fs_types, "auto_64-bit_support", 0))
+                       ext2fs_set_feature_64bit(&fs_param);
+
+               if (ext2fs_has_feature_64bit(&fs_param)) {
+                       ext2fs_clear_feature_resize_inode(&fs_param);
+               } else {
+                       fprintf(stderr,
+                               _("%s: Size of device (0x%llx blocks) %s "
                                  "too big to be expressed\n\t"
                                  "in 32 bits using a blocksize of %d.\n"),
-                       program_name, (unsigned long long) fs_blocks_count,
-                       device_name, EXT2_BLOCK_SIZE(&fs_param));
-               exit(1);
+                               program_name,
+                               (unsigned long long) fs_blocks_count,
+                               device_name, EXT2_BLOCK_SIZE(&fs_param));
+                       exit(1);
+               }
        }
+
        /*
         * Guard against group descriptor count overflowing... Mostly to avoid
         * strange results for absurdly large devices.  This is in log2:
@@ -2325,13 +2340,13 @@ profile_error:
                fs_param.s_feature_compat = 0;
                fs_param.s_feature_ro_compat &=
                                        EXT4_FEATURE_RO_COMPAT_METADATA_CSUM;
-       }
+       }
 
        /* Check the user's mkfs options for 64bit */
-       if (ext2fs_has_feature_64bit(&fs_param) &&
+       if (fs_blocks_count > MAX_32_NUM &&
            !ext2fs_has_feature_extents(&fs_param)) {
-               printf("%s", _("Extents MUST be enabled for a 64-bit "
-                              "filesystem.  Pass -O extents to rectify.\n"));
+               printf("%s", _("Extents MUST be enabled for filesystems with "
+                              "over 2^32 blocks. Use '-O extents' to fix.\n"));
                exit(1);
        }
 
@@ -2659,15 +2674,11 @@ _("128-byte inodes cannot handle dates beyond 2038 and are deprecated\n"));
                unsigned long long n;
                n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio;
                if (n > MAX_32_NUM) {
-                       if (ext2fs_has_feature_64bit(&fs_param))
-                               num_inodes = MAX_32_NUM;
-                       else {
+                       num_inodes = MAX_32_NUM;
+                       if (!ext2fs_has_feature_64bit(&fs_param))
                                com_err(program_name, 0,
-                                       _("too many inodes (%llu), raise "
-                                         "inode ratio?"),
-                                       (unsigned long long) n);
-                               exit(1);
-                       }
+                                       _("too many inodes (%llu), reduced to "
+                                         "%llu"), n, MAX_32_NUM);
                }
        } else if (num_inodes > MAX_32_NUM) {
                com_err(program_name, 0,