[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1458716752-18005-1-git-send-email-peterx@redhat.com>
Date: Wed, 23 Mar 2016 15:05:52 +0800
From: Peter Xu <peterx@...hat.com>
To: linux-kernel@...r.kernel.org, srostedt@...hat.com
Cc: peterx@...hat.com
Subject: [PATCH trace-cmd v2] trace-recorder: better error handling during copy
Currently we have two ways to copy data, one is splice, one is read +
write. For both, we should make sure all bytes written, and update
written bytes only. It might happen when we got, e.g., no space error,
or connection error when copying data to remote sockets. In the past, we
just got silence errors without notice.
Signed-off-by: Peter Xu <peterx@...hat.com>
---
trace-recorder.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/trace-recorder.c b/trace-recorder.c
index 49b04ea..ac319d8 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -334,7 +334,7 @@ static inline void update_fd(struct tracecmd_recorder *recorder, int size)
*/
static long splice_data(struct tracecmd_recorder *recorder)
{
- long ret;
+ long ret, written;
ret = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL,
recorder->page_size, 1 /* SPLICE_F_MOVE */);
@@ -348,16 +348,22 @@ static long splice_data(struct tracecmd_recorder *recorder)
} else if (ret == 0)
return 0;
- ret = splice(recorder->brass[0], NULL, recorder->fd, NULL,
- recorder->page_size, recorder->fd_flags);
- if (ret < 0) {
+ written = splice(recorder->brass[0], NULL, recorder->fd, NULL,
+ recorder->page_size, recorder->fd_flags);
+ if (written < 0) {
if (errno != EAGAIN && errno != EINTR) {
warning("recorder error in splice output");
return -1;
}
ret = 0;
- } else
+ } else {
+ if (written != ret) {
+ warning("recorder written %ld to write %d",
+ written, ret);
+ return -1;
+ }
update_fd(recorder, ret);
+ }
return ret;
}
@@ -369,7 +375,7 @@ static long splice_data(struct tracecmd_recorder *recorder)
static long read_data(struct tracecmd_recorder *recorder)
{
char buf[recorder->page_size];
- long ret;
+ ssize_t ret, written;
ret = read(recorder->trace_fd, buf, recorder->page_size);
if (ret < 0) {
@@ -380,7 +386,12 @@ static long read_data(struct tracecmd_recorder *recorder)
ret = 0;
}
if (ret > 0) {
- write(recorder->fd, buf, ret);
+ written = write(recorder->fd, buf, ret);
+ if (written != ret) {
+ warning("recorder written %ld to write %d",
+ written, ret);
+ return -1;
+ }
update_fd(recorder, ret);
}
--
2.4.3
Powered by blists - more mailing lists