Re: [PATCH 6/8] trace-cmd output: Set file_state of output handle after copy of headers

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

 



On Tue, 2 Mar 2021 10:10:24 +0200
Tzvetomir Stoyanov <tz.stoyanov@xxxxxxxxx> wrote:

> On Mon, Mar 1, 2021 at 4:38 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > From: "Steven Rostedt (VMware)" <rostedt@xxxxxxxxxxx>
> >
> > Now that the input and output handles know the state they are at in reading
> > or writing, the tracecmd_copy() has to set the state of the output handle it
> > creates.
> >
> > Signed-off-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
> > ---
> >  lib/trace-cmd/trace-output.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
> > index 6d504cbaf133..1156899a85d3 100644
> > --- a/lib/trace-cmd/trace-output.c
> > +++ b/lib/trace-cmd/trace-output.c
> > @@ -1656,6 +1656,8 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle,
> >         if (tracecmd_copy_headers(ihandle, handle->fd) < 0)
> >                 goto out_free;
> >
> > +       handle->file_state = TRACECMD_FILE_CMD_LINES;  
> 
> Why is the state overwritten here, isn't it more logical to be set in
> tracecmd_copy_headers(), by each function that copies a header to set

That's because the handle is not passed into tracecmd_copy_headers.

And because the handle is a struct tracecmd_output, the
tracecmd_copy_headers() which is in trace-input.c doesn't have access to
this structure, and I prefer to keep it that way.

That said, we could modify tracecmd_copy_header() to return the state that
it copied up to, or negative on error.

	state = tracecmd_copy_headers(ihandle, handle->fd);
	if (state < 0)
		goto out_free;

	handle->file_state = state;

That would be more robust!

-- Steve


> the relevant state. The last call in tracecmd_copy_headers()
> is copy_command_lines(), which should set state to
> TRACECMD_FILE_CMD_LINES in case of success.
> The state is already TRACECMD_FILE_CMD_LINES
> in tracecmd_copy_headers(), but right before its exit it
> is overwritten to the old file state. And here again it is
> overwritten back to TRACECMD_FILE_CMD_LINES.
> May be I miss something here, cannot understand the logic.
> 
> > +
> >         /* The file is all ready to have cpu data attached */
> >         return handle;
> >
> > --
> > 2.30.0
> >
> >  
> 
> 




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

  Powered by Linux