diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-06-15 19:06:53 -0400 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-06-15 19:18:52 -0400 |
commit | b704c9df363fe842bfbaff1e821f7fd692be27f9 (patch) | |
tree | 783091bb94e2965813bf664aa3452f37bedd72bf | |
parent | 4bf754dae1d925e9fa31e22838d7b9231eddf680 (diff) | |
download | trace-cmd-b704c9df363fe842bfbaff1e821f7fd692be27f9.tar.gz |
trace-cmd record: Verify that splice works before using it
Add a test to make sure that splice works on the source directory before
using it, and if not automatically switch over to read/write method.
Link: https://lore.kernel.org/linux-trace-devel/20220615190653.559ad605@gandalf.local.home
Suggested-by: Johannes Berg <johannes@sipsolutions.net>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=213659
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | lib/trace-cmd/trace-recorder.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c index c8333789..c7ef13c8 100644 --- a/lib/trace-cmd/trace-recorder.c +++ b/lib/trace-cmd/trace-recorder.c @@ -220,6 +220,41 @@ tracecmd_create_buffer_recorder_fd2(int fd, int fd2, int cpu, unsigned flags, return NULL; } +static void verify_splice(const char *file, unsigned *flags) +{ + int brass[2]; + int ret; + int fd; + + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) + return; /* Will fail by the caller too */ + + if (pipe(brass) < 0) + goto fail_pipe; + + ret = splice(brass[0], NULL, fd, NULL, 0, SPLICE_F_NONBLOCK); + if (ret < 0) + goto fail_splice; + + out_pipe: + close(brass[0]); + close(brass[1]); + out: + close(fd); + return; + + fail_pipe: + tracecmd_warning("Failed opening pipe, trying read/write"); + *flags |= TRACECMD_RECORD_NOSPLICE; + goto out; + + fail_splice: + tracecmd_warning("Failed splice to file, trying read/write"); + *flags |= TRACECMD_RECORD_NOSPLICE; + goto out_pipe; +} + struct tracecmd_recorder * tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, const char *buffer) { @@ -233,6 +268,9 @@ __tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, struct tracecmd_recorder *recorder; int fd; + if (!(flags & TRACECMD_RECORD_NOSPLICE)) + verify_splice(file, &flags); + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); if (fd < 0) return NULL; |