* [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP
@ 2021-07-05 8:25 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:31 ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Cyril Hrubis
0 siblings, 2 replies; 6+ messages in thread
From: Li Wang @ 2021-07-05 8:25 UTC (permalink / raw)
To: ltp
LTP mount and make use of the whole tmpfs of the test system,
generally, it's fine. But if a test (e.g fallocate06) try to
fill full in the filesystem, it takes too long to complete
testing on a large memory system.
This patch adds a new function limit_tmpfs_mount_size with
appending '-o size=xxM' to the mount options in prepare_device()
which helps limit the tmpfs mount size.
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Li Wang <liwang@redhat.com>
---
Notes:
V1 --> V2
* state limit_tmpfs_mount_size as a static function
* make use of the loop device size directly since
it already gets a proper size in tst_acquire_device_
* do NOT modify the tst_test->mnt_data
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);
+
+ 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 2/2] lib: mount tmpfs name as ltp-tmpfs
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 ` Li Wang
2021-07-07 9:32 ` Cyril Hrubis
2021-07-07 9:31 ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Cyril Hrubis
1 sibling, 1 reply; 6+ messages in thread
From: Li Wang @ 2021-07-05 8:25 UTC (permalink / raw)
To: ltp
Given a specific name as "ltp-tmpfs" instead of the "/dev/loopX"
string in order to make "tmpfs" filesystem more evident.
Achieve that in get_device_name() function.
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Li Wang <liwang@redhat.com>
---
Notes:
V1 --> V2
* create a function get_device_name()
lib/tst_test.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 93761868e..b85134709 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -907,6 +907,14 @@ static char *limit_tmpfs_mount_size(const char *mnt_data,
return buf;
}
+static const char *get_device_name(const char *fs_type)
+{
+ if (!strcmp(fs_type, "tmpfs"))
+ return "ltp-tmpfs";
+ else
+ return tdev.dev;
+}
+
static void prepare_device(void)
{
char *mnt_data, buf[1024];
@@ -926,8 +934,8 @@ static void prepare_device(void)
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, mnt_data);
+ SAFE_MOUNT(get_device_name(tdev.fs_type), tst_test->mntpoint,
+ tdev.fs_type, tst_test->mnt_flags, mnt_data);
mntpoint_mounted = 1;
}
}
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP
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:31 ` Cyril Hrubis
2021-07-08 2:50 ` Li Wang
1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2021-07-07 9:31 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 2/2] lib: mount tmpfs name as ltp-tmpfs
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
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2021-07-07 9:32 UTC (permalink / raw)
To: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP
2021-07-07 9:31 ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Cyril Hrubis
@ 2021-07-08 2:50 ` Li Wang
2021-07-08 6:36 ` Li Wang
0 siblings, 1 reply; 6+ messages in thread
From: Li Wang @ 2021-07-08 2:50 UTC (permalink / raw)
To: ltp
Cyril Hrubis <chrubis@suse.cz> wrote:
>
> > +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.
>
That should be fine. But I'm afraid we have to change the return type
for many functions in tst_device.c, because currently most of them
only return a path to the test device. And that will affect more tests.
Or, maybe just create a function to get the device size and pass it
to tdev.size simply?
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210708/5ddf761e/attachment.htm>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP
2021-07-08 2:50 ` Li Wang
@ 2021-07-08 6:36 ` Li Wang
0 siblings, 0 replies; 6+ messages in thread
From: Li Wang @ 2021-07-08 6:36 UTC (permalink / raw)
To: ltp
On Thu, Jul 8, 2021 at 10:50 AM Li Wang <liwang@redhat.com> wrote:
> Cyril Hrubis <chrubis@suse.cz> wrote:
>
>
>>
>> > +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.
>>
>
>
> That should be fine. But I'm afraid we have to change the return type
> for many functions in tst_device.c, because currently most of them
> only return a path to the test device. And that will affect more tests.
>
> Or, maybe just create a function to get the device size and pass it
> to tdev.size simply?
>
With adding new field 'size' in struct tst_device, I'm also planning
to extract that from tst_acquire_device__ and export it as a global
function:
uint64_t tst_get_device_size(const char *dev_path);
then reuse of it to get block device size in more places, like:
tdev.size = tst_get_device_size(tdev.dev); <-- in prepare_device
and
ltp_dev_size = tst_get_device_size(dev); <-- in tst_acquire_device__
That would keep most of the function API no change and save
the tdev.size. Is this way OK, or any else?
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210708/f5cb6423/attachment.htm>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-08 6:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [LTP] [PATCH v2 1/2] lib: limit the size of tmpfs in LTP Cyril Hrubis
2021-07-08 2:50 ` Li Wang
2021-07-08 6:36 ` Li Wang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.