aio_tio: fix error diagnosis for byte transfers
PATCH v2 1/2 aio_tio: fix error diagnosis for byte transfers
In case the expected bytes written during an async io operation did not match the actually written ones, the wrong error code (res2) had been reported. Correct that to reflect the error condition (res!=bytes).
--- testcases/kernel/io/aio/aio02/aio_tio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/io/aio/aio02/aio_tio.c +1 -1
@@ -57,7 +57,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)if (res != iocb->u.c.nbytes) {fprintf (stderr,"write missed bytes expect %lu got %ld\n" , - iocb->u.c.nbytes, res2); + iocb->u.c.nbytes, res);exit (1 ); } wait_count--;
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 2/2 aio_tio: determine alignment based on target filesystem
The alignment for O_DIRECT operations has to match the blocksize of the underlying filesystem. Determine the alignment from the target file's file system.
aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.
Determining the blocksize from the file system and using it for the alignment resolves the test issue.
--- testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/io/aio/aio02/aio_tio.c +7 -1
@@ -34,6 +34,7 @@#include "config.h" #include "common.h" #include "test.h" +#include "safe_macros.h" #include <string.h> #include <errno.h>
@@ -42,7 +43,6 @@#define AIO_MAXIO 32#define AIO_BLKSIZE (64*1024) -static int alignment =512 ;static int wait_count =0 ;/*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)void *bufptr =NULL ;off_t offset =0 ;struct timespec timeout; +struct stat fi_stat; +size_t alignment;io_context_t myctx;struct iocb iocb_array[AIO_MAXIO ];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)return -1 ; } +/* determine the alignment from the blksize of the underlying fs */ +SAFE_FSTAT (NULL , fd, &fi_stat); + alignment = fi_stat.st_blksize; + res =io_queue_init (n, &myctx);//printf (" res = %d \n", res);
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 2/2 aio_tio: determine alignment based on target filesystem
Quoted 57 lines · Matthias Maennich
The alignment for
O_DIRECToperations has to match the blocksize of the underlying filesystem. Determine the alignment from the target file's file system.
aio_tiotest cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.Determining the blocksize from the file system and using it for the alignment resolves the test issue.
Signed-off-by Matthias Maennich <[email protected]>Reviewed-by Alessio Balsini <[email protected]>--- testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)testcases/kernel/io/aio/aio02/aio_tio.c +7
-1@@ -34,6 +34,7 @@#include "config.h" #include "common.h" #include "test.h" +#include "safe_macros.h" #include <string.h> #include <errno.h> @@ -42,7 +43,6 @@#define AIO_MAXIO 32#define AIO_BLKSIZE (64*1024) -static int alignment =512 ;static int wait_count =0 ;/* @@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)void *bufptr =NULL ;off_t offset =0 ;struct timespec timeout; +struct stat fi_stat; +size_t alignment;io_context_t myctx;struct iocb iocb_array[AIO_MAXIO ];@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)return -1 ; } +/* determine the alignment from the blksize of the underlying fs */ +SAFE_FSTAT (NULL , fd, &fi_stat); + alignment = fi_stat.st_blksize; + res =io_queue_init (n, &myctx);//printf (" res = %d \n", res);
PATCH v2 2/2 aio_tio: determine alignment based on target filesystem
In reply to Matthias MaennichHi!
Quoted 6 lines
The alignment for
O_DIRECToperations has to match the blocksize of the underlying filesystem. Determine the alignment from the target file's file system.
aio_tiotest cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.
Is this really about the filesystem? Citing man open:
Under Linux 2.4, transfer sizes, and the alignment of the user buffer and the file offset must all be multiples of the logical block size of the filesystem. Since Linux 2.6.0, alignment to the logical block size of the underlying storage (typically 512 bytes) suffices. The logical block size can be determined using the ioctl(2) BLKSSZGET operation or from the shell using the command:
blockdev --getss
So unless you are running ancient 2.4 kernel the aligment restrictions should be result of the blocksize of the device rather than of the filesystem.
What does the blockdev command return on the particular system?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 aio_tio: determine alignment based on target filesystem
Hi!
Quoted 16 lines · Cyril Hrubis
Quoted 6 lines
The alignment for
O_DIRECToperations has to match the blocksize of the underlying filesystem. Determine the alignment from the target file's file system.
aio_tiotest cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.Is this really about the filesystem? Citing man open:
Under Linux 2.4, transfer sizes, and the alignment of the user buffer and the file offset must all be multiples of the logical block size of the filesystem. Since Linux 2.6.0, alignment to the logical block size of the underlying storage (typically 512 bytes) suffices. The logical block size can be determined using the ioctl(2) BLKSSZGET operation or from the shell using the command:
Quoted 4 lines
blockdev --getss
So unless you are running ancient 2.4 kernel the aligment restrictions should be result of the blocksize of the device rather than of the filesystem.
Yes. You are right. The blocksize of the device is what I was referring to. Sorry for that.
In particular the test hits the alignment check in fs/direct-io.c (do_blockdev_direct_IO) [1], which makes the direct io operation fail in my case with EINVAL.
Quoted 1 line
What does the blockdev command return on the particular system?
4096
I will update the patch to correct comment and commit message.
Thanks,
Matthias
[1] https://elixir.bootlin.com/linux/v4.20/source/fs/direct-io.c#L1199
v3 cover aio_tio: fixes and conversion to new lib
In reply to Matthias MaennichThis patch series is a resend of an earlier series for two bug fixes. In addition, it now contains a patch to migrate the test to the new lib along with some cleanup.
Cheers,
Matthias
Matthias Maennich (3):
aio_tio: fix error diagnosis for byte transfers
aio_tio: determine alignment based on target filesystem
aio_tio: convert to new lib
testcases/kernel/io/aio/aio02/Makefile | 24 +-- testcases/kernel/io/aio/aio02/aio_tio.c | 207 +++++++++++++----------- testcases/kernel/io/aio/aio02/common.h | 28 ---- testcases/kernel/io/aio/aio02/main.c | 37 ----- 4 files changed, 112 insertions(+), 184 deletions(-) delete mode 100644 testcases/kernel/io/aio/aio02/common.h delete mode 100644 testcases/kernel/io/aio/aio02/main.c
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v3 1/3 aio_tio: fix error diagnosis for byte transfers
In case the expected bytes written during an async io operation did not match the actually written ones, the wrong error code (res2) had been reported. Correct that to reflect the error condition (res!=bytes).
--- testcases/kernel/io/aio/aio02/aio_tio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/io/aio/aio02/aio_tio.c +1 -1
@@ -57,7 +57,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)if (res != iocb->u.c.nbytes) {fprintf (stderr,"write missed bytes expect %lu got %ld\n" , - iocb->u.c.nbytes, res2); + iocb->u.c.nbytes, res);exit (1 ); } wait_count--;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v3 2/3 aio_tio: determine alignment based on target filesystem
In reply to Matthias MaennichThe alignment for O_DIRECT operations has to match the blocksize of the underlying filesystem. Determine the alignment from the target file's file system.
aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize filesystem and with an alignment of 512 bytes.
Determining the blocksize from the file system and using it for the alignment resolves the test issue.
--- testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/io/aio/aio02/aio_tio.c +7 -1
@@ -34,6 +34,7 @@#include "config.h" #include "common.h" #include "test.h" +#include "safe_macros.h" #include <string.h> #include <errno.h>
@@ -42,7 +43,6 @@#define AIO_MAXIO 32#define AIO_BLKSIZE (64*1024) -static int alignment =512 ;static int wait_count =0 ;/*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)void *bufptr =NULL ;off_t offset =0 ;struct timespec timeout; +struct stat fi_stat; +size_t alignment;io_context_t myctx;struct iocb iocb_array[AIO_MAXIO ];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)return -1 ; } +/* determine the alignment from the blksize of the underlying fs */ +SAFE_FSTAT (NULL , fd, &fi_stat); + alignment = fi_stat.st_blksize; + res =io_queue_init (n, &myctx);//printf (" res = %d \n", res);
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v3 3/3 aio_tio: convert to new lib
In reply to Matthias MaennichConvert to the new test lib and perform various cleanups. Also refactor the test definition for readability.
--- testcases/kernel/io/aio/aio02/Makefile | 24 +-- testcases/kernel/io/aio/aio02/aio_tio.c | 201 +++++++++++++----------- testcases/kernel/io/aio/aio02/common.h | 28 ---- testcases/kernel/io/aio/aio02/main.c | 37 ----- 4 files changed, 106 insertions(+), 184 deletions(-) delete mode 100644 testcases/kernel/io/aio/aio02/common.h delete mode 100644 testcases/kernel/io/aio/aio02/main.c
testcases/kernel/io/aio/aio02/Makefile +1 -23
@@ -1,36 +1,14 @@ -# -# kernel/io/aio/aio2 testcase Makefile. +// SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (C) 2009, Cisco Systems Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Ngie Cooper, July 2009 -# top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk -# Needed for common.h... CPPFLAGS += -D_GNU_SOURCE LDLIBS += $(AIO_LIBS) -FILTER_OUT_MAKE_TARGETS := main - include $(top_srcdir)/include/mk/generic_leaf_target.mk - -$(MAKE_TARGETS): %: %.o main.o
testcases/kernel/io/aio/aio02/aio_tio.c +105 -96
300 lines not on this page · raw message
testcases/kernel/io/aio/aio02/common.h deleted +0 -28
@@ -1,28 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/param.h> -#include <errno.h> -#include <stdlib.h> -#include <sys/select.h> -#if HAVE_LIBAIO_H -#include <libaio.h> -#endif -#include <sys/uio.h> -#include <assert.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> - -/* Fatal error handler */ -static void io_error (const char *func,int rc) -{ -if (rc == -ENOSYS ) -fprintf (stderr,"AIO not in this kernel\n" ); -else if (rc <0 ) -fprintf (stderr,"%s: %s\n" , func,strerror (-rc)); -else -fprintf (stderr,"%s: error %d\n" , func, rc); - -exit (1 ); -}
testcases/kernel/io/aio/aio02/main.c deleted +0 -37
@@ -1,37 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include "config.h" -#include "test.h" - -#define TEST_NAME "aio_tio" - -char *TCID ="aio02/" TEST_NAME ; -int TST_TOTAL =0 ; - -#ifdef HAVE_LIBAIO -#include <libaio.h> - -int test_main (void ); - -int main (void ) -{ -tst_tmpdir (); - -test_main (); - -tst_rmdir (); -tst_exit (); -} -#else -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"test requires libaio and it's development packages" ); -} -#endif
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v3 3/3 aio_tio: convert to new lib
Hi Matthias,
Quoted 9 lines · Matthias Maennich' via kernel-team
Convert to the new test lib and perform various cleanups. Also refactor the test definition for readability.
Signed-off-by Matthias Maennich <[email protected]>--- testcases/kernel/io/aio/aio02/Makefile | 24 +-- testcases/kernel/io/aio/aio02/aio_tio.c | 201 +++++++++++++----------- testcases/kernel/io/aio/aio02/common.h | 28 ---- testcases/kernel/io/aio/aio02/main.c | 37 -----
Given that aio02 is just a single file now it'd be a nice cleanup to get rid of the extra directory level here and just have
testcases/kernel/io/aio/aio01.ctestcases/kernel/io/aio/aio_tio.c
testcases/kernel/io/aio/Makefile
Not proposing that as part of this patch but rather just possible for someone to do in the future.
Also maybe renaming aio_tio.c to aio02.c. The only instance I see in runtest/ of aio_tio is as aio02.
Quoted 110 lines
4 files changed, 106 insertions(+), 184 deletions(-)delete mode 100644
testcases/kernel/io/aio/aio02/common.hdelete mode 100644testcases/kernel/io/aio/aio02/main.ctestcases/kernel/io/aio/aio02/Makefile +1
-23@@ -1,36 +1,14 @@ -# -# kernel/io/aio/aio2 testcase Makefile. +// SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (C) 2009, Cisco Systems Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Ngie Cooper, July 2009 -# top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk -# Needed for common.h... CPPFLAGS += -D_GNU_SOURCE LDLIBS += $(AIO_LIBS) -FILTER_OUT_MAKE_TARGETS := main - include $(top_srcdir)/include/mk/generic_leaf_target.mk - -$(MAKE_TARGETS): %: %.o main.otestcases/kernel/io/aio/aio02/aio_tio.c +18
-36@@ -1,64 +1,59 @@ -/************************************************************************************* -* -* Copyright (c) International Business Machines Corp., 2003 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, -* -* FILE : aio_tio -* USAGE : ./aio_tio -* -* DESCRIPTION : This program will test Asynchronous I/O for 2.5 Kernel infrastructure -* REQUIREMENTS: -* 1) libaio-0.3.92 or up for 2.5 kernal -* 2) glibc 2.1.91 or up -* HISTORY : -* 11/03/2003 Kai Zhao ([email protected]) -* -* CODE COVERAGE: -* 68.3% - fs/aio.c -* -************************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) International Business Machines Corp., 2003 +* +* AUTHORS +* Kai Zhao ([email protected]) +* +* DESCRIPTION : Test Asynchronous I/O for 2.5 Kernel Infrastructure +* +* REQUIREMENTS: +* 1) libaio-0.3.92 or up for 2.5 kernel +* 2) glibc 2.1.91 or up +*/ #include "config.h" -#include "common.h" -#include "test.h" -#include "safe_macros.h" -#include <string.h> +#include "tst_test.h" #include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #ifdef HAVE_LIBAIO +#include <libaio.h>
testcases/kernel/io/aio/aio02/aio_tio.c line 33
Quoted 10 lines
testcases/kernel/io/aio/aio02/aio_tio.c +4
-0#define AIO_MAXIO 32#define AIO_BLKSIZE (64*1024)static int wait_count =0 ; +/* +* Fatal error handler +*/ +void io_error (const char *func,int rc)
can this be static (or better yet, just merge into work_done())
Quoted 7 lines
testcases/kernel/io/aio/aio02/aio_tio.c +7
-0+{ +if (rc == -ENOSYS ) +tst_brk (TCONF ,"AIO not in this kernel\n" ); +else if (rc <0 ) +tst_brk (TFAIL ,"%s: %s\n" , func,strerror (-rc)); +else +tst_brk (TFAIL ,"%s: error %d\n" , func, rc);
testcases/kernel/io/aio/aio02/aio_tio.c line 50
Quoted 10 lines
testcases/kernel/io/aio/aio02/aio_tio.c +3
-0+} +/* * write work done */ static void work_done (io_context_t ctx,struct iocb *iocb,long res,long res2) { + (void ) ctx;// silence compiler warning (-Wunused) if (res2 !=0 ) {
can remove the braces here
testcases/kernel/io/aio/aio02/aio_tio.c line 54
Quoted 6 lines
testcases/kernel/io/aio/aio02/aio_tio.c +1
-2io_error ("aio write" , res2); } -if (res != iocb->u.c.nbytes) { - fprintf(stderr, "write missed bytes expect %lu got %ld\n", +if (res != (long )iocb->u.c.nbytes) {
can remove the braces here
Quoted 16 lines
testcases/kernel/io/aio/aio02/aio_tio.c +2
-2+tst_brk (TFAIL ,"write missed bytes expect %lu got %ld\n" , iocb->u.c.nbytes, res); -exit (1 ); } wait_count--; }@@ -66,7 +61,7 @@ static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)/* * io_wait_run() - wait for an io_event and then call the callback. */ -int io_wait_run (io_context_t ctx,struct timespec *to) +static int io_wait_run (io_context_t ctx,struct timespec *to) {struct io_event events[AIO_MAXIO ];struct io_event *ep;
testcases/kernel/io/aio/aio02/aio_tio.c int io_wait_run(io_context_t ctx, struct timespec *to) · line 86
Quoted 5 lines
testcases/kernel/io/aio/aio02/aio_tio.c +1
-1@@ -88,7 +83,7 @@ int io_wait_run(io_context_t ctx, struct timespec *to)return ret; } -int io_tio (char *pathname,int flag,int n,int operation) +static int io_tio (char *pathname,int flag,int n,int operation)
I noticed this fn is always getting called with n = AIO_MAXIO, is the parameter still needed as opposed to just hardcoding that in here
Quoted 67 lines
testcases/kernel/io/aio/aio02/aio_tio.c +7
-14{int res, fd =0 , i =0 ;void *bufptr =NULL ;@@ -101,31 +96,26 @@ int io_tio(char *pathname, int flag, int n, int operation)struct iocb iocb_array[AIO_MAXIO ];struct iocb *iocbps[AIO_MAXIO ]; - fd =open (pathname, flag,S_IRUSR |S_IWUSR |S_IRGRP |S_IROTH ); -if (fd <=0 ) { -printf ("open for %s failed: %s\n" , pathname,strerror (errno)); -return -1 ; - } + fd =SAFE_OPEN (pathname, flag,S_IRUSR |S_IWUSR |S_IRGRP |S_IROTH );/* determine the alignment from the blksize of the underlying fs */ -SAFE_FSTAT (NULL , fd, &fi_stat); +SAFE_FSTAT (fd, &fi_stat); alignment = fi_stat.st_blksize; res =io_queue_init (n, &myctx); -//printf (" res = %d \n", res); for (i =0 ; i <AIO_MAXIO ; i++) {switch (operation) {case IO_CMD_PWRITE :if (posix_memalign (&bufptr, alignment,AIO_BLKSIZE )) { -perror (" posix_memalign failed " ); +tst_brk (TBROK |TERRNO ,"posix_memalign failed" );return -1 ; }memset (bufptr,0 ,AIO_BLKSIZE );io_prep_pwrite (&iocb_array[i], fd, bufptr, -AIO_BLKSIZE , offset); +AIO_BLKSIZE , offset);io_set_callback (&iocb_array[i], work_done); iocbps[i] = &iocb_array[i]; offset +=AIO_BLKSIZE ;@@ -133,13 +123,13 @@ int io_tio(char *pathname, int flag, int n, int operation)break ;case IO_CMD_PREAD :if (posix_memalign (&bufptr, alignment,AIO_BLKSIZE )) { -perror (" posix_memalign failed " ); +tst_brk (TBROK |TERRNO ,"posix_memalign failed" );return -1 ; }memset (bufptr,0 ,AIO_BLKSIZE );io_prep_pread (&iocb_array[i], fd, bufptr, -AIO_BLKSIZE , offset); +AIO_BLKSIZE , offset);io_set_callback (&iocb_array[i], work_done); iocbps[i] = &iocb_array[i]; offset +=AIO_BLKSIZE ;@@ -148,9 +138,7 @@ int io_tio(char *pathname, int flag, int n, int operation)case IO_CMD_NOOP :break ;default : -tst_resm (TFAIL , -"Command failed; opcode returned: %d\n" , - operation); +tst_res (TFAIL ,"Command failed; opcode returned: %d\n" , operation);return -1 ;break ; }
testcases/kernel/io/aio/aio02/aio_tio.c int io_tio(char *pathname, int flag, int n, int operation) · line 156
Quoted 7 lines
testcases/kernel/io/aio/aio02/aio_tio.c +2
-2@@ -164,8 +152,8 @@ int io_tio(char *pathname, int flag, int n, int operation) }/* -* We have submitted all the i/o requests. Wait for at least one to complete -* and call the callbacks. +* We have submitted all the i/o requests. Wait for at least one to +* complete and call the callbacks.
Is this comment accurate? It looks like we're waiting for all the io requests to complete (not at least one)
Quoted 90 lines
testcases/kernel/io/aio/aio02/aio_tio.c +40
-33*/ wait_count =AIO_MAXIO ;@@ -185,7 +173,7 @@ int io_tio(char *pathname, int flag, int n, int operation)break ; } -close (fd); +SAFE_CLOSE (fd);for (i =0 ; i <AIO_MAXIO ; i++) {if (iocb_array[i].u.c.buf !=NULL ) {@@ -198,49 +186,70 @@ int io_tio(char *pathname, int flag, int n, int operation)return 0 ; } -int test_main (void ) +static void test_main (void ) { -int status =0 ; - -tst_resm (TINFO ,"Running test 1\n" ); - status =io_tio ("file1" , -O_TRUNC |O_DIRECT |O_WRONLY |O_CREAT |O_LARGEFILE , -AIO_MAXIO ,IO_CMD_PWRITE ); -if (status) { -return status; - } +struct testcase { +const char *description; +int flags; +int operation; + } testcases[] = { + { .description = +"WRITE: O_WRONLY | O_TRUNC | O_DIRECT | O_LARGEFILE | O_CREAT" , + .flags =O_WRONLY |O_TRUNC |O_DIRECT |O_LARGEFILE |O_CREAT , + .operation =IO_CMD_PWRITE + }, + { .description = +"WRITE: O_RDONLY | O_DIRECT | O_LARGEFILE" , + .flags =O_RDONLY |O_DIRECT |O_LARGEFILE , + .operation =IO_CMD_PREAD + }, + { .description = +"WRITE: O_RDWR | O_TRUNC" , + .flags =O_RDWR |O_TRUNC , + .operation =IO_CMD_PWRITE + }, + { .description = +"READ : O_RDWR" , + .flags =O_RDWR , + .operation =IO_CMD_PREAD + }, + { .description = +"WRITE: O_WRONLY | O_TRUNC" , + .flags =O_WRONLY |O_TRUNC , + .operation =IO_CMD_PWRITE + }, + { .description = +"READ : O_RDONLY" , + .flags =O_RDONLY , + .operation =IO_CMD_PREAD + }, + }; -tst_resm (TINFO ,"Running test 2\n" ); - status =io_tio ("file1" ,O_RDONLY |O_DIRECT |O_LARGEFILE , -AIO_MAXIO ,IO_CMD_PREAD ); -if (status) { -return status; - } - -tst_resm (TINFO ,"Running test 3\n" ); - status =io_tio ("file1" ,O_TRUNC |O_RDWR ,AIO_MAXIO ,IO_CMD_PWRITE ); -if (status) { -return status; - } - -tst_resm (TINFO ,"Running test 4\n" ); - status =io_tio ("file1" ,O_RDWR ,AIO_MAXIO ,IO_CMD_PREAD ); -if (status) { -return status; - } +int status =0 ; -tst_resm (TINFO ,"Running test 5\n" ); - status =io_tio ("file1" ,O_TRUNC |O_WRONLY ,AIO_MAXIO ,IO_CMD_PWRITE ); -if (status) { -return status; +for (size_t i =0 ; i <ARRAY_SIZE (testcases); ++i) {
testcases/kernel/io/aio/aio02/aio_tio.c int io_tio(char *pathname, int flag, int n, int operation) · line 240
Quoted 10 lines
testcases/kernel/io/aio/aio02/aio_tio.c +9
-0+tst_res (TINFO ,"%s" , testcases[i].description); + status =io_tio ("file" , testcases[i].flags,AIO_MAXIO , + testcases[i].operation); +if (status) { +tst_res (TFAIL ,"%s, status = %d" , + testcases[i].description, status); + }else { +tst_res (TPASS ,"%s" , testcases[i].description); + } }
The LTP lib has support for testcases that have multiple subtests like this, see for example testcases/kernel/syscalls/access01.c. It'll save you having to iterate over the subtests here.
I thought maybe it would also allow running individual subtests directly from the command line - that doesn't seem to be supported currently but perhaps will in the future.
testcases/kernel/io/aio/aio02/aio_tio.c int io_tio(char *pathname, int flag, int n, int operation) · line 247
Quoted 13 lines
testcases/kernel/io/aio/aio02/aio_tio.c +5
-6+} -tst_resm (TINFO ,"Running test 6 \n" ); - status =io_tio ("file1" ,O_RDONLY ,AIO_MAXIO ,IO_CMD_PREAD ); -if (status) { -return status; - } +#else -return status; +static void test_main (void ) +{ +tst_brk (TCONF ,"test requires libaio and it's development packages" );
nit, its instead of it's
Quoted 86 lines
testcases/kernel/io/aio/aio02/aio_tio.c +6
-0} +#endif + +static struct tst_test test = { + .needs_tmpdir =1 , + .test_all = test_main +};testcases/kernel/io/aio/aio02/common.h deleted +0
-28@@ -1,28 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/param.h> -#include <errno.h> -#include <stdlib.h> -#include <sys/select.h> -#if HAVE_LIBAIO_H -#include <libaio.h> -#endif -#include <sys/uio.h> -#include <assert.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> - -/* Fatal error handler */ -static void io_error (const char *func,int rc) -{ -if (rc == -ENOSYS ) -fprintf (stderr,"AIO not in this kernel\n" ); -else if (rc <0 ) -fprintf (stderr,"%s: %s\n" , func,strerror (-rc)); -else -fprintf (stderr,"%s: error %d\n" , func, rc); - -exit (1 ); -}testcases/kernel/io/aio/aio02/main.c deleted +0
-37@@ -1,37 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include "config.h" -#include "test.h" - -#define TEST_NAME "aio_tio" - -char *TCID ="aio02/" TEST_NAME ; -int TST_TOTAL =0 ; - -#ifdef HAVE_LIBAIO -#include <libaio.h> - -int test_main (void ); - -int main (void ) -{ -tst_tmpdir (); - -test_main (); - -tst_rmdir (); -tst_exit (); -} -#else -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"test requires libaio and it's development packages" ); -} -#endif
PATCH v2 1/2 aio_tio: fix error diagnosis for byte transfers
In reply to Matthias MaennichHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
v4 cover aio_tio: fixes and conversion to new lib
In reply to Matthias MaennichThis patch series fixes aio_tio and migrates the test to the new lib along with some cleanup.
v3->v4: - address review comments
- add directory cleanup patch
Matthias Maennich (3):
aio_tio: determine alignment based on target block device
aio_tio: convert to new lib
io/aio: cleanup test directory
runtest/io | 2 +-
testcases/kernel/io/aio/.gitignore | 4 +-
testcases/kernel/io/aio/Makefile | 22 +-
testcases/kernel/io/aio/{aio01 => }/aio01.c | 0
testcases/kernel/io/aio/aio01/Makefile | 30 ---
testcases/kernel/io/aio/aio02.c | 246 ++++++++++++++++++++
testcases/kernel/io/aio/aio02/Makefile | 36 ---
testcases/kernel/io/aio/aio02/README | 12 -
testcases/kernel/io/aio/aio02/aio_tio.c | 240 -------------------
testcases/kernel/io/aio/aio02/common.h | 28 ---
testcases/kernel/io/aio/aio02/main.c | 37 ---
11 files changed, 256 insertions(+), 401 deletions(-)
rename testcases/kernel/io/aio/{aio01 => }/aio01.c (100%)
delete mode 100644 testcases/kernel/io/aio/aio01/Makefile
create mode 100644 testcases/kernel/io/aio/aio02.c
delete mode 100644 testcases/kernel/io/aio/aio02/Makefile
delete mode 100644 testcases/kernel/io/aio/aio02/README
delete mode 100644 testcases/kernel/io/aio/aio02/aio_tio.c
delete mode 100644 testcases/kernel/io/aio/aio02/common.h
delete mode 100644 testcases/kernel/io/aio/aio02/main.cSignature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH v4 1/3 aio_tio: determine alignment based on target block device
The alignment for O_DIRECT operations has to match the blocksize of the underlying block device. Determine the alignment from the target file.
aio_tio test cases 1 and 2 failed (nondeterministic) on aarch64 when run on a 4096 byte blocksize and with an alignment of 512 bytes.
Determining the blocksize from the block device and using it for the alignment resolves the test issue.
--- testcases/kernel/io/aio/aio02/aio_tio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/io/aio/aio02/aio_tio.c +7 -1
@@ -34,6 +34,7 @@#include "config.h" #include "common.h" #include "test.h" +#include "safe_macros.h" #include <string.h> #include <errno.h>
@@ -42,7 +43,6 @@#define AIO_MAXIO 32#define AIO_BLKSIZE (64*1024) -static int alignment =512 ;static int wait_count =0 ;/*
@@ -94,6 +94,8 @@ int io_tio(char *pathname, int flag, int n, int operation)void *bufptr =NULL ;off_t offset =0 ;struct timespec timeout; +struct stat fi_stat; +size_t alignment;io_context_t myctx;struct iocb iocb_array[AIO_MAXIO ];
@@ -105,6 +107,10 @@ int io_tio(char *pathname, int flag, int n, int operation)return -1 ; } +/* determine the alignment from the blksize of the underlying device */ +SAFE_FSTAT (NULL , fd, &fi_stat); + alignment = fi_stat.st_blksize; + res =io_queue_init (n, &myctx);//printf (" res = %d \n", res);
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH v4 2/3 aio_tio: convert to new lib
In reply to Matthias MaennichConvert to the new test lib and perform various cleanups. Also refactor the test definition for readability.
--- testcases/kernel/io/aio/aio02/Makefile | 24 +-- testcases/kernel/io/aio/aio02/aio_tio.c | 218 ++++++++++++------------ testcases/kernel/io/aio/aio02/common.h | 28 --- testcases/kernel/io/aio/aio02/main.c | 37 ---- 4 files changed, 110 insertions(+), 197 deletions(-) delete mode 100644 testcases/kernel/io/aio/aio02/common.h delete mode 100644 testcases/kernel/io/aio/aio02/main.c
testcases/kernel/io/aio/aio02/Makefile +1 -23
@@ -1,36 +1,14 @@ -# -# kernel/io/aio/aio2 testcase Makefile. +// SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (C) 2009, Cisco Systems Inc. # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Ngie Cooper, July 2009 -# top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk -# Needed for common.h... CPPFLAGS += -D_GNU_SOURCE LDLIBS += $(AIO_LIBS) -FILTER_OUT_MAKE_TARGETS := main - include $(top_srcdir)/include/mk/generic_leaf_target.mk - -$(MAKE_TARGETS): %: %.o main.o
testcases/kernel/io/aio/aio02/aio_tio.c +109 -109
316 lines not on this page · raw message
testcases/kernel/io/aio/aio02/common.h deleted +0 -28
@@ -1,28 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/param.h> -#include <errno.h> -#include <stdlib.h> -#include <sys/select.h> -#if HAVE_LIBAIO_H -#include <libaio.h> -#endif -#include <sys/uio.h> -#include <assert.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> - -/* Fatal error handler */ -static void io_error (const char *func,int rc) -{ -if (rc == -ENOSYS ) -fprintf (stderr,"AIO not in this kernel\n" ); -else if (rc <0 ) -fprintf (stderr,"%s: %s\n" , func,strerror (-rc)); -else -fprintf (stderr,"%s: error %d\n" , func, rc); - -exit (1 ); -}
testcases/kernel/io/aio/aio02/main.c deleted +0 -37
@@ -1,37 +0,0 @@ -#include <stdio.h> -#include <errno.h> -#include <assert.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include "config.h" -#include "test.h" - -#define TEST_NAME "aio_tio" - -char *TCID ="aio02/" TEST_NAME ; -int TST_TOTAL =0 ; - -#ifdef HAVE_LIBAIO -#include <libaio.h> - -int test_main (void ); - -int main (void ) -{ -tst_tmpdir (); - -test_main (); - -tst_rmdir (); -tst_exit (); -} -#else -int main (void ) -{ -tst_brkm (TCONF ,NULL ,"test requires libaio and it's development packages" ); -} -#endif
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH v4 2/3 aio_tio: convert to new lib
Quoted 4 lines · Matthias Maennich
Convert to the new test lib and perform various cleanups. Also refactor the test definition for readability.
Signed-off-by Matthias Maennich <[email protected]>
Quoted 8 lines
--- testcases/kernel/io/aio/aio02/Makefile | 24 +-- testcases/kernel/io/aio/aio02/aio_tio.c | 218 ++++++++++++------------ testcases/kernel/io/aio/aio02/common.h | 28 --- testcases/kernel/io/aio/aio02/main.c | 37 ---- 4 files changed, 110 insertions(+), 197 deletions(-)delete mode 100644
testcases/kernel/io/aio/aio02/common.hdelete mode 100644testcases/kernel/io/aio/aio02/main.c
PATCH v4 2/3 aio_tio: convert to new lib
In reply to Matthias MaennichHi Matthias,
Quoted 2 lines
Convert to the new test lib and perform various cleanups. Also refactor the test definition for readability.
Thanks for your work, whole patchset pushed, with following fixes and further cleanup.
Defining struct tst_test after HAVE_LIBAIO guard lead to build failures on distros without libaio.
Kind regards,
Petr
kernel/io/aio/Makefile +2 -5
@@ -1,14 +1,11 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -# -# Copyright (c) International Business Machines Corp., 2001 -# +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk CPPFLAGS += -D_GNU_SOURCE - LDLIBS += $(AIO_LIBS) include $(top_srcdir)/include/mk/generic_leaf_target.mk
kernel/io/aio/aio02.c +26 -48
122 lines not on this page · raw message
PATCH v4 3/3 io/aio: cleanup test directory
In reply to Matthias MaennichNow that aio_tio is just a single file test, consolidate the aio tests within io/aio.
---
runtest/io | 2 +-
testcases/kernel/io/aio/.gitignore | 4 +--
testcases/kernel/io/aio/Makefile | 22 +++++---------
testcases/kernel/io/aio/{aio01 => }/aio01.c | 0
testcases/kernel/io/aio/aio01/Makefile | 30 -------------------
.../io/aio/{aio02/aio_tio.c => aio02.c} | 0
testcases/kernel/io/aio/aio02/Makefile | 14 ---------
testcases/kernel/io/aio/aio02/README | 12 --------
8 files changed, 10 insertions(+), 74 deletions(-)
rename testcases/kernel/io/aio/{aio01 => }/aio01.c (100%)
delete mode 100644 testcases/kernel/io/aio/aio01/Makefile
rename testcases/kernel/io/aio/{aio02/aio_tio.c => aio02.c} (100%)
delete mode 100644 testcases/kernel/io/aio/aio02/Makefile
delete mode 100644 testcases/kernel/io/aio/aio02/READMEruntest/io +1 -1
@@ -1,3 +1,3 @@ #AIO01 & AIO02 tests to be run aio01 aio01 -aio02 aio_tio +aio02 aio02
testcases/kernel/io/aio/.gitignore +2 -2
@@ -1,2 +1,2 @@ -/aio01/aio01 -/aio02/aio_tio +aio01 +aio02
testcases/kernel/io/aio/Makefile +7 -15
@@ -1,22 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later # # Copyright (c) International Business Machines Corp., 2001 # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/include/mk/generic_trunk_target.mk + +CPPFLAGS += -D_GNU_SOURCE + +LDLIBS += $(AIO_LIBS) + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/io/aio/aio01.c renamed from testcases/kernel/io/aio/aio01/aio01.c +0 -0
testcases/kernel/io/aio/aio01/Makefile deleted +0 -30
@@ -1,30 +0,0 @@ -# -# Copyright (c) International Business Machines Corp., 2001 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -########################################################################### -# name of file : Makefile # -# description : make(1) description file # -########################################################################### - -top_srcdir ?= ../../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -LDLIBS += $(AIO_LIBS) - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/io/aio/aio02.c renamed from testcases/kernel/io/aio/aio02/aio_tio.c +0 -0
testcases/kernel/io/aio/aio02/Makefile deleted +0 -14
@@ -1,14 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -# -# Copyright (C) 2009, Cisco Systems Inc. -# - -top_srcdir ?= ../../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -D_GNU_SOURCE - -LDLIBS += $(AIO_LIBS) - -include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/io/aio/aio02/README deleted +0 -12
@@ -1,12 +0,0 @@ -This program will test Asynchronous I/O support by kernel 2.5 . -make the program - make -execute the test - ./aio_tio - - -NOTE: - make sure your system are support with libaio-0.3.92 or higher. - you can download this form http://www.kernel.org. - make sure your system are support with glibc 2.1.91 or higher. -
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
PATCH v4 3/3 io/aio: cleanup test directory
Quoted 15 lines · Matthias Maennich
Now that
aio_tiois just a single file test, consolidate the aio tests within io/aio.Suggested-by Steve Muckle <[email protected]>Signed-off-by Matthias Maennich <[email protected]>--- runtest/io | 2 +- testcases/kernel/io/aio/.gitignore | 4 +-- testcases/kernel/io/aio/Makefile | 22 +++++--------- testcases/kernel/io/aio/{aio01 => }/aio01.c | 0 testcases/kernel/io/aio/aio01/Makefile | 30 ------------------- .../io/aio/{aio02/aio_tio.c => aio02.c} | 0 testcases/kernel/io/aio/aio02/Makefile | 14 --------- testcases/kernel/io/aio/aio02/README | 12 -------- 8 files changed, 10 insertions(+), 74 deletions(-)
Quoted 5 lines
rename testcases/kernel/io/aio/{aio01 =>
}/aio01.c(100%) delete mode 100644 testcases/kernel/io/aio/aio01/Makefile renametestcases/kernel/io/aio/{aio02/aio_tio.c=>aio02.c} (100%) delete mode 100644 testcases/kernel/io/aio/aio02/Makefile delete mode 100644 testcases/kernel/io/aio/aio02/README