From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 6/6] syscalls/readahead02: test readahead using posix_fadvise()
Date: Wed, 28 Nov 2018 18:46:45 +0200 [thread overview]
Message-ID: <20181128164645.783-7-amir73il@gmail.com> (raw)
In-Reply-To: <20181128164645.783-1-amir73il@gmail.com>
The call to posix_fadvise(POSIX_FADV_WILLNEED) should have the same
effect as the call to readahead() syscall.
Repeat the test cases for local file and overlayfs file with
posix_fadvise().
The new test case is a regression test for kernel commit b833a3660394
("ovl: add ovl_fadvise()") which fixes a regression of fadvise() on
an overlay file that was introduced by kernel commit 5b910bd615ba
("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs").
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/readahead/readahead02.c | 41 +++++++++++++++----
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 73c8a6ce6..44475487e 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -54,12 +54,30 @@ static struct tst_option options[] = {
static struct tcase {
const char *tname;
int use_overlay;
+ int use_fadvise;
} tcases[] = {
- { "readahead on file", 0 },
- { "readahead on overlayfs file", 1 },
+ { "readahead on file", 0, 0 },
+ { "readahead on overlayfs file", 1, 0 },
+ { "POSIX_FADV_WILLNEED on file", 0, 1 },
+ { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 },
};
+static int fadvise_willneed(int fd, off_t offset, size_t len)
+{
+ /* Should have the same effect as readahead() syscall */
+ return posix_fadvise(fd, offset, len, POSIX_FADV_WILLNEED);
+}
+
+static int libc_readahead(int fd, off_t offset, size_t len)
+{
+ return readahead(fd, offset, len);
+}
+
+typedef int (*readahead_func_t)(int, off_t, size_t);
+static readahead_func_t readahead_func = libc_readahead;
+
static int readahead_supported = 1;
+static int fadvise_supported = 1;
static int has_file(const char *fname, int required)
{
@@ -135,7 +153,6 @@ static void create_testfile(int use_overlay)
free(tmp);
}
-
/* read_testfile - mmap testfile and read every page.
* This functions measures how many I/O and time it takes to fully
* read contents of test file.
@@ -163,7 +180,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,
if (do_readahead) {
cached_start = get_cached_size();
do {
- TEST(readahead(fd, offset, fsize - offset));
+ TEST(readahead_func(fd, offset, fsize - offset));
if (TST_RET != 0) {
SAFE_CLOSE(fd);
return;
@@ -241,6 +258,9 @@ static void test_readahead(unsigned int n)
create_testfile(tc->use_overlay);
+ /* Use either readahead() syscall or POSIX_FADV_WILLNEED */
+ readahead_func = tc->use_fadvise ? fadvise_willneed : libc_readahead;
+
/* find out how much can cache hold if we read whole file */
read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached);
cached_high = get_cached_size();
@@ -263,13 +283,20 @@ static void test_readahead(unsigned int n)
read_testfile(1, testfile, testfile_size, &read_bytes_ra,
&usec_ra, &cached_ra);
if (TST_RET != 0) {
- if (TST_ERR == EINVAL &&
- (!tc->use_overlay || !readahead_supported)) {
+ /* posix_fadvise returns error number (not in errno) */
+ if (tc->use_fadvise && (TST_ERR = TST_RET) == EINVAL &&
+ (!tc->use_overlay || !fadvise_supported)) {
+ fadvise_supported = 0;
+ tst_res(TCONF, "fadvise not supported on %s",
+ tst_device->fs_type);
+ } else if (TST_ERR == EINVAL &&
+ (!tc->use_overlay || !readahead_supported)) {
readahead_supported = 0;
tst_res(TCONF, "readahead not supported on %s",
tst_device->fs_type);
} else {
- tst_res(TFAIL | TTERRNO, "readahead failed on %s",
+ tst_res(TFAIL | TTERRNO, "%s failed on %s",
+ tc->use_fadvise ? "fadvise" : "readahead",
tc->use_overlay ? "overlayfs" :
tst_device->fs_type);
}
--
2.17.1
next prev parent reply other threads:[~2018-11-28 16:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 16:46 [LTP] [PATCH v4 0/6] Tests for readahead() and fadvise() on overlayfs Amir Goldstein
2018-11-28 16:46 ` [LTP] [PATCH v4 1/6] syscalls/readahead02: Convert to newlib and cleanup Amir Goldstein
2018-12-03 14:39 ` Cyril Hrubis
2018-12-03 14:59 ` Amir Goldstein
2018-11-28 16:46 ` [LTP] [PATCH v4 2/6] syscalls/readahead02: abort test if readahead syscall fails Amir Goldstein
2018-12-03 14:27 ` Cyril Hrubis
2018-12-03 14:52 ` Amir Goldstein
2018-11-28 16:46 ` [LTP] [PATCH v4 3/6] syscalls/readahead02: fail test if readahead did not use any cache Amir Goldstein
2018-11-28 16:46 ` [LTP] [PATCH v4 4/6] syscalls/readahead02: Convert to tst_timer helpers Amir Goldstein
2018-11-28 16:46 ` [LTP] [PATCH v4 5/6] syscalls/readahead02: test readahead() on an overlayfs file Amir Goldstein
2018-12-04 14:02 ` Cyril Hrubis
2018-11-28 16:46 ` Amir Goldstein [this message]
2018-12-04 14:10 ` [LTP] [PATCH v4 6/6] syscalls/readahead02: test readahead using posix_fadvise() 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=20181128164645.783-7-amir73il@gmail.com \
--to=amir73il@gmail.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