From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] tst_fill_fs: enhance the filesystem filling routine
Date: Mon, 25 Nov 2019 14:01:55 +0100 [thread overview]
Message-ID: <20191125130155.GA8703@rei.lan> (raw)
In-Reply-To: <20191120072311.32333-1-liwang@redhat.com>
Hi!
> diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c
> index 4003dce97..3015c066e 100644
> --- a/lib/tst_fill_fs.c
> +++ b/lib/tst_fill_fs.c
> @@ -6,6 +6,7 @@
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
> +#include <sys/statvfs.h>
>
> #define TST_NO_DEFAULT_MAIN
> #include "tst_test.h"
> @@ -19,6 +20,8 @@ void tst_fill_fs(const char *path, int verbose)
> size_t len;
> ssize_t ret;
> int fd;
> + struct statvfs fi;
> + statvfs(path, &fi);
>
> for (;;) {
> len = random() % (1024 * 102400);
> @@ -37,17 +40,20 @@ void tst_fill_fs(const char *path, int verbose)
> return;
> }
>
> - while (len) {
> + while (len >= fi.f_bsize/2) {
> ret = write(fd, buf, MIN(len, sizeof(buf)));
>
> if (ret < 0) {
> + if (errno == ENOSPC) {
> + SAFE_FSYNC(fd);
> + len /= 2;
> + continue;
> + }
> +
> SAFE_CLOSE(fd);
>
> if (errno != ENOSPC)
> tst_brk(TBROK | TERRNO, "write()");
> -
> - tst_res(TINFO | TERRNO, "write()");
> - return;
> }
>
> len -= ret;
Wouldn't this cause second SAFE_CLOSE() here because we no longer do a
return from from the while loop on ENOSPC?
Why not just:
diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c
index 4003dce97..2226171d8 100644
--- a/lib/tst_fill_fs.c
+++ b/lib/tst_fill_fs.c
@@ -41,6 +41,13 @@ void tst_fill_fs(const char *path, int verbose)
ret = write(fd, buf, MIN(len, sizeof(buf)));
if (ret < 0) {
+ /* retry on ENOSPC to make sure filesystem is really full */
+ if (errno == ENOSPC && len >= fi.f_bsize/2) {
+ SAFE_FSYNC(fd);
+ len /= 2;
+ continue;
+ }
+
SAFE_CLOSE(fd);
if (errno != ENOSPC)
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2019-11-25 13:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 7:23 [LTP] [PATCH v2] tst_fill_fs: enhance the filesystem filling routine Li Wang
2019-11-25 13:01 ` Cyril Hrubis [this message]
2019-11-26 3:24 ` 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=20191125130155.GA8703@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