linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd record: Verify that splice works before using it
@ 2022-06-08 17:05 Steven Rostedt
  2023-01-19 21:03 ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2022-06-08 17:05 UTC (permalink / raw)
  To: Linux Trace Devel; +Cc: Johannes Berg

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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.

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>
---
Johannes, can you test this?
I want to make sure that it fixes the issue.

 lib/trace-cmd/trace-recorder.c | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c
index c83337899098..c7ef13c851d2 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;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] trace-cmd record: Verify that splice works before using it
  2022-06-08 17:05 [PATCH] trace-cmd record: Verify that splice works before using it Steven Rostedt
@ 2023-01-19 21:03 ` Johannes Berg
  2023-01-19 21:53   ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2023-01-19 21:03 UTC (permalink / raw)
  To: Steven Rostedt, Linux Trace Devel

On Wed, 2022-06-08 at 13:05 -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> 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.
> 
> 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>
> ---
> Johannes, can you test this?
> I want to make sure that it fixes the issue.
> 

Umm, yeah, long time ago. Sorry, I've been meaning to do that, but it
isn't easy, so I kept pushing it off.

My use case for this was UML with hostfs, which I've since fixed (kernel
upstream commit 1568cb0e6d97 ("hostfs: support splice_write"); I can
revert that easily of course, but then I still have to build my own
trace-cmd with that patch... But that needs libtracefs 1.6 which even
Fedora doesn't ship.

Given that you've merged the patch already, I think I'll just give up on
testing it, sorry about that.

johannes

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] trace-cmd record: Verify that splice works before using it
  2023-01-19 21:03 ` Johannes Berg
@ 2023-01-19 21:53   ` Steven Rostedt
  0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2023-01-19 21:53 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Linux Trace Devel

On Thu, 19 Jan 2023 22:03:27 +0100
Johannes Berg <johannes@sipsolutions.net> wrote:

> On Wed, 2022-06-08 at 13:05 -0400, Steven Rostedt wrote:
> > From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> > 
> > 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.
> > 
> > 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>
> > ---
> > Johannes, can you test this?
> > I want to make sure that it fixes the issue.
> >   
> 
> Umm, yeah, long time ago. Sorry, I've been meaning to do that, but it
> isn't easy, so I kept pushing it off.
> 
> My use case for this was UML with hostfs, which I've since fixed (kernel
> upstream commit 1568cb0e6d97 ("hostfs: support splice_write"); I can
> revert that easily of course, but then I still have to build my own
> trace-cmd with that patch... But that needs libtracefs 1.6 which even
> Fedora doesn't ship.

They should ;-)

> 
> Given that you've merged the patch already, I think I'll just give up on
> testing it, sorry about that.

No worries. I'll just close the bug. Thanks, for responding.

-- Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-19 22:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 17:05 [PATCH] trace-cmd record: Verify that splice works before using it Steven Rostedt
2023-01-19 21:03 ` Johannes Berg
2023-01-19 21:53   ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).