From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/1] Use real FS block size in fallocate05
Date: Fri, 29 Nov 2019 07:01:36 -0500 (EST) [thread overview]
Message-ID: <26933665.14359191.1575028896043.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20191128093610.6903-2-mdoucha@suse.cz>
Hi,
<snip>
>
> static void run(void)
> {
> - char buf[FALLOCATE_SIZE];
> - ssize_t ret;
> + size_t bufsize, i;
> + struct stat statbuf;
>
> fd = SAFE_OPEN(MNTPOINT "/test_file", O_WRONLY | O_CREAT);
>
> - if (fallocate(fd, 0, 0, FALLOCATE_SIZE)) {
> - if (errno == EOPNOTSUPP) {
> - tst_res(TCONF | TERRNO, "fallocate() not supported");
> + // Use real FS block size, otherwise fallocate() call will test
> + // different things on different platforms
Style guide favors c-style comments.
> + SAFE_FSTAT(fd, &statbuf);
> + bufsize = FALLOCATE_BLOCKS * statbuf.st_blksize;
> + buf = realloc(buf, bufsize);
> +
> + if (!buf) {
> + tst_brk(TBROK, "Buffer allocation failed");
> + SAFE_CLOSE(fd);
> + return;
Anything after TBROK will be unreachable.
> + }
> +
> + TEST(fallocate(fd, 0, 0, bufsize));
> +
> + if (TST_RET) {
> + if (errno == ENOTSUP) {
TEST_ERR
> + tst_res(TCONF | TTERRNO, "fallocate() not supported");
tst_brk would make more sense here. If we fail here we can end the test.
> SAFE_CLOSE(fd);
> return;
> }
>
> - tst_brk(TBROK | TERRNO,
> - "fallocate(fd, 0, 0, %i)", FALLOCATE_SIZE);
> + tst_brk(TBROK | TTERRNO, "fallocate(fd, 0, 0, %i)", bufsize);
> }
>
> tst_fill_fs(MNTPOINT, 1);
>
> - ret = write(fd, buf, sizeof(buf));
> + TEST(write(fd, buf, bufsize));
>
> - if (ret < 0)
> - tst_res(TFAIL | TERRNO, "write() failed unexpectedly");
> + if (TST_RET < 0)
> + tst_res(TFAIL | TTERRNO, "write() failed unexpectedly");
> + else if (TST_RET != bufsize)
> + tst_res(TFAIL,
> + "Short write(): %ld bytes (expected %zu)",
> + TST_RET, bufsize);
> else
> - tst_res(TPASS, "write() wrote %zu bytes", ret);
> + tst_res(TPASS, "write() wrote %ld bytes", TST_RET);
>
> - ret = fallocate(fd, 0, FALLOCATE_SIZE, FALLOCATE_SIZE);
> - if (ret != -1)
> + // fallocate(1 block) may pass here on XFS. Original test allocated
> + // 8KB (2 blocks on x86) so keep the original behavior.
> + TEST(fallocate(fd, 0, bufsize, 2 * statbuf.st_blksize));
I don't understand why there is need to find minimum value that can
satisfy this check. It looks like we are testing tst_fill_fs() more
than fallocate().
In other words, what is wrong with current test? Is the problem that
FALLOCATE_SIZE (1M) is not aligned on all platforms? Or is the test
invalid with FALLOCATE_SIZE that big? Or both?
<snip>
>
> @@ -80,6 +102,9 @@ static void cleanup(void)
> {
> if (fd > 0)
> SAFE_CLOSE(fd);
> +
> + if (buf)
Check is not needed, free() can handle NULL.
next prev parent reply other threads:[~2019-11-29 12:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-28 9:36 [LTP] [PATCH 0/1] Use real FS block size in fallocate05 Martin Doucha
2019-11-28 9:36 ` [LTP] [PATCH 1/1] " Martin Doucha
2019-11-28 17:47 ` Petr Vorel
2019-11-29 9:54 ` Martin Doucha
2019-11-29 12:01 ` Jan Stancek [this message]
2019-11-29 15:25 ` Martin Doucha
2019-11-29 16:17 ` Jan Stancek
2019-12-04 10:38 ` Martin Doucha
2019-12-13 13:40 ` Cyril Hrubis
2019-12-17 13:17 ` [LTP] [PATCH v2] " Martin Doucha
2019-12-17 21:02 ` Jan Stancek
2019-12-18 9:09 ` Martin Doucha
2019-12-18 10:01 ` Martin Doucha
2019-12-18 10:07 ` Jan Stancek
2019-12-18 13:15 ` [LTP] [PATCH v3] " Martin Doucha
2020-01-02 10:01 ` Jan Stancek
2020-01-07 15:21 ` Cyril Hrubis
2020-01-07 15:50 ` Martin Doucha
2020-01-13 12:16 ` Martin Doucha
2020-01-13 13:16 ` Qu WenRuo
2020-01-13 13:25 ` Martin Doucha
2020-01-13 13:30 ` Qu WenRuo
2020-01-07 16:09 ` Martin Doucha
2020-01-07 16:29 ` Cyril Hrubis
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=26933665.14359191.1575028896043.JavaMail.zimbra@redhat.com \
--to=jstancek@redhat.com \
--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