* [LTP] [PATCH v2] tst_fill_fs: enhance the filesystem filling routine
@ 2019-11-20 7:23 Li Wang
2019-11-25 13:01 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Li Wang @ 2019-11-20 7:23 UTC (permalink / raw)
To: ltp
Do more tries with size in half when write() getting ENOSPC, until the size
is less than the filesystem block size. Though we can't really fill a filesystem
full, this could make the routine more robust.
Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Jan Stancek <jstancek@redhat.com>
Cc: Martin Doucha <mdoucha@suse.cz>
---
lib/tst_fill_fs.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
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;
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH v2] tst_fill_fs: enhance the filesystem filling routine
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
2019-11-26 3:24 ` Li Wang
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2019-11-25 13:01 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH v2] tst_fill_fs: enhance the filesystem filling routine
2019-11-25 13:01 ` Cyril Hrubis
@ 2019-11-26 3:24 ` Li Wang
0 siblings, 0 replies; 3+ messages in thread
From: Li Wang @ 2019-11-26 3:24 UTC (permalink / raw)
To: ltp
On Mon, Nov 25, 2019 at 9:13 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> 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?
>
No, it wouldn't cause that. The while's condition judgment will help to
go-out the loop when len < fi.f_bsize/2, and it only do SAFE_CLOSE() once
in any situation I think.
> 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;
>
It does the same thing as my patch, but your code looks a little better
because it reserves the print&reutrn part in below.
I will send patch V3 on your suggestion.
> + }
> +
> SAFE_CLOSE(fd);
>
> if (errno != ENOSPC)
>
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
>
--
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191126/7afc91dc/attachment.htm>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-26 3:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2019-11-26 3:24 ` Li Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox