libtracefs: Handle EAGAIN case in flush functions
cover libtracefs: Handle EAGAIN case in flush functions
From: "Steven Rostedt (Google)" <[email protected]>
Have tracefs_cpu_flush_write() not error on EGAIN.
Have bothe tracefs_cpu_flush() and tracefs_cpu_flush_write() reset errno back to zero when it finishes with EAGAIN.
Steven Rostedt (Google) (2):
libtracefs: Do not return negative on EAGAIN for
tracefs_cpu_flush_write()
libtracefs: Reset errno to success on EAGAIN for the flush functions
src/tracefs-record.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/2 libtracefs: Do not return negative on EAGAIN for tracefs_cpu_flush_write()
From: "Steven Rostedt (Google)" <[email protected]>
Like tracefs_cpu_flush(), when the buffer is empty, and because the reading of the buffer is done in NON_BLOCK mode, it will finish with a negative and EAGAIN. This is a successful state, do not return a negative number here.
--- src/tracefs-record.c | 4 ++++ 1 file changed, 4 insertions(+)
src/tracefs-record.c +4 -0
@@ -495,6 +495,10 @@ int tracefs_cpu_flush_write(struct tracefs_cpu *tcpu, int wfd)if (ret >0 ) ret =write (wfd, buffer, ret); +/* It's OK if there's no data to read */ +if (ret <0 && errno ==EAGAIN ) + ret =0 ; +return ret; }
Signature · 1 line
2.35.1
PATCH 2/2 libtracefs: Reset errno to success on EAGAIN for the flush functions
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The functions tracefs_cpu_flush() and tracefs_cpu_flush_write() both usually end with errno = EAGAIN. This should not be passed to the calling function, so reset it to 0.
--- src/tracefs-record.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
src/tracefs-record.c +8 -2
@@ -308,8 +308,11 @@ int tracefs_cpu_read(struct tracefs_cpu *tcpu, void *buffer, bool nonblock) ret =read (tcpu->fd, buffer, tcpu->subbuf_size);/* It's OK if there's no data to read */ -if (ret <0 && errno ==EAGAIN ) +if (ret <0 && errno ==EAGAIN ) { +/* Reset errno */ + errno =0 ; ret =0 ; + }return ret; }
@@ -470,8 +473,11 @@ int tracefs_cpu_flush(struct tracefs_cpu *tcpu, void *buffer) tcpu->buffered -= ret;/* It's OK if there's no data to read */ -if (ret <0 && errno ==EAGAIN ) +if (ret <0 && errno ==EAGAIN ) { +/* Reset errno */ + errno =0 ; ret =0 ; + }return ret; }
Signature · 1 line
2.35.1