[RFC,v5,10/11] trace-cmd: Set both input and output to non-blocking when recording is stopped
diff mbox series

Message ID 20190204065848.8248-11-kaslevs@vmware.com
State Superseded
Headers show
Series
  • Add VM kernel tracing over vsockets and FIFOs
Related show

Commit Message

Slavomir Kaslev Feb. 4, 2019, 6:58 a.m. UTC
When tracing VMs over FIFOs both the agent and the host recording process might
get blocked doing IO over a FIFO when the other side is gone. In this case we
won't get EPIPE error (as in the vsockets case) since the FIFOs will always be
opened by the hypervisor.

Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 lib/trace-cmd/trace-recorder.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c
index b750935..1c12c9e 100644
--- a/lib/trace-cmd/trace-recorder.c
+++ b/lib/trace-cmd/trace-recorder.c
@@ -40,6 +40,7 @@  struct tracecmd_recorder {
 	int		pages;
 	int		count;
 	unsigned	fd_flags;
+	unsigned	trace_fd_flags;
 	unsigned	flags;
 };
 
@@ -121,6 +122,8 @@  tracecmd_create_buffer_recorder_fd2(int fd, int fd2, int cpu, unsigned flags,
 	if (!(recorder->flags & TRACECMD_RECORD_BLOCK))
 		recorder->fd_flags |= 2; /* and NON_BLOCK */
 
+	recorder->trace_fd_flags = 1; /* SPLICE_F_MOVE */
+
 	/* Init to know what to free and release */
 	recorder->trace_fd = -1;
 	recorder->brass[0] = -1;
@@ -366,7 +369,7 @@  static long splice_data(struct tracecmd_recorder *recorder)
 	long ret;
 
 	read = splice(recorder->trace_fd, NULL, recorder->brass[1], NULL,
-		      recorder->pipe_size, 1 /* SPLICE_F_MOVE */);
+		      recorder->pipe_size, recorder->trace_fd_flags);
 	if (read < 0) {
 		if (errno != EAGAIN && errno != EINTR) {
 			warning("recorder error in splice input");
@@ -434,9 +437,12 @@  static void set_nonblock(struct tracecmd_recorder *recorder)
 	/* Do not block on reads for flushing */
 	flags = fcntl(recorder->trace_fd, F_GETFL);
 	fcntl(recorder->trace_fd, F_SETFL, flags | O_NONBLOCK);
+	recorder->trace_fd_flags |= 2; /* SPLICE_F_NONBLOCK */
 
 	/* Do not block on streams for write */
-	recorder->fd_flags |= 2; /* NON_BLOCK */
+	flags = fcntl(recorder->fd, F_GETFL);
+	fcntl(recorder->fd, F_SETFL, flags | O_NONBLOCK);
+	recorder->fd_flags |= 2; /* SPLICE_F_NONBLOCK */
 }
 
 long tracecmd_flush_recording(struct tracecmd_recorder *recorder)