lib/tst_rand_data: Add statically defined data pattern
PATCH v2 1/3 lib/tst_rand_data: Add statically defined data pattern
Often we need to write some pattern to memory or a block device. There are a number of requirements:
* It can be identified
* It can't be compressed in a degenerate way
* It can be reproduced
We could generate the data at runtime with a pseudo RNG and constant seed. However the storage and bandwidth cost of statically defining 4KB of random data is negligible.
---
V2:
* Add static random data instead of reading /dev/urandom.
* Add alternate fill method
include/tst_rand_data.h | 15 +++ lib/tst_rand_data.c | 211 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 include/tst_rand_data.h create mode 100644 lib/tst_rand_data.c
include/tst_rand_data.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* Copyright (c) Linux Test Project, 2022 +*/ + +#ifndef TST_RAND_DATA_H__ +#define TST_RAND_DATA_H__ + +#include <stddef.h> + +/* Includes null byte */ +extern const size_t tst_rand_data_len; +/* statically defined random data */ +extern const char *const tst_rand_data; + +#endif
lib/tst_rand_data.c new file +211 -0
211 lines not on this page · raw message
Signature · 5 lines
2.38.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 tst_fill_fs: Ensure data is not easily compressed
If the stack is auto initialized to zero, then we will write all zeros. Some FS may treat this as a special case and just record the number of zero bytes or sectors.
This could alter the test behaviour in unpredictable ways. For example a large number of (slow) syscalls may be required to fill up the drive, extending the required test time. Or we could overflow the file size/offset causing EFBIG.
So this uses tst_rand_data.
--- lib/tst_fill_fs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/tst_fill_fs.c +3 -2
@@ -11,16 +11,17 @@#define TST_NO_DEFAULT_MAIN #include "tst_test.h" #include "tst_fs.h" +#include "tst_rand_data.h" void tst_fill_fs (const char *path,int verbose) {int i =0 ;char file[PATH_MAX ]; -char buf[4096 ];size_t len;ssize_t ret;int fd;struct statvfs fi; +statvfs (path, &fi);for (;;) {
@@ -41,7 +42,7 @@ void tst_fill_fs(const char *path, int verbose) }while (len) { - ret =write (fd, buf,MIN (len,sizeof (buf))); + ret =write (fd, tst_rand_data,MIN (len, tst_rand_data_len));if (ret <0 ) {/* retry on ENOSPC to make sure filesystem is really full */
Signature · 5 lines
2.38.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 tst_fill_fs: Add alternate access pattern "flat"
In reply to Richard Palethorpe via ltpDepending on the workload, the way in which a file system is filled will be different. The system calls will also be different.
This adds a fill mode which uses writev with uniform batches of data. This simulates when the FS is filled by a program which batches writes.
--- include/tst_fs.h | 7 ++- lib/tst_fill_fs.c | 59 ++++++++++++++++++- testcases/kernel/fs/fs_fill/fs_fill.c | 18 ++++-- .../kernel/syscalls/fallocate/fallocate05.c | 2 +- .../kernel/syscalls/fallocate/fallocate06.c | 2 +- 5 files changed, 78 insertions(+), 10 deletions(-)
include/tst_fs.h +6 -1
@@ -34,6 +34,11 @@#define TST_VFAT_MAGIC 0x4d44/* AKA MSDOS */ #define TST_EXFAT_MAGIC 0x2011BAB0UL +enum tst_fill_access_pattern { +TST_FILL_FLAT_VEC , +TST_FILL_RANDOM +}; +enum {TST_BYTES =1 ,TST_KB =1024 ,
@@ -201,7 +206,7 @@ int tst_fs_in_skiplist(const char *fs_type, const char *const *skiplist);/* * Creates and writes to files on given path until write fails with ENOSPC */ -void tst_fill_fs (const char *path,int verbose); +void tst_fill_fs (const char *path,int verbose,enum tst_fill_access_pattern pattern);/* * test if FIBMAP ioctl is supported
lib/tst_fill_fs.c +58 -1
74 lines not on this page · raw message
testcases/kernel/fs/fs_fill/fs_fill.c +12 -6
@@ -25,6 +25,7 @@ static int enospc_cnt;static struct worker *workers;struct worker { +enum tst_fill_access_pattern pattern;char dir[PATH_MAX ]; };
@@ -36,7 +37,7 @@ static void *worker(void *p)char file[PATH_MAX ];while (run) { -tst_fill_fs (w->dir,0 ); +tst_fill_fs (w->dir,1 , w->pattern);tst_atomic_inc (&enospc_cnt);
@@ -61,22 +62,26 @@ static void *worker(void *p)return NULL ; } -static void testrun (void ) +static void testrun (unsigned int n) {pthread_t threads[nthreads];unsigned int i, ms; +tst_atomic_store (0 , &enospc_cnt); + run =1 ; -for (i =0 ; i < nthreads; i++) +for (i =0 ; i < nthreads; i++) { + workers[i].pattern = n;SAFE_PTHREAD_CREATE (&threads[i],NULL , worker, &workers[i]); + }for (ms =0 ; ; ms++) {usleep (1000 ); -if (ms >=1000 && enospc_cnt) +if (ms >=1000 &&tst_atomic_load (&enospc_cnt))break ; -if (enospc_cnt >100 ) +if (tst_atomic_load (&enospc_cnt) >100 )break ; }
@@ -116,5 +121,6 @@ static struct tst_test test = { .all_filesystems = 1, .setup = setup, .cleanup = cleanup, - .test_all = testrun, + .test = testrun, + .tcnt = 2 };
testcases/kernel/syscalls/fallocate/fallocate05.c +1 -1
@@ -68,7 +68,7 @@ static void run(void)tst_brk (TBROK |TTERRNO ,"fallocate(fd, 0, 0, %ld)" , bufsize); } -tst_fill_fs (MNTPOINT ,1 ); +tst_fill_fs (MNTPOINT ,1 ,TST_FILL_RANDOM );TEST (write (fd, buf, bufsize));
testcases/kernel/syscalls/fallocate/fallocate06.c +1 -1
@@ -202,7 +202,7 @@ static void run(unsigned int n) }if (tc->fill_fs) -tst_fill_fs (MNTPOINT ,1 ); +tst_fill_fs (MNTPOINT ,1 ,TST_FILL_RANDOM );SAFE_LSEEK (fd, offset,SEEK_SET );TEST (write (fd, wbuf, size));
Signature · 5 lines
2.38.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] tst_fill_fs: Add alternate access pattern "flat"
Hi!
include/tst_fs.h line 38
Quoted 2 lines
include/tst_fs.h +2
-0+enum tst_fill_access_pattern { +TST_FILL_FLAT_VEC ,
Not sure if this is a good name, maybe TST_FILL_BLOCKS or TST_FILL_PAGES.
include/tst_fs.h line 40
Quoted 2 lines
include/tst_fs.h +2
-0+ TST_FILL_RANDOM +};
Otherwise the whole patchset looks good to me.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] tst_fill_fs: Add alternate access pattern "flat"
Hello,
Quoted 6 lines · Cyril Hrubis
Hi!
include/tst_fs.h line 38
Quoted 2 lines
include/tst_fs.h +2
-0+enum tst_fill_access_pattern { +TST_FILL_FLAT_VEC ,Not sure if this is a good name, maybe
TST_FILL_BLOCKSorTST_FILL_PAGES.
hhmm, OK blocks then.
Quoted 7 lines
include/tst_fs.h line 40
Quoted 3 lines
include/tst_fs.h +2
-0+ TST_FILL_RANDOM +};Otherwise the whole patchset looks good to me.
Reviewed-by Cyril Hrubis <[email protected]>
Thanks
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] tst_fill_fs: Add alternate access pattern "flat"
In reply to Richard Palethorpe via ltpHi Richie,
Quoted 6 lines
Depending on the workload, the way in which a file system is filled will be different. The system calls will also be different.
This adds a fill mode which uses writev with uniform batches of data. This simulates when the FS is filled by a program which batches writes.
...
FYI this broke CI on Alpine.
Quoted 1 line
+++
b/lib/tst_fill_fs.c
...
lib/tst_fill_fs.c void tst_fill_fs(const char *path, int verbose) · line 76
Quoted 3 lines
lib/tst_fill_fs.c +3
-0+void fill_flat_vec (const char *path,int verbose) +{ +int dir =SAFE_OPEN (path,O_PATH |O_DIRECTORY |O_FSYNC );
Alpine has problem with O_FSYNC:
In file included from ../include/tst_test.h:110,
from tst_fill_fs.c:13:
tst_fill_fs.c: In function 'fill_flat_vec':
tst_fill_fs.c:76:58: error: 'O_FSYNC' undeclared (first use in this function); did you mean 'O_ASYNC'?
76 | int dir = SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__, __LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
tst_fill_fs.c:76:58: note: each undeclared identifier is reported only once for each function it appears in
76 | int dir = SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__, __LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
make: *** [../include/mk/rules.mk:15: tst_fill_fs.o] Error 1
It actually does not have it in fcntl.h (and nowhere in the sources).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] tst_fill_fs: Add alternate access pattern "flat"
Hi!
Quoted 35 lines
Quoted 6 lines
Depending on the workload, the way in which a file system is filled will be different. The system calls will also be different.
This adds a fill mode which uses writev with uniform batches of data. This simulates when the FS is filled by a program which batches writes.
...
FYI this broke CI on Alpine.
Quoted 1 line
+++
b/lib/tst_fill_fs.c...
lib/tst_fill_fs.c void tst_fill_fs(const char *path, int verbose) · line 76
Quoted 3 lines
lib/tst_fill_fs.c +3
-0+void fill_flat_vec (const char *path,int verbose) +{ +int dir =SAFE_OPEN (path,O_PATH |O_DIRECTORY |O_FSYNC );Alpine has problem with
O_FSYNC:In file included from
../include/tst_test.h:110,from tst_fill_fs.c:13:
tst_fill_fs.c: In function 'fill_flat_vec':
tst_fill_fs.c:76:58: error: 'O_FSYNC' undeclared (first use in this function); did you mean 'O_ASYNC'?
76 | int dir =SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__,__LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
tst_fill_fs.c:76:58: note: each undeclared identifier is reported only once for each function it appears in
76 | int dir =SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__,__LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
make: *** [../include/mk/rules.mk:15: tst_fill_fs.o] Error 1
Quoted 1 line
It actually does not have it in
fcntl.h(and nowhere in the sources).
O_FSYNC originates from BSD it should be O_SYNC on Linux, but given that this is only file descriptor passed to later openat() we can just remove it instead since it does not make sense at all.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] tst_fill_fs: Add alternate access pattern "flat"
Hello,
Quoted 36 lines · Cyril Hrubis
Hi!
Quoted 35 lines
Quoted 6 lines
Depending on the workload, the way in which a file system is filled will be different. The system calls will also be different.
This adds a fill mode which uses writev with uniform batches of data. This simulates when the FS is filled by a program which batches writes.
...
FYI this broke CI on Alpine.
Quoted 1 line
+++
b/lib/tst_fill_fs.c...
lib/tst_fill_fs.c void tst_fill_fs(const char *path, int verbose) · line 76
Quoted 3 lines
lib/tst_fill_fs.c +3
-0+void fill_flat_vec (const char *path,int verbose) +{ +int dir =SAFE_OPEN (path,O_PATH |O_DIRECTORY |O_FSYNC );Alpine has problem with
O_FSYNC:In file included from
../include/tst_test.h:110,from tst_fill_fs.c:13:
tst_fill_fs.c: In function 'fill_flat_vec':
tst_fill_fs.c:76:58: error: 'O_FSYNC' undeclared (first use in this function); did you mean 'O_ASYNC'?
76 | int dir =SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__,__LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
tst_fill_fs.c:76:58: note: each undeclared identifier is reported only once for each function it appears in
76 | int dir =SAFE_OPEN(path, O_PATH | O_DIRECTORY | O_FSYNC);
| ^~~~~~~../include/tst_safe_macros.h:90:58: note: in definition of macro 'SAFE_OPEN'
90 | safe_open(__FILE__,__LINE__, NULL, (pathname), (oflags), \
| ^~~~~~
make: *** [../include/mk/rules.mk:15: tst_fill_fs.o] Error 1
Quoted 5 lines
Quoted 1 line
It actually does not have it in
fcntl.h(and nowhere in the sources).
O_FSYNCoriginates from BSD it should beO_SYNCon Linux, but given that this is only file descriptor passed to lateropenat()we can just remove it instead since it does not make sense at all.
Ah, that was supposed to be added to the next open. However I guess it can just be removed.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp