public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] lib/tst_mkfs: new tst_mkfs_sized function for create appointed size fs
Date: Wed, 9 Mar 2016 14:07:10 +0100	[thread overview]
Message-ID: <20160309130709.GA28171@rei.lan> (raw)
In-Reply-To: <1457444133-5671-1-git-send-email-zlang@redhat.com>

Hi!
>  #include "test.h"
>  #include "ltp_priv.h"
>  
>  #define OPTS_MAX 32
>  
> -void tst_mkfs(void (cleanup_fn)(void), const char *dev,
> -	      const char *fs_type, const char *const fs_opts[])
> +long long cvtnum(const char *s)
> +{
> +	long long i;
> +	char *sp = NULL;
> +
> +	i = strtoll(s, &sp, 0);
> +	if (i == 0 && sp == s)
> +		return -1LL;
> +	if (*sp == '\0')
> +		return i;
> +
> +	if (*sp == 'k' && sp[1] == '\0')
> +		return 1024LL * i;
> +	if (*sp == 'm' && sp[1] == '\0')
> +		return 1024LL * 1024LL * i;
> +	if (*sp == 'g' && sp[1] == '\0')
> +		return 1024LL * 1024LL * 1024LL * i;
> +	if (*sp == 't' && sp[1] == '\0')
> +		return 1024LL * 1024LL * 1024LL * 1024LL * i;
> +	if (*sp == 'p' && sp[1] == '\0')
> +		return 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * i;
> +	if (*sp == 'e' && sp[1] == '\0')
> +		return 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * i;
> +	return -1LL;
> +}

We allready have bytes_by_prefix() in LTP library.

> +void tst_mkfs_sized(void (cleanup_fn)(void), const char *dev,
> +                    const char *fs_type, const char *const fs_opts[],
> +                    const char *fssize, const char *blocksize)

What about passing the size parameter as we do in tst_fs_has_free()?

I.e. with two paramters where one is size and the second is units?

Also why have you added the blocksize parameter as well? The block size
is needed only for the mmap16 test while limiting filesystem size seems
like good addition to the library?

>  {
>  	int i, pos = 3;
>  	const char *argv[OPTS_MAX] = {"mkfs", "-t", fs_type};
>  	char fs_opts_str[1024] = "";
> +	char blk_size_str[256] = "";
> +	char fs_size_str[256] = "";
> +	long long fssz = 0;
> +	unsigned int blsz= 0;
>  
>  	if (!fs_type)
>  		tst_brkm(TBROK, cleanup_fn, "No fs_type specified");
>  
> -	/*
> -	 * mkfs.xfs and mkfs.btrfs aborts if it finds a filesystem
> -	 * superblock on the device, which is the case here as we
> -	 * reuse one device for all tests.
> -	 */
>  	if (!strcmp(fs_type, "xfs")) {
> +		/*
> +		 * mkfs.xfs and mkfs.btrfs aborts if it finds a filesystem
> +		 * superblock on the device, which is the case here as we
> +		 * reuse one device for all tests.
> +		 */
>  		tst_resm(TINFO, "Appending '-f' flag to mkfs.%s", fs_type);
>  		argv[pos++] = "-f";
> -	}
> +		if (blocksize) {
> +			argv[pos++] = "-b";
> +			strcat(blk_size_str, "size=");
> +			strcat(blk_size_str, blocksize);
> +			argv[pos++] = blk_size_str;
> +		}
>  
> -	if (!strcmp(fs_type, "btrfs")) {
> +		if (!fssize) {
> +			argv[pos++] = "-d";
> +			strcat(fs_size_str, "size=");
> +			strcat(fs_size_str, fssize);
> +			argv[pos++] = fs_size_str;
> +		}
> +	} else if (!strncmp(fs_type, "ext", 3)) {
> +		if (blocksize) {
> +			argv[pos++] = "-b";
> +			argv[pos++] = blocksize;
> +		}
> +		/*
> +		 * If fs is extX, the fs_size should be set behind device name.
> +		 * Not set at here.
> +		 */
> +	} else if (!strcmp(fs_type, "btrfs")) {
>  		/*
>  		 * The -f option was added to btrfs-progs v3.12
>  		 */
> @@ -50,6 +102,21 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
>  				fs_type);
>  			argv[pos++] = "-f";
>  		}
> +		if (fssize) {
> +			/*
> +			 * The recommended size for the mixed mode is for filesystems less than 1GiB
> +			 */
> +			if (cvtnum(fssize) < 1024 * 1024 * 1024)
> +				argv[pos++] = "--mixed";
> +			argv[pos++] = "-b";
> +			argv[pos++] = fssize;
> +		}
> +	} else if (fssize || blocksize) {
> +		/*
> +		 * Can't set fs size or block size for others fs,
> +		 * except add new fs support as above.
> +		 */
> +		tst_brkm(TBROK, cleanup_fn, "tst_mkfs_sized don't support '%s' fs, please add this fs as a new feature", fs_type);
>  	}
>  
>  	if (fs_opts) {
> @@ -68,10 +135,30 @@ void tst_mkfs(void (cleanup_fn)(void), const char *dev,
>  	}
>  
>  	argv[pos++] = dev;
> +
> +	/*
> +	 * According to mke2fs(8) manual, fs-size need be behind the device
> +	 * parameter. So add fs size into argv[pos++] after dev name.
> +	 */
> +	if (!strncmp(fs_type, "ext", 3) && fssize && blocksize) {
> +		fssz = cvtnum(fssize);
> +		blsz = cvtnum(blocksize);
> +		if (fssz > 0 && blsz > 0){
> +			sprintf(fs_size_str, "%llu", fssz / blsz);
> +		} else {
> +			tst_brkm(TBROK, cleanup_fn, "No suitable filesystem/block size specified");
> +		}
> +		argv[pos++] = fs_size_str;
> +	}

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2016-03-09 13:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 13:35 [LTP] [PATCH 1/2] lib/tst_mkfs: new tst_mkfs_sized function for create appointed size fs Zorro Lang
2016-03-08 13:35 ` [LTP] [PATCH 2/2] mmap16: fix ETIMEDOUT error if test device is too large Zorro Lang
2016-03-09  2:22   ` Eryu Guan
2016-03-09  3:12     ` Zirong Lang
2016-03-09 13:07 ` Cyril Hrubis [this message]
2016-03-09 15:31   ` [LTP] [PATCH 1/2] lib/tst_mkfs: new tst_mkfs_sized function for create appointed size fs Zirong Lang
2016-03-09 15:52     ` Cyril Hrubis
2016-03-09 16:05       ` Zirong Lang
2016-03-09 16:09         ` Cyril Hrubis
2016-03-09 16:30           ` Zirong Lang
2016-03-09 17:43             ` Cyril Hrubis
2016-03-10  1:45               ` Zirong Lang
2016-03-10 10:04                 ` Cyril Hrubis
2016-03-10 12:00                   ` Zirong Lang
2016-03-10 12:19                     ` Cyril Hrubis
2016-03-10 13:30                       ` Zirong Lang
2016-03-10 14:06                         ` Cyril Hrubis
2016-03-10 16:24                           ` Zirong Lang
2016-03-14 17:15                             ` Cyril Hrubis
2016-03-09 16:01     ` Zirong Lang
2016-03-09 13:09 ` Cyril Hrubis
2016-03-09 15:09   ` Zirong Lang

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=20160309130709.GA28171@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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