[PATCH 1/3] tools/virtio-trace: Ignore EAGAIN error on splice()

From: Masami Hiramatsu (Google)
Date: Thu Aug 17 2023 - 01:08:40 EST


splice() can return EAGAIN error instead of returning 0 size read.
In that case, wait a while and try to call splice() again.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
tools/virtio/virtio-trace/trace-agent-rw.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/virtio/virtio-trace/trace-agent-rw.c b/tools/virtio/virtio-trace/trace-agent-rw.c
index ddfe7875eb16..e8a4c4f0c499 100644
--- a/tools/virtio/virtio-trace/trace-agent-rw.c
+++ b/tools/virtio/virtio-trace/trace-agent-rw.c
@@ -8,6 +8,7 @@
*/

#define _GNU_SOURCE
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -127,10 +128,10 @@ static void *rw_thread_main(void *thread_info)
rlen = splice(ts->in_fd, NULL, ts->read_pipe, NULL,
ts->pipe_size, SPLICE_F_MOVE | SPLICE_F_MORE);

- if (rlen < 0) {
- pr_err("Splice_read in rw-thread(%d)\n", ts->cpu_num);
+ if (rlen < 0 && errno != EAGAIN) {
+ pr_err("Splice_read error (%d) in rw-thread(%d)\n", errno, ts->cpu_num);
goto error;
- } else if (rlen == 0) {
+ } else if (rlen == 0 || errno == EAGAIN) {
/*
* If trace data do not exist or are unreadable not
* for exceeding the page size, splice_read returns
--
2.34.1


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>