Tests for readahead() and fadvise() on overlayfs
cover Tests for readahead() and fadvise() on overlayfs
Cyril,
The following series adds test covergae for readahead() syscall over overlayfs file and adds test coverage for a specific posix_fadvise() syscall advice (POSIX_FADV_WILLNEED).
So far, the posix_fadvise syscall tests in LTP only test for error conditions, but not functionality. The functionality of the advice POSIX_FADV_WILLNEED is indentical to readahead(), so I decided not to duplicate the readahead functional test and add test cases to readahead02 that use the POSIX_FADV_WILLNEED implementation.
Before I decided not to write new posix_fadvise() tests I converted the existing tests to newlib. That is available for you as github PR:
https://github.com/linux-test-project/ltp/pull/401
Thanks,
Amir.
Amir Goldstein (4):
syscalls/readahead01: Convert to newlib syscalls/readahead02: Convert to newlib and cleanup syscalls/readahead02: test readahead() on an overlayfs file syscalls/readahead02: test readahead using posix_fadvise()
.../kernel/syscalls/readahead/readahead01.c | 119 ++----- .../kernel/syscalls/readahead/readahead02.c | 332 +++++++++--------- 2 files changed, 191 insertions(+), 260 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/4 syscalls/readahead01: Convert to newlib
* Use SPDX-License-Identifier
--- .../kernel/syscalls/readahead/readahead01.c | 119 +++++------------- 1 file changed, 34 insertions(+), 85 deletions(-)
testcases/kernel/syscalls/readahead/readahead01.c +34 -85
@@ -1,25 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. */ /*
@@ -36,47 +17,36 @@#include <sys/syscall.h> #include <sys/types.h> #include "config.h" -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" -char *TCID ="readahead01" ; -int TST_TOTAL =1 ; - -option_t options[] = { - {NULL ,NULL ,NULL } -}; -#if defined(__NR_readahead) -static void setup (void ); -static void cleanup (void ); -static int check_ret (long expected_ret) { -if (expected_ret ==TEST_RETURN ) { -tst_resm (TPASS ,"expected ret success - " -"returned value = %ld" ,TEST_RETURN ); +if (expected_ret ==TST_RET ) { +tst_res (TPASS ,"expected ret success - " +"returned value = %ld" ,TST_RET );return 0 ; } -tst_resm (TFAIL ,"unexpected failure - " -"returned value = %ld, expected: %ld" , -TEST_RETURN , expected_ret); +tst_res (TFAIL ,"unexpected failure - " +"returned value = %ld, expected: %ld" , +TST_RET , expected_ret);return 1 ; }static int check_errno (long expected_errno) { -if (TEST_ERRNO == expected_errno) { -tst_resm (TPASS |TTERRNO ,"expected failure" ); +if (TST_ERR == expected_errno) { +tst_res (TPASS |TTERRNO ,"expected failure" );return 0 ; } -if (TEST_ERRNO ==0 ) -tst_resm (TFAIL ,"call succeeded unexpectedly" ); +if (TST_ERR ==0 ) +tst_res (TFAIL ,"call succeeded unexpectedly" );else -tst_resm (TFAIL |TTERRNO ,"unexpected failure - " -"expected = %ld : %s, actual" , - expected_errno,strerror (expected_errno)); +tst_res (TFAIL |TTERRNO ,"unexpected failure - " +"expected = %ld : %s, actual" , + expected_errno,strerror (expected_errno));return 1 ; }
@@ -85,19 +55,17 @@ static void test_bad_fd(void)char tempname[PATH_MAX ] ="readahead01_XXXXXX" ;int fd; -tst_resm (TINFO ,"test_bad_fd -1" ); +tst_res (TINFO ,"test_bad_fd -1" );TEST (readahead (-1 ,0 ,getpagesize ()));check_ret (-1 );check_errno (EBADF ); -tst_resm (TINFO ,"test_bad_fd O_WRONLY" ); +tst_res (TINFO ,"test_bad_fd O_WRONLY" ); fd =mkstemp (tempname);if (fd ==-1 ) -tst_resm (TBROK |TERRNO ,"mkstemp failed" ); +tst_res (TBROK |TERRNO ,"mkstemp failed" );close (fd); - fd =open (tempname,O_WRONLY ); -if (fd ==-1 ) -tst_resm (TBROK |TERRNO ,"Failed to open testfile" ); + fd =SAFE_OPEN (tempname,O_WRONLY );TEST (readahead (fd,0 ,getpagesize ()));check_ret (-1 );check_errno (EBADF );
@@ -109,60 +77,41 @@ static void test_invalid_fd(void) {int fd[2 ]; -tst_resm (TINFO ,"test_invalid_fd pipe" ); -if (pipe (fd) <0 ) -tst_resm (TBROK |TERRNO ,"Failed to create pipe" ); +tst_res (TINFO ,"test_invalid_fd pipe" ); +SAFE_PIPE (fd);TEST (readahead (fd[0 ],0 ,getpagesize ()));check_ret (-1 );check_errno (EINVAL );close (fd[0 ]);close (fd[1 ]); -tst_resm (TINFO ,"test_invalid_fd socket" ); - fd[0 ] =socket (AF_INET ,SOCK_STREAM ,0 ); -if (fd[0 ] <0 ) -tst_resm (TBROK |TERRNO ,"Failed to create socket" ); +tst_res (TINFO ,"test_invalid_fd socket" ); + fd[0 ] =SAFE_SOCKET (AF_INET ,SOCK_STREAM ,0 );TEST (readahead (fd[0 ],0 ,getpagesize ()));check_ret (-1 );check_errno (EINVAL );close (fd[0 ]); } -int main (int argc,char *argv[]) +void test_readahead (void ) { -int lc; - -tst_parse_opts (argc, argv, options,NULL ); - -setup (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -test_bad_fd (); -test_invalid_fd (); - } -cleanup (); -tst_exit (); +test_bad_fd (); +test_invalid_fd (); }static void setup (void ) { -tst_require_root (); -tst_tmpdir (); -/* check if readahead syscall is supported */ -ltp_syscall (__NR_readahead,0 ,0 ,0 ); - -TEST_PAUSE ; +tst_syscall (__NR_readahead,0 ,0 ,0 ); } -static void cleanup (void ) -{ -tst_rmdir (); -} +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .setup = setup, + .test_all = test_readahead, +};#else /* __NR_readahead */ -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"System doesn't support __NR_readahead" ); -} +TST_TEST_TCONF ("System doesn't support __NR_readahead" );#endif
Signature · 1 line
2.17.1
PATCH 2/4 syscalls/readahead02: Convert to newlib and cleanup
In reply to Amir Goldstein* Use SAFE macros
* Use SPDX-License-Identifier
* No need to cleanup test file from temp dir
--- .../kernel/syscalls/readahead/readahead02.c | 246 +++++------------- 1 file changed, 70 insertions(+), 176 deletions(-)
testcases/kernel/syscalls/readahead/readahead02.c +70 -176
@@ -1,25 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of version 2 of the GNU General Public -* License as published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* Further, this software is distributed without any warranty that it -* is free of the rightful claim of any third person regarding -* infringement or the like. Any license provided herein, whether -* implied or otherwise, applies only to this software file. Patent -* licenses, if any, provided herein do not apply to combinations of -* this program with other software, or any other product whatsoever. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -* 02110-1301, USA. */ /*
@@ -43,86 +24,55 @@#include <unistd.h> #include <fcntl.h> #include "config.h" -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" -char *TCID ="readahead02" ; -int TST_TOTAL =1 ; -#if defined(__NR_readahead)static char testfile[PATH_MAX ] ="testfile" ;static const char drop_caches_fname[] ="/proc/sys/vm/drop_caches" ;static const char meminfo_fname[] ="/proc/meminfo" ;static size_t testfile_size =64 *1024 *1024 ; -static int opt_fsize;static char *opt_fsizestr;static int pagesize; -static const char *fs_type; -static const char *device; -static int mount_flag;#define MNTPOINT "mntpoint" +static const char mntpoint[] ="mntpoint" ;#define MIN_SANE_READAHEAD (4u * 1024u) -option_t options[] = { - {"s:" , &opt_fsize, &opt_fsizestr}, +static struct tst_option options[] = { + {"s:" , &opt_fsizestr,"-s testfile size (default 64MB)" }, {NULL ,NULL ,NULL } }; -static void setup (void ); -static void cleanup (void ); - -static void help (void ) -{ -printf (" -s x testfile size (default 64MB)\n" ); -} -static int check_ret (long expected_ret) { -if (expected_ret ==TEST_RETURN ) { -tst_resm (TPASS ,"expected ret success - " -"returned value = %ld" ,TEST_RETURN ); +if (expected_ret ==TST_RET ) { +tst_res (TPASS ,"expected ret success - " +"returned value = %ld" ,TST_RET );return 0 ; } -tst_resm (TFAIL |TTERRNO ,"unexpected failure - " -"returned value = %ld, expected: %ld" , -TEST_RETURN , expected_ret); +tst_res (TFAIL |TTERRNO ,"unexpected failure - " +"returned value = %ld, expected: %ld" , +TST_RET , expected_ret);return 1 ; }static int has_file (const char *fname,int required) { -int ret;struct stat buf; - ret =stat (fname, &buf); -if (ret ==-1 ) { -if (errno ==ENOENT ) -if (required) -tst_brkm (TCONF , cleanup,"%s not available" , - fname); -else -return 0 ; -else -tst_brkm (TBROK |TERRNO , cleanup,"stat %s" , fname); + +if (stat (fname, &buf) ==-1 ) { +if (errno !=ENOENT ) +tst_brk (TBROK |TERRNO ,"stat %s" , fname); +if (required) +tst_brk (TCONF ,"%s not available" , fname); }return 1 ; }static void drop_caches (void ) { -int ret; -FILE *f; - - f =fopen (drop_caches_fname,"w" ); -if (f) { - ret =fprintf (f,"1" ); -fclose (f); -if (ret <1 ) -tst_brkm (TBROK , cleanup,"Failed to drop caches" ); - }else { -tst_brkm (TBROK , cleanup,"Failed to open drop_caches" ); - } +SAFE_FILE_PRINTF (drop_caches_fname,"1" ); }static unsigned long parse_entry (const char *fname,const char *entry)
@@ -161,32 +111,21 @@ static unsigned long get_cached_size(void)static void create_testfile (void ) { -FILE *f; +int fd;char *tmp;size_t i; -tst_resm (TINFO ,"creating test file of size: %zu" , testfile_size); - tmp =SAFE_MALLOC (cleanup, pagesize); +tst_res (TINFO ,"creating test file of size: %zu" , testfile_size); + tmp =SAFE_MALLOC (pagesize);/* round to page size */ testfile_size = testfile_size & ~((long )pagesize -1 ); - f =fopen (testfile,"w" ); -if (!f) { -free (tmp); -tst_brkm (TBROK |TERRNO , cleanup,"Failed to create %s" , - testfile); - } - + fd =SAFE_CREAT (testfile,0644 );for (i =0 ; i < testfile_size; i += pagesize) -if (fwrite (tmp, pagesize,1 , f) <1 ) { -free (tmp); -tst_brkm (TBROK , cleanup,"Failed to create %s" , - testfile); - } -fflush (f); -fsync (fileno (f)); -fclose (f); +SAFE_WRITE (1 , fd, tmp, pagesize); +SAFE_FSYNC (fd); +SAFE_CLOSE (fd);free (tmp); }
@@ -215,13 +154,13 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,off_t offset =0 ;struct timeval now; - fd =SAFE_OPEN (cleanup, fname,O_RDONLY ); + fd =SAFE_OPEN (fname,O_RDONLY );if (do_readahead) { cached_start =get_cached_size (); do { TEST(readahead(fd, offset, fsize - offset)); - if (TEST_RETURN != 0) { + if (TST_RET != 0) { check_ret(0); break; }
@@ -232,7 +171,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,if (*cached > cached_start) { max_ra_estimate = (1024 * (*cached - cached_start)); -tst_resm (TINFO ,"max ra estimate: %lu" , +tst_res (TINFO ,"max ra estimate: %lu" , max_ra_estimate); } max_ra_estimate = MAX(max_ra_estimate,
@@ -242,27 +181,23 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, i++; offset += max_ra_estimate; }while ((size_t )offset < fsize); -tst_resm (TINFO ,"readahead calls made: %zu" , i); +tst_res (TINFO ,"readahead calls made: %zu" , i); *cached =get_cached_size ();/* offset of file shouldn't change after readahead */ - offset =lseek (fd,0 ,SEEK_CUR ); -if (offset == (off_t) -1 ) -tst_brkm (TBROK |TERRNO , cleanup,"lseek failed" ); + offset =SAFE_LSEEK (fd,0 ,SEEK_CUR );if (offset ==0 ) -tst_resm (TPASS ,"offset is still at 0 as expected" ); +tst_res (TPASS ,"offset is still at 0 as expected" );else -tst_resm (TFAIL ,"offset has changed to: %lu" , offset); +tst_res (TFAIL ,"offset has changed to: %lu" , offset); }if (gettimeofday (&now,NULL ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"gettimeofday failed" ); +tst_brk (TBROK |TERRNO ,"gettimeofday failed" ); time_start_usec = now.tv_sec *1000000 + now.tv_usec; read_bytes_start =get_bytes_read (); - p =mmap (NULL , fsize,PROT_READ ,MAP_SHARED |MAP_POPULATE , fd,0 ); -if (p ==MAP_FAILED ) -tst_brkm (TBROK |TERRNO , cleanup,"mmap failed" ); + p =SAFE_MMAP (NULL , fsize,PROT_READ ,MAP_SHARED |MAP_POPULATE , fd,0 );/* for old kernels, where MAP_POPULATE doesn't work, touch each page */ tmp =0 ;
@@ -270,20 +205,20 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, tmp = tmp ^ p[i];/* prevent gcc from optimizing out loop above */ if (tmp !=0 ) -tst_brkm (TBROK ,NULL ,"This line should not be reached" ); +tst_brk (TBROK ,"This line should not be reached" );if (!do_readahead) *cached =get_cached_size (); -SAFE_MUNMAP (cleanup, p, fsize); +SAFE_MUNMAP (p, fsize); *read_bytes =get_bytes_read () - read_bytes_start;if (gettimeofday (&now,NULL ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"gettimeofday failed" ); +tst_brk (TBROK |TERRNO ,"gettimeofday failed" ); time_end_usec = now.tv_sec *1000000 + now.tv_usec; *usec = time_end_usec - time_start_usec; -SAFE_CLOSE (cleanup, fd); +SAFE_CLOSE (fd); }static void test_readahead (void )
@@ -302,7 +237,7 @@ static void test_readahead(void) cached_low =get_cached_size (); cached_max = cached_max - cached_low; -tst_resm (TINFO ,"read_testfile(0)" ); +tst_res (TINFO ,"read_testfile(0)" );read_testfile (0 , testfile, testfile_size, &read_bytes, &usec, &cached);if (cached > cached_low) cached = cached - cached_low;
@@ -312,7 +247,7 @@ static void test_readahead(void)sync ();drop_caches (); cached_low =get_cached_size (); -tst_resm (TINFO ,"read_testfile(1)" ); +tst_res (TINFO ,"read_testfile(1)" );read_testfile (1 , testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra);if (cached_ra > cached_low)
@@ -320,25 +255,25 @@ static void test_readahead(void)else cached_ra =0 ; -tst_resm (TINFO ,"read_testfile(0) took: %ld usec" , usec); -tst_resm (TINFO ,"read_testfile(1) took: %ld usec" , usec_ra); +tst_res (TINFO ,"read_testfile(0) took: %ld usec" , usec); +tst_res (TINFO ,"read_testfile(1) took: %ld usec" , usec_ra);if (has_file (proc_io_fname,0 )) { -tst_resm (TINFO ,"read_testfile(0) read: %ld bytes" , read_bytes); -tst_resm (TINFO ,"read_testfile(1) read: %ld bytes" , - read_bytes_ra); +tst_res (TINFO ,"read_testfile(0) read: %ld bytes" , read_bytes); +tst_res (TINFO ,"read_testfile(1) read: %ld bytes" , + read_bytes_ra);/* actual number of read bytes depends on total RAM */ if (read_bytes_ra < read_bytes) -tst_resm (TPASS ,"readahead saved some I/O" ); +tst_res (TPASS ,"readahead saved some I/O" );else -tst_resm (TFAIL ,"readahead failed to save any I/O" ); +tst_res (TFAIL ,"readahead failed to save any I/O" ); }else { -tst_resm (TCONF ,"Your system doesn't have /proc/pid/io," -" unable to determine read bytes during test" ); +tst_res (TCONF ,"Your system doesn't have /proc/pid/io," +" unable to determine read bytes during test" ); } -tst_resm (TINFO ,"cache can hold at least: %ld kB" , cached_max); -tst_resm (TINFO ,"read_testfile(0) used cache: %ld kB" , cached); -tst_resm (TINFO ,"read_testfile(1) used cache: %ld kB" , cached_ra); +tst_res (TINFO ,"cache can hold at least: %ld kB" , cached_max); +tst_res (TINFO ,"read_testfile(0) used cache: %ld kB" , cached); +tst_res (TINFO ,"read_testfile(1) used cache: %ld kB" , cached_ra);if (cached_max *1024 >= testfile_size) {/*
@@ -346,83 +281,42 @@ static void test_readahead(void)* for readahead should be at least testfile_size/2 */ if (cached_ra *1024 > testfile_size /2 ) -tst_resm (TPASS ,"using cache as expected" ); +tst_res (TPASS ,"using cache as expected" );else - tst_resm(TWARN, "using less cache than expected"); + tst_res(TWARN, "using less cache than expected"); }else { -tst_resm (TCONF ,"Page cache on your system is too small " -"to hold whole testfile." ); +tst_res (TCONF ,"Page cache on your system is too small " +"to hold whole testfile." ); } } -int main (int argc,char *argv[]) -{ -int lc; - -tst_parse_opts (argc, argv, options, help); - -if (opt_fsize) - testfile_size =atoi (opt_fsizestr); - -setup (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -test_readahead (); - } -cleanup (); -tst_exit (); -} -static void setup (void ) { -tst_require_root (); -tst_tmpdir (); -TEST_PAUSE ; +if (opt_fsizestr) + testfile_size =SAFE_STRTOL (opt_fsizestr,1 ,INT_MAX );has_file (drop_caches_fname,1 );has_file (meminfo_fname,1 );/* check if readahead is supported */ -ltp_syscall (__NR_readahead,0 ,0 ,0 ); +tst_syscall (__NR_readahead,0 ,0 ,0 ); pagesize =getpagesize (); -if (tst_fs_type (cleanup,"." ) ==TST_TMPFS_MAGIC ) { -tst_resm (TINFO ,"TMPFS detected, creating loop device" ); - - fs_type =tst_dev_fs_type (); - device =tst_acquire_device (cleanup); -if (!device) { -tst_brkm (TCONF , cleanup, -"Failed to obtain block device" ); - } - -tst_mkfs (cleanup, device, fs_type,NULL ,NULL ); - -SAFE_MKDIR (cleanup,MNTPOINT ,0755 ); -SAFE_MOUNT (cleanup, device,MNTPOINT , fs_type,0 ,NULL ); - mount_flag =1 ; - -sprintf (testfile,MNTPOINT "/testfile" ); - } +sprintf (testfile,"%s/testfile" , mntpoint);create_testfile (); } -static void cleanup (void ) -{ -unlink (testfile); -if (mount_flag &&tst_umount (MNTPOINT ) <0 ) -tst_resm (TWARN |TERRNO ,"umount device:%s failed" , device); - -if (device) -tst_release_device (device); - -tst_rmdir (); -} +static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .mount_device =1 , + .mntpoint = mntpoint, + .setup = setup, + .options = options, + .test_all = test_readahead, +};#else /* __NR_readahead */ -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"System doesn't support __NR_readahead" ); -} +TST_TEST_TCONF ("System doesn't support __NR_readahead" );#endif
Signature · 1 line
2.17.1
Re: [LTP] [PATCH 2/4] syscalls/readahead02: Convert to newlib and cleanup
----- Original Message -----
Quoted 7 lines
* Use SAFE macros
* Use SPDX-License-Identifier
* No need to cleanup test file from temp dir
Signed-off-by Amir Goldstein <[email protected]>
Hi,
ack to 1/4
Quoted 14 lines
static int
has_file(const char *fname, int required){testcases/kernel/syscalls/readahead/readahead02.c +0
-10-int ret;struct stat buf; - ret =stat (fname, &buf); -if (ret ==-1 ) { -if (errno ==ENOENT ) -if (required) -tst_brkm (TCONF , cleanup,"%s not available" , - fname); -else -return 0 ; -else
testcases/kernel/syscalls/readahead/readahead02.c line 71
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +6
-1-tst_brkm (TBROK |TERRNO , cleanup,"stat %s" , fname); + +if (stat (fname, &buf) ==-1 ) { +if (errno !=ENOENT ) +tst_brk (TBROK |TERRNO ,"stat %s" , fname); +if (required) +tst_brk (TCONF ,"%s not available" , fname); }return 1 ; }
This will return 1 even when file doesn't exist.
(Not that it makes big difference for test)
<snip>
testcases/kernel/syscalls/readahead/readahead02.c static void test_readahead(void) · line 318
Quoted 9 lines
testcases/kernel/syscalls/readahead/readahead02.c +9
-0+static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .mount_device =1 , + .mntpoint = mntpoint, + .setup = setup, + .options = options, + .test_all = test_readahead, +};
Would it make sense to enable this for 'all_filesystems = 1'? Previously we used whatever fs /tmp was, now we seem to default always to ext2.
Regards,
Jan
Quoted 15 lines
#else /*
__NR_readahead*/testcases/kernel/syscalls/readahead/readahead02.c +1
-5-int main (void ) -{ -tst_brkm (TCONF ,NULL ,"System doesn't support __NR_readahead" ); -} +TST_TEST_TCONF ("System doesn't support __NR_readahead" );#endif --2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/4] syscalls/readahead02: Convert to newlib and cleanup
Quoted 40 lines · Jan Stancek
----- Original Message -----
Quoted 7 lines
* Use SAFE macros
* Use SPDX-License-Identifier
* No need to cleanup test file from temp dir
Signed-off-by Amir Goldstein <[email protected]>Hi,
ack to 1/4
Quoted 14 lines
static int
has_file(const char *fname, int required){testcases/kernel/syscalls/readahead/readahead02.c +0
-10-int ret;struct stat buf; - ret =stat (fname, &buf); -if (ret ==-1 ) { -if (errno ==ENOENT ) -if (required) -tst_brkm (TCONF , cleanup,"%s not available" , - fname); -else -return 0 ; -else testcases/kernel/syscalls/readahead/readahead02.c line 71
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +6
-1-tst_brkm (TBROK |TERRNO , cleanup,"stat %s" , fname); + +if (stat (fname, &buf) ==-1 ) { +if (errno !=ENOENT ) +tst_brk (TBROK |TERRNO ,"stat %s" , fname); +if (required) +tst_brk (TCONF ,"%s not available" , fname); }return 1 ; }
Quoted 3 lines
This will return 1 even when file doesn't exist.
(Not that it makes big difference for test)
Oops. better fix it anyway.
I think it matters if /proc/pid/io does not exist.
Quoted 12 lines
testcases/kernel/syscalls/readahead/readahead02.c static void test_readahead(void) · line 318
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +9
-0+static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .mount_device =1 , + .mntpoint = mntpoint, + .setup = setup, + .options = options, + .test_all = test_readahead, +};Would it make sense to enable this for '
all_filesystems= 1'?
I don't know. Not sure which tests are good candidates for that. But anyway it's a different change.
Quoted 3 lines
Previously we used whatever fs /tmp was, now we seem to default always to ext2.
Not exactly. Before cleanup we either used whatever fs /tmp was or if it was tmpfs we created a loop backed default fs (ext2?).
Now we skip the conditional part and always format fs. Do you think that matters for the test?
Thanks,
Amir.
Re: [LTP] [PATCH 2/4] syscalls/readahead02: Convert to newlib and cleanup
----- Original Message -----
Quoted 70 lines · Jan Stancek
Quoted 42 lines
----- Original Message -----
Quoted 7 lines
* Use SAFE macros
* Use SPDX-License-Identifier
* No need to cleanup test file from temp dir
Signed-off-by Amir Goldstein <[email protected]>Hi,
ack to 1/4
Quoted 17 lines
static int
has_file(const char *fname, int required){testcases/kernel/syscalls/readahead/readahead02.c +0
-6-int ret;struct stat buf; - ret =stat (fname, &buf); -if (ret ==-1 ) { -if (errno ==ENOENT ) -if (required) - tst_brkm(TCONF, cleanup, "%s notavailable",
testcases/kernel/syscalls/readahead/readahead02.c +0
-5- fname); - else - return 0; - else - tst_brkm(TBROK | TERRNO, cleanup, "stat %s",fname);
testcases/kernel/syscalls/readahead/readahead02.c line 71
Quoted 9 lines
testcases/kernel/syscalls/readahead/readahead02.c +6
-0+ +if (stat (fname, &buf) ==-1 ) { +if (errno !=ENOENT ) +tst_brk (TBROK |TERRNO ,"stat %s" , fname); +if (required) +tst_brk (TCONF ,"%s not available" , fname); }return 1 ; }Quoted 3 lines
This will return 1 even when file doesn't exist.
(Not that it makes big difference for test)Oops. better fix it anyway.
I think it matters if/proc/pid/iodoes not exist.Quoted 12 lines
testcases/kernel/syscalls/readahead/readahead02.c static void test_readahead(void) · line 318
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +9
-0+static struct tst_test test = { + .needs_root =1 , + .needs_tmpdir =1 , + .mount_device =1 , + .mntpoint = mntpoint, + .setup = setup, + .options = options, + .test_all = test_readahead, +};Would it make sense to enable this for '
all_filesystems= 1'?I don't know. Not sure which tests are good candidates for that. But anyway it's a different change.
Quoted 3 lines
Previously we used whatever fs /tmp was, now we seem to default always to ext2.
Quoted 5 lines
Not exactly. Before cleanup we either used whatever fs /tmp was or if it was tmpfs we created a loop backed default fs (ext2?).
Now we skip the conditional part and always format fs. Do you think that matters for the test?
Isn't the reason for your series to test on different fs as well? :-)
I don't have strong opinion on this, it's a test for "suggestion to kernel", so it could also make it prone to report more false positives. Feel free to ignore this comment for v2.
Regards,
Jan
Quoted 4 lines
Thanks,
Amir.
Re: [LTP] [PATCH 2/4] syscalls/readahead02: Convert to newlib and cleanup
Quoted 1 line · Jan Stancek
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Would it make sense to enable this for '
all_filesystems= 1'?I don't know. Not sure which tests are good candidates for that. But anyway it's a different change.
[...]
Quoted 3 lines
Isn't the reason for your series to test on different fs as well? :-)
Well, yes and no.
Yes, overlayfs is a filesystem driver.
No, I don't think overlayfs was what the author of all_filesystems had in mind, because setting .dev_fs_type = "overlay" is not enough to describe the setup. That sort of setup would need to be described something like this:
.dev_fs_type = "foo",
.mntpoint = MNTPOINT,
.overlay_mount = OVL_MNT,
So overlayfs does not belong on the all_filesystems axis IMO, it belongs on a tangent axis of the test matrix, e.g.:
.all_filesystems = 1,
.needs_overlay = 1,
.mntpoint = MNTPOINT,
.overlay_mount = OVL_MNT,
I personally question the value of such feature, but putting something like setup_overlay() in a library is probably not a bad idea.
A similar pattern already exists in inotify07/inotify08, however in those tests as
well as in readahead02, a feature of .need_overlay = 1 if existed would not have been sufficient.
Thanks,
Amir.
PATCH 3/4 syscalls/readahead02: test readahead() on an overlayfs file
In reply to Amir GoldsteinRepeat the test case on an overlayfs file.
The new test case is a regression test for kernel commit b833a3660394 ("ovl: add ovl_fadvise()") which fixes a regression of readahead() on an overlay file that was introduced by kernel commit 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs").
--- .../kernel/syscalls/readahead/readahead02.c | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/readahead/readahead02.c +49 -6
@@ -14,6 +14,7 @@#include <sys/types.h> #include <sys/syscall.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h>
@@ -34,9 +35,15 @@ static const char meminfo_fname[] = "/proc/meminfo";static size_t testfile_size =64 *1024 *1024 ;static char *opt_fsizestr;static int pagesize; +static int ovl_mounted;#define MNTPOINT "mntpoint" -static const char mntpoint[] ="mntpoint" ; +#define OVL_LOWER MNTPOINT"/lower" +#define OVL_UPPER MNTPOINT"/upper" +#define OVL_WORK MNTPOINT"/work" +#define OVL_MNT MNTPOINT"/ovl" + +static const char mntpoint[] =MNTPOINT ;#define MIN_SANE_READAHEAD (4u * 1024u)static struct tst_option options[] = {
@@ -109,12 +116,39 @@ static unsigned long get_cached_size(void)return parse_entry (meminfo_fname, entry); } -static void create_testfile (void ) +static int setup_overlay (void ) +{ +int ret; + +/* Setup an overlay mount with lower dir and file */ +SAFE_MKDIR (OVL_LOWER ,0755 ); +SAFE_MKDIR (OVL_UPPER ,0755 ); +SAFE_MKDIR (OVL_WORK ,0755 ); +SAFE_MKDIR (OVL_MNT ,0755 ); + ret =mount ("overlay" ,OVL_MNT ,"overlay" ,0 ,"lowerdir=" OVL_LOWER +",upperdir=" OVL_UPPER ",workdir=" OVL_WORK ); +if (ret <0 ) { +if (errno ==ENODEV ) { +tst_res (TCONF , +"overlayfs is not configured in this kernel." ); +return ret; + } +tst_brk (TBROK |TERRNO ,"overlayfs mount failed" ); + } + ovl_mounted =1 ; +return 0 ; +} + +static int create_testfile (unsigned int use_overlay) {int fd;char *tmp;size_t i; +if (use_overlay &&setup_overlay () !=0 ) +return -1 ; + +sprintf (testfile,"%s/testfile" , use_overlay ?OVL_MNT :MNTPOINT );tst_res (TINFO ,"creating test file of size: %zu" , testfile_size); tmp =SAFE_MALLOC (pagesize);
@@ -127,6 +161,7 @@ static void create_testfile(void)SAFE_FSYNC (fd);SAFE_CLOSE (fd);free (tmp); +return 0 ; }
@@ -221,7 +256,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,SAFE_CLOSE (fd); } -static void test_readahead (void ) +static void test_readahead (unsigned int use_overlay) {unsigned long read_bytes, read_bytes_ra;long usec, usec_ra;
@@ -229,6 +264,9 @@ static void test_readahead(void)char proc_io_fname[128 ];sprintf (proc_io_fname,"/proc/%u/io" ,getpid ()); +if (create_testfile (use_overlay) !=0 ) +return ; +/* find out how much can cache hold if we read whole file */ read_testfile (0 , testfile, testfile_size, &read_bytes, &usec, &cached); cached_max =get_cached_size ();
@@ -302,9 +340,12 @@ static void setup(void)tst_syscall (__NR_readahead,0 ,0 ,0 ); pagesize =getpagesize (); +} -sprintf (testfile,"%s/testfile" , mntpoint); -create_testfile (); +static void cleanup (void ) +{ +if (ovl_mounted) +SAFE_UMOUNT (OVL_MNT ); }static struct tst_test test = {
@@ -313,8 +354,10 @@ static struct tst_test test = { .mount_device = 1, .mntpoint = mntpoint, .setup = setup, + .cleanup = cleanup, .options = options, - .test_all = test_readahead, + .test = test_readahead, + .tcnt = 2, /* Repeat with overlayfs */ };#else /* __NR_readahead */
Signature · 1 line
2.17.1
Re: [LTP] [PATCH 3/4] syscalls/readahead02: test readahead() on an overlayfs file
----- Original Message -----
Quoted 102 lines
Repeat the test case on an overlayfs file.
The new test case is a regression test for kernel commit
b833a3660394("ovl: addovl_fadvise()") which fixes a regression ofreadahead()on an overlay file that was introduced by kernel commit5b910bd615ba("ovl: fix GPF inswapfile_activateof file from overlayfs over xfs").Signed-off-by Amir Goldstein <[email protected]>--- .../kernel/syscalls/readahead/readahead02.c | 55 +++++++++++++++++-- 1 file changed, 49 insertions(+), 6 deletions(-)testcases/kernel/syscalls/readahead/readahead02.c +38
-3@@ -14,6 +14,7 @@#include <sys/types.h> #include <sys/syscall.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h> @@ -34,9 +35,15 @@ static const char meminfo_fname[] = "/proc/meminfo";static size_t testfile_size =64 *1024 *1024 ;static char *opt_fsizestr;static int pagesize; +static int ovl_mounted;#define MNTPOINT "mntpoint" -static const char mntpoint[] ="mntpoint" ; +#define OVL_LOWER MNTPOINT"/lower" +#define OVL_UPPER MNTPOINT"/upper" +#define OVL_WORK MNTPOINT"/work" +#define OVL_MNT MNTPOINT"/ovl" + +static const char mntpoint[] =MNTPOINT ;#define MIN_SANE_READAHEAD (4u * 1024u)static struct tst_option options[] = {@@ -109,12 +116,39 @@ static unsigned long get_cached_size(void)return parse_entry (meminfo_fname, entry); } -static void create_testfile (void ) +static int setup_overlay (void ) +{ +int ret; + +/* Setup an overlay mount with lower dir and file */ +SAFE_MKDIR (OVL_LOWER ,0755 ); +SAFE_MKDIR (OVL_UPPER ,0755 ); +SAFE_MKDIR (OVL_WORK ,0755 ); +SAFE_MKDIR (OVL_MNT ,0755 ); + ret =mount ("overlay" ,OVL_MNT ,"overlay" ,0 ,"lowerdir=" OVL_LOWER +",upperdir=" OVL_UPPER ",workdir=" OVL_WORK ); +if (ret <0 ) { +if (errno ==ENODEV ) { +tst_res (TCONF , +"overlayfs is not configured in this kernel." ); +return ret; + } +tst_brk (TBROK |TERRNO ,"overlayfs mount failed" ); + } + ovl_mounted =1 ; +return 0 ; +} + +static int create_testfile (unsigned int use_overlay) {int fd;char *tmp;size_t i; +if (use_overlay &&setup_overlay () !=0 ) +return -1 ; + +sprintf (testfile,"%s/testfile" , use_overlay ?OVL_MNT :MNTPOINT );tst_res (TINFO ,"creating test file of size: %zu" , testfile_size); tmp =SAFE_MALLOC (pagesize);@@ -127,6 +161,7 @@ static void create_testfile(void)SAFE_FSYNC (fd);SAFE_CLOSE (fd);free (tmp); +return 0 ; }@@ -221,7 +256,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,SAFE_CLOSE (fd); } -static void test_readahead (void ) +static void test_readahead (unsigned int use_overlay) {unsigned long read_bytes, read_bytes_ra;testcases/kernel/syscalls/readahead/readahead02.c +0
-0long usec, usec_ra;
testcases/kernel/syscalls/readahead/readahead02.c static void test_readahead(void) · line 269
Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-0@@ -229,6 +264,9 @@ static void test_readahead(void)char proc_io_fname[128 ];sprintf (proc_io_fname,"/proc/%u/io" ,getpid ()); +if (create_testfile (use_overlay) !=0 ) +return ; +
This could use some TINFO message, what is being tested. .. and I see you added it in 4/4.
Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +0
-0/* find out how much can cache hold if we read whole file */ read_testfile (0 , testfile, testfile_size, &read_bytes, &usec, &cached); cached_max =get_cached_size ();@@ -302,9 +340,12 @@ static void setup(void)tst_syscall (__NR_readahead,0 ,0 ,0 );
testcases/kernel/syscalls/readahead/readahead02.c static void setup(void) · line 349
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +5
-2pagesize =getpagesize (); +} -sprintf (testfile,"%s/testfile" , mntpoint); -create_testfile (); +static void cleanup (void ) +{ +if (ovl_mounted) +SAFE_UMOUNT (OVL_MNT ); }
This creates a small conflict, because setup and cleanup don't match.
If you run this with multiple iterations (parameter -i), it's going
to fail:
safe_macros.c:169: BROK: readahead02.c:124: mkdir(mntpoint/lower,0755) failed: EEXIST
testcases/kernel/syscalls/readahead/readahead02.c static struct tst_test test = { · line 360
Quoted 11 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-1static struct tst_test test = {@@ -313,8 +354,10 @@ static struct tst_test test = { .mount_device = 1, .mntpoint = mntpoint, .setup = setup, + .cleanup = cleanup, .options = options, - .test_all = test_readahead, + .test = test_readahead, + .tcnt = 2, /* Repeat with overlayfs */
I'd rather add a function to call old and new test, single int will make it harder to add additional tests in future. .. and I see you changed this in 4/4 already.
Regards,
Jan
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +0
-1};#else /* __NR_readahead */ --2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/4] syscalls/readahead02: test readahead() on an overlayfs file
Quoted 13 lines · Jan Stancek
----- Original Message -----
Quoted 9 lines
Repeat the test case on an overlayfs file.
The new test case is a regression test for kernel commit
b833a3660394("ovl: addovl_fadvise()") which fixes a regression ofreadahead()on an overlay file that was introduced by kernel commit5b910bd615ba("ovl: fix GPF inswapfile_activateof file from overlayfs over xfs").Signed-off-by Amir Goldstein <[email protected]>---
[...]
Quoted 3 lines
This could use some TINFO message, what is being tested. .. and I see you added it in 4/4.
Yap. I hope you don;t mind this temporary simplicity....
Quoted 9 lines
Quoted 9 lines
/* find out how much can cache hold if we read whole file */ read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); cached_max = get_cached_size();testcases/kernel/syscalls/readahead/readahead02.c +1
-0@@ -302,9 +340,12 @@ static void setup(void)tst_syscall (__NR_readahead,0 ,0 ,0 ); pagesize =getpagesize (); +}
Quoted 13 lines
testcases/kernel/syscalls/readahead/readahead02.c static void setup(void) · line 349
Quoted 7 lines
testcases/kernel/syscalls/readahead/readahead02.c +4
-2-sprintf (testfile,"%s/testfile" , mntpoint); -create_testfile (); +static void cleanup (void ) +{ +if (ovl_mounted) +SAFE_UMOUNT (OVL_MNT ); }This creates a small conflict, because setup and cleanup don't match.
If you run this with multiple iterations (parameter -i), it's going
to fail:
safe_macros.c:169: BROK: readahead02.c:124:mkdir(mntpoint/lower,0755)failed: EEXIST
Right. I have noticed and fixes it in
https://github.com/amir73il/ltp/commits/overlayfs-devel
was waiting on more review before posting v2.
Thanks,
Amir.
PATCH 4/4 syscalls/readahead02: test readahead using posix_fadvise()
In reply to Amir GoldsteinThe 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").
--- .../kernel/syscalls/readahead/readahead02.c | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/readahead/readahead02.c +51 -6
@@ -51,6 +51,42 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 32 +#endif + +#ifndef __NR_fadvise64 +#define __NR_fadvise64 0 +#endif + +static struct tcase { +const char *tname; +int use_overlay; +int use_fadvise; +} tcases[] = { + {"readahead on file" ,0 ,0 }, + {"readahead on overlayfs file" ,1 ,0 }, +/* Check this system has fadvise64 system which is used in posix_fadvise. */ +#if ((_FILE_OFFSET_BITS == 64) || (__NR_fadvise64 != 0)) + {"POSIX_FADV_WILLNEED on file" ,0 ,1 }, + {"POSIX_FADV_WILLNEED on overlayfs file" ,1 ,1 }, +#endif +}; + +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 check_ret (long expected_ret) {if (expected_ret ==TST_RET ) {
@@ -120,6 +156,9 @@ static int setup_overlay(void) {int ret; +if (ovl_mounted) +return 0 ; +/* Setup an overlay mount with lower dir and file */ SAFE_MKDIR (OVL_LOWER ,0755 );SAFE_MKDIR (OVL_UPPER ,0755 );
@@ -139,7 +178,7 @@ static int setup_overlay(void)return 0 ; } -static int create_testfile (unsigned int use_overlay) +static int create_testfile (int use_overlay) {int fd;char *tmp;
@@ -164,7 +203,6 @@ static int create_testfile(unsigned int use_overlay)return 0 ; } -/* 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.
@@ -194,7 +232,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) { check_ret(0); break;
@@ -256,17 +294,24 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,SAFE_CLOSE (fd); } -static void test_readahead (unsigned int use_overlay) +static void test_readahead (unsigned int n) {unsigned long read_bytes, read_bytes_ra;long usec, usec_ra;unsigned long cached_max, cached_low, cached, cached_ra;char proc_io_fname[128 ]; +struct tcase *tc = &tcases[n]; + +tst_res (TINFO ,"Test #%d: %s" , n, tc->tname); +sprintf (proc_io_fname,"/proc/%u/io" ,getpid ()); -if (create_testfile (use_overlay) !=0 ) +if (create_testfile (tc->use_overlay) !=0 )return ; +/* 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_max =get_cached_size ();
@@ -357,7 +402,7 @@ static struct tst_test test = { .cleanup = cleanup, .options = options, .test = test_readahead, - .tcnt = 2, /* Repeat with overlayfs */ + .tcnt = ARRAY_SIZE(tcases), };#else /* __NR_readahead */
Signature · 1 line
2.17.1
Re: [LTP] [PATCH 4/4] syscalls/readahead02: test readahead using posix_fadvise()
----- Original Message -----
Quoted 22 lines
The call to
posix_fadvise(POSIX_FADV_WILLNEED)should have the same effect as the call toreadahead()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: addovl_fadvise()") which fixes a regression offadvise()on an overlay file that was introduced by kernel commit5b910bd615ba("ovl: fix GPF inswapfile_activateof file from overlayfs over xfs").Signed-off-by Amir Goldstein <[email protected]>--- .../kernel/syscalls/readahead/readahead02.c | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-)testcases/kernel/syscalls/readahead/readahead02.c +0
-0
testcases/kernel/syscalls/readahead/readahead02.c static struct tst_option options[] = { · line 56
Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-0@@ -51,6 +51,42 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 32 +#endif
I don't think we should be touching this.
Quoted 4 lines
testcases/kernel/syscalls/readahead/readahead02.c +4
-0+ +#ifndef __NR_fadvise64 +#define __NR_fadvise64 0 +#endif
testcases/kernel/syscalls/readahead/readahead02.c static struct tst_option options[] = { · line 70
Quoted 10 lines
testcases/kernel/syscalls/readahead/readahead02.c +10
-0+ +static struct tcase { +const char *tname; +int use_overlay; +int use_fadvise; +} tcases[] = { + {"readahead on file" ,0 ,0 }, + {"readahead on overlayfs file" ,1 ,0 }, +/* Check this system has fadvise64 system which is used in posix_fadvise. */ +#if ((_FILE_OFFSET_BITS == 64) || (__NR_fadvise64 != 0))
Can you elaborate on this check? Why do we need to care about _FILE_OFFSET_BITS?
Quoted 23 lines
testcases/kernel/syscalls/readahead/readahead02.c +19
-0+ { "POSIX_FADV_WILLNEED on file", 0, 1 }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 }, +#endif +}; + +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 check_ret(long expected_ret) { if (expected_ret == TST_RET) {
testcases/kernel/syscalls/readahead/readahead02.c static int setup_overlay(void) · line 161
Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-0@@ -120,6 +156,9 @@ static int setup_overlay(void) {int ret; +if (ovl_mounted) +return 0 ; +
You could call it once from setup() and drop check above and other call from create_testfile().
Regards,
Jan
Quoted 74 lines
testcases/kernel/syscalls/readahead/readahead02.c +2
-3/* Setup an overlay mount with lower dir and file */ SAFE_MKDIR (OVL_LOWER ,0755 );SAFE_MKDIR (OVL_UPPER ,0755 );@@ -139,7 +178,7 @@ static int setup_overlay(void)return 0 ; } -static int create_testfile (unsigned int use_overlay) +static int create_testfile (int use_overlay) {int fd;char *tmp;@@ -164,7 +203,6 @@ static int create_testfile(unsigned int use_overlay)return 0 ; } -/* 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. @@ -194,7 +232,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) { check_ret(0);testcases/kernel/syscalls/readahead/readahead02.c +9
-2break ;@@ -256,17 +294,24 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize,SAFE_CLOSE (fd); } -static void test_readahead (unsigned int use_overlay) +static void test_readahead (unsigned int n) {unsigned long read_bytes, read_bytes_ra;long usec, usec_ra;unsigned long cached_max, cached_low, cached, cached_ra;char proc_io_fname[128 ]; +struct tcase *tc = &tcases[n]; + +tst_res (TINFO ,"Test #%d: %s" , n, tc->tname); +sprintf (proc_io_fname,"/proc/%u/io" ,getpid ()); -if (create_testfile (use_overlay) !=0 ) +if (create_testfile (tc->use_overlay) !=0 )return ; +/* 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);testcases/kernel/syscalls/readahead/readahead02.c +1
-2cached_max =get_cached_size ();@@ -357,7 +402,7 @@ static struct tst_test test = { .cleanup = cleanup, .options = options, .test = test_readahead, - .tcnt = 2, /* Repeat with overlayfs */ + .tcnt = ARRAY_SIZE(tcases), };#else /* __NR_readahead */ --2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/4] syscalls/readahead02: test readahead using posix_fadvise()
Quoted 44 lines · Jan Stancek
----- Original Message -----
Quoted 22 lines
The call to
posix_fadvise(POSIX_FADV_WILLNEED)should have the same effect as the call toreadahead()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: addovl_fadvise()") which fixes a regression offadvise()on an overlay file that was introduced by kernel commit5b910bd615ba("ovl: fix GPF inswapfile_activateof file from overlayfs over xfs").Signed-off-by Amir Goldstein <[email protected]>--- .../kernel/syscalls/readahead/readahead02.c | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-)testcases/kernel/syscalls/readahead/readahead02.c +0
-0testcases/kernel/syscalls/readahead/readahead02.c static struct tst_option options[] = { · line 56
Quoted 6 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-0@@ -51,6 +51,42 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +#ifndef _FILE_OFFSET_BITS +#define _FILE_OFFSET_BITS 32 +#endif I don't think we should be touching this.
Quoted 9 lines
testcases/kernel/syscalls/readahead/readahead02.c +9
-0+ +#ifndef __NR_fadvise64 +#define __NR_fadvise64 0 +#endif + +static struct tcase { + const char *tname; + int use_overlay; + int use_fadvise;
Quoted 8 lines
testcases/kernel/syscalls/readahead/readahead02.c static struct tst_option options[] = { · line 70
Quoted 5 lines
testcases/kernel/syscalls/readahead/readahead02.c +5
-0+} tcases[] = { + { "readahead on file", 0, 0 }, + { "readahead on overlayfs file", 1, 0 }, +/* Check this system has fadvise64 system which is used in posix_fadvise. */ +#if ((_FILE_OFFSET_BITS == 64) || (__NR_fadvise64 != 0))Can you elaborate on this check? Why do we need to care about
_FILE_OFFSET_BITS?
I am not completely sure, this is copied along with the comment and ifndefs above from posix_fadvise tests.
Quoted 27 lines
Quoted 27 lines
testcases/kernel/syscalls/readahead/readahead02.c +19
-0+ { "POSIX_FADV_WILLNEED on file", 0, 1 }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 }, +#endif +}; + +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 check_ret(long expected_ret) { if (expected_ret == TST_RET) {@@ -120,6 +156,9 @@ static int setup_overlay(void) {int ret;
Quoted 7 lines
testcases/kernel/syscalls/readahead/readahead02.c static int setup_overlay(void) · line 161
Quoted 3 lines
testcases/kernel/syscalls/readahead/readahead02.c +3
-0+if (ovl_mounted) +return 0 ; +You could call it once from
setup()and drop check above and other call fromcreate_testfile().
Yap. Already fixed in my github overlayfs-devel branch :)
Thanks,
Amir.