Skip to contentSkip to conversation

libtracefs: Handle EAGAIN case in flush functions

PATCH New Steven Rostedt 1 participant 3 messages Nov 10, 2022

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index dbe0e9f01aad..71d1df99bb02 100644
@@ -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
#2 lore raw

PATCH 2/2 libtracefs: Reset errno to success on EAGAIN for the flush functions

In reply to Steven Rostedt

From: "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
index 71d1df99bb02..428bec0dfe3d 100644
@@ -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