From: Peter Xu <peterx@redhat.com>
To: linux-kernel@vger.kernel.org, srostedt@redhat.com
Cc: peterx@redhat.com
Subject: [PATCH trace-cmd 2/2] trace-recorder: better error handling during copy
Date: Tue, 22 Mar 2016 15:40:42 +0800 [thread overview]
Message-ID: <1458632442-6878-3-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1458632442-6878-1-git-send-email-peterx@redhat.com>
Currently we have two ways to copy data, one is splice, one is read +
write. For both, dump more information when we got errors during the
copy. Also, when we update_fd(), we should make sure all bytes written,
and update written bytes only.
These information might be important to better diagnose when the copy
got wrong, like 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@redhat.com>
---
trace-recorder.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/trace-recorder.c b/trace-recorder.c
index 49b04ea..7d6feb0 100644
--- a/trace-recorder.c
+++ b/trace-recorder.c
@@ -334,13 +334,14 @@ 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 */);
if (ret < 0) {
if (errno != EAGAIN && errno != EINTR) {
- warning("recorder error in splice input");
+ warning("recorder error in splice input: %s",
+ strerror(errno));
return -1;
}
if (errno == EINTR)
@@ -348,16 +349,23 @@ 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");
+ warning("recorder error in splice output: %s",
+ strerror(errno));
return -1;
}
ret = 0;
- } else
+ } else {
+ if (written != ret) {
+ warning("recorder written %ld to write %d: %s",
+ written, ret, strerror(errno));
+ return -1;
+ }
update_fd(recorder, ret);
+ }
return ret;
}
@@ -369,18 +377,24 @@ 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) {
if (errno != EAGAIN && errno != EINTR) {
- warning("recorder error in read output");
+ warning("recorder error in read output: %s",
+ strerror(errno));
return -1;
}
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: %s",
+ written, ret, strerror(errno));
+ return -1;
+ }
update_fd(recorder, ret);
}
--
2.4.3
next prev parent reply other threads:[~2016-03-22 7:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 7:40 [PATCH trace-cmd 0/2] " Peter Xu
2016-03-22 7:40 ` [PATCH trace-cmd 1/2] trace-cmd-listen: remove useless printf Peter Xu
2016-03-22 13:18 ` Steven Rostedt
2016-03-23 6:39 ` Peter Xu
2016-03-22 7:40 ` Peter Xu [this message]
2016-03-22 13:19 ` [PATCH trace-cmd 2/2] trace-recorder: better error handling during copy Steven Rostedt
2016-03-23 7:02 ` Peter Xu
2016-03-23 7:05 ` [PATCH trace-cmd v2] " Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458632442-6878-3-git-send-email-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®