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 v2 1/2] lib: limit the size of tmpfs in LTP
Date: Wed, 7 Jul 2021 11:31:25 +0200	[thread overview]
Message-ID: <YOV0bemK+1NI0Cz4@yuki> (raw)
In-Reply-To: <20210705082527.855688-1-liwang@redhat.com>

Hi!
>  lib/tst_test.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 55449c80b..93761868e 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -882,8 +882,35 @@ static void prepare_and_mount_dev_fs(const char *mntpoint)
>  	}
>  }
>  
> +static char *limit_tmpfs_mount_size(const char *mnt_data,
> +			char *buf, size_t buf_size, const char *fs_type)
> +{
> +	int fd;
> +	uint64_t dev_size;
> +
> +	if (strcmp(fs_type, "tmpfs"))
> +		return mnt_data;
> +
> +	fd = SAFE_OPEN(tdev.dev, O_RDONLY);
> +	SAFE_IOCTL(fd, BLKGETSIZE64, &dev_size);
> +	SAFE_CLOSE(fd);

We can as well add size to the struct tst_device and fill it in when
device is created, that would be a slightly cleaner solution.

Other than this the rest looks good.

> +	dev_size = dev_size/1024/1024;
> +
> +	if (mnt_data)
> +		snprintf(buf, buf_size, "%s,size=%luM", mnt_data, dev_size);
> +	else
> +		snprintf(buf, buf_size, "size=%luM", dev_size);
> +
> +	tst_res(TINFO, "Limiting tmpfs size to %luMB", dev_size);
> +
> +	return buf;
> +}
> +
>  static void prepare_device(void)
>  {
> +	char *mnt_data, buf[1024];
> +
>  	if (tst_test->format_device) {
>  		SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
>  			  tst_test->dev_extra_opts);
> @@ -896,8 +923,11 @@ static void prepare_device(void)
>  	}
>  
>  	if (tst_test->mount_device) {
> +		mnt_data = limit_tmpfs_mount_size(tst_test->mnt_data,
> +				buf, sizeof(buf), tdev.fs_type);
> +
>  		SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
> -			   tst_test->mnt_flags, tst_test->mnt_data);
> +			   tst_test->mnt_flags, mnt_data);
>  		mntpoint_mounted = 1;
>  	}
>  }
> -- 
> 2.31.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2021-07-07  9:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-05  8:25 [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Li Wang
2021-07-05  8:25 ` [LTP] [PATCH v2 2/2] lib: mount tmpfs name as ltp-tmpfs Li Wang
2021-07-07  9:32   ` Cyril Hrubis
2021-07-07  9:31 ` Cyril Hrubis [this message]
2021-07-08  2:50   ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Li Wang
2021-07-08  6:36     ` Li Wang

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=YOV0bemK+1NI0Cz4@yuki \
    --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