@@ -2910,30 +2910,47 @@ static int handle_options(struct tracecmd_input *handle)
long long offset;
unsigned short option;
unsigned int size;
+ unsigned short id, flags;
char *cpustats = NULL;
struct input_buffer_instance *buffer;
struct hook_list *hook;
+ bool comperss = false;
char *buf;
int cpus;
int ret;
- handle->options_start = lseek64(handle->fd, 0, SEEK_CUR);
-
- for (;;) {
- if (read2(handle, &option))
+ if (handle->file_version < 7) {
+ handle->options_start = lseek64(handle->fd, 0, SEEK_CUR);
+ } else {
+ if (read_section_header(handle, &id, &flags, NULL, NULL))
return -1;
+ if (id != TRACECMD_OPTION_DONE)
+ return -1;
+ if (flags & TRACECMD_SEC_FL_COMPRESS)
+ comperss = true;
+ }
- if (option == TRACECMD_OPTION_DONE)
+ if (comperss && in_uncompress_block(handle))
+ return -1;
+ for (;;) {
+ ret = read2(handle, &option);
+ if (ret)
+ goto out;
+ if (handle->file_version < 7 && option == TRACECMD_OPTION_DONE)
break;
/* next 4 bytes is the size of the option */
- if (read4(handle, &size))
- return -1;
+ ret = read4(handle, &size);
+ if (ret)
+ goto out;
buf = malloc(size);
- if (!buf)
- return -ENOMEM;
- if (do_read_check(handle, buf, size))
- return -1;
+ if (!buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ ret = do_read_check(handle, buf, size);
+ if (ret)
+ goto out;
switch (option) {
case TRACECMD_OPTION_DATE:
@@ -2983,7 +3000,7 @@ static int handle_options(struct tracecmd_input *handle)
buf + 8, 4);
ret = tsync_cpu_offsets_load(handle, buf + 12, size - 12);
if (ret < 0)
- return ret;
+ goto out;
tracecmd_enable_tsync(handle, true);
break;
case TRACECMD_OPTION_CPUSTAT:
@@ -2992,7 +3009,7 @@ static int handle_options(struct tracecmd_input *handle)
handle->cpustats_size + size + 1);
if (!cpustats) {
ret = -ENOMEM;
- return ret;
+ goto out;
}
memcpy(cpustats + handle->cpustats_size, buf, size);
handle->cpustats_size += size;
@@ -3079,9 +3096,12 @@ static int handle_options(struct tracecmd_input *handle)
}
- handle->cpustats = cpustats;
+ ret = 0;
- return 0;
+out:
+ if (comperss)
+ in_uncompress_reset(handle);
+ return ret;
}
static int read_options_type(struct tracecmd_input *handle)
In trace file version 7, options section has a section header and possible compression of the data. Extend the options handling logic with this new format. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 50 ++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-)