On Tue, 14 Sep 2021 16:12:19 +0300 "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote: > Make the function, that checks if the next file state is valid, global > for the trace-cmd library, so it can be reused. It is important the same check > logic to be used in the whole library. FYI, Normally this would be broken into two patches. > > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> > --- > lib/trace-cmd/include/trace-cmd-local.h | 2 + > lib/trace-cmd/trace-input.c | 1 + > lib/trace-cmd/trace-output.c | 66 ++++++++----------------- > lib/trace-cmd/trace-util.c | 28 +++++++++++ > 4 files changed, 51 insertions(+), 46 deletions(-) > > diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h > index 821b5cdb..7f3b45a8 100644 > --- a/lib/trace-cmd/include/trace-cmd-local.h > +++ b/lib/trace-cmd/include/trace-cmd-local.h > @@ -31,5 +31,7 @@ void tracecmd_info(const char *fmt, ...); > #endif > #endif > > +bool check_file_state(unsigned long file_version, int current_state, int new_state); > +bool check_out_state(struct tracecmd_output *handle, int new_state); The first just adding the check_out_state. > @@ -1661,3 +1630,8 @@ out_free: > tracecmd_output_close(handle); > return NULL; > } > + > +__hidden bool check_out_state(struct tracecmd_output *handle, int new_state) > +{ > + return check_file_state(handle->file_version, handle->file_state, new_state); > +} > diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c > index 9bc94822..db7ce7ee 100644 > --- a/lib/trace-cmd/trace-util.c > +++ b/lib/trace-cmd/trace-util.c > @@ -624,3 +624,31 @@ bool tracecmd_is_version_supported(unsigned int version) > return true; > return false; > } The second patch, adding the file_version parameter, as currently nothing uses this, and it really isn't part of what this patch should do. But I'll just take this as is for now. -- Steve > + > +__hidden bool check_file_state(unsigned long file_version, int current_state, int new_state) > +{ > + switch (new_state) { > + case TRACECMD_FILE_HEADERS: > + case TRACECMD_FILE_FTRACE_EVENTS: > + case TRACECMD_FILE_ALL_EVENTS: > + case TRACECMD_FILE_KALLSYMS: > + case TRACECMD_FILE_PRINTK: > + case TRACECMD_FILE_CMD_LINES: > + case TRACECMD_FILE_CPU_COUNT: > + if (current_state == (new_state - 1)) > + return true; > + break; > + case TRACECMD_FILE_OPTIONS: > + if (current_state == (new_state - 1)) > + return true; > + break; > + case TRACECMD_FILE_CPU_LATENCY: > + case TRACECMD_FILE_CPU_FLYRECORD: > + if (current_state == TRACECMD_FILE_OPTIONS) > + return true; > + break; > + } > + > + return false; > +} > +