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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 lib/trace-cmd/trace-recorder.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

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)
-- 
2.19.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux