Introduce SAFE_SPLICE()
v3 cover Introduce SAFE_SPLICE()
- add SAFE_SPLICE()
- update tests to use the new macro
---
Changes in v3:
- fix commit add correct imports
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- fix compile issues by moving SAFE_SPLICE in lapi/splice.h
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (2):
lib: Add SAFE_SPLICE() macro
tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
include/lapi/splice.h | 28 +++++++++++++++++++++++++ testcases/kernel/crypto/af_alg08.c | 9 ++------ testcases/kernel/syscalls/tee/tee01.c | 8 ++----- testcases/kernel/syscalls/vmsplice/vmsplice01.c | 5 +---- 4 files changed, 33 insertions(+), 17 deletions(-)
---
base-commit: 73cfad509db014e5a631bd2298f4e9d8ea3ee1c1
change-id: 20260430-safe_splice-a3d6403f99cd
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/2 lib: Add SAFE_SPLICE() macro
From: Andrea Cervesato <[email protected]>
Add new SAFE_SPLIT() in lapi/splice.h.
--- include/lapi/splice.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
include/lapi/splice.h +28 -0
@@ -7,6 +7,13 @@#ifndef LAPI_SPLICE_H__ #define LAPI_SPLICE_H__ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif + +#include <fcntl.h> +#include <sys/types.h> +#include "config.h" #include "lapi/syscalls.h"
@@ -19,4 +26,25 @@ static inline ssize_t splice(int fd_in, loff_t *off_in, int fd_out, }#endif +static inline ssize_t safe_splice (const char *file,const int lineno, +int fd_in,loff_t *off_in, +int fd_out,loff_t *off_out, +size_t len,unsigned int flags) +{ +ssize_t ret; + + ret =splice (fd_in, off_in, fd_out, off_out, len, flags); + +if (ret <0 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"splice(%d, %d, %zu) failed" , fd_in, fd_out, len); + } + +return ret; +} + +#define SAFE_SPLICE (fd_in, off_in, fd_out, off_out, len, flags) \ + safe_splice(__FILE__, __LINE__, (fd_in), (off_in), (fd_out), \ + (off_out), (len), (flags)) +#endif /* LAPI_SPLICE_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro
Hi!
Quoted 31 lines
Add new
SAFE_SPLIT()inlapi/splice.h.Signed-off-by Andrea Cervesato <[email protected]>--- include/lapi/splice.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/lapi/splice.h +9
-0@@ -7,6 +7,13 @@#ifndef LAPI_SPLICE_H__ #define LAPI_SPLICE_H__ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif + +#include <fcntl.h> +#include <sys/types.h> +#include "config.h" #include "lapi/syscalls.h" @@ -19,4 +26,25 @@ static inline ssize_t splice(int fd_in, loff_t *off_in, int fd_out, }#endif +static inline ssize_t safe_splice(const char *file, const int lineno, + int fd_in, loff_t *off_in,
include/lapi/splice.h static inline ssize_t splice(int fd_in, loff_t *off_in, int fd_out, · line 40
Quoted 10 lines
include/lapi/splice.h +10
-0+ int fd_out, loff_t *off_out, + size_t len, unsigned int flags) +{ + ssize_t ret; + + ret =splice (fd_in, off_in, fd_out, off_out, len, flags); + +if (ret <0 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"splice(%d, %d, %zu) failed" , fd_in, fd_out, len);
Why don't we print the offsets?
Otherwise:
Quoted 17 lines
include/lapi/splice.h +9
-0+ } + +return ret; +} + +#define SAFE_SPLICE (fd_in, off_in, fd_out, off_out, len, flags) \ + safe_splice(__FILE__, __LINE__, (fd_in), (off_in), (fd_out), \ + (off_out), (len), (flags)) +#endif /* LAPI_SPLICE_H__ */ Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro
Quoted 1 line
Why don't we print the offsets?
will fix before merge. thanks
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/2 tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Replace raw splice() calls with SAFE_SPLICE() in tests where splice is utility plumbing, not the subject of testing.
--- testcases/kernel/crypto/af_alg08.c | 9 ++------- testcases/kernel/syscalls/tee/tee01.c | 8 ++------ testcases/kernel/syscalls/vmsplice/vmsplice01.c | 5 +---- 3 files changed, 5 insertions(+), 17 deletions(-)
testcases/kernel/crypto/af_alg08.c +2 -7
@@ -96,13 +96,8 @@ static void try_corrupt(void)SAFE_PIPE (pipefd); -TEST (splice (file_fd, &off_in, pipefd[1 ],NULL ,OVERWRITE_SIZE ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"splice(file -> pipe)" ); - -TEST (splice (pipefd[0 ],NULL , reqfd,NULL ,OVERWRITE_SIZE ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"splice(pipe -> AF_ALG)" ); +SAFE_SPLICE (file_fd, &off_in, pipefd[1 ],NULL ,OVERWRITE_SIZE ,0 ); +SAFE_SPLICE (pipefd[0 ],NULL , reqfd,NULL ,OVERWRITE_SIZE ,0 );/* Expected to fail (invalid ciphertext); triggers the scratch write */ TST_EXP_FAIL_SILENT (recv (reqfd, recvbuf,sizeof (recvbuf),0 ),EBADMSG );
testcases/kernel/syscalls/tee/tee01.c +2 -6
@@ -58,17 +58,13 @@ static void tee_test(void)SAFE_PIPE (pipe1);SAFE_PIPE (pipe2); - ret =splice (fd_in,NULL , pipe1[1 ],NULL ,TEST_BLOCK_SIZE ,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice(fd_in, pipe1) failed" ); +SAFE_SPLICE (fd_in,NULL , pipe1[1 ],NULL ,TEST_BLOCK_SIZE ,0 ); ret =tee (pipe1[0 ], pipe2[1 ],TEST_BLOCK_SIZE ,SPLICE_F_NONBLOCK );if (ret <0 )tst_brk (TBROK |TERRNO ,"tee() failed" ); - ret =splice (pipe2[0 ],NULL , fd_out,NULL ,TEST_BLOCK_SIZE ,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice(pipe2, fd_out) failed" ); +SAFE_SPLICE (pipe2[0 ],NULL , fd_out,NULL ,TEST_BLOCK_SIZE ,0 );SAFE_CLOSE (pipe2[0 ]);SAFE_CLOSE (pipe2[1 ]);
testcases/kernel/syscalls/vmsplice/vmsplice01.c +1 -4
@@ -50,7 +50,6 @@ static void vmsplice_test(void) {int pipes[2 ];long written; -int ret;int fd_out;struct iovec v;loff_t offset;
@@ -85,9 +84,7 @@ static void vmsplice_test(void) } } - ret =splice (pipes[0 ],NULL , fd_out, &offset, written,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice() failed" ); +SAFE_SPLICE (pipes[0 ],NULL , fd_out, &offset, written,0 );//printf("offset = %lld\n", (long long)offset); }
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
AppliedMerged, Thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp