From: Zheng Liu <gnehzuil.liu@gmail.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH 2/6] mke2fs: clean up kernel version tests
Date: Tue, 21 Jan 2014 15:32:40 +0800 [thread overview]
Message-ID: <20140121073240.GC1819@gmail.com> (raw)
In-Reply-To: <20140121062151.20507.41042.stgit@birch.djwong.org>
On Mon, Jan 20, 2014 at 10:21:51PM -0800, Darrick J. Wong wrote:
> Refactor the running kernel version checks to hide the details of
> version code checking, etc.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
- Zheng
> ---
> misc/mke2fs.c | 39 +++++++++++++++++++++++++--------------
> 1 file changed, 25 insertions(+), 14 deletions(-)
>
>
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index 527f25b..f8232d4 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -27,6 +27,7 @@
> #include <time.h>
> #ifdef __linux__
> #include <sys/utsname.h>
> +#include <linux/version.h>
> #endif
> #ifdef HAVE_GETOPT_H
> #include <getopt.h>
> @@ -169,7 +170,28 @@ static int parse_version_number(const char *s)
> rev = strtol(cp, &endptr, 10);
> if (cp == endptr)
> return 0;
> - return ((((major * 256) + minor) * 256) + rev);
> + return KERNEL_VERSION(major, minor, rev);
> +}
> +
> +static int is_before_linux_ver(unsigned int major, unsigned int minor)
> +{
> + struct utsname ut;
> + int linux_version_code = 0;
> +
> + if (uname(&ut)) {
> + perror("uname");
> + exit(1);
> + }
> + linux_version_code = parse_version_number(ut.release);
> + if (linux_version_code == 0)
> + return 0;
> +
> + return linux_version_code < KERNEL_VERSION(major, minor, 0);
> +}
> +#else
> +static int is_before_linux_ver(unsigned int major, unsigned int minor)
> +{
> + return 0;
> }
> #endif
>
> @@ -1362,9 +1384,6 @@ static void PRS(int argc, char *argv[])
> * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs.
> */
> blk64_t fs_blocks_count = 0;
> -#ifdef __linux__
> - struct utsname ut;
> -#endif
> long sysval;
> int s_opt = -1, r_opt = -1;
> char *fs_features = 0;
> @@ -1430,15 +1449,8 @@ profile_error:
> memset(&fs_param, 0, sizeof(struct ext2_super_block));
> fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
>
> -#ifdef __linux__
> - if (uname(&ut)) {
> - perror("uname");
> - exit(1);
> - }
> - linux_version_code = parse_version_number(ut.release);
> - if (linux_version_code && linux_version_code < (2*65536 + 2*256))
> + if (is_before_linux_ver(2, 2))
> fs_param.s_rev_level = 0;
> -#endif
>
> if (argc && *argv) {
> program_name = get_progname(*argv);
> @@ -1876,8 +1888,7 @@ profile_error:
>
> if (use_bsize == -1) {
> use_bsize = sys_page_size;
> - if ((linux_version_code < (2*65536 + 6*256)) &&
> - (use_bsize > 4096))
> + if (is_before_linux_ver(2, 6) && use_bsize > 4096)
> use_bsize = 4096;
> }
> if (lsector_size && use_bsize < lsector_size)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-01-21 7:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-21 6:21 [PATCH 0/6] miscellaneous e2fsprogs fixes Darrick J. Wong
2014-01-21 6:21 ` [PATCH 1/6] misc: fix resource leaks in e2fsprogs Darrick J. Wong
2014-01-21 7:25 ` Zheng Liu
2014-01-21 18:18 ` Darrick J. Wong
2014-01-21 6:21 ` [PATCH 2/6] mke2fs: clean up kernel version tests Darrick J. Wong
2014-01-21 7:32 ` Zheng Liu [this message]
2014-02-06 20:28 ` Theodore Ts'o
2014-01-21 6:21 ` [PATCH 3/6] libext2fs: iterate past lower extents during punch Darrick J. Wong
2014-01-21 7:40 ` Zheng Liu
2014-02-06 20:29 ` Theodore Ts'o
2014-01-21 6:22 ` [PATCH 4/6] libext2fs: during punch, fix parent extents after modifying extent Darrick J. Wong
2014-01-21 7:43 ` Zheng Liu
2014-02-06 20:31 ` Theodore Ts'o
2014-01-21 6:22 ` [PATCH 5/6] libext2fs: don't hang on to unmapped block if extent tree update fails Darrick J. Wong
2014-01-21 7:45 ` Zheng Liu
2014-01-21 6:22 ` [PATCH 6/6] libext2fs: try to roll back when splitting an extent fails Darrick J. Wong
2014-01-21 7:49 ` Zheng Liu
2014-02-06 20:34 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140121073240.GC1819@gmail.com \
--to=gnehzuil.liu@gmail.com \
--cc=darrick.wong@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).