syscalls/preadv01: Run test for all filesystems
PATCH 1/2 syscalls/preadv01: Run test for all filesystems
--- testcases/kernel/syscalls/preadv/preadv01.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/preadv/preadv01.c +6 -1
@@ -30,6 +30,8 @@#include "preadv.h" #define CHUNK 64 +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file"static int fd;static char buf[CHUNK ];
@@ -97,7 +99,7 @@ void setup(void) {char buf[CHUNK ]; - fd =SAFE_OPEN ("file" ,O_RDWR |O_CREAT ,0644 ); + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT ,0644 );memset (buf,'a' ,sizeof (buf));SAFE_WRITE (1 , fd, buf,sizeof (buf));
@@ -119,4 +121,7 @@ static struct tst_test test = { .test = verify_preadv, .min_kver = "2.6.30", .needs_tmpdir = 1, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, };
Signature · 1 line
1.8.3.1
PATCH 2/2 syscalls/pwritev01: Run test for all filesystems
--- testcases/kernel/syscalls/pwritev/pwritev01.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/pwritev/pwritev01.c +6 -1
@@ -31,6 +31,8 @@#include "tst_safe_prw.h" #define CHUNK 64 +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file"static char buf[CHUNK ];static char initbuf[CHUNK *2 ];
@@ -99,7 +101,7 @@ static void setup(void) {memset (&buf,0x61 ,CHUNK ); - fd =SAFE_OPEN ("file" ,O_RDWR |O_CREAT ,0644 ); + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT ,0644 ); }static void cleanup (void )
@@ -115,4 +117,7 @@ static struct tst_test test = { .test = verify_pwritev, .min_kver = "2.6.30", .needs_tmpdir = 1, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, };
Signature · 1 line
1.8.3.1
PATCH 1/2 syscalls/preadv01: Run test for all filesystems
In reply to Xiao YangHi!
Looking at the test running it for all filesystems would not make much sense as it is since as far as I can tell:
1) setup() creates a file and writes data to it
- dirty pagecache record is created
2) test() reads data from the file
- kernel will copy the data from pagecache
3) test library cleanup will umount() the device
- dirty pagecache is written at this point
So we will not reach any filesystem specific code at all.
I guess that we may fix that by opening second file descriptor with O_DIRECT which would bypass pagecache so each read/write request would trigger I/O request from the block device.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 syscalls/preadv01: Run test for all filesystems
Quoted 10 lines · Cyril Hrubis
Hi!
Looking at the test running it for all filesystems would not make much sense as it is since as far as I can tell:1)
setup()creates a file and writes data to it
- dirty pagecache record is created2)
test()reads data from the file
- kernel will copy the data from pagecache
Quoted 8 lines
3) test library cleanup will
umount()the device
- dirty pagecache is written at this pointSo we will not reach any filesystem specific code at all.
I guess that we may fix that by opening second file descriptor with
O_DIRECTwhich would bypass pagecache so each read/write request would trigger I/O request from the block device.
Hi Cyril,
Sorry, i ignored the fact that they use pagecache. Can we just keep them and add two new tests as you suggested?
Thanks,
Xiao Yang
PATCH 1/2 syscalls/preadv01: Run test for all filesystems
Hi!
Quoted 14 lines
Quoted 14 lines
Looking at the test running it for all filesystems would not make much sense as it is since as far as I can tell:
1)
setup()creates a file and writes data to it
- dirty pagecache record is created2)
test()reads data from the file
- kernel will copy the data from pagecache3) test library cleanup will
umount()the device
- dirty pagecache is written at this pointSo we will not reach any filesystem specific code at all.
Quoted 7 lines
Quoted 3 lines
I guess that we may fix that by opening second file descriptor with
O_DIRECTwhich would bypass pagecache so each read/write request would trigger I/O request from the block device.Hi Cyril,
Sorry, i ignored the fact that they use pagecache. Can we just keep them and add two new tests as you suggested?
I was simply thinking about opening second fd with O_DIRECT in the test setup and running the test twice, once for the regular fd and once for the O_DIRECT one, however creating new test would work as well and may be even cleaner solution.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 preadv/preadv03.c: Add new testcase
Check the basic functionality of the preadv(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/preadv03.c | 143 ++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c
runtest/ltplite +1 -0
@@ -589,6 +589,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/stress.part3 +1 -0
@@ -496,6 +496,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/syscalls +2 -0
@@ -821,6 +821,8 @@ preadv01 preadv01 preadv01_64 preadv01_64 preadv02 preadv02 preadv02_64 preadv02_64 +preadv03 preadv03 +preadv03_64 preadv03_64 profil01 profil01
testcases/kernel/syscalls/.gitignore +2 -0
@@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64
testcases/kernel/syscalls/preadv/preadv03.c new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/2 pwritev/pwritev03.c: Add new testcase
Check the basic functionality of the pwritev(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/pwritev03.c | 137 ++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c
runtest/ltplite +1 -0
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/stress.part3 +1 -0
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/syscalls +2 -0
@@ -865,6 +865,8 @@ pwritev01 pwritev01 pwritev01_64 pwritev01_64 pwritev02 pwritev02 pwritev02_64 pwritev02_64 +pwritev03 pwritev03 +pwritev03_64 pwritev03_64 quotactl01 quotactl01 quotactl02 quotactl02
testcases/kernel/syscalls/.gitignore +2 -0
@@ -726,6 +726,8 @@ /pwritev/pwritev01_64 /pwritev/pwritev02 /pwritev/pwritev02_64 +/pwritev/pwritev03 +/pwritev/pwritev03_64 /quotactl/quotactl01 /quotactl/quotactl02 /quotactl/quotactl03
testcases/kernel/syscalls/pwritev/pwritev03.c new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 1/2 preadv/preadv03.c: Add new testcase
In reply to Xiao YangHi!
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+static void setup (void ) +{ + pgsz =getpagesize (); + tst_off1 = pgsz; + tst_off2 = pgsz *3 /2 ; + exp_sz1 = pgsz; + exp_sz2 = pgsz /2 ; + + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT |O_DIRECT ,0644 ); +
testcases/kernel/syscalls/preadv/preadv03.c line 121
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+ pop_buf =SAFE_MEMALIGN (pgsz, pgsz); +memset (pop_buf,0x61 , pgsz); +SAFE_WRITE (1 , fd, pop_buf, pgsz); + +memset (pop_buf,0x62 , pgsz); +SAFE_WRITE (1 , fd, pop_buf, pgsz); + + rd_iovec =SAFE_MEMALIGN (pgsz, pgsz +sizeof (size_t )); + rd_iovec->iov_base =SAFE_MEMALIGN (pgsz, pgsz); + rd_iovec->iov_len = pgsz;
The open(2) manual page says that O_DIRECT buffers should be aligned to disk block size which can be queried by BLKSSZGET ioctl(). And I suppose that the offsets should be multiple of the disk block size as well.
Quoted 11 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +11
-0+} + +static void cleanup (void ) +{ +free (pop_buf); +free (rd_iovec->iov_base); +free (rd_iovec); + +if (fd >0 ) +SAFE_CLOSE (fd); +}
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 preadv/preadv03.c: Add new testcase
Check the basic functionality of the preadv(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/preadv03.c | 146 ++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c
runtest/ltplite +1 -0
@@ -589,6 +589,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/stress.part3 +1 -0
@@ -496,6 +496,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/syscalls +2 -0
@@ -821,6 +821,8 @@ preadv01 preadv01 preadv01_64 preadv01_64 preadv02 preadv02 preadv02_64 preadv02_64 +preadv03 preadv03 +preadv03_64 preadv03_64 profil01 profil01
testcases/kernel/syscalls/.gitignore +2 -0
@@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64
testcases/kernel/syscalls/preadv/preadv03.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/2 pwritev/pwritev03.c: Add new testcase
Check the basic functionality of the pwritev(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/pwritev03.c | 146 ++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c
runtest/ltplite +1 -0
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/stress.part3 +1 -0
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/syscalls +2 -0
@@ -865,6 +865,8 @@ pwritev01 pwritev01 pwritev01_64 pwritev01_64 pwritev02 pwritev02 pwritev02_64 pwritev02_64 +pwritev03 pwritev03 +pwritev03_64 pwritev03_64 quotactl01 quotactl01 quotactl02 quotactl02
testcases/kernel/syscalls/.gitignore +2 -0
@@ -726,6 +726,8 @@ /pwritev/pwritev01_64 /pwritev/pwritev02 /pwritev/pwritev02_64 +/pwritev/pwritev03 +/pwritev/pwritev03_64 /quotactl/quotactl01 /quotactl/quotactl02 /quotactl/quotactl03
testcases/kernel/syscalls/pwritev/pwritev03.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 1/2 preadv/preadv03.c: Add new testcase
In reply to Xiao YangHi!
Quoted 19 lines
testcases/kernel/syscalls/.gitignore +2
-0@@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64testcases/kernel/syscalls/preadv/preadv03.c new file +0
-0
testcases/kernel/syscalls/preadv/preadv03.c line 7
Quoted 7 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +7
-0@@ -0,0 +1,146 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang <[email protected]> +* +* 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.
Can we use GPLv2+ instead of GPLv2 please?
testcases/kernel/syscalls/preadv/preadv03.c line 18
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+* 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. +* +* You should have received a copy of the GNU General Public License +* alone with this program. +*/ + +/* +* Test Name: preadv03
I would avoid the test name here as it does not add any useful information.
Quoted 11 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +11
-0+* Test Description: +* Check the basic functionality of the preadv(2) for the file +* opened with O_DIRECT in all filesystem. +* Preadv(2) should succeed to read the expected content of data +* and after reading the file, the file offset is not changed. +*/ + +#define _GNU_SOURCE +#include <stdlib.h> +#include <string.h> +#include <sys/uio.h>
testcases/kernel/syscalls/preadv/preadv03.c line 40
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+#include <sys/ioctl.h> +#include <sys/mount.h> +#include "tst_test.h" +#include "preadv.h" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file" + +static int fd, blksz; +static off_t org_off, tst_off;
^
The tst_ prefix is reserved for the test library, you should not use it when naming test variables/functions.
Quoted 58 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +58
-0+static ssize_t exp_sz; +static char *pop_buf; +static struct iovec *rd_iovec; + +static struct tcase { +int count; +off_t *offset; +ssize_t *size; +char content; +} tcases[] = { + {1 , &org_off, &exp_sz,0x61 }, + {2 , &org_off, &exp_sz,0x61 }, + {1 , &tst_off, &exp_sz,0x62 }, +}; + +static void verify_direct_preadv (unsigned int n) +{ +int i; +char *vec; +struct tcase *tc = &tcases[n]; + + vec = rd_iovec->iov_base; +memset (vec,0x00 , blksz); + +SAFE_LSEEK (fd,0 ,SEEK_SET ); + +TEST (preadv (fd, rd_iovec, tc->count, *tc->offset)); +if (TEST_RETURN <0 ) { +tst_res (TFAIL |TTERRNO ,"Preadv(O_DIRECT) fails" ); +return ; + } + +if (TEST_RETURN != *tc->size) { +tst_res (TFAIL ,"Preadv(O_DIRECT) read %li bytes, expected %zi" , +TEST_RETURN , *tc->size); +return ; + } + +for (i =0 ; i < *tc->size; i++) { +if (vec[i] != tc->content) +break ; + } + +if (i < *tc->size) { +tst_res (TFAIL ,"Buffer wrong at %i have %02x expected %02x" , + i, vec[i], tc->content); +return ; + } + +if (SAFE_LSEEK (fd,0 ,SEEK_CUR ) !=0 ) { +tst_res (TFAIL ,"Preadv(O_DIRECT) has changed file offset" ); +return ; + } + +tst_res (TPASS ,"Preadv(O_DIRECT) read %zi bytes successfully " +"with content '%c' expectedly" , *tc->size, tc->content); +} +
testcases/kernel/syscalls/preadv/preadv03.c line 108
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+static void setup (void ) +{ +int dev_fd; + + dev_fd =SAFE_OPEN (tst_device->dev,O_RDWR ); +if (ioctl (dev_fd,BLKSSZGET , &blksz)) { +SAFE_CLOSE (dev_fd); +tst_brk (TBROK |TERRNO ,"ioctl(%s, BLKSSZGET) failed" , + tst_device->dev); + }
We do have SAFE_IOCTL() now :-).
Quoted 4 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +4
-0+SAFE_CLOSE (dev_fd); + tst_off = blksz; + exp_sz = blksz; +
testcases/kernel/syscalls/preadv/preadv03.c line 122
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+ fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT |O_DIRECT ,0644 ); + + pop_buf =SAFE_MEMALIGN (blksz, blksz); +memset (pop_buf,0x61 , blksz); +SAFE_WRITE (1 , fd, pop_buf, blksz); + +memset (pop_buf,0x62 , blksz); +SAFE_WRITE (1 , fd, pop_buf, blksz); + + rd_iovec =SAFE_MEMALIGN (blksz, blksz +sizeof (size_t ));
Also I do not think that we actually have to align the iovec structure, AFAIC only the actual buffer, i.e. iov_base.
testcases/kernel/syscalls/preadv/preadv03.c line 124
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +2
-0+ rd_iovec->iov_base =SAFE_MEMALIGN (blksz, blksz); + rd_iovec->iov_len = blksz;
Also looking at the testcase definition, we pass iovcnt == 2 there but initialize only the first one here. I suppose that for the original testcase we relied on the fact that the global variable rd_iovec was initialized to 0 but that does not hold true for allocated memory.
Anyway we should either set rd_iovec[1].iov_base = NULL and rd_iovec[1].iov_len = 0 or make it static global variable again...
Quoted 27 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +22
-0+} + +static void cleanup (void ) +{ +free (pop_buf); +free (rd_iovec->iov_base); +free (rd_iovec); + +if (fd >0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_direct_preadv, + .min_kver ="2.6.30" , + .mntpoint =MNTPOINT , + .mount_device =1 , + .all_filesystems =1 , +};Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/2 preadv/preadv03.c: Add new testcase
Check the basic functionality of the preadv(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/preadv03.c | 140 ++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 testcases/kernel/syscalls/preadv/preadv03.c
runtest/ltplite +1 -0
@@ -589,6 +589,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/stress.part3 +1 -0
@@ -496,6 +496,7 @@ pread03 pread03 preadv01 preadv01 preadv02 preadv02 +preadv03 preadv03 profil01 profil01
runtest/syscalls +2 -0
@@ -821,6 +821,8 @@ preadv01 preadv01 preadv01_64 preadv01_64 preadv02 preadv02 preadv02_64 preadv02_64 +preadv03 preadv03 +preadv03_64 preadv03_64 profil01 profil01
testcases/kernel/syscalls/.gitignore +2 -0
@@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64
testcases/kernel/syscalls/preadv/preadv03.c new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 2/2 pwritev/pwritev03.c: Add new testcase
Check the basic functionality of the pwritev(2) for the file opened with O_DIRECT in all filesystem.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/pwritev03.c | 139 ++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev/pwritev03.c
runtest/ltplite +1 -0
@@ -612,6 +612,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/stress.part3 +1 -0
@@ -517,6 +517,7 @@ pwrite04_64 pwrite04_64 pwritev01 pwritev01 pwritev02 pwritev02 +pwritev03 pwritev03 read01 read01 read02 read02
runtest/syscalls +2 -0
@@ -865,6 +865,8 @@ pwritev01 pwritev01 pwritev01_64 pwritev01_64 pwritev02 pwritev02 pwritev02_64 pwritev02_64 +pwritev03 pwritev03 +pwritev03_64 pwritev03_64 quotactl01 quotactl01 quotactl02 quotactl02
testcases/kernel/syscalls/.gitignore +2 -0
@@ -726,6 +726,8 @@ /pwritev/pwritev01_64 /pwritev/pwritev02 /pwritev/pwritev02_64 +/pwritev/pwritev03 +/pwritev/pwritev03_64 /quotactl/quotactl01 /quotactl/quotactl02 /quotactl/quotactl03
testcases/kernel/syscalls/pwritev/pwritev03.c new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 1/2 preadv/preadv03.c: Add new testcase
In reply to Xiao YangHi!
Both pushed with a minor changes, thanks.
I've changed the test to close the dev_fd in the test setup() as there is no need to keep it open during the test. And also removed the capitalization of the first letter of the syscall from the messages, which may have caused confusing when grepping the logs.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 preadv/preadv03.c: Add new testcase
In reply to Cyril HrubisHi Cyril,
Thanks for your detailed review, and i will send v4 patch soon. :-)
Thanks,
Xiao Yang
Quoted 191 lines · Cyril Hrubis
Hi!
Quoted 19 lines
testcases/kernel/syscalls/.gitignore +2
-0@@ -696,6 +696,8 @@ /preadv/preadv01_64 /preadv/preadv02 /preadv/preadv02_64 +/preadv/preadv03 +/preadv/preadv03_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64testcases/kernel/syscalls/preadv/preadv03.c new file +0
-0testcases/kernel/syscalls/preadv/preadv03.c line 7
Quoted 7 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +7
-0@@ -0,0 +1,146 @@ +/* +* Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. +* Author: Xiao Yang<[email protected]> +* +* 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. Can we use GPLv2+ instead of GPLv2 please?
testcases/kernel/syscalls/preadv/preadv03.c line 18
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+* 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. +* +* You should have received a copy of the GNU General Public License +* alone with this program. +*/ + +/* +* Test Name: preadv03 I would avoid the test name here as it does not add any useful information.
Quoted 11 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +11
-0+* Test Description: +* Check the basic functionality of the preadv(2) for the file +* opened with O_DIRECT in all filesystem. +* Preadv(2) should succeed to read the expected content of data +* and after reading the file, the file offset is not changed. +*/ + +#define _GNU_SOURCE +#include <stdlib.h> +#include <string.h> +#include <sys/uio.h> testcases/kernel/syscalls/preadv/preadv03.c line 40
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+#include <sys/ioctl.h> +#include <sys/mount.h> +#include "tst_test.h" +#include "preadv.h" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/file" + +static int fd, blksz; +static off_t org_off, tst_off;^
Thetst_prefix is reserved for the test library, you should not use it when naming test variables/functions.Quoted 58 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +58
-0+static ssize_t exp_sz; +static char *pop_buf; +static struct iovec *rd_iovec; + +static struct tcase { +int count; +off_t *offset; +ssize_t *size; +char content; +} tcases[] = { + {1 ,&org_off,&exp_sz,0x61 }, + {2 ,&org_off,&exp_sz,0x61 }, + {1 ,&tst_off,&exp_sz,0x62 }, +}; + +static void verify_direct_preadv (unsigned int n) +{ +int i; +char *vec; +struct tcase *tc =&tcases[n]; + + vec = rd_iovec->iov_base; +memset (vec,0x00 , blksz); + +SAFE_LSEEK (fd,0 ,SEEK_SET ); + +TEST (preadv (fd, rd_iovec, tc->count, *tc->offset)); +if (TEST_RETURN <0 ) { +tst_res (TFAIL |TTERRNO ,"Preadv(O_DIRECT) fails" ); +return ; + } + +if (TEST_RETURN != *tc->size) { +tst_res (TFAIL ,"Preadv(O_DIRECT) read %li bytes, expected %zi" , +TEST_RETURN , *tc->size); +return ; + } + +for (i =0 ; i< *tc->size; i++) { +if (vec[i] != tc->content) +break ; + } + +if (i< *tc->size) { +tst_res (TFAIL ,"Buffer wrong at %i have %02x expected %02x" , + i, vec[i], tc->content); +return ; + } + +if (SAFE_LSEEK (fd,0 ,SEEK_CUR ) !=0 ) { +tst_res (TFAIL ,"Preadv(O_DIRECT) has changed file offset" ); +return ; + } + +tst_res (TPASS ,"Preadv(O_DIRECT) read %zi bytes successfully " +"with content '%c' expectedly" , *tc->size, tc->content); +} +testcases/kernel/syscalls/preadv/preadv03.c line 108
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+static void setup (void ) +{ +int dev_fd; + + dev_fd =SAFE_OPEN (tst_device->dev,O_RDWR ); +if (ioctl (dev_fd,BLKSSZGET ,&blksz)) { +SAFE_CLOSE (dev_fd); +tst_brk (TBROK |TERRNO ,"ioctl(%s, BLKSSZGET) failed" , + tst_device->dev); + }We do have
SAFE_IOCTL()now :-).Quoted 4 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +4
-0+SAFE_CLOSE (dev_fd); + tst_off = blksz; + exp_sz = blksz; +testcases/kernel/syscalls/preadv/preadv03.c line 122
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +10
-0+ fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT |O_DIRECT ,0644 ); + + pop_buf =SAFE_MEMALIGN (blksz, blksz); +memset (pop_buf,0x61 , blksz); +SAFE_WRITE (1 , fd, pop_buf, blksz); + +memset (pop_buf,0x62 , blksz); +SAFE_WRITE (1 , fd, pop_buf, blksz); + + rd_iovec =SAFE_MEMALIGN (blksz, blksz +sizeof (size_t ));Also I do not think that we actually have to align the iovec structure, AFAIC only the actual buffer, i.e.
iov_base.testcases/kernel/syscalls/preadv/preadv03.c line 124
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +2
-0+ rd_iovec->iov_base =SAFE_MEMALIGN (blksz, blksz); + rd_iovec->iov_len = blksz;Also looking at the testcase definition, we pass iovcnt == 2 there but initialize only the first one here. I suppose that for the original testcase we relied on the fact that the global variable
rd_iovecwas initialized to 0 but that does not hold true for allocated memory.Anyway we should either set rd_iovec[1].iov_base = NULL and rd_iovec[1].iov_len = 0 or make it static global variable again...
Quoted 27 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +22
-0+} + +static void cleanup (void ) +{ +free (pop_buf); +free (rd_iovec->iov_base); +free (rd_iovec); + +if (fd>0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_direct_preadv, + .min_kver ="2.6.30" , + .mntpoint =MNTPOINT , + .mount_device =1 , + .all_filesystems =1 , +};Signature · 1 line
1.8.3.1
PATCH v2 1/2 preadv/preadv03.c: Add new testcase
In reply to Cyril HrubisQuoted 16 lines · Cyril Hrubis
Hi!
Quoted 15 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +15
-0+static void setup (void ) +{ + pgsz =getpagesize (); + tst_off1 = pgsz; + tst_off2 = pgsz *3 /2 ; + exp_sz1 = pgsz; + exp_sz2 = pgsz /2 ; + + fd =SAFE_OPEN (FNAME ,O_RDWR |O_CREAT |O_DIRECT ,0644 ); + + pop_buf =SAFE_MEMALIGN (pgsz, pgsz); +memset (pop_buf,0x61 , pgsz); +SAFE_WRITE (1 , fd, pop_buf, pgsz); + +memset (pop_buf,0x62 , pgsz);
Quoted 8 lines
testcases/kernel/syscalls/preadv/preadv03.c line 121
Quoted 5 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +5
-0+SAFE_WRITE (1 , fd, pop_buf, pgsz); + + rd_iovec =SAFE_MEMALIGN (pgsz, pgsz +sizeof (size_t )); + rd_iovec->iov_base =SAFE_MEMALIGN (pgsz, pgsz); + rd_iovec->iov_len = pgsz;The open(2) manual page says that
O_DIRECTbuffers should be aligned to disk block size which can be queried by BLKSSZGETioctl(). And I suppose that the offsets should be multiple of the disk block size as well.
Hi Cyril,
OK, i will replace page size with block size as you suggested.
Thanks,
Xiao Yang
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/preadv/preadv03.c new file +11
-0+} + +static void cleanup (void ) +{ +free (pop_buf); +free (rd_iovec->iov_base); +free (rd_iovec); + +if (fd>0 ) +SAFE_CLOSE (fd); +}