<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 25, 2019 at 9:13 PM Cyril Hrubis <<a href="mailto:chrubis@suse.cz" target="_blank">chrubis@suse.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi!<br>
> diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c<br>
> index 4003dce97..3015c066e 100644<br>
> --- a/lib/tst_fill_fs.c<br>
> +++ b/lib/tst_fill_fs.c<br>
> @@ -6,6 +6,7 @@<br>
>  #include <errno.h><br>
>  #include <stdio.h><br>
>  #include <stdlib.h><br>
> +#include <sys/statvfs.h><br>
>  <br>
>  #define TST_NO_DEFAULT_MAIN<br>
>  #include "tst_test.h"<br>
> @@ -19,6 +20,8 @@ void tst_fill_fs(const char *path, int verbose)<br>
>       size_t len;<br>
>       ssize_t ret;<br>
>       int fd;<br>
> +     struct statvfs fi;<br>
> +     statvfs(path, &fi);<br>
>  <br>
>       for (;;) {<br>
>               len = random() % (1024 * 102400);<br>
> @@ -37,17 +40,20 @@ void tst_fill_fs(const char *path, int verbose)<br>
>                       return;<br>
>               }<br>
>  <br>
> -             while (len) {<br>
> +             while (len >= fi.f_bsize/2) {<br>
>                       ret = write(fd, buf, MIN(len, sizeof(buf)));<br>
>  <br>
>                       if (ret < 0) {<br>
> +                             if (errno == ENOSPC) {<br>
> +                                     SAFE_FSYNC(fd);<br>
> +                                     len /= 2;<br>
> +                                     continue;<br>
> +                             }<br>
> +<br>
>                               SAFE_CLOSE(fd);<br>
>  <br>
>                               if (errno != ENOSPC)<br>
>                                       tst_brk(TBROK | TERRNO, "write()");<br>
> -<br>
> -                             tst_res(TINFO | TERRNO, "write()");<br>
> -                             return;<br>
>                       }<br>
>  <br>
>                       len -= ret;<br>
<br>
Wouldn't this cause second SAFE_CLOSE() here because we no longer do a<br>
return from from the while loop on ENOSPC?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">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.</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Why not just:<br>
<br>
diff --git a/lib/tst_fill_fs.c b/lib/tst_fill_fs.c<br>
index 4003dce97..2226171d8 100644<br>
--- a/lib/tst_fill_fs.c<br>
+++ b/lib/tst_fill_fs.c<br>
@@ -41,6 +41,13 @@ void tst_fill_fs(const char *path, int verbose)<br>
                        ret = write(fd, buf, MIN(len, sizeof(buf)));<br>
<br>
                        if (ret < 0) {<br>
+                               /* retry on ENOSPC to make sure filesystem is really full */<br>
+                               if (errno == ENOSPC && len >= fi.f_bsize/2) {<br>
+                                       SAFE_FSYNC(fd);<br>
+                                       len /= 2;<br>
+                                       continue;<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">It does the same thing as my patch, but your code looks a little better because it reserves the print&reutrn part in below.</div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I will send patch V3 on your suggestion.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                               }<br>
+<br>
                                SAFE_CLOSE(fd);<br>
<br>
                                if (errno != ENOSPC)<br>
<br>
<br>
-- <br>
Cyril Hrubis<br>
<a href="mailto:chrubis@suse.cz" target="_blank">chrubis@suse.cz</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>