From: Eric Sandeen Date: Fri, 2 Oct 2009 16:32:42 +0000 (-0500) Subject: mke2fs: get device topology values from blkid X-Git-Tag: v1.41.10~42 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=9ed8e5fec226aa53634ed95cbeac736d90a518e5;p=tools%2Fe2fsprogs.git mke2fs: get device topology values from blkid Handle automatic selection of stride/stripe: mke2fs 1.41.9 (22-Aug-2009) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=16 blocks, Stripe width=32 blocks ... And warn on block device misalignment: mke2fs 1.41.9 (22-Aug-2009) /dev/sdc1 alignment is offset by 32256 bytes. This may result in very poor performance, (re)-partitioning suggested. Proceed anyway? (y,n) Signed-off-by: Eric Sandeen Signed-off-by: Theodore Ts'o --- diff --git a/configure b/configure index 10ee09f..3d6c5c8 100755 --- a/configure +++ b/configure @@ -15737,6 +15737,96 @@ _ACEOF fi +if test -n "$BLKID_CMT"; then + { $as_echo "$as_me:$LINENO: checking for library containing blkid_probe_all" >&5 +$as_echo_n "checking for library containing blkid_probe_all... " >&6; } +if test "${ac_cv_search_blkid_probe_all+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char blkid_probe_all (); +int +main () +{ +return blkid_probe_all (); + ; + return 0; +} +_ACEOF +for ac_lib in '' blkid; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then + ac_cv_search_blkid_probe_all=$ac_res +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext + if test "${ac_cv_search_blkid_probe_all+set}" = set; then + break +fi +done +if test "${ac_cv_search_blkid_probe_all+set}" = set; then + : +else + ac_cv_search_blkid_probe_all=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_blkid_probe_all" >&5 +$as_echo "$ac_cv_search_blkid_probe_all" >&6; } +ac_res=$ac_cv_search_blkid_probe_all +if test "$ac_res" != no; then + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +fi + +fi + @@ -15770,7 +15860,7 @@ fi -for ac_func in chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep getdtablesize getrlimit +for ac_func in chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep getdtablesize getrlimit blkid_probe_get_topology2 do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` { $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index c38f0a8..eeeccec 100644 --- a/configure.in +++ b/configure.in @@ -802,7 +802,14 @@ AC_CHECK_MEMBER(struct sockaddr.sa_len, [#include #include ]) dnl -AC_CHECK_FUNCS(chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep getdtablesize getrlimit) +dnl This will add -lblkid to the AC_CHECK_FUNCS search if we are using +dnl the system-provided blkid library +dnl +if test -n "$BLKID_CMT"; then + AC_SEARCH_LIBS([blkid_probe_all], [blkid]) +fi +dnl +AC_CHECK_FUNCS(chflags getrusage llseek lseek64 open64 fstat64 ftruncate64 getmntinfo strtoull strcasecmp srandom jrand48 fchown mallinfo fdatasync strnlen strptime strdup sysconf pathconf posix_memalign memalign valloc __secure_getenv prctl mmap utime setresuid setresgid usleep nanosleep getdtablesize getrlimit blkid_probe_get_topology2) dnl dnl Check to see if -lsocket is required (solaris) to make something dnl that uses socket() to compile; this is needed for the UUID library diff --git a/misc/mke2fs.c b/misc/mke2fs.c index e10fd35..f86d6e7 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -49,6 +49,7 @@ extern int optind; #include #include #include +#include #include "ext2fs/ext2_fs.h" #include "et/com_err.h" @@ -614,6 +615,8 @@ static void show_stats(ext2_filsys fs) s->s_log_block_size); printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize, s->s_log_frag_size); + printf(_("Stride=%u blocks, Stripe width=%u blocks\n"), + s->s_raid_stride, s->s_raid_stripe_width); printf(_("%u inodes, %u blocks\n"), s->s_inodes_count, s->s_blocks_count); printf(_("%u blocks (%2.2f%%) reserved for the super user\n"), @@ -1073,6 +1076,43 @@ static int get_bool_from_profile(char **fs_types, const char *opt, int def_val) extern const char *mke2fs_default_profile; static const char *default_files[] = { "", 0 }; +#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY +/* + * Sets the geometry of a device (stripe/stride), and returns the + * device's alignment offset, if any, or a negative error. + */ +static int ext2fs_get_device_geometry(const char *file, + struct ext2_super_block *fs_param) +{ + int rc = -1; + int blocksize; + blkid_probe pr; + blkid_topology tp; + unsigned long min_io; + unsigned long opt_io; + + pr = blkid_new_probe_from_filename(file); + if (!pr) + goto out; + + tp = blkid_probe_get_topology(pr); + if (!tp) + goto out; + + min_io = blkid_topology_get_minimum_io_size(tp); + opt_io = blkid_topology_get_optimal_io_size(tp); + blocksize = EXT2_BLOCK_SIZE(fs_param); + + fs_param->s_raid_stride = min_io / blocksize; + fs_param->s_raid_stripe_width = opt_io / blocksize; + + rc = blkid_topology_get_alignment_offset(tp); +out: + blkid_free_probe(pr); + return rc; +} +#endif + static void PRS(int argc, char *argv[]) { int b, c; @@ -1633,6 +1673,21 @@ got_size: fs_param.s_log_frag_size = fs_param.s_log_block_size = int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); +#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY + retval = ext2fs_get_device_geometry(device_name, &fs_param); + if (retval < 0) { + fprintf(stderr, + _("warning: Unable to get device geometry for %s"), + device_name); + } else if (retval) { + printf(_("%s alignment is offset by %lu bytes.\n"), + device_name, retval); + printf(_("This may result in very poor performance, " + "(re)-partitioning suggested.\n")); + proceed_question(); + } +#endif + blocksize = EXT2_BLOCK_SIZE(&fs_param); lazy_itable_init = get_bool_from_profile(fs_types,